@neurosity/sdk 6.5.1 → 6.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -470,7 +470,7 @@ var e=arguments[3];Object.defineProperty(exports,"__esModule",{value:!0}),export
470
470
  },{}],"VxYX":[function(require,module,exports) {
471
471
  "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.firebase=exports.default=void 0;var e,n,t=require("tslib"),r=require("@firebase/util"),i=require("@firebase/component"),a=require("@firebase/logger"),o=((e={})["no-app"]="No Firebase App '{$appName}' has been created - call Firebase App.initializeApp()",e["bad-app-name"]="Illegal App name: '{$appName}",e["duplicate-app"]="Firebase App named '{$appName}' already exists",e["app-deleted"]="Firebase App named '{$appName}' already deleted",e["invalid-app-argument"]="firebase.{$appName}() takes either no argument or a Firebase App instance.",e["invalid-log-argument"]="First argument to `onLog` must be null or a function.",e),s=new r.ErrorFactory("app","Firebase",o),p="@firebase/app",c="0.6.30",l="@firebase/analytics",u="@firebase/app-check",f="@firebase/auth",d="@firebase/database",m="@firebase/functions",b="@firebase/installations",h="@firebase/messaging",g="@firebase/performance",v="@firebase/remote-config",y="@firebase/storage",_="@firebase/firestore",w="firebase-wrapper",N="[DEFAULT]",C=((n={})[p]="fire-core",n[l]="fire-analytics",n[u]="fire-app-check",n[f]="fire-auth",n[d]="fire-rtdb",n[m]="fire-fn",n[b]="fire-iid",n[h]="fire-fcm",n[g]="fire-perf",n[v]="fire-rc",n[y]="fire-gcs",n[_]="fire-fst",n["fire-js"]="fire-js",n[w]="fire-js-all",n),E=new a.Logger("@firebase/app"),I=function(){function e(e,n,t){var a=this;this.firebase_=t,this.isDeleted_=!1,this.name_=n.name,this.automaticDataCollectionEnabled_=n.automaticDataCollectionEnabled||!1,this.options_=(0,r.deepCopy)(e),this.container=new i.ComponentContainer(n.name),this._addComponent(new i.Component("app",function(){return a},"PUBLIC")),this.firebase_.INTERNAL.components.forEach(function(e){return a._addComponent(e)})}return Object.defineProperty(e.prototype,"automaticDataCollectionEnabled",{get:function(){return this.checkDestroyed_(),this.automaticDataCollectionEnabled_},set:function(e){this.checkDestroyed_(),this.automaticDataCollectionEnabled_=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"name",{get:function(){return this.checkDestroyed_(),this.name_},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"options",{get:function(){return this.checkDestroyed_(),this.options_},enumerable:!1,configurable:!0}),e.prototype.delete=function(){var e=this;return new Promise(function(n){e.checkDestroyed_(),n()}).then(function(){return e.firebase_.INTERNAL.removeApp(e.name_),Promise.all(e.container.getProviders().map(function(e){return e.delete()}))}).then(function(){e.isDeleted_=!0})},e.prototype._getService=function(e,n){var t;void 0===n&&(n=N),this.checkDestroyed_();var r=this.container.getProvider(e);return r.isInitialized()||"EXPLICIT"!==(null===(t=r.getComponent())||void 0===t?void 0:t.instantiationMode)||r.initialize(),r.getImmediate({identifier:n})},e.prototype._removeServiceInstance=function(e,n){void 0===n&&(n=N),this.container.getProvider(e).clearInstance(n)},e.prototype._addComponent=function(e){try{this.container.addComponent(e)}catch(n){E.debug("Component "+e.name+" failed to register with FirebaseApp "+this.name,n)}},e.prototype._addOrOverwriteComponent=function(e){this.container.addOrOverwriteComponent(e)},e.prototype.toJSON=function(){return{name:this.name,automaticDataCollectionEnabled:this.automaticDataCollectionEnabled,options:this.options}},e.prototype.checkDestroyed_=function(){if(this.isDeleted_)throw s.create("app-deleted",{appName:this.name_})},e}();I.prototype.name&&I.prototype.options||I.prototype.delete||console.log("dc");var A="8.10.0";function P(e){var n={},t=new Map,o={__esModule:!0,initializeApp:function(t,i){void 0===i&&(i={});if("object"!=typeof i||null===i){var a=i;i={name:a}}var p=i;void 0===p.name&&(p.name=N);var c=p.name;if("string"!=typeof c||!c)throw s.create("bad-app-name",{appName:String(c)});if((0,r.contains)(n,c))throw s.create("duplicate-app",{appName:c});var l=new e(t,p,o);return n[c]=l,l},app:p,registerVersion:function(e,n,t){var r,a=null!==(r=C[e])&&void 0!==r?r:e;t&&(a+="-"+t);var o=a.match(/\s|\//),s=n.match(/\s|\//);if(o||s){var p=['Unable to register library "'+a+'" with version "'+n+'":'];return o&&p.push('library name "'+a+'" contains illegal characters (whitespace or "/")'),o&&s&&p.push("and"),s&&p.push('version name "'+n+'" contains illegal characters (whitespace or "/")'),void E.warn(p.join(" "))}c(new i.Component(a+"-version",function(){return{library:a,version:n}},"VERSION"))},setLogLevel:a.setLogLevel,onLog:function(e,n){if(null!==e&&"function"!=typeof e)throw s.create("invalid-log-argument");(0,a.setUserLogHandler)(e,n)},apps:null,SDK_VERSION:A,INTERNAL:{registerComponent:c,removeApp:function(e){delete n[e]},components:t,useAsService:function(e,n){if("serverAuth"===n)return null;return n}}};function p(e){if(e=e||N,!(0,r.contains)(n,e))throw s.create("no-app",{appName:e});return n[e]}function c(i){var a=i.name;if(t.has(a))return E.debug("There were multiple attempts to register component "+a+"."),"PUBLIC"===i.type?o[a]:null;if(t.set(a,i),"PUBLIC"===i.type){var c=function(e){if(void 0===e&&(e=p()),"function"!=typeof e[a])throw s.create("invalid-app-argument",{appName:a});return e[a]()};void 0!==i.serviceProps&&(0,r.deepExtend)(c,i.serviceProps),o[a]=c,e.prototype[a]=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return this._getService.bind(this,a).apply(this,i.multipleInstances?e:[])}}for(var l=0,u=Object.keys(n);l<u.length;l++){var f=u[l];n[f]._addComponent(i)}return"PUBLIC"===i.type?o[a]:null}return o.default=o,Object.defineProperty(o,"apps",{get:function(){return Object.keys(n).map(function(e){return n[e]})}}),p.App=e,o}function F(){var e=P(I);return e.INTERNAL=(0,t.__assign)((0,t.__assign)({},e.INTERNAL),{createFirebaseNamespace:F,extendNamespace:function(n){(0,r.deepExtend)(e,n)},createSubscribe:r.createSubscribe,ErrorFactory:r.ErrorFactory,deepExtend:r.deepExtend}),e}var L=F(),D=function(){function e(e){this.container=e}return e.prototype.getPlatformInfoString=function(){return this.container.getProviders().map(function(e){if(k(e)){var n=e.getImmediate();return n.library+"/"+n.version}return null}).filter(function(e){return e}).join(" ")},e}();function k(e){var n=e.getComponent();return"VERSION"===(null==n?void 0:n.type)}function O(e,n){e.INTERNAL.registerComponent(new i.Component("platform-logger",function(e){return new D(e)},"PRIVATE")),e.registerVersion(p,c,n),e.registerVersion("fire-js","")}if((0,r.isBrowser)()&&void 0!==self.firebase){E.warn("\n Warning: Firebase is already defined in the global scope. Please make sure\n Firebase library is only loaded once.\n ");var j=self.firebase.SDK_VERSION;j&&j.indexOf("LITE")>=0&&E.warn("\n Warning: You are trying to load Firebase while using Firebase Performance standalone script.\n You should load Firebase Performance with this instance of Firebase to avoid loading duplicate code.\n ")}var S=L.initializeApp;L.initializeApp=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return(0,r.isNode)()&&E.warn('\n Warning: This is a browser-targeted Firebase bundle but it appears it is being\n run in a Node environment. If running in a Node environment, make sure you\n are using the bundle specified by the "main" field in package.json.\n \n If you are using Webpack, you can specify "main" as the first item in\n "resolve.mainFields":\n https://webpack.js.org/configuration/resolve/#resolvemainfields\n \n If using Rollup, use the @rollup/plugin-node-resolve plugin and specify "main"\n as the first item in "mainFields", e.g. [\'main\', \'module\'].\n https://github.com/rollup/@rollup/plugin-node-resolve\n '),S.apply(void 0,e)};var x=L;exports.firebase=x,O(x);var R=x;exports.default=R;
472
472
  },{"tslib":"f2sD","@firebase/util":"KxmD","@firebase/component":"sLOu","@firebase/logger":"TUpU"}],"OJEJ":[function(require,module,exports) {
473
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return e.default}});var e=r(require("@firebase/app"));function r(e){return e&&e.__esModule?e:{default:e}}var t="firebase",u="8.10.0";e.default.registerVersion(t,u,"app"),e.default.SDK_VERSION=u;
473
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return e.default}});var e=r(require("@firebase/app"));function r(e){return e&&e.__esModule?e:{default:e}}var t="firebase",u="8.10.1";e.default.registerVersion(t,u,"app"),e.default.SDK_VERSION=u;
474
474
  },{"@firebase/app":"VxYX"}],"EMWj":[function(require,module,exports) {
475
475
  var process = require("process");
476
476
  var e=require("process");Object.defineProperty(exports,"__esModule",{value:!0}),exports.enableLogging=exports.ServerValue=exports.Reference=exports.Query=exports.OnDisconnect=exports.Database=exports.DataSnapshot=void 0,exports.registerDatabase=nl;var t=a(require("@firebase/app")),n=require("@firebase/component"),r=require("@firebase/util"),i=require("tslib"),o=require("@firebase/logger");function a(e){return e&&e.__esModule?e:{default:e}}var s="@firebase/database",u="0.11.0",l="";function c(e){l=e}var h=function(){function e(e){this.domStorage_=e,this.prefix_="firebase:"}return e.prototype.set=function(e,t){null==t?this.domStorage_.removeItem(this.prefixedName_(e)):this.domStorage_.setItem(this.prefixedName_(e),(0,r.stringify)(t))},e.prototype.get=function(e){var t=this.domStorage_.getItem(this.prefixedName_(e));return null==t?null:(0,r.jsonEval)(t)},e.prototype.remove=function(e){this.domStorage_.removeItem(this.prefixedName_(e))},e.prototype.prefixedName_=function(e){return this.prefix_+e},e.prototype.toString=function(){return this.domStorage_.toString()},e}(),d=function(){function e(){this.cache_={},this.isInMemoryStorage=!0}return e.prototype.set=function(e,t){null==t?delete this.cache_[e]:this.cache_[e]=t},e.prototype.get=function(e){return(0,r.contains)(this.cache_,e)?this.cache_[e]:null},e.prototype.remove=function(e){delete this.cache_[e]},e}(),p=function(e){try{if("undefined"!=typeof window&&void 0!==window[e]){var t=window[e];return t.setItem("firebase:sentinel","cache"),t.removeItem("firebase:sentinel"),new h(t)}}catch(n){}return new d},f=p("localStorage"),_=p("sessionStorage"),v=new o.Logger("@firebase/database"),y=function(){var e=1;return function(){return e++}}(),g=function(e){var t=(0,r.stringToByteArray)(e),n=new r.Sha1;n.update(t);var i=n.digest();return r.base64.encodeByteArray(i)},m=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var n="",i=0;i<e.length;i++){var o=e[i];Array.isArray(o)||o&&"object"==typeof o&&"number"==typeof o.length?n+=m.apply(null,o):n+="object"==typeof o?(0,r.stringify)(o):o,n+=" "}return n},C=null,w=!0,b=function(e,t){(0,r.assert)(!t||!0===e||!1===e,"Can't turn on custom loggers persistently."),!0===e?(v.logLevel=o.LogLevel.VERBOSE,C=v.log.bind(v),t&&_.set("logging_enabled",!0)):"function"==typeof e?C=e:(C=null,_.remove("logging_enabled"))};exports.enableLogging=b;var T=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(!0===w&&(w=!1,null===C&&!0===_.get("logging_enabled")&&b(!0)),C){var n=m.apply(null,e);C(n)}},k=function(e){return function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];T.apply(void 0,(0,i.__spreadArray)([e],(0,i.__read)(t)))}},I=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n="FIREBASE INTERNAL ERROR: "+m.apply(void 0,(0,i.__spreadArray)([],(0,i.__read)(e)));v.error(n)},E=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n="FIREBASE FATAL ERROR: "+m.apply(void 0,(0,i.__spreadArray)([],(0,i.__read)(e)));throw v.error(n),new Error(n)},S=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n="FIREBASE WARNING: "+m.apply(void 0,(0,i.__spreadArray)([],(0,i.__read)(e)));v.warn(n)},P=function(){"undefined"!=typeof window&&window.location&&window.location.protocol&&-1!==window.location.protocol.indexOf("https:")&&S("Insecure Firebase access from a secure page. Please use https in calls to new Firebase().")},x=function(e){return"number"==typeof e&&(e!=e||e===Number.POSITIVE_INFINITY||e===Number.NEGATIVE_INFINITY)},N=function(e){if((0,r.isNodeSdk)()||"complete"===document.readyState)e();else{var t=!1,n=function(){document.body?t||(t=!0,e()):setTimeout(n,Math.floor(10))};document.addEventListener?(document.addEventListener("DOMContentLoaded",n,!1),window.addEventListener("load",n,!1)):document.attachEvent&&(document.attachEvent("onreadystatechange",function(){"complete"===document.readyState&&n()}),window.attachEvent("onload",n))}},R="[MIN_NAME]",A="[MAX_NAME]",D=function(e,t){if(e===t)return 0;if(e===R||t===A)return-1;if(t===R||e===A)return 1;var n=z(e),r=z(t);return null!==n?null!==r?n-r==0?e.length-t.length:n-r:-1:null!==r?1:e<t?-1:1},O=function(e,t){return e===t?0:e<t?-1:1},M=function(e,t){if(t&&e in t)return t[e];throw new Error("Missing required key ("+e+") in object: "+(0,r.stringify)(t))},q=function(e){if("object"!=typeof e||null===e)return(0,r.stringify)(e);var t=[];for(var n in e)t.push(n);t.sort();for(var i="{",o=0;o<t.length;o++)0!==o&&(i+=","),i+=(0,r.stringify)(t[o]),i+=":",i+=q(e[t[o]]);return i+="}"},F=function(e,t){var n=e.length;if(n<=t)return[e];for(var r=[],i=0;i<n;i+=t)i+t>n?r.push(e.substring(i,n)):r.push(e.substring(i,i+t));return r};function L(e,t){for(var n in e)e.hasOwnProperty(n)&&t(n,e[n])}var W=function(e){(0,r.assert)(!x(e),"Invalid JSON number");var t,n,i,o,a;0===e?(n=0,i=0,t=1/e==-1/0?1:0):(t=e<0,(e=Math.abs(e))>=Math.pow(2,-1022)?(n=(o=Math.min(Math.floor(Math.log(e)/Math.LN2),1023))+1023,i=Math.round(e*Math.pow(2,52-o)-Math.pow(2,52))):(n=0,i=Math.round(e/Math.pow(2,-1074))));var s=[];for(a=52;a;a-=1)s.push(i%2?1:0),i=Math.floor(i/2);for(a=11;a;a-=1)s.push(n%2?1:0),n=Math.floor(n/2);s.push(t?1:0),s.reverse();var u=s.join(""),l="";for(a=0;a<64;a+=8){var c=parseInt(u.substr(a,8),2).toString(16);1===c.length&&(c="0"+c),l+=c}return l.toLowerCase()},j=function(){return!("object"!=typeof window||!window.chrome||!window.chrome.extension||/^chrome/.test(window.location.href))},U=function(){return"object"==typeof Windows&&"object"==typeof Windows.UI};function B(e,t){var n="Unknown Error";"too_big"===e?n="The data requested exceeds the maximum size that can be accessed with a single request.":"permission_denied"===e?n="Client doesn't have permission to access the desired data.":"unavailable"===e&&(n="The service is unavailable");var r=new Error(e+" at "+t._path.toString()+": "+n);return r.code=e.toUpperCase(),r}var V=new RegExp("^-?(0*)\\d{1,10}$"),Q=-2147483648,H=2147483647,z=function(e){if(V.test(e)){var t=Number(e);if(t>=Q&&t<=H)return t}return null},Y=function(e){try{e()}catch(t){setTimeout(function(){var e=t.stack||"";throw S("Exception was thrown by user callback.",e),t},Math.floor(0))}},K=function(){return("object"==typeof window&&window.navigator&&window.navigator.userAgent||"").search(/googlebot|google webmaster tools|bingbot|yahoo! slurp|baiduspider|yandexbot|duckduckbot/i)>=0},G=function(e,t){var n=setTimeout(e,t);return"object"==typeof n&&n.unref&&n.unref(),n},$=function(){function e(e,t){var n=this;this.appName_=e,this.appCheckProvider=t,this.appCheck=null==t?void 0:t.getImmediate({optional:!0}),this.appCheck||null==t||t.get().then(function(e){return n.appCheck=e})}return e.prototype.getToken=function(e){var t=this;return this.appCheck?this.appCheck.getToken(e):new Promise(function(n,r){setTimeout(function(){t.appCheck?t.getToken(e).then(n,r):n(null)},0)})},e.prototype.addTokenChangeListener=function(e){var t;null===(t=this.appCheckProvider)||void 0===t||t.get().then(function(t){return t.addTokenListener(e)})},e.prototype.notifyForInvalidToken=function(){S('Provided AppCheck credentials for the app named "'+this.appName_+'" are invalid. This usually indicates your app was not initialized correctly.')},e}(),J=function(){function e(e,t,n){var r=this;this.appName_=e,this.firebaseOptions_=t,this.authProvider_=n,this.auth_=null,this.auth_=n.getImmediate({optional:!0}),this.auth_||n.onInit(function(e){return r.auth_=e})}return e.prototype.getToken=function(e){var t=this;return this.auth_?this.auth_.getToken(e).catch(function(e){return e&&"auth/token-not-initialized"===e.code?(T("Got auth/token-not-initialized error. Treating as null token."),null):Promise.reject(e)}):new Promise(function(n,r){setTimeout(function(){t.auth_?t.getToken(e).then(n,r):n(null)},0)})},e.prototype.addTokenChangeListener=function(e){this.auth_?this.auth_.addAuthTokenListener(e):this.authProvider_.get().then(function(t){return t.addAuthTokenListener(e)})},e.prototype.removeTokenChangeListener=function(e){this.authProvider_.get().then(function(t){return t.removeAuthTokenListener(e)})},e.prototype.notifyForInvalidToken=function(){var e='Provided authentication credentials for the app named "'+this.appName_+'" are invalid. This usually indicates your app was not initialized correctly. ';"credential"in this.firebaseOptions_?e+='Make sure the "credential" property provided to initializeApp() is authorized to access the specified "databaseURL" and is from the correct project.':"serviceAccount"in this.firebaseOptions_?e+='Make sure the "serviceAccount" property provided to initializeApp() is authorized to access the specified "databaseURL" and is from the correct project.':e+='Make sure the "apiKey" and "databaseURL" properties provided to initializeApp() match the values provided for your app at https://console.firebase.google.com/.',S(e)},e}(),X=function(){function e(e){this.accessToken=e}return e.prototype.getToken=function(e){return Promise.resolve({accessToken:this.accessToken})},e.prototype.addTokenChangeListener=function(e){e(this.accessToken)},e.prototype.removeTokenChangeListener=function(e){},e.prototype.notifyForInvalidToken=function(){},e.OWNER="owner",e}(),Z="5",ee="v",te="s",ne="r",re="f",ie=/(console\.firebase|firebase-console-\w+\.corp|firebase\.corp)\.google\.com/,oe="ls",ae="p",se="ac",ue="websocket",le="long_polling",ce=function(){function e(e,t,n,r,i,o,a){void 0===i&&(i=!1),void 0===o&&(o=""),void 0===a&&(a=!1),this.secure=t,this.namespace=n,this.webSocketOnly=r,this.nodeAdmin=i,this.persistenceKey=o,this.includeNamespaceInQueryParams=a,this._host=e.toLowerCase(),this._domain=this._host.substr(this._host.indexOf(".")+1),this.internalHost=f.get("host:"+e)||this._host}return e.prototype.isCacheableHost=function(){return"s-"===this.internalHost.substr(0,2)},e.prototype.isCustomHost=function(){return"firebaseio.com"!==this._domain&&"firebaseio-demo.com"!==this._domain},Object.defineProperty(e.prototype,"host",{get:function(){return this._host},set:function(e){e!==this.internalHost&&(this.internalHost=e,this.isCacheableHost()&&f.set("host:"+this._host,this.internalHost))},enumerable:!1,configurable:!0}),e.prototype.toString=function(){var e=this.toURLString();return this.persistenceKey&&(e+="<"+this.persistenceKey+">"),e},e.prototype.toURLString=function(){var e=this.secure?"https://":"http://",t=this.includeNamespaceInQueryParams?"?ns="+this.namespace:"";return""+e+this.host+"/"+t},e}();function he(e){return e.host!==e.internalHost||e.isCustomHost()||e.includeNamespaceInQueryParams}function de(e,t,n){var i;if((0,r.assert)("string"==typeof t,"typeof type must == string"),(0,r.assert)("object"==typeof n,"typeof params must == object"),t===ue)i=(e.secure?"wss://":"ws://")+e.internalHost+"/.ws?";else{if(t!==le)throw new Error("Unknown connection type: "+t);i=(e.secure?"https://":"http://")+e.internalHost+"/.lp?"}he(e)&&(n.ns=e.namespace);var o=[];return L(n,function(e,t){o.push(e+"="+t)}),i+o.join("&")}var pe=function(){function e(){this.counters_={}}return e.prototype.incrementCounter=function(e,t){void 0===t&&(t=1),(0,r.contains)(this.counters_,e)||(this.counters_[e]=0),this.counters_[e]+=t},e.prototype.get=function(){return(0,r.deepCopy)(this.counters_)},e}(),fe={},_e={};function ve(e){var t=e.toString();return fe[t]||(fe[t]=new pe),fe[t]}function ye(e,t){var n=e.toString();return _e[n]||(_e[n]=t()),_e[n]}var ge=function(){function e(e){this.onMessage_=e,this.pendingResponses=[],this.currentResponseNum=0,this.closeAfterResponse=-1,this.onClose=null}return e.prototype.closeAfter=function(e,t){this.closeAfterResponse=e,this.onClose=t,this.closeAfterResponse<this.currentResponseNum&&(this.onClose(),this.onClose=null)},e.prototype.handleResponse=function(e,t){var n=this;this.pendingResponses[e]=t;for(var r=function(){var e=i.pendingResponses[i.currentResponseNum];delete i.pendingResponses[i.currentResponseNum];for(var t=function(t){e[t]&&Y(function(){n.onMessage_(e[t])})},r=0;r<e.length;++r)t(r);if(i.currentResponseNum===i.closeAfterResponse)return i.onClose&&(i.onClose(),i.onClose=null),"break";i.currentResponseNum++},i=this;this.pendingResponses[this.currentResponseNum];){if("break"===r())break}},e}(),me="start",Ce="close",we="pLPCommand",be="pRTLPCB",Te="id",ke="pw",Ie="ser",Ee="cb",Se="seg",Pe="ts",xe="d",Ne="dframe",Re=1870,Ae=30,De=Re-Ae,Oe=25e3,Me=3e4,qe=function(){function e(e,t,n,r,i,o,a){var s=this;this.connId=e,this.repoInfo=t,this.applicationId=n,this.appCheckToken=r,this.authToken=i,this.transportSessionId=o,this.lastSessionId=a,this.bytesSent=0,this.bytesReceived=0,this.everConnected_=!1,this.log_=k(e),this.stats_=ve(t),this.urlFn=function(e){return s.appCheckToken&&(e[se]=s.appCheckToken),de(t,le,e)}}return e.prototype.open=function(e,t){var n=this;this.curSegmentNum=0,this.onDisconnect_=t,this.myPacketOrderer=new ge(e),this.isClosed_=!1,this.connectTimeoutTimer_=setTimeout(function(){n.log_("Timed out trying to connect."),n.onClosed_(),n.connectTimeoutTimer_=null},Math.floor(Me)),N(function(){if(!n.isClosed_){n.scriptTagHolder=new Fe(function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=(0,i.__read)(e,5),o=r[0],a=r[1],s=r[2];if(r[3],r[4],n.incrementIncomingBytes_(e),n.scriptTagHolder)if(n.connectTimeoutTimer_&&(clearTimeout(n.connectTimeoutTimer_),n.connectTimeoutTimer_=null),n.everConnected_=!0,o===me)n.id=a,n.password=s;else{if(o!==Ce)throw new Error("Unrecognized command received: "+o);a?(n.scriptTagHolder.sendNewPolls=!1,n.myPacketOrderer.closeAfter(a,function(){n.onClosed_()})):n.onClosed_()}},function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=(0,i.__read)(e,2),o=r[0],a=r[1];n.incrementIncomingBytes_(e),n.myPacketOrderer.handleResponse(o,a)},function(){n.onClosed_()},n.urlFn);var e={};e[me]="t",e[Ie]=Math.floor(1e8*Math.random()),n.scriptTagHolder.uniqueCallbackIdentifier&&(e[Ee]=n.scriptTagHolder.uniqueCallbackIdentifier),e[ee]=Z,n.transportSessionId&&(e[te]=n.transportSessionId),n.lastSessionId&&(e[oe]=n.lastSessionId),n.applicationId&&(e[ae]=n.applicationId),n.appCheckToken&&(e[se]=n.appCheckToken),"undefined"!=typeof location&&location.hostname&&ie.test(location.hostname)&&(e[ne]=re);var t=n.urlFn(e);n.log_("Connecting via long-poll to "+t),n.scriptTagHolder.addTag(t,function(){})}})},e.prototype.start=function(){this.scriptTagHolder.startLongPoll(this.id,this.password),this.addDisconnectPingFrame(this.id,this.password)},e.forceAllow=function(){e.forceAllow_=!0},e.forceDisallow=function(){e.forceDisallow_=!0},e.isAvailable=function(){return!(0,r.isNodeSdk)()&&(!!e.forceAllow_||!e.forceDisallow_&&"undefined"!=typeof document&&null!=document.createElement&&!j()&&!U())},e.prototype.markConnectionHealthy=function(){},e.prototype.shutdown_=function(){this.isClosed_=!0,this.scriptTagHolder&&(this.scriptTagHolder.close(),this.scriptTagHolder=null),this.myDisconnFrame&&(document.body.removeChild(this.myDisconnFrame),this.myDisconnFrame=null),this.connectTimeoutTimer_&&(clearTimeout(this.connectTimeoutTimer_),this.connectTimeoutTimer_=null)},e.prototype.onClosed_=function(){this.isClosed_||(this.log_("Longpoll is closing itself"),this.shutdown_(),this.onDisconnect_&&(this.onDisconnect_(this.everConnected_),this.onDisconnect_=null))},e.prototype.close=function(){this.isClosed_||(this.log_("Longpoll is being closed."),this.shutdown_())},e.prototype.send=function(e){var t=(0,r.stringify)(e);this.bytesSent+=t.length,this.stats_.incrementCounter("bytes_sent",t.length);for(var n=(0,r.base64Encode)(t),i=F(n,De),o=0;o<i.length;o++)this.scriptTagHolder.enqueueSegment(this.curSegmentNum,i.length,i[o]),this.curSegmentNum++},e.prototype.addDisconnectPingFrame=function(e,t){if(!(0,r.isNodeSdk)()){this.myDisconnFrame=document.createElement("iframe");var n={};n[Ne]="t",n[Te]=e,n[ke]=t,this.myDisconnFrame.src=this.urlFn(n),this.myDisconnFrame.style.display="none",document.body.appendChild(this.myDisconnFrame)}},e.prototype.incrementIncomingBytes_=function(e){var t=(0,r.stringify)(e).length;this.bytesReceived+=t,this.stats_.incrementCounter("bytes_received",t)},e}(),Fe=function(){function e(t,n,i,o){if(this.onDisconnect=i,this.urlFn=o,this.outstandingRequests=new Set,this.pendingSegs=[],this.currentSerial=Math.floor(1e8*Math.random()),this.sendNewPolls=!0,(0,r.isNodeSdk)())this.commandCB=t,this.onMessageCB=n;else{this.uniqueCallbackIdentifier=y(),window[we+this.uniqueCallbackIdentifier]=t,window[be+this.uniqueCallbackIdentifier]=n,this.myIFrame=e.createIFrame_();var a="";if(this.myIFrame.src&&"javascript:"===this.myIFrame.src.substr(0,"javascript:".length))a='<script>document.domain="'+document.domain+'";<\/script>';var s="<html><body>"+a+"</body></html>";try{this.myIFrame.doc.open(),this.myIFrame.doc.write(s),this.myIFrame.doc.close()}catch(u){T("frame writing exception"),u.stack&&T(u.stack),T(u)}}}return e.createIFrame_=function(){var e=document.createElement("iframe");if(e.style.display="none",!document.body)throw"Document body has not initialized. Wait to initialize Firebase until after the document is ready.";document.body.appendChild(e);try{e.contentWindow.document||T("No IE domain setting required")}catch(n){var t=document.domain;e.src="javascript:void((function(){document.open();document.domain='"+t+"';document.close();})())"}return e.contentDocument?e.doc=e.contentDocument:e.contentWindow?e.doc=e.contentWindow.document:e.document&&(e.doc=e.document),e},e.prototype.close=function(){var e=this;this.alive=!1,this.myIFrame&&(this.myIFrame.doc.body.innerHTML="",setTimeout(function(){null!==e.myIFrame&&(document.body.removeChild(e.myIFrame),e.myIFrame=null)},Math.floor(0)));var t=this.onDisconnect;t&&(this.onDisconnect=null,t())},e.prototype.startLongPoll=function(e,t){for(this.myID=e,this.myPW=t,this.alive=!0;this.newRequest_(););},e.prototype.newRequest_=function(){if(this.alive&&this.sendNewPolls&&this.outstandingRequests.size<(this.pendingSegs.length>0?2:1)){this.currentSerial++;var e={};e[Te]=this.myID,e[ke]=this.myPW,e[Ie]=this.currentSerial;for(var t=this.urlFn(e),n="",r=0;this.pendingSegs.length>0;){if(!(this.pendingSegs[0].d.length+Ae+n.length<=Re))break;var i=this.pendingSegs.shift();n=n+"&"+Se+r+"="+i.seg+"&"+Pe+r+"="+i.ts+"&"+xe+r+"="+i.d,r++}return t+=n,this.addLongPollTag_(t,this.currentSerial),!0}return!1},e.prototype.enqueueSegment=function(e,t,n){this.pendingSegs.push({seg:e,ts:t,d:n}),this.alive&&this.newRequest_()},e.prototype.addLongPollTag_=function(e,t){var n=this;this.outstandingRequests.add(t);var r=function(){n.outstandingRequests.delete(t),n.newRequest_()},i=setTimeout(r,Math.floor(Oe));this.addTag(e,function(){clearTimeout(i),r()})},e.prototype.addTag=function(e,t){var n=this;(0,r.isNodeSdk)()?this.doNodeLongPoll(e,t):setTimeout(function(){try{if(!n.sendNewPolls)return;var r=n.myIFrame.doc.createElement("script");r.type="text/javascript",r.async=!0,r.src=e,r.onload=r.onreadystatechange=function(){var e=r.readyState;e&&"loaded"!==e&&"complete"!==e||(r.onload=r.onreadystatechange=null,r.parentNode&&r.parentNode.removeChild(r),t())},r.onerror=function(){T("Long-poll script failed to load: "+e),n.sendNewPolls=!1,n.close()},n.myIFrame.doc.body.appendChild(r)}catch(i){}},Math.floor(1))},e}(),Le=16384,We=45e3,je=null;"undefined"!=typeof MozWebSocket?je=MozWebSocket:"undefined"!=typeof WebSocket&&(je=WebSocket);var Ue=function(){function t(e,n,r,i,o,a,s){this.connId=e,this.applicationId=r,this.appCheckToken=i,this.authToken=o,this.keepaliveTimer=null,this.frames=null,this.totalFrames=0,this.bytesSent=0,this.bytesReceived=0,this.log_=k(this.connId),this.stats_=ve(n),this.connURL=t.connectionURL_(n,a,s,i),this.nodeAdmin=n.nodeAdmin}return t.connectionURL_=function(e,t,n,i){var o={};return o[ee]=Z,!(0,r.isNodeSdk)()&&"undefined"!=typeof location&&location.hostname&&ie.test(location.hostname)&&(o[ne]=re),t&&(o[te]=t),n&&(o[oe]=n),i&&(o[se]=i),de(e,ue,o)},t.prototype.open=function(t,n){var i=this;this.onDisconnect=n,this.onMessage=t,this.log_("Websocket connecting to "+this.connURL),this.everConnected_=!1,f.set("previous_websocket_failure",!0);try{if((0,r.isNodeSdk)()){var o=this.nodeAdmin?"AdminNode":"Node",a={headers:{"User-Agent":"Firebase/"+Z+"/"+l+"/"+e.platform+"/"+o,"X-Firebase-GMPID":this.applicationId||""}};this.authToken&&(a.headers.Authorization="Bearer "+this.authToken),this.appCheckToken&&(a.headers["X-Firebase-AppCheck"]=this.appCheckToken);var s=e.env,u=0===this.connURL.indexOf("wss://")?s.HTTPS_PROXY||s.https_proxy:s.HTTP_PROXY||s.http_proxy;u&&(a.proxy={origin:u}),this.mySock=new je(this.connURL,[],a)}else{a={headers:{"X-Firebase-GMPID":this.applicationId||"","X-Firebase-AppCheck":this.appCheckToken||""}};this.mySock=new je(this.connURL,[],a)}}catch(h){this.log_("Error instantiating WebSocket.");var c=h.message||h.data;return c&&this.log_(c),void this.onClosed_()}this.mySock.onopen=function(){i.log_("Websocket connected."),i.everConnected_=!0},this.mySock.onclose=function(){i.log_("Websocket connection was disconnected."),i.mySock=null,i.onClosed_()},this.mySock.onmessage=function(e){i.handleIncomingFrame(e)},this.mySock.onerror=function(e){i.log_("WebSocket error. Closing connection.");var t=e.message||e.data;t&&i.log_(t),i.onClosed_()}},t.prototype.start=function(){},t.forceDisallow=function(){t.forceDisallow_=!0},t.isAvailable=function(){var e=!1;if("undefined"!=typeof navigator&&navigator.userAgent){var n=navigator.userAgent.match(/Android ([0-9]{0,}\.[0-9]{0,})/);n&&n.length>1&&parseFloat(n[1])<4.4&&(e=!0)}return!e&&null!==je&&!t.forceDisallow_},t.previouslyFailed=function(){return f.isInMemoryStorage||!0===f.get("previous_websocket_failure")},t.prototype.markConnectionHealthy=function(){f.remove("previous_websocket_failure")},t.prototype.appendFrame_=function(e){if(this.frames.push(e),this.frames.length===this.totalFrames){var t=this.frames.join("");this.frames=null;var n=(0,r.jsonEval)(t);this.onMessage(n)}},t.prototype.handleNewFrameCount_=function(e){this.totalFrames=e,this.frames=[]},t.prototype.extractFrameCount_=function(e){if((0,r.assert)(null===this.frames,"We already have a frame buffer"),e.length<=6){var t=Number(e);if(!isNaN(t))return this.handleNewFrameCount_(t),null}return this.handleNewFrameCount_(1),e},t.prototype.handleIncomingFrame=function(e){if(null!==this.mySock){var t=e.data;if(this.bytesReceived+=t.length,this.stats_.incrementCounter("bytes_received",t.length),this.resetKeepAlive(),null!==this.frames)this.appendFrame_(t);else{var n=this.extractFrameCount_(t);null!==n&&this.appendFrame_(n)}}},t.prototype.send=function(e){this.resetKeepAlive();var t=(0,r.stringify)(e);this.bytesSent+=t.length,this.stats_.incrementCounter("bytes_sent",t.length);var n=F(t,Le);n.length>1&&this.sendString_(String(n.length));for(var i=0;i<n.length;i++)this.sendString_(n[i])},t.prototype.shutdown_=function(){this.isClosed_=!0,this.keepaliveTimer&&(clearInterval(this.keepaliveTimer),this.keepaliveTimer=null),this.mySock&&(this.mySock.close(),this.mySock=null)},t.prototype.onClosed_=function(){this.isClosed_||(this.log_("WebSocket is closing itself"),this.shutdown_(),this.onDisconnect&&(this.onDisconnect(this.everConnected_),this.onDisconnect=null))},t.prototype.close=function(){this.isClosed_||(this.log_("WebSocket is being closed"),this.shutdown_())},t.prototype.resetKeepAlive=function(){var e=this;clearInterval(this.keepaliveTimer),this.keepaliveTimer=setInterval(function(){e.mySock&&e.sendString_("0"),e.resetKeepAlive()},Math.floor(We))},t.prototype.sendString_=function(e){try{this.mySock.send(e)}catch(t){this.log_("Exception thrown from WebSocket.send():",t.message||t.data,"Closing connection."),setTimeout(this.onClosed_.bind(this),0)}},t.responsesRequiredToBeHealthy=2,t.healthyTimeout=3e4,t}(),Be=function(){function e(e){this.initTransports_(e)}return Object.defineProperty(e,"ALL_TRANSPORTS",{get:function(){return[qe,Ue]},enumerable:!1,configurable:!0}),e.prototype.initTransports_=function(t){var n,r,o=Ue&&Ue.isAvailable(),a=o&&!Ue.previouslyFailed();if(t.webSocketOnly&&(o||S("wss:// URL used, but browser isn't known to support websockets. Trying anyway."),a=!0),a)this.transports_=[Ue];else{var s=this.transports_=[];try{for(var u=(0,i.__values)(e.ALL_TRANSPORTS),l=u.next();!l.done;l=u.next()){var c=l.value;c&&c.isAvailable()&&s.push(c)}}catch(h){n={error:h}}finally{try{l&&!l.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}}},e.prototype.initialTransport=function(){if(this.transports_.length>0)return this.transports_[0];throw new Error("No transports available")},e.prototype.upgradeTransport=function(){return this.transports_.length>1?this.transports_[1]:null},e}(),Ve=6e4,Qe=5e3,He=10240,ze=102400,Ye="t",Ke="d",Ge="s",$e="r",Je="e",Xe="o",Ze="a",et="n",tt="p",nt="h",rt=function(){function e(e,t,n,r,i,o,a,s,u,l){this.id=e,this.repoInfo_=t,this.applicationId_=n,this.appCheckToken_=r,this.authToken_=i,this.onMessage_=o,this.onReady_=a,this.onDisconnect_=s,this.onKill_=u,this.lastSessionId=l,this.connectionCount=0,this.pendingDataMessages=[],this.state_=0,this.log_=k("c:"+this.id+":"),this.transportManager_=new Be(t),this.log_("Connection created"),this.start_()}return e.prototype.start_=function(){var e=this,t=this.transportManager_.initialTransport();this.conn_=new t(this.nextTransportId_(),this.repoInfo_,this.applicationId_,this.appCheckToken_,this.authToken_,null,this.lastSessionId),this.primaryResponsesRequired_=t.responsesRequiredToBeHealthy||0;var n=this.connReceiver_(this.conn_),r=this.disconnReceiver_(this.conn_);this.tx_=this.conn_,this.rx_=this.conn_,this.secondaryConn_=null,this.isHealthy_=!1,setTimeout(function(){e.conn_&&e.conn_.open(n,r)},Math.floor(0));var i=t.healthyTimeout||0;i>0&&(this.healthyTimeout_=G(function(){e.healthyTimeout_=null,e.isHealthy_||(e.conn_&&e.conn_.bytesReceived>ze?(e.log_("Connection exceeded healthy timeout but has received "+e.conn_.bytesReceived+" bytes. Marking connection healthy."),e.isHealthy_=!0,e.conn_.markConnectionHealthy()):e.conn_&&e.conn_.bytesSent>He?e.log_("Connection exceeded healthy timeout but has sent "+e.conn_.bytesSent+" bytes. Leaving connection alive."):(e.log_("Closing unhealthy connection after timeout."),e.close()))},Math.floor(i)))},e.prototype.nextTransportId_=function(){return"c:"+this.id+":"+this.connectionCount++},e.prototype.disconnReceiver_=function(e){var t=this;return function(n){e===t.conn_?t.onConnectionLost_(n):e===t.secondaryConn_?(t.log_("Secondary connection lost."),t.onSecondaryConnectionLost_()):t.log_("closing an old connection")}},e.prototype.connReceiver_=function(e){var t=this;return function(n){2!==t.state_&&(e===t.rx_?t.onPrimaryMessageReceived_(n):e===t.secondaryConn_?t.onSecondaryMessageReceived_(n):t.log_("message on old connection"))}},e.prototype.sendRequest=function(e){var t={t:"d",d:e};this.sendData_(t)},e.prototype.tryCleanupConnection=function(){this.tx_===this.secondaryConn_&&this.rx_===this.secondaryConn_&&(this.log_("cleaning up and promoting a connection: "+this.secondaryConn_.connId),this.conn_=this.secondaryConn_,this.secondaryConn_=null)},e.prototype.onSecondaryControl_=function(e){if(Ye in e){var t=e[Ye];t===Ze?this.upgradeIfSecondaryHealthy_():t===$e?(this.log_("Got a reset on secondary, closing it"),this.secondaryConn_.close(),this.tx_!==this.secondaryConn_&&this.rx_!==this.secondaryConn_||this.close()):t===Xe&&(this.log_("got pong on secondary."),this.secondaryResponsesRequired_--,this.upgradeIfSecondaryHealthy_())}},e.prototype.onSecondaryMessageReceived_=function(e){var t=M("t",e),n=M("d",e);if("c"===t)this.onSecondaryControl_(n);else{if("d"!==t)throw new Error("Unknown protocol layer: "+t);this.pendingDataMessages.push(n)}},e.prototype.upgradeIfSecondaryHealthy_=function(){this.secondaryResponsesRequired_<=0?(this.log_("Secondary connection is healthy."),this.isHealthy_=!0,this.secondaryConn_.markConnectionHealthy(),this.proceedWithUpgrade_()):(this.log_("sending ping on secondary."),this.secondaryConn_.send({t:"c",d:{t:tt,d:{}}}))},e.prototype.proceedWithUpgrade_=function(){this.secondaryConn_.start(),this.log_("sending client ack on secondary"),this.secondaryConn_.send({t:"c",d:{t:Ze,d:{}}}),this.log_("Ending transmission on primary"),this.conn_.send({t:"c",d:{t:et,d:{}}}),this.tx_=this.secondaryConn_,this.tryCleanupConnection()},e.prototype.onPrimaryMessageReceived_=function(e){var t=M("t",e),n=M("d",e);"c"===t?this.onControl_(n):"d"===t&&this.onDataMessage_(n)},e.prototype.onDataMessage_=function(e){this.onPrimaryResponse_(),this.onMessage_(e)},e.prototype.onPrimaryResponse_=function(){this.isHealthy_||(this.primaryResponsesRequired_--,this.primaryResponsesRequired_<=0&&(this.log_("Primary connection is healthy."),this.isHealthy_=!0,this.conn_.markConnectionHealthy()))},e.prototype.onControl_=function(e){var t=M(Ye,e);if(Ke in e){var n=e[Ke];if(t===nt)this.onHandshake_(n);else if(t===et){this.log_("recvd end transmission on primary"),this.rx_=this.secondaryConn_;for(var r=0;r<this.pendingDataMessages.length;++r)this.onDataMessage_(this.pendingDataMessages[r]);this.pendingDataMessages=[],this.tryCleanupConnection()}else t===Ge?this.onConnectionShutdown_(n):t===$e?this.onReset_(n):t===Je?I("Server Error: "+n):t===Xe?(this.log_("got pong on primary."),this.onPrimaryResponse_(),this.sendPingOnPrimaryIfNecessary_()):I("Unknown control packet command: "+t)}},e.prototype.onHandshake_=function(e){var t=e.ts,n=e.v,r=e.h;this.sessionId=e.s,this.repoInfo_.host=r,0===this.state_&&(this.conn_.start(),this.onConnectionEstablished_(this.conn_,t),Z!==n&&S("Protocol version mismatch detected"),this.tryStartUpgrade_())},e.prototype.tryStartUpgrade_=function(){var e=this.transportManager_.upgradeTransport();e&&this.startUpgrade_(e)},e.prototype.startUpgrade_=function(e){var t=this;this.secondaryConn_=new e(this.nextTransportId_(),this.repoInfo_,this.applicationId_,this.appCheckToken_,this.authToken_,this.sessionId),this.secondaryResponsesRequired_=e.responsesRequiredToBeHealthy||0;var n=this.connReceiver_(this.secondaryConn_),r=this.disconnReceiver_(this.secondaryConn_);this.secondaryConn_.open(n,r),G(function(){t.secondaryConn_&&(t.log_("Timed out trying to upgrade."),t.secondaryConn_.close())},Math.floor(Ve))},e.prototype.onReset_=function(e){this.log_("Reset packet received. New host: "+e),this.repoInfo_.host=e,1===this.state_?this.close():(this.closeConnections_(),this.start_())},e.prototype.onConnectionEstablished_=function(e,t){var n=this;this.log_("Realtime connection established."),this.conn_=e,this.state_=1,this.onReady_&&(this.onReady_(t,this.sessionId),this.onReady_=null),0===this.primaryResponsesRequired_?(this.log_("Primary connection is healthy."),this.isHealthy_=!0):G(function(){n.sendPingOnPrimaryIfNecessary_()},Math.floor(Qe))},e.prototype.sendPingOnPrimaryIfNecessary_=function(){this.isHealthy_||1!==this.state_||(this.log_("sending ping on primary."),this.sendData_({t:"c",d:{t:tt,d:{}}}))},e.prototype.onSecondaryConnectionLost_=function(){var e=this.secondaryConn_;this.secondaryConn_=null,this.tx_!==e&&this.rx_!==e||this.close()},e.prototype.onConnectionLost_=function(e){this.conn_=null,e||0!==this.state_?1===this.state_&&this.log_("Realtime connection lost."):(this.log_("Realtime connection failed."),this.repoInfo_.isCacheableHost()&&(f.remove("host:"+this.repoInfo_.host),this.repoInfo_.internalHost=this.repoInfo_.host)),this.close()},e.prototype.onConnectionShutdown_=function(e){this.log_("Connection shutdown command received. Shutting down..."),this.onKill_&&(this.onKill_(e),this.onKill_=null),this.onDisconnect_=null,this.close()},e.prototype.sendData_=function(e){if(1!==this.state_)throw"Connection is not connected";this.tx_.send(e)},e.prototype.close=function(){2!==this.state_&&(this.log_("Closing realtime connection."),this.state_=2,this.closeConnections_(),this.onDisconnect_&&(this.onDisconnect_(),this.onDisconnect_=null))},e.prototype.closeConnections_=function(){this.log_("Shutting down all connections"),this.conn_&&(this.conn_.close(),this.conn_=null),this.secondaryConn_&&(this.secondaryConn_.close(),this.secondaryConn_=null),this.healthyTimeout_&&(clearTimeout(this.healthyTimeout_),this.healthyTimeout_=null)},e}(),it=function(){function e(){}return e.prototype.put=function(e,t,n,r){},e.prototype.merge=function(e,t,n,r){},e.prototype.refreshAuthToken=function(e){},e.prototype.refreshAppCheckToken=function(e){},e.prototype.onDisconnectPut=function(e,t,n){},e.prototype.onDisconnectMerge=function(e,t,n){},e.prototype.onDisconnectCancel=function(e,t){},e.prototype.reportStats=function(e){},e}(),ot=function(){function e(e){this.allowedEvents_=e,this.listeners_={},(0,r.assert)(Array.isArray(e)&&e.length>0,"Requires a non-empty array")}return e.prototype.trigger=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];if(Array.isArray(this.listeners_[e]))for(var r=(0,i.__spreadArray)([],(0,i.__read)(this.listeners_[e])),o=0;o<r.length;o++)r[o].callback.apply(r[o].context,t)},e.prototype.on=function(e,t,n){this.validateEventType_(e),this.listeners_[e]=this.listeners_[e]||[],this.listeners_[e].push({callback:t,context:n});var r=this.getInitialEvent(e);r&&t.apply(n,r)},e.prototype.off=function(e,t,n){this.validateEventType_(e);for(var r=this.listeners_[e]||[],i=0;i<r.length;i++)if(r[i].callback===t&&(!n||n===r[i].context))return void r.splice(i,1)},e.prototype.validateEventType_=function(e){(0,r.assert)(this.allowedEvents_.find(function(t){return t===e}),"Unknown event: "+e)},e}(),at=function(e){function t(){var t=e.call(this,["online"])||this;return t.online_=!0,"undefined"==typeof window||void 0===window.addEventListener||(0,r.isMobileCordova)()||(window.addEventListener("online",function(){t.online_||(t.online_=!0,t.trigger("online",!0))},!1),window.addEventListener("offline",function(){t.online_&&(t.online_=!1,t.trigger("online",!1))},!1)),t}return(0,i.__extends)(t,e),t.getInstance=function(){return new t},t.prototype.getInitialEvent=function(e){return(0,r.assert)("online"===e,"Unknown event type: "+e),[this.online_]},t.prototype.currentlyOnline=function(){return this.online_},t}(ot),st=32,ut=768,lt=function(){function e(e,t){if(void 0===t){this.pieces_=e.split("/");for(var n=0,r=0;r<this.pieces_.length;r++)this.pieces_[r].length>0&&(this.pieces_[n]=this.pieces_[r],n++);this.pieces_.length=n,this.pieceNum_=0}else this.pieces_=e,this.pieceNum_=t}return e.prototype.toString=function(){for(var e="",t=this.pieceNum_;t<this.pieces_.length;t++)""!==this.pieces_[t]&&(e+="/"+this.pieces_[t]);return e||"/"},e}();function ct(){return new lt("")}function ht(e){return e.pieceNum_>=e.pieces_.length?null:e.pieces_[e.pieceNum_]}function dt(e){return e.pieces_.length-e.pieceNum_}function pt(e){var t=e.pieceNum_;return t<e.pieces_.length&&t++,new lt(e.pieces_,t)}function ft(e){return e.pieceNum_<e.pieces_.length?e.pieces_[e.pieces_.length-1]:null}function _t(e){for(var t="",n=e.pieceNum_;n<e.pieces_.length;n++)""!==e.pieces_[n]&&(t+="/"+encodeURIComponent(String(e.pieces_[n])));return t||"/"}function vt(e,t){return void 0===t&&(t=0),e.pieces_.slice(e.pieceNum_+t)}function yt(e){if(e.pieceNum_>=e.pieces_.length)return null;for(var t=[],n=e.pieceNum_;n<e.pieces_.length-1;n++)t.push(e.pieces_[n]);return new lt(t,0)}function gt(e,t){for(var n=[],r=e.pieceNum_;r<e.pieces_.length;r++)n.push(e.pieces_[r]);if(t instanceof lt)for(r=t.pieceNum_;r<t.pieces_.length;r++)n.push(t.pieces_[r]);else{var i=t.split("/");for(r=0;r<i.length;r++)i[r].length>0&&n.push(i[r])}return new lt(n,0)}function mt(e){return e.pieceNum_>=e.pieces_.length}function Ct(e,t){var n=ht(e),r=ht(t);if(null===n)return t;if(n===r)return Ct(pt(e),pt(t));throw new Error("INTERNAL ERROR: innerPath ("+t+") is not within outerPath ("+e+")")}function wt(e,t){for(var n=vt(e,0),r=vt(t,0),i=0;i<n.length&&i<r.length;i++){var o=D(n[i],r[i]);if(0!==o)return o}return n.length===r.length?0:n.length<r.length?-1:1}function bt(e,t){if(dt(e)!==dt(t))return!1;for(var n=e.pieceNum_,r=t.pieceNum_;n<=e.pieces_.length;n++,r++)if(e.pieces_[n]!==t.pieces_[r])return!1;return!0}function Tt(e,t){var n=e.pieceNum_,r=t.pieceNum_;if(dt(e)>dt(t))return!1;for(;n<e.pieces_.length;){if(e.pieces_[n]!==t.pieces_[r])return!1;++n,++r}return!0}var kt=function(){return function(e,t){this.errorPrefix_=t,this.parts_=vt(e,0),this.byteLength_=Math.max(1,this.parts_.length);for(var n=0;n<this.parts_.length;n++)this.byteLength_+=(0,r.stringLength)(this.parts_[n]);St(this)}}();function It(e,t){e.parts_.length>0&&(e.byteLength_+=1),e.parts_.push(t),e.byteLength_+=(0,r.stringLength)(t),St(e)}function Et(e){var t=e.parts_.pop();e.byteLength_-=(0,r.stringLength)(t),e.parts_.length>0&&(e.byteLength_-=1)}function St(e){if(e.byteLength_>ut)throw new Error(e.errorPrefix_+"has a key path longer than "+ut+" bytes ("+e.byteLength_+").");if(e.parts_.length>st)throw new Error(e.errorPrefix_+"path specified exceeds the maximum depth that can be written ("+st+") or object contains a cycle "+Pt(e))}function Pt(e){return 0===e.parts_.length?"":"in property '"+e.parts_.join(".")+"'"}var xt,Nt,Rt=function(e){function t(){var t,n,r=e.call(this,["visible"])||this;return"undefined"!=typeof document&&void 0!==document.addEventListener&&(void 0!==document.hidden?(n="visibilitychange",t="hidden"):void 0!==document.mozHidden?(n="mozvisibilitychange",t="mozHidden"):void 0!==document.msHidden?(n="msvisibilitychange",t="msHidden"):void 0!==document.webkitHidden&&(n="webkitvisibilitychange",t="webkitHidden")),r.visible_=!0,n&&document.addEventListener(n,function(){var e=!document[t];e!==r.visible_&&(r.visible_=e,r.trigger("visible",e))},!1),r}return(0,i.__extends)(t,e),t.getInstance=function(){return new t},t.prototype.getInitialEvent=function(e){return(0,r.assert)("visible"===e,"Unknown event type: "+e),[this.visible_]},t}(ot),At=1e3,Dt=3e5,Ot=3e3,Mt=3e4,qt=1.3,Ft=3e4,Lt="server_kill",Wt=3,jt=function(e){function t(n,i,o,a,s,u,l,c){var h=e.call(this)||this;if(h.repoInfo_=n,h.applicationId_=i,h.onDataUpdate_=o,h.onConnectStatus_=a,h.onServerInfoUpdate_=s,h.authTokenProvider_=u,h.appCheckTokenProvider_=l,h.authOverride_=c,h.id=t.nextPersistentConnectionId_++,h.log_=k("p:"+h.id+":"),h.interruptReasons_={},h.listens=new Map,h.outstandingPuts_=[],h.outstandingGets_=[],h.outstandingPutCount_=0,h.outstandingGetCount_=0,h.onDisconnectRequestQueue_=[],h.connected_=!1,h.reconnectDelay_=At,h.maxReconnectDelay_=Dt,h.securityDebugCallback_=null,h.lastSessionId=null,h.establishConnectionTimer_=null,h.visible_=!1,h.requestCBHash_={},h.requestNumber_=0,h.realtime_=null,h.authToken_=null,h.appCheckToken_=null,h.forceTokenRefresh_=!1,h.invalidAuthTokenCount_=0,h.invalidAppCheckTokenCount_=0,h.firstConnection_=!0,h.lastConnectionAttemptTime_=null,h.lastConnectionEstablishedTime_=null,c&&!(0,r.isNodeSdk)())throw new Error("Auth override specified in options, but not supported on non Node.js platforms");return Rt.getInstance().on("visible",h.onVisible_,h),-1===n.host.indexOf("fblocal")&&at.getInstance().on("online",h.onOnline_,h),h}return(0,i.__extends)(t,e),t.prototype.sendRequest=function(e,t,n){var i=++this.requestNumber_,o={r:i,a:e,b:t};this.log_((0,r.stringify)(o)),(0,r.assert)(this.connected_,"sendRequest call when we're not connected not allowed."),this.realtime_.sendRequest(o),n&&(this.requestCBHash_[i]=n)},t.prototype.get=function(e){var t=this;this.initConnection_();var n=new r.Deferred,i={p:e._path.toString(),q:e._queryObject},o={action:"g",request:i,onComplete:function(e){var r=e.d;"ok"===e.s?(t.onDataUpdate_(i.p,r,!1,null),n.resolve(r)):n.reject(r)}};this.outstandingGets_.push(o),this.outstandingGetCount_++;var a=this.outstandingGets_.length-1;return this.connected_||setTimeout(function(){var e=t.outstandingGets_[a];void 0!==e&&o===e&&(delete t.outstandingGets_[a],t.outstandingGetCount_--,0===t.outstandingGetCount_&&(t.outstandingGets_=[]),t.log_("get "+a+" timed out on connection"),n.reject(new Error("Client is offline.")))},Ot),this.connected_&&this.sendGet_(a),n.promise},t.prototype.listen=function(e,t,n,i){this.initConnection_();var o=e._queryIdentifier,a=e._path.toString();this.log_("Listen called for "+a+" "+o),this.listens.has(a)||this.listens.set(a,new Map),(0,r.assert)(e._queryParams.isDefault()||!e._queryParams.loadsAllData(),"listen() called for non-default but complete query"),(0,r.assert)(!this.listens.get(a).has(o),"listen() called twice for same path/queryId.");var s={onComplete:i,hashFn:t,query:e,tag:n};this.listens.get(a).set(o,s),this.connected_&&this.sendListen_(s)},t.prototype.sendGet_=function(e){var t=this,n=this.outstandingGets_[e];this.sendRequest("g",n.request,function(r){delete t.outstandingGets_[e],t.outstandingGetCount_--,0===t.outstandingGetCount_&&(t.outstandingGets_=[]),n.onComplete&&n.onComplete(r)})},t.prototype.sendListen_=function(e){var n=this,r=e.query,i=r._path.toString(),o=r._queryIdentifier;this.log_("Listen on "+i+" for "+o);var a={p:i};e.tag&&(a.q=r._queryObject,a.t=e.tag),a.h=e.hashFn(),this.sendRequest("q",a,function(a){var s=a.d,u=a.s;t.warnOnListenWarnings_(s,r),(n.listens.get(i)&&n.listens.get(i).get(o))===e&&(n.log_("listen response",a),"ok"!==u&&n.removeListen_(i,o),e.onComplete&&e.onComplete(u,s))})},t.warnOnListenWarnings_=function(e,t){if(e&&"object"==typeof e&&(0,r.contains)(e,"w")){var n=(0,r.safeGet)(e,"w");if(Array.isArray(n)&&~n.indexOf("no_index")){var i='".indexOn": "'+t._queryParams.getIndex().toString()+'"',o=t._path.toString();S("Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding "+i+" at "+o+" to your security rules for better performance.")}}},t.prototype.refreshAuthToken=function(e){this.authToken_=e,this.log_("Auth token refreshed"),this.authToken_?this.tryAuth():this.connected_&&this.sendRequest("unauth",{},function(){}),this.reduceReconnectDelayIfAdminCredential_(e)},t.prototype.reduceReconnectDelayIfAdminCredential_=function(e){(e&&40===e.length||(0,r.isAdmin)(e))&&(this.log_("Admin auth credential detected. Reducing max reconnect time."),this.maxReconnectDelay_=Mt)},t.prototype.refreshAppCheckToken=function(e){this.appCheckToken_=e,this.log_("App check token refreshed"),this.appCheckToken_?this.tryAppCheck():this.connected_&&this.sendRequest("unappeck",{},function(){})},t.prototype.tryAuth=function(){var e=this;if(this.connected_&&this.authToken_){var t=this.authToken_,n=(0,r.isValidFormat)(t)?"auth":"gauth",i={cred:t};null===this.authOverride_?i.noauth=!0:"object"==typeof this.authOverride_&&(i.authvar=this.authOverride_),this.sendRequest(n,i,function(n){var r=n.s,i=n.d||"error";e.authToken_===t&&("ok"===r?e.invalidAuthTokenCount_=0:e.onAuthRevoked_(r,i))})}},t.prototype.tryAppCheck=function(){var e=this;this.connected_&&this.appCheckToken_&&this.sendRequest("appcheck",{token:this.appCheckToken_},function(t){var n=t.s,r=t.d||"error";"ok"===n?e.invalidAppCheckTokenCount_=0:e.onAppCheckRevoked_(n,r)})},t.prototype.unlisten=function(e,t){var n=e._path.toString(),i=e._queryIdentifier;this.log_("Unlisten called for "+n+" "+i),(0,r.assert)(e._queryParams.isDefault()||!e._queryParams.loadsAllData(),"unlisten() called for non-default but complete query"),this.removeListen_(n,i)&&this.connected_&&this.sendUnlisten_(n,i,e._queryObject,t)},t.prototype.sendUnlisten_=function(e,t,n,r){this.log_("Unlisten on "+e+" for "+t);var i={p:e};r&&(i.q=n,i.t=r),this.sendRequest("n",i)},t.prototype.onDisconnectPut=function(e,t,n){this.initConnection_(),this.connected_?this.sendOnDisconnect_("o",e,t,n):this.onDisconnectRequestQueue_.push({pathString:e,action:"o",data:t,onComplete:n})},t.prototype.onDisconnectMerge=function(e,t,n){this.initConnection_(),this.connected_?this.sendOnDisconnect_("om",e,t,n):this.onDisconnectRequestQueue_.push({pathString:e,action:"om",data:t,onComplete:n})},t.prototype.onDisconnectCancel=function(e,t){this.initConnection_(),this.connected_?this.sendOnDisconnect_("oc",e,null,t):this.onDisconnectRequestQueue_.push({pathString:e,action:"oc",data:null,onComplete:t})},t.prototype.sendOnDisconnect_=function(e,t,n,r){var i={p:t,d:n};this.log_("onDisconnect "+e,i),this.sendRequest(e,i,function(e){r&&setTimeout(function(){r(e.s,e.d)},Math.floor(0))})},t.prototype.put=function(e,t,n,r){this.putInternal("p",e,t,n,r)},t.prototype.merge=function(e,t,n,r){this.putInternal("m",e,t,n,r)},t.prototype.putInternal=function(e,t,n,r,i){this.initConnection_();var o={p:t,d:n};void 0!==i&&(o.h=i),this.outstandingPuts_.push({action:e,request:o,onComplete:r}),this.outstandingPutCount_++;var a=this.outstandingPuts_.length-1;this.connected_?this.sendPut_(a):this.log_("Buffering put: "+t)},t.prototype.sendPut_=function(e){var t=this,n=this.outstandingPuts_[e].action,r=this.outstandingPuts_[e].request,i=this.outstandingPuts_[e].onComplete;this.outstandingPuts_[e].queued=this.connected_,this.sendRequest(n,r,function(r){t.log_(n+" response",r),delete t.outstandingPuts_[e],t.outstandingPutCount_--,0===t.outstandingPutCount_&&(t.outstandingPuts_=[]),i&&i(r.s,r.d)})},t.prototype.reportStats=function(e){var t=this;if(this.connected_){var n={c:e};this.log_("reportStats",n),this.sendRequest("s",n,function(e){if("ok"!==e.s){var n=e.d;t.log_("reportStats","Error sending stats: "+n)}})}},t.prototype.onDataMessage_=function(e){if("r"in e){this.log_("from server: "+(0,r.stringify)(e));var t=e.r,n=this.requestCBHash_[t];n&&(delete this.requestCBHash_[t],n(e.b))}else{if("error"in e)throw"A server-side error has occurred: "+e.error;"a"in e&&this.onDataPush_(e.a,e.b)}},t.prototype.onDataPush_=function(e,t){this.log_("handleServerMessage",e,t),"d"===e?this.onDataUpdate_(t.p,t.d,!1,t.t):"m"===e?this.onDataUpdate_(t.p,t.d,!0,t.t):"c"===e?this.onListenRevoked_(t.p,t.q):"ac"===e?this.onAuthRevoked_(t.s,t.d):"apc"===e?this.onAppCheckRevoked_(t.s,t.d):"sd"===e?this.onSecurityDebugPacket_(t):I("Unrecognized action received from server: "+(0,r.stringify)(e)+"\nAre you using the latest client?")},t.prototype.onReady_=function(e,t){this.log_("connection ready"),this.connected_=!0,this.lastConnectionEstablishedTime_=(new Date).getTime(),this.handleTimestamp_(e),this.lastSessionId=t,this.firstConnection_&&this.sendConnectStats_(),this.restoreState_(),this.firstConnection_=!1,this.onConnectStatus_(!0)},t.prototype.scheduleConnect_=function(e){var t=this;(0,r.assert)(!this.realtime_,"Scheduling a connect when we're already connected/ing?"),this.establishConnectionTimer_&&clearTimeout(this.establishConnectionTimer_),this.establishConnectionTimer_=setTimeout(function(){t.establishConnectionTimer_=null,t.establishConnection_()},Math.floor(e))},t.prototype.initConnection_=function(){!this.realtime_&&this.firstConnection_&&this.scheduleConnect_(0)},t.prototype.onVisible_=function(e){e&&!this.visible_&&this.reconnectDelay_===this.maxReconnectDelay_&&(this.log_("Window became visible. Reducing delay."),this.reconnectDelay_=At,this.realtime_||this.scheduleConnect_(0)),this.visible_=e},t.prototype.onOnline_=function(e){e?(this.log_("Browser went online."),this.reconnectDelay_=At,this.realtime_||this.scheduleConnect_(0)):(this.log_("Browser went offline. Killing connection."),this.realtime_&&this.realtime_.close())},t.prototype.onRealtimeDisconnect_=function(){if(this.log_("data client disconnected"),this.connected_=!1,this.realtime_=null,this.cancelSentTransactions_(),this.requestCBHash_={},this.shouldReconnect_()){if(this.visible_){if(this.lastConnectionEstablishedTime_){(new Date).getTime()-this.lastConnectionEstablishedTime_>Ft&&(this.reconnectDelay_=At),this.lastConnectionEstablishedTime_=null}}else this.log_("Window isn't visible. Delaying reconnect."),this.reconnectDelay_=this.maxReconnectDelay_,this.lastConnectionAttemptTime_=(new Date).getTime();var e=(new Date).getTime()-this.lastConnectionAttemptTime_,t=Math.max(0,this.reconnectDelay_-e);t=Math.random()*t,this.log_("Trying to reconnect in "+t+"ms"),this.scheduleConnect_(t),this.reconnectDelay_=Math.min(this.maxReconnectDelay_,this.reconnectDelay_*qt)}this.onConnectStatus_(!1)},t.prototype.establishConnection_=function(){return(0,i.__awaiter)(this,void 0,void 0,function(){var e,n,o,a,s,u,l,c,h,d,p,f,_,v,y=this;return(0,i.__generator)(this,function(g){switch(g.label){case 0:if(!this.shouldReconnect_())return[3,4];this.log_("Making a connection attempt"),this.lastConnectionAttemptTime_=(new Date).getTime(),this.lastConnectionEstablishedTime_=null,e=this.onDataMessage_.bind(this),n=this.onReady_.bind(this),o=this.onRealtimeDisconnect_.bind(this),a=this.id+":"+t.nextConnectionId_++,s=this.lastSessionId,u=!1,l=null,c=function(){l?l.close():(u=!0,o())},h=function(e){(0,r.assert)(l,"sendRequest call when we're not connected not allowed."),l.sendRequest(e)},this.realtime_={close:c,sendRequest:h},d=this.forceTokenRefresh_,this.forceTokenRefresh_=!1,g.label=1;case 1:return g.trys.push([1,3,,4]),[4,Promise.all([this.authTokenProvider_.getToken(d),this.appCheckTokenProvider_.getToken(d)])];case 2:return p=i.__read.apply(void 0,[g.sent(),2]),f=p[0],_=p[1],u?T("getToken() completed but was canceled"):(T("getToken() completed. Creating connection."),this.authToken_=f&&f.accessToken,this.appCheckToken_=_&&_.token,l=new rt(a,this.repoInfo_,this.applicationId_,this.appCheckToken_,this.authToken_,e,n,o,function(e){S(e+" ("+y.repoInfo_.toString()+")"),y.interrupt(Lt)},s)),[3,4];case 3:return v=g.sent(),this.log_("Failed to get token: "+v),u||(this.repoInfo_.nodeAdmin&&S(v),c()),[3,4];case 4:return[2]}})})},t.prototype.interrupt=function(e){T("Interrupting connection for reason: "+e),this.interruptReasons_[e]=!0,this.realtime_?this.realtime_.close():(this.establishConnectionTimer_&&(clearTimeout(this.establishConnectionTimer_),this.establishConnectionTimer_=null),this.connected_&&this.onRealtimeDisconnect_())},t.prototype.resume=function(e){T("Resuming connection for reason: "+e),delete this.interruptReasons_[e],(0,r.isEmpty)(this.interruptReasons_)&&(this.reconnectDelay_=At,this.realtime_||this.scheduleConnect_(0))},t.prototype.handleTimestamp_=function(e){var t=e-(new Date).getTime();this.onServerInfoUpdate_({serverTimeOffset:t})},t.prototype.cancelSentTransactions_=function(){for(var e=0;e<this.outstandingPuts_.length;e++){var t=this.outstandingPuts_[e];t&&"h"in t.request&&t.queued&&(t.onComplete&&t.onComplete("disconnect"),delete this.outstandingPuts_[e],this.outstandingPutCount_--)}0===this.outstandingPutCount_&&(this.outstandingPuts_=[])},t.prototype.onListenRevoked_=function(e,t){var n;n=t?t.map(function(e){return q(e)}).join("$"):"default";var r=this.removeListen_(e,n);r&&r.onComplete&&r.onComplete("permission_denied")},t.prototype.removeListen_=function(e,t){var n,r=new lt(e).toString();if(this.listens.has(r)){var i=this.listens.get(r);n=i.get(t),i.delete(t),0===i.size&&this.listens.delete(r)}else n=void 0;return n},t.prototype.onAuthRevoked_=function(e,t){T("Auth token revoked: "+e+"/"+t),this.authToken_=null,this.forceTokenRefresh_=!0,this.realtime_.close(),"invalid_token"!==e&&"permission_denied"!==e||(this.invalidAuthTokenCount_++,this.invalidAuthTokenCount_>=Wt&&(this.reconnectDelay_=Mt,this.authTokenProvider_.notifyForInvalidToken()))},t.prototype.onAppCheckRevoked_=function(e,t){T("App check token revoked: "+e+"/"+t),this.appCheckToken_=null,this.forceTokenRefresh_=!0,"invalid_token"!==e&&"permission_denied"!==e||(this.invalidAppCheckTokenCount_++,this.invalidAppCheckTokenCount_>=Wt&&this.appCheckTokenProvider_.notifyForInvalidToken())},t.prototype.onSecurityDebugPacket_=function(e){this.securityDebugCallback_?this.securityDebugCallback_(e):"msg"in e&&console.log("FIREBASE: "+e.msg.replace("\n","\nFIREBASE: "))},t.prototype.restoreState_=function(){var e,t,n,r;this.tryAuth(),this.tryAppCheck();try{for(var o=(0,i.__values)(this.listens.values()),a=o.next();!a.done;a=o.next()){var s=a.value;try{for(var u=(n=void 0,(0,i.__values)(s.values())),l=u.next();!l.done;l=u.next()){var c=l.value;this.sendListen_(c)}}catch(p){n={error:p}}finally{try{l&&!l.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}}}catch(f){e={error:f}}finally{try{a&&!a.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}for(var h=0;h<this.outstandingPuts_.length;h++)this.outstandingPuts_[h]&&this.sendPut_(h);for(;this.onDisconnectRequestQueue_.length;){var d=this.onDisconnectRequestQueue_.shift();this.sendOnDisconnect_(d.action,d.pathString,d.data,d.onComplete)}for(h=0;h<this.outstandingGets_.length;h++)this.outstandingGets_[h]&&this.sendGet_(h)},t.prototype.sendConnectStats_=function(){var e={},t="js";(0,r.isNodeSdk)()&&(t=this.repoInfo_.nodeAdmin?"admin_node":"node"),e["sdk."+t+"."+l.replace(/\./g,"-")]=1,(0,r.isMobileCordova)()?e["framework.cordova"]=1:(0,r.isReactNative)()&&(e["framework.reactnative"]=1),this.reportStats(e)},t.prototype.shouldReconnect_=function(){var e=at.getInstance().currentlyOnline();return(0,r.isEmpty)(this.interruptReasons_)&&e},t.nextPersistentConnectionId_=0,t.nextConnectionId_=0,t}(it),Ut=function(){function e(e,t){this.name=e,this.node=t}return e.Wrap=function(t,n){return new e(t,n)},e}(),Bt=function(){function e(){}return e.prototype.getCompare=function(){return this.compare.bind(this)},e.prototype.indexedValueChanged=function(e,t){var n=new Ut(R,e),r=new Ut(R,t);return 0!==this.compare(n,r)},e.prototype.minPost=function(){return Ut.MIN},e}(),Vt=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return(0,i.__extends)(t,e),Object.defineProperty(t,"__EMPTY_NODE",{get:function(){return xt},set:function(e){xt=e},enumerable:!1,configurable:!0}),t.prototype.compare=function(e,t){return D(e.name,t.name)},t.prototype.isDefinedOn=function(e){throw(0,r.assertionError)("KeyIndex.isDefinedOn not expected to be called.")},t.prototype.indexedValueChanged=function(e,t){return!1},t.prototype.minPost=function(){return Ut.MIN},t.prototype.maxPost=function(){return new Ut(A,xt)},t.prototype.makePost=function(e,t){return(0,r.assert)("string"==typeof e,"KeyIndex indexValue must always be a string."),new Ut(e,xt)},t.prototype.toString=function(){return".key"},t}(Bt),Qt=new Vt,Ht=function(){function e(e,t,n,r,i){void 0===i&&(i=null),this.isReverse_=r,this.resultGenerator_=i,this.nodeStack_=[];for(var o=1;!e.isEmpty();)if(e=e,o=t?n(e.key,t):1,r&&(o*=-1),o<0)e=this.isReverse_?e.left:e.right;else{if(0===o){this.nodeStack_.push(e);break}this.nodeStack_.push(e),e=this.isReverse_?e.right:e.left}}return e.prototype.getNext=function(){if(0===this.nodeStack_.length)return null;var e,t=this.nodeStack_.pop();if(e=this.resultGenerator_?this.resultGenerator_(t.key,t.value):{key:t.key,value:t.value},this.isReverse_)for(t=t.left;!t.isEmpty();)this.nodeStack_.push(t),t=t.right;else for(t=t.right;!t.isEmpty();)this.nodeStack_.push(t),t=t.left;return e},e.prototype.hasNext=function(){return this.nodeStack_.length>0},e.prototype.peek=function(){if(0===this.nodeStack_.length)return null;var e=this.nodeStack_[this.nodeStack_.length-1];return this.resultGenerator_?this.resultGenerator_(e.key,e.value):{key:e.key,value:e.value}},e}(),zt=function(){function e(t,n,r,i,o){this.key=t,this.value=n,this.color=null!=r?r:e.RED,this.left=null!=i?i:Kt.EMPTY_NODE,this.right=null!=o?o:Kt.EMPTY_NODE}return e.prototype.copy=function(t,n,r,i,o){return new e(null!=t?t:this.key,null!=n?n:this.value,null!=r?r:this.color,null!=i?i:this.left,null!=o?o:this.right)},e.prototype.count=function(){return this.left.count()+1+this.right.count()},e.prototype.isEmpty=function(){return!1},e.prototype.inorderTraversal=function(e){return this.left.inorderTraversal(e)||!!e(this.key,this.value)||this.right.inorderTraversal(e)},e.prototype.reverseTraversal=function(e){return this.right.reverseTraversal(e)||e(this.key,this.value)||this.left.reverseTraversal(e)},e.prototype.min_=function(){return this.left.isEmpty()?this:this.left.min_()},e.prototype.minKey=function(){return this.min_().key},e.prototype.maxKey=function(){return this.right.isEmpty()?this.key:this.right.maxKey()},e.prototype.insert=function(e,t,n){var r=this,i=n(e,r.key);return(r=i<0?r.copy(null,null,null,r.left.insert(e,t,n),null):0===i?r.copy(null,t,null,null,null):r.copy(null,null,null,null,r.right.insert(e,t,n))).fixUp_()},e.prototype.removeMin_=function(){if(this.left.isEmpty())return Kt.EMPTY_NODE;var e=this;return e.left.isRed_()||e.left.left.isRed_()||(e=e.moveRedLeft_()),(e=e.copy(null,null,null,e.left.removeMin_(),null)).fixUp_()},e.prototype.remove=function(e,t){var n,r;if(t(e,(n=this).key)<0)n.left.isEmpty()||n.left.isRed_()||n.left.left.isRed_()||(n=n.moveRedLeft_()),n=n.copy(null,null,null,n.left.remove(e,t),null);else{if(n.left.isRed_()&&(n=n.rotateRight_()),n.right.isEmpty()||n.right.isRed_()||n.right.left.isRed_()||(n=n.moveRedRight_()),0===t(e,n.key)){if(n.right.isEmpty())return Kt.EMPTY_NODE;r=n.right.min_(),n=n.copy(r.key,r.value,null,null,n.right.removeMin_())}n=n.copy(null,null,null,null,n.right.remove(e,t))}return n.fixUp_()},e.prototype.isRed_=function(){return this.color},e.prototype.fixUp_=function(){var e=this;return e.right.isRed_()&&!e.left.isRed_()&&(e=e.rotateLeft_()),e.left.isRed_()&&e.left.left.isRed_()&&(e=e.rotateRight_()),e.left.isRed_()&&e.right.isRed_()&&(e=e.colorFlip_()),e},e.prototype.moveRedLeft_=function(){var e=this.colorFlip_();return e.right.left.isRed_()&&(e=(e=(e=e.copy(null,null,null,null,e.right.rotateRight_())).rotateLeft_()).colorFlip_()),e},e.prototype.moveRedRight_=function(){var e=this.colorFlip_();return e.left.left.isRed_()&&(e=(e=e.rotateRight_()).colorFlip_()),e},e.prototype.rotateLeft_=function(){var t=this.copy(null,null,e.RED,null,this.right.left);return this.right.copy(null,null,this.color,t,null)},e.prototype.rotateRight_=function(){var t=this.copy(null,null,e.RED,this.left.right,null);return this.left.copy(null,null,this.color,null,t)},e.prototype.colorFlip_=function(){var e=this.left.copy(null,null,!this.left.color,null,null),t=this.right.copy(null,null,!this.right.color,null,null);return this.copy(null,null,!this.color,e,t)},e.prototype.checkMaxDepth_=function(){var e=this.check_();return Math.pow(2,e)<=this.count()+1},e.prototype.check_=function(){if(this.isRed_()&&this.left.isRed_())throw new Error("Red node has red child("+this.key+","+this.value+")");if(this.right.isRed_())throw new Error("Right child of ("+this.key+","+this.value+") is red");var e=this.left.check_();if(e!==this.right.check_())throw new Error("Black depths differ");return e+(this.isRed_()?0:1)},e.RED=!0,e.BLACK=!1,e}(),Yt=function(){function e(){}return e.prototype.copy=function(e,t,n,r,i){return this},e.prototype.insert=function(e,t,n){return new zt(e,t,null)},e.prototype.remove=function(e,t){return this},e.prototype.count=function(){return 0},e.prototype.isEmpty=function(){return!0},e.prototype.inorderTraversal=function(e){return!1},e.prototype.reverseTraversal=function(e){return!1},e.prototype.minKey=function(){return null},e.prototype.maxKey=function(){return null},e.prototype.check_=function(){return 0},e.prototype.isRed_=function(){return!1},e}(),Kt=function(){function e(t,n){void 0===n&&(n=e.EMPTY_NODE),this.comparator_=t,this.root_=n}return e.prototype.insert=function(t,n){return new e(this.comparator_,this.root_.insert(t,n,this.comparator_).copy(null,null,zt.BLACK,null,null))},e.prototype.remove=function(t){return new e(this.comparator_,this.root_.remove(t,this.comparator_).copy(null,null,zt.BLACK,null,null))},e.prototype.get=function(e){for(var t,n=this.root_;!n.isEmpty();){if(0===(t=this.comparator_(e,n.key)))return n.value;t<0?n=n.left:t>0&&(n=n.right)}return null},e.prototype.getPredecessorKey=function(e){for(var t,n=this.root_,r=null;!n.isEmpty();){if(0===(t=this.comparator_(e,n.key))){if(n.left.isEmpty())return r?r.key:null;for(n=n.left;!n.right.isEmpty();)n=n.right;return n.key}t<0?n=n.left:t>0&&(r=n,n=n.right)}throw new Error("Attempted to find predecessor key for a nonexistent key. What gives?")},e.prototype.isEmpty=function(){return this.root_.isEmpty()},e.prototype.count=function(){return this.root_.count()},e.prototype.minKey=function(){return this.root_.minKey()},e.prototype.maxKey=function(){return this.root_.maxKey()},e.prototype.inorderTraversal=function(e){return this.root_.inorderTraversal(e)},e.prototype.reverseTraversal=function(e){return this.root_.reverseTraversal(e)},e.prototype.getIterator=function(e){return new Ht(this.root_,null,this.comparator_,!1,e)},e.prototype.getIteratorFrom=function(e,t){return new Ht(this.root_,e,this.comparator_,!1,t)},e.prototype.getReverseIteratorFrom=function(e,t){return new Ht(this.root_,e,this.comparator_,!0,t)},e.prototype.getReverseIterator=function(e){return new Ht(this.root_,null,this.comparator_,!0,e)},e.EMPTY_NODE=new Yt,e}();function Gt(e,t){return D(e.name,t.name)}function $t(e,t){return D(e,t)}function Jt(e){Nt=e}var Xt,Zt,en,tn=function(e){return"number"==typeof e?"number:"+W(e):"string:"+e},nn=function(e){if(e.isLeafNode()){var t=e.val();(0,r.assert)("string"==typeof t||"number"==typeof t||"object"==typeof t&&(0,r.contains)(t,".sv"),"Priority must be a string or number.")}else(0,r.assert)(e===Nt||e.isEmpty(),"priority of unexpected type.");(0,r.assert)(e===Nt||e.getPriority().isEmpty(),"Priority nodes can't have a priority of their own.")},rn=function(){function e(t,n){void 0===n&&(n=e.__childrenNodeConstructor.EMPTY_NODE),this.value_=t,this.priorityNode_=n,this.lazyHash_=null,(0,r.assert)(void 0!==this.value_&&null!==this.value_,"LeafNode shouldn't be created with null/undefined value."),nn(this.priorityNode_)}return Object.defineProperty(e,"__childrenNodeConstructor",{get:function(){return Xt},set:function(e){Xt=e},enumerable:!1,configurable:!0}),e.prototype.isLeafNode=function(){return!0},e.prototype.getPriority=function(){return this.priorityNode_},e.prototype.updatePriority=function(t){return new e(this.value_,t)},e.prototype.getImmediateChild=function(t){return".priority"===t?this.priorityNode_:e.__childrenNodeConstructor.EMPTY_NODE},e.prototype.getChild=function(t){return mt(t)?this:".priority"===ht(t)?this.priorityNode_:e.__childrenNodeConstructor.EMPTY_NODE},e.prototype.hasChild=function(){return!1},e.prototype.getPredecessorChildName=function(e,t){return null},e.prototype.updateImmediateChild=function(t,n){return".priority"===t?this.updatePriority(n):n.isEmpty()&&".priority"!==t?this:e.__childrenNodeConstructor.EMPTY_NODE.updateImmediateChild(t,n).updatePriority(this.priorityNode_)},e.prototype.updateChild=function(t,n){var i=ht(t);return null===i?n:n.isEmpty()&&".priority"!==i?this:((0,r.assert)(".priority"!==i||1===dt(t),".priority must be the last token in a path"),this.updateImmediateChild(i,e.__childrenNodeConstructor.EMPTY_NODE.updateChild(pt(t),n)))},e.prototype.isEmpty=function(){return!1},e.prototype.numChildren=function(){return 0},e.prototype.forEachChild=function(e,t){return!1},e.prototype.val=function(e){return e&&!this.getPriority().isEmpty()?{".value":this.getValue(),".priority":this.getPriority().val()}:this.getValue()},e.prototype.hash=function(){if(null===this.lazyHash_){var e="";this.priorityNode_.isEmpty()||(e+="priority:"+tn(this.priorityNode_.val())+":");var t=typeof this.value_;e+=t+":",e+="number"===t?W(this.value_):this.value_,this.lazyHash_=g(e)}return this.lazyHash_},e.prototype.getValue=function(){return this.value_},e.prototype.compareTo=function(t){return t===e.__childrenNodeConstructor.EMPTY_NODE?1:t instanceof e.__childrenNodeConstructor?-1:((0,r.assert)(t.isLeafNode(),"Unknown node type"),this.compareToLeafNode_(t))},e.prototype.compareToLeafNode_=function(t){var n=typeof t.value_,i=typeof this.value_,o=e.VALUE_TYPE_ORDER.indexOf(n),a=e.VALUE_TYPE_ORDER.indexOf(i);return(0,r.assert)(o>=0,"Unknown leaf type: "+n),(0,r.assert)(a>=0,"Unknown leaf type: "+i),o===a?"object"===i?0:this.value_<t.value_?-1:this.value_===t.value_?0:1:a-o},e.prototype.withIndex=function(){return this},e.prototype.isIndexed=function(){return!0},e.prototype.equals=function(e){if(e===this)return!0;if(e.isLeafNode()){var t=e;return this.value_===t.value_&&this.priorityNode_.equals(t.priorityNode_)}return!1},e.VALUE_TYPE_ORDER=["object","boolean","number","string"],e}();function on(e){Zt=e}function an(e){en=e}var sn,un,ln=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return(0,i.__extends)(t,e),t.prototype.compare=function(e,t){var n=e.node.getPriority(),r=t.node.getPriority(),i=n.compareTo(r);return 0===i?D(e.name,t.name):i},t.prototype.isDefinedOn=function(e){return!e.getPriority().isEmpty()},t.prototype.indexedValueChanged=function(e,t){return!e.getPriority().equals(t.getPriority())},t.prototype.minPost=function(){return Ut.MIN},t.prototype.maxPost=function(){return new Ut(A,new rn("[PRIORITY-POST]",en))},t.prototype.makePost=function(e,t){var n=Zt(e);return new Ut(t,new rn("[PRIORITY-POST]",n))},t.prototype.toString=function(){return".priority"},t}(Bt),cn=new ln,hn=Math.log(2),dn=function(){function e(e){var t;this.count=(t=e+1,parseInt(Math.log(t)/hn,10)),this.current_=this.count-1;var n,r=(n=this.count,parseInt(Array(n+1).join("1"),2));this.bits_=e+1&r}return e.prototype.nextBitIsOne=function(){var e=!(this.bits_&1<<this.current_);return this.current_--,e},e}(),pn=function(e,t,n,r){e.sort(t);var i=function(t,r){var o,a,s=r-t;if(0===s)return null;if(1===s)return o=e[t],a=n?n(o):o,new zt(a,o.node,zt.BLACK,null,null);var u=parseInt(s/2,10)+t,l=i(t,u),c=i(u+1,r);return o=e[u],a=n?n(o):o,new zt(a,o.node,zt.BLACK,l,c)},o=function(t){for(var r=null,o=null,a=e.length,s=function(t,r){var o=a-t,s=a;a-=t;var l=i(o+1,s),c=e[o],h=n?n(c):c;u(new zt(h,c.node,r,null,l))},u=function(e){r?(r.left=e,r=e):(o=e,r=e)},l=0;l<t.count;++l){var c=t.nextBitIsOne(),h=Math.pow(2,t.count-(l+1));c?s(h,zt.BLACK):(s(h,zt.BLACK),s(h,zt.RED))}return o}(new dn(e.length));return new Kt(r||t,o)},fn={},_n=function(){function e(e,t){this.indexes_=e,this.indexSet_=t}return Object.defineProperty(e,"Default",{get:function(){return(0,r.assert)(fn&&cn,"ChildrenNode.ts has not been loaded"),sn=sn||new e({".priority":fn},{".priority":cn})},enumerable:!1,configurable:!0}),e.prototype.get=function(e){var t=(0,r.safeGet)(this.indexes_,e);if(!t)throw new Error("No index defined for "+e);return t instanceof Kt?t:null},e.prototype.hasIndex=function(e){return(0,r.contains)(this.indexSet_,e.toString())},e.prototype.addIndex=function(t,n){(0,r.assert)(t!==Qt,"KeyIndex always exists and isn't meant to be added to the IndexMap.");for(var o,a=[],s=!1,u=n.getIterator(Ut.Wrap),l=u.getNext();l;)s=s||t.isDefinedOn(l.node),a.push(l),l=u.getNext();o=s?pn(a,t.getCompare()):fn;var c=t.toString(),h=(0,i.__assign)({},this.indexSet_);h[c]=t;var d=(0,i.__assign)({},this.indexes_);return d[c]=o,new e(d,h)},e.prototype.addToIndexes=function(t,n){var i=this;return new e((0,r.map)(this.indexes_,function(e,o){var a=(0,r.safeGet)(i.indexSet_,o);if((0,r.assert)(a,"Missing index implementation for "+o),e===fn){if(a.isDefinedOn(t.node)){for(var s=[],u=n.getIterator(Ut.Wrap),l=u.getNext();l;)l.name!==t.name&&s.push(l),l=u.getNext();return s.push(t),pn(s,a.getCompare())}return fn}var c=n.get(t.name),h=e;return c&&(h=h.remove(new Ut(t.name,c))),h.insert(t,t.node)}),this.indexSet_)},e.prototype.removeFromIndexes=function(t,n){return new e((0,r.map)(this.indexes_,function(e){if(e===fn)return e;var r=n.get(t.name);return r?e.remove(new Ut(t.name,r)):e}),this.indexSet_)},e}(),vn=function(){function e(e,t,n){this.children_=e,this.priorityNode_=t,this.indexMap_=n,this.lazyHash_=null,this.priorityNode_&&nn(this.priorityNode_),this.children_.isEmpty()&&(0,r.assert)(!this.priorityNode_||this.priorityNode_.isEmpty(),"An empty node cannot have a priority")}return Object.defineProperty(e,"EMPTY_NODE",{get:function(){return un||(un=new e(new Kt($t),null,_n.Default))},enumerable:!1,configurable:!0}),e.prototype.isLeafNode=function(){return!1},e.prototype.getPriority=function(){return this.priorityNode_||un},e.prototype.updatePriority=function(t){return this.children_.isEmpty()?this:new e(this.children_,t,this.indexMap_)},e.prototype.getImmediateChild=function(e){if(".priority"===e)return this.getPriority();var t=this.children_.get(e);return null===t?un:t},e.prototype.getChild=function(e){var t=ht(e);return null===t?this:this.getImmediateChild(t).getChild(pt(e))},e.prototype.hasChild=function(e){return null!==this.children_.get(e)},e.prototype.updateImmediateChild=function(t,n){if((0,r.assert)(n,"We should always be passing snapshot nodes"),".priority"===t)return this.updatePriority(n);var i=new Ut(t,n),o=void 0,a=void 0;n.isEmpty()?(o=this.children_.remove(t),a=this.indexMap_.removeFromIndexes(i,this.children_)):(o=this.children_.insert(t,n),a=this.indexMap_.addToIndexes(i,this.children_));var s=o.isEmpty()?un:this.priorityNode_;return new e(o,s,a)},e.prototype.updateChild=function(e,t){var n=ht(e);if(null===n)return t;(0,r.assert)(".priority"!==ht(e)||1===dt(e),".priority must be the last token in a path");var i=this.getImmediateChild(n).updateChild(pt(e),t);return this.updateImmediateChild(n,i)},e.prototype.isEmpty=function(){return this.children_.isEmpty()},e.prototype.numChildren=function(){return this.children_.count()},e.prototype.val=function(t){if(this.isEmpty())return null;var n={},r=0,i=0,o=!0;if(this.forEachChild(cn,function(a,s){n[a]=s.val(t),r++,o&&e.INTEGER_REGEXP_.test(a)?i=Math.max(i,Number(a)):o=!1}),!t&&o&&i<2*r){var a=[];for(var s in n)a[s]=n[s];return a}return t&&!this.getPriority().isEmpty()&&(n[".priority"]=this.getPriority().val()),n},e.prototype.hash=function(){if(null===this.lazyHash_){var e="";this.getPriority().isEmpty()||(e+="priority:"+tn(this.getPriority().val())+":"),this.forEachChild(cn,function(t,n){var r=n.hash();""!==r&&(e+=":"+t+":"+r)}),this.lazyHash_=""===e?"":g(e)}return this.lazyHash_},e.prototype.getPredecessorChildName=function(e,t,n){var r=this.resolveIndex_(n);if(r){var i=r.getPredecessorKey(new Ut(e,t));return i?i.name:null}return this.children_.getPredecessorKey(e)},e.prototype.getFirstChildName=function(e){var t=this.resolveIndex_(e);if(t){var n=t.minKey();return n&&n.name}return this.children_.minKey()},e.prototype.getFirstChild=function(e){var t=this.getFirstChildName(e);return t?new Ut(t,this.children_.get(t)):null},e.prototype.getLastChildName=function(e){var t=this.resolveIndex_(e);if(t){var n=t.maxKey();return n&&n.name}return this.children_.maxKey()},e.prototype.getLastChild=function(e){var t=this.getLastChildName(e);return t?new Ut(t,this.children_.get(t)):null},e.prototype.forEachChild=function(e,t){var n=this.resolveIndex_(e);return n?n.inorderTraversal(function(e){return t(e.name,e.node)}):this.children_.inorderTraversal(t)},e.prototype.getIterator=function(e){return this.getIteratorFrom(e.minPost(),e)},e.prototype.getIteratorFrom=function(e,t){var n=this.resolveIndex_(t);if(n)return n.getIteratorFrom(e,function(e){return e});for(var r=this.children_.getIteratorFrom(e.name,Ut.Wrap),i=r.peek();null!=i&&t.compare(i,e)<0;)r.getNext(),i=r.peek();return r},e.prototype.getReverseIterator=function(e){return this.getReverseIteratorFrom(e.maxPost(),e)},e.prototype.getReverseIteratorFrom=function(e,t){var n=this.resolveIndex_(t);if(n)return n.getReverseIteratorFrom(e,function(e){return e});for(var r=this.children_.getReverseIteratorFrom(e.name,Ut.Wrap),i=r.peek();null!=i&&t.compare(i,e)>0;)r.getNext(),i=r.peek();return r},e.prototype.compareTo=function(e){return this.isEmpty()?e.isEmpty()?0:-1:e.isLeafNode()||e.isEmpty()?1:e===gn?-1:0},e.prototype.withIndex=function(t){if(t===Qt||this.indexMap_.hasIndex(t))return this;var n=this.indexMap_.addIndex(t,this.children_);return new e(this.children_,this.priorityNode_,n)},e.prototype.isIndexed=function(e){return e===Qt||this.indexMap_.hasIndex(e)},e.prototype.equals=function(e){if(e===this)return!0;if(e.isLeafNode())return!1;var t=e;if(this.getPriority().equals(t.getPriority())){if(this.children_.count()===t.children_.count()){for(var n=this.getIterator(cn),r=t.getIterator(cn),i=n.getNext(),o=r.getNext();i&&o;){if(i.name!==o.name||!i.node.equals(o.node))return!1;i=n.getNext(),o=r.getNext()}return null===i&&null===o}return!1}return!1},e.prototype.resolveIndex_=function(e){return e===Qt?null:this.indexMap_.get(e.toString())},e.INTEGER_REGEXP_=/^(0|[1-9]\d*)$/,e}(),yn=function(e){function t(){return e.call(this,new Kt($t),vn.EMPTY_NODE,_n.Default)||this}return(0,i.__extends)(t,e),t.prototype.compareTo=function(e){return e===this?0:1},t.prototype.equals=function(e){return e===this},t.prototype.getPriority=function(){return this},t.prototype.getImmediateChild=function(e){return vn.EMPTY_NODE},t.prototype.isEmpty=function(){return!1},t}(vn),gn=new yn;Object.defineProperties(Ut,{MIN:{value:new Ut(R,vn.EMPTY_NODE)},MAX:{value:new Ut(A,gn)}}),Vt.__EMPTY_NODE=vn.EMPTY_NODE,rn.__childrenNodeConstructor=vn,Jt(gn),an(gn);var mn=!0;function Cn(e,t){if(void 0===t&&(t=null),null===e)return vn.EMPTY_NODE;if("object"==typeof e&&".priority"in e&&(t=e[".priority"]),(0,r.assert)(null===t||"string"==typeof t||"number"==typeof t||"object"==typeof t&&".sv"in t,"Invalid priority type found: "+typeof t),"object"==typeof e&&".value"in e&&null!==e[".value"]&&(e=e[".value"]),"object"!=typeof e||".sv"in e)return new rn(e,Cn(t));if(e instanceof Array||!mn){var n=vn.EMPTY_NODE;return L(e,function(t,i){if((0,r.contains)(e,t)&&"."!==t.substring(0,1)){var o=Cn(i);!o.isLeafNode()&&o.isEmpty()||(n=n.updateImmediateChild(t,o))}}),n.updatePriority(Cn(t))}var i=[],o=!1;if(L(e,function(e,t){if("."!==e.substring(0,1)){var n=Cn(t);n.isEmpty()||(o=o||!n.getPriority().isEmpty(),i.push(new Ut(e,n)))}}),0===i.length)return vn.EMPTY_NODE;var a=pn(i,Gt,function(e){return e.name},$t);if(o){var s=pn(i,cn.getCompare());return new vn(a,Cn(t),new _n({".priority":s},{".priority":cn}))}return new vn(a,Cn(t),_n.Default)}on(Cn);var wn=function(e){function t(t){var n=e.call(this)||this;return n.indexPath_=t,(0,r.assert)(!mt(t)&&".priority"!==ht(t),"Can't create PathIndex with empty path or .priority key"),n}return(0,i.__extends)(t,e),t.prototype.extractChild=function(e){return e.getChild(this.indexPath_)},t.prototype.isDefinedOn=function(e){return!e.getChild(this.indexPath_).isEmpty()},t.prototype.compare=function(e,t){var n=this.extractChild(e.node),r=this.extractChild(t.node),i=n.compareTo(r);return 0===i?D(e.name,t.name):i},t.prototype.makePost=function(e,t){var n=Cn(e),r=vn.EMPTY_NODE.updateChild(this.indexPath_,n);return new Ut(t,r)},t.prototype.maxPost=function(){var e=vn.EMPTY_NODE.updateChild(this.indexPath_,gn);return new Ut(A,e)},t.prototype.toString=function(){return vt(this.indexPath_,0).join("/")},t}(Bt),bn=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return(0,i.__extends)(t,e),t.prototype.compare=function(e,t){var n=e.node.compareTo(t.node);return 0===n?D(e.name,t.name):n},t.prototype.isDefinedOn=function(e){return!0},t.prototype.indexedValueChanged=function(e,t){return!e.equals(t)},t.prototype.minPost=function(){return Ut.MIN},t.prototype.maxPost=function(){return Ut.MAX},t.prototype.makePost=function(e,t){var n=Cn(e);return new Ut(t,n)},t.prototype.toString=function(){return".value"},t}(Bt),Tn=new bn,kn="-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz",In="-",En="z",Sn=786,Pn=function(){var e=0,t=[];return function(n){var i,o=n===e;e=n;var a=new Array(8);for(i=7;i>=0;i--)a[i]=kn.charAt(n%64),n=Math.floor(n/64);(0,r.assert)(0===n,"Cannot push at time == 0");var s=a.join("");if(o){for(i=11;i>=0&&63===t[i];i--)t[i]=0;t[i]++}else for(i=0;i<12;i++)t[i]=Math.floor(64*Math.random());for(i=0;i<12;i++)s+=kn.charAt(t[i]);return(0,r.assert)(20===s.length,"nextPushId: Length should be 20."),s}}(),xn=function(e){if(e===""+H)return In;var t=z(e);if(null!=t)return""+(t+1);for(var n=new Array(e.length),r=0;r<n.length;r++)n[r]=e.charAt(r);if(n.length<Sn)return n.push(In),n.join("");for(var i=n.length-1;i>=0&&n[i]===En;)i--;if(-1===i)return A;var o=n[i],a=kn.charAt(kn.indexOf(o)+1);return n[i]=a,n.slice(0,i+1).join("")},Nn=function(e){if(e===""+Q)return R;var t=z(e);if(null!=t)return""+(t-1);for(var n=new Array(e.length),r=0;r<n.length;r++)n[r]=e.charAt(r);return n[n.length-1]===In?1===n.length?""+H:(delete n[n.length-1],n.join("")):(n[n.length-1]=kn.charAt(kn.indexOf(n[n.length-1])-1),n.join("")+En.repeat(Sn-n.length))};function Rn(e){return{type:"value",snapshotNode:e}}function An(e,t){return{type:"child_added",snapshotNode:t,childName:e}}function Dn(e,t){return{type:"child_removed",snapshotNode:t,childName:e}}function On(e,t,n){return{type:"child_changed",snapshotNode:t,childName:e,oldSnap:n}}function Mn(e,t){return{type:"child_moved",snapshotNode:t,childName:e}}var qn=function(){function e(e){this.index_=e}return e.prototype.updateChild=function(e,t,n,i,o,a){(0,r.assert)(e.isIndexed(this.index_),"A node must be indexed if only a child is updated");var s=e.getImmediateChild(t);return s.getChild(i).equals(n.getChild(i))&&s.isEmpty()===n.isEmpty()?e:(null!=a&&(n.isEmpty()?e.hasChild(t)?a.trackChildChange(Dn(t,s)):(0,r.assert)(e.isLeafNode(),"A child remove without an old child only makes sense on a leaf node"):s.isEmpty()?a.trackChildChange(An(t,n)):a.trackChildChange(On(t,n,s))),e.isLeafNode()&&n.isEmpty()?e:e.updateImmediateChild(t,n).withIndex(this.index_))},e.prototype.updateFullNode=function(e,t,n){return null!=n&&(e.isLeafNode()||e.forEachChild(cn,function(e,r){t.hasChild(e)||n.trackChildChange(Dn(e,r))}),t.isLeafNode()||t.forEachChild(cn,function(t,r){if(e.hasChild(t)){var i=e.getImmediateChild(t);i.equals(r)||n.trackChildChange(On(t,r,i))}else n.trackChildChange(An(t,r))})),t.withIndex(this.index_)},e.prototype.updatePriority=function(e,t){return e.isEmpty()?vn.EMPTY_NODE:e.updatePriority(t)},e.prototype.filtersNodes=function(){return!1},e.prototype.getIndexedFilter=function(){return this},e.prototype.getIndex=function(){return this.index_},e}(),Fn=function(){function e(t){this.indexedFilter_=new qn(t.getIndex()),this.index_=t.getIndex(),this.startPost_=e.getStartPost_(t),this.endPost_=e.getEndPost_(t)}return e.prototype.getStartPost=function(){return this.startPost_},e.prototype.getEndPost=function(){return this.endPost_},e.prototype.matches=function(e){return this.index_.compare(this.getStartPost(),e)<=0&&this.index_.compare(e,this.getEndPost())<=0},e.prototype.updateChild=function(e,t,n,r,i,o){return this.matches(new Ut(t,n))||(n=vn.EMPTY_NODE),this.indexedFilter_.updateChild(e,t,n,r,i,o)},e.prototype.updateFullNode=function(e,t,n){t.isLeafNode()&&(t=vn.EMPTY_NODE);var r=t.withIndex(this.index_);r=r.updatePriority(vn.EMPTY_NODE);var i=this;return t.forEachChild(cn,function(e,t){i.matches(new Ut(e,t))||(r=r.updateImmediateChild(e,vn.EMPTY_NODE))}),this.indexedFilter_.updateFullNode(e,r,n)},e.prototype.updatePriority=function(e,t){return e},e.prototype.filtersNodes=function(){return!0},e.prototype.getIndexedFilter=function(){return this.indexedFilter_},e.prototype.getIndex=function(){return this.index_},e.getStartPost_=function(e){if(e.hasStart()){var t=e.getIndexStartName();return e.getIndex().makePost(e.getIndexStartValue(),t)}return e.getIndex().minPost()},e.getEndPost_=function(e){if(e.hasEnd()){var t=e.getIndexEndName();return e.getIndex().makePost(e.getIndexEndValue(),t)}return e.getIndex().maxPost()},e}(),Ln=function(){function e(e){this.rangedFilter_=new Fn(e),this.index_=e.getIndex(),this.limit_=e.getLimit(),this.reverse_=!e.isViewFromLeft()}return e.prototype.updateChild=function(e,t,n,r,i,o){return this.rangedFilter_.matches(new Ut(t,n))||(n=vn.EMPTY_NODE),e.getImmediateChild(t).equals(n)?e:e.numChildren()<this.limit_?this.rangedFilter_.getIndexedFilter().updateChild(e,t,n,r,i,o):this.fullLimitUpdateChild_(e,t,n,i,o)},e.prototype.updateFullNode=function(e,t,n){var r;if(t.isLeafNode()||t.isEmpty())r=vn.EMPTY_NODE.withIndex(this.index_);else if(2*this.limit_<t.numChildren()&&t.isIndexed(this.index_)){r=vn.EMPTY_NODE.withIndex(this.index_);var i=void 0;i=this.reverse_?t.getReverseIteratorFrom(this.rangedFilter_.getEndPost(),this.index_):t.getIteratorFrom(this.rangedFilter_.getStartPost(),this.index_);for(var o=0;i.hasNext()&&o<this.limit_;){var a=i.getNext();if(!(this.reverse_?this.index_.compare(this.rangedFilter_.getStartPost(),a)<=0:this.index_.compare(a,this.rangedFilter_.getEndPost())<=0))break;r=r.updateImmediateChild(a.name,a.node),o++}}else{r=(r=t.withIndex(this.index_)).updatePriority(vn.EMPTY_NODE);var s=void 0,u=void 0,l=void 0;i=void 0;if(this.reverse_){i=r.getReverseIterator(this.index_),s=this.rangedFilter_.getEndPost(),u=this.rangedFilter_.getStartPost();var c=this.index_.getCompare();l=function(e,t){return c(t,e)}}else i=r.getIterator(this.index_),s=this.rangedFilter_.getStartPost(),u=this.rangedFilter_.getEndPost(),l=this.index_.getCompare();o=0;for(var h=!1;i.hasNext();){a=i.getNext();!h&&l(s,a)<=0&&(h=!0),h&&o<this.limit_&&l(a,u)<=0?o++:r=r.updateImmediateChild(a.name,vn.EMPTY_NODE)}}return this.rangedFilter_.getIndexedFilter().updateFullNode(e,r,n)},e.prototype.updatePriority=function(e,t){return e},e.prototype.filtersNodes=function(){return!0},e.prototype.getIndexedFilter=function(){return this.rangedFilter_.getIndexedFilter()},e.prototype.getIndex=function(){return this.index_},e.prototype.fullLimitUpdateChild_=function(e,t,n,i,o){var a;if(this.reverse_){var s=this.index_.getCompare();a=function(e,t){return s(t,e)}}else a=this.index_.getCompare();var u=e;(0,r.assert)(u.numChildren()===this.limit_,"");var l=new Ut(t,n),c=this.reverse_?u.getFirstChild(this.index_):u.getLastChild(this.index_),h=this.rangedFilter_.matches(l);if(u.hasChild(t)){for(var d=u.getImmediateChild(t),p=i.getChildAfterChild(this.index_,c,this.reverse_);null!=p&&(p.name===t||u.hasChild(p.name));)p=i.getChildAfterChild(this.index_,p,this.reverse_);var f=null==p?1:a(p,l);if(h&&!n.isEmpty()&&f>=0)return null!=o&&o.trackChildChange(On(t,n,d)),u.updateImmediateChild(t,n);null!=o&&o.trackChildChange(Dn(t,d));var _=u.updateImmediateChild(t,vn.EMPTY_NODE);return null!=p&&this.rangedFilter_.matches(p)?(null!=o&&o.trackChildChange(An(p.name,p.node)),_.updateImmediateChild(p.name,p.node)):_}return n.isEmpty()?e:h&&a(c,l)>=0?(null!=o&&(o.trackChildChange(Dn(c.name,c.node)),o.trackChildChange(An(t,n))),u.updateImmediateChild(t,n).updateImmediateChild(c.name,vn.EMPTY_NODE)):e},e}(),Wn=function(){function e(){this.limitSet_=!1,this.startSet_=!1,this.startNameSet_=!1,this.startAfterSet_=!1,this.endSet_=!1,this.endNameSet_=!1,this.endBeforeSet_=!1,this.limit_=0,this.viewFrom_="",this.indexStartValue_=null,this.indexStartName_="",this.indexEndValue_=null,this.indexEndName_="",this.index_=cn}return e.prototype.hasStart=function(){return this.startSet_},e.prototype.hasStartAfter=function(){return this.startAfterSet_},e.prototype.hasEndBefore=function(){return this.endBeforeSet_},e.prototype.isViewFromLeft=function(){return""===this.viewFrom_?this.startSet_:"l"===this.viewFrom_},e.prototype.getIndexStartValue=function(){return(0,r.assert)(this.startSet_,"Only valid if start has been set"),this.indexStartValue_},e.prototype.getIndexStartName=function(){return(0,r.assert)(this.startSet_,"Only valid if start has been set"),this.startNameSet_?this.indexStartName_:R},e.prototype.hasEnd=function(){return this.endSet_},e.prototype.getIndexEndValue=function(){return(0,r.assert)(this.endSet_,"Only valid if end has been set"),this.indexEndValue_},e.prototype.getIndexEndName=function(){return(0,r.assert)(this.endSet_,"Only valid if end has been set"),this.endNameSet_?this.indexEndName_:A},e.prototype.hasLimit=function(){return this.limitSet_},e.prototype.hasAnchoredLimit=function(){return this.limitSet_&&""!==this.viewFrom_},e.prototype.getLimit=function(){return(0,r.assert)(this.limitSet_,"Only valid if limit has been set"),this.limit_},e.prototype.getIndex=function(){return this.index_},e.prototype.loadsAllData=function(){return!(this.startSet_||this.endSet_||this.limitSet_)},e.prototype.isDefault=function(){return this.loadsAllData()&&this.index_===cn},e.prototype.copy=function(){var t=new e;return t.limitSet_=this.limitSet_,t.limit_=this.limit_,t.startSet_=this.startSet_,t.indexStartValue_=this.indexStartValue_,t.startNameSet_=this.startNameSet_,t.indexStartName_=this.indexStartName_,t.endSet_=this.endSet_,t.indexEndValue_=this.indexEndValue_,t.endNameSet_=this.endNameSet_,t.indexEndName_=this.indexEndName_,t.index_=this.index_,t.viewFrom_=this.viewFrom_,t},e}();function jn(e){return e.loadsAllData()?new qn(e.getIndex()):e.hasLimit()?new Ln(e):new Fn(e)}function Un(e,t){var n=e.copy();return n.limitSet_=!0,n.limit_=t,n.viewFrom_="l",n}function Bn(e,t){var n=e.copy();return n.limitSet_=!0,n.limit_=t,n.viewFrom_="r",n}function Vn(e,t,n){var r=e.copy();return r.startSet_=!0,void 0===t&&(t=null),r.indexStartValue_=t,null!=n?(r.startNameSet_=!0,r.indexStartName_=n):(r.startNameSet_=!1,r.indexStartName_=""),r}function Qn(e,t,n){var r;if(e.index_===Qt)"string"==typeof t&&(t=xn(t)),r=Vn(e,t,n);else{r=Vn(e,t,null==n?A:xn(n))}return r.startAfterSet_=!0,r}function Hn(e,t,n){var r=e.copy();return r.endSet_=!0,void 0===t&&(t=null),r.indexEndValue_=t,void 0!==n?(r.endNameSet_=!0,r.indexEndName_=n):(r.endNameSet_=!1,r.indexEndName_=""),r}function zn(e,t,n){var r;return e.index_===Qt?("string"==typeof t&&(t=Nn(t)),r=Hn(e,t,n)):r=Hn(e,t,null==n?R:Nn(n)),r.endBeforeSet_=!0,r}function Yn(e,t){var n=e.copy();return n.index_=t,n}function Kn(e){var t,n={};return e.isDefault()?n:(e.index_===cn?t="$priority":e.index_===Tn?t="$value":e.index_===Qt?t="$key":((0,r.assert)(e.index_ instanceof wn,"Unrecognized index type!"),t=e.index_.toString()),n.orderBy=(0,r.stringify)(t),e.startSet_&&(n.startAt=(0,r.stringify)(e.indexStartValue_),e.startNameSet_&&(n.startAt+=","+(0,r.stringify)(e.indexStartName_))),e.endSet_&&(n.endAt=(0,r.stringify)(e.indexEndValue_),e.endNameSet_&&(n.endAt+=","+(0,r.stringify)(e.indexEndName_))),e.limitSet_&&(e.isViewFromLeft()?n.limitToFirst=e.limit_:n.limitToLast=e.limit_),n)}function Gn(e){var t={};if(e.startSet_&&(t.sp=e.indexStartValue_,e.startNameSet_&&(t.sn=e.indexStartName_)),e.endSet_&&(t.ep=e.indexEndValue_,e.endNameSet_&&(t.en=e.indexEndName_)),e.limitSet_){t.l=e.limit_;var n=e.viewFrom_;""===n&&(n=e.isViewFromLeft()?"l":"r"),t.vf=n}return e.index_!==cn&&(t.i=e.index_.toString()),t}var $n=function(e){function t(t,n,r,i){var o=e.call(this)||this;return o.repoInfo_=t,o.onDataUpdate_=n,o.authTokenProvider_=r,o.appCheckTokenProvider_=i,o.log_=k("p:rest:"),o.listens_={},o}return(0,i.__extends)(t,e),t.prototype.reportStats=function(e){throw new Error("Method not implemented.")},t.getListenId_=function(e,t){return void 0!==t?"tag$"+t:((0,r.assert)(e._queryParams.isDefault(),"should have a tag if it's not a default query."),e._path.toString())},t.prototype.listen=function(e,n,i,o){var a=this,s=e._path.toString();this.log_("Listen called for "+s+" "+e._queryIdentifier);var u=t.getListenId_(e,i),l={};this.listens_[u]=l;var c=Kn(e._queryParams);this.restRequest_(s+".json",c,function(e,t){var n=t;(404===e&&(n=null,e=null),null===e&&a.onDataUpdate_(s,n,!1,i),(0,r.safeGet)(a.listens_,u)===l)&&o(e?401===e?"permission_denied":"rest_error:"+e:"ok",null)})},t.prototype.unlisten=function(e,n){var r=t.getListenId_(e,n);delete this.listens_[r]},t.prototype.get=function(e){var t=this,n=Kn(e._queryParams),i=e._path.toString(),o=new r.Deferred;return this.restRequest_(i+".json",n,function(e,n){var r=n;404===e&&(r=null,e=null),null===e?(t.onDataUpdate_(i,r,!1,null),o.resolve(r)):o.reject(new Error(r))}),o.promise},t.prototype.refreshAuthToken=function(e){},t.prototype.restRequest_=function(e,t,n){var o=this;return void 0===t&&(t={}),t.format="export",Promise.all([this.authTokenProvider_.getToken(!1),this.appCheckTokenProvider_.getToken(!1)]).then(function(a){var s=(0,i.__read)(a,2),u=s[0],l=s[1];u&&u.accessToken&&(t.auth=u.accessToken),l&&l.token&&(t.ac=l.token);var c=(o.repoInfo_.secure?"https://":"http://")+o.repoInfo_.host+e+"?ns="+o.repoInfo_.namespace+(0,r.querystring)(t);o.log_("Sending REST request for "+c);var h=new XMLHttpRequest;h.onreadystatechange=function(){if(n&&4===h.readyState){o.log_("REST Response for "+c+" received. status:",h.status,"response:",h.responseText);var e=null;if(h.status>=200&&h.status<300){try{e=(0,r.jsonEval)(h.responseText)}catch(t){S("Failed to parse JSON response for "+c+": "+h.responseText)}n(null,e)}else 401!==h.status&&404!==h.status&&S("Got unsuccessful REST response for "+c+" Status: "+h.status),n(h.status);n=null}},h.open("GET",c,!0),h.send()})},t}(it),Jn=function(){function e(){this.rootNode_=vn.EMPTY_NODE}return e.prototype.getNode=function(e){return this.rootNode_.getChild(e)},e.prototype.updateSnapshot=function(e,t){this.rootNode_=this.rootNode_.updateChild(e,t)},e}();function Xn(){return{value:null,children:new Map}}function Zn(e,t,n){if(mt(t))e.value=n,e.children.clear();else if(null!==e.value)e.value=e.value.updateChild(t,n);else{var r=ht(t);e.children.has(r)||e.children.set(r,Xn()),Zn(e.children.get(r),t=pt(t),n)}}function er(e,t){if(mt(t))return e.value=null,e.children.clear(),!0;if(null!==e.value){if(e.value.isLeafNode())return!1;var n=e.value;return e.value=null,n.forEachChild(cn,function(t,n){Zn(e,new lt(t),n)}),er(e,t)}if(e.children.size>0){var r=ht(t);if(t=pt(t),e.children.has(r))er(e.children.get(r),t)&&e.children.delete(r);return 0===e.children.size}return!0}function tr(e,t,n){null!==e.value?n(t,e.value):nr(e,function(e,r){tr(r,new lt(t.toString()+"/"+e),n)})}function nr(e,t){e.children.forEach(function(e,n){t(n,e)})}var rr,ir=function(){function e(e){this.collection_=e,this.last_=null}return e.prototype.get=function(){var e=this.collection_.get(),t=(0,i.__assign)({},e);return this.last_&&L(this.last_,function(e,n){t[e]=t[e]-n}),this.last_=e,t},e}(),or=1e4,ar=3e4,sr=3e5,ur=function(){function e(e,t){this.server_=t,this.statsToReport_={},this.statsListener_=new ir(e);var n=or+(ar-or)*Math.random();G(this.reportStats_.bind(this),Math.floor(n))}return e.prototype.reportStats_=function(){var e=this,t=this.statsListener_.get(),n={},i=!1;L(t,function(t,o){o>0&&(0,r.contains)(e.statsToReport_,t)&&(n[t]=o,i=!0)}),i&&this.server_.reportStats(n),G(this.reportStats_.bind(this),Math.floor(2*Math.random()*sr))},e}();function lr(e,t){e.statsToReport_[t]=!0}function cr(){return{fromUser:!0,fromServer:!1,queryId:null,tagged:!1}}function hr(){return{fromUser:!1,fromServer:!0,queryId:null,tagged:!1}}function dr(e){return{fromUser:!1,fromServer:!0,queryId:e,tagged:!0}}!function(e){e[e.OVERWRITE=0]="OVERWRITE",e[e.MERGE=1]="MERGE",e[e.ACK_USER_WRITE=2]="ACK_USER_WRITE",e[e.LISTEN_COMPLETE=3]="LISTEN_COMPLETE"}(rr||(rr={}));var pr,fr=function(){function e(e,t,n){this.path=e,this.affectedTree=t,this.revert=n,this.type=rr.ACK_USER_WRITE,this.source=cr()}return e.prototype.operationForChild=function(t){if(mt(this.path)){if(null!=this.affectedTree.value)return(0,r.assert)(this.affectedTree.children.isEmpty(),"affectedTree should not have overlapping affected paths."),this;var n=this.affectedTree.subtree(new lt(t));return new e(ct(),n,this.revert)}return(0,r.assert)(ht(this.path)===t,"operationForChild called for unrelated child."),new e(pt(this.path),this.affectedTree,this.revert)},e}(),_r=function(){function e(e,t){this.source=e,this.path=t,this.type=rr.LISTEN_COMPLETE}return e.prototype.operationForChild=function(t){return mt(this.path)?new e(this.source,ct()):new e(this.source,pt(this.path))},e}(),vr=function(){function e(e,t,n){this.source=e,this.path=t,this.snap=n,this.type=rr.OVERWRITE}return e.prototype.operationForChild=function(t){return mt(this.path)?new e(this.source,ct(),this.snap.getImmediateChild(t)):new e(this.source,pt(this.path),this.snap)},e}(),yr=function(){function e(e,t,n){this.source=e,this.path=t,this.children=n,this.type=rr.MERGE}return e.prototype.operationForChild=function(t){if(mt(this.path)){var n=this.children.subtree(new lt(t));return n.isEmpty()?null:n.value?new vr(this.source,ct(),n.value):new e(this.source,ct(),n)}return(0,r.assert)(ht(this.path)===t,"Can't get a merge for a child not on the path of the operation"),new e(this.source,pt(this.path),this.children)},e.prototype.toString=function(){return"Operation("+this.path+": "+this.source.toString()+" merge: "+this.children.toString()+")"},e}(),gr=function(){function e(e,t,n){this.node_=e,this.fullyInitialized_=t,this.filtered_=n}return e.prototype.isFullyInitialized=function(){return this.fullyInitialized_},e.prototype.isFiltered=function(){return this.filtered_},e.prototype.isCompleteForPath=function(e){if(mt(e))return this.isFullyInitialized()&&!this.filtered_;var t=ht(e);return this.isCompleteForChild(t)},e.prototype.isCompleteForChild=function(e){return this.isFullyInitialized()&&!this.filtered_||this.node_.hasChild(e)},e.prototype.getNode=function(){return this.node_},e}(),mr=function(){return function(e){this.query_=e,this.index_=this.query_._queryParams.getIndex()}}();function Cr(e,t,n,r){var i=[],o=[];return t.forEach(function(t){"child_changed"===t.type&&e.index_.indexedValueChanged(t.oldSnap,t.snapshotNode)&&o.push(Mn(t.childName,t.snapshotNode))}),wr(e,i,"child_removed",t,r,n),wr(e,i,"child_added",t,r,n),wr(e,i,"child_moved",o,r,n),wr(e,i,"child_changed",t,r,n),wr(e,i,"value",t,r,n),i}function wr(e,t,n,r,i,o){var a=r.filter(function(e){return e.type===n});a.sort(function(t,n){return Tr(e,t,n)}),a.forEach(function(n){var r=br(e,n,o);i.forEach(function(i){i.respondsTo(n.type)&&t.push(i.createEvent(r,e.query_))})})}function br(e,t,n){return"value"===t.type||"child_removed"===t.type?t:(t.prevName=n.getPredecessorChildName(t.childName,t.snapshotNode,e.index_),t)}function Tr(e,t,n){if(null==t.childName||null==n.childName)throw(0,r.assertionError)("Should only compare child_ events.");var i=new Ut(t.childName,t.snapshotNode),o=new Ut(n.childName,n.snapshotNode);return e.index_.compare(i,o)}function kr(e,t){return{eventCache:e,serverCache:t}}function Ir(e,t,n,r){return kr(new gr(t,n,r),e.serverCache)}function Er(e,t,n,r){return kr(e.eventCache,new gr(t,n,r))}function Sr(e){return e.eventCache.isFullyInitialized()?e.eventCache.getNode():null}function Pr(e){return e.serverCache.isFullyInitialized()?e.serverCache.getNode():null}var xr=function(){return pr||(pr=new Kt(O)),pr},Nr=function(){function e(e,t){void 0===t&&(t=xr()),this.value=e,this.children=t}return e.fromObject=function(t){var n=new e(null);return L(t,function(e,t){n=n.set(new lt(e),t)}),n},e.prototype.isEmpty=function(){return null===this.value&&this.children.isEmpty()},e.prototype.findRootMostMatchingPathAndValue=function(e,t){if(null!=this.value&&t(this.value))return{path:ct(),value:this.value};if(mt(e))return null;var n=ht(e),r=this.children.get(n);if(null!==r){var i=r.findRootMostMatchingPathAndValue(pt(e),t);return null!=i?{path:gt(new lt(n),i.path),value:i.value}:null}return null},e.prototype.findRootMostValueAndPath=function(e){return this.findRootMostMatchingPathAndValue(e,function(){return!0})},e.prototype.subtree=function(t){if(mt(t))return this;var n=ht(t),r=this.children.get(n);return null!==r?r.subtree(pt(t)):new e(null)},e.prototype.set=function(t,n){if(mt(t))return new e(n,this.children);var r=ht(t),i=(this.children.get(r)||new e(null)).set(pt(t),n),o=this.children.insert(r,i);return new e(this.value,o)},e.prototype.remove=function(t){if(mt(t))return this.children.isEmpty()?new e(null):new e(null,this.children);var n=ht(t),r=this.children.get(n);if(r){var i=r.remove(pt(t)),o=void 0;return o=i.isEmpty()?this.children.remove(n):this.children.insert(n,i),null===this.value&&o.isEmpty()?new e(null):new e(this.value,o)}return this},e.prototype.get=function(e){if(mt(e))return this.value;var t=ht(e),n=this.children.get(t);return n?n.get(pt(e)):null},e.prototype.setTree=function(t,n){if(mt(t))return n;var r=ht(t),i=(this.children.get(r)||new e(null)).setTree(pt(t),n),o=void 0;return o=i.isEmpty()?this.children.remove(r):this.children.insert(r,i),new e(this.value,o)},e.prototype.fold=function(e){return this.fold_(ct(),e)},e.prototype.fold_=function(e,t){var n={};return this.children.inorderTraversal(function(r,i){n[r]=i.fold_(gt(e,r),t)}),t(e,this.value,n)},e.prototype.findOnPath=function(e,t){return this.findOnPath_(e,ct(),t)},e.prototype.findOnPath_=function(e,t,n){var r=!!this.value&&n(t,this.value);if(r)return r;if(mt(e))return null;var i=ht(e),o=this.children.get(i);return o?o.findOnPath_(pt(e),gt(t,i),n):null},e.prototype.foreachOnPath=function(e,t){return this.foreachOnPath_(e,ct(),t)},e.prototype.foreachOnPath_=function(t,n,r){if(mt(t))return this;this.value&&r(n,this.value);var i=ht(t),o=this.children.get(i);return o?o.foreachOnPath_(pt(t),gt(n,i),r):new e(null)},e.prototype.foreach=function(e){this.foreach_(ct(),e)},e.prototype.foreach_=function(e,t){this.children.inorderTraversal(function(n,r){r.foreach_(gt(e,n),t)}),this.value&&t(e,this.value)},e.prototype.foreachChild=function(e){this.children.inorderTraversal(function(t,n){n.value&&e(t,n.value)})},e}(),Rr=function(){function e(e){this.writeTree_=e}return e.empty=function(){return new e(new Nr(null))},e}();function Ar(e,t,n){if(mt(t))return new Rr(new Nr(n));var r=e.writeTree_.findRootMostValueAndPath(t);if(null!=r){var i=r.path,o=r.value,a=Ct(i,t);return o=o.updateChild(a,n),new Rr(e.writeTree_.set(i,o))}var s=new Nr(n),u=e.writeTree_.setTree(t,s);return new Rr(u)}function Dr(e,t,n){var r=e;return L(n,function(e,n){r=Ar(r,gt(t,e),n)}),r}function Or(e,t){if(mt(t))return Rr.empty();var n=e.writeTree_.setTree(t,new Nr(null));return new Rr(n)}function Mr(e,t){return null!=qr(e,t)}function qr(e,t){var n=e.writeTree_.findRootMostValueAndPath(t);return null!=n?e.writeTree_.get(n.path).getChild(Ct(n.path,t)):null}function Fr(e){var t=[],n=e.writeTree_.value;return null!=n?n.isLeafNode()||n.forEachChild(cn,function(e,n){t.push(new Ut(e,n))}):e.writeTree_.children.inorderTraversal(function(e,n){null!=n.value&&t.push(new Ut(e,n.value))}),t}function Lr(e,t){if(mt(t))return e;var n=qr(e,t);return new Rr(null!=n?new Nr(n):e.writeTree_.subtree(t))}function Wr(e){return e.writeTree_.isEmpty()}function jr(e,t){return Ur(ct(),e.writeTree_,t)}function Ur(e,t,n){if(null!=t.value)return n.updateChild(e,t.value);var i=null;return t.children.inorderTraversal(function(t,o){".priority"===t?((0,r.assert)(null!==o.value,"Priority writes must always be leaf nodes"),i=o.value):n=Ur(gt(e,t),o,n)}),n.getChild(e).isEmpty()||null===i||(n=n.updateChild(gt(e,".priority"),i)),n}function Br(e,t){return hi(t,e)}function Vr(e,t,n,i,o){(0,r.assert)(i>e.lastWriteId,"Stacking an older write on top of newer ones"),void 0===o&&(o=!0),e.allWrites.push({path:t,snap:n,writeId:i,visible:o}),o&&(e.visibleWrites=Ar(e.visibleWrites,t,n)),e.lastWriteId=i}function Qr(e,t,n,i){(0,r.assert)(i>e.lastWriteId,"Stacking an older merge on top of newer ones"),e.allWrites.push({path:t,children:n,writeId:i,visible:!0}),e.visibleWrites=Dr(e.visibleWrites,t,n),e.lastWriteId=i}function Hr(e,t){for(var n=0;n<e.allWrites.length;n++){var r=e.allWrites[n];if(r.writeId===t)return r}return null}function zr(e,t){var n=e.allWrites.findIndex(function(e){return e.writeId===t});(0,r.assert)(n>=0,"removeWrite called with nonexistent writeId.");var i=e.allWrites[n];e.allWrites.splice(n,1);for(var o=i.visible,a=!1,s=e.allWrites.length-1;o&&s>=0;){var u=e.allWrites[s];u.visible&&(s>=n&&Yr(u,i.path)?o=!1:Tt(i.path,u.path)&&(a=!0)),s--}if(o){if(a)return Kr(e),!0;i.snap?e.visibleWrites=Or(e.visibleWrites,i.path):L(i.children,function(t){e.visibleWrites=Or(e.visibleWrites,gt(i.path,t))});return!0}return!1}function Yr(e,t){if(e.snap)return Tt(e.path,t);for(var n in e.children)if(e.children.hasOwnProperty(n)&&Tt(gt(e.path,n),t))return!0;return!1}function Kr(e){e.visibleWrites=$r(e.allWrites,Gr,ct()),e.allWrites.length>0?e.lastWriteId=e.allWrites[e.allWrites.length-1].writeId:e.lastWriteId=-1}function Gr(e){return e.visible}function $r(e,t,n){for(var i=Rr.empty(),o=0;o<e.length;++o){var a=e[o];if(t(a)){var s=a.path,u=void 0;if(a.snap)Tt(n,s)?i=Ar(i,u=Ct(n,s),a.snap):Tt(s,n)&&(u=Ct(s,n),i=Ar(i,ct(),a.snap.getChild(u)));else{if(!a.children)throw(0,r.assertionError)("WriteRecord should have .snap or .children");if(Tt(n,s))i=Dr(i,u=Ct(n,s),a.children);else if(Tt(s,n))if(mt(u=Ct(s,n)))i=Dr(i,ct(),a.children);else{var l=(0,r.safeGet)(a.children,ht(u));if(l){var c=l.getChild(pt(u));i=Ar(i,ct(),c)}}}}}return i}function Jr(e,t,n,r,i){if(r||i){var o=Lr(e.visibleWrites,t);if(!i&&Wr(o))return n;if(i||null!=n||Mr(o,ct())){return jr($r(e.allWrites,function(e){return(e.visible||i)&&(!r||!~r.indexOf(e.writeId))&&(Tt(e.path,t)||Tt(t,e.path))},t),n||vn.EMPTY_NODE)}return null}var a=qr(e.visibleWrites,t);if(null!=a)return a;var s=Lr(e.visibleWrites,t);return Wr(s)?n:null!=n||Mr(s,ct())?jr(s,n||vn.EMPTY_NODE):null}function Xr(e,t,n){var r=vn.EMPTY_NODE,i=qr(e.visibleWrites,t);if(i)return i.isLeafNode()||i.forEachChild(cn,function(e,t){r=r.updateImmediateChild(e,t)}),r;if(n){var o=Lr(e.visibleWrites,t);return n.forEachChild(cn,function(e,t){var n=jr(Lr(o,new lt(e)),t);r=r.updateImmediateChild(e,n)}),Fr(o).forEach(function(e){r=r.updateImmediateChild(e.name,e.node)}),r}return Fr(Lr(e.visibleWrites,t)).forEach(function(e){r=r.updateImmediateChild(e.name,e.node)}),r}function Zr(e,t,n,i,o){(0,r.assert)(i||o,"Either existingEventSnap or existingServerSnap must exist");var a=gt(t,n);if(Mr(e.visibleWrites,a))return null;var s=Lr(e.visibleWrites,a);return Wr(s)?o.getChild(n):jr(s,o.getChild(n))}function ei(e,t,n,r){var i=gt(t,n),o=qr(e.visibleWrites,i);return null!=o?o:r.isCompleteForChild(n)?jr(Lr(e.visibleWrites,i),r.getNode().getImmediateChild(n)):null}function ti(e,t){return qr(e.visibleWrites,t)}function ni(e,t,n,r,i,o,a){var s,u=Lr(e.visibleWrites,t),l=qr(u,ct());if(null!=l)s=l;else{if(null==n)return[];s=jr(u,n)}if((s=s.withIndex(a)).isEmpty()||s.isLeafNode())return[];for(var c=[],h=a.getCompare(),d=o?s.getReverseIteratorFrom(r,a):s.getIteratorFrom(r,a),p=d.getNext();p&&c.length<i;)0!==h(p,r)&&c.push(p),p=d.getNext();return c}function ri(){return{visibleWrites:Rr.empty(),allWrites:[],lastWriteId:-1}}function ii(e,t,n,r){return Jr(e.writeTree,e.treePath,t,n,r)}function oi(e,t){return Xr(e.writeTree,e.treePath,t)}function ai(e,t,n,r){return Zr(e.writeTree,e.treePath,t,n,r)}function si(e,t){return ti(e.writeTree,gt(e.treePath,t))}function ui(e,t,n,r,i,o){return ni(e.writeTree,e.treePath,t,n,r,i,o)}function li(e,t,n){return ei(e.writeTree,e.treePath,t,n)}function ci(e,t){return hi(gt(e.treePath,t),e.writeTree)}function hi(e,t){return{treePath:e,writeTree:t}}var di=function(){function e(){this.changeMap=new Map}return e.prototype.trackChildChange=function(e){var t=e.type,n=e.childName;(0,r.assert)("child_added"===t||"child_changed"===t||"child_removed"===t,"Only child changes supported for tracking"),(0,r.assert)(".priority"!==n,"Only non-priority child changes can be tracked.");var i=this.changeMap.get(n);if(i){var o=i.type;if("child_added"===t&&"child_removed"===o)this.changeMap.set(n,On(n,e.snapshotNode,i.snapshotNode));else if("child_removed"===t&&"child_added"===o)this.changeMap.delete(n);else if("child_removed"===t&&"child_changed"===o)this.changeMap.set(n,Dn(n,i.oldSnap));else if("child_changed"===t&&"child_added"===o)this.changeMap.set(n,An(n,e.snapshotNode));else{if("child_changed"!==t||"child_changed"!==o)throw(0,r.assertionError)("Illegal combination of changes: "+e+" occurred after "+i);this.changeMap.set(n,On(n,e.snapshotNode,i.oldSnap))}}else this.changeMap.set(n,e)},e.prototype.getChanges=function(){return Array.from(this.changeMap.values())},e}(),pi=function(){function e(){}return e.prototype.getCompleteChild=function(e){return null},e.prototype.getChildAfterChild=function(e,t,n){return null},e}(),fi=new pi,_i=function(){function e(e,t,n){void 0===n&&(n=null),this.writes_=e,this.viewCache_=t,this.optCompleteServerCache_=n}return e.prototype.getCompleteChild=function(e){var t=this.viewCache_.eventCache;if(t.isCompleteForChild(e))return t.getNode().getImmediateChild(e);var n=null!=this.optCompleteServerCache_?new gr(this.optCompleteServerCache_,!0,!1):this.viewCache_.serverCache;return li(this.writes_,e,n)},e.prototype.getChildAfterChild=function(e,t,n){var r=null!=this.optCompleteServerCache_?this.optCompleteServerCache_:Pr(this.viewCache_),i=ui(this.writes_,r,t,1,n,e);return 0===i.length?null:i[0]},e}();function vi(e){return{filter:e}}function yi(e,t){(0,r.assert)(t.eventCache.getNode().isIndexed(e.filter.getIndex()),"Event snap not indexed"),(0,r.assert)(t.serverCache.getNode().isIndexed(e.filter.getIndex()),"Server snap not indexed")}function gi(e,t,n,i,o){var a,s,u=new di;if(n.type===rr.OVERWRITE){var l=n;l.source.fromUser?a=bi(e,t,l.path,l.snap,i,o,u):((0,r.assert)(l.source.fromServer,"Unknown source."),s=l.source.tagged||t.serverCache.isFiltered()&&!mt(l.path),a=wi(e,t,l.path,l.snap,i,o,s,u))}else if(n.type===rr.MERGE){var c=n;c.source.fromUser?a=ki(e,t,c.path,c.children,i,o,u):((0,r.assert)(c.source.fromServer,"Unknown source."),s=c.source.tagged||t.serverCache.isFiltered(),a=Ei(e,t,c.path,c.children,i,o,s,u))}else if(n.type===rr.ACK_USER_WRITE){var h=n;a=h.revert?xi(e,t,h.path,i,o,u):Si(e,t,h.path,h.affectedTree,i,o,u)}else{if(n.type!==rr.LISTEN_COMPLETE)throw(0,r.assertionError)("Unknown operation type: "+n.type);a=Pi(e,t,n.path,i,u)}var d=u.getChanges();return mi(t,a,d),{viewCache:a,changes:d}}function mi(e,t,n){var r=t.eventCache;if(r.isFullyInitialized()){var i=r.getNode().isLeafNode()||r.getNode().isEmpty(),o=Sr(e);(n.length>0||!e.eventCache.isFullyInitialized()||i&&!r.getNode().equals(o)||!r.getNode().getPriority().equals(o.getPriority()))&&n.push(Rn(Sr(t)))}}function Ci(e,t,n,i,o,a){var s=t.eventCache;if(null!=si(i,n))return t;var u=void 0,l=void 0;if(mt(n))if((0,r.assert)(t.serverCache.isFullyInitialized(),"If change path is empty, we must have complete server data"),t.serverCache.isFiltered()){var c=Pr(t),h=oi(i,c instanceof vn?c:vn.EMPTY_NODE);u=e.filter.updateFullNode(t.eventCache.getNode(),h,a)}else{var d=ii(i,Pr(t));u=e.filter.updateFullNode(t.eventCache.getNode(),d,a)}else{var p=ht(n);if(".priority"===p){(0,r.assert)(1===dt(n),"Can't have a priority with additional path components");var f=s.getNode(),_=ai(i,n,f,l=t.serverCache.getNode());u=null!=_?e.filter.updatePriority(f,_):s.getNode()}else{var v=pt(n),y=void 0;if(s.isCompleteForChild(p)){l=t.serverCache.getNode();var g=ai(i,n,s.getNode(),l);y=null!=g?s.getNode().getImmediateChild(p).updateChild(v,g):s.getNode().getImmediateChild(p)}else y=li(i,p,t.serverCache);u=null!=y?e.filter.updateChild(s.getNode(),p,y,v,o,a):s.getNode()}}return Ir(t,u,s.isFullyInitialized()||mt(n),e.filter.filtersNodes())}function wi(e,t,n,r,i,o,a,s){var u,l=t.serverCache,c=a?e.filter:e.filter.getIndexedFilter();if(mt(n))u=c.updateFullNode(l.getNode(),r,null);else if(c.filtersNodes()&&!l.isFiltered()){var h=l.getNode().updateChild(n,r);u=c.updateFullNode(l.getNode(),h,null)}else{var d=ht(n);if(!l.isCompleteForPath(n)&&dt(n)>1)return t;var p=pt(n),f=l.getNode().getImmediateChild(d).updateChild(p,r);u=".priority"===d?c.updatePriority(l.getNode(),f):c.updateChild(l.getNode(),d,f,p,fi,null)}var _=Er(t,u,l.isFullyInitialized()||mt(n),c.filtersNodes());return Ci(e,_,n,i,new _i(i,_,o),s)}function bi(e,t,n,r,i,o,a){var s,u,l=t.eventCache,c=new _i(i,t,o);if(mt(n))u=e.filter.updateFullNode(t.eventCache.getNode(),r,a),s=Ir(t,u,!0,e.filter.filtersNodes());else{var h=ht(n);if(".priority"===h)u=e.filter.updatePriority(t.eventCache.getNode(),r),s=Ir(t,u,l.isFullyInitialized(),l.isFiltered());else{var d=pt(n),p=l.getNode().getImmediateChild(h),f=void 0;if(mt(d))f=r;else{var _=c.getCompleteChild(h);f=null!=_?".priority"===ft(d)&&_.getChild(yt(d)).isEmpty()?_:_.updateChild(d,r):vn.EMPTY_NODE}if(p.equals(f))s=t;else s=Ir(t,e.filter.updateChild(l.getNode(),h,f,d,c,a),l.isFullyInitialized(),e.filter.filtersNodes())}}return s}function Ti(e,t){return e.eventCache.isCompleteForChild(t)}function ki(e,t,n,r,i,o,a){var s=t;return r.foreach(function(r,u){var l=gt(n,r);Ti(t,ht(l))&&(s=bi(e,s,l,u,i,o,a))}),r.foreach(function(r,u){var l=gt(n,r);Ti(t,ht(l))||(s=bi(e,s,l,u,i,o,a))}),s}function Ii(e,t,n){return n.foreach(function(e,n){t=t.updateChild(e,n)}),t}function Ei(e,t,n,r,i,o,a,s){if(t.serverCache.getNode().isEmpty()&&!t.serverCache.isFullyInitialized())return t;var u,l=t;u=mt(n)?r:new Nr(null).setTree(n,r);var c=t.serverCache.getNode();return u.children.inorderTraversal(function(n,r){if(c.hasChild(n)){var u=t.serverCache.getNode().getImmediateChild(n),h=Ii(e,u,r);l=wi(e,l,new lt(n),h,i,o,a,s)}}),u.children.inorderTraversal(function(n,r){var u=!t.serverCache.isCompleteForChild(n)&&void 0===r.value;if(!c.hasChild(n)&&!u){var h=t.serverCache.getNode().getImmediateChild(n),d=Ii(e,h,r);l=wi(e,l,new lt(n),d,i,o,a,s)}}),l}function Si(e,t,n,r,i,o,a){if(null!=si(i,n))return t;var s=t.serverCache.isFiltered(),u=t.serverCache;if(null!=r.value){if(mt(n)&&u.isFullyInitialized()||u.isCompleteForPath(n))return wi(e,t,n,u.getNode().getChild(n),i,o,s,a);if(mt(n)){var l=new Nr(null);return u.getNode().forEachChild(Qt,function(e,t){l=l.set(new lt(e),t)}),Ei(e,t,n,l,i,o,s,a)}return t}var c=new Nr(null);return r.foreach(function(e,t){var r=gt(n,e);u.isCompleteForPath(r)&&(c=c.set(e,u.getNode().getChild(r)))}),Ei(e,t,n,c,i,o,s,a)}function Pi(e,t,n,r,i){var o=t.serverCache;return Ci(e,Er(t,o.getNode(),o.isFullyInitialized()||mt(n),o.isFiltered()),n,r,fi,i)}function xi(e,t,n,i,o,a){var s;if(null!=si(i,n))return t;var u=new _i(i,t,o),l=t.eventCache.getNode(),c=void 0;if(mt(n)||".priority"===ht(n)){var h=void 0;if(t.serverCache.isFullyInitialized())h=ii(i,Pr(t));else{var d=t.serverCache.getNode();(0,r.assert)(d instanceof vn,"serverChildren would be complete if leaf node"),h=oi(i,d)}h=h,c=e.filter.updateFullNode(l,h,a)}else{var p=ht(n),f=li(i,p,t.serverCache);null==f&&t.serverCache.isCompleteForChild(p)&&(f=l.getImmediateChild(p)),(c=null!=f?e.filter.updateChild(l,p,f,pt(n),u,a):t.eventCache.getNode().hasChild(p)?e.filter.updateChild(l,p,vn.EMPTY_NODE,pt(n),u,a):l).isEmpty()&&t.serverCache.isFullyInitialized()&&(s=ii(i,Pr(t))).isLeafNode()&&(c=e.filter.updateFullNode(c,s,a))}return s=t.serverCache.isFullyInitialized()||null!=si(i,ct()),Ir(t,c,s,e.filter.filtersNodes())}var Ni,Ri=function(){function e(e,t){this.query_=e,this.eventRegistrations_=[];var n=this.query_._queryParams,r=new qn(n.getIndex()),i=jn(n);this.processor_=vi(i);var o=t.serverCache,a=t.eventCache,s=r.updateFullNode(vn.EMPTY_NODE,o.getNode(),null),u=i.updateFullNode(vn.EMPTY_NODE,a.getNode(),null),l=new gr(s,o.isFullyInitialized(),r.filtersNodes()),c=new gr(u,a.isFullyInitialized(),i.filtersNodes());this.viewCache_=kr(c,l),this.eventGenerator_=new mr(this.query_)}return Object.defineProperty(e.prototype,"query",{get:function(){return this.query_},enumerable:!1,configurable:!0}),e}();function Ai(e){return e.viewCache_.serverCache.getNode()}function Di(e){return Sr(e.viewCache_)}function Oi(e,t){var n=Pr(e.viewCache_);return n&&(e.query._queryParams.loadsAllData()||!mt(t)&&!n.getImmediateChild(ht(t)).isEmpty())?n.getChild(t):null}function Mi(e){return 0===e.eventRegistrations_.length}function qi(e,t){e.eventRegistrations_.push(t)}function Fi(e,t,n){var i=[];if(n){(0,r.assert)(null==t,"A cancel should cancel all event registrations.");var o=e.query._path;e.eventRegistrations_.forEach(function(e){var t=e.createCancelEvent(n,o);t&&i.push(t)})}if(t){for(var a=[],s=0;s<e.eventRegistrations_.length;++s){var u=e.eventRegistrations_[s];if(u.matches(t)){if(t.hasAnyCallback()){a=a.concat(e.eventRegistrations_.slice(s+1));break}}else a.push(u)}e.eventRegistrations_=a}else e.eventRegistrations_=[];return i}function Li(e,t,n,i){t.type===rr.MERGE&&null!==t.source.queryId&&((0,r.assert)(Pr(e.viewCache_),"We should always have a full cache before handling merges"),(0,r.assert)(Sr(e.viewCache_),"Missing event cache, even though we have a server cache"));var o=e.viewCache_,a=gi(e.processor_,o,t,n,i);return yi(e.processor_,a.viewCache),(0,r.assert)(a.viewCache.serverCache.isFullyInitialized()||!o.serverCache.isFullyInitialized(),"Once a server snap is complete, it should never go back"),e.viewCache_=a.viewCache,ji(e,a.changes,a.viewCache.eventCache.getNode(),null)}function Wi(e,t){var n=e.viewCache_.eventCache,r=[];n.getNode().isLeafNode()||n.getNode().forEachChild(cn,function(e,t){r.push(An(e,t))});return n.isFullyInitialized()&&r.push(Rn(n.getNode())),ji(e,r,n.getNode(),t)}function ji(e,t,n,r){var i=r?[r]:e.eventRegistrations_;return Cr(e.eventGenerator_,t,n,i)}var Ui,Bi=function(){return function(){this.views=new Map}}();function Vi(e){(0,r.assert)(!Ni,"__referenceConstructor has already been defined"),Ni=e}function Qi(){return(0,r.assert)(Ni,"Reference.ts has not been loaded"),Ni}function Hi(e){return 0===e.views.size}function zi(e,t,n,o){var a,s,u=t.source.queryId;if(null!==u){var l=e.views.get(u);return(0,r.assert)(null!=l,"SyncTree gave us an op for an invalid query."),Li(l,t,n,o)}var c=[];try{for(var h=(0,i.__values)(e.views.values()),d=h.next();!d.done;d=h.next()){l=d.value;c=c.concat(Li(l,t,n,o))}}catch(p){a={error:p}}finally{try{d&&!d.done&&(s=h.return)&&s.call(h)}finally{if(a)throw a.error}}return c}function Yi(e,t,n,r,i){var o=t._queryIdentifier,a=e.views.get(o);if(!a){var s=ii(n,i?r:null),u=!1;s?u=!0:r instanceof vn?(s=oi(n,r),u=!1):(s=vn.EMPTY_NODE,u=!1);var l=kr(new gr(s,u,!1),new gr(r,i,!1));return new Ri(t,l)}return a}function Ki(e,t,n,r,i,o){var a=Yi(e,t,r,i,o);return e.views.has(t._queryIdentifier)||e.views.set(t._queryIdentifier,a),qi(a,n),Wi(a,n)}function Gi(e,t,n,r){var o,a,s=t._queryIdentifier,u=[],l=[],c=eo(e);if("default"===s)try{for(var h=(0,i.__values)(e.views.entries()),d=h.next();!d.done;d=h.next()){var p=(0,i.__read)(d.value,2),f=p[0],_=p[1];l=l.concat(Fi(_,n,r)),Mi(_)&&(e.views.delete(f),_.query._queryParams.loadsAllData()||u.push(_.query))}}catch(v){o={error:v}}finally{try{d&&!d.done&&(a=h.return)&&a.call(h)}finally{if(o)throw o.error}}else(_=e.views.get(s))&&(l=l.concat(Fi(_,n,r)),Mi(_)&&(e.views.delete(s),_.query._queryParams.loadsAllData()||u.push(_.query)));return c&&!eo(e)&&u.push(new(Qi())(t._repo,t._path)),{removed:u,events:l}}function $i(e){var t,n,r=[];try{for(var o=(0,i.__values)(e.views.values()),a=o.next();!a.done;a=o.next()){var s=a.value;s.query._queryParams.loadsAllData()||r.push(s)}}catch(u){t={error:u}}finally{try{a&&!a.done&&(n=o.return)&&n.call(o)}finally{if(t)throw t.error}}return r}function Ji(e,t){var n,r,o=null;try{for(var a=(0,i.__values)(e.views.values()),s=a.next();!s.done;s=a.next()){var u=s.value;o=o||Oi(u,t)}}catch(l){n={error:l}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}return o}function Xi(e,t){if(t._queryParams.loadsAllData())return to(e);var n=t._queryIdentifier;return e.views.get(n)}function Zi(e,t){return null!=Xi(e,t)}function eo(e){return null!=to(e)}function to(e){var t,n;try{for(var r=(0,i.__values)(e.views.values()),o=r.next();!o.done;o=r.next()){var a=o.value;if(a.query._queryParams.loadsAllData())return a}}catch(s){t={error:s}}finally{try{o&&!o.done&&(n=r.return)&&n.call(r)}finally{if(t)throw t.error}}return null}function no(e){(0,r.assert)(!Ui,"__referenceConstructor has already been defined"),Ui=e}function ro(){return(0,r.assert)(Ui,"Reference.ts has not been loaded"),Ui}var io=1,oo=function(){return function(e){this.listenProvider_=e,this.syncPointTree_=new Nr(null),this.pendingWriteTree_=ri(),this.tagToQueryMap=new Map,this.queryToTagMap=new Map}}();function ao(e,t,n,r,i){return Vr(e.pendingWriteTree_,t,n,r,i),i?Co(e,new vr(cr(),t,n)):[]}function so(e,t,n,r){Qr(e.pendingWriteTree_,t,n,r);var i=Nr.fromObject(n);return Co(e,new yr(cr(),t,i))}function uo(e,t,n){void 0===n&&(n=!1);var r=Hr(e.pendingWriteTree_,t);if(zr(e.pendingWriteTree_,t)){var i=new Nr(null);return null!=r.snap?i=i.set(ct(),!0):L(r.children,function(e){i=i.set(new lt(e),!0)}),Co(e,new fr(r.path,i,n))}return[]}function lo(e,t,n){return Co(e,new vr(hr(),t,n))}function co(e,t,n){var r=Nr.fromObject(n);return Co(e,new yr(hr(),t,r))}function ho(e,t){return Co(e,new _r(hr(),t))}function po(e,t,n){var r=Eo(e,n);if(r){var i=So(r),o=i.path,a=i.queryId,s=Ct(o,t);return Po(e,o,new _r(dr(a),s))}return[]}function fo(e,t,n,r){var i=t._path,o=e.syncPointTree_.get(i),a=[];if(o&&("default"===t._queryIdentifier||Zi(o,t))){var s=Gi(o,t,n,r);Hi(o)&&(e.syncPointTree_=e.syncPointTree_.remove(i));var u=s.removed;a=s.events;var l=-1!==u.findIndex(function(e){return e._queryParams.loadsAllData()}),c=e.syncPointTree_.findOnPath(i,function(e,t){return eo(t)});if(l&&!c){var h=e.syncPointTree_.subtree(i);if(!h.isEmpty())for(var d=xo(h),p=0;p<d.length;++p){var f=d[p],_=f.query,v=To(e,f);e.listenProvider_.startListening(No(_),ko(e,_),v.hashFn,v.onComplete)}}if(!c&&u.length>0&&!r)if(l){e.listenProvider_.stopListening(No(t),null)}else u.forEach(function(t){var n=e.queryToTagMap.get(Io(t));e.listenProvider_.stopListening(No(t),n)});Ro(e,u)}return a}function _o(e,t,n,r){var i=Eo(e,r);if(null!=i){var o=So(i),a=o.path,s=o.queryId,u=Ct(a,t);return Po(e,a,new vr(dr(s),u,n))}return[]}function vo(e,t,n,r){var i=Eo(e,r);if(i){var o=So(i),a=o.path,s=o.queryId,u=Ct(a,t),l=Nr.fromObject(n);return Po(e,a,new yr(dr(s),u,l))}return[]}function yo(e,t,n){var i=t._path,o=null,a=!1;e.syncPointTree_.foreachOnPath(i,function(e,t){var n=Ct(e,i);o=o||Ji(t,n),a=a||eo(t)});var s,u=e.syncPointTree_.get(i);(u?(a=a||eo(u),o=o||Ji(u,ct())):(u=new Bi,e.syncPointTree_=e.syncPointTree_.set(i,u)),null!=o)?s=!0:(s=!1,o=vn.EMPTY_NODE,e.syncPointTree_.subtree(i).foreachChild(function(e,t){var n=Ji(t,ct());n&&(o=o.updateImmediateChild(e,n))}));var l=Zi(u,t);if(!l&&!t._queryParams.loadsAllData()){var c=Io(t);(0,r.assert)(!e.queryToTagMap.has(c),"View does not exist, but we have a tag");var h=Ao();e.queryToTagMap.set(c,h),e.tagToQueryMap.set(h,c)}var d=Ki(u,t,n,Br(e.pendingWriteTree_,i),o,s);if(!l&&!a){var p=Xi(u,t);d=d.concat(Do(e,t,p))}return d}function go(e,t,n){var r=e.pendingWriteTree_,i=e.syncPointTree_.findOnPath(t,function(e,n){var r=Ji(n,Ct(e,t));if(r)return r});return Jr(r,t,i,n,!0)}function mo(e,t){var n=t._path,r=null;e.syncPointTree_.foreachOnPath(n,function(e,t){var i=Ct(e,n);r=r||Ji(t,i)});var i=e.syncPointTree_.get(n);i?r=r||Ji(i,ct()):(i=new Bi,e.syncPointTree_=e.syncPointTree_.set(n,i));var o=null!=r,a=o?new gr(r,!0,!1):null;return Di(Yi(i,t,Br(e.pendingWriteTree_,t._path),o?a.getNode():vn.EMPTY_NODE,o))}function Co(e,t){return wo(t,e.syncPointTree_,null,Br(e.pendingWriteTree_,ct()))}function wo(e,t,n,r){if(mt(e.path))return bo(e,t,n,r);var i=t.get(ct());null==n&&null!=i&&(n=Ji(i,ct()));var o=[],a=ht(e.path),s=e.operationForChild(a),u=t.children.get(a);if(u&&s){var l=n?n.getImmediateChild(a):null,c=ci(r,a);o=o.concat(wo(s,u,l,c))}return i&&(o=o.concat(zi(i,e,r,n))),o}function bo(e,t,n,r){var i=t.get(ct());null==n&&null!=i&&(n=Ji(i,ct()));var o=[];return t.children.inorderTraversal(function(t,i){var a=n?n.getImmediateChild(t):null,s=ci(r,t),u=e.operationForChild(t);u&&(o=o.concat(bo(u,i,a,s)))}),i&&(o=o.concat(zi(i,e,r,n))),o}function To(e,t){var n=t.query,r=ko(e,n);return{hashFn:function(){return(Ai(t)||vn.EMPTY_NODE).hash()},onComplete:function(t){if("ok"===t)return r?po(e,n._path,r):ho(e,n._path);var i=B(t,n);return fo(e,n,null,i)}}}function ko(e,t){var n=Io(t);return e.queryToTagMap.get(n)}function Io(e){return e._path.toString()+"$"+e._queryIdentifier}function Eo(e,t){return e.tagToQueryMap.get(t)}function So(e){var t=e.indexOf("$");return(0,r.assert)(-1!==t&&t<e.length-1,"Bad queryKey."),{queryId:e.substr(t+1),path:new lt(e.substr(0,t))}}function Po(e,t,n){var i=e.syncPointTree_.get(t);return(0,r.assert)(i,"Missing sync point for query tag that we're tracking"),zi(i,n,Br(e.pendingWriteTree_,t),null)}function xo(e){return e.fold(function(e,t,n){if(t&&eo(t))return[to(t)];var r=[];return t&&(r=$i(t)),L(n,function(e,t){r=r.concat(t)}),r})}function No(e){return e._queryParams.loadsAllData()&&!e._queryParams.isDefault()?new(ro())(e._repo,e._path):e}function Ro(e,t){for(var n=0;n<t.length;++n){var r=t[n];if(!r._queryParams.loadsAllData()){var i=Io(r),o=e.queryToTagMap.get(i);e.queryToTagMap.delete(i),e.tagToQueryMap.delete(o)}}}function Ao(){return io++}function Do(e,t,n){var i=t._path,o=ko(e,t),a=To(e,n),s=e.listenProvider_.startListening(No(t),o,a.hashFn,a.onComplete),u=e.syncPointTree_.subtree(i);if(o)(0,r.assert)(!eo(u.value),"If we're adding a query, it shouldn't be shadowed");else for(var l=u.fold(function(e,t,n){if(!mt(e)&&t&&eo(t))return[to(t).query];var r=[];return t&&(r=r.concat($i(t).map(function(e){return e.query}))),L(n,function(e,t){r=r.concat(t)}),r}),c=0;c<l.length;++c){var h=l[c];e.listenProvider_.stopListening(No(h),ko(e,h))}return s}var Oo=function(){function e(e){this.node_=e}return e.prototype.getImmediateChild=function(t){return new e(this.node_.getImmediateChild(t))},e.prototype.node=function(){return this.node_},e}(),Mo=function(){function e(e,t){this.syncTree_=e,this.path_=t}return e.prototype.getImmediateChild=function(t){var n=gt(this.path_,t);return new e(this.syncTree_,n)},e.prototype.node=function(){return go(this.syncTree_,this.path_)},e}(),qo=function(e){return(e=e||{}).timestamp=e.timestamp||(new Date).getTime(),e},Fo=function(e,t,n){return e&&"object"==typeof e?((0,r.assert)(".sv"in e,"Unexpected leaf node or priority contents"),"string"==typeof e[".sv"]?Lo(e[".sv"],t,n):"object"==typeof e[".sv"]?Wo(e[".sv"],t):void(0,r.assert)(!1,"Unexpected server value: "+JSON.stringify(e,null,2))):e},Lo=function(e,t,n){switch(e){case"timestamp":return n.timestamp;default:(0,r.assert)(!1,"Unexpected server value: "+e)}},Wo=function(e,t,n){e.hasOwnProperty("increment")||(0,r.assert)(!1,"Unexpected server value: "+JSON.stringify(e,null,2));var i=e.increment;"number"!=typeof i&&(0,r.assert)(!1,"Unexpected increment value: "+i);var o=t.node();if((0,r.assert)(null!=o,"Expected ChildrenNode.EMPTY_NODE for nulls"),!o.isLeafNode())return i;var a=o.getValue();return"number"!=typeof a?i:a+i},jo=function(e,t,n,r){return Bo(t,new Mo(n,e),r)},Uo=function(e,t,n){return Bo(e,new Oo(t),n)};function Bo(e,t,n){var r,i=e.getPriority().val(),o=Fo(i,t.getImmediateChild(".priority"),n);if(e.isLeafNode()){var a=e,s=Fo(a.getValue(),t,n);return s!==a.getValue()||o!==a.getPriority().val()?new rn(s,Cn(o)):e}var u=e;return r=u,o!==u.getPriority().val()&&(r=r.updatePriority(new rn(o))),u.forEachChild(cn,function(e,i){var o=Bo(i,t.getImmediateChild(e),n);o!==i&&(r=r.updateImmediateChild(e,o))}),r}var Vo=function(){return function(e,t,n){void 0===e&&(e=""),void 0===t&&(t=null),void 0===n&&(n={children:{},childCount:0}),this.name=e,this.parent=t,this.node=n}}();function Qo(e,t){for(var n=t instanceof lt?t:new lt(t),i=e,o=ht(n);null!==o;){var a=(0,r.safeGet)(i.node.children,o)||{children:{},childCount:0};i=new Vo(o,i,a),o=ht(n=pt(n))}return i}function Ho(e){return e.node.value}function zo(e,t){e.node.value=t,Zo(e)}function Yo(e){return e.node.childCount>0}function Ko(e){return void 0===Ho(e)&&!Yo(e)}function Go(e,t){L(e.node.children,function(n,r){t(new Vo(n,e,r))})}function $o(e,t,n,r){n&&!r&&t(e),Go(e,function(e){$o(e,t,!0,r)}),n&&r&&t(e)}function Jo(e,t,n){for(var r=n?e:e.parent;null!==r;){if(t(r))return!0;r=r.parent}return!1}function Xo(e){return new lt(null===e.parent?e.name:Xo(e.parent)+"/"+e.name)}function Zo(e){null!==e.parent&&ea(e.parent,e.name,e)}function ea(e,t,n){var i=Ko(n),o=(0,r.contains)(e.node.children,t);i&&o?(delete e.node.children[t],e.node.childCount--,Zo(e)):i||o||(e.node.children[t]=n.node,e.node.childCount++,Zo(e))}var ta=/[\[\].#$\/\u0000-\u001F\u007F]/,na=/[\[\].#$\u0000-\u001F\u007F]/,ra=10485760,ia=function(e){return"string"==typeof e&&0!==e.length&&!ta.test(e)},oa=function(e){return"string"==typeof e&&0!==e.length&&!na.test(e)},aa=function(e){return e&&(e=e.replace(/^\/*\.info(\/|$)/,"/")),oa(e)},sa=function(e){return null===e||"string"==typeof e||"number"==typeof e&&!x(e)||e&&"object"==typeof e&&(0,r.contains)(e,".sv")},ua=function(e,t,n,i){i&&void 0===t||la((0,r.errorPrefix)(e,"value"),t,n)},la=function(e,t,n){var i=n instanceof lt?new kt(n,e):n;if(void 0===t)throw new Error(e+"contains undefined "+Pt(i));if("function"==typeof t)throw new Error(e+"contains a function "+Pt(i)+" with contents = "+t.toString());if(x(t))throw new Error(e+"contains "+t.toString()+" "+Pt(i));if("string"==typeof t&&t.length>ra/3&&(0,r.stringLength)(t)>ra)throw new Error(e+"contains a string greater than "+ra+" utf8 bytes "+Pt(i)+" ('"+t.substring(0,50)+"...')");if(t&&"object"==typeof t){var o=!1,a=!1;if(L(t,function(t,n){if(".value"===t)o=!0;else if(".priority"!==t&&".sv"!==t&&(a=!0,!ia(t)))throw new Error(e+" contains an invalid key ("+t+") "+Pt(i)+'. Keys must be non-empty strings and can\'t contain ".", "#", "$", "/", "[", or "]"');It(i,t),la(e,n,i),Et(i)}),o&&a)throw new Error(e+' contains ".value" child '+Pt(i)+" in addition to actual children.")}},ca=function(e,t){var n,r;for(n=0;n<t.length;n++)for(var i=vt(r=t[n]),o=0;o<i.length;o++)if(".priority"===i[o]&&o===i.length-1);else if(!ia(i[o]))throw new Error(e+"contains an invalid key ("+i[o]+") in path "+r.toString()+'. Keys must be non-empty strings and can\'t contain ".", "#", "$", "/", "[", or "]"');t.sort(wt);var a=null;for(n=0;n<t.length;n++){if(r=t[n],null!==a&&Tt(a,r))throw new Error(e+"contains a path "+a.toString()+" that is ancestor of another path "+r.toString());a=r}},ha=function(e,t,n,i){if(!i||void 0!==t){var o=(0,r.errorPrefix)(e,"values");if(!t||"object"!=typeof t||Array.isArray(t))throw new Error(o+" must be an object containing the children to replace.");var a=[];L(t,function(e,t){var r=new lt(e);if(la(o,t,gt(n,r)),".priority"===ft(r)&&!sa(t))throw new Error(o+"contains an invalid value for '"+r.toString()+"', which must be a valid Firebase priority (a string, finite number, server value, or null).");a.push(r)}),ca(o,a)}},da=function(e,t,n){if(!n||void 0!==t){if(x(t))throw new Error((0,r.errorPrefix)(e,"priority")+"is "+t.toString()+", but must be a valid Firebase priority (a string, finite number, server value, or null).");if(!sa(t))throw new Error((0,r.errorPrefix)(e,"priority")+"must be a valid Firebase priority (a string, finite number, server value, or null).")}},pa=function(e,t,n){if(!n||void 0!==t)switch(t){case"value":case"child_added":case"child_removed":case"child_changed":case"child_moved":break;default:throw new Error((0,r.errorPrefix)(e,"eventType")+'must be a valid event type = "value", "child_added", "child_removed", "child_changed", or "child_moved".')}},fa=function(e,t,n,i){if(!(i&&void 0===n||ia(n)))throw new Error((0,r.errorPrefix)(e,t)+'was an invalid key = "'+n+'". Firebase keys must be non-empty strings and can\'t contain ".", "#", "$", "/", "[", or "]").')},_a=function(e,t,n,i){if(!(i&&void 0===n||oa(n)))throw new Error((0,r.errorPrefix)(e,t)+'was an invalid path = "'+n+'". Paths must be non-empty strings and can\'t contain ".", "#", "$", "[", or "]"')},va=function(e,t,n,r){n&&(n=n.replace(/^\/*\.info(\/|$)/,"/")),_a(e,t,n,r)},ya=function(e,t){if(".info"===ht(t))throw new Error(e+" failed = Can't modify data under /.info/")},ga=function(e,t){var n=t.path.toString();if("string"!=typeof t.repoInfo.host||0===t.repoInfo.host.length||!ia(t.repoInfo.namespace)&&"localhost"!==t.repoInfo.host.split(":")[0]||0!==n.length&&!aa(n))throw new Error((0,r.errorPrefix)(e,"url")+'must be a valid firebase URL and the path can\'t contain ".", "#", "$", "[", or "]".')},ma=function(e,t,n,i){if((!i||void 0!==n)&&"boolean"!=typeof n)throw new Error((0,r.errorPrefix)(e,t)+"must be a boolean.")},Ca=function(){return function(){this.eventLists_=[],this.recursionDepth_=0}}();function wa(e,t){for(var n=null,r=0;r<t.length;r++){var i=t[r],o=i.getPath();null===n||bt(o,n.path)||(e.eventLists_.push(n),n=null),null===n&&(n={events:[],path:o}),n.events.push(i)}n&&e.eventLists_.push(n)}function ba(e,t,n){wa(e,n),ka(e,function(e){return bt(e,t)})}function Ta(e,t,n){wa(e,n),ka(e,function(e){return Tt(e,t)||Tt(t,e)})}function ka(e,t){e.recursionDepth_++;for(var n=!0,r=0;r<e.eventLists_.length;r++){var i=e.eventLists_[r];if(i)t(i.path)?(Ia(e.eventLists_[r]),e.eventLists_[r]=null):n=!1}n&&(e.eventLists_=[]),e.recursionDepth_--}function Ia(e){for(var t=0;t<e.events.length;t++){var n=e.events[t];if(null!==n){e.events[t]=null;var r=n.getEventRunner();C&&T("event: "+n.toString()),Y(r)}}}var Ea="repo_interrupt",Sa=25,Pa=function(){function e(e,t,n,r){this.repoInfo_=e,this.forceRestClient_=t,this.authTokenProvider_=n,this.appCheckProvider_=r,this.dataUpdateCount=0,this.statsListener_=null,this.eventQueue_=new Ca,this.nextWriteId_=1,this.interceptServerDataCallback_=null,this.onDisconnect_=Xn(),this.transactionQueueTree_=new Vo,this.persistentConnection_=null,this.key=this.repoInfo_.toURLString()}return e.prototype.toString=function(){return(this.repoInfo_.secure?"https://":"http://")+this.repoInfo_.host},e}();function xa(e,t,n){if(e.stats_=ve(e.repoInfo_),e.forceRestClient_||K())e.server_=new $n(e.repoInfo_,function(t,n,r,i){Aa(e,t,n,r,i)},e.authTokenProvider_,e.appCheckProvider_),setTimeout(function(){return Oa(e,!0)},0);else{if(null!=n){if("object"!=typeof n)throw new Error("Only objects are supported for option databaseAuthVariableOverride");try{(0,r.stringify)(n)}catch(i){throw new Error("Invalid authOverride provided: "+i)}}e.persistentConnection_=new jt(e.repoInfo_,t,function(t,n,r,i){Aa(e,t,n,r,i)},function(t){Oa(e,t)},function(t){Ma(e,t)},e.authTokenProvider_,e.appCheckProvider_,n),e.server_=e.persistentConnection_}e.authTokenProvider_.addTokenChangeListener(function(t){e.server_.refreshAuthToken(t)}),e.appCheckProvider_.addTokenChangeListener(function(t){e.server_.refreshAppCheckToken(t.token)}),e.statsReporter_=ye(e.repoInfo_,function(){return new ur(e.stats_,e.server_)}),e.infoData_=new Jn,e.infoSyncTree_=new oo({startListening:function(t,n,r,i){var o=[],a=e.infoData_.getNode(t._path);return a.isEmpty()||(o=lo(e.infoSyncTree_,t._path,a),setTimeout(function(){i("ok")},0)),o},stopListening:function(){}}),qa(e,"connected",!1),e.serverSyncTree_=new oo({startListening:function(t,n,r,i){return e.server_.listen(t,r,n,function(n,r){var o=i(n,r);Ta(e.eventQueue_,t._path,o)}),[]},stopListening:function(t,n){e.server_.unlisten(t,n)}})}function Na(e){var t=e.infoData_.getNode(new lt(".info/serverTimeOffset")).val()||0;return(new Date).getTime()+t}function Ra(e){return qo({timestamp:Na(e)})}function Aa(e,t,n,i,o){e.dataUpdateCount++;var a=new lt(t);n=e.interceptServerDataCallback_?e.interceptServerDataCallback_(t,n):n;var s=[];if(o)if(i){var u=(0,r.map)(n,function(e){return Cn(e)});s=vo(e.serverSyncTree_,a,u,o)}else{var l=Cn(n);s=_o(e.serverSyncTree_,a,l,o)}else if(i){var c=(0,r.map)(n,function(e){return Cn(e)});s=co(e.serverSyncTree_,a,c)}else{var h=Cn(n);s=lo(e.serverSyncTree_,a,h)}var d=a;s.length>0&&(d=is(e,a)),Ta(e.eventQueue_,d,s)}function Da(e,t){e.interceptServerDataCallback_=t}function Oa(e,t){qa(e,"connected",t),!1===t&&Ua(e)}function Ma(e,t){L(t,function(t,n){qa(e,t,n)})}function qa(e,t,n){var r=new lt("/.info/"+t),i=Cn(n);e.infoData_.updateSnapshot(r,i);var o=lo(e.infoSyncTree_,r,i);Ta(e.eventQueue_,r,o)}function Fa(e){return e.nextWriteId_++}function La(e,t){var n=mo(e.serverSyncTree_,t);return null!=n?Promise.resolve(n):e.server_.get(t).then(function(n){var r=Cn(n).withIndex(t._queryParams.getIndex()),i=lo(e.serverSyncTree_,t._path,r);return ba(e.eventQueue_,t._path,i),Promise.resolve(r)},function(n){return Xa(e,"get for query "+(0,r.stringify)(t)+" failed: "+n),Promise.reject(new Error(n))})}function Wa(e,t,n,r,i){Xa(e,"set",{path:t.toString(),value:n,priority:r});var o=Ra(e),a=Cn(n,r),s=go(e.serverSyncTree_,t),u=Uo(a,s,o),l=Fa(e),c=ao(e.serverSyncTree_,t,u,l,!0);wa(e.eventQueue_,c),e.server_.put(t.toString(),a.val(!0),function(n,r){var o="ok"===n;o||S("set at "+t+" failed: "+n);var a=uo(e.serverSyncTree_,l,!o);Ta(e.eventQueue_,t,a),Za(e,i,n,r)});var h=cs(e,t);is(e,h),Ta(e.eventQueue_,h,[])}function ja(e,t,n,r){Xa(e,"update",{path:t.toString(),value:n});var i=!0,o=Ra(e),a={};if(L(n,function(n,r){i=!1,a[n]=jo(gt(t,n),Cn(r),e.serverSyncTree_,o)}),i)T("update() called with empty data. Don't do anything."),Za(e,r,"ok",void 0);else{var s=Fa(e),u=so(e.serverSyncTree_,t,a,s);wa(e.eventQueue_,u),e.server_.merge(t.toString(),n,function(n,i){var o="ok"===n;o||S("update at "+t+" failed: "+n);var a=uo(e.serverSyncTree_,s,!o),u=a.length>0?is(e,t):t;Ta(e.eventQueue_,u,a),Za(e,r,n,i)}),L(n,function(n){var r=cs(e,gt(t,n));is(e,r)}),Ta(e.eventQueue_,t,[])}}function Ua(e){Xa(e,"onDisconnectEvents");var t=Ra(e),n=Xn();tr(e.onDisconnect_,ct(),function(r,i){var o=jo(r,i,e.serverSyncTree_,t);Zn(n,r,o)});var r=[];tr(n,ct(),function(t,n){r=r.concat(lo(e.serverSyncTree_,t,n));var i=cs(e,t);is(e,i)}),e.onDisconnect_=Xn(),Ta(e.eventQueue_,ct(),r)}function Ba(e,t,n){e.server_.onDisconnectCancel(t.toString(),function(r,i){"ok"===r&&er(e.onDisconnect_,t),Za(e,n,r,i)})}function Va(e,t,n,r){var i=Cn(n);e.server_.onDisconnectPut(t.toString(),i.val(!0),function(n,o){"ok"===n&&Zn(e.onDisconnect_,t,i),Za(e,r,n,o)})}function Qa(e,t,n,r,i){var o=Cn(n,r);e.server_.onDisconnectPut(t.toString(),o.val(!0),function(n,r){"ok"===n&&Zn(e.onDisconnect_,t,o),Za(e,i,n,r)})}function Ha(e,t,n,i){if((0,r.isEmpty)(n))return T("onDisconnect().update() called with empty data. Don't do anything."),void Za(e,i,"ok",void 0);e.server_.onDisconnectMerge(t.toString(),n,function(r,o){"ok"===r&&L(n,function(n,r){var i=Cn(r);Zn(e.onDisconnect_,gt(t,n),i)}),Za(e,i,r,o)})}function za(e,t,n){var r;r=".info"===ht(t._path)?yo(e.infoSyncTree_,t,n):yo(e.serverSyncTree_,t,n),ba(e.eventQueue_,t._path,r)}function Ya(e,t,n){var r;r=".info"===ht(t._path)?fo(e.infoSyncTree_,t,n):fo(e.serverSyncTree_,t,n),ba(e.eventQueue_,t._path,r)}function Ka(e){e.persistentConnection_&&e.persistentConnection_.interrupt(Ea)}function Ga(e){e.persistentConnection_&&e.persistentConnection_.resume(Ea)}function $a(e,t){if(void 0===t&&(t=!1),"undefined"!=typeof console){var n;t?(e.statsListener_||(e.statsListener_=new ir(e.stats_)),n=e.statsListener_.get()):n=e.stats_.get();var r=Object.keys(n).reduce(function(e,t){return Math.max(t.length,e)},0);L(n,function(e,t){for(var n=e,i=e.length;i<r+2;i++)n+=" ";console.log(n+t)})}}function Ja(e,t){e.stats_.incrementCounter(t),lr(e.statsReporter_,t)}function Xa(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var r="";e.persistentConnection_&&(r=e.persistentConnection_.id+":"),T.apply(void 0,(0,i.__spreadArray)([r],(0,i.__read)(t)))}function Za(e,t,n,r){t&&Y(function(){if("ok"===n)t(null);else{var e=(n||"error").toUpperCase(),i=e;r&&(i+=": "+r);var o=new Error(i);o.code=e,t(o)}})}function es(e,t,n,i,o,a){Xa(e,"transaction on "+t);var s={path:t,update:n,onComplete:i,status:null,order:y(),applyLocally:a,retryCount:0,unwatcher:o,abortReason:null,currentWriteId:null,currentInputSnapshot:null,currentOutputSnapshotRaw:null,currentOutputSnapshotResolved:null},u=ts(e,t,void 0);s.currentInputSnapshot=u;var l=s.update(u.val());if(void 0===l)s.unwatcher(),s.currentOutputSnapshotRaw=null,s.currentOutputSnapshotResolved=null,s.onComplete&&s.onComplete(null,!1,s.currentInputSnapshot);else{la("transaction failed: Data returned ",l,s.path),s.status=0;var c=Qo(e.transactionQueueTree_,t),h=Ho(c)||[];h.push(s),zo(c,h);var d=void 0;if("object"==typeof l&&null!==l&&(0,r.contains)(l,".priority"))d=(0,r.safeGet)(l,".priority"),(0,r.assert)(sa(d),"Invalid priority returned by transaction. Priority must be a valid string, finite number, server value, or null.");else d=(go(e.serverSyncTree_,t)||vn.EMPTY_NODE).getPriority().val();var p=Ra(e),f=Cn(l,d),_=Uo(f,u,p);s.currentOutputSnapshotRaw=f,s.currentOutputSnapshotResolved=_,s.currentWriteId=Fa(e);var v=ao(e.serverSyncTree_,t,_,s.currentWriteId,s.applyLocally);Ta(e.eventQueue_,t,v),ns(e,e.transactionQueueTree_)}}function ts(e,t,n){return go(e.serverSyncTree_,t,n)||vn.EMPTY_NODE}function ns(e,t){if(void 0===t&&(t=e.transactionQueueTree_),t||ls(e,t),Ho(t)){var n=ss(e,t);(0,r.assert)(n.length>0,"Sending zero length transaction queue"),n.every(function(e){return 0===e.status})&&rs(e,Xo(t),n)}else Yo(t)&&Go(t,function(t){ns(e,t)})}function rs(e,t,n){for(var i=n.map(function(e){return e.currentWriteId}),o=ts(e,t,i),a=o,s=o.hash(),u=0;u<n.length;u++){var l=n[u];(0,r.assert)(0===l.status,"tryToSendTransactionQueue_: items in queue should all be run."),l.status=1,l.retryCount++;var c=Ct(t,l.path);a=a.updateChild(c,l.currentOutputSnapshotRaw)}var h=a.val(!0),d=t;e.server_.put(d.toString(),h,function(r){Xa(e,"transaction put response",{path:d.toString(),status:r});var i=[];if("ok"===r){for(var o=[],a=function(t){n[t].status=2,i=i.concat(uo(e.serverSyncTree_,n[t].currentWriteId)),n[t].onComplete&&o.push(function(){return n[t].onComplete(null,!0,n[t].currentOutputSnapshotResolved)}),n[t].unwatcher()},s=0;s<n.length;s++)a(s);ls(e,Qo(e.transactionQueueTree_,t)),ns(e,e.transactionQueueTree_),Ta(e.eventQueue_,t,i);for(s=0;s<o.length;s++)Y(o[s])}else{if("datastale"===r)for(s=0;s<n.length;s++)3===n[s].status?n[s].status=4:n[s].status=0;else{S("transaction at "+d.toString()+" failed: "+r);for(s=0;s<n.length;s++)n[s].status=4,n[s].abortReason=r}is(e,t)}},s)}function is(e,t){var n=as(e,t),r=Xo(n);return os(e,ss(e,n),r),r}function os(e,t,n){if(0!==t.length){for(var i=[],o=[],a=t.filter(function(e){return 0===e.status}).map(function(e){return e.currentWriteId}),s=function(s){var u,l,c=t[s],h=Ct(n,c.path),d=!1;if((0,r.assert)(null!==h,"rerunTransactionsUnderNode_: relativePath should not be null."),4===c.status)d=!0,u=c.abortReason,o=o.concat(uo(e.serverSyncTree_,c.currentWriteId,!0));else if(0===c.status)if(c.retryCount>=Sa)d=!0,u="maxretry",o=o.concat(uo(e.serverSyncTree_,c.currentWriteId,!0));else{var p=ts(e,c.path,a);c.currentInputSnapshot=p;var f=t[s].update(p.val());if(void 0!==f){la("transaction failed: Data returned ",f,c.path);var _=Cn(f);"object"==typeof f&&null!=f&&(0,r.contains)(f,".priority")||(_=_.updatePriority(p.getPriority()));var v=c.currentWriteId,y=Ra(e),g=Uo(_,p,y);c.currentOutputSnapshotRaw=_,c.currentOutputSnapshotResolved=g,c.currentWriteId=Fa(e),a.splice(a.indexOf(v),1),o=(o=o.concat(ao(e.serverSyncTree_,c.path,g,c.currentWriteId,c.applyLocally))).concat(uo(e.serverSyncTree_,v,!0))}else d=!0,u="nodata",o=o.concat(uo(e.serverSyncTree_,c.currentWriteId,!0))}Ta(e.eventQueue_,n,o),o=[],d&&(t[s].status=2,l=t[s].unwatcher,setTimeout(l,Math.floor(0)),t[s].onComplete&&("nodata"===u?i.push(function(){return t[s].onComplete(null,!1,t[s].currentInputSnapshot)}):i.push(function(){return t[s].onComplete(new Error(u),!1,null)})))},u=0;u<t.length;u++)s(u);ls(e,e.transactionQueueTree_);for(u=0;u<i.length;u++)Y(i[u]);ns(e,e.transactionQueueTree_)}}function as(e,t){var n,r=e.transactionQueueTree_;for(n=ht(t);null!==n&&void 0===Ho(r);)r=Qo(r,n),n=ht(t=pt(t));return r}function ss(e,t){var n=[];return us(e,t,n),n.sort(function(e,t){return e.order-t.order}),n}function us(e,t,n){var r=Ho(t);if(r)for(var i=0;i<r.length;i++)n.push(r[i]);Go(t,function(t){us(e,t,n)})}function ls(e,t){var n=Ho(t);if(n){for(var r=0,i=0;i<n.length;i++)2!==n[i].status&&(n[r]=n[i],r++);n.length=r,zo(t,n.length>0?n:void 0)}Go(t,function(t){ls(e,t)})}function cs(e,t){var n=Xo(as(e,t)),r=Qo(e.transactionQueueTree_,t);return Jo(r,function(t){hs(e,t)}),hs(e,r),$o(r,function(t){hs(e,t)}),n}function hs(e,t){var n=Ho(t);if(n){for(var i=[],o=[],a=-1,s=0;s<n.length;s++)3===n[s].status||(1===n[s].status?((0,r.assert)(a===s-1,"All SENT items should be at beginning of queue."),a=s,n[s].status=3,n[s].abortReason="set"):((0,r.assert)(0===n[s].status,"Unexpected transaction status in abort"),n[s].unwatcher(),o=o.concat(uo(e.serverSyncTree_,n[s].currentWriteId,!0)),n[s].onComplete&&i.push(n[s].onComplete.bind(null,new Error("set"),!1,null))));-1===a?zo(t,void 0):n.length=a+1,Ta(e.eventQueue_,Xo(t),o);for(s=0;s<i.length;s++)Y(i[s])}}function ds(e){for(var t="",n=e.split("/"),r=0;r<n.length;r++)if(n[r].length>0){var i=n[r];try{i=decodeURIComponent(i.replace(/\+/g," "))}catch(o){}t+="/"+i}return t}function ps(e){var t,n,r={};"?"===e.charAt(0)&&(e=e.substring(1));try{for(var o=(0,i.__values)(e.split("&")),a=o.next();!a.done;a=o.next()){var s=a.value;if(0!==s.length){var u=s.split("=");2===u.length?r[decodeURIComponent(u[0])]=decodeURIComponent(u[1]):S("Invalid query segment '"+s+"' in query '"+e+"'")}}}catch(l){t={error:l}}finally{try{a&&!a.done&&(n=o.return)&&n.call(o)}finally{if(t)throw t.error}}return r}var fs=function(e,t){var n=_s(e),r=n.namespace;"firebase.com"===n.domain&&E(n.host+" is no longer supported. Please use <YOUR FIREBASE>.firebaseio.com instead"),r&&"undefined"!==r||"localhost"===n.domain||E("Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com"),n.secure||P();var i="ws"===n.scheme||"wss"===n.scheme;return{repoInfo:new ce(n.host,n.secure,r,t,i,"",r!==n.subdomain),path:new lt(n.pathString)}},_s=function(e){var t="",n="",r="",i="",o="",a=!0,s="https",u=443;if("string"==typeof e){var l=e.indexOf("//");l>=0&&(s=e.substring(0,l-1),e=e.substring(l+2));var c=e.indexOf("/");-1===c&&(c=e.length);var h=e.indexOf("?");-1===h&&(h=e.length),t=e.substring(0,Math.min(c,h)),c<h&&(i=ds(e.substring(c,h)));var d=ps(e.substring(Math.min(e.length,h)));(l=t.indexOf(":"))>=0?(a="https"===s||"wss"===s,u=parseInt(t.substring(l+1),10)):l=t.length;var p=t.slice(0,l);if("localhost"===p.toLowerCase())n="localhost";else if(p.split(".").length<=2)n=p;else{var f=t.indexOf(".");r=t.substring(0,f).toLowerCase(),n=t.substring(f+1),o=r}"ns"in d&&(o=d.ns)}return{host:t,port:u,domain:n,subdomain:r,secure:a,scheme:s,pathString:i,namespace:o}},vs=function(){function e(e,t,n,r){this.eventType=e,this.eventRegistration=t,this.snapshot=n,this.prevName=r}return e.prototype.getPath=function(){var e=this.snapshot.ref;return"value"===this.eventType?e._path:e.parent._path},e.prototype.getEventType=function(){return this.eventType},e.prototype.getEventRunner=function(){return this.eventRegistration.getEventRunner(this)},e.prototype.toString=function(){return this.getPath().toString()+":"+this.eventType+":"+(0,r.stringify)(this.snapshot.exportVal())},e}(),ys=function(){function e(e,t,n){this.eventRegistration=e,this.error=t,this.path=n}return e.prototype.getPath=function(){return this.path},e.prototype.getEventType=function(){return"cancel"},e.prototype.getEventRunner=function(){return this.eventRegistration.getEventRunner(this)},e.prototype.toString=function(){return this.path.toString()+":cancel"},e}(),gs=function(){function e(e,t){this.snapshotCallback=e,this.cancelCallback=t}return e.prototype.onValue=function(e,t){this.snapshotCallback.call(null,e,t)},e.prototype.onCancel=function(e){return(0,r.assert)(this.hasCancelCallback,"Raising a cancel event on a listener with no cancel callback"),this.cancelCallback.call(null,e)},Object.defineProperty(e.prototype,"hasCancelCallback",{get:function(){return!!this.cancelCallback},enumerable:!1,configurable:!0}),e.prototype.matches=function(e){return this.snapshotCallback===e.snapshotCallback||void 0!==this.snapshotCallback.userCallback&&this.snapshotCallback.userCallback===e.snapshotCallback.userCallback&&this.snapshotCallback.context===e.snapshotCallback.context},e}(),ms=function(){function e(e,t){this._repo=e,this._path=t}return e.prototype.cancel=function(){var e=new r.Deferred;return Ba(this._repo,this._path,e.wrapCallback(function(){})),e.promise},e.prototype.remove=function(){ya("OnDisconnect.remove",this._path);var e=new r.Deferred;return Va(this._repo,this._path,null,e.wrapCallback(function(){})),e.promise},e.prototype.set=function(e){ya("OnDisconnect.set",this._path),ua("OnDisconnect.set",e,this._path,!1);var t=new r.Deferred;return Va(this._repo,this._path,e,t.wrapCallback(function(){})),t.promise},e.prototype.setWithPriority=function(e,t){ya("OnDisconnect.setWithPriority",this._path),ua("OnDisconnect.setWithPriority",e,this._path,!1),da("OnDisconnect.setWithPriority",t,!1);var n=new r.Deferred;return Qa(this._repo,this._path,e,t,n.wrapCallback(function(){})),n.promise},e.prototype.update=function(e){ya("OnDisconnect.update",this._path),ha("OnDisconnect.update",e,this._path,!1);var t=new r.Deferred;return Ha(this._repo,this._path,e,t.wrapCallback(function(){})),t.promise},e}(),Cs=function(){function e(e,t,n,r){this._repo=e,this._path=t,this._queryParams=n,this._orderByCalled=r}return Object.defineProperty(e.prototype,"key",{get:function(){return mt(this._path)?null:ft(this._path)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"ref",{get:function(){return new ks(this._repo,this._path)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"_queryIdentifier",{get:function(){var e=Gn(this._queryParams),t=q(e);return"{}"===t?"default":t},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"_queryObject",{get:function(){return Gn(this._queryParams)},enumerable:!1,configurable:!0}),e.prototype.isEqual=function(t){if(!((t=(0,r.getModularInstance)(t))instanceof e))return!1;var n=this._repo===t._repo,i=bt(this._path,t._path),o=this._queryIdentifier===t._queryIdentifier;return n&&i&&o},e.prototype.toJSON=function(){return this.toString()},e.prototype.toString=function(){return this._repo.toString()+_t(this._path)},e}();function ws(e,t){if(!0===e._orderByCalled)throw new Error(t+": You can't combine multiple orderBy calls.")}function bs(e){var t=null,n=null;if(e.hasStart()&&(t=e.getIndexStartValue()),e.hasEnd()&&(n=e.getIndexEndValue()),e.getIndex()===Qt){var i="Query: When ordering by key, you may only pass one argument to startAt(), endAt(), or equalTo().",o="Query: When ordering by key, the argument passed to startAt(), startAfter(), endAt(), endBefore(), or equalTo() must be a string.";if(e.hasStart()){if(e.getIndexStartName()!==R)throw new Error(i);if("string"!=typeof t)throw new Error(o)}if(e.hasEnd()){if(e.getIndexEndName()!==A)throw new Error(i);if("string"!=typeof n)throw new Error(o)}}else if(e.getIndex()===cn){if(null!=t&&!sa(t)||null!=n&&!sa(n))throw new Error("Query: When ordering by priority, the first argument passed to startAt(), startAfter() endAt(), endBefore(), or equalTo() must be a valid priority value (null, a number, or a string).")}else if((0,r.assert)(e.getIndex()instanceof wn||e.getIndex()===Tn,"unknown index type."),null!=t&&"object"==typeof t||null!=n&&"object"==typeof n)throw new Error("Query: First argument passed to startAt(), startAfter(), endAt(), endBefore(), or equalTo() cannot be an object.")}function Ts(e){if(e.hasStart()&&e.hasEnd()&&e.hasLimit()&&!e.hasAnchoredLimit())throw new Error("Query: Can't combine startAt(), startAfter(), endAt(), endBefore(), and limit(). Use limitToFirst() or limitToLast() instead.")}var ks=function(e){function t(t,n){return e.call(this,t,n,new Wn,!1)||this}return(0,i.__extends)(t,e),Object.defineProperty(t.prototype,"parent",{get:function(){var e=yt(this._path);return null===e?null:new t(this._repo,e)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"root",{get:function(){for(var e=this;null!==e.parent;)e=e.parent;return e},enumerable:!1,configurable:!0}),t}(Cs),Is=function(){function e(e,t,n){this._node=e,this.ref=t,this._index=n}return Object.defineProperty(e.prototype,"priority",{get:function(){return this._node.getPriority().val()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"key",{get:function(){return this.ref.key},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return this._node.numChildren()},enumerable:!1,configurable:!0}),e.prototype.child=function(t){var n=new lt(t),r=Ps(this.ref,t);return new e(this._node.getChild(n),r,cn)},e.prototype.exists=function(){return!this._node.isEmpty()},e.prototype.exportVal=function(){return this._node.val(!0)},e.prototype.forEach=function(t){var n=this;return!this._node.isLeafNode()&&!!this._node.forEachChild(this._index,function(r,i){return t(new e(i,Ps(n.ref,r),cn))})},e.prototype.hasChild=function(e){var t=new lt(e);return!this._node.getChild(t).isEmpty()},e.prototype.hasChildren=function(){return!this._node.isLeafNode()&&!this._node.isEmpty()},e.prototype.toJSON=function(){return this.exportVal()},e.prototype.val=function(){return this._node.val()},e}();function Es(e,t){return(e=(0,r.getModularInstance)(e))._checkNotDeleted("ref"),void 0!==t?Ps(e._root,t):e._root}function Ss(e,t){(e=(0,r.getModularInstance)(e))._checkNotDeleted("refFromURL");var n=fs(t,e._repo.repoInfo_.nodeAdmin);ga("refFromURL",n);var i=n.repoInfo;return e._repo.repoInfo_.isCustomHost()||i.host===e._repo.repoInfo_.host||E("refFromURL: Host name does not match the current database: (found "+i.host+" but expected "+e._repo.repoInfo_.host+")"),Es(e,n.path.toString())}function Ps(e,t){return null===ht((e=(0,r.getModularInstance)(e))._path)?va("child","path",t,!1):_a("child","path",t,!1),new ks(e._repo,gt(e._path,t))}function xs(e,t){e=(0,r.getModularInstance)(e),ya("push",e._path),ua("push",t,e._path,!0);var n,i=Na(e._repo),o=Pn(i),a=Ps(e,o),s=Ps(e,o);return n=null!=t?Rs(s,t).then(function(){return s}):Promise.resolve(s),a.then=n.then.bind(n),a.catch=n.then.bind(n,void 0),a}function Ns(e){return ya("remove",e._path),Rs(e,null)}function Rs(e,t){e=(0,r.getModularInstance)(e),ya("set",e._path),ua("set",t,e._path,!1);var n=new r.Deferred;return Wa(e._repo,e._path,t,null,n.wrapCallback(function(){})),n.promise}function As(e,t){e=(0,r.getModularInstance)(e),ya("setPriority",e._path),da("setPriority",t,!1);var n=new r.Deferred;return Wa(e._repo,gt(e._path,".priority"),t,null,n.wrapCallback(function(){})),n.promise}function Ds(e,t,n){if(ya("setWithPriority",e._path),ua("setWithPriority",t,e._path,!1),da("setWithPriority",n,!1),".length"===e.key||".keys"===e.key)throw"setWithPriority failed: "+e.key+" is a read-only object.";var i=new r.Deferred;return Wa(e._repo,e._path,t,n,i.wrapCallback(function(){})),i.promise}function Os(e,t){ha("update",t,e._path,!1);var n=new r.Deferred;return ja(e._repo,e._path,t,n.wrapCallback(function(){})),n.promise}function Ms(e){return La((e=(0,r.getModularInstance)(e))._repo,e).then(function(t){return new Is(t,new ks(e._repo,e._path),e._queryParams.getIndex())})}var qs=function(){function e(e){this.callbackContext=e}return e.prototype.respondsTo=function(e){return"value"===e},e.prototype.createEvent=function(e,t){var n=t._queryParams.getIndex();return new vs("value",this,new Is(e.snapshotNode,new ks(t._repo,t._path),n))},e.prototype.getEventRunner=function(e){var t=this;return"cancel"===e.getEventType()?function(){return t.callbackContext.onCancel(e.error)}:function(){return t.callbackContext.onValue(e.snapshot,null)}},e.prototype.createCancelEvent=function(e,t){return this.callbackContext.hasCancelCallback?new ys(this,e,t):null},e.prototype.matches=function(t){return t instanceof e&&(!t.callbackContext||!this.callbackContext||t.callbackContext.matches(this.callbackContext))},e.prototype.hasAnyCallback=function(){return null!==this.callbackContext},e}(),Fs=function(){function e(e,t){this.eventType=e,this.callbackContext=t}return e.prototype.respondsTo=function(e){var t="children_added"===e?"child_added":e;return t="children_removed"===t?"child_removed":t,this.eventType===t},e.prototype.createCancelEvent=function(e,t){return this.callbackContext.hasCancelCallback?new ys(this,e,t):null},e.prototype.createEvent=function(e,t){(0,r.assert)(null!=e.childName,"Child events should have a childName.");var n=Ps(new ks(t._repo,t._path),e.childName),i=t._queryParams.getIndex();return new vs(e.type,this,new Is(e.snapshotNode,n,i),e.prevName)},e.prototype.getEventRunner=function(e){var t=this;return"cancel"===e.getEventType()?function(){return t.callbackContext.onCancel(e.error)}:function(){return t.callbackContext.onValue(e.snapshot,e.prevName)}},e.prototype.matches=function(t){return t instanceof e&&(this.eventType===t.eventType&&(!this.callbackContext||!t.callbackContext||this.callbackContext.matches(t.callbackContext)))},e.prototype.hasAnyCallback=function(){return!!this.callbackContext},e}();function Ls(e,t,n,r,i){var o;if("object"==typeof r&&(o=void 0,i=r),"function"==typeof r&&(o=r),i&&i.onlyOnce){var a=n,s=function(t,n){Ya(e._repo,e,l),a(t,n)};s.userCallback=n.userCallback,s.context=n.context,n=s}var u=new gs(n,o||void 0),l="value"===t?new qs(u):new Fs(t,u);return za(e._repo,e,l),function(){return Ya(e._repo,e,l)}}function Ws(e,t,n,r){return Ls(e,"value",t,n,r)}function js(e,t,n,r){return Ls(e,"child_added",t,n,r)}function Us(e,t,n,r){return Ls(e,"child_changed",t,n,r)}function Bs(e,t,n,r){return Ls(e,"child_moved",t,n,r)}function Vs(e,t,n,r){return Ls(e,"child_removed",t,n,r)}function Qs(e,t,n){var r=null,i=n?new gs(n):null;"value"===t?r=new qs(i):t&&(r=new Fs(t,i)),Ya(e._repo,e,r)}var Hs=function(){return function(){}}(),zs=function(e){function t(t,n){var r=e.call(this)||this;return r._value=t,r._key=n,r}return(0,i.__extends)(t,e),t.prototype._apply=function(e){ua("endAt",this._value,e._path,!0);var t=Hn(e._queryParams,this._value,this._key);if(Ts(t),bs(t),e._queryParams.hasEnd())throw new Error("endAt: Starting point was already set (by another call to endAt, endBefore or equalTo).");return new Cs(e._repo,e._path,t,e._orderByCalled)},t}(Hs);function Ys(e,t){return fa("endAt","key",t,!0),new zs(e,t)}var Ks=function(e){function t(t,n){var r=e.call(this)||this;return r._value=t,r._key=n,r}return(0,i.__extends)(t,e),t.prototype._apply=function(e){ua("endBefore",this._value,e._path,!1);var t=zn(e._queryParams,this._value,this._key);if(Ts(t),bs(t),e._queryParams.hasEnd())throw new Error("endBefore: Starting point was already set (by another call to endAt, endBefore or equalTo).");return new Cs(e._repo,e._path,t,e._orderByCalled)},t}(Hs);function Gs(e,t){return fa("endBefore","key",t,!0),new Ks(e,t)}var $s=function(e){function t(t,n){var r=e.call(this)||this;return r._value=t,r._key=n,r}return(0,i.__extends)(t,e),t.prototype._apply=function(e){ua("startAt",this._value,e._path,!0);var t=Vn(e._queryParams,this._value,this._key);if(Ts(t),bs(t),e._queryParams.hasStart())throw new Error("startAt: Starting point was already set (by another call to startAt, startBefore or equalTo).");return new Cs(e._repo,e._path,t,e._orderByCalled)},t}(Hs);function Js(e,t){return void 0===e&&(e=null),fa("startAt","key",t,!0),new $s(e,t)}var Xs=function(e){function t(t,n){var r=e.call(this)||this;return r._value=t,r._key=n,r}return(0,i.__extends)(t,e),t.prototype._apply=function(e){ua("startAfter",this._value,e._path,!1);var t=Qn(e._queryParams,this._value,this._key);if(Ts(t),bs(t),e._queryParams.hasStart())throw new Error("startAfter: Starting point was already set (by another call to startAt, startAfter, or equalTo).");return new Cs(e._repo,e._path,t,e._orderByCalled)},t}(Hs);function Zs(e,t){return fa("startAfter","key",t,!0),new Xs(e,t)}var eu=function(e){function t(t){var n=e.call(this)||this;return n._limit=t,n}return(0,i.__extends)(t,e),t.prototype._apply=function(e){if(e._queryParams.hasLimit())throw new Error("limitToFirst: Limit was already set (by another call to limitToFirst or limitToLast).");return new Cs(e._repo,e._path,Un(e._queryParams,this._limit),e._orderByCalled)},t}(Hs);function tu(e){if("number"!=typeof e||Math.floor(e)!==e||e<=0)throw new Error("limitToFirst: First argument must be a positive integer.");return new eu(e)}var nu=function(e){function t(t){var n=e.call(this)||this;return n._limit=t,n}return(0,i.__extends)(t,e),t.prototype._apply=function(e){if(e._queryParams.hasLimit())throw new Error("limitToLast: Limit was already set (by another call to limitToFirst or limitToLast).");return new Cs(e._repo,e._path,Bn(e._queryParams,this._limit),e._orderByCalled)},t}(Hs);function ru(e){if("number"!=typeof e||Math.floor(e)!==e||e<=0)throw new Error("limitToLast: First argument must be a positive integer.");return new nu(e)}var iu=function(e){function t(t){var n=e.call(this)||this;return n._path=t,n}return(0,i.__extends)(t,e),t.prototype._apply=function(e){ws(e,"orderByChild");var t=new lt(this._path);if(mt(t))throw new Error("orderByChild: cannot pass in empty path. Use orderByValue() instead.");var n=new wn(t),r=Yn(e._queryParams,n);return bs(r),new Cs(e._repo,e._path,r,!0)},t}(Hs);function ou(e){if("$key"===e)throw new Error('orderByChild: "$key" is invalid. Use orderByKey() instead.');if("$priority"===e)throw new Error('orderByChild: "$priority" is invalid. Use orderByPriority() instead.');if("$value"===e)throw new Error('orderByChild: "$value" is invalid. Use orderByValue() instead.');return _a("orderByChild","path",e,!1),new iu(e)}var au=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return(0,i.__extends)(t,e),t.prototype._apply=function(e){ws(e,"orderByKey");var t=Yn(e._queryParams,Qt);return bs(t),new Cs(e._repo,e._path,t,!0)},t}(Hs);function su(){return new au}var uu=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return(0,i.__extends)(t,e),t.prototype._apply=function(e){ws(e,"orderByPriority");var t=Yn(e._queryParams,cn);return bs(t),new Cs(e._repo,e._path,t,!0)},t}(Hs);function lu(){return new uu}var cu=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return(0,i.__extends)(t,e),t.prototype._apply=function(e){ws(e,"orderByValue");var t=Yn(e._queryParams,Tn);return bs(t),new Cs(e._repo,e._path,t,!0)},t}(Hs);function hu(){return new cu}var du=function(e){function t(t,n){var r=e.call(this)||this;return r._value=t,r._key=n,r}return(0,i.__extends)(t,e),t.prototype._apply=function(e){if(ua("equalTo",this._value,e._path,!1),e._queryParams.hasStart())throw new Error("equalTo: Starting point was already set (by another call to startAt/startAfter or equalTo).");if(e._queryParams.hasEnd())throw new Error("equalTo: Ending point was already set (by another call to endAt/endBefore or equalTo).");return new zs(this._value,this._key)._apply(new $s(this._value,this._key)._apply(e))},t}(Hs);function pu(e,t){return fa("equalTo","key",t,!0),new du(e,t)}function fu(e){for(var t,n,o=[],a=1;a<arguments.length;a++)o[a-1]=arguments[a];var s=(0,r.getModularInstance)(e);try{for(var u=(0,i.__values)(o),l=u.next();!l.done;l=u.next()){s=l.value._apply(s)}}catch(c){t={error:c}}finally{try{l&&!l.done&&(n=u.return)&&n.call(u)}finally{if(t)throw t.error}}return s}Vi(ks),no(ks);var _u="FIREBASE_DATABASE_EMULATOR_HOST",vu={},yu=!1;function gu(e,t,n,r){e.repoInfo_=new ce(t+":"+n,!1,e.repoInfo_.namespace,e.repoInfo_.webSocketOnly,e.repoInfo_.nodeAdmin,e.repoInfo_.persistenceKey,e.repoInfo_.includeNamespaceInQueryParams),r&&(e.authTokenProvider_=r)}function mu(t,n,r,i,o){var a=i||t.options.databaseURL;void 0===a&&(t.options.projectId||E("Can't determine Firebase Database URL. Be sure to include a Project ID when calling firebase.initializeApp()."),T("Using default host for project ",t.options.projectId),a=t.options.projectId+"-default-rtdb.firebaseio.com");var s,u=fs(a,o),l=u.repoInfo,c=void 0;void 0!==e&&(c=e.env[_u]),c?(s=!0,a="http://"+c+"?ns="+l.namespace,l=(u=fs(a,o)).repoInfo):s=!u.repoInfo.secure;var h=o&&s?new X(X.OWNER):new J(t.name,t.options,n);ga("Invalid Firebase Database URL",u),mt(u.path)||E("Database URL must point to the root of a Firebase Database (not including a child path).");var d=wu(l,t,h,new $(t.name,r));return new Tu(d,t)}function Cu(e,t){var n=vu[t];n&&n[e.key]===e||E("Database "+t+"("+e.repoInfo_+") has already been deleted."),Ka(e),delete n[e.key]}function wu(e,t,n,r){var i=vu[t.name];i||(i={},vu[t.name]=i);var o=i[e.toURLString()];return o&&E("Database initialized multiple times. Please make sure the format of the database URL matches with each database() call."),o=new Pa(e,yu,n,r),i[e.toURLString()]=o,o}function bu(e){yu=e}var Tu=function(){function e(e,t){this._repoInternal=e,this.app=t,this.type="database",this._instanceStarted=!1}return Object.defineProperty(e.prototype,"_repo",{get:function(){return this._instanceStarted||(xa(this._repoInternal,this.app.options.appId,this.app.options.databaseAuthVariableOverride),this._instanceStarted=!0),this._repoInternal},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"_root",{get:function(){return this._rootInternal||(this._rootInternal=new ks(this._repo,ct())),this._rootInternal},enumerable:!1,configurable:!0}),e.prototype._delete=function(){return null!==this._rootInternal&&(Cu(this._repo,this.app.name),this._repoInternal=null,this._rootInternal=null),Promise.resolve()},e.prototype._checkNotDeleted=function(e){null===this._rootInternal&&E("Cannot call "+e+" on a deleted database.")},e}();function ku(e,t,n,i){void 0===i&&(i={}),(e=(0,r.getModularInstance)(e))._checkNotDeleted("useEmulator"),e._instanceStarted&&E("Cannot call useEmulator() after instance has already been initialized.");var o=e._repoInternal,a=void 0;if(o.repoInfo_.nodeAdmin)i.mockUserToken&&E('mockUserToken is not supported by the Admin SDK. For client access with mock users, please use the "firebase" package instead of "firebase-admin".'),a=new X(X.OWNER);else if(i.mockUserToken){var s="string"==typeof i.mockUserToken?i.mockUserToken:(0,r.createMockUserToken)(i.mockUserToken,e.app.options.projectId);a=new X(s)}gu(o,t,n,a)}function Iu(e){(e=(0,r.getModularInstance)(e))._checkNotDeleted("goOffline"),Ka(e._repo)}function Eu(e){(e=(0,r.getModularInstance)(e))._checkNotDeleted("goOnline"),Ga(e._repo)}var Su={".sv":"timestamp"};function Pu(){return Su}function xu(e){return{".sv":{increment:e}}}var Nu=function(){function e(e,t){this.committed=e,this.snapshot=t}return e.prototype.toJSON=function(){return{committed:this.committed,snapshot:this.snapshot.toJSON()}},e}();function Ru(e,t,n){var i;if(e=(0,r.getModularInstance)(e),ya("Reference.transaction",e._path),".length"===e.key||".keys"===e.key)throw"Reference.transaction failed: "+e.key+" is a read-only object.";var o=null===(i=null==n?void 0:n.applyLocally)||void 0===i||i,a=new r.Deferred,s=Ws(e,function(){});return es(e._repo,e._path,t,function(t,n,r){var i=null;t?a.reject(t):(i=new Is(r,new ks(e._repo,e._path),cn),a.resolve(new Nu(n,i)))},s,o),a.promise}var Au=function(){function e(e){this._delegate=e}return e.prototype.cancel=function(e){(0,r.validateArgCount)("OnDisconnect.cancel",0,1,arguments.length),(0,r.validateCallback)("OnDisconnect.cancel","onComplete",e,!0);var t=this._delegate.cancel();return e&&t.then(function(){return e(null)},function(t){return e(t)}),t},e.prototype.remove=function(e){(0,r.validateArgCount)("OnDisconnect.remove",0,1,arguments.length),(0,r.validateCallback)("OnDisconnect.remove","onComplete",e,!0);var t=this._delegate.remove();return e&&t.then(function(){return e(null)},function(t){return e(t)}),t},e.prototype.set=function(e,t){(0,r.validateArgCount)("OnDisconnect.set",1,2,arguments.length),(0,r.validateCallback)("OnDisconnect.set","onComplete",t,!0);var n=this._delegate.set(e);return t&&n.then(function(){return t(null)},function(e){return t(e)}),n},e.prototype.setWithPriority=function(e,t,n){(0,r.validateArgCount)("OnDisconnect.setWithPriority",2,3,arguments.length),(0,r.validateCallback)("OnDisconnect.setWithPriority","onComplete",n,!0);var i=this._delegate.setWithPriority(e,t);return n&&i.then(function(){return n(null)},function(e){return n(e)}),i},e.prototype.update=function(e,t){if((0,r.validateArgCount)("OnDisconnect.update",1,2,arguments.length),Array.isArray(e)){for(var n={},i=0;i<e.length;++i)n[""+i]=e[i];e=n,S("Passing an Array to firebase.database.onDisconnect().update() is deprecated. Use set() if you want to overwrite the existing data, or an Object with integer keys if you really do want to only update some of the children.")}(0,r.validateCallback)("OnDisconnect.update","onComplete",t,!0);var o=this._delegate.update(e);return t&&o.then(function(){return t(null)},function(e){return t(e)}),o},e}();exports.OnDisconnect=Au;var Du=function(){function e(e,t){this.committed=e,this.snapshot=t}return e.prototype.toJSON=function(){return(0,r.validateArgCount)("TransactionResult.toJSON",0,1,arguments.length),{committed:this.committed,snapshot:this.snapshot.toJSON()}},e}(),Ou=function(){function e(e,t){this._database=e,this._delegate=t}return e.prototype.val=function(){return(0,r.validateArgCount)("DataSnapshot.val",0,0,arguments.length),this._delegate.val()},e.prototype.exportVal=function(){return(0,r.validateArgCount)("DataSnapshot.exportVal",0,0,arguments.length),this._delegate.exportVal()},e.prototype.toJSON=function(){return(0,r.validateArgCount)("DataSnapshot.toJSON",0,1,arguments.length),this._delegate.toJSON()},e.prototype.exists=function(){return(0,r.validateArgCount)("DataSnapshot.exists",0,0,arguments.length),this._delegate.exists()},e.prototype.child=function(t){return(0,r.validateArgCount)("DataSnapshot.child",0,1,arguments.length),t=String(t),_a("DataSnapshot.child","path",t,!1),new e(this._database,this._delegate.child(t))},e.prototype.hasChild=function(e){return(0,r.validateArgCount)("DataSnapshot.hasChild",1,1,arguments.length),_a("DataSnapshot.hasChild","path",e,!1),this._delegate.hasChild(e)},e.prototype.getPriority=function(){return(0,r.validateArgCount)("DataSnapshot.getPriority",0,0,arguments.length),this._delegate.priority},e.prototype.forEach=function(t){var n=this;return(0,r.validateArgCount)("DataSnapshot.forEach",1,1,arguments.length),(0,r.validateCallback)("DataSnapshot.forEach","action",t,!1),this._delegate.forEach(function(r){return t(new e(n._database,r))})},e.prototype.hasChildren=function(){return(0,r.validateArgCount)("DataSnapshot.hasChildren",0,0,arguments.length),this._delegate.hasChildren()},Object.defineProperty(e.prototype,"key",{get:function(){return this._delegate.key},enumerable:!1,configurable:!0}),e.prototype.numChildren=function(){return(0,r.validateArgCount)("DataSnapshot.numChildren",0,0,arguments.length),this._delegate.size},e.prototype.getRef=function(){return(0,r.validateArgCount)("DataSnapshot.ref",0,0,arguments.length),new qu(this._database,this._delegate.ref)},Object.defineProperty(e.prototype,"ref",{get:function(){return this.getRef()},enumerable:!1,configurable:!0}),e}();exports.DataSnapshot=Ou;var Mu=function(){function e(e,t){this.database=e,this._delegate=t}return e.prototype.on=function(t,n,i,o){var a,s=this;(0,r.validateArgCount)("Query.on",2,4,arguments.length),(0,r.validateCallback)("Query.on","callback",n,!1);var u=e.getCancelAndContextArgs_("Query.on",i,o),l=function(e,t){n.call(u.context,new Ou(s.database,e),t)};l.userCallback=n,l.context=u.context;var c=null===(a=u.cancel)||void 0===a?void 0:a.bind(u.context);switch(t){case"value":return Ws(this._delegate,l,c),n;case"child_added":return js(this._delegate,l,c),n;case"child_removed":return Vs(this._delegate,l,c),n;case"child_changed":return Us(this._delegate,l,c),n;case"child_moved":return Bs(this._delegate,l,c),n;default:throw new Error((0,r.errorPrefix)("Query.on","eventType")+'must be a valid event type = "value", "child_added", "child_removed", "child_changed", or "child_moved".')}},e.prototype.off=function(e,t,n){if((0,r.validateArgCount)("Query.off",0,3,arguments.length),pa("Query.off",e,!0),(0,r.validateCallback)("Query.off","callback",t,!0),(0,r.validateContextObject)("Query.off","context",n,!0),t){var i=function(){};i.userCallback=t,i.context=n,Qs(this._delegate,e,i)}else Qs(this._delegate,e)},e.prototype.get=function(){var e=this;return Ms(this._delegate).then(function(t){return new Ou(e.database,t)})},e.prototype.once=function(t,n,i,o){var a=this;(0,r.validateArgCount)("Query.once",1,4,arguments.length),(0,r.validateCallback)("Query.once","callback",n,!0);var s=e.getCancelAndContextArgs_("Query.once",i,o),u=new r.Deferred,l=function(e,t){var r=new Ou(a.database,e);n&&n.call(s.context,r,t),u.resolve(r)};l.userCallback=n,l.context=s.context;var c=function(e){s.cancel&&s.cancel.call(s.context,e),u.reject(e)};switch(t){case"value":Ws(this._delegate,l,c,{onlyOnce:!0});break;case"child_added":js(this._delegate,l,c,{onlyOnce:!0});break;case"child_removed":Vs(this._delegate,l,c,{onlyOnce:!0});break;case"child_changed":Us(this._delegate,l,c,{onlyOnce:!0});break;case"child_moved":Bs(this._delegate,l,c,{onlyOnce:!0});break;default:throw new Error((0,r.errorPrefix)("Query.once","eventType")+'must be a valid event type = "value", "child_added", "child_removed", "child_changed", or "child_moved".')}return u.promise},e.prototype.limitToFirst=function(t){return(0,r.validateArgCount)("Query.limitToFirst",1,1,arguments.length),new e(this.database,fu(this._delegate,tu(t)))},e.prototype.limitToLast=function(t){return(0,r.validateArgCount)("Query.limitToLast",1,1,arguments.length),new e(this.database,fu(this._delegate,ru(t)))},e.prototype.orderByChild=function(t){return(0,r.validateArgCount)("Query.orderByChild",1,1,arguments.length),new e(this.database,fu(this._delegate,ou(t)))},e.prototype.orderByKey=function(){return(0,r.validateArgCount)("Query.orderByKey",0,0,arguments.length),new e(this.database,fu(this._delegate,su()))},e.prototype.orderByPriority=function(){return(0,r.validateArgCount)("Query.orderByPriority",0,0,arguments.length),new e(this.database,fu(this._delegate,lu()))},e.prototype.orderByValue=function(){return(0,r.validateArgCount)("Query.orderByValue",0,0,arguments.length),new e(this.database,fu(this._delegate,hu()))},e.prototype.startAt=function(t,n){return void 0===t&&(t=null),(0,r.validateArgCount)("Query.startAt",0,2,arguments.length),new e(this.database,fu(this._delegate,Js(t,n)))},e.prototype.startAfter=function(t,n){return void 0===t&&(t=null),(0,r.validateArgCount)("Query.startAfter",0,2,arguments.length),new e(this.database,fu(this._delegate,Zs(t,n)))},e.prototype.endAt=function(t,n){return void 0===t&&(t=null),(0,r.validateArgCount)("Query.endAt",0,2,arguments.length),new e(this.database,fu(this._delegate,Ys(t,n)))},e.prototype.endBefore=function(t,n){return void 0===t&&(t=null),(0,r.validateArgCount)("Query.endBefore",0,2,arguments.length),new e(this.database,fu(this._delegate,Gs(t,n)))},e.prototype.equalTo=function(t,n){return(0,r.validateArgCount)("Query.equalTo",1,2,arguments.length),new e(this.database,fu(this._delegate,pu(t,n)))},e.prototype.toString=function(){return(0,r.validateArgCount)("Query.toString",0,0,arguments.length),this._delegate.toString()},e.prototype.toJSON=function(){return(0,r.validateArgCount)("Query.toJSON",0,1,arguments.length),this._delegate.toJSON()},e.prototype.isEqual=function(t){if((0,r.validateArgCount)("Query.isEqual",1,1,arguments.length),!(t instanceof e)){throw new Error("Query.isEqual failed: First argument must be an instance of firebase.database.Query.")}return this._delegate.isEqual(t._delegate)},e.getCancelAndContextArgs_=function(e,t,n){var i={cancel:void 0,context:void 0};if(t&&n)i.cancel=t,(0,r.validateCallback)(e,"cancel",i.cancel,!0),i.context=n,(0,r.validateContextObject)(e,"context",i.context,!0);else if(t)if("object"==typeof t&&null!==t)i.context=t;else{if("function"!=typeof t)throw new Error((0,r.errorPrefix)(e,"cancelOrContext")+" must either be a cancel callback or a context object.");i.cancel=t}return i},Object.defineProperty(e.prototype,"ref",{get:function(){return new qu(this.database,new ks(this._delegate._repo,this._delegate._path))},enumerable:!1,configurable:!0}),e}();exports.Query=Mu;var qu=function(e){function t(t,n){var r=e.call(this,t,new Cs(n._repo,n._path,new Wn,!1))||this;return r.database=t,r._delegate=n,r}return(0,i.__extends)(t,e),t.prototype.getKey=function(){return(0,r.validateArgCount)("Reference.key",0,0,arguments.length),this._delegate.key},t.prototype.child=function(e){return(0,r.validateArgCount)("Reference.child",1,1,arguments.length),"number"==typeof e&&(e=String(e)),new t(this.database,Ps(this._delegate,e))},t.prototype.getParent=function(){(0,r.validateArgCount)("Reference.parent",0,0,arguments.length);var e=this._delegate.parent;return e?new t(this.database,e):null},t.prototype.getRoot=function(){return(0,r.validateArgCount)("Reference.root",0,0,arguments.length),new t(this.database,this._delegate.root)},t.prototype.set=function(e,t){(0,r.validateArgCount)("Reference.set",1,2,arguments.length),(0,r.validateCallback)("Reference.set","onComplete",t,!0);var n=Rs(this._delegate,e);return t&&n.then(function(){return t(null)},function(e){return t(e)}),n},t.prototype.update=function(e,t){if((0,r.validateArgCount)("Reference.update",1,2,arguments.length),Array.isArray(e)){for(var n={},i=0;i<e.length;++i)n[""+i]=e[i];e=n,S("Passing an Array to Firebase.update() is deprecated. Use set() if you want to overwrite the existing data, or an Object with integer keys if you really do want to only update some of the children.")}ya("Reference.update",this._delegate._path),(0,r.validateCallback)("Reference.update","onComplete",t,!0);var o=Os(this._delegate,e);return t&&o.then(function(){return t(null)},function(e){return t(e)}),o},t.prototype.setWithPriority=function(e,t,n){(0,r.validateArgCount)("Reference.setWithPriority",2,3,arguments.length),(0,r.validateCallback)("Reference.setWithPriority","onComplete",n,!0);var i=Ds(this._delegate,e,t);return n&&i.then(function(){return n(null)},function(e){return n(e)}),i},t.prototype.remove=function(e){(0,r.validateArgCount)("Reference.remove",0,1,arguments.length),(0,r.validateCallback)("Reference.remove","onComplete",e,!0);var t=Ns(this._delegate);return e&&t.then(function(){return e(null)},function(t){return e(t)}),t},t.prototype.transaction=function(e,t,n){var i=this;(0,r.validateArgCount)("Reference.transaction",1,3,arguments.length),(0,r.validateCallback)("Reference.transaction","transactionUpdate",e,!1),(0,r.validateCallback)("Reference.transaction","onComplete",t,!0),ma("Reference.transaction","applyLocally",n,!0);var o=Ru(this._delegate,e,{applyLocally:n}).then(function(e){return new Du(e.committed,new Ou(i.database,e.snapshot))});return t&&o.then(function(e){return t(null,e.committed,e.snapshot)},function(e){return t(e,!1,null)}),o},t.prototype.setPriority=function(e,t){(0,r.validateArgCount)("Reference.setPriority",1,2,arguments.length),(0,r.validateCallback)("Reference.setPriority","onComplete",t,!0);var n=As(this._delegate,e);return t&&n.then(function(){return t(null)},function(e){return t(e)}),n},t.prototype.push=function(e,n){var i=this;(0,r.validateArgCount)("Reference.push",0,2,arguments.length),(0,r.validateCallback)("Reference.push","onComplete",n,!0);var o=xs(this._delegate,e),a=o.then(function(e){return new t(i.database,e)});n&&a.then(function(){return n(null)},function(e){return n(e)});var s=new t(this.database,o);return s.then=a.then.bind(a),s.catch=a.catch.bind(a,void 0),s},t.prototype.onDisconnect=function(){return ya("Reference.onDisconnect",this._delegate._path),new Au(new ms(this._delegate._repo,this._delegate._path))},Object.defineProperty(t.prototype,"key",{get:function(){return this.getKey()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"parent",{get:function(){return this.getParent()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"root",{get:function(){return this.getRoot()},enumerable:!1,configurable:!0}),t}(Mu);exports.Reference=qu;var Fu=function(){function e(e,t){var n=this;this._delegate=e,this.app=t,this.INTERNAL={delete:function(){return n._delegate._delete()}}}return e.prototype.useEmulator=function(e,t,n){void 0===n&&(n={}),ku(this._delegate,e,t,n)},e.prototype.ref=function(e){if((0,r.validateArgCount)("database.ref",0,1,arguments.length),e instanceof qu){var t=Ss(this._delegate,e.toString());return new qu(this,t)}t=Es(this._delegate,e);return new qu(this,t)},e.prototype.refFromURL=function(e){(0,r.validateArgCount)("database.refFromURL",1,1,arguments.length);var t=Ss(this._delegate,e);return new qu(this,t)},e.prototype.goOffline=function(){return(0,r.validateArgCount)("database.goOffline",0,0,arguments.length),Iu(this._delegate)},e.prototype.goOnline=function(){return(0,r.validateArgCount)("database.goOnline",0,0,arguments.length),Eu(this._delegate)},e.ServerValue={TIMESTAMP:Pu(),increment:function(e){return xu(e)}},e}();exports.Database=Fu;var Lu=function(){Ue.forceDisallow(),qe.forceAllow()},Wu=function(){qe.forceDisallow()},ju=function(){return Ue.isAvailable()},Uu=function(e,t){e._delegate._repo.persistentConnection_.securityDebugCallback_=t},Bu=function(e,t){$a(e._delegate._repo,t)},Vu=function(e,t){Ja(e._delegate._repo,t)},Qu=function(e){return e._delegate._repo.dataUpdateCount},Hu=function(e,t){return Da(e._delegate._repo,t)};function zu(e){var t=e.app,r=e.url,i=e.version,o=e.customAuthImpl,a=e.namespace,s=e.nodeAdmin,u=void 0!==s&&s;c(i);var l=new n.Provider("auth-internal",new n.ComponentContainer("database-standalone"));return l.setComponent(new n.Component("auth-internal",function(){return o},"PRIVATE")),{instance:new Fu(mu(t,l,void 0,r,u),t),namespace:a}}var Yu=Object.freeze({__proto__:null,forceLongPolling:Lu,forceWebSockets:Wu,isWebSocketsAvailable:ju,setSecurityDebugCallback:Uu,stats:Bu,statsIncrementCounter:Vu,dataUpdateCount:Qu,interceptServerData:Hu,initStandalone:zu}),Ku=jt;jt.prototype.simpleListen=function(e,t){this.sendRequest("q",{p:e},t)},jt.prototype.echo=function(e,t){this.sendRequest("echo",{d:e},t)};var Gu=rt,$u=function(e){var t=jt.prototype.put;return jt.prototype.put=function(n,r,i,o){void 0!==o&&(o=e()),t.call(this,n,r,i,o)},function(){jt.prototype.put=t}},Ju=ce,Xu=function(e){return e._delegate._queryIdentifier},Zu=function(e){bu(e)},el=Object.freeze({__proto__:null,DataConnection:Ku,RealTimeConnection:Gu,hijackHash:$u,ConnectionTarget:Ju,queryIdentifier:Xu,forceRestClient:Zu}),tl=Fu.ServerValue;function nl(e){c(e.SDK_VERSION);var t=e.INTERNAL.registerComponent(new n.Component("database",function(e,t){var n=t.instanceIdentifier,r=e.getProvider("app").getImmediate(),i=e.getProvider("auth-internal"),o=e.getProvider("app-check-internal");return new Fu(mu(r,i,o,n),r)},"PUBLIC").setServiceProps({Reference:qu,Query:Mu,Database:Fu,DataSnapshot:Ou,enableLogging:b,INTERNAL:Yu,ServerValue:tl,TEST_ACCESS:el}).setMultipleInstances(!0));e.registerVersion(s,u),(0,r.isNodeSdk)()&&(module.exports=t)}exports.ServerValue=tl,nl(t.default);
@@ -482,18 +482,18 @@ var t=arguments[3],e=n(require("@firebase/app"));function n(t){return t&&t.__esM
482
482
  },{"@firebase/app":"VxYX"}],"zKjx":[function(require,module,exports) {
483
483
  "use strict";require("@firebase/auth");
484
484
  },{"@firebase/auth":"EkFk"}],"SScM":[function(require,module,exports) {
485
- "use strict";var e=r(require("@firebase/app")),t=require("tslib"),n=require("@firebase/component");function r(e){return e&&e.__esModule?e:{default:e}}var i={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"},o=function(e){function n(t,r,i){var o=e.call(this,r)||this;return Object.setPrototypeOf(o,n.prototype),o.code=t,o.details=i,o}return(0,t.__extends)(n,e),n}(Error);function a(e){if(e>=200&&e<300)return"ok";switch(e){case 0:return"internal";case 400:return"invalid-argument";case 401:return"unauthenticated";case 403:return"permission-denied";case 404:return"not-found";case 409:return"aborted";case 429:return"resource-exhausted";case 499:return"cancelled";case 500:return"internal";case 501:return"unimplemented";case 503:return"unavailable";case 504:return"deadline-exceeded"}return"unknown"}function s(e,t,n){var r=a(e),s=r,u=void 0;try{var c=t&&t.error;if(c){var l=c.status;if("string"==typeof l){if(!i[l])return new o("internal","internal");r=i[l],s=l}var d=c.message;"string"==typeof d&&(s=d),void 0!==(u=c.details)&&(u=n.decode(u))}}catch(f){}return"ok"===r?null:new o(r,s,u)}var u=function(){function e(e,t){var n=this;this.auth=null,this.messaging=null,this.auth=e.getImmediate({optional:!0}),this.messaging=t.getImmediate({optional:!0}),this.auth||e.get().then(function(e){return n.auth=e},function(){}),this.messaging||t.get().then(function(e){return n.messaging=e},function(){})}return e.prototype.getAuthToken=function(){return(0,t.__awaiter)(this,void 0,void 0,function(){var e;return(0,t.__generator)(this,function(t){switch(t.label){case 0:if(!this.auth)return[2,void 0];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,this.auth.getToken()];case 2:return(e=t.sent())?[2,e.accessToken]:[2,void 0];case 3:return t.sent(),[2,void 0];case 4:return[2]}})})},e.prototype.getInstanceIdToken=function(){return(0,t.__awaiter)(this,void 0,void 0,function(){return(0,t.__generator)(this,function(e){switch(e.label){case 0:if(!(this.messaging&&"Notification"in self&&"granted"===Notification.permission))return[2,void 0];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.messaging.getToken()];case 2:return[2,e.sent()];case 3:return e.sent(),[2,void 0];case 4:return[2]}})})},e.prototype.getContext=function(){return(0,t.__awaiter)(this,void 0,void 0,function(){var e,n;return(0,t.__generator)(this,function(t){switch(t.label){case 0:return[4,this.getAuthToken()];case 1:return e=t.sent(),[4,this.getInstanceIdToken()];case 2:return n=t.sent(),[2,{authToken:e,instanceIdToken:n}]}})})},e}(),c="type.googleapis.com/google.protobuf.Int64Value",l="type.googleapis.com/google.protobuf.UInt64Value";function d(e,t){var n={};for(var r in e)e.hasOwnProperty(r)&&(n[r]=t(e[r]));return n}var f=function(){function e(){}return e.prototype.encode=function(e){var t=this;if(null==e)return null;if(e instanceof Number&&(e=e.valueOf()),"number"==typeof e&&isFinite(e))return e;if(!0===e||!1===e)return e;if("[object String]"===Object.prototype.toString.call(e))return e;if(e instanceof Date)return e.toISOString();if(Array.isArray(e))return e.map(function(e){return t.encode(e)});if("function"==typeof e||"object"==typeof e)return d(e,function(e){return t.encode(e)});throw new Error("Data cannot be encoded in JSON: "+e)},e.prototype.decode=function(e){var t=this;if(null==e)return e;if(e["@type"])switch(e["@type"]){case c:case l:var n=Number(e.value);if(isNaN(n))throw new Error("Data cannot be decoded from JSON: "+e);return n;default:throw new Error("Data cannot be decoded from JSON: "+e)}return Array.isArray(e)?e.map(function(e){return t.decode(e)}):"function"==typeof e||"object"==typeof e?d(e,function(e){return t.decode(e)}):e},e}();function h(e){var t,n=new Promise(function(n,r){t=setTimeout(function(){r(new o("deadline-exceeded","deadline-exceeded"))},e)});return{timer:t,promise:n}}var p=function(){function e(e,t,n,r,i,o){var a=this;void 0===i&&(i="us-central1"),this.app_=e,this.appCheckProvider=r,this.fetchImpl=o,this.serializer=new f,this.emulatorOrigin=null,this.INTERNAL={delete:function(){return Promise.resolve(a.deleteService())}},this.contextProvider=new u(t,n),this.cancelAllRequests=new Promise(function(e){a.deleteService=function(){return e()}});try{var s=new URL(i);this.customDomain=s.origin,this.region="us-central1"}catch(c){this.customDomain=null,this.region=i}}return Object.defineProperty(e.prototype,"app",{get:function(){return this.app_},enumerable:!1,configurable:!0}),e.prototype._url=function(e){var t=this.app_.options.projectId;return null!==this.emulatorOrigin?this.emulatorOrigin+"/"+t+"/"+this.region+"/"+e:null!==this.customDomain?this.customDomain+"/"+e:"https://"+this.region+"-"+t+".cloudfunctions.net/"+e},e.prototype.useEmulator=function(e,t){this.emulatorOrigin="http://"+e+":"+t},e.prototype.useFunctionsEmulator=function(e){this.emulatorOrigin=e},e.prototype.httpsCallable=function(e,t){var n=this;return function(r){return n.call(e,r,t||{})}},e.prototype.postJSON=function(e,n,r){return(0,t.__awaiter)(this,void 0,void 0,function(){var i,o,a;return(0,t.__generator)(this,function(t){switch(t.label){case 0:return r["Content-Type"]="application/json",[4,this.getAppCheckToken()];case 1:null!==(i=t.sent())&&(r["X-Firebase-AppCheck"]=i),t.label=2;case 2:return t.trys.push([2,4,,5]),[4,this.fetchImpl(e,{method:"POST",body:JSON.stringify(n),headers:r})];case 3:return o=t.sent(),[3,5];case 4:return t.sent(),[2,{status:0,json:null}];case 5:a=null,t.label=6;case 6:return t.trys.push([6,8,,9]),[4,o.json()];case 7:return a=t.sent(),[3,9];case 8:return t.sent(),[3,9];case 9:return[2,{status:o.status,json:a}]}})})},e.prototype.getAppCheckToken=function(){return(0,t.__awaiter)(this,void 0,void 0,function(){var e;return(0,t.__generator)(this,function(t){switch(t.label){case 0:return(e=this.appCheckProvider.getImmediate({optional:!0}))?[4,e.getToken()]:[3,2];case 1:return[2,t.sent().token];case 2:return[2,null]}})})},e.prototype.call=function(e,n,r){return(0,t.__awaiter)(this,void 0,void 0,function(){var i,a,u,c,l,d,f,p,v,m,_;return(0,t.__generator)(this,function(t){switch(t.label){case 0:return i=this._url(e),n=this.serializer.encode(n),a={data:n},u={},[4,this.contextProvider.getContext()];case 1:return(c=t.sent()).authToken&&(u.Authorization="Bearer "+c.authToken),c.instanceIdToken&&(u["Firebase-Instance-ID-Token"]=c.instanceIdToken),l=r.timeout||7e4,d=h(l),f=d.timer,p=d.promise,[4,Promise.race([g(f,this.postJSON(i,a,u)),p,g(f,this.cancelAllRequests)])];case 2:if(!(v=t.sent()))throw new o("cancelled","Firebase Functions instance was deleted.");if(m=s(v.status,v.json,this.serializer))throw m;if(!v.json)throw new o("internal","Response is not valid JSON object.");if(void 0===(_=v.json.data)&&(_=v.json.result),void 0===_)throw new o("internal","Response is missing data field.");return[2,{data:this.serializer.decode(_)}]}})})},e}();function g(e,n){return(0,t.__awaiter)(this,void 0,void 0,function(){var r;return(0,t.__generator)(this,function(t){switch(t.label){case 0:return[4,n];case 1:return r=t.sent(),clearTimeout(e),[2,r]}})})}var v="functions";function m(e,t){var r={Functions:p};e.INTERNAL.registerComponent(new n.Component(v,function(e,n){var r=n.instanceIdentifier,i=e.getProvider("app").getImmediate(),o=e.getProvider("auth-internal"),a=e.getProvider("app-check-internal"),s=e.getProvider("messaging");return new p(i,o,s,a,r,t)},"PUBLIC").setServiceProps(r).setMultipleInstances(!0))}var _="@firebase/functions",w="0.6.15";m(e.default,fetch.bind(self)),e.default.registerVersion(_,w);
486
- },{"@firebase/app":"VxYX","tslib":"f2sD","@firebase/component":"sLOu"}],"a7Bh":[function(require,module,exports) {
485
+ "use strict";var e=r(require("@firebase/app")),t=require("tslib"),n=require("@firebase/component");function r(e){return e&&e.__esModule?e:{default:e}}var i={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"},o=function(e){function n(t,r,i){var o=e.call(this,r)||this;return Object.setPrototypeOf(o,n.prototype),o.code=t,o.details=i,o}return(0,t.__extends)(n,e),n}(Error);function a(e){if(e>=200&&e<300)return"ok";switch(e){case 0:return"internal";case 400:return"invalid-argument";case 401:return"unauthenticated";case 403:return"permission-denied";case 404:return"not-found";case 409:return"aborted";case 429:return"resource-exhausted";case 499:return"cancelled";case 500:return"internal";case 501:return"unimplemented";case 503:return"unavailable";case 504:return"deadline-exceeded"}return"unknown"}function s(e,t,n){var r=a(e),s=r,u=void 0;try{var c=t&&t.error;if(c){var l=c.status;if("string"==typeof l){if(!i[l])return new o("internal","internal");r=i[l],s=l}var d=c.message;"string"==typeof d&&(s=d),void 0!==(u=c.details)&&(u=n.decode(u))}}catch(f){}return"ok"===r?null:new o(r,s,u)}var u=function(){function e(e,t){var n=this;this.auth=null,this.messaging=null,this.auth=e.getImmediate({optional:!0}),this.messaging=t.getImmediate({optional:!0}),this.auth||e.get().then(function(e){return n.auth=e},function(){}),this.messaging||t.get().then(function(e){return n.messaging=e},function(){})}return e.prototype.getAuthToken=function(){return(0,t.__awaiter)(this,void 0,void 0,function(){var e;return(0,t.__generator)(this,function(t){switch(t.label){case 0:if(!this.auth)return[2,void 0];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,this.auth.getToken()];case 2:return(e=t.sent())?[2,e.accessToken]:[2,void 0];case 3:return t.sent(),[2,void 0];case 4:return[2]}})})},e.prototype.getInstanceIdToken=function(){return(0,t.__awaiter)(this,void 0,void 0,function(){return(0,t.__generator)(this,function(e){switch(e.label){case 0:if(!(this.messaging&&"Notification"in self&&"granted"===Notification.permission))return[2,void 0];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.messaging.getToken()];case 2:return[2,e.sent()];case 3:return e.sent(),[2,void 0];case 4:return[2]}})})},e.prototype.getContext=function(){return(0,t.__awaiter)(this,void 0,void 0,function(){var e,n;return(0,t.__generator)(this,function(t){switch(t.label){case 0:return[4,this.getAuthToken()];case 1:return e=t.sent(),[4,this.getInstanceIdToken()];case 2:return n=t.sent(),[2,{authToken:e,instanceIdToken:n}]}})})},e}(),c="type.googleapis.com/google.protobuf.Int64Value",l="type.googleapis.com/google.protobuf.UInt64Value";function d(e,t){var n={};for(var r in e)e.hasOwnProperty(r)&&(n[r]=t(e[r]));return n}var f=function(){function e(){}return e.prototype.encode=function(e){var t=this;if(null==e)return null;if(e instanceof Number&&(e=e.valueOf()),"number"==typeof e&&isFinite(e))return e;if(!0===e||!1===e)return e;if("[object String]"===Object.prototype.toString.call(e))return e;if(e instanceof Date)return e.toISOString();if(Array.isArray(e))return e.map(function(e){return t.encode(e)});if("function"==typeof e||"object"==typeof e)return d(e,function(e){return t.encode(e)});throw new Error("Data cannot be encoded in JSON: "+e)},e.prototype.decode=function(e){var t=this;if(null==e)return e;if(e["@type"])switch(e["@type"]){case c:case l:var n=Number(e.value);if(isNaN(n))throw new Error("Data cannot be decoded from JSON: "+e);return n;default:throw new Error("Data cannot be decoded from JSON: "+e)}return Array.isArray(e)?e.map(function(e){return t.decode(e)}):"function"==typeof e||"object"==typeof e?d(e,function(e){return t.decode(e)}):e},e}();function h(e){var t,n=new Promise(function(n,r){t=setTimeout(function(){r(new o("deadline-exceeded","deadline-exceeded"))},e)});return{timer:t,promise:n}}var p=function(){function e(e,t,n,r,i,o){var a=this;void 0===i&&(i="us-central1"),this.app_=e,this.appCheckProvider=r,this.fetchImpl=o,this.serializer=new f,this.emulatorOrigin=null,this.INTERNAL={delete:function(){return Promise.resolve(a.deleteService())}},this.contextProvider=new u(t,n),this.cancelAllRequests=new Promise(function(e){a.deleteService=function(){return e()}});try{var s=new URL(i);this.customDomain=s.origin,this.region="us-central1"}catch(c){this.customDomain=null,this.region=i}}return Object.defineProperty(e.prototype,"app",{get:function(){return this.app_},enumerable:!1,configurable:!0}),e.prototype._url=function(e){var t=this.app_.options.projectId;return null!==this.emulatorOrigin?this.emulatorOrigin+"/"+t+"/"+this.region+"/"+e:null!==this.customDomain?this.customDomain+"/"+e:"https://"+this.region+"-"+t+".cloudfunctions.net/"+e},e.prototype.useEmulator=function(e,t){this.emulatorOrigin="http://"+e+":"+t},e.prototype.useFunctionsEmulator=function(e){this.emulatorOrigin=e},e.prototype.httpsCallable=function(e,t){var n=this;return function(r){return n.call(e,r,t||{})}},e.prototype.postJSON=function(e,n,r){return(0,t.__awaiter)(this,void 0,void 0,function(){var i,o,a;return(0,t.__generator)(this,function(t){switch(t.label){case 0:return r["Content-Type"]="application/json",[4,this.getAppCheckToken()];case 1:null!==(i=t.sent())&&(r["X-Firebase-AppCheck"]=i),t.label=2;case 2:return t.trys.push([2,4,,5]),[4,this.fetchImpl(e,{method:"POST",body:JSON.stringify(n),headers:r})];case 3:return o=t.sent(),[3,5];case 4:return t.sent(),[2,{status:0,json:null}];case 5:a=null,t.label=6;case 6:return t.trys.push([6,8,,9]),[4,o.json()];case 7:return a=t.sent(),[3,9];case 8:return t.sent(),[3,9];case 9:return[2,{status:o.status,json:a}]}})})},e.prototype.getAppCheckToken=function(){return(0,t.__awaiter)(this,void 0,void 0,function(){var e;return(0,t.__generator)(this,function(t){switch(t.label){case 0:return(e=this.appCheckProvider.getImmediate({optional:!0}))?[4,e.getToken()]:[3,2];case 1:return[2,t.sent().token];case 2:return[2,null]}})})},e.prototype.call=function(e,n,r){return(0,t.__awaiter)(this,void 0,void 0,function(){var i,a,u,c,l,d,f,p,v,m,_;return(0,t.__generator)(this,function(t){switch(t.label){case 0:return i=this._url(e),n=this.serializer.encode(n),a={data:n},u={},[4,this.contextProvider.getContext()];case 1:return(c=t.sent()).authToken&&(u.Authorization="Bearer "+c.authToken),c.instanceIdToken&&(u["Firebase-Instance-ID-Token"]=c.instanceIdToken),l=r.timeout||7e4,d=h(l),f=d.timer,p=d.promise,[4,Promise.race([g(f,this.postJSON(i,a,u)),p,g(f,this.cancelAllRequests)])];case 2:if(!(v=t.sent()))throw new o("cancelled","Firebase Functions instance was deleted.");if(m=s(v.status,v.json,this.serializer))throw m;if(!v.json)throw new o("internal","Response is not valid JSON object.");if(void 0===(_=v.json.data)&&(_=v.json.result),void 0===_)throw new o("internal","Response is missing data field.");return[2,{data:this.serializer.decode(_)}]}})})},e}();function g(e,n){return(0,t.__awaiter)(this,void 0,void 0,function(){var r;return(0,t.__generator)(this,function(t){switch(t.label){case 0:return[4,n];case 1:return r=t.sent(),clearTimeout(e),[2,r]}})})}var v="functions";function m(e,t){var r={Functions:p};e.INTERNAL.registerComponent(new n.Component(v,function(e,n){var r=n.instanceIdentifier,i=e.getProvider("app").getImmediate(),o=e.getProvider("auth-internal"),a=e.getProvider("app-check-internal"),s=e.getProvider("messaging");return new p(i,o,s,a,r,t)},"PUBLIC").setServiceProps(r).setMultipleInstances(!0))}var _="@firebase/functions",w="0.6.16";m(e.default,fetch.bind(self)),e.default.registerVersion(_,w);
486
+ },{"@firebase/app":"VxYX","tslib":"vCxL","@firebase/component":"sLOu"}],"a7Bh":[function(require,module,exports) {
487
487
  "use strict";require("@firebase/functions");
488
488
  },{"@firebase/functions":"SScM"}],"ueHA":[function(require,module,exports) {
489
489
  var global = arguments[3];
490
490
  var t=arguments[3];Object.defineProperty(exports,"__esModule",{value:!0}),exports.getStatEventTarget=exports.default=exports.createWebChannelTransport=exports.XhrIo=exports.WebChannel=exports.Stat=exports.FetchXmlHttpFactory=exports.EventType=exports.Event=exports.ErrorCode=void 0;var i=function(t,e){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&(t[e]=i[e])})(t,e)};function e(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function n(t){var i="function"==typeof Symbol&&Symbol.iterator,e=i&&t[i],n=0;if(e)return e.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(i?"Object is not iterable.":"Symbol.iterator is not defined.")}var r,s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:void 0!==t?t:"undefined"!=typeof self?self:{},o=o||{},h=s||self;function a(){}function l(t){var i=typeof t;return"array"==(i="object"!=i?i:t?Array.isArray(t)?"array":i:"null")||"object"==i&&"number"==typeof t.length}function u(t){var i=typeof t;return"object"==i&&null!=t||"function"==i}function c(t){return Object.prototype.hasOwnProperty.call(t,f)&&t[f]||(t[f]=++g)}var f="closure_uid_"+(1e9*Math.random()>>>0),g=0;function p(t,i,e){return t.call.apply(t.bind,arguments)}function v(t,i,e){if(!t)throw Error();if(2<arguments.length){var n=Array.prototype.slice.call(arguments,2);return function(){var e=Array.prototype.slice.call(arguments);return Array.prototype.unshift.apply(e,n),t.apply(i,e)}}return function(){return t.apply(i,arguments)}}function d(t,i,e){return(d=Function.prototype.bind&&-1!=Function.prototype.bind.toString().indexOf("native code")?p:v).apply(null,arguments)}function y(t,i){var e=Array.prototype.slice.call(arguments,1);return function(){var i=e.slice();return i.push.apply(i,arguments),t.apply(this,i)}}function m(t,i){function e(){}e.prototype=i.prototype,t.Z=i.prototype,t.prototype=new e,t.prototype.constructor=t,t.Vb=function(t,e,n){for(var r=Array(arguments.length-2),s=2;s<arguments.length;s++)r[s-2]=arguments[s];return i.prototype[e].apply(t,r)}}function b(){this.s=this.s,this.o=this.o}var w=0,T={};b.prototype.s=!1,b.prototype.na=function(){if(!this.s&&(this.s=!0,this.M(),0!=w)){var t=c(this);delete T[t]}},b.prototype.M=function(){if(this.o)for(;this.o.length;)this.o.shift()()};var E=Array.prototype.indexOf?function(t,i){return Array.prototype.indexOf.call(t,i,void 0)}:function(t,i){if("string"==typeof t)return"string"!=typeof i||1!=i.length?-1:t.indexOf(i,0);for(var e=0;e<t.length;e++)if(e in t&&t[e]===i)return e;return-1},S=Array.prototype.forEach?function(t,i,e){Array.prototype.forEach.call(t,i,e)}:function(t,i,e){for(var n=t.length,r="string"==typeof t?t.split(""):t,s=0;s<n;s++)s in r&&i.call(e,r[s],s,t)};function x(t){t:{for(var i=Ne,e=t.length,n="string"==typeof t?t.split(""):t,r=0;r<e;r++)if(r in n&&i.call(void 0,n[r],r,t)){i=r;break t}i=-1}return 0>i?null:"string"==typeof t?t.charAt(i):t[i]}function j(t){return Array.prototype.concat.apply([],arguments)}function C(t){var i=t.length;if(0<i){for(var e=Array(i),n=0;n<i;n++)e[n]=t[n];return e}return[]}function I(t){return/^[\s\xa0]*$/.test(t)}var A,R=String.prototype.trim?function(t){return t.trim()}:function(t){return/^[\s\xa0]*([\s\S]*?)[\s\xa0]*$/.exec(t)[1]};function O(t,i){return-1!=t.indexOf(i)}function P(t,i){return t<i?-1:t>i?1:0}t:{var D=h.navigator;if(D){var M=D.userAgent;if(M){A=M;break t}}A=""}function L(t,i,e){for(var n in t)i.call(e,t[n],n,t)}function X(t){var i={};for(var e in t)i[e]=t[e];return i}var H="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" ");function _(t,i){for(var e,n,r=1;r<arguments.length;r++){for(e in n=arguments[r])t[e]=n[e];for(var s=0;s<H.length;s++)e=H[s],Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])}}function k(t){return k[" "](t),t}function B(t){var i=Z;return Object.prototype.hasOwnProperty.call(i,9)?i[9]:i[9]=t(9)}k[" "]=a;var F,N=O(A,"Opera"),U=O(A,"Trident")||O(A,"MSIE"),K=O(A,"Edge"),Y=K||U,G=O(A,"Gecko")&&!(O(A.toLowerCase(),"webkit")&&!O(A,"Edge"))&&!(O(A,"Trident")||O(A,"MSIE"))&&!O(A,"Edge"),J=O(A.toLowerCase(),"webkit")&&!O(A,"Edge");function W(){var t=h.document;return t?t.documentMode:void 0}t:{var V="",$=function(){var t=A;return G?/rv:([^\);]+)(\)|;)/.exec(t):K?/Edge\/([\d\.]+)/.exec(t):U?/\b(?:MSIE|rv)[: ]([^\);]+)(\)|;)/.exec(t):J?/WebKit\/(\S+)/.exec(t):N?/(?:Version)[ \/]?(\S+)/.exec(t):void 0}();if($&&(V=$?$[1]:""),U){var q=W();if(null!=q&&q>parseFloat(V)){F=String(q);break t}}F=V}var z,Z={};function Q(){return B(function(){for(var t=0,i=R(String(F)).split("."),e=R("9").split("."),n=Math.max(i.length,e.length),r=0;0==t&&r<n;r++){var s=i[r]||"",o=e[r]||"";do{if(s=/(\d*)(\D*)(.*)/.exec(s)||["","","",""],o=/(\d*)(\D*)(.*)/.exec(o)||["","","",""],0==s[0].length&&0==o[0].length)break;t=P(0==s[1].length?0:parseInt(s[1],10),0==o[1].length?0:parseInt(o[1],10))||P(0==s[2].length,0==o[2].length)||P(s[2],o[2]),s=s[3],o=o[3]}while(0==t)}return 0<=t})}if(h.document&&U){var tt=W();z=tt||(parseInt(F,10)||void 0)}else z=void 0;var it=z,et=function(){if(!h.addEventListener||!Object.defineProperty)return!1;var t=!1,i=Object.defineProperty({},"passive",{get:function(){t=!0}});try{h.addEventListener("test",a,i),h.removeEventListener("test",a,i)}catch(e){}return t}();function nt(t,i){this.type=t,this.g=this.target=i,this.defaultPrevented=!1}function rt(t,i){if(nt.call(this,t?t.type:""),this.relatedTarget=this.g=this.target=null,this.button=this.screenY=this.screenX=this.clientY=this.clientX=0,this.key="",this.metaKey=this.shiftKey=this.altKey=this.ctrlKey=!1,this.state=null,this.pointerId=0,this.pointerType="",this.i=null,t){var e=this.type=t.type,n=t.changedTouches&&t.changedTouches.length?t.changedTouches[0]:null;if(this.target=t.target||t.srcElement,this.g=i,i=t.relatedTarget){if(G){t:{try{k(i.nodeName);var r=!0;break t}catch(s){}r=!1}r||(i=null)}}else"mouseover"==e?i=t.fromElement:"mouseout"==e&&(i=t.toElement);this.relatedTarget=i,n?(this.clientX=void 0!==n.clientX?n.clientX:n.pageX,this.clientY=void 0!==n.clientY?n.clientY:n.pageY,this.screenX=n.screenX||0,this.screenY=n.screenY||0):(this.clientX=void 0!==t.clientX?t.clientX:t.pageX,this.clientY=void 0!==t.clientY?t.clientY:t.pageY,this.screenX=t.screenX||0,this.screenY=t.screenY||0),this.button=t.button,this.key=t.key||"",this.ctrlKey=t.ctrlKey,this.altKey=t.altKey,this.shiftKey=t.shiftKey,this.metaKey=t.metaKey,this.pointerId=t.pointerId||0,this.pointerType="string"==typeof t.pointerType?t.pointerType:st[t.pointerType]||"",this.state=t.state,this.i=t,t.defaultPrevented&&rt.Z.h.call(this)}}nt.prototype.h=function(){this.defaultPrevented=!0},m(rt,nt);var st={2:"touch",3:"pen",4:"mouse"};rt.prototype.h=function(){rt.Z.h.call(this);var t=this.i;t.preventDefault?t.preventDefault():t.returnValue=!1};var ot="closure_listenable_"+(1e6*Math.random()|0),ht=0;function at(t,i,e,n,r){this.listener=t,this.proxy=null,this.src=i,this.type=e,this.capture=!!n,this.ia=r,this.key=++ht,this.ca=this.fa=!1}function lt(t){t.ca=!0,t.listener=null,t.proxy=null,t.src=null,t.ia=null}function ut(t){this.src=t,this.g={},this.h=0}function ct(t,i){var e=i.type;if(e in t.g){var n,r=t.g[e],s=E(r,i);(n=0<=s)&&Array.prototype.splice.call(r,s,1),n&&(lt(i),0==t.g[e].length&&(delete t.g[e],t.h--))}}function ft(t,i,e,n){for(var r=0;r<t.length;++r){var s=t[r];if(!s.ca&&s.listener==i&&s.capture==!!e&&s.ia==n)return r}return-1}ut.prototype.add=function(t,i,e,n,r){var s=t.toString();(t=this.g[s])||(t=this.g[s]=[],this.h++);var o=ft(t,i,n,r);return-1<o?(i=t[o],e||(i.fa=!1)):((i=new at(i,this.src,s,!!n,r)).fa=e,t.push(i)),i};var gt="closure_lm_"+(1e6*Math.random()|0),pt={};function vt(t,i,e,n,r){if(n&&n.once)return mt(t,i,e,n,r);if(Array.isArray(i)){for(var s=0;s<i.length;s++)vt(t,i[s],e,n,r);return null}return e=jt(e),t&&t[ot]?t.N(i,e,u(n)?!!n.capture:!!n,r):dt(t,i,e,!1,n,r)}function dt(t,i,e,n,r,s){if(!i)throw Error("Invalid event type");var o=u(r)?!!r.capture:!!r,h=St(t);if(h||(t[gt]=h=new ut(t)),(e=h.add(i,e,n,o,s)).proxy)return e;if(n=yt(),e.proxy=n,n.src=t,n.listener=e,t.addEventListener)et||(r=o),void 0===r&&(r=!1),t.addEventListener(i.toString(),n,r);else if(t.attachEvent)t.attachEvent(Tt(i.toString()),n);else{if(!t.addListener||!t.removeListener)throw Error("addEventListener and attachEvent are unavailable.");t.addListener(n)}return e}function yt(){var t=Et;return function i(e){return t.call(i.src,i.listener,e)}}function mt(t,i,e,n,r){if(Array.isArray(i)){for(var s=0;s<i.length;s++)mt(t,i[s],e,n,r);return null}return e=jt(e),t&&t[ot]?t.O(i,e,u(n)?!!n.capture:!!n,r):dt(t,i,e,!0,n,r)}function bt(t,i,e,n,r){if(Array.isArray(i))for(var s=0;s<i.length;s++)bt(t,i[s],e,n,r);else n=u(n)?!!n.capture:!!n,e=jt(e),t&&t[ot]?(t=t.i,(i=String(i).toString())in t.g&&(-1<(e=ft(s=t.g[i],e,n,r))&&(lt(s[e]),Array.prototype.splice.call(s,e,1),0==s.length&&(delete t.g[i],t.h--)))):t&&(t=St(t))&&(i=t.g[i.toString()],t=-1,i&&(t=ft(i,e,n,r)),(e=-1<t?i[t]:null)&&wt(e))}function wt(t){if("number"!=typeof t&&t&&!t.ca){var i=t.src;if(i&&i[ot])ct(i.i,t);else{var e=t.type,n=t.proxy;i.removeEventListener?i.removeEventListener(e,n,t.capture):i.detachEvent?i.detachEvent(Tt(e),n):i.addListener&&i.removeListener&&i.removeListener(n),(e=St(i))?(ct(e,t),0==e.h&&(e.src=null,i[gt]=null)):lt(t)}}}function Tt(t){return t in pt?pt[t]:pt[t]="on"+t}function Et(t,i){if(t.ca)t=!0;else{i=new rt(i,this);var e=t.listener,n=t.ia||t.src;t.fa&&wt(t),t=e.call(n,i)}return t}function St(t){return(t=t[gt])instanceof ut?t:null}var xt="__closure_events_fn_"+(1e9*Math.random()>>>0);function jt(t){return"function"==typeof t?t:(t[xt]||(t[xt]=function(i){return t.handleEvent(i)}),t[xt])}function Ct(){b.call(this),this.i=new ut(this),this.P=this,this.I=null}function It(t,i){var e,n=t.I;if(n)for(e=[];n;n=n.I)e.push(n);if(t=t.P,n=i.type||i,"string"==typeof i)i=new nt(i,t);else if(i instanceof nt)i.target=i.target||t;else{var r=i;_(i=new nt(n,t),r)}if(r=!0,e)for(var s=e.length-1;0<=s;s--){var o=i.g=e[s];r=At(o,n,!0,i)&&r}if(r=At(o=i.g=t,n,!0,i)&&r,r=At(o,n,!1,i)&&r,e)for(s=0;s<e.length;s++)r=At(o=i.g=e[s],n,!1,i)&&r}function At(t,i,e,n){if(!(i=t.i.g[String(i)]))return!0;i=i.concat();for(var r=!0,s=0;s<i.length;++s){var o=i[s];if(o&&!o.ca&&o.capture==e){var h=o.listener,a=o.ia||o.src;o.fa&&ct(t.i,o),r=!1!==h.call(a,n)&&r}}return r&&!n.defaultPrevented}m(Ct,b),Ct.prototype[ot]=!0,Ct.prototype.removeEventListener=function(t,i,e,n){bt(this,t,i,e,n)},Ct.prototype.M=function(){if(Ct.Z.M.call(this),this.i){var t,i=this.i;for(t in i.g){for(var e=i.g[t],n=0;n<e.length;n++)lt(e[n]);delete i.g[t],i.h--}}this.I=null},Ct.prototype.N=function(t,i,e,n){return this.i.add(String(t),i,!1,e,n)},Ct.prototype.O=function(t,i,e,n){return this.i.add(String(t),i,!0,e,n)};var Rt=h.JSON.stringify;function Ot(){var t=Bt,i=null;return t.g&&(i=t.g,t.g=t.g.next,t.g||(t.h=null),i.next=null),i}var Pt,Dt=function(){function t(){this.h=this.g=null}return t.prototype.add=function(t,i){var e=Mt.get();e.set(t,i),this.h?this.h.next=e:this.g=e,this.h=e},t}(),Mt=new(function(){function t(t,i){this.i=t,this.j=i,this.h=0,this.g=null}return t.prototype.get=function(){var t;return 0<this.h?(this.h--,t=this.g,this.g=t.next,t.next=null):t=this.i(),t},t}())(function(){return new Lt},function(t){return t.reset()}),Lt=function(){function t(){this.next=this.g=this.h=null}return t.prototype.set=function(t,i){this.h=t,this.g=i,this.next=null},t.prototype.reset=function(){this.next=this.g=this.h=null},t}();function Xt(t){h.setTimeout(function(){throw t},0)}function Ht(t,i){Pt||_t(),kt||(Pt(),kt=!0),Bt.add(t,i)}function _t(){var t=h.Promise.resolve(void 0);Pt=function(){t.then(Ft)}}var kt=!1,Bt=new Dt;function Ft(){for(var t;t=Ot();){try{t.h.call(t.g)}catch(e){Xt(e)}var i=Mt;i.j(t),100>i.h&&(i.h++,t.next=i.g,i.g=t)}kt=!1}function Nt(t,i){Ct.call(this),this.h=t||1,this.g=i||h,this.j=d(this.kb,this),this.l=Date.now()}function Ut(t){t.da=!1,t.S&&(t.g.clearTimeout(t.S),t.S=null)}function Kt(t,i,e){if("function"==typeof t)e&&(t=d(t,e));else{if(!t||"function"!=typeof t.handleEvent)throw Error("Invalid listener argument");t=d(t.handleEvent,t)}return 2147483647<Number(i)?-1:h.setTimeout(t,i||0)}function Yt(t){t.g=Kt(function(){t.g=null,t.i&&(t.i=!1,Yt(t))},t.j);var i=t.h;t.h=null,t.m.apply(null,i)}m(Nt,Ct),(r=Nt.prototype).da=!1,r.S=null,r.kb=function(){if(this.da){var t=Date.now()-this.l;0<t&&t<.8*this.h?this.S=this.g.setTimeout(this.j,this.h-t):(this.S&&(this.g.clearTimeout(this.S),this.S=null),It(this,"tick"),this.da&&(Ut(this),this.start()))}},r.start=function(){this.da=!0,this.S||(this.S=this.g.setTimeout(this.j,this.h),this.l=Date.now())},r.M=function(){Nt.Z.M.call(this),Ut(this),delete this.g};var Gt=function(t){function i(i,e){var n=t.call(this)||this;return n.m=i,n.j=e,n.h=null,n.i=!1,n.g=null,n}return e(i,t),i.prototype.l=function(t){this.h=arguments,this.g?this.i=!0:Yt(this)},i.prototype.M=function(){t.prototype.M.call(this),this.g&&(h.clearTimeout(this.g),this.g=null,this.i=!1,this.h=null)},i}(b);function Jt(t){b.call(this),this.h=t,this.g={}}m(Jt,b);var Wt=[];function Vt(t,i,e,n){Array.isArray(e)||(e&&(Wt[0]=e.toString()),e=Wt);for(var r=0;r<e.length;r++){var s=vt(i,e[r],n||t.handleEvent,!1,t.h||t);if(!s)break;t.g[s.key]=s}}function $t(t){L(t.g,function(t,i){this.g.hasOwnProperty(i)&&wt(t)},t),t.g={}}function qt(){this.g=!0}function zt(t,i,e,n,r,s){t.info(function(){if(t.g)if(s)for(var o="",h=s.split("&"),a=0;a<h.length;a++){var l=h[a].split("=");if(1<l.length){var u=l[0];l=l[1];var c=u.split("_");o=2<=c.length&&"type"==c[1]?o+(u+"=")+l+"&":o+(u+"=redacted&")}}else o=null;else o=s;return"XMLHTTP REQ ("+n+") [attempt "+r+"]: "+i+"\n"+e+"\n"+o})}function Zt(t,i,e,n,r,s,o){t.info(function(){return"XMLHTTP RESP ("+n+") [ attempt "+r+"]: "+i+"\n"+e+"\n"+s+" "+o})}function Qt(t,i,e,n){t.info(function(){return"XMLHTTP TEXT ("+i+"): "+ii(t,e)+(n?" "+n:"")})}function ti(t,i){t.info(function(){return"TIMEOUT: "+i})}function ii(t,i){if(!t.g)return i;if(!i)return null;try{var e=JSON.parse(i);if(e)for(t=0;t<e.length;t++)if(Array.isArray(e[t])){var n=e[t];if(!(2>n.length)){var r=n[1];if(Array.isArray(r)&&!(1>r.length)){var s=r[0];if("noop"!=s&&"stop"!=s&&"close"!=s)for(var o=1;o<r.length;o++)r[o]=""}}}return Rt(e)}catch(h){return i}}Jt.prototype.M=function(){Jt.Z.M.call(this),$t(this)},Jt.prototype.handleEvent=function(){throw Error("EventHandler.handleEvent not implemented")},qt.prototype.Aa=function(){this.g=!1},qt.prototype.info=function(){};var ei={},ni=null;function ri(){return ni=ni||new Ct}function si(t){nt.call(this,ei.Ma,t)}function oi(t){var i=ri();It(i,new si(i,t))}function hi(t,i){nt.call(this,ei.STAT_EVENT,t),this.stat=i}function ai(t){var i=ri();It(i,new hi(i,t))}function li(t,i){nt.call(this,ei.Na,t),this.size=i}function ui(t,i){if("function"!=typeof t)throw Error("Fn must not be null and must be a function");return h.setTimeout(function(){t()},i)}ei.Ma="serverreachability",m(si,nt),ei.STAT_EVENT="statevent",m(hi,nt),ei.Na="timingevent",m(li,nt);var ci={NO_ERROR:0,lb:1,yb:2,xb:3,sb:4,wb:5,zb:6,Ja:7,TIMEOUT:8,Cb:9},fi={qb:"complete",Mb:"success",Ka:"error",Ja:"abort",Eb:"ready",Fb:"readystatechange",TIMEOUT:"timeout",Ab:"incrementaldata",Db:"progress",tb:"downloadprogress",Ub:"uploadprogress"};function gi(){}function pi(t){return t.h||(t.h=t.i())}function vi(){}gi.prototype.h=null;var di,yi={OPEN:"a",pb:"b",Ka:"c",Bb:"d"};function mi(){nt.call(this,"d")}function bi(){nt.call(this,"c")}function wi(){}function Ti(t,i,e,n){this.l=t,this.j=i,this.m=e,this.X=n||1,this.V=new Jt(this),this.P=Si,t=Y?125:void 0,this.W=new Nt(t),this.H=null,this.i=!1,this.s=this.A=this.v=this.K=this.F=this.Y=this.B=null,this.D=[],this.g=null,this.C=0,this.o=this.u=null,this.N=-1,this.I=!1,this.O=0,this.L=null,this.aa=this.J=this.$=this.U=!1,this.h=new Ei}function Ei(){this.i=null,this.g="",this.h=!1}m(mi,nt),m(bi,nt),m(wi,gi),wi.prototype.g=function(){return new XMLHttpRequest},wi.prototype.i=function(){return{}},di=new wi;var Si=45e3,xi={},ji={};function Ci(t,i,e){t.K=1,t.v=zi(Gi(i)),t.s=e,t.U=!0,Ii(t,null)}function Ii(t,i){t.F=Date.now(),Pi(t),t.A=Gi(t.v);var e=t.A,n=t.X;Array.isArray(n)||(n=[String(n)]),fe(e.h,"t",n),t.C=0,e=t.l.H,t.h=new Ei,t.g=bn(t.l,e?i:null,!t.s),0<t.O&&(t.L=new Gt(d(t.Ia,t,t.g),t.O)),Vt(t.V,t.g,"readystatechange",t.gb),i=t.H?X(t.H):{},t.s?(t.u||(t.u="POST"),i["Content-Type"]="application/x-www-form-urlencoded",t.g.ea(t.A,t.u,t.s,i)):(t.u="GET",t.g.ea(t.A,t.u,null,i)),oi(1),zt(t.j,t.u,t.A,t.m,t.X,t.s)}function Ai(t){return!!t.g&&("GET"==t.u&&2!=t.K&&t.l.Ba)}function Ri(t,i,e){for(var n,r=!0;!t.I&&t.C<e.length;){if((n=Oi(t,e))==ji){4==i&&(t.o=4,ai(14),r=!1),Qt(t.j,t.m,null,"[Incomplete Response]");break}if(n==xi){t.o=4,ai(15),Qt(t.j,t.m,e,"[Invalid Chunk]"),r=!1;break}Qt(t.j,t.m,n,null),Hi(t,n)}Ai(t)&&n!=ji&&n!=xi&&(t.h.g="",t.C=0),4!=i||0!=e.length||t.h.h||(t.o=1,ai(16),r=!1),t.i=t.i&&r,r?0<e.length&&!t.aa&&(t.aa=!0,(i=t.l).g==t&&i.$&&!i.L&&(i.h.info("Great, no buffering proxy detected. Bytes received: "+e.length),cn(i),i.L=!0,ai(11))):(Qt(t.j,t.m,e,"[Invalid Chunked Response]"),Xi(t),Li(t))}function Oi(t,i){var e=t.C,n=i.indexOf("\n",e);return-1==n?ji:(e=Number(i.substring(e,n)),isNaN(e)?xi:(n+=1)+e>i.length?ji:(i=i.substr(n,e),t.C=n+e,i))}function Pi(t){t.Y=Date.now()+t.P,Di(t,t.P)}function Di(t,i){if(null!=t.B)throw Error("WatchDog timer not null");t.B=ui(d(t.eb,t),i)}function Mi(t){t.B&&(h.clearTimeout(t.B),t.B=null)}function Li(t){0==t.l.G||t.I||pn(t.l,t)}function Xi(t){Mi(t);var i=t.L;i&&"function"==typeof i.na&&i.na(),t.L=null,Ut(t.W),$t(t.V),t.g&&(i=t.g,t.g=null,i.abort(),i.na())}function Hi(t,i){try{var e=t.l;if(0!=e.G&&(e.g==t||we(e.i,t)))if(e.I=t.N,!t.J&&we(e.i,t)&&3==e.G){try{var n=e.Ca.g.parse(i)}catch(s){n=null}if(Array.isArray(n)&&3==n.length){var r=n;if(0==r[0]){t:if(!e.u){if(e.g){if(!(e.g.F+3e3<t.F))break t;gn(e),tn(e)}un(e),ai(18)}}else e.ta=r[1],0<e.ta-e.U&&37500>r[2]&&e.N&&0==e.A&&!e.v&&(e.v=ui(d(e.ab,e),6e3));if(1>=be(e.i)&&e.ka){try{e.ka()}catch(s){}e.ka=void 0}}else dn(e,11)}else if((t.J||e.g==t)&&gn(e),!I(i))for(r=e.Ca.g.parse(i),i=0;i<r.length;i++){var s=r[i];if(e.U=s[0],s=s[1],2==e.G)if("c"==s[0]){e.J=s[1],e.la=s[2];var o=s[3];null!=o&&(e.ma=o,e.h.info("VER="+e.ma));var h=s[4];null!=h&&(e.za=h,e.h.info("SVER="+e.za));var a=s[5];null!=a&&"number"==typeof a&&0<a&&(n=1.5*a,e.K=n,e.h.info("backChannelRequestTimeoutMs_="+n)),n=e;var l=t.g;if(l){var u=l.g?l.g.getResponseHeader("X-Client-Wire-Protocol"):null;if(u){var c=n.i;!c.g&&(O(u,"spdy")||O(u,"quic")||O(u,"h2"))&&(c.j=c.l,c.g=new Set,c.h&&(Te(c,c.h),c.h=null))}if(n.D){var f=l.g?l.g.getResponseHeader("X-HTTP-Session-Id"):null;f&&(n.sa=f,qi(n.F,n.D,f))}}e.G=3,e.j&&e.j.xa(),e.$&&(e.O=Date.now()-t.F,e.h.info("Handshake RTT: "+e.O+"ms"));var g=t;if((n=e).oa=mn(n,n.H?n.la:null,n.W),g.J){Ee(n.i,g);var p=g,v=n.K;v&&p.setTimeout(v),p.B&&(Mi(p),Pi(p)),n.g=g}else ln(n);0<e.l.length&&rn(e)}else"stop"!=s[0]&&"close"!=s[0]||dn(e,7);else 3==e.G&&("stop"==s[0]||"close"==s[0]?"stop"==s[0]?dn(e,7):Qe(e):"noop"!=s[0]&&e.j&&e.j.wa(s),e.A=0)}oi(4)}catch(s){}}function _i(t){if(t.R&&"function"==typeof t.R)return t.R();if("string"==typeof t)return t.split("");if(l(t)){for(var i=[],e=t.length,n=0;n<e;n++)i.push(t[n]);return i}for(n in i=[],e=0,t)i[e++]=t[n];return i}function ki(t,i){if(t.forEach&&"function"==typeof t.forEach)t.forEach(i,void 0);else if(l(t)||"string"==typeof t)S(t,i,void 0);else{if(t.T&&"function"==typeof t.T)var e=t.T();else if(t.R&&"function"==typeof t.R)e=void 0;else if(l(t)||"string"==typeof t){e=[];for(var n=t.length,r=0;r<n;r++)e.push(r)}else for(r in e=[],n=0,t)e[n++]=r;r=(n=_i(t)).length;for(var s=0;s<r;s++)i.call(void 0,n[s],e&&e[s],t)}}function Bi(t,i){this.h={},this.g=[],this.i=0;var e=arguments.length;if(1<e){if(e%2)throw Error("Uneven number of arguments");for(var n=0;n<e;n+=2)this.set(arguments[n],arguments[n+1])}else if(t)if(t instanceof Bi)for(e=t.T(),n=0;n<e.length;n++)this.set(e[n],t.get(e[n]));else for(n in t)this.set(n,t[n])}function Fi(t){if(t.i!=t.g.length){for(var i=0,e=0;i<t.g.length;){var n=t.g[i];Ni(t.h,n)&&(t.g[e++]=n),i++}t.g.length=e}if(t.i!=t.g.length){var r={};for(e=i=0;i<t.g.length;)Ni(r,n=t.g[i])||(t.g[e++]=n,r[n]=1),i++;t.g.length=e}}function Ni(t,i){return Object.prototype.hasOwnProperty.call(t,i)}(r=Ti.prototype).setTimeout=function(t){this.P=t},r.gb=function(t){t=t.target;var i=this.L;i&&3==We(t)?i.l():this.Ia(t)},r.Ia=function(t){try{if(t==this.g)t:{var i=We(this.g),e=this.g.Da(),n=this.g.ba();if(!(3>i)&&(3!=i||Y||this.g&&(this.h.h||this.g.ga()||Ve(this.g)))){this.I||4!=i||7==e||oi(8==e||0>=n?3:2),Mi(this);var r=this.g.ba();this.N=r;i:if(Ai(this)){var s=Ve(this.g);t="";var o=s.length,a=4==We(this.g);if(!this.h.i){if("undefined"==typeof TextDecoder){Xi(this),Li(this);var l="";break i}this.h.i=new h.TextDecoder}for(e=0;e<o;e++)this.h.h=!0,t+=this.h.i.decode(s[e],{stream:a&&e==o-1});s.splice(0,o),this.h.g+=t,this.C=0,l=this.h.g}else l=this.g.ga();if(this.i=200==r,Zt(this.j,this.u,this.A,this.m,this.X,i,r),this.i){if(this.$&&!this.J){i:{if(this.g){var u,c=this.g;if((u=c.g?c.g.getResponseHeader("X-HTTP-Initial-Response"):null)&&!I(u)){var f=u;break i}}f=null}if(!(r=f)){this.i=!1,this.o=3,ai(12),Xi(this),Li(this);break t}Qt(this.j,this.m,r,"Initial handshake response via X-HTTP-Initial-Response"),this.J=!0,Hi(this,r)}this.U?(Ri(this,i,l),Y&&this.i&&3==i&&(Vt(this.V,this.W,"tick",this.fb),this.W.start())):(Qt(this.j,this.m,l,null),Hi(this,l)),4==i&&Xi(this),this.i&&!this.I&&(4==i?pn(this.l,this):(this.i=!1,Pi(this)))}else 400==r&&0<l.indexOf("Unknown SID")?(this.o=3,ai(12)):(this.o=0,ai(13)),Xi(this),Li(this)}}}catch(i){}},r.fb=function(){if(this.g){var t=We(this.g),i=this.g.ga();this.C<i.length&&(Mi(this),Ri(this,t,i),this.i&&4!=t&&Pi(this))}},r.cancel=function(){this.I=!0,Xi(this)},r.eb=function(){this.B=null;var t=Date.now();0<=t-this.Y?(ti(this.j,this.A),2!=this.K&&(oi(3),ai(17)),Xi(this),this.o=2,Li(this)):Di(this,this.Y-t)},(r=Bi.prototype).R=function(){Fi(this);for(var t=[],i=0;i<this.g.length;i++)t.push(this.h[this.g[i]]);return t},r.T=function(){return Fi(this),this.g.concat()},r.get=function(t,i){return Ni(this.h,t)?this.h[t]:i},r.set=function(t,i){Ni(this.h,t)||(this.i++,this.g.push(t)),this.h[t]=i},r.forEach=function(t,i){for(var e=this.T(),n=0;n<e.length;n++){var r=e[n],s=this.get(r);t.call(i,s,r,this)}};var Ui=/^(?:([^:/?#.]+):)?(?:\/\/(?:([^\\/?#]*)@)?([^\\/?#]*?)(?::([0-9]+))?(?=[\\/?#]|$))?([^?#]+)?(?:\?([^#]*))?(?:#([\s\S]*))?$/;function Ki(t,i){if(t){t=t.split("&");for(var e=0;e<t.length;e++){var n=t[e].indexOf("="),r=null;if(0<=n){var s=t[e].substring(0,n);r=t[e].substring(n+1)}else s=t[e];i(s,r?decodeURIComponent(r.replace(/\+/g," ")):"")}}}function Yi(t,i){if(this.i=this.s=this.j="",this.m=null,this.o=this.l="",this.g=!1,t instanceof Yi){this.g=void 0!==i?i:t.g,Ji(this,t.j),this.s=t.s,Wi(this,t.i),Vi(this,t.m),this.l=t.l,i=t.h;var e=new ae;e.i=i.i,i.g&&(e.g=new Bi(i.g),e.h=i.h),$i(this,e),this.o=t.o}else t&&(e=String(t).match(Ui))?(this.g=!!i,Ji(this,e[1]||"",!0),this.s=te(e[2]||""),Wi(this,e[3]||"",!0),Vi(this,e[4]),this.l=te(e[5]||"",!0),$i(this,e[6]||"",!0),this.o=te(e[7]||"")):(this.g=!!i,this.h=new ae(null,this.g))}function Gi(t){return new Yi(t)}function Ji(t,i,e){t.j=e?te(i,!0):i,t.j&&(t.j=t.j.replace(/:$/,""))}function Wi(t,i,e){t.i=e?te(i,!0):i}function Vi(t,i){if(i){if(i=Number(i),isNaN(i)||0>i)throw Error("Bad port number "+i);t.m=i}else t.m=null}function $i(t,i,e){i instanceof ae?(t.h=i,pe(t.h,t.g)):(e||(i=ie(i,oe)),t.h=new ae(i,t.g))}function qi(t,i,e){t.h.set(i,e)}function zi(t){return qi(t,"zx",Math.floor(2147483648*Math.random()).toString(36)+Math.abs(Math.floor(2147483648*Math.random())^Date.now()).toString(36)),t}function Zi(t){return t instanceof Yi?Gi(t):new Yi(t,void 0)}function Qi(t,i,e,n){var r=new Yi(null,void 0);return t&&Ji(r,t),i&&Wi(r,i),e&&Vi(r,e),n&&(r.l=n),r}function te(t,i){return t?i?decodeURI(t.replace(/%25/g,"%2525")):decodeURIComponent(t):""}function ie(t,i,e){return"string"==typeof t?(t=encodeURI(t).replace(i,ee),e&&(t=t.replace(/%25([0-9a-fA-F]{2})/g,"%$1")),t):null}function ee(t){return"%"+((t=t.charCodeAt(0))>>4&15).toString(16)+(15&t).toString(16)}Yi.prototype.toString=function(){var t=[],i=this.j;i&&t.push(ie(i,ne,!0),":");var e=this.i;return(e||"file"==i)&&(t.push("//"),(i=this.s)&&t.push(ie(i,ne,!0),"@"),t.push(encodeURIComponent(String(e)).replace(/%25([0-9a-fA-F]{2})/g,"%$1")),null!=(e=this.m)&&t.push(":",String(e))),(e=this.l)&&(this.i&&"/"!=e.charAt(0)&&t.push("/"),t.push(ie(e,"/"==e.charAt(0)?se:re,!0))),(e=this.h.toString())&&t.push("?",e),(e=this.o)&&t.push("#",ie(e,he)),t.join("")};var ne=/[#\/\?@]/g,re=/[#\?:]/g,se=/[#\?]/g,oe=/[#\?@]/g,he=/#/g;function ae(t,i){this.h=this.g=null,this.i=t||null,this.j=!!i}function le(t){t.g||(t.g=new Bi,t.h=0,t.i&&Ki(t.i,function(i,e){t.add(decodeURIComponent(i.replace(/\+/g," ")),e)}))}function ue(t,i){le(t),i=ge(t,i),Ni(t.g.h,i)&&(t.i=null,t.h-=t.g.get(i).length,Ni((t=t.g).h,i)&&(delete t.h[i],t.i--,t.g.length>2*t.i&&Fi(t)))}function ce(t,i){return le(t),i=ge(t,i),Ni(t.g.h,i)}function fe(t,i,e){ue(t,i),0<e.length&&(t.i=null,t.g.set(ge(t,i),C(e)),t.h+=e.length)}function ge(t,i){return i=String(i),t.j&&(i=i.toLowerCase()),i}function pe(t,i){i&&!t.j&&(le(t),t.i=null,t.g.forEach(function(t,i){var e=i.toLowerCase();i!=e&&(ue(this,i),fe(this,e,t))},t)),t.j=i}(r=ae.prototype).add=function(t,i){le(this),this.i=null,t=ge(this,t);var e=this.g.get(t);return e||this.g.set(t,e=[]),e.push(i),this.h+=1,this},r.forEach=function(t,i){le(this),this.g.forEach(function(e,n){S(e,function(e){t.call(i,e,n,this)},this)},this)},r.T=function(){le(this);for(var t=this.g.R(),i=this.g.T(),e=[],n=0;n<i.length;n++)for(var r=t[n],s=0;s<r.length;s++)e.push(i[n]);return e},r.R=function(t){le(this);var i=[];if("string"==typeof t)ce(this,t)&&(i=j(i,this.g.get(ge(this,t))));else{t=this.g.R();for(var e=0;e<t.length;e++)i=j(i,t[e])}return i},r.set=function(t,i){return le(this),this.i=null,ce(this,t=ge(this,t))&&(this.h-=this.g.get(t).length),this.g.set(t,[i]),this.h+=1,this},r.get=function(t,i){return t&&0<(t=this.R(t)).length?String(t[0]):i},r.toString=function(){if(this.i)return this.i;if(!this.g)return"";for(var t=[],i=this.g.T(),e=0;e<i.length;e++){var n=i[e],r=encodeURIComponent(String(n));n=this.R(n);for(var s=0;s<n.length;s++){var o=r;""!==n[s]&&(o+="="+encodeURIComponent(String(n[s]))),t.push(o)}}return this.i=t.join("&")};var ve=function(){return function(t,i){this.h=t,this.g=i}}();function de(t){this.l=t||ye,h.PerformanceNavigationTiming?t=0<(t=h.performance.getEntriesByType("navigation")).length&&("hq"==t[0].nextHopProtocol||"h2"==t[0].nextHopProtocol):t=!!(h.g&&h.g.Ea&&h.g.Ea()&&h.g.Ea().Zb),this.j=t?this.l:1,this.g=null,1<this.j&&(this.g=new Set),this.h=null,this.i=[]}var ye=10;function me(t){return!!t.h||!!t.g&&t.g.size>=t.j}function be(t){return t.h?1:t.g?t.g.size:0}function we(t,i){return t.h?t.h==i:!!t.g&&t.g.has(i)}function Te(t,i){t.g?t.g.add(i):t.h=i}function Ee(t,i){t.h&&t.h==i?t.h=null:t.g&&t.g.has(i)&&t.g.delete(i)}function Se(t){var i,e;if(null!=t.h)return t.i.concat(t.h.D);if(null!=t.g&&0!==t.g.size){var r=t.i;try{for(var s=n(t.g.values()),o=s.next();!o.done;o=s.next()){var h=o.value;r=r.concat(h.D)}}catch(a){i={error:a}}finally{try{o&&!o.done&&(e=s.return)&&e.call(s)}finally{if(i)throw i.error}}return r}return C(t.i)}function xe(){}function je(){this.g=new xe}function Ce(t,i,e){var n=e||"";try{ki(t,function(t,e){var r=t;u(t)&&(r=Rt(t)),i.push(n+e+"="+encodeURIComponent(r))})}catch(r){throw i.push(n+"type="+encodeURIComponent("_badmap")),r}}function Ie(t,i){var e=new qt;if(h.Image){var n=new Image;n.onload=y(Ae,e,n,"TestLoadImage: loaded",!0,i),n.onerror=y(Ae,e,n,"TestLoadImage: error",!1,i),n.onabort=y(Ae,e,n,"TestLoadImage: abort",!1,i),n.ontimeout=y(Ae,e,n,"TestLoadImage: timeout",!1,i),h.setTimeout(function(){n.ontimeout&&n.ontimeout()},1e4),n.src=t}else i(!1)}function Ae(t,i,e,n,r){try{i.onload=null,i.onerror=null,i.onabort=null,i.ontimeout=null,r(n)}catch(s){}}function Re(t){this.l=t.$b||null,this.j=t.ib||!1}function Oe(t,i){Ct.call(this),this.D=t,this.u=i,this.m=void 0,this.readyState=Pe,this.status=0,this.responseType=this.responseText=this.response=this.statusText="",this.onreadystatechange=null,this.v=new Headers,this.h=null,this.C="GET",this.B="",this.g=!1,this.A=this.j=this.l=null}de.prototype.cancel=function(){var t,i;if(this.i=Se(this),this.h)this.h.cancel(),this.h=null;else if(this.g&&0!==this.g.size){try{for(var e=n(this.g.values()),r=e.next();!r.done;r=e.next()){r.value.cancel()}}catch(s){t={error:s}}finally{try{r&&!r.done&&(i=e.return)&&i.call(e)}finally{if(t)throw t.error}}this.g.clear()}},xe.prototype.stringify=function(t){return h.JSON.stringify(t,void 0)},xe.prototype.parse=function(t){return h.JSON.parse(t,void 0)},m(Re,gi),Re.prototype.g=function(){return new Oe(this.l,this.j)},Re.prototype.i=function(t){return function(){return t}}({}),m(Oe,Ct);var Pe=0;function De(t){t.j.read().then(t.Sa.bind(t)).catch(t.ha.bind(t))}function Me(t){t.readyState=4,t.l=null,t.j=null,t.A=null,Le(t)}function Le(t){t.onreadystatechange&&t.onreadystatechange.call(t)}(r=Oe.prototype).open=function(t,i){if(this.readyState!=Pe)throw this.abort(),Error("Error reopening a connection");this.C=t,this.B=i,this.readyState=1,Le(this)},r.send=function(t){if(1!=this.readyState)throw this.abort(),Error("need to call open() first. ");this.g=!0;var i={headers:this.v,method:this.C,credentials:this.m,cache:void 0};t&&(i.body=t),(this.D||h).fetch(new Request(this.B,i)).then(this.Va.bind(this),this.ha.bind(this))},r.abort=function(){this.response=this.responseText="",this.v=new Headers,this.status=0,this.j&&this.j.cancel("Request was aborted."),1<=this.readyState&&this.g&&4!=this.readyState&&(this.g=!1,Me(this)),this.readyState=Pe},r.Va=function(t){if(this.g&&(this.l=t,this.h||(this.status=this.l.status,this.statusText=this.l.statusText,this.h=t.headers,this.readyState=2,Le(this)),this.g&&(this.readyState=3,Le(this),this.g)))if("arraybuffer"===this.responseType)t.arrayBuffer().then(this.Ta.bind(this),this.ha.bind(this));else if(void 0!==h.ReadableStream&&"body"in t){if(this.j=t.body.getReader(),this.u){if(this.responseType)throw Error('responseType must be empty for "streamBinaryChunks" mode responses.');this.response=[]}else this.response=this.responseText="",this.A=new TextDecoder;De(this)}else t.text().then(this.Ua.bind(this),this.ha.bind(this))},r.Sa=function(t){if(this.g){if(this.u&&t.value)this.response.push(t.value);else if(!this.u){var i=t.value?t.value:new Uint8Array(0);(i=this.A.decode(i,{stream:!t.done}))&&(this.response=this.responseText+=i)}t.done?Me(this):Le(this),3==this.readyState&&De(this)}},r.Ua=function(t){this.g&&(this.response=this.responseText=t,Me(this))},r.Ta=function(t){this.g&&(this.response=t,Me(this))},r.ha=function(){this.g&&Me(this)},r.setRequestHeader=function(t,i){this.v.append(t,i)},r.getResponseHeader=function(t){return this.h&&this.h.get(t.toLowerCase())||""},r.getAllResponseHeaders=function(){if(!this.h)return"";for(var t=[],i=this.h.entries(),e=i.next();!e.done;)e=e.value,t.push(e[0]+": "+e[1]),e=i.next();return t.join("\r\n")},Object.defineProperty(Oe.prototype,"withCredentials",{get:function(){return"include"===this.m},set:function(t){this.m=t?"include":"same-origin"}});var Xe=h.JSON.parse;function He(t){Ct.call(this),this.headers=new Bi,this.u=t||null,this.h=!1,this.C=this.g=null,this.H="",this.m=0,this.j="",this.l=this.F=this.v=this.D=!1,this.B=0,this.A=null,this.J=_e,this.K=this.L=!1}m(He,Ct);var _e="",ke=/^https?$/i,Be=["POST","PUT"];function Fe(t){return U&&Q()&&"number"==typeof t.timeout&&void 0!==t.ontimeout}function Ne(t){return"content-type"==t.toLowerCase()}function Ue(t,i){t.h=!1,t.g&&(t.l=!0,t.g.abort(),t.l=!1),t.j=i,t.m=5,Ke(t),Ge(t)}function Ke(t){t.D||(t.D=!0,It(t,"complete"),It(t,"error"))}function Ye(t){if(t.h&&void 0!==o&&(!t.C[1]||4!=We(t)||2!=t.ba()))if(t.v&&4==We(t))Kt(t.Fa,0,t);else if(It(t,"readystatechange"),4==We(t)){t.h=!1;try{var i,e=t.ba();t:switch(e){case 200:case 201:case 202:case 204:case 206:case 304:case 1223:var n=!0;break t;default:n=!1}if(!(i=n)){var r;if(r=0===e){var s=String(t.H).match(Ui)[1]||null;if(!s&&h.self&&h.self.location){var a=h.self.location.protocol;s=a.substr(0,a.length-1)}r=!ke.test(s?s.toLowerCase():"")}i=r}if(i)It(t,"complete"),It(t,"success");else{t.m=6;try{var l=2<We(t)?t.g.statusText:""}catch(u){l=""}t.j=l+" ["+t.ba()+"]",Ke(t)}}finally{Ge(t)}}}function Ge(t,i){if(t.g){Je(t);var e=t.g,n=t.C[0]?a:null;t.g=null,t.C=null,i||It(t,"ready");try{e.onreadystatechange=n}catch(r){}}}function Je(t){t.g&&t.K&&(t.g.ontimeout=null),t.A&&(h.clearTimeout(t.A),t.A=null)}function We(t){return t.g?t.g.readyState:0}function Ve(t){try{if(!t.g)return null;if("response"in t.g)return t.g.response;switch(t.J){case _e:case"text":return t.g.responseText;case"arraybuffer":if("mozResponseArrayBuffer"in t.g)return t.g.mozResponseArrayBuffer}return null}catch(i){return null}}function $e(t){var i="";return L(t,function(t,e){i+=e,i+=":",i+=t,i+="\r\n"}),i}function qe(t,i,e){t:{for(n in e){var n=!1;break t}n=!0}n||(e=$e(e),"string"==typeof t?null!=e&&encodeURIComponent(String(e)):qi(t,i,e))}function ze(t,i,e){return e&&e.internalChannelParams&&e.internalChannelParams[t]||i}function Ze(t){this.za=0,this.l=[],this.h=new qt,this.la=this.oa=this.F=this.W=this.g=this.sa=this.D=this.aa=this.o=this.P=this.s=null,this.Za=this.V=0,this.Xa=ze("failFast",!1,t),this.N=this.v=this.u=this.m=this.j=null,this.X=!0,this.I=this.ta=this.U=-1,this.Y=this.A=this.C=0,this.Pa=ze("baseRetryDelayMs",5e3,t),this.$a=ze("retryDelaySeedMs",1e4,t),this.Ya=ze("forwardChannelMaxRetries",2,t),this.ra=ze("forwardChannelRequestTimeoutMs",2e4,t),this.qa=t&&t.xmlHttpFactory||void 0,this.Ba=t&&t.Yb||!1,this.K=void 0,this.H=t&&t.supportsCrossDomainXhr||!1,this.J="",this.i=new de(t&&t.concurrentRequestLimit),this.Ca=new je,this.ja=t&&t.fastHandshake||!1,this.Ra=t&&t.Wb||!1,t&&t.Aa&&this.h.Aa(),t&&t.forceLongPolling&&(this.X=!1),this.$=!this.ja&&this.X&&t&&t.detectBufferingProxy||!1,this.ka=void 0,this.O=0,this.L=!1,this.B=null,this.Wa=!t||!1!==t.Xb}function Qe(t){if(en(t),3==t.G){var i=t.V++,e=Gi(t.F);qi(e,"SID",t.J),qi(e,"RID",i),qi(e,"TYPE","terminate"),hn(t,e),(i=new Ti(t,t.h,i,void 0)).K=2,i.v=zi(Gi(e)),e=!1,h.navigator&&h.navigator.sendBeacon&&(e=h.navigator.sendBeacon(i.v.toString(),"")),!e&&h.Image&&((new Image).src=i.v,e=!0),e||(i.g=bn(i.l,null),i.g.ea(i.v)),i.F=Date.now(),Pi(i)}yn(t)}function tn(t){t.g&&(cn(t),t.g.cancel(),t.g=null)}function en(t){tn(t),t.u&&(h.clearTimeout(t.u),t.u=null),gn(t),t.i.cancel(),t.m&&("number"==typeof t.m&&h.clearTimeout(t.m),t.m=null)}function nn(t,i){t.l.push(new ve(t.Za++,i)),3==t.G&&rn(t)}function rn(t){me(t.i)||t.m||(t.m=!0,Ht(t.Ha,t),t.C=0)}function sn(t,i){return!(be(t.i)>=t.i.j-(t.m?1:0))&&(t.m?(t.l=i.D.concat(t.l),!0):!(1==t.G||2==t.G||t.C>=(t.Xa?0:t.Ya))&&(t.m=ui(d(t.Ha,t,i),vn(t,t.C)),t.C++,!0))}function on(t,i){var e;e=i?i.m:t.V++;var n=Gi(t.F);qi(n,"SID",t.J),qi(n,"RID",e),qi(n,"AID",t.U),hn(t,n),t.o&&t.s&&qe(n,t.o,t.s),e=new Ti(t,t.h,e,t.C+1),null===t.o&&(e.H=t.s),i&&(t.l=i.D.concat(t.l)),i=an(t,e,1e3),e.setTimeout(Math.round(.5*t.ra)+Math.round(.5*t.ra*Math.random())),Te(t.i,e),Ci(e,n,i)}function hn(t,i){t.j&&ki({},function(t,e){qi(i,e,t)})}function an(t,i,e){e=Math.min(t.l.length,e);var n=t.j?d(t.j.Oa,t.j,t):null;t:for(var r=t.l,s=-1;;){var o=["count="+e];-1==s?0<e?(s=r[0].h,o.push("ofs="+s)):s=0:o.push("ofs="+s);for(var h=!0,a=0;a<e;a++){var l=r[a].h,u=r[a].g;if(0>(l-=s))s=Math.max(0,r[a].h-100),h=!1;else try{Ce(u,o,"req"+l+"_")}catch(c){n&&n(u)}}if(h){n=o.join("&");break t}}return t=t.l.splice(0,e),i.D=t,n}function ln(t){t.g||t.u||(t.Y=1,Ht(t.Ga,t),t.A=0)}function un(t){return!(t.g||t.u||3<=t.A)&&(t.Y++,t.u=ui(d(t.Ga,t),vn(t,t.A)),t.A++,!0)}function cn(t){null!=t.B&&(h.clearTimeout(t.B),t.B=null)}function fn(t){t.g=new Ti(t,t.h,"rpc",t.Y),null===t.o&&(t.g.H=t.s),t.g.O=0;var i=Gi(t.oa);qi(i,"RID","rpc"),qi(i,"SID",t.J),qi(i,"CI",t.N?"0":"1"),qi(i,"AID",t.U),hn(t,i),qi(i,"TYPE","xmlhttp"),t.o&&t.s&&qe(i,t.o,t.s),t.K&&t.g.setTimeout(t.K);var e=t.g;t=t.la,e.K=1,e.v=zi(Gi(i)),e.s=null,e.U=!0,Ii(e,t)}function gn(t){null!=t.v&&(h.clearTimeout(t.v),t.v=null)}function pn(t,i){var e=null;if(t.g==i){gn(t),cn(t),t.g=null;var n=2}else{if(!we(t.i,i))return;e=i.D,Ee(t.i,i),n=1}if(t.I=i.N,0!=t.G)if(i.i)if(1==n){e=i.s?i.s.length:0,i=Date.now()-i.F;var r=t.C;It(n=ri(),new li(n,e,i,r)),rn(t)}else ln(t);else if(3==(r=i.o)||0==r&&0<t.I||!(1==n&&sn(t,i)||2==n&&un(t)))switch(e&&0<e.length&&(i=t.i,i.i=i.i.concat(e)),r){case 1:dn(t,5);break;case 4:dn(t,10);break;case 3:dn(t,6);break;default:dn(t,2)}}function vn(t,i){var e=t.Pa+Math.floor(Math.random()*t.$a);return t.j||(e*=2),e*i}function dn(t,i){if(t.h.info("Error code "+i),2==i){var e=null;t.j&&(e=null);var n=d(t.jb,t);e||(e=new Yi("//www.google.com/images/cleardot.gif"),h.location&&"http"==h.location.protocol||Ji(e,"https"),zi(e)),Ie(e.toString(),n)}else ai(2);t.G=0,t.j&&t.j.va(i),yn(t),en(t)}function yn(t){t.G=0,t.I=-1,t.j&&(0==Se(t.i).length&&0==t.l.length||(t.i.i.length=0,C(t.l),t.l.length=0),t.j.ua())}function mn(t,i,e){var n=Zi(e);if(""!=n.i)i&&Wi(n,i+"."+n.i),Vi(n,n.m);else{var r=h.location;n=Qi(r.protocol,i?i+"."+r.hostname:r.hostname,+r.port,e)}return t.aa&&L(t.aa,function(t,i){qi(n,i,t)}),i=t.D,e=t.sa,i&&e&&qi(n,i,e),qi(n,"VER",t.ma),hn(t,n),n}function bn(t,i,e){if(i&&!t.H)throw Error("Can't create secondary domain capable XhrIo object.");return(i=e&&t.Ba&&!t.qa?new He(new Re({ib:!0})):new He(t.qa)).L=t.H,i}function wn(){}function Tn(){if(U&&!(10<=Number(it)))throw Error("Environmental error: no available transport.")}function En(t,i){Ct.call(this),this.g=new Ze(i),this.l=t,this.h=i&&i.messageUrlParams||null,t=i&&i.messageHeaders||null,i&&i.clientProtocolHeaderRequired&&(t?t["X-Client-Protocol"]="webchannel":t={"X-Client-Protocol":"webchannel"}),this.g.s=t,t=i&&i.initMessageHeaders||null,i&&i.messageContentType&&(t?t["X-WebChannel-Content-Type"]=i.messageContentType:t={"X-WebChannel-Content-Type":i.messageContentType}),i&&i.ya&&(t?t["X-WebChannel-Client-Profile"]=i.ya:t={"X-WebChannel-Client-Profile":i.ya}),this.g.P=t,(t=i&&i.httpHeadersOverwriteParam)&&!I(t)&&(this.g.o=t),this.A=i&&i.supportsCrossDomainXhr||!1,this.v=i&&i.sendRawJson||!1,(i=i&&i.httpSessionIdParam)&&!I(i)&&(this.g.D=i,null!==(t=this.h)&&i in t&&(i in(t=this.h)&&delete t[i])),this.j=new jn(this)}function Sn(t){mi.call(this);var i=t.__sm__;if(i){t:{for(var e in i){t=e;break t}t=void 0}(this.i=t)&&(t=this.i,i=null!==i&&t in i?i[t]:void 0),this.data=i}else this.data=t}function xn(){bi.call(this),this.status=1}function jn(t){this.g=t}(r=He.prototype).ea=function(t,i,e,n){if(this.g)throw Error("[goog.net.XhrIo] Object is active with another request="+this.H+"; newUri="+t);i=i?i.toUpperCase():"GET",this.H=t,this.j="",this.m=0,this.D=!1,this.h=!0,this.g=this.u?this.u.g():di.g(),this.C=this.u?pi(this.u):pi(di),this.g.onreadystatechange=d(this.Fa,this);try{this.F=!0,this.g.open(i,String(t),!0),this.F=!1}catch(s){return void Ue(this,s)}t=e||"";var r=new Bi(this.headers);n&&ki(n,function(t,i){r.set(i,t)}),n=x(r.T()),e=h.FormData&&t instanceof h.FormData,!(0<=E(Be,i))||n||e||r.set("Content-Type","application/x-www-form-urlencoded;charset=utf-8"),r.forEach(function(t,i){this.g.setRequestHeader(i,t)},this),this.J&&(this.g.responseType=this.J),"withCredentials"in this.g&&this.g.withCredentials!==this.L&&(this.g.withCredentials=this.L);try{Je(this),0<this.B&&((this.K=Fe(this.g))?(this.g.timeout=this.B,this.g.ontimeout=d(this.pa,this)):this.A=Kt(this.pa,this.B,this)),this.v=!0,this.g.send(t),this.v=!1}catch(s){Ue(this,s)}},r.pa=function(){void 0!==o&&this.g&&(this.j="Timed out after "+this.B+"ms, aborting",this.m=8,It(this,"timeout"),this.abort(8))},r.abort=function(t){this.g&&this.h&&(this.h=!1,this.l=!0,this.g.abort(),this.l=!1,this.m=t||7,It(this,"complete"),It(this,"abort"),Ge(this))},r.M=function(){this.g&&(this.h&&(this.h=!1,this.l=!0,this.g.abort(),this.l=!1),Ge(this,!0)),He.Z.M.call(this)},r.Fa=function(){this.s||(this.F||this.v||this.l?Ye(this):this.cb())},r.cb=function(){Ye(this)},r.ba=function(){try{return 2<We(this)?this.g.status:-1}catch(t){return-1}},r.ga=function(){try{return this.g?this.g.responseText:""}catch(t){return""}},r.Qa=function(t){if(this.g){var i=this.g.responseText;return t&&0==i.indexOf(t)&&(i=i.substring(t.length)),Xe(i)}},r.Da=function(){return this.m},r.La=function(){return"string"==typeof this.j?this.j:String(this.j)},(r=Ze.prototype).ma=8,r.G=1,r.hb=function(t){try{this.h.info("Origin Trials invoked: "+t)}catch(i){}},r.Ha=function(t){if(this.m)if(this.m=null,1==this.G){if(!t){this.V=Math.floor(1e5*Math.random()),t=this.V++;var i=new Ti(this,this.h,t,void 0),e=this.s;if(this.P&&(e?_(e=X(e),this.P):e=this.P),null===this.o&&(i.H=e),this.ja)t:{for(var n=0,r=0;r<this.l.length;r++){var s=this.l[r];if(void 0===(s="__data__"in s.g&&"string"==typeof(s=s.g.__data__)?s.length:void 0))break;if(4096<(n+=s)){n=r;break t}if(4096===n||r===this.l.length-1){n=r+1;break t}}n=1e3}else n=1e3;n=an(this,i,n),qi(r=Gi(this.F),"RID",t),qi(r,"CVER",22),this.D&&qi(r,"X-HTTP-Session-Id",this.D),hn(this,r),this.o&&e&&qe(r,this.o,e),Te(this.i,i),this.Ra&&qi(r,"TYPE","init"),this.ja?(qi(r,"$req",n),qi(r,"SID","null"),i.$=!0,Ci(i,r,null)):Ci(i,r,n),this.G=2}}else 3==this.G&&(t?on(this,t):0==this.l.length||me(this.i)||on(this))},r.Ga=function(){if(this.u=null,fn(this),this.$&&!(this.L||null==this.g||0>=this.O)){var t=2*this.O;this.h.info("BP detection timer enabled: "+t),this.B=ui(d(this.bb,this),t)}},r.bb=function(){this.B&&(this.B=null,this.h.info("BP detection timeout reached."),this.h.info("Buffering proxy detected and switch to long-polling!"),this.N=!1,this.L=!0,ai(10),tn(this),fn(this))},r.ab=function(){null!=this.v&&(this.v=null,tn(this),un(this),ai(19))},r.jb=function(t){t?(this.h.info("Successfully pinged google.com"),ai(2)):(this.h.info("Failed to ping google.com"),ai(1))},(r=wn.prototype).xa=function(){},r.wa=function(){},r.va=function(){},r.ua=function(){},r.Oa=function(){},Tn.prototype.g=function(t,i){return new En(t,i)},m(En,Ct),En.prototype.m=function(){this.g.j=this.j,this.A&&(this.g.H=!0);var t=this.g,i=this.l,e=this.h||void 0;t.Wa&&(t.h.info("Origin Trials enabled."),Ht(d(t.hb,t,i))),ai(0),t.W=i,t.aa=e||{},t.N=t.X,t.F=mn(t,null,t.W),rn(t)},En.prototype.close=function(){Qe(this.g)},En.prototype.u=function(t){if("string"==typeof t){var i={};i.__data__=t,nn(this.g,i)}else this.v?((i={}).__data__=Rt(t),nn(this.g,i)):nn(this.g,t)},En.prototype.M=function(){this.g.j=null,delete this.j,Qe(this.g),delete this.g,En.Z.M.call(this)},m(Sn,mi),m(xn,bi),m(jn,wn),jn.prototype.xa=function(){It(this.g,"a")},jn.prototype.wa=function(t){It(this.g,new Sn(t))},jn.prototype.va=function(t){It(this.g,new xn(t))},jn.prototype.ua=function(){It(this.g,"b")},Tn.prototype.createWebChannel=Tn.prototype.g,En.prototype.send=En.prototype.u,En.prototype.open=En.prototype.m,En.prototype.close=En.prototype.close,ci.NO_ERROR=0,ci.TIMEOUT=8,ci.HTTP_ERROR=6,fi.COMPLETE="complete",vi.EventType=yi,yi.OPEN="a",yi.CLOSE="b",yi.ERROR="c",yi.MESSAGE="d",Ct.prototype.listen=Ct.prototype.N,He.prototype.listenOnce=He.prototype.O,He.prototype.getLastError=He.prototype.La,He.prototype.getLastErrorCode=He.prototype.Da,He.prototype.getStatus=He.prototype.ba,He.prototype.getResponseJson=He.prototype.Qa,He.prototype.getResponseText=He.prototype.ga,He.prototype.send=He.prototype.ea;var Cn=function(){return new Tn};exports.createWebChannelTransport=Cn;var In=function(){return ri()};exports.getStatEventTarget=In;var An=ci;exports.ErrorCode=An;var Rn=fi;exports.EventType=Rn;var On=ei;exports.Event=On;var Pn={rb:0,ub:1,vb:2,Ob:3,Tb:4,Qb:5,Rb:6,Pb:7,Nb:8,Sb:9,PROXY:10,NOPROXY:11,Lb:12,Hb:13,Ib:14,Gb:15,Jb:16,Kb:17,nb:18,mb:19,ob:20};exports.Stat=Pn;var Dn=Re;exports.FetchXmlHttpFactory=Dn;var Mn=vi;exports.WebChannel=Mn;var Ln=He;exports.XhrIo=Ln;var Xn={createWebChannelTransport:Cn,getStatEventTarget:In,ErrorCode:An,EventType:Rn,Event:On,Stat:Pn,FetchXmlHttpFactory:Dn,WebChannel:Mn,XhrIo:Ln},Hn=Xn;exports.default=Hn;
491
- },{}],"Emx5":[function(require,module,exports) {
491
+ },{}],"pbUl":[function(require,module,exports) {
492
492
  var process = require("process");
493
- var t=require("process");Object.defineProperty(exports,"__esModule",{value:!0}),exports.M=exports.E=exports.C=void 0,exports.Q=ac,exports.a=exports.Z=exports.X=exports.W=exports.U=exports.T=void 0,exports.c=Tc,exports.t=exports.s=exports.r=exports.q=exports.o=exports.n=exports.j=void 0,exports.u=Sc,exports.z=void 0;var e=require("tslib"),n=require("@firebase/util"),r=require("@firebase/logger"),i=require("@firebase/webchannel-wrapper");function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var s=function(){function t(t,e){var n=this;this.previousValue=t,e&&(e.sequenceNumberHandler=function(t){return n.t(t)},this.i=function(t){return e.writeSequenceNumber(t)})}return t.prototype.t=function(t){return this.previousValue=Math.max(t,this.previousValue),this.previousValue},t.prototype.next=function(){var t=++this.previousValue;return this.i&&this.i(t),t},t}();s.o=-1;var a={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"},u=function(t){function n(e,n){var r=this;return(r=t.call(this,n)||this).code=e,r.message=n,r.name="FirebaseError",r.toString=function(){return r.name+": [code="+r.code+"]: "+r.message},r}return(0,e.__extends)(n,t),n}(Error),c=new r.Logger("@firebase/firestore");function h(){return c.logLevel}function f(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];if(c.logLevel<=r.LogLevel.DEBUG){var o=n.map(p);c.debug.apply(c,(0,e.__spreadArray)(["Firestore (8.10.0): "+t],o))}}function l(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];if(c.logLevel<=r.LogLevel.ERROR){var o=n.map(p);c.error.apply(c,(0,e.__spreadArray)(["Firestore (8.10.0): "+t],o))}}function d(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];if(c.logLevel<=r.LogLevel.WARN){var o=n.map(p);c.warn.apply(c,(0,e.__spreadArray)(["Firestore (8.10.0): "+t],o))}}function p(t){if("string"==typeof t)return t;try{return e=t,JSON.stringify(e)}catch(e){return t}var e}function y(t){void 0===t&&(t="Unexpected state");var e="FIRESTORE (8.10.0) INTERNAL ASSERTION FAILED: "+t;throw l(e),new Error(e)}function v(t,e){t||y()}function m(t,e){return t}function g(t){var e="undefined"!=typeof self&&(self.crypto||self.msCrypto),n=new Uint8Array(t);if(e&&"function"==typeof e.getRandomValues)e.getRandomValues(n);else for(var r=0;r<t;r++)n[r]=Math.floor(256*Math.random());return n}var _=function(){function t(){}return t.u=function(){for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",e=Math.floor(256/t.length)*t.length,n="";n.length<20;)for(var r=g(40),i=0;i<r.length;++i)n.length<20&&r[i]<e&&(n+=t.charAt(r[i]%t.length));return n},t}();function w(t,e){return t<e?-1:t>e?1:0}function b(t,e,n){return t.length===e.length&&t.every(function(t,r){return n(t,e[r])})}function I(t){return t+"\0"}var E=function(){function t(t,e){if(this.seconds=t,this.nanoseconds=e,e<0)throw new u(a.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+e);if(e>=1e9)throw new u(a.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+e);if(t<-62135596800)throw new u(a.INVALID_ARGUMENT,"Timestamp seconds out of range: "+t);if(t>=253402300800)throw new u(a.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,Math.floor(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._compareTo=function(t){return this.seconds===t.seconds?w(this.nanoseconds,t.nanoseconds):w(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.prototype.toJSON=function(){return{seconds:this.seconds,nanoseconds:this.nanoseconds}},t.prototype.valueOf=function(){var t=this.seconds- -62135596800;return String(t).padStart(12,"0")+"."+String(this.nanoseconds).padStart(9,"0")},t}(),T=function(){function t(t){this.timestamp=t}return t.fromTimestamp=function(e){return new t(e)},t.min=function(){return new t(new E(0,0))},t.prototype.compareTo=function(t){return this.timestamp._compareTo(t.timestamp)},t.prototype.isEqual=function(t){return this.timestamp.isEqual(t.timestamp)},t.prototype.toMicroseconds=function(){return 1e6*this.timestamp.seconds+this.timestamp.nanoseconds/1e3},t.prototype.toString=function(){return"SnapshotVersion("+this.timestamp.toString()+")"},t.prototype.toTimestamp=function(){return this.timestamp},t}();function S(t){var e=0;for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e++;return e}function N(t,e){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e(n,t[n])}function D(t){for(var e in t)if(Object.prototype.hasOwnProperty.call(t,e))return!1;return!0}exports.M=E;var A=function(){function t(t,e,n){void 0===e?e=0:e>t.length&&y(),void 0===n?n=t.length-e:n>t.length-e&&y(),this.segments=t,this.offset=e,this.len=n}return Object.defineProperty(t.prototype,"length",{get:function(){return this.len},enumerable:!1,configurable:!0}),t.prototype.isEqual=function(e){return 0===t.comparator(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.construct(n)},t.prototype.limit=function(){return this.offset+this.length},t.prototype.popFirst=function(t){return t=void 0===t?1:t,this.construct(this.segments,this.offset+t,this.length-t)},t.prototype.popLast=function(){return this.construct(this.segments,this.offset,this.length-1)},t.prototype.firstSegment=function(){return this.segments[this.offset]},t.prototype.lastSegment=function(){return this.get(this.length-1)},t.prototype.get=function(t){return this.segments[this.offset+t]},t.prototype.isEmpty=function(){return 0===this.length},t.prototype.isPrefixOf=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.isImmediateParentOf=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.toArray=function(){return this.segments.slice(this.offset,this.limit())},t.comparator=function(t,e){for(var n=Math.min(t.length,e.length),r=0;r<n;r++){var i=t.get(r),o=e.get(r);if(i<o)return-1;if(i>o)return 1}return t.length<e.length?-1:t.length>e.length?1:0},t}(),x=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return(0,e.__extends)(n,t),n.prototype.construct=function(t,e,r){return new n(t,e,r)},n.prototype.canonicalString=function(){return this.toArray().join("/")},n.prototype.toString=function(){return this.canonicalString()},n.fromString=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];for(var r=[],i=0,o=t;i<o.length;i++){var s=o[i];if(s.indexOf("//")>=0)throw new u(a.INVALID_ARGUMENT,"Invalid segment ("+s+"). Paths must not contain // in them.");r.push.apply(r,s.split("/").filter(function(t){return t.length>0}))}return new n(r)},n.emptyPath=function(){return new n([])},n}(A),k=/^[_a-zA-Z][_a-zA-Z0-9]*$/,C=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return(0,e.__extends)(n,t),n.prototype.construct=function(t,e,r){return new n(t,e,r)},n.isValidIdentifier=function(t){return k.test(t)},n.prototype.canonicalString=function(){return this.toArray().map(function(t){return t=t.replace(/\\/g,"\\\\").replace(/`/g,"\\`"),n.isValidIdentifier(t)||(t="`"+t+"`"),t}).join(".")},n.prototype.toString=function(){return this.canonicalString()},n.prototype.isKeyField=function(){return 1===this.length&&"__name__"===this.get(0)},n.keyField=function(){return new n(["__name__"])},n.fromServerFormat=function(t){for(var e=[],r="",i=0,o=function(){if(0===r.length)throw new u(a.INVALID_ARGUMENT,"Invalid field path ("+t+"). Paths must not be empty, begin with '.', end with '.', or contain '..'");e.push(r),r=""},s=!1;i<t.length;){var c=t[i];if("\\"===c){if(i+1===t.length)throw new u(a.INVALID_ARGUMENT,"Path has trailing escape character: "+t);var h=t[i+1];if("\\"!==h&&"."!==h&&"`"!==h)throw new u(a.INVALID_ARGUMENT,"Path has invalid escape sequence: "+t);r+=h,i+=2}else"`"===c?(s=!s,i++):"."!==c||s?(r+=c,i++):(o(),i++)}if(o(),s)throw new u(a.INVALID_ARGUMENT,"Unterminated ` in path: "+t);return new n(e)},n.emptyPath=function(){return new n([])},n}(A),R=function(){function t(t){this.fields=t,t.sort(C.comparator)}return t.prototype.covers=function(t){for(var e=0,n=this.fields;e<n.length;e++)if(n[e].isPrefixOf(t))return!0;return!1},t.prototype.isEqual=function(t){return b(this.fields,t.fields,function(t,e){return t.isEqual(e)})},t}(),L=function(){function t(t){this.binaryString=t}return t.fromBase64String=function(e){return new t(atob(e))},t.fromUint8Array=function(e){return new t(function(t){for(var e="",n=0;n<t.length;++n)e+=String.fromCharCode(t[n]);return e}(e))},t.prototype.toBase64=function(){return t=this.binaryString,btoa(t);var t},t.prototype.toUint8Array=function(){return function(t){for(var e=new Uint8Array(t.length),n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return e}(this.binaryString)},t.prototype.approximateByteSize=function(){return 2*this.binaryString.length},t.prototype.compareTo=function(t){return w(this.binaryString,t.binaryString)},t.prototype.isEqual=function(t){return this.binaryString===t.binaryString},t}();L.EMPTY_BYTE_STRING=new L("");var O=new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);function P(t){if(v(!!t),"string"==typeof t){var e=0,n=O.exec(t);if(v(!!n),n[1]){var r=n[1];r=(r+"000000000").substr(0,9),e=Number(r)}var i=new Date(t);return{seconds:Math.floor(i.getTime()/1e3),nanos:e}}return{seconds:F(t.seconds),nanos:F(t.nanos)}}function F(t){return"number"==typeof t?t:"string"==typeof t?Number(t):0}function M(t){return"string"==typeof t?L.fromBase64String(t):L.fromUint8Array(t)}function V(t){var e,n;return"server_timestamp"===(null===(n=((null===(e=null==t?void 0:t.mapValue)||void 0===e?void 0:e.fields)||{}).__type__)||void 0===n?void 0:n.stringValue)}function q(t){var e=t.mapValue.fields.__previous_value__;return V(e)?q(e):e}function U(t){var e=P(t.mapValue.fields.__local_write_time__.timestampValue);return new E(e.seconds,e.nanos)}function B(t){return null==t}function j(t){return 0===t&&1/t==-1/0}function K(t){return"number"==typeof t&&Number.isInteger(t)&&!j(t)&&t<=Number.MAX_SAFE_INTEGER&&t>=Number.MIN_SAFE_INTEGER}var Q=function(){function t(t){this.path=t}return t.fromPath=function(e){return new t(x.fromString(e))},t.fromName=function(e){return new t(x.fromString(e).popFirst(5))},t.prototype.hasCollectionId=function(t){return this.path.length>=2&&this.path.get(this.path.length-2)===t},t.prototype.isEqual=function(t){return null!==t&&0===x.comparator(this.path,t.path)},t.prototype.toString=function(){return this.path.toString()},t.comparator=function(t,e){return x.comparator(t.path,e.path)},t.isDocumentKey=function(t){return t.length%2==0},t.fromSegments=function(e){return new t(new x(e.slice()))},t}();function G(t){return"nullValue"in t?0:"booleanValue"in t?1:"integerValue"in t||"doubleValue"in t?2:"timestampValue"in t?3:"stringValue"in t?5:"bytesValue"in t?6:"referenceValue"in t?7:"geoPointValue"in t?8:"arrayValue"in t?9:"mapValue"in t?V(t)?4:10:y()}function z(t,e){var n=G(t);if(n!==G(e))return!1;switch(n){case 0:return!0;case 1:return t.booleanValue===e.booleanValue;case 4:return U(t).isEqual(U(e));case 3:return function(t,e){if("string"==typeof t.timestampValue&&"string"==typeof e.timestampValue&&t.timestampValue.length===e.timestampValue.length)return t.timestampValue===e.timestampValue;var n=P(t.timestampValue),r=P(e.timestampValue);return n.seconds===r.seconds&&n.nanos===r.nanos}(t,e);case 5:return t.stringValue===e.stringValue;case 6:return function(t,e){return M(t.bytesValue).isEqual(M(e.bytesValue))}(t,e);case 7:return t.referenceValue===e.referenceValue;case 8:return function(t,e){return F(t.geoPointValue.latitude)===F(e.geoPointValue.latitude)&&F(t.geoPointValue.longitude)===F(e.geoPointValue.longitude)}(t,e);case 2:return function(t,e){if("integerValue"in t&&"integerValue"in e)return F(t.integerValue)===F(e.integerValue);if("doubleValue"in t&&"doubleValue"in e){var n=F(t.doubleValue),r=F(e.doubleValue);return n===r?j(n)===j(r):isNaN(n)&&isNaN(r)}return!1}(t,e);case 9:return b(t.arrayValue.values||[],e.arrayValue.values||[],z);case 10:return function(t,e){var n=t.mapValue.fields||{},r=e.mapValue.fields||{};if(S(n)!==S(r))return!1;for(var i in n)if(n.hasOwnProperty(i)&&(void 0===r[i]||!z(n[i],r[i])))return!1;return!0}(t,e);default:return y()}}function W(t,e){return void 0!==(t.values||[]).find(function(t){return z(t,e)})}function H(t,e){var n=G(t),r=G(e);if(n!==r)return w(n,r);switch(n){case 0:return 0;case 1:return w(t.booleanValue,e.booleanValue);case 2:return function(t,e){var n=F(t.integerValue||t.doubleValue),r=F(e.integerValue||e.doubleValue);return n<r?-1:n>r?1:n===r?0:isNaN(n)?isNaN(r)?0:-1:1}(t,e);case 3:return Y(t.timestampValue,e.timestampValue);case 4:return Y(U(t),U(e));case 5:return w(t.stringValue,e.stringValue);case 6:return function(t,e){var n=M(t),r=M(e);return n.compareTo(r)}(t.bytesValue,e.bytesValue);case 7:return function(t,e){for(var n=t.split("/"),r=e.split("/"),i=0;i<n.length&&i<r.length;i++){var o=w(n[i],r[i]);if(0!==o)return o}return w(n.length,r.length)}(t.referenceValue,e.referenceValue);case 8:return function(t,e){var n=w(F(t.latitude),F(e.latitude));return 0!==n?n:w(F(t.longitude),F(e.longitude))}(t.geoPointValue,e.geoPointValue);case 9:return function(t,e){for(var n=t.values||[],r=e.values||[],i=0;i<n.length&&i<r.length;++i){var o=H(n[i],r[i]);if(o)return o}return w(n.length,r.length)}(t.arrayValue,e.arrayValue);case 10:return function(t,e){var n=t.fields||{},r=Object.keys(n),i=e.fields||{},o=Object.keys(i);r.sort(),o.sort();for(var s=0;s<r.length&&s<o.length;++s){var a=w(r[s],o[s]);if(0!==a)return a;var u=H(n[r[s]],i[o[s]]);if(0!==u)return u}return w(r.length,o.length)}(t.mapValue,e.mapValue);default:throw y()}}function Y(t,e){if("string"==typeof t&&"string"==typeof e&&t.length===e.length)return w(t,e);var n=P(t),r=P(e),i=w(n.seconds,r.seconds);return 0!==i?i:w(n.nanos,r.nanos)}function $(t){return X(t)}function X(t){return"nullValue"in t?"null":"booleanValue"in t?""+t.booleanValue:"integerValue"in t?""+t.integerValue:"doubleValue"in t?""+t.doubleValue:"timestampValue"in t?function(t){var e=P(t);return"time("+e.seconds+","+e.nanos+")"}(t.timestampValue):"stringValue"in t?t.stringValue:"bytesValue"in t?M(t.bytesValue).toBase64():"referenceValue"in t?(n=t.referenceValue,Q.fromName(n).toString()):"geoPointValue"in t?"geo("+(e=t.geoPointValue).latitude+","+e.longitude+")":"arrayValue"in t?function(t){for(var e="[",n=!0,r=0,i=t.values||[];r<i.length;r++)n?n=!1:e+=",",e+=X(i[r]);return e+"]"}(t.arrayValue):"mapValue"in t?function(t){for(var e="{",n=!0,r=0,i=Object.keys(t.fields||{}).sort();r<i.length;r++){var o=i[r];n?n=!1:e+=",",e+=o+":"+X(t.fields[o])}return e+"}"}(t.mapValue):y();var e,n}function J(t,e){return{referenceValue:"projects/"+t.projectId+"/databases/"+t.database+"/documents/"+e.path.canonicalString()}}function Z(t){return!!t&&"integerValue"in t}function tt(t){return!!t&&"arrayValue"in t}function et(t){return!!t&&"nullValue"in t}function nt(t){return!!t&&"doubleValue"in t&&isNaN(Number(t.doubleValue))}function rt(t){return!!t&&"mapValue"in t}function it(t){if(t.geoPointValue)return{geoPointValue:Object.assign({},t.geoPointValue)};if(t.timestampValue&&"object"==o(t.timestampValue))return{timestampValue:Object.assign({},t.timestampValue)};if(t.mapValue){var e={mapValue:{fields:{}}};return N(t.mapValue.fields,function(t,n){return e.mapValue.fields[t]=it(n)}),e}if(t.arrayValue){for(var n={arrayValue:{values:[]}},r=0;r<(t.arrayValue.values||[]).length;++r)n.arrayValue.values[r]=it(t.arrayValue.values[r]);return n}return Object.assign({},t)}var ot=function(){function t(t){this.value=t}return t.empty=function(){return new t({mapValue:{}})},t.prototype.field=function(t){if(t.isEmpty())return this.value;for(var e=this.value,n=0;n<t.length-1;++n)if(!rt(e=(e.mapValue.fields||{})[t.get(n)]))return null;return(e=(e.mapValue.fields||{})[t.lastSegment()])||null},t.prototype.set=function(t,e){this.getFieldsMap(t.popLast())[t.lastSegment()]=it(e)},t.prototype.setAll=function(t){var e=this,n=C.emptyPath(),r={},i=[];t.forEach(function(t,o){if(!n.isImmediateParentOf(o)){var s=e.getFieldsMap(n);e.applyChanges(s,r,i),r={},i=[],n=o.popLast()}t?r[o.lastSegment()]=it(t):i.push(o.lastSegment())});var o=this.getFieldsMap(n);this.applyChanges(o,r,i)},t.prototype.delete=function(t){var e=this.field(t.popLast());rt(e)&&e.mapValue.fields&&delete e.mapValue.fields[t.lastSegment()]},t.prototype.isEqual=function(t){return z(this.value,t.value)},t.prototype.getFieldsMap=function(t){var e=this.value;e.mapValue.fields||(e.mapValue={fields:{}});for(var n=0;n<t.length;++n){var r=e.mapValue.fields[t.get(n)];rt(r)&&r.mapValue.fields||(r={mapValue:{fields:{}}},e.mapValue.fields[t.get(n)]=r),e=r}return e.mapValue.fields},t.prototype.applyChanges=function(t,e,n){N(e,function(e,n){return t[e]=n});for(var r=0,i=n;r<i.length;r++){var o=i[r];delete t[o]}},t.prototype.clone=function(){return new t(it(this.value))},t}();function st(t){var e=[];return N(t.fields,function(t,n){var r=new C([t]);if(rt(n)){var i=st(n.mapValue).fields;if(0===i.length)e.push(r);else for(var o=0,s=i;o<s.length;o++){var a=s[o];e.push(r.child(a))}}else e.push(r)}),new R(e)}var at=function(){function t(t,e,n,r,i){this.key=t,this.documentType=e,this.version=n,this.data=r,this.documentState=i}return t.newInvalidDocument=function(e){return new t(e,0,T.min(),ot.empty(),0)},t.newFoundDocument=function(e,n,r){return new t(e,1,n,r,0)},t.newNoDocument=function(e,n){return new t(e,2,n,ot.empty(),0)},t.newUnknownDocument=function(e,n){return new t(e,3,n,ot.empty(),2)},t.prototype.convertToFoundDocument=function(t,e){return this.version=t,this.documentType=1,this.data=e,this.documentState=0,this},t.prototype.convertToNoDocument=function(t){return this.version=t,this.documentType=2,this.data=ot.empty(),this.documentState=0,this},t.prototype.convertToUnknownDocument=function(t){return this.version=t,this.documentType=3,this.data=ot.empty(),this.documentState=2,this},t.prototype.setHasCommittedMutations=function(){return this.documentState=2,this},t.prototype.setHasLocalMutations=function(){return this.documentState=1,this},Object.defineProperty(t.prototype,"hasLocalMutations",{get:function(){return 1===this.documentState},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hasCommittedMutations",{get:function(){return 2===this.documentState},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hasPendingWrites",{get:function(){return this.hasLocalMutations||this.hasCommittedMutations},enumerable:!1,configurable:!0}),t.prototype.isValidDocument=function(){return 0!==this.documentType},t.prototype.isFoundDocument=function(){return 1===this.documentType},t.prototype.isNoDocument=function(){return 2===this.documentType},t.prototype.isUnknownDocument=function(){return 3===this.documentType},t.prototype.isEqual=function(e){return e instanceof t&&this.key.isEqual(e.key)&&this.version.isEqual(e.version)&&this.documentType===e.documentType&&this.documentState===e.documentState&&this.data.isEqual(e.data)},t.prototype.clone=function(){return new t(this.key,this.documentType,this.version,this.data.clone(),this.documentState)},t.prototype.toString=function(){return"Document("+this.key+", "+this.version+", "+JSON.stringify(this.data.value)+", {documentType: "+this.documentType+"}), {documentState: "+this.documentState+"})"},t}(),ut=function(t,e,n,r,i,o,s){void 0===e&&(e=null),void 0===n&&(n=[]),void 0===r&&(r=[]),void 0===i&&(i=null),void 0===o&&(o=null),void 0===s&&(s=null),this.path=t,this.collectionGroup=e,this.orderBy=n,this.filters=r,this.limit=i,this.startAt=o,this.endAt=s,this.h=null};function ct(t,e,n,r,i,o,s){return void 0===e&&(e=null),void 0===n&&(n=[]),void 0===r&&(r=[]),void 0===i&&(i=null),void 0===o&&(o=null),void 0===s&&(s=null),new ut(t,e,n,r,i,o,s)}function ht(t){var e=m(t);if(null===e.h){var n=e.path.canonicalString();null!==e.collectionGroup&&(n+="|cg:"+e.collectionGroup),n+="|f:",n+=e.filters.map(function(t){return function(t){return t.field.canonicalString()+t.op.toString()+$(t.value)}(t)}).join(","),n+="|ob:",n+=e.orderBy.map(function(t){return function(t){return t.field.canonicalString()+t.dir}(t)}).join(","),B(e.limit)||(n+="|l:",n+=e.limit),e.startAt&&(n+="|lb:",n+=Et(e.startAt)),e.endAt&&(n+="|ub:",n+=Et(e.endAt)),e.h=n}return e.h}function ft(t,e){if(t.limit!==e.limit)return!1;if(t.orderBy.length!==e.orderBy.length)return!1;for(var n=0;n<t.orderBy.length;n++)if(!St(t.orderBy[n],e.orderBy[n]))return!1;if(t.filters.length!==e.filters.length)return!1;for(var r=0;r<t.filters.length;r++)if(i=t.filters[r],o=e.filters[r],i.op!==o.op||!i.field.isEqual(o.field)||!z(i.value,o.value))return!1;var i,o;return t.collectionGroup===e.collectionGroup&&!!t.path.isEqual(e.path)&&!!Dt(t.startAt,e.startAt)&&Dt(t.endAt,e.endAt)}function lt(t){return Q.isDocumentKey(t.path)&&null===t.collectionGroup&&0===t.filters.length}var dt=function(t){function n(e,n,r){var i=this;return(i=t.call(this)||this).field=e,i.op=n,i.value=r,i}return(0,e.__extends)(n,t),n.create=function(t,e,r){return t.isKeyField()?"in"===e||"not-in"===e?this.l(t,e,r):new pt(t,e,r):"array-contains"===e?new gt(t,r):"in"===e?new _t(t,r):"not-in"===e?new wt(t,r):"array-contains-any"===e?new bt(t,r):new n(t,e,r)},n.l=function(t,e,n){return"in"===e?new yt(t,n):new vt(t,n)},n.prototype.matches=function(t){var e=t.data.field(this.field);return"!="===this.op?null!==e&&this.m(H(e,this.value)):null!==e&&G(this.value)===G(e)&&this.m(H(e,this.value))},n.prototype.m=function(t){switch(this.op){case"<":return t<0;case"<=":return t<=0;case"==":return 0===t;case"!=":return 0!==t;case">":return t>0;case">=":return t>=0;default:return y()}},n.prototype.g=function(){return["<","<=",">",">=","!=","not-in"].indexOf(this.op)>=0},n}(function(){}),pt=function(t){function n(e,n,r){var i=this;return(i=t.call(this,e,n,r)||this).key=Q.fromName(r.referenceValue),i}return(0,e.__extends)(n,t),n.prototype.matches=function(t){var e=Q.comparator(t.key,this.key);return this.m(e)},n}(dt),yt=function(t){function n(e,n){var r=this;return(r=t.call(this,e,"in",n)||this).keys=mt("in",n),r}return(0,e.__extends)(n,t),n.prototype.matches=function(t){return this.keys.some(function(e){return e.isEqual(t.key)})},n}(dt),vt=function(t){function n(e,n){var r=this;return(r=t.call(this,e,"not-in",n)||this).keys=mt("not-in",n),r}return(0,e.__extends)(n,t),n.prototype.matches=function(t){return!this.keys.some(function(e){return e.isEqual(t.key)})},n}(dt);function mt(t,e){var n;return((null===(n=e.arrayValue)||void 0===n?void 0:n.values)||[]).map(function(t){return Q.fromName(t.referenceValue)})}var gt=function(t){function n(e,n){return t.call(this,e,"array-contains",n)||this}return(0,e.__extends)(n,t),n.prototype.matches=function(t){var e=t.data.field(this.field);return tt(e)&&W(e.arrayValue,this.value)},n}(dt),_t=function(t){function n(e,n){return t.call(this,e,"in",n)||this}return(0,e.__extends)(n,t),n.prototype.matches=function(t){var e=t.data.field(this.field);return null!==e&&W(this.value.arrayValue,e)},n}(dt),wt=function(t){function n(e,n){return t.call(this,e,"not-in",n)||this}return(0,e.__extends)(n,t),n.prototype.matches=function(t){if(W(this.value.arrayValue,{nullValue:"NULL_VALUE"}))return!1;var e=t.data.field(this.field);return null!==e&&!W(this.value.arrayValue,e)},n}(dt),bt=function(t){function n(e,n){return t.call(this,e,"array-contains-any",n)||this}return(0,e.__extends)(n,t),n.prototype.matches=function(t){var e=this,n=t.data.field(this.field);return!(!tt(n)||!n.arrayValue.values)&&n.arrayValue.values.some(function(t){return W(e.value.arrayValue,t)})},n}(dt),It=function(t,e){this.position=t,this.before=e};function Et(t){return(t.before?"b":"a")+":"+t.position.map(function(t){return $(t)}).join(",")}var Tt=function(t,e){void 0===e&&(e="asc"),this.field=t,this.dir=e};function St(t,e){return t.dir===e.dir&&t.field.isEqual(e.field)}function Nt(t,e,n){for(var r=0,i=0;i<t.position.length;i++){var o=e[i],s=t.position[i];if(r=o.field.isKeyField()?Q.comparator(Q.fromName(s.referenceValue),n.key):H(s,n.data.field(o.field)),"desc"===o.dir&&(r*=-1),0!==r)break}return t.before?r<=0:r<0}function Dt(t,e){if(null===t)return null===e;if(null===e)return!1;if(t.before!==e.before||t.position.length!==e.position.length)return!1;for(var n=0;n<t.position.length;n++)if(!z(t.position[n],e.position[n]))return!1;return!0}var At=function(t,e,n,r,i,o,s,a){void 0===e&&(e=null),void 0===n&&(n=[]),void 0===r&&(r=[]),void 0===i&&(i=null),void 0===o&&(o="F"),void 0===s&&(s=null),void 0===a&&(a=null),this.path=t,this.collectionGroup=e,this.explicitOrderBy=n,this.filters=r,this.limit=i,this.limitType=o,this.startAt=s,this.endAt=a,this.p=null,this.T=null,this.startAt,this.endAt};function xt(t,e,n,r,i,o,s,a){return new At(t,e,n,r,i,o,s,a)}function kt(t){return new At(t)}function Ct(t){return!B(t.limit)&&"F"===t.limitType}function Rt(t){return!B(t.limit)&&"L"===t.limitType}function Lt(t){return t.explicitOrderBy.length>0?t.explicitOrderBy[0].field:null}function Ot(t){for(var e=0,n=t.filters;e<n.length;e++){var r=n[e];if(r.g())return r.field}return null}function Pt(t){return null!==t.collectionGroup}function Ft(t){var e=m(t);if(null===e.p){e.p=[];var n=Ot(e),r=Lt(e);if(null!==n&&null===r)n.isKeyField()||e.p.push(new Tt(n)),e.p.push(new Tt(C.keyField(),"asc"));else{for(var i=!1,o=0,s=e.explicitOrderBy;o<s.length;o++){var a=s[o];e.p.push(a),a.field.isKeyField()&&(i=!0)}if(!i){var u=e.explicitOrderBy.length>0?e.explicitOrderBy[e.explicitOrderBy.length-1].dir:"asc";e.p.push(new Tt(C.keyField(),u))}}}return e.p}function Mt(t){var e=m(t);if(!e.T)if("F"===e.limitType)e.T=ct(e.path,e.collectionGroup,Ft(e),e.filters,e.limit,e.startAt,e.endAt);else{for(var n=[],r=0,i=Ft(e);r<i.length;r++){var o=i[r],s="desc"===o.dir?"asc":"desc";n.push(new Tt(o.field,s))}var a=e.endAt?new It(e.endAt.position,!e.endAt.before):null,u=e.startAt?new It(e.startAt.position,!e.startAt.before):null;e.T=ct(e.path,e.collectionGroup,n,e.filters,e.limit,a,u)}return e.T}function Vt(t,e,n){return new At(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),e,n,t.startAt,t.endAt)}function qt(t,e){return ft(Mt(t),Mt(e))&&t.limitType===e.limitType}function Ut(t){return ht(Mt(t))+"|lt:"+t.limitType}function Bt(t){return"Query(target="+function(t){var e=t.path.canonicalString();return null!==t.collectionGroup&&(e+=" collectionGroup="+t.collectionGroup),t.filters.length>0&&(e+=", filters: ["+t.filters.map(function(t){return(e=t).field.canonicalString()+" "+e.op+" "+$(e.value);var e}).join(", ")+"]"),B(t.limit)||(e+=", limit: "+t.limit),t.orderBy.length>0&&(e+=", orderBy: ["+t.orderBy.map(function(t){return function(t){return t.field.canonicalString()+" ("+t.dir+")"}(t)}).join(", ")+"]"),t.startAt&&(e+=", startAt: "+Et(t.startAt)),t.endAt&&(e+=", endAt: "+Et(t.endAt)),"Target("+e+")"}(Mt(t))+"; limitType="+t.limitType+")"}function jt(t,e){return e.isFoundDocument()&&function(t,e){var n=e.key.path;return null!==t.collectionGroup?e.key.hasCollectionId(t.collectionGroup)&&t.path.isPrefixOf(n):Q.isDocumentKey(t.path)?t.path.isEqual(n):t.path.isImmediateParentOf(n)}(t,e)&&function(t,e){for(var n=0,r=t.explicitOrderBy;n<r.length;n++){var i=r[n];if(!i.field.isKeyField()&&null===e.data.field(i.field))return!1}return!0}(t,e)&&function(t,e){for(var n=0,r=t.filters;n<r.length;n++)if(!r[n].matches(e))return!1;return!0}(t,e)&&function(t,e){return!(t.startAt&&!Nt(t.startAt,Ft(t),e)||t.endAt&&Nt(t.endAt,Ft(t),e))}(t,e)}function Kt(t){return function(e,n){for(var r=!1,i=0,o=Ft(t);i<o.length;i++){var s=o[i],a=Qt(s,e,n);if(0!==a)return a;r=r||s.field.isKeyField()}return 0}}function Qt(t,e,n){var r=t.field.isKeyField()?Q.comparator(e.key,n.key):function(t,e,n){var r=e.data.field(t),i=n.data.field(t);return null!==r&&null!==i?H(r,i):y()}(t.field,e,n);switch(t.dir){case"asc":return r;case"desc":return-1*r;default:return y()}}function Gt(t,e){if(t.I){if(isNaN(e))return{doubleValue:"NaN"};if(e===1/0)return{doubleValue:"Infinity"};if(e===-1/0)return{doubleValue:"-Infinity"}}return{doubleValue:j(e)?"-0":e}}function zt(t){return{integerValue:""+t}}function Wt(t,e){return K(e)?zt(e):Gt(t,e)}var Ht=function(){this._=void 0};function Yt(t,e,n){return t instanceof Jt?function(t,e){var n={fields:{__type__:{stringValue:"server_timestamp"},__local_write_time__:{timestampValue:{seconds:t.seconds,nanos:t.nanoseconds}}}};return e&&(n.fields.__previous_value__=e),{mapValue:n}}(n,e):t instanceof Zt?te(t,e):t instanceof ee?ne(t,e):function(t,e){var n=Xt(t,e),r=ie(n)+ie(t.A);return Z(n)&&Z(t.A)?zt(r):Gt(t.R,r)}(t,e)}function $t(t,e,n){return t instanceof Zt?te(t,e):t instanceof ee?ne(t,e):n}function Xt(t,e){return t instanceof re?Z(n=e)||n&&"doubleValue"in n?e:{integerValue:0}:null;var n}var Jt=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return(0,e.__extends)(n,t),n}(Ht),Zt=function(t){function n(e){var n=this;return(n=t.call(this)||this).elements=e,n}return(0,e.__extends)(n,t),n}(Ht);function te(t,e){for(var n=oe(e),r=function(t){n.some(function(e){return z(e,t)})||n.push(t)},i=0,o=t.elements;i<o.length;i++)r(o[i]);return{arrayValue:{values:n}}}var ee=function(t){function n(e){var n=this;return(n=t.call(this)||this).elements=e,n}return(0,e.__extends)(n,t),n}(Ht);function ne(t,e){for(var n=oe(e),r=function(t){n=n.filter(function(e){return!z(e,t)})},i=0,o=t.elements;i<o.length;i++)r(o[i]);return{arrayValue:{values:n}}}var re=function(t){function n(e,n){var r=this;return(r=t.call(this)||this).R=e,r.A=n,r}return(0,e.__extends)(n,t),n}(Ht);function ie(t){return F(t.integerValue||t.doubleValue)}function oe(t){return tt(t)&&t.arrayValue.values?t.arrayValue.values.slice():[]}var se=function(t,e){this.field=t,this.transform=e},ae=function(t,e){this.version=t,this.transformResults=e},ue=function(){function t(t,e){this.updateTime=t,this.exists=e}return t.none=function(){return new t},t.exists=function(e){return new t(void 0,e)},t.updateTime=function(e){return new t(e)},Object.defineProperty(t.prototype,"isNone",{get:function(){return void 0===this.updateTime&&void 0===this.exists},enumerable:!1,configurable:!0}),t.prototype.isEqual=function(t){return this.exists===t.exists&&(this.updateTime?!!t.updateTime&&this.updateTime.isEqual(t.updateTime):!t.updateTime)},t}();function ce(t,e){return void 0!==t.updateTime?e.isFoundDocument()&&e.version.isEqual(t.updateTime):void 0===t.exists||t.exists===e.isFoundDocument()}var he=function(){};function fe(t,e,n){t instanceof ve?function(t,e,n){var r=t.value.clone(),i=_e(t.fieldTransforms,e,n.transformResults);r.setAll(i),e.convertToFoundDocument(n.version,r).setHasCommittedMutations()}(t,e,n):t instanceof me?function(t,e,n){if(ce(t.precondition,e)){var r=_e(t.fieldTransforms,e,n.transformResults),i=e.data;i.setAll(ge(t)),i.setAll(r),e.convertToFoundDocument(n.version,i).setHasCommittedMutations()}else e.convertToUnknownDocument(n.version)}(t,e,n):function(t,e,n){e.convertToNoDocument(n.version).setHasCommittedMutations()}(0,e,n)}function le(t,e,n){t instanceof ve?function(t,e,n){if(ce(t.precondition,e)){var r=t.value.clone(),i=we(t.fieldTransforms,n,e);r.setAll(i),e.convertToFoundDocument(ye(e),r).setHasLocalMutations()}}(t,e,n):t instanceof me?function(t,e,n){if(ce(t.precondition,e)){var r=we(t.fieldTransforms,n,e),i=e.data;i.setAll(ge(t)),i.setAll(r),e.convertToFoundDocument(ye(e),i).setHasLocalMutations()}}(t,e,n):function(t,e){ce(t.precondition,e)&&e.convertToNoDocument(T.min())}(t,e)}function de(t,e){for(var n=null,r=0,i=t.fieldTransforms;r<i.length;r++){var o=i[r],s=e.data.field(o.field),a=Xt(o.transform,s||null);null!=a&&(null==n&&(n=ot.empty()),n.set(o.field,a))}return n||null}function pe(t,e){return t.type===e.type&&!!t.key.isEqual(e.key)&&!!t.precondition.isEqual(e.precondition)&&!!function(t,e){return void 0===t&&void 0===e||!(!t||!e)&&b(t,e,function(t,e){return function(t,e){return t.field.isEqual(e.field)&&function(t,e){return t instanceof Zt&&e instanceof Zt||t instanceof ee&&e instanceof ee?b(t.elements,e.elements,z):t instanceof re&&e instanceof re?z(t.A,e.A):t instanceof Jt&&e instanceof Jt}(t.transform,e.transform)}(t,e)})}(t.fieldTransforms,e.fieldTransforms)&&(0===t.type?t.value.isEqual(e.value):1!==t.type||t.data.isEqual(e.data)&&t.fieldMask.isEqual(e.fieldMask))}function ye(t){return t.isFoundDocument()?t.version:T.min()}var ve=function(t){function n(e,n,r,i){void 0===i&&(i=[]);var o=this;return(o=t.call(this)||this).key=e,o.value=n,o.precondition=r,o.fieldTransforms=i,o.type=0,o}return(0,e.__extends)(n,t),n}(he),me=function(t){function n(e,n,r,i,o){void 0===o&&(o=[]);var s=this;return(s=t.call(this)||this).key=e,s.data=n,s.fieldMask=r,s.precondition=i,s.fieldTransforms=o,s.type=1,s}return(0,e.__extends)(n,t),n}(he);function ge(t){var e=new Map;return t.fieldMask.fields.forEach(function(n){if(!n.isEmpty()){var r=t.data.field(n);e.set(n,r)}}),e}function _e(t,e,n){var r=new Map;v(t.length===n.length);for(var i=0;i<n.length;i++){var o=t[i],s=o.transform,a=e.data.field(o.field);r.set(o.field,$t(s,a,n[i]))}return r}function we(t,e,n){for(var r=new Map,i=0,o=t;i<o.length;i++){var s=o[i],a=s.transform,u=n.data.field(s.field);r.set(s.field,Yt(a,u,e))}return r}var be,Ie,Ee=function(t){function n(e,n){var r=this;return(r=t.call(this)||this).key=e,r.precondition=n,r.type=2,r.fieldTransforms=[],r}return(0,e.__extends)(n,t),n}(he),Te=function(t){function n(e,n){var r=this;return(r=t.call(this)||this).key=e,r.precondition=n,r.type=3,r.fieldTransforms=[],r}return(0,e.__extends)(n,t),n}(he),Se=function(t){this.count=t};function Ne(t){switch(t){case a.OK:return y();case a.CANCELLED:case a.UNKNOWN:case a.DEADLINE_EXCEEDED:case a.RESOURCE_EXHAUSTED:case a.INTERNAL:case a.UNAVAILABLE:case a.UNAUTHENTICATED:return!1;case a.INVALID_ARGUMENT:case a.NOT_FOUND:case a.ALREADY_EXISTS:case a.PERMISSION_DENIED:case a.FAILED_PRECONDITION:case a.ABORTED:case a.OUT_OF_RANGE:case a.UNIMPLEMENTED:case a.DATA_LOSS:return!0;default:return y()}}function De(t){if(void 0===t)return l("GRPC error has no .code"),a.UNKNOWN;switch(t){case be.OK:return a.OK;case be.CANCELLED:return a.CANCELLED;case be.UNKNOWN:return a.UNKNOWN;case be.DEADLINE_EXCEEDED:return a.DEADLINE_EXCEEDED;case be.RESOURCE_EXHAUSTED:return a.RESOURCE_EXHAUSTED;case be.INTERNAL:return a.INTERNAL;case be.UNAVAILABLE:return a.UNAVAILABLE;case be.UNAUTHENTICATED:return a.UNAUTHENTICATED;case be.INVALID_ARGUMENT:return a.INVALID_ARGUMENT;case be.NOT_FOUND:return a.NOT_FOUND;case be.ALREADY_EXISTS:return a.ALREADY_EXISTS;case be.PERMISSION_DENIED:return a.PERMISSION_DENIED;case be.FAILED_PRECONDITION:return a.FAILED_PRECONDITION;case be.ABORTED:return a.ABORTED;case be.OUT_OF_RANGE:return a.OUT_OF_RANGE;case be.UNIMPLEMENTED:return a.UNIMPLEMENTED;case be.DATA_LOSS:return a.DATA_LOSS;default:return y()}}(Ie=be||(be={}))[Ie.OK=0]="OK",Ie[Ie.CANCELLED=1]="CANCELLED",Ie[Ie.UNKNOWN=2]="UNKNOWN",Ie[Ie.INVALID_ARGUMENT=3]="INVALID_ARGUMENT",Ie[Ie.DEADLINE_EXCEEDED=4]="DEADLINE_EXCEEDED",Ie[Ie.NOT_FOUND=5]="NOT_FOUND",Ie[Ie.ALREADY_EXISTS=6]="ALREADY_EXISTS",Ie[Ie.PERMISSION_DENIED=7]="PERMISSION_DENIED",Ie[Ie.UNAUTHENTICATED=16]="UNAUTHENTICATED",Ie[Ie.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",Ie[Ie.FAILED_PRECONDITION=9]="FAILED_PRECONDITION",Ie[Ie.ABORTED=10]="ABORTED",Ie[Ie.OUT_OF_RANGE=11]="OUT_OF_RANGE",Ie[Ie.UNIMPLEMENTED=12]="UNIMPLEMENTED",Ie[Ie.INTERNAL=13]="INTERNAL",Ie[Ie.UNAVAILABLE=14]="UNAVAILABLE",Ie[Ie.DATA_LOSS=15]="DATA_LOSS";var Ae=function(){function t(t,e){this.comparator=t,this.root=e||ke.EMPTY}return t.prototype.insert=function(e,n){return new t(this.comparator,this.root.insert(e,n,this.comparator).copy(null,null,ke.BLACK,null,null))},t.prototype.remove=function(e){return new t(this.comparator,this.root.remove(e,this.comparator).copy(null,null,ke.BLACK,null,null))},t.prototype.get=function(t){for(var e=this.root;!e.isEmpty();){var n=this.comparator(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.isEmpty();){var r=this.comparator(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.isEmpty=function(){return this.root.isEmpty()},Object.defineProperty(t.prototype,"size",{get:function(){return this.root.size},enumerable:!1,configurable:!0}),t.prototype.minKey=function(){return this.root.minKey()},t.prototype.maxKey=function(){return this.root.maxKey()},t.prototype.inorderTraversal=function(t){return this.root.inorderTraversal(t)},t.prototype.forEach=function(t){this.inorderTraversal(function(e,n){return t(e,n),!1})},t.prototype.toString=function(){var t=[];return this.inorderTraversal(function(e,n){return t.push(e+":"+n),!1}),"{"+t.join(", ")+"}"},t.prototype.reverseTraversal=function(t){return this.root.reverseTraversal(t)},t.prototype.getIterator=function(){return new xe(this.root,null,this.comparator,!1)},t.prototype.getIteratorFrom=function(t){return new xe(this.root,t,this.comparator,!1)},t.prototype.getReverseIterator=function(){return new xe(this.root,null,this.comparator,!0)},t.prototype.getReverseIteratorFrom=function(t){return new xe(this.root,t,this.comparator,!0)},t}(),xe=function(){function t(t,e,n,r){this.isReverse=r,this.nodeStack=[];for(var i=1;!t.isEmpty();)if(i=e?n(t.key,e):1,r&&(i*=-1),i<0)t=this.isReverse?t.left:t.right;else{if(0===i){this.nodeStack.push(t);break}this.nodeStack.push(t),t=this.isReverse?t.right:t.left}}return t.prototype.getNext=function(){var t=this.nodeStack.pop(),e={key:t.key,value:t.value};if(this.isReverse)for(t=t.left;!t.isEmpty();)this.nodeStack.push(t),t=t.right;else for(t=t.right;!t.isEmpty();)this.nodeStack.push(t),t=t.left;return e},t.prototype.hasNext=function(){return this.nodeStack.length>0},t.prototype.peek=function(){if(0===this.nodeStack.length)return null;var t=this.nodeStack[this.nodeStack.length-1];return{key:t.key,value:t.value}},t}(),ke=function(){function t(e,n,r,i,o){this.key=e,this.value=n,this.color=null!=r?r:t.RED,this.left=null!=i?i:t.EMPTY,this.right=null!=o?o:t.EMPTY,this.size=this.left.size+1+this.right.size}return t.prototype.copy=function(e,n,r,i,o){return new t(null!=e?e:this.key,null!=n?n:this.value,null!=r?r:this.color,null!=i?i:this.left,null!=o?o:this.right)},t.prototype.isEmpty=function(){return!1},t.prototype.inorderTraversal=function(t){return this.left.inorderTraversal(t)||t(this.key,this.value)||this.right.inorderTraversal(t)},t.prototype.reverseTraversal=function(t){return this.right.reverseTraversal(t)||t(this.key,this.value)||this.left.reverseTraversal(t)},t.prototype.min=function(){return this.left.isEmpty()?this:this.left.min()},t.prototype.minKey=function(){return this.min().key},t.prototype.maxKey=function(){return this.right.isEmpty()?this.key:this.right.maxKey()},t.prototype.insert=function(t,e,n){var r=this,i=n(t,r.key);return(r=i<0?r.copy(null,null,null,r.left.insert(t,e,n),null):0===i?r.copy(null,e,null,null,null):r.copy(null,null,null,null,r.right.insert(t,e,n))).fixUp()},t.prototype.removeMin=function(){if(this.left.isEmpty())return t.EMPTY;var e=this;return e.left.isRed()||e.left.left.isRed()||(e=e.moveRedLeft()),(e=e.copy(null,null,null,e.left.removeMin(),null)).fixUp()},t.prototype.remove=function(e,n){var r,i=this;if(n(e,i.key)<0)i.left.isEmpty()||i.left.isRed()||i.left.left.isRed()||(i=i.moveRedLeft()),i=i.copy(null,null,null,i.left.remove(e,n),null);else{if(i.left.isRed()&&(i=i.rotateRight()),i.right.isEmpty()||i.right.isRed()||i.right.left.isRed()||(i=i.moveRedRight()),0===n(e,i.key)){if(i.right.isEmpty())return t.EMPTY;r=i.right.min(),i=i.copy(r.key,r.value,null,null,i.right.removeMin())}i=i.copy(null,null,null,null,i.right.remove(e,n))}return i.fixUp()},t.prototype.isRed=function(){return this.color},t.prototype.fixUp=function(){var t=this;return t.right.isRed()&&!t.left.isRed()&&(t=t.rotateLeft()),t.left.isRed()&&t.left.left.isRed()&&(t=t.rotateRight()),t.left.isRed()&&t.right.isRed()&&(t=t.colorFlip()),t},t.prototype.moveRedLeft=function(){var t=this.colorFlip();return t.right.left.isRed()&&(t=(t=(t=t.copy(null,null,null,null,t.right.rotateRight())).rotateLeft()).colorFlip()),t},t.prototype.moveRedRight=function(){var t=this.colorFlip();return t.left.left.isRed()&&(t=(t=t.rotateRight()).colorFlip()),t},t.prototype.rotateLeft=function(){var e=this.copy(null,null,t.RED,null,this.right.left);return this.right.copy(null,null,this.color,e,null)},t.prototype.rotateRight=function(){var e=this.copy(null,null,t.RED,this.left.right,null);return this.left.copy(null,null,this.color,null,e)},t.prototype.colorFlip=function(){var t=this.left.copy(null,null,!this.left.color,null,null),e=this.right.copy(null,null,!this.right.color,null,null);return this.copy(null,null,!this.color,t,e)},t.prototype.checkMaxDepth=function(){var t=this.check();return Math.pow(2,t)<=this.size+1},t.prototype.check=function(){if(this.isRed()&&this.left.isRed())throw y();if(this.right.isRed())throw y();var t=this.left.check();if(t!==this.right.check())throw y();return t+(this.isRed()?0:1)},t}();ke.EMPTY=null,ke.RED=!0,ke.BLACK=!1,ke.EMPTY=new(function(){function t(){this.size=0}return Object.defineProperty(t.prototype,"key",{get:function(){throw y()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"value",{get:function(){throw y()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"color",{get:function(){throw y()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"left",{get:function(){throw y()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"right",{get:function(){throw y()},enumerable:!1,configurable:!0}),t.prototype.copy=function(t,e,n,r,i){return this},t.prototype.insert=function(t,e,n){return new ke(t,e)},t.prototype.remove=function(t,e){return this},t.prototype.isEmpty=function(){return!0},t.prototype.inorderTraversal=function(t){return!1},t.prototype.reverseTraversal=function(t){return!1},t.prototype.minKey=function(){return null},t.prototype.maxKey=function(){return null},t.prototype.isRed=function(){return!1},t.prototype.checkMaxDepth=function(){return!0},t.prototype.check=function(){return 0},t}());var Ce=function(){function t(t){this.comparator=t,this.data=new Ae(this.comparator)}return t.prototype.has=function(t){return null!==this.data.get(t)},t.prototype.first=function(){return this.data.minKey()},t.prototype.last=function(){return this.data.maxKey()},Object.defineProperty(t.prototype,"size",{get:function(){return this.data.size},enumerable:!1,configurable:!0}),t.prototype.indexOf=function(t){return this.data.indexOf(t)},t.prototype.forEach=function(t){this.data.inorderTraversal(function(e,n){return t(e),!1})},t.prototype.forEachInRange=function(t,e){for(var n=this.data.getIteratorFrom(t[0]);n.hasNext();){var r=n.getNext();if(this.comparator(r.key,t[1])>=0)return;e(r.key)}},t.prototype.forEachWhile=function(t,e){var n;for(n=void 0!==e?this.data.getIteratorFrom(e):this.data.getIterator();n.hasNext();)if(!t(n.getNext().key))return},t.prototype.firstAfterOrEqual=function(t){var e=this.data.getIteratorFrom(t);return e.hasNext()?e.getNext().key:null},t.prototype.getIterator=function(){return new Re(this.data.getIterator())},t.prototype.getIteratorFrom=function(t){return new Re(this.data.getIteratorFrom(t))},t.prototype.add=function(t){return this.copy(this.data.remove(t).insert(t,!0))},t.prototype.delete=function(t){return this.has(t)?this.copy(this.data.remove(t)):this},t.prototype.isEmpty=function(){return this.data.isEmpty()},t.prototype.unionWith=function(t){var e=this;return e.size<t.size&&(e=t,t=this),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.getIterator(),r=e.data.getIterator();n.hasNext();){var i=n.getNext().key,o=r.getNext().key;if(0!==this.comparator(i,o))return!1}return!0},t.prototype.toArray=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.copy=function(e){var n=new t(this.comparator);return n.data=e,n},t}(),Re=function(){function t(t){this.iter=t}return t.prototype.getNext=function(){return this.iter.getNext().key},t.prototype.hasNext=function(){return this.iter.hasNext()},t}(),Le=new Ae(Q.comparator);function Oe(){return Le}var Pe=new Ae(Q.comparator);function Fe(){return Pe}var Me=new Ae(Q.comparator);function Ve(){return Me}var qe=new Ce(Q.comparator);function Ue(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];for(var n=qe,r=0,i=t;r<i.length;r++){var o=i[r];n=n.add(o)}return n}var Be=new Ce(w);function je(){return Be}var Ke=function(){function t(t,e,n,r,i){this.snapshotVersion=t,this.targetChanges=e,this.targetMismatches=n,this.documentUpdates=r,this.resolvedLimboDocuments=i}return t.createSynthesizedRemoteEventForCurrentChange=function(e,n){var r=new Map;return r.set(e,Qe.createSynthesizedTargetChangeForCurrentChange(e,n)),new t(T.min(),r,je(),Oe(),Ue())},t}(),Qe=function(){function t(t,e,n,r,i){this.resumeToken=t,this.current=e,this.addedDocuments=n,this.modifiedDocuments=r,this.removedDocuments=i}return t.createSynthesizedTargetChangeForCurrentChange=function(e,n){return new t(L.EMPTY_BYTE_STRING,n,Ue(),Ue(),Ue())},t}(),Ge=function(t,e,n,r){this.v=t,this.removedTargetIds=e,this.key=n,this.P=r},ze=function(t,e){this.targetId=t,this.V=e},We=function(t,e,n,r){void 0===n&&(n=L.EMPTY_BYTE_STRING),void 0===r&&(r=null),this.state=t,this.targetIds=e,this.resumeToken=n,this.cause=r},He=function(){function t(){this.S=0,this.D=Xe(),this.C=L.EMPTY_BYTE_STRING,this.N=!1,this.k=!0}return Object.defineProperty(t.prototype,"current",{get:function(){return this.N},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"resumeToken",{get:function(){return this.C},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"F",{get:function(){return 0!==this.S},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"$",{get:function(){return this.k},enumerable:!1,configurable:!0}),t.prototype.O=function(t){t.approximateByteSize()>0&&(this.k=!0,this.C=t)},t.prototype.M=function(){var t=Ue(),e=Ue(),n=Ue();return this.D.forEach(function(r,i){switch(i){case 0:t=t.add(r);break;case 2:e=e.add(r);break;case 1:n=n.add(r);break;default:y()}}),new Qe(this.C,this.N,t,e,n)},t.prototype.L=function(){this.k=!1,this.D=Xe()},t.prototype.B=function(t,e){this.k=!0,this.D=this.D.insert(t,e)},t.prototype.q=function(t){this.k=!0,this.D=this.D.remove(t)},t.prototype.U=function(){this.S+=1},t.prototype.K=function(){this.S-=1},t.prototype.j=function(){this.k=!0,this.N=!0},t}(),Ye=function(){function t(t){this.W=t,this.G=new Map,this.H=Oe(),this.J=$e(),this.Y=new Ce(w)}return t.prototype.X=function(t){for(var e=0,n=t.v;e<n.length;e++){var r=n[e];t.P&&t.P.isFoundDocument()?this.Z(r,t.P):this.tt(r,t.key,t.P)}for(var i=0,o=t.removedTargetIds;i<o.length;i++)r=o[i],this.tt(r,t.key,t.P)},t.prototype.et=function(t){var e=this;this.forEachTarget(t,function(n){var r=e.nt(n);switch(t.state){case 0:e.st(n)&&r.O(t.resumeToken);break;case 1:r.K(),r.F||r.L(),r.O(t.resumeToken);break;case 2:r.K(),r.F||e.removeTarget(n);break;case 3:e.st(n)&&(r.j(),r.O(t.resumeToken));break;case 4:e.st(n)&&(e.it(n),r.O(t.resumeToken));break;default:y()}})},t.prototype.forEachTarget=function(t,e){var n=this;t.targetIds.length>0?t.targetIds.forEach(e):this.G.forEach(function(t,r){n.st(r)&&e(r)})},t.prototype.rt=function(t){var e=t.targetId,n=t.V.count,r=this.ot(e);if(r){var i=r.target;if(lt(i))if(0===n){var o=new Q(i.path);this.tt(e,o,at.newNoDocument(o,T.min()))}else v(1===n);else this.ct(e)!==n&&(this.it(e),this.Y=this.Y.add(e))}},t.prototype.ut=function(t){var e=this,n=new Map;this.G.forEach(function(r,i){var o=e.ot(i);if(o){if(r.current&&lt(o.target)){var s=new Q(o.target.path);null!==e.H.get(s)||e.at(i,s)||e.tt(i,s,at.newNoDocument(s,t))}r.$&&(n.set(i,r.M()),r.L())}});var r=Ue();this.J.forEach(function(t,n){var i=!0;n.forEachWhile(function(t){var n=e.ot(t);return!n||2===n.purpose||(i=!1,!1)}),i&&(r=r.add(t))});var i=new Ke(t,n,this.Y,this.H,r);return this.H=Oe(),this.J=$e(),this.Y=new Ce(w),i},t.prototype.Z=function(t,e){if(this.st(t)){var n=this.at(t,e.key)?2:0;this.nt(t).B(e.key,n),this.H=this.H.insert(e.key,e),this.J=this.J.insert(e.key,this.ht(e.key).add(t))}},t.prototype.tt=function(t,e,n){if(this.st(t)){var r=this.nt(t);this.at(t,e)?r.B(e,1):r.q(e),this.J=this.J.insert(e,this.ht(e).delete(t)),n&&(this.H=this.H.insert(e,n))}},t.prototype.removeTarget=function(t){this.G.delete(t)},t.prototype.ct=function(t){var e=this.nt(t).M();return this.W.getRemoteKeysForTarget(t).size+e.addedDocuments.size-e.removedDocuments.size},t.prototype.U=function(t){this.nt(t).U()},t.prototype.nt=function(t){var e=this.G.get(t);return e||(e=new He,this.G.set(t,e)),e},t.prototype.ht=function(t){var e=this.J.get(t);return e||(e=new Ce(w),this.J=this.J.insert(t,e)),e},t.prototype.st=function(t){var e=null!==this.ot(t);return e||f("WatchChangeAggregator","Detected inactive target",t),e},t.prototype.ot=function(t){var e=this.G.get(t);return e&&e.F?null:this.W.lt(t)},t.prototype.it=function(t){var e=this;this.G.set(t,new He),this.W.getRemoteKeysForTarget(t).forEach(function(n){e.tt(t,n,null)})},t.prototype.at=function(t,e){return this.W.getRemoteKeysForTarget(t).has(e)},t}();function $e(){return new Ae(Q.comparator)}function Xe(){return new Ae(Q.comparator)}var Je={asc:"ASCENDING",desc:"DESCENDING"},Ze={"<":"LESS_THAN","<=":"LESS_THAN_OR_EQUAL",">":"GREATER_THAN",">=":"GREATER_THAN_OR_EQUAL","==":"EQUAL","!=":"NOT_EQUAL","array-contains":"ARRAY_CONTAINS",in:"IN","not-in":"NOT_IN","array-contains-any":"ARRAY_CONTAINS_ANY"},tn=function(t,e){this.databaseId=t,this.I=e};function en(t,e){return t.I?new Date(1e3*e.seconds).toISOString().replace(/\.\d*/,"").replace("Z","")+"."+("000000000"+e.nanoseconds).slice(-9)+"Z":{seconds:""+e.seconds,nanos:e.nanoseconds}}function nn(t,e){return t.I?e.toBase64():e.toUint8Array()}function rn(t,e){return en(t,e.toTimestamp())}function on(t){return v(!!t),T.fromTimestamp(function(t){var e=P(t);return new E(e.seconds,e.nanos)}(t))}function sn(t,e){return function(t){return new x(["projects",t.projectId,"databases",t.database])}(t).child("documents").child(e).canonicalString()}function an(t){var e=x.fromString(t);return v(Cn(e)),e}function un(t,e){return sn(t.databaseId,e.path)}function cn(t,e){var n=an(e);if(n.get(1)!==t.databaseId.projectId)throw new u(a.INVALID_ARGUMENT,"Tried to deserialize key from different project: "+n.get(1)+" vs "+t.databaseId.projectId);if(n.get(3)!==t.databaseId.database)throw new u(a.INVALID_ARGUMENT,"Tried to deserialize key from different database: "+n.get(3)+" vs "+t.databaseId.database);return new Q(dn(n))}function hn(t,e){return sn(t.databaseId,e)}function fn(t){var e=an(t);return 4===e.length?x.emptyPath():dn(e)}function ln(t){return new x(["projects",t.databaseId.projectId,"databases",t.databaseId.database]).canonicalString()}function dn(t){return v(t.length>4&&"documents"===t.get(4)),t.popFirst(5)}function pn(t,e,n){return{name:un(t,e),fields:n.value.mapValue.fields}}function yn(t,e,n){var r=cn(t,e.name),i=on(e.updateTime),o=new ot({mapValue:{fields:e.fields}}),s=at.newFoundDocument(r,i,o);return n&&s.setHasCommittedMutations(),n?s.setHasCommittedMutations():s}function vn(t,e){var n;if(e instanceof ve)n={update:pn(t,e.key,e.value)};else if(e instanceof Ee)n={delete:un(t,e.key)};else if(e instanceof me)n={update:pn(t,e.key,e.data),updateMask:kn(e.fieldMask)};else{if(!(e instanceof Te))return y();n={verify:un(t,e.key)}}return e.fieldTransforms.length>0&&(n.updateTransforms=e.fieldTransforms.map(function(t){return function(t,e){var n=e.transform;if(n instanceof Jt)return{fieldPath:e.field.canonicalString(),setToServerValue:"REQUEST_TIME"};if(n instanceof Zt)return{fieldPath:e.field.canonicalString(),appendMissingElements:{values:n.elements}};if(n instanceof ee)return{fieldPath:e.field.canonicalString(),removeAllFromArray:{values:n.elements}};if(n instanceof re)return{fieldPath:e.field.canonicalString(),increment:n.A};throw y()}(0,t)})),e.precondition.isNone||(n.currentDocument=function(t,e){return void 0!==e.updateTime?{updateTime:rn(t,e.updateTime)}:void 0!==e.exists?{exists:e.exists}:y()}(t,e.precondition)),n}function mn(t,e){var n=e.currentDocument?function(t){return void 0!==t.updateTime?ue.updateTime(on(t.updateTime)):void 0!==t.exists?ue.exists(t.exists):ue.none()}(e.currentDocument):ue.none(),r=e.updateTransforms?e.updateTransforms.map(function(e){return function(t,e){var n=null;if("setToServerValue"in e)v("REQUEST_TIME"===e.setToServerValue),n=new Jt;else if("appendMissingElements"in e){var r=e.appendMissingElements.values||[];n=new Zt(r)}else if("removeAllFromArray"in e){var i=e.removeAllFromArray.values||[];n=new ee(i)}else"increment"in e?n=new re(t,e.increment):y();var o=C.fromServerFormat(e.fieldPath);return new se(o,n)}(t,e)}):[];if(e.update){e.update.name;var i=cn(t,e.update.name),o=new ot({mapValue:{fields:e.update.fields}});if(e.updateMask){var s=function(t){var e=t.fieldPaths||[];return new R(e.map(function(t){return C.fromServerFormat(t)}))}(e.updateMask);return new me(i,o,s,n,r)}return new ve(i,o,n,r)}if(e.delete){var a=cn(t,e.delete);return new Ee(a,n)}if(e.verify){var u=cn(t,e.verify);return new Te(u,n)}return y()}function gn(t,e){return{documents:[hn(t,e.path)]}}function _n(t,e){var n={structuredQuery:{}},r=e.path;null!==e.collectionGroup?(n.parent=hn(t,r),n.structuredQuery.from=[{collectionId:e.collectionGroup,allDescendants:!0}]):(n.parent=hn(t,r.popLast()),n.structuredQuery.from=[{collectionId:r.lastSegment()}]);var i=function(t){if(0!==t.length){var e=t.map(function(t){return function(t){if("=="===t.op){if(nt(t.value))return{unaryFilter:{field:Nn(t.field),op:"IS_NAN"}};if(et(t.value))return{unaryFilter:{field:Nn(t.field),op:"IS_NULL"}}}else if("!="===t.op){if(nt(t.value))return{unaryFilter:{field:Nn(t.field),op:"IS_NOT_NAN"}};if(et(t.value))return{unaryFilter:{field:Nn(t.field),op:"IS_NOT_NULL"}}}return{fieldFilter:{field:Nn(t.field),op:Sn(t.op),value:t.value}}}(t)});return 1===e.length?e[0]:{compositeFilter:{op:"AND",filters:e}}}}(e.filters);i&&(n.structuredQuery.where=i);var o=function(t){if(0!==t.length)return t.map(function(t){return function(t){return{field:Nn(t.field),direction:Tn(t.dir)}}(t)})}(e.orderBy);o&&(n.structuredQuery.orderBy=o);var s=function(t,e){return t.I||B(e)?e:{value:e}}(t,e.limit);return null!==s&&(n.structuredQuery.limit=s),e.startAt&&(n.structuredQuery.startAt=In(e.startAt)),e.endAt&&(n.structuredQuery.endAt=In(e.endAt)),n}function wn(t){var e=fn(t.parent),n=t.structuredQuery,r=n.from?n.from.length:0,i=null;if(r>0){v(1===r);var s=n.from[0];s.allDescendants?i=s.collectionId:e=e.child(s.collectionId)}var a=[];n.where&&(a=bn(n.where));var u=[];n.orderBy&&(u=n.orderBy.map(function(t){return function(t){return new Tt(Dn(t.field),function(t){switch(t){case"ASCENDING":return"asc";case"DESCENDING":return"desc";default:return}}(t.direction))}(t)}));var c=null;n.limit&&(c=function(t){var e;return B(e="object"==o(t)?t.value:t)?null:e}(n.limit));var h=null;n.startAt&&(h=En(n.startAt));var f=null;return n.endAt&&(f=En(n.endAt)),xt(e,i,u,a,c,"F",h,f)}function bn(t){return t?void 0!==t.unaryFilter?[xn(t)]:void 0!==t.fieldFilter?[An(t)]:void 0!==t.compositeFilter?t.compositeFilter.filters.map(function(t){return bn(t)}).reduce(function(t,e){return t.concat(e)}):y():[]}function In(t){return{before:t.before,values:t.position}}function En(t){var e=!!t.before,n=t.values||[];return new It(n,e)}function Tn(t){return Je[t]}function Sn(t){return Ze[t]}function Nn(t){return{fieldPath:t.canonicalString()}}function Dn(t){return C.fromServerFormat(t.fieldPath)}function An(t){return dt.create(Dn(t.fieldFilter.field),function(t){switch(t){case"EQUAL":return"==";case"NOT_EQUAL":return"!=";case"GREATER_THAN":return">";case"GREATER_THAN_OR_EQUAL":return">=";case"LESS_THAN":return"<";case"LESS_THAN_OR_EQUAL":return"<=";case"ARRAY_CONTAINS":return"array-contains";case"IN":return"in";case"NOT_IN":return"not-in";case"ARRAY_CONTAINS_ANY":return"array-contains-any";case"OPERATOR_UNSPECIFIED":default:return y()}}(t.fieldFilter.op),t.fieldFilter.value)}function xn(t){switch(t.unaryFilter.op){case"IS_NAN":var e=Dn(t.unaryFilter.field);return dt.create(e,"==",{doubleValue:NaN});case"IS_NULL":var n=Dn(t.unaryFilter.field);return dt.create(n,"==",{nullValue:"NULL_VALUE"});case"IS_NOT_NAN":var r=Dn(t.unaryFilter.field);return dt.create(r,"!=",{doubleValue:NaN});case"IS_NOT_NULL":var i=Dn(t.unaryFilter.field);return dt.create(i,"!=",{nullValue:"NULL_VALUE"});case"OPERATOR_UNSPECIFIED":default:return y()}}function kn(t){var e=[];return t.fields.forEach(function(t){return e.push(t.canonicalString())}),{fieldPaths:e}}function Cn(t){return t.length>=4&&"projects"===t.get(0)&&"databases"===t.get(2)}function Rn(t){for(var e="",n=0;n<t.length;n++)e.length>0&&(e=On(e)),e=Ln(t.get(n),e);return On(e)}function Ln(t,e){for(var n=e,r=t.length,i=0;i<r;i++){var o=t.charAt(i);switch(o){case"\0":n+="";break;case"":n+="";break;default:n+=o}}return n}function On(t){return t+""}function Pn(t){var e=t.length;if(v(e>=2),2===e)return v(""===t.charAt(0)&&""===t.charAt(1)),x.emptyPath();for(var n=e-2,r=[],i="",o=0;o<e;){var s=t.indexOf("",o);switch((s<0||s>n)&&y(),t.charAt(s+1)){case"":var a=t.substring(o,s),u=void 0;0===i.length?u=a:(u=i+=a,i=""),r.push(u);break;case"":i+=t.substring(o,s),i+="\0";break;case"":i+=t.substring(o,s+1);break;default:y()}o=s+2}return new x(r)}var Fn=function(t,e){this.seconds=t,this.nanoseconds=e},Mn=function(t,e,n){this.ownerId=t,this.allowTabSynchronization=e,this.leaseTimestampMs=n};Mn.store="owner",Mn.key="owner";var Vn=function(t,e,n){this.userId=t,this.lastAcknowledgedBatchId=e,this.lastStreamToken=n};Vn.store="mutationQueues",Vn.keyPath="userId";var qn=function(t,e,n,r,i){this.userId=t,this.batchId=e,this.localWriteTimeMs=n,this.baseMutations=r,this.mutations=i};qn.store="mutations",qn.keyPath="batchId",qn.userMutationsIndex="userMutationsIndex",qn.userMutationsKeyPath=["userId","batchId"];var Un=function(){function t(){}return t.prefixForUser=function(t){return[t]},t.prefixForPath=function(t,e){return[t,Rn(e)]},t.key=function(t,e,n){return[t,Rn(e),n]},t}();Un.store="documentMutations",Un.PLACEHOLDER=new Un;var Bn=function(t,e){this.path=t,this.readTime=e},jn=function(t,e){this.path=t,this.version=e},Kn=function(t,e,n,r,i,o){this.unknownDocument=t,this.noDocument=e,this.document=n,this.hasCommittedMutations=r,this.readTime=i,this.parentPath=o};Kn.store="remoteDocuments",Kn.readTimeIndex="readTimeIndex",Kn.readTimeIndexPath="readTime",Kn.collectionReadTimeIndex="collectionReadTimeIndex",Kn.collectionReadTimeIndexPath=["parentPath","readTime"];var Qn=function(t){this.byteSize=t};Qn.store="remoteDocumentGlobal",Qn.key="remoteDocumentGlobalKey";var Gn=function(t,e,n,r,i,o,s){this.targetId=t,this.canonicalId=e,this.readTime=n,this.resumeToken=r,this.lastListenSequenceNumber=i,this.lastLimboFreeSnapshotVersion=o,this.query=s};Gn.store="targets",Gn.keyPath="targetId",Gn.queryTargetsIndexName="queryTargetsIndex",Gn.queryTargetsKeyPath=["canonicalId","targetId"];var zn=function(t,e,n){this.targetId=t,this.path=e,this.sequenceNumber=n};zn.store="targetDocuments",zn.keyPath=["targetId","path"],zn.documentTargetsIndex="documentTargetsIndex",zn.documentTargetsKeyPath=["path","targetId"];var Wn=function(t,e,n,r){this.highestTargetId=t,this.highestListenSequenceNumber=e,this.lastRemoteSnapshotVersion=n,this.targetCount=r};Wn.key="targetGlobalKey",Wn.store="targetGlobal";var Hn=function(t,e){this.collectionId=t,this.parent=e};Hn.store="collectionParents",Hn.keyPath=["collectionId","parent"];var Yn=function(t,e,n,r){this.clientId=t,this.updateTimeMs=e,this.networkEnabled=n,this.inForeground=r};Yn.store="clientMetadata",Yn.keyPath="clientId";var $n=function(t,e,n){this.bundleId=t,this.createTime=e,this.version=n};$n.store="bundles",$n.keyPath="bundleId";var Xn=function(t,e,n){this.name=t,this.readTime=e,this.bundledQuery=n};Xn.store="namedQueries",Xn.keyPath="name";var Jn=(0,e.__spreadArray)((0,e.__spreadArray)([],(0,e.__spreadArray)((0,e.__spreadArray)([],(0,e.__spreadArray)((0,e.__spreadArray)([],(0,e.__spreadArray)((0,e.__spreadArray)([],[Vn.store,qn.store,Un.store,Kn.store,Gn.store,Mn.store,Wn.store,zn.store]),[Yn.store])),[Qn.store])),[Hn.store])),[$n.store,Xn.store]),Zn="The current tab is not in the required state to perform this operation. It might be necessary to refresh the browser tab.",tr=function(){function t(){this.onCommittedListeners=[]}return t.prototype.addOnCommittedListener=function(t){this.onCommittedListeners.push(t)},t.prototype.raiseOnCommittedEvent=function(){this.onCommittedListeners.forEach(function(t){return t()})},t}(),er=function(){var t=this;this.promise=new Promise(function(e,n){t.resolve=e,t.reject=n})},nr=function(){function t(t){var e=this;this.nextCallback=null,this.catchCallback=null,this.result=void 0,this.error=void 0,this.isDone=!1,this.callbackAttached=!1,t(function(t){e.isDone=!0,e.result=t,e.nextCallback&&e.nextCallback(t)},function(t){e.isDone=!0,e.error=t,e.catchCallback&&e.catchCallback(t)})}return t.prototype.catch=function(t){return this.next(void 0,t)},t.prototype.next=function(e,n){var r=this;return this.callbackAttached&&y(),this.callbackAttached=!0,this.isDone?this.error?this.wrapFailure(n,this.error):this.wrapSuccess(e,this.result):new t(function(t,i){r.nextCallback=function(n){r.wrapSuccess(e,n).next(t,i)},r.catchCallback=function(e){r.wrapFailure(n,e).next(t,i)}})},t.prototype.toPromise=function(){var t=this;return new Promise(function(e,n){t.next(e,n)})},t.prototype.wrapUserFunction=function(e){try{var n=e();return n instanceof t?n:t.resolve(n)}catch(e){return t.reject(e)}},t.prototype.wrapSuccess=function(e,n){return e?this.wrapUserFunction(function(){return e(n)}):t.resolve(n)},t.prototype.wrapFailure=function(e,n){return e?this.wrapUserFunction(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.waitFor=function(e){return new t(function(t,n){var r=0,i=0,o=!1;e.forEach(function(e){++r,e.next(function(){++i,o&&i===r&&t()},function(t){return n(t)})}),o=!0,i===r&&t()})},t.or=function(e){for(var n=t.resolve(!1),r=function(e){n=n.next(function(n){return n?t.resolve(n):e()})},i=0,o=e;i<o.length;i++)r(o[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.waitFor(r)},t}(),rr=function(){function t(t,e){var n=this;this.action=t,this.transaction=e,this.aborted=!1,this.ft=new er,this.transaction.oncomplete=function(){n.ft.resolve()},this.transaction.onabort=function(){e.error?n.ft.reject(new sr(t,e.error)):n.ft.resolve()},this.transaction.onerror=function(e){var r=fr(e.target.error);n.ft.reject(new sr(t,r))}}return t.open=function(e,n,r,i){try{return new t(n,e.transaction(i,r))}catch(e){throw new sr(n,e)}},Object.defineProperty(t.prototype,"dt",{get:function(){return this.ft.promise},enumerable:!1,configurable:!0}),t.prototype.abort=function(t){t&&this.ft.reject(t),this.aborted||(f("SimpleDb","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 new ur(e)},t}(),ir=function(){function r(t,e,i){this.name=t,this.version=e,this.wt=i,12.2===r._t((0,n.getUA)())&&l("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 r.delete=function(t){return f("SimpleDb","Removing database:",t),cr(window.indexedDB.deleteDatabase(t)).toPromise()},r.yt=function(){if("undefined"==typeof indexedDB)return!1;if(r.gt())return!0;var t=(0,n.getUA)(),e=r._t(t),i=0<e&&e<10,o=r.Et(t),s=0<o&&o<4.5;return!(t.indexOf("MSIE ")>0||t.indexOf("Trident/")>0||t.indexOf("Edge/")>0||i||s)},r.gt=function(){var e;return void 0!==t&&"YES"===(null===(e=t.env)||void 0===e?void 0:e.Tt)},r.It=function(t,e){return t.store(e)},r._t=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)},r.Et=function(t){var e=t.match(/Android ([\d.]+)/i),n=e?e[1].split(".").slice(0,2).join("."):"-1";return Number(n)},r.prototype.At=function(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n,r=this;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return this.db?[3,2]:(f("SimpleDb","Opening database:",this.name),n=this,[4,new Promise(function(e,n){var i=indexedDB.open(r.name,r.version);i.onsuccess=function(t){var n=t.target.result;e(n)},i.onblocked=function(){n(new sr(t,"Cannot upgrade IndexedDB schema while another tab is open. Close all tabs that access Firestore and reload this page to proceed."))},i.onerror=function(e){var r=e.target.error;"VersionError"===r.name?n(new u(a.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.")):n(new sr(t,r))},i.onupgradeneeded=function(t){f("SimpleDb",'Database "'+r.name+'" requires upgrade from version:',t.oldVersion);var e=t.target.result;r.wt.Rt(e,i.transaction,t.oldVersion,r.version).next(function(){f("SimpleDb","Database upgrade to version "+r.version+" complete")})}})]);case 1:n.db=e.sent(),e.label=2;case 2:return[2,(this.bt&&(this.db.onversionchange=function(t){return r.bt(t)}),this.db)]}})})},r.prototype.vt=function(t){this.bt=t,this.db&&(this.db.onversionchange=function(e){return t(e)})},r.prototype.runTransaction=function(t,n,r,i){return(0,e.__awaiter)(this,void 0,void 0,function(){var s,a,u,c,h;return(0,e.__generator)(this,function(l){switch(l.label){case 0:s="readonly"===n,a=0,u=function(){var n,o,u,h,l;return(0,e.__generator)(this,function(e){switch(e.label){case 0:++a,e.label=1;case 1:return e.trys.push([1,4,,5]),[4,c.At(t)];case 2:return c.db=e.sent(),n=rr.open(c.db,t,s?"readonly":"readwrite",r),o=i(n).catch(function(t){return n.abort(t),nr.reject(t)}).toPromise(),u={},o.catch(function(){}),[4,n.dt];case 3:return[2,(u.value=(e.sent(),o),u)];case 4:return h=e.sent(),l="FirebaseError"!==h.name&&a<3,f("SimpleDb","Transaction failed with error:",h.message,"Retrying:",l),c.close(),l?[3,5]:[2,{value:Promise.reject(h)}];case 5:return[2]}})},c=this,l.label=1;case 1:return[5,u()];case 2:if("object"==o(h=l.sent()))return[2,h.value];l.label=3;case 3:return[3,1];case 4:return[2]}})})},r.prototype.close=function(){this.db&&this.db.close(),this.db=void 0},r}(),or=function(){function t(t){this.Pt=t,this.Vt=!1,this.St=null}return Object.defineProperty(t.prototype,"isDone",{get:function(){return this.Vt},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Dt",{get:function(){return this.St},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"cursor",{set:function(t){this.Pt=t},enumerable:!1,configurable:!0}),t.prototype.done=function(){this.Vt=!0},t.prototype.Ct=function(t){this.St=t},t.prototype.delete=function(){return cr(this.Pt.delete())},t}(),sr=function(t){function n(e,n){var r=this;return(r=t.call(this,a.UNAVAILABLE,"IndexedDB transaction '"+e+"' failed: "+n)||this).name="IndexedDbTransactionError",r}return(0,e.__extends)(n,t),n}(u);function ar(t){return"IndexedDbTransactionError"===t.name}var ur=function(){function t(t){this.store=t}return t.prototype.put=function(t,e){var n;return void 0!==e?(f("SimpleDb","PUT",this.store.name,t,e),n=this.store.put(e,t)):(f("SimpleDb","PUT",this.store.name,"<auto-key>",t),n=this.store.put(t)),cr(n)},t.prototype.add=function(t){return f("SimpleDb","ADD",this.store.name,t,t),cr(this.store.add(t))},t.prototype.get=function(t){var e=this;return cr(this.store.get(t)).next(function(n){return void 0===n&&(n=null),f("SimpleDb","GET",e.store.name,t,n),n})},t.prototype.delete=function(t){return f("SimpleDb","DELETE",this.store.name,t),cr(this.store.delete(t))},t.prototype.count=function(){return f("SimpleDb","COUNT",this.store.name),cr(this.store.count())},t.prototype.Nt=function(t,e){var n=this.cursor(this.options(t,e)),r=[];return this.xt(n,function(t,e){r.push(e)}).next(function(){return r})},t.prototype.kt=function(t,e){f("SimpleDb","DELETE ALL",this.store.name);var n=this.options(t,e);n.Ft=!1;var r=this.cursor(n);return this.xt(r,function(t,e,n){return n.delete()})},t.prototype.$t=function(t,e){var n;e?n=t:(n={},e=t);var r=this.cursor(n);return this.xt(r,e)},t.prototype.Ot=function(t){var e=this.cursor({});return new nr(function(n,r){e.onerror=function(t){var e=fr(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.xt=function(t,e){var n=[];return new nr(function(r,i){t.onerror=function(t){i(t.target.error)},t.onsuccess=function(t){var i=t.target.result;if(i){var o=new or(i),s=e(i.primaryKey,i.value,o);if(s instanceof nr){var a=s.catch(function(t){return o.done(),nr.reject(t)});n.push(a)}o.isDone?r():null===o.Dt?i.continue():i.continue(o.Dt)}else r()}}).next(function(){return nr.waitFor(n)})},t.prototype.options=function(t,e){var n;return void 0!==t&&("string"==typeof t?n=t: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.Ft?n.openKeyCursor(t.range,e):n.openCursor(t.range,e)}return this.store.openCursor(t.range,e)},t}();function cr(t){return new nr(function(e,n){t.onsuccess=function(t){var n=t.target.result;e(n)},t.onerror=function(t){var e=fr(t.target.error);n(e)}})}var hr=!1;function fr(t){var e=ir._t((0,n.getUA)());if(e>=12.2&&e<13){var r="An internal error was encountered in the Indexed Database server";if(t.message.indexOf(r)>=0){var i=new u("internal","IOS_INDEXEDDB_BUG1: IndexedDb has thrown '"+r+"'. This is likely due to an unavoidable bug in iOS. See https://stackoverflow.com/q/56496296/110915 for details and a potential workaround.");return hr||(hr=!0,setTimeout(function(){throw i},0)),i}}return t}var lr=function(t){function n(e,n){var r=this;return(r=t.call(this)||this).Mt=e,r.currentSequenceNumber=n,r}return(0,e.__extends)(n,t),n}(tr);function dr(t,e){var n=m(t);return ir.It(n.Mt,e)}var pr=function(){function t(t,e,n,r){this.batchId=t,this.localWriteTime=e,this.baseMutations=n,this.mutations=r}return t.prototype.applyToRemoteDocument=function(t,e){for(var n=e.mutationResults,r=0;r<this.mutations.length;r++){var i=this.mutations[r];i.key.isEqual(t.key)&&fe(i,t,n[r])}},t.prototype.applyToLocalView=function(t){for(var e=0,n=this.baseMutations;e<n.length;e++)(o=n[e]).key.isEqual(t.key)&&le(o,t,this.localWriteTime);for(var r=0,i=this.mutations;r<i.length;r++){var o;(o=i[r]).key.isEqual(t.key)&&le(o,t,this.localWriteTime)}},t.prototype.applyToLocalDocumentSet=function(t){var e=this;this.mutations.forEach(function(n){var r=t.get(n.key),i=r;e.applyToLocalView(i),r.isValidDocument()||i.convertToNoDocument(T.min())})},t.prototype.keys=function(){return this.mutations.reduce(function(t,e){return t.add(e.key)},Ue())},t.prototype.isEqual=function(t){return this.batchId===t.batchId&&b(this.mutations,t.mutations,function(t,e){return pe(t,e)})&&b(this.baseMutations,t.baseMutations,function(t,e){return pe(t,e)})},t}(),yr=function(){function t(t,e,n,r){this.batch=t,this.commitVersion=e,this.mutationResults=n,this.docVersions=r}return t.from=function(e,n,r){v(e.mutations.length===r.length);for(var i=Ve(),o=e.mutations,s=0;s<o.length;s++)i=i.insert(o[s].key,r[s].version);return new t(e,n,r,i)},t}(),vr=function(){function t(t,e,n,r,i,o,s){void 0===i&&(i=T.min()),void 0===o&&(o=T.min()),void 0===s&&(s=L.EMPTY_BYTE_STRING),this.target=t,this.targetId=e,this.purpose=n,this.sequenceNumber=r,this.snapshotVersion=i,this.lastLimboFreeSnapshotVersion=o,this.resumeToken=s}return t.prototype.withSequenceNumber=function(e){return new t(this.target,this.targetId,this.purpose,e,this.snapshotVersion,this.lastLimboFreeSnapshotVersion,this.resumeToken)},t.prototype.withResumeToken=function(e,n){return new t(this.target,this.targetId,this.purpose,this.sequenceNumber,n,this.lastLimboFreeSnapshotVersion,e)},t.prototype.withLastLimboFreeSnapshotVersion=function(e){return new t(this.target,this.targetId,this.purpose,this.sequenceNumber,this.snapshotVersion,e,this.resumeToken)},t}(),mr=function(t){this.Lt=t};function gr(t,e){if(e.document)return yn(t.Lt,e.document,!!e.hasCommittedMutations);if(e.noDocument){var n=Q.fromSegments(e.noDocument.path),r=Er(e.noDocument.readTime),i=at.newNoDocument(n,r);return e.hasCommittedMutations?i.setHasCommittedMutations():i}if(e.unknownDocument){var o=Q.fromSegments(e.unknownDocument.path);return r=Er(e.unknownDocument.version),at.newUnknownDocument(o,r)}return y()}function _r(t,e,n){var r=wr(n),i=e.key.path.popLast().toArray();if(e.isFoundDocument()){var o=function(t,e){return{name:un(t,e.key),fields:e.data.value.mapValue.fields,updateTime:en(t,e.version.toTimestamp())}}(t.Lt,e),s=e.hasCommittedMutations;return new Kn(null,null,o,s,r,i)}if(e.isNoDocument()){var a=e.key.path.toArray(),u=Ir(e.version);return s=e.hasCommittedMutations,new Kn(null,new Bn(a,u),null,s,r,i)}if(e.isUnknownDocument()){var c=e.key.path.toArray(),h=Ir(e.version);return new Kn(new jn(c,h),null,null,!0,r,i)}return y()}function wr(t){var e=t.toTimestamp();return[e.seconds,e.nanoseconds]}function br(t){var e=new E(t[0],t[1]);return T.fromTimestamp(e)}function Ir(t){var e=t.toTimestamp();return new Fn(e.seconds,e.nanoseconds)}function Er(t){var e=new E(t.seconds,t.nanoseconds);return T.fromTimestamp(e)}function Tr(t,e){for(var n=(e.baseMutations||[]).map(function(e){return mn(t.Lt,e)}),r=0;r<e.mutations.length-1;++r){var i=e.mutations[r];if(r+1<e.mutations.length&&void 0!==e.mutations[r+1].transform){var o=e.mutations[r+1];i.updateTransforms=o.transform.fieldTransforms,e.mutations.splice(r+1,1),++r}}var s=e.mutations.map(function(e){return mn(t.Lt,e)}),a=E.fromMillis(e.localWriteTimeMs);return new pr(e.batchId,a,n,s)}function Sr(t){var e,n,r=Er(t.readTime),i=void 0!==t.lastLimboFreeSnapshotVersion?Er(t.lastLimboFreeSnapshotVersion):T.min();return void 0!==t.query.documents?(v(1===(n=t.query).documents.length),e=Mt(kt(fn(n.documents[0])))):e=function(t){return Mt(wn(t))}(t.query),new vr(e,t.targetId,0,t.lastListenSequenceNumber,r,i,L.fromBase64String(t.resumeToken))}function Nr(t,e){var n,r=Ir(e.snapshotVersion),i=Ir(e.lastLimboFreeSnapshotVersion);n=lt(e.target)?gn(t.Lt,e.target):_n(t.Lt,e.target);var o=e.resumeToken.toBase64();return new Gn(e.targetId,ht(e.target),r,o,e.sequenceNumber,i,n)}function Dr(t){var e=wn({parent:t.parent,structuredQuery:t.structuredQuery});return"LAST"===t.limitType?Vt(e,e.limit,"L"):e}var Ar=function(){function t(){}return t.prototype.getBundleMetadata=function(t,e){return xr(t).get(e).next(function(t){if(t)return{id:(e=t).bundleId,createTime:Er(e.createTime),version:e.version};var e})},t.prototype.saveBundleMetadata=function(t,e){return xr(t).put({bundleId:(n=e).id,createTime:Ir(on(n.createTime)),version:n.version});var n},t.prototype.getNamedQuery=function(t,e){return kr(t).get(e).next(function(t){if(t)return{name:(e=t).name,query:Dr(e.bundledQuery),readTime:Er(e.readTime)};var e})},t.prototype.saveNamedQuery=function(t,e){return kr(t).put(function(t){return{name:t.name,readTime:Ir(on(t.readTime)),bundledQuery:t.bundledQuery}}(e))},t}();function xr(t){return dr(t,$n.store)}function kr(t){return dr(t,Xn.store)}var Cr=function(){function t(){this.Bt=new Rr}return t.prototype.addToCollectionParentIndex=function(t,e){return this.Bt.add(e),nr.resolve()},t.prototype.getCollectionParents=function(t,e){return nr.resolve(this.Bt.getEntries(e))},t}(),Rr=function(){function t(){this.index={}}return t.prototype.add=function(t){var e=t.lastSegment(),n=t.popLast(),r=this.index[e]||new Ce(x.comparator),i=!r.has(n);return this.index[e]=r.add(n),i},t.prototype.has=function(t){var e=t.lastSegment(),n=t.popLast(),r=this.index[e];return r&&r.has(n)},t.prototype.getEntries=function(t){return(this.index[t]||new Ce(x.comparator)).toArray()},t}(),Lr=function(){function t(){this.qt=new Rr}return t.prototype.addToCollectionParentIndex=function(t,e){var n=this;if(!this.qt.has(e)){var r=e.lastSegment(),i=e.popLast();t.addOnCommittedListener(function(){n.qt.add(e)});var o={collectionId:r,parent:Rn(i)};return Or(t).put(o)}return nr.resolve()},t.prototype.getCollectionParents=function(t,e){var n=[],r=IDBKeyRange.bound([e,""],[I(e),""],!1,!0);return Or(t).Nt(r).next(function(t){for(var r=0,i=t;r<i.length;r++){var o=i[r];if(o.collectionId!==e)break;n.push(Pn(o.parent))}return n})},t}();function Or(t){return dr(t,Hn.store)}var Pr={didRun:!1,sequenceNumbersCollected:0,targetsRemoved:0,documentsRemoved:0},Fr=function(){function t(t,e,n){this.cacheSizeCollectionThreshold=t,this.percentileToCollect=e,this.maximumSequenceNumbersToCollect=n}return t.withCacheSize=function(e){return new t(e,t.DEFAULT_COLLECTION_PERCENTILE,t.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT)},t}();function Mr(t,e,n){var r=t.store(qn.store),i=t.store(Un.store),o=[],s=IDBKeyRange.only(n.batchId),a=0,u=r.$t({range:s},function(t,e,n){return a++,n.delete()});o.push(u.next(function(){v(1===a)}));for(var c=[],h=0,f=n.mutations;h<f.length;h++){var l=f[h],d=Un.key(e,l.key.path,n.batchId);o.push(i.delete(d)),c.push(l.key)}return nr.waitFor(o).next(function(){return c})}function Vr(t){if(!t)return 0;var e;if(t.document)e=t.document;else if(t.unknownDocument)e=t.unknownDocument;else{if(!t.noDocument)throw y();e=t.noDocument}return JSON.stringify(e).length}Fr.DEFAULT_COLLECTION_PERCENTILE=10,Fr.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT=1e3,Fr.DEFAULT=new Fr(41943040,Fr.DEFAULT_COLLECTION_PERCENTILE,Fr.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT),Fr.DISABLED=new Fr(-1,0,0);var qr=function(){function t(t,e,n,r){this.userId=t,this.R=e,this.Ut=n,this.referenceDelegate=r,this.Kt={}}return t.Qt=function(e,n,r,i){return v(""!==e.uid),new t(e.isAuthenticated()?e.uid:"",n,r,i)},t.prototype.checkEmpty=function(t){var e=!0,n=IDBKeyRange.bound([this.userId,Number.NEGATIVE_INFINITY],[this.userId,Number.POSITIVE_INFINITY]);return Br(t).$t({index:qn.userMutationsIndex,range:n},function(t,n,r){e=!1,r.done()}).next(function(){return e})},t.prototype.addMutationBatch=function(t,e,n,r){var i=this,o=jr(t),s=Br(t);return s.add({}).next(function(a){v("number"==typeof a);for(var u=new pr(a,e,n,r),c=function(t,e,n){var r=n.baseMutations.map(function(e){return vn(t.Lt,e)}),i=n.mutations.map(function(e){return vn(t.Lt,e)});return new qn(e,n.batchId,n.localWriteTime.toMillis(),r,i)}(i.R,i.userId,u),h=[],f=new Ce(function(t,e){return w(t.canonicalString(),e.canonicalString())}),l=0,d=r;l<d.length;l++){var p=d[l],y=Un.key(i.userId,p.key.path,a);f=f.add(p.key.path.popLast()),h.push(s.put(c)),h.push(o.put(y,Un.PLACEHOLDER))}return f.forEach(function(e){h.push(i.Ut.addToCollectionParentIndex(t,e))}),t.addOnCommittedListener(function(){i.Kt[a]=u.keys()}),nr.waitFor(h).next(function(){return u})})},t.prototype.lookupMutationBatch=function(t,e){var n=this;return Br(t).get(e).next(function(t){return t?(v(t.userId===n.userId),Tr(n.R,t)):null})},t.prototype.jt=function(t,e){var n=this;return this.Kt[e]?nr.resolve(this.Kt[e]):this.lookupMutationBatch(t,e).next(function(t){if(t){var r=t.keys();return n.Kt[e]=r,r}return null})},t.prototype.getNextMutationBatchAfterBatchId=function(t,e){var n=this,r=e+1,i=IDBKeyRange.lowerBound([this.userId,r]),o=null;return Br(t).$t({index:qn.userMutationsIndex,range:i},function(t,e,i){e.userId===n.userId&&(v(e.batchId>=r),o=Tr(n.R,e)),i.done()}).next(function(){return o})},t.prototype.getHighestUnacknowledgedBatchId=function(t){var e=IDBKeyRange.upperBound([this.userId,Number.POSITIVE_INFINITY]),n=-1;return Br(t).$t({index:qn.userMutationsIndex,range:e,reverse:!0},function(t,e,r){n=e.batchId,r.done()}).next(function(){return n})},t.prototype.getAllMutationBatches=function(t){var e=this,n=IDBKeyRange.bound([this.userId,-1],[this.userId,Number.POSITIVE_INFINITY]);return Br(t).Nt(qn.userMutationsIndex,n).next(function(t){return t.map(function(t){return Tr(e.R,t)})})},t.prototype.getAllMutationBatchesAffectingDocumentKey=function(t,e){var n=this,r=Un.prefixForPath(this.userId,e.path),i=IDBKeyRange.lowerBound(r),o=[];return jr(t).$t({range:i},function(r,i,s){var a=r[0],u=r[1],c=r[2],h=Pn(u);if(a===n.userId&&e.path.isEqual(h))return Br(t).get(c).next(function(t){if(!t)throw y();v(t.userId===n.userId),o.push(Tr(n.R,t))});s.done()}).next(function(){return o})},t.prototype.getAllMutationBatchesAffectingDocumentKeys=function(t,e){var n=this,r=new Ce(w),i=[];return e.forEach(function(e){var o=Un.prefixForPath(n.userId,e.path),s=IDBKeyRange.lowerBound(o),a=jr(t).$t({range:s},function(t,i,o){var s=t[0],a=t[1],u=t[2],c=Pn(a);s===n.userId&&e.path.isEqual(c)?r=r.add(u):o.done()});i.push(a)}),nr.waitFor(i).next(function(){return n.Wt(t,r)})},t.prototype.getAllMutationBatchesAffectingQuery=function(t,e){var n=this,r=e.path,i=r.length+1,o=Un.prefixForPath(this.userId,r),s=IDBKeyRange.lowerBound(o),a=new Ce(w);return jr(t).$t({range:s},function(t,e,o){var s=t[0],u=t[1],c=t[2],h=Pn(u);s===n.userId&&r.isPrefixOf(h)?h.length===i&&(a=a.add(c)):o.done()}).next(function(){return n.Wt(t,a)})},t.prototype.Wt=function(t,e){var n=this,r=[],i=[];return e.forEach(function(e){i.push(Br(t).get(e).next(function(t){if(null===t)throw y();v(t.userId===n.userId),r.push(Tr(n.R,t))}))}),nr.waitFor(i).next(function(){return r})},t.prototype.removeMutationBatch=function(t,e){var n=this;return Mr(t.Mt,this.userId,e).next(function(r){return t.addOnCommittedListener(function(){n.Gt(e.batchId)}),nr.forEach(r,function(e){return n.referenceDelegate.markPotentiallyOrphaned(t,e)})})},t.prototype.Gt=function(t){delete this.Kt[t]},t.prototype.performConsistencyCheck=function(t){var e=this;return this.checkEmpty(t).next(function(n){if(!n)return nr.resolve();var r=IDBKeyRange.lowerBound(Un.prefixForUser(e.userId)),i=[];return jr(t).$t({range:r},function(t,n,r){if(t[0]===e.userId){var o=Pn(t[1]);i.push(o)}else r.done()}).next(function(){v(0===i.length)})})},t.prototype.containsKey=function(t,e){return Ur(t,this.userId,e)},t.prototype.zt=function(t){var e=this;return Kr(t).get(this.userId).next(function(t){return t||new Vn(e.userId,-1,"")})},t}();function Ur(t,e,n){var r=Un.prefixForPath(e,n.path),i=r[1],o=IDBKeyRange.lowerBound(r),s=!1;return jr(t).$t({range:o,Ft:!0},function(t,n,r){var o=t[0],a=t[1];t[2],o===e&&a===i&&(s=!0),r.done()}).next(function(){return s})}function Br(t){return dr(t,qn.store)}function jr(t){return dr(t,Un.store)}function Kr(t){return dr(t,Vn.store)}var Qr=function(){function t(t){this.Ht=t}return t.prototype.next=function(){return this.Ht+=2,this.Ht},t.Jt=function(){return new t(0)},t.Yt=function(){return new t(-1)},t}(),Gr=function(){function t(t,e){this.referenceDelegate=t,this.R=e}return t.prototype.allocateTargetId=function(t){var e=this;return this.Xt(t).next(function(n){var r=new Qr(n.highestTargetId);return n.highestTargetId=r.next(),e.Zt(t,n).next(function(){return n.highestTargetId})})},t.prototype.getLastRemoteSnapshotVersion=function(t){return this.Xt(t).next(function(t){return T.fromTimestamp(new E(t.lastRemoteSnapshotVersion.seconds,t.lastRemoteSnapshotVersion.nanoseconds))})},t.prototype.getHighestSequenceNumber=function(t){return this.Xt(t).next(function(t){return t.highestListenSequenceNumber})},t.prototype.setTargetsMetadata=function(t,e,n){var r=this;return this.Xt(t).next(function(i){return i.highestListenSequenceNumber=e,n&&(i.lastRemoteSnapshotVersion=n.toTimestamp()),e>i.highestListenSequenceNumber&&(i.highestListenSequenceNumber=e),r.Zt(t,i)})},t.prototype.addTargetData=function(t,e){var n=this;return this.te(t,e).next(function(){return n.Xt(t).next(function(r){return r.targetCount+=1,n.ee(e,r),n.Zt(t,r)})})},t.prototype.updateTargetData=function(t,e){return this.te(t,e)},t.prototype.removeTargetData=function(t,e){var n=this;return this.removeMatchingKeysForTargetId(t,e.targetId).next(function(){return zr(t).delete(e.targetId)}).next(function(){return n.Xt(t)}).next(function(e){return v(e.targetCount>0),e.targetCount-=1,n.Zt(t,e)})},t.prototype.removeTargets=function(t,e,n){var r=this,i=0,o=[];return zr(t).$t(function(s,a){var u=Sr(a);u.sequenceNumber<=e&&null===n.get(u.targetId)&&(i++,o.push(r.removeTargetData(t,u)))}).next(function(){return nr.waitFor(o)}).next(function(){return i})},t.prototype.forEachTarget=function(t,e){return zr(t).$t(function(t,n){var r=Sr(n);e(r)})},t.prototype.Xt=function(t){return Wr(t).get(Wn.key).next(function(t){return v(null!==t),t})},t.prototype.Zt=function(t,e){return Wr(t).put(Wn.key,e)},t.prototype.te=function(t,e){return zr(t).put(Nr(this.R,e))},t.prototype.ee=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.getTargetCount=function(t){return this.Xt(t).next(function(t){return t.targetCount})},t.prototype.getTargetData=function(t,e){var n=ht(e),r=IDBKeyRange.bound([n,Number.NEGATIVE_INFINITY],[n,Number.POSITIVE_INFINITY]),i=null;return zr(t).$t({range:r,index:Gn.queryTargetsIndexName},function(t,n,r){var o=Sr(n);ft(e,o.target)&&(i=o,r.done())}).next(function(){return i})},t.prototype.addMatchingKeys=function(t,e,n){var r=this,i=[],o=Hr(t);return e.forEach(function(e){var s=Rn(e.path);i.push(o.put(new zn(n,s))),i.push(r.referenceDelegate.addReference(t,n,e))}),nr.waitFor(i)},t.prototype.removeMatchingKeys=function(t,e,n){var r=this,i=Hr(t);return nr.forEach(e,function(e){var o=Rn(e.path);return nr.waitFor([i.delete([n,o]),r.referenceDelegate.removeReference(t,n,e)])})},t.prototype.removeMatchingKeysForTargetId=function(t,e){var n=Hr(t),r=IDBKeyRange.bound([e],[e+1],!1,!0);return n.delete(r)},t.prototype.getMatchingKeysForTargetId=function(t,e){var n=IDBKeyRange.bound([e],[e+1],!1,!0),r=Hr(t),i=Ue();return r.$t({range:n,Ft:!0},function(t,e,n){var r=Pn(t[1]),o=new Q(r);i=i.add(o)}).next(function(){return i})},t.prototype.containsKey=function(t,e){var n=Rn(e.path),r=IDBKeyRange.bound([n],[I(n)],!1,!0),i=0;return Hr(t).$t({index:zn.documentTargetsIndex,Ft:!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.lt=function(t,e){return zr(t).get(e).next(function(t){return t?Sr(t):null})},t}();function zr(t){return dr(t,Gn.store)}function Wr(t){return dr(t,Wn.store)}function Hr(t){return dr(t,zn.store)}function Yr(t){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(e){if(t.code!==a.FAILED_PRECONDITION||t.message!==Zn)throw t;return f("LocalStore","Unexpectedly lost primary lease"),[2]})})}function $r(t,e){var n=t[0],r=t[1],i=e[0],o=e[1],s=w(n,i);return 0===s?w(r,o):s}var Xr=function(){function t(t){this.ne=t,this.buffer=new Ce($r),this.se=0}return t.prototype.ie=function(){return++this.se},t.prototype.re=function(t){var e=[t,this.ie()];if(this.buffer.size<this.ne)this.buffer=this.buffer.add(e);else{var n=this.buffer.last();$r(e,n)<0&&(this.buffer=this.buffer.delete(n).add(e))}},Object.defineProperty(t.prototype,"maxValue",{get:function(){return this.buffer.last()[0]},enumerable:!1,configurable:!0}),t}(),Jr=function(){function t(t,e){this.garbageCollector=t,this.asyncQueue=e,this.oe=!1,this.ce=null}return t.prototype.start=function(t){-1!==this.garbageCollector.params.cacheSizeCollectionThreshold&&this.ue(t)},t.prototype.stop=function(){this.ce&&(this.ce.cancel(),this.ce=null)},Object.defineProperty(t.prototype,"started",{get:function(){return null!==this.ce},enumerable:!1,configurable:!0}),t.prototype.ue=function(t){var n=this,r=this.oe?3e5:6e4;f("LruGarbageCollector","Garbage collection scheduled in "+r+"ms"),this.ce=this.asyncQueue.enqueueAfterDelay("lru_garbage_collection",r,function(){return(0,e.__awaiter)(n,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:this.ce=null,this.oe=!0,e.label=1;case 1:return e.trys.push([1,3,,7]),[4,t.collectGarbage(this.garbageCollector)];case 2:return e.sent(),[3,7];case 3:return ar(n=e.sent())?(f("LruGarbageCollector","Ignoring IndexedDB error during garbage collection: ",n),[3,6]):[3,4];case 4:return[4,Yr(n)];case 5:e.sent(),e.label=6;case 6:return[3,7];case 7:return[4,this.ue(t)];case 8:return e.sent(),[2]}})})})},t}(),Zr=function(){function t(t,e){this.ae=t,this.params=e}return t.prototype.calculateTargetCount=function(t,e){return this.ae.he(t).next(function(t){return Math.floor(e/100*t)})},t.prototype.nthSequenceNumber=function(t,e){var n=this;if(0===e)return nr.resolve(s.o);var r=new Xr(e);return this.ae.forEachTarget(t,function(t){return r.re(t.sequenceNumber)}).next(function(){return n.ae.le(t,function(t){return r.re(t)})}).next(function(){return r.maxValue})},t.prototype.removeTargets=function(t,e,n){return this.ae.removeTargets(t,e,n)},t.prototype.removeOrphanedDocuments=function(t,e){return this.ae.removeOrphanedDocuments(t,e)},t.prototype.collect=function(t,e){var n=this;return-1===this.params.cacheSizeCollectionThreshold?(f("LruGarbageCollector","Garbage collection skipped; disabled"),nr.resolve(Pr)):this.getCacheSize(t).next(function(r){return r<n.params.cacheSizeCollectionThreshold?(f("LruGarbageCollector","Garbage collection skipped; Cache size "+r+" is lower than threshold "+n.params.cacheSizeCollectionThreshold),Pr):n.fe(t,e)})},t.prototype.getCacheSize=function(t){return this.ae.getCacheSize(t)},t.prototype.fe=function(t,e){var n,i,o,s,a,u,c,l=this,d=Date.now();return this.calculateTargetCount(t,this.params.percentileToCollect).next(function(e){return e>l.params.maximumSequenceNumbersToCollect?(f("LruGarbageCollector","Capping sequence numbers to collect down to the maximum of "+l.params.maximumSequenceNumbersToCollect+" from "+e),i=l.params.maximumSequenceNumbersToCollect):i=e,s=Date.now(),l.nthSequenceNumber(t,i)}).next(function(r){return n=r,a=Date.now(),l.removeTargets(t,n,e)}).next(function(e){return o=e,u=Date.now(),l.removeOrphanedDocuments(t,n)}).next(function(t){return c=Date.now(),h()<=r.LogLevel.DEBUG&&f("LruGarbageCollector","LRU Garbage Collection\n\tCounted targets in "+(s-d)+"ms\n\tDetermined least recently used "+i+" in "+(a-s)+"ms\n\tRemoved "+o+" targets in "+(u-a)+"ms\n\tRemoved "+t+" documents in "+(c-u)+"ms\nTotal Duration: "+(c-d)+"ms"),nr.resolve({didRun:!0,sequenceNumbersCollected:i,targetsRemoved:o,documentsRemoved:t})})},t}(),ti=function(){function t(t,e){this.db=t,this.garbageCollector=function(t,e){return new Zr(t,e)}(this,e)}return t.prototype.he=function(t){var e=this.de(t);return this.db.getTargetCache().getTargetCount(t).next(function(t){return e.next(function(e){return t+e})})},t.prototype.de=function(t){var e=0;return this.le(t,function(t){e++}).next(function(){return e})},t.prototype.forEachTarget=function(t,e){return this.db.getTargetCache().forEachTarget(t,e)},t.prototype.le=function(t,e){return this.we(t,function(t,n){return e(n)})},t.prototype.addReference=function(t,e,n){return ei(t,n)},t.prototype.removeReference=function(t,e,n){return ei(t,n)},t.prototype.removeTargets=function(t,e,n){return this.db.getTargetCache().removeTargets(t,e,n)},t.prototype.markPotentiallyOrphaned=function(t,e){return ei(t,e)},t.prototype._e=function(t,e){return function(t,e){var n=!1;return Kr(t).Ot(function(r){return Ur(t,r,e).next(function(t){return t&&(n=!0),nr.resolve(!t)})}).next(function(){return n})}(t,e)},t.prototype.removeOrphanedDocuments=function(t,e){var n=this,r=this.db.getRemoteDocumentCache().newChangeBuffer(),i=[],o=0;return this.we(t,function(s,a){if(a<=e){var u=n._e(t,s).next(function(e){if(!e)return o++,r.getEntry(t,s).next(function(){return r.removeEntry(s),Hr(t).delete([0,Rn(s.path)])})});i.push(u)}}).next(function(){return nr.waitFor(i)}).next(function(){return r.apply(t)}).next(function(){return o})},t.prototype.removeTarget=function(t,e){var n=e.withSequenceNumber(t.currentSequenceNumber);return this.db.getTargetCache().updateTargetData(t,n)},t.prototype.updateLimboDocument=function(t,e){return ei(t,e)},t.prototype.we=function(t,e){var n,r=Hr(t),i=s.o;return r.$t({index:zn.documentTargetsIndex},function(t,r){var o=t[0];t[1];var a=r.path,u=r.sequenceNumber;0===o?(i!==s.o&&e(new Q(Pn(n)),i),i=u,n=a):i=s.o}).next(function(){i!==s.o&&e(new Q(Pn(n)),i)})},t.prototype.getCacheSize=function(t){return this.db.getRemoteDocumentCache().getSize(t)},t}();function ei(t,e){return Hr(t).put(function(t,e){return new zn(0,Rn(t.path),e)}(e,t.currentSequenceNumber))}var ni=function(){function t(t,e){this.mapKeyFn=t,this.equalsFn=e,this.inner={}}return t.prototype.get=function(t){var e=this.mapKeyFn(t),n=this.inner[e];if(void 0!==n)for(var r=0,i=n;r<i.length;r++){var o=i[r],s=o[0],a=o[1];if(this.equalsFn(s,t))return a}},t.prototype.has=function(t){return void 0!==this.get(t)},t.prototype.set=function(t,e){var n=this.mapKeyFn(t),r=this.inner[n];if(void 0!==r){for(var i=0;i<r.length;i++)if(this.equalsFn(r[i][0],t))return void(r[i]=[t,e]);r.push([t,e])}else this.inner[n]=[[t,e]]},t.prototype.delete=function(t){var e=this.mapKeyFn(t),n=this.inner[e];if(void 0===n)return!1;for(var r=0;r<n.length;r++)if(this.equalsFn(n[r][0],t))return 1===n.length?delete this.inner[e]:n.splice(r,1),!0;return!1},t.prototype.forEach=function(t){N(this.inner,function(e,n){for(var r=0,i=n;r<i.length;r++){var o=i[r],s=o[0],a=o[1];t(s,a)}})},t.prototype.isEmpty=function(){return D(this.inner)},t}(),ri=function(){function t(){this.changes=new ni(function(t){return t.toString()},function(t,e){return t.isEqual(e)}),this.changesApplied=!1}return t.prototype.getReadTime=function(t){var e=this.changes.get(t);return e?e.readTime:T.min()},t.prototype.addEntry=function(t,e){this.assertNotApplied(),this.changes.set(t.key,{document:t,readTime:e})},t.prototype.removeEntry=function(t,e){void 0===e&&(e=null),this.assertNotApplied(),this.changes.set(t,{document:at.newInvalidDocument(t),readTime:e})},t.prototype.getEntry=function(t,e){this.assertNotApplied();var n=this.changes.get(e);return void 0!==n?nr.resolve(n.document):this.getFromCache(t,e)},t.prototype.getEntries=function(t,e){return this.getAllFromCache(t,e)},t.prototype.apply=function(t){return this.assertNotApplied(),this.changesApplied=!0,this.applyChanges(t)},t.prototype.assertNotApplied=function(){},t}(),ii=function(){function t(t,e){this.R=t,this.Ut=e}return t.prototype.addEntry=function(t,e,n){return ai(t).put(ui(e),n)},t.prototype.removeEntry=function(t,e){var n=ai(t),r=ui(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.me(t,r)})},t.prototype.getEntry=function(t,e){var n=this;return ai(t).get(ui(e)).next(function(t){return n.ye(e,t)})},t.prototype.ge=function(t,e){var n=this;return ai(t).get(ui(e)).next(function(t){return{document:n.ye(e,t),size:Vr(t)}})},t.prototype.getEntries=function(t,e){var n=this,r=Oe();return this.pe(t,e,function(t,e){var i=n.ye(t,e);r=r.insert(t,i)}).next(function(){return r})},t.prototype.Ee=function(t,e){var n=this,r=Oe(),i=new Ae(Q.comparator);return this.pe(t,e,function(t,e){var o=n.ye(t,e);r=r.insert(t,o),i=i.insert(t,Vr(e))}).next(function(){return{documents:r,Te:i}})},t.prototype.pe=function(t,e,n){if(e.isEmpty())return nr.resolve();var r=IDBKeyRange.bound(e.first().path.toArray(),e.last().path.toArray()),i=e.getIterator(),o=i.getNext();return ai(t).$t({range:r},function(t,e,r){for(var s=Q.fromSegments(t);o&&Q.comparator(o,s)<0;)n(o,null),o=i.getNext();o&&o.isEqual(s)&&(n(o,e),o=i.hasNext()?i.getNext():null),o?r.Ct(o.path.toArray()):r.done()}).next(function(){for(;o;)n(o,null),o=i.hasNext()?i.getNext():null})},t.prototype.getDocumentsMatchingQuery=function(t,e,n){var r=this,i=Oe(),o=e.path.length+1,s={};if(n.isEqual(T.min())){var a=e.path.toArray();s.range=IDBKeyRange.lowerBound(a)}else{var u=e.path.toArray(),c=wr(n);s.range=IDBKeyRange.lowerBound([u,c],!0),s.index=Kn.collectionReadTimeIndex}return ai(t).$t(s,function(t,n,s){if(t.length===o){var a=gr(r.R,n);e.path.isPrefixOf(a.key.path)?jt(e,a)&&(i=i.insert(a.key,a)):s.done()}}).next(function(){return i})},t.prototype.newChangeBuffer=function(t){return new oi(this,!!t&&t.trackRemovals)},t.prototype.getSize=function(t){return this.getMetadata(t).next(function(t){return t.byteSize})},t.prototype.getMetadata=function(t){return si(t).get(Qn.key).next(function(t){return v(!!t),t})},t.prototype.me=function(t,e){return si(t).put(Qn.key,e)},t.prototype.ye=function(t,e){if(e){var n=gr(this.R,e);if(!n.isNoDocument()||!n.version.isEqual(T.min()))return n}return at.newInvalidDocument(t)},t}(),oi=function(t){function n(e,n){var r=this;return(r=t.call(this)||this).Ie=e,r.trackRemovals=n,r.Ae=new ni(function(t){return t.toString()},function(t,e){return t.isEqual(e)}),r}return(0,e.__extends)(n,t),n.prototype.applyChanges=function(t){var e=this,n=[],r=0,i=new Ce(function(t,e){return w(t.canonicalString(),e.canonicalString())});return this.changes.forEach(function(o,s){var a=e.Ae.get(o);if(s.document.isValidDocument()){var u=_r(e.Ie.R,s.document,e.getReadTime(o));i=i.add(o.path.popLast());var c=Vr(u);r+=c-a,n.push(e.Ie.addEntry(t,o,u))}else if(r-=a,e.trackRemovals){var h=_r(e.Ie.R,at.newNoDocument(o,T.min()),e.getReadTime(o));n.push(e.Ie.addEntry(t,o,h))}else n.push(e.Ie.removeEntry(t,o))}),i.forEach(function(r){n.push(e.Ie.Ut.addToCollectionParentIndex(t,r))}),n.push(this.Ie.updateMetadata(t,r)),nr.waitFor(n)},n.prototype.getFromCache=function(t,e){var n=this;return this.Ie.ge(t,e).next(function(t){return n.Ae.set(e,t.size),t.document})},n.prototype.getAllFromCache=function(t,e){var n=this;return this.Ie.Ee(t,e).next(function(t){var e=t.documents;return t.Te.forEach(function(t,e){n.Ae.set(t,e)}),e})},n}(ri);function si(t){return dr(t,Qn.store)}function ai(t){return dr(t,Kn.store)}function ui(t){return t.path.toArray()}var ci=function(){function t(t){this.R=t}return t.prototype.Rt=function(t,e,n,r){var i=this;v(n<r&&n>=0&&r<=11);var o=new rr("createOrUpgrade",e);n<1&&r>=1&&(function(t){t.createObjectStore(Mn.store)}(t),function(t){t.createObjectStore(Vn.store,{keyPath:Vn.keyPath}),t.createObjectStore(qn.store,{keyPath:qn.keyPath,autoIncrement:!0}).createIndex(qn.userMutationsIndex,qn.userMutationsKeyPath,{unique:!0}),t.createObjectStore(Un.store)}(t),hi(t),function(t){t.createObjectStore(Kn.store)}(t));var s=nr.resolve();return n<3&&r>=3&&(0!==n&&(function(t){t.deleteObjectStore(zn.store),t.deleteObjectStore(Gn.store),t.deleteObjectStore(Wn.store)}(t),hi(t)),s=s.next(function(){return t=o.store(Wn.store),e=new Wn(0,0,T.min().toTimestamp(),0),t.put(Wn.key,e);var t,e})),n<4&&r>=4&&(0!==n&&(s=s.next(function(){return function(t,e){return e.store(qn.store).Nt().next(function(n){t.deleteObjectStore(qn.store),t.createObjectStore(qn.store,{keyPath:qn.keyPath,autoIncrement:!0}).createIndex(qn.userMutationsIndex,qn.userMutationsKeyPath,{unique:!0});var r=e.store(qn.store),i=n.map(function(t){return r.put(t)});return nr.waitFor(i)})}(t,o)})),s=s.next(function(){!function(t){t.createObjectStore(Yn.store,{keyPath:Yn.keyPath})}(t)})),n<5&&r>=5&&(s=s.next(function(){return i.Re(o)})),n<6&&r>=6&&(s=s.next(function(){return function(t){t.createObjectStore(Qn.store)}(t),i.be(o)})),n<7&&r>=7&&(s=s.next(function(){return i.ve(o)})),n<8&&r>=8&&(s=s.next(function(){return i.Pe(t,o)})),n<9&&r>=9&&(s=s.next(function(){!function(t){t.objectStoreNames.contains("remoteDocumentChanges")&&t.deleteObjectStore("remoteDocumentChanges")}(t),function(t){var e=t.objectStore(Kn.store);e.createIndex(Kn.readTimeIndex,Kn.readTimeIndexPath,{unique:!1}),e.createIndex(Kn.collectionReadTimeIndex,Kn.collectionReadTimeIndexPath,{unique:!1})}(e)})),n<10&&r>=10&&(s=s.next(function(){return i.Ve(o)})),n<11&&r>=11&&(s=s.next(function(){!function(t){t.createObjectStore($n.store,{keyPath:$n.keyPath})}(t),function(t){t.createObjectStore(Xn.store,{keyPath:Xn.keyPath})}(t)})),s},t.prototype.be=function(t){var e=0;return t.store(Kn.store).$t(function(t,n){e+=Vr(n)}).next(function(){var n=new Qn(e);return t.store(Qn.store).put(Qn.key,n)})},t.prototype.Re=function(t){var e=this,n=t.store(Vn.store),r=t.store(qn.store);return n.Nt().next(function(n){return nr.forEach(n,function(n){var i=IDBKeyRange.bound([n.userId,-1],[n.userId,n.lastAcknowledgedBatchId]);return r.Nt(qn.userMutationsIndex,i).next(function(r){return nr.forEach(r,function(r){v(r.userId===n.userId);var i=Tr(e.R,r);return Mr(t,n.userId,i).next(function(){})})})})})},t.prototype.ve=function(t){var e=t.store(zn.store),n=t.store(Kn.store);return t.store(Wn.store).get(Wn.key).next(function(t){var r=[];return n.$t(function(n,i){var o=new x(n),s=[0,Rn(o)];r.push(e.get(s).next(function(n){return n?nr.resolve():function(n){return e.put(new zn(0,Rn(n),t.highestListenSequenceNumber))}(o)}))}).next(function(){return nr.waitFor(r)})})},t.prototype.Pe=function(t,e){t.createObjectStore(Hn.store,{keyPath:Hn.keyPath});var n=e.store(Hn.store),r=new Rr,i=function(t){if(r.add(t)){var e=t.lastSegment(),i=t.popLast();return n.put({collectionId:e,parent:Rn(i)})}};return e.store(Kn.store).$t({Ft:!0},function(t,e){var n=new x(t);return i(n.popLast())}).next(function(){return e.store(Un.store).$t({Ft:!0},function(t,e){t[0];var n=t[1];t[2];var r=Pn(n);return i(r.popLast())})})},t.prototype.Ve=function(t){var e=this,n=t.store(Gn.store);return n.$t(function(t,r){var i=Sr(r),o=Nr(e.R,i);return n.put(o)})},t}();function hi(t){t.createObjectStore(zn.store,{keyPath:zn.keyPath}).createIndex(zn.documentTargetsIndex,zn.documentTargetsKeyPath,{unique:!0}),t.createObjectStore(Gn.store,{keyPath:Gn.keyPath}).createIndex(Gn.queryTargetsIndexName,Gn.queryTargetsKeyPath,{unique:!0}),t.createObjectStore(Wn.store)}var fi="Failed to obtain exclusive access to the persistence layer. To allow shared access, multi-tab synchronization has to be enabled in all tabs. If you are using `experimentalForceOwningTab:true`, make sure that only one tab has persistence enabled at any given time.",li=function(){function t(e,n,r,i,o,s,c,h,f,d){if(this.allowTabSynchronization=e,this.persistenceKey=n,this.clientId=r,this.Se=o,this.window=s,this.document=c,this.De=f,this.Ce=d,this.Ne=null,this.xe=!1,this.isPrimary=!1,this.networkEnabled=!0,this.ke=null,this.inForeground=!1,this.Fe=null,this.$e=null,this.Oe=Number.NEGATIVE_INFINITY,this.Me=function(t){return Promise.resolve()},!t.yt())throw new u(a.UNIMPLEMENTED,"This platform is either missing IndexedDB or is known to have an incomplete implementation. Offline persistence has been disabled.");this.referenceDelegate=new ti(this,i),this.Le=n+"main",this.R=new mr(h),this.Be=new ir(this.Le,11,new ci(this.R)),this.qe=new Gr(this.referenceDelegate,this.R),this.Ut=new Lr,this.Ue=function(t,e){return new ii(t,e)}(this.R,this.Ut),this.Ke=new Ar,this.window&&this.window.localStorage?this.Qe=this.window.localStorage:(this.Qe=null,!1===d&&l("IndexedDbPersistence","LocalStorage is unavailable. As a result, persistence may not work reliably. In particular enablePersistence() could fail immediately after refreshing the page."))}return t.prototype.start=function(){var t=this;return this.je().then(function(){if(!t.isPrimary&&!t.allowTabSynchronization)throw new u(a.FAILED_PRECONDITION,fi);return t.We(),t.Ge(),t.ze(),t.runTransaction("getHighestListenSequenceNumber","readonly",function(e){return t.qe.getHighestSequenceNumber(e)})}).then(function(e){t.Ne=new s(e,t.De)}).then(function(){t.xe=!0}).catch(function(e){return t.Be&&t.Be.close(),Promise.reject(e)})},t.prototype.He=function(t){var n=this;return this.Me=function(r){return(0,e.__awaiter)(n,void 0,void 0,function(){return(0,e.__generator)(this,function(e){return this.started?[2,t(r)]:[2]})})},t(this.isPrimary)},t.prototype.setDatabaseDeletedListener=function(t){var n=this;this.Be.vt(function(r){return(0,e.__awaiter)(n,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return null===r.newVersion?[4,t()]:[3,2];case 1:e.sent(),e.label=2;case 2:return[2]}})})})},t.prototype.setNetworkEnabled=function(t){var n=this;this.networkEnabled!==t&&(this.networkEnabled=t,this.Se.enqueueAndForget(function(){return(0,e.__awaiter)(n,void 0,void 0,function(){return(0,e.__generator)(this,function(t){switch(t.label){case 0:return this.started?[4,this.je()]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}})})}))},t.prototype.je=function(){var t=this;return this.runTransaction("updateClientMetadataAndTryBecomePrimary","readwrite",function(e){return pi(e).put(new Yn(t.clientId,Date.now(),t.networkEnabled,t.inForeground)).next(function(){if(t.isPrimary)return t.Je(e).next(function(e){e||(t.isPrimary=!1,t.Se.enqueueRetryable(function(){return t.Me(!1)}))})}).next(function(){return t.Ye(e)}).next(function(n){return t.isPrimary&&!n?t.Xe(e).next(function(){return!1}):!!n&&t.Ze(e).next(function(){return!0})})}).catch(function(e){if(ar(e))return f("IndexedDbPersistence","Failed to extend owner lease: ",e),t.isPrimary;if(!t.allowTabSynchronization)throw e;return f("IndexedDbPersistence","Releasing owner lease after error during lease refresh",e),!1}).then(function(e){t.isPrimary!==e&&t.Se.enqueueRetryable(function(){return t.Me(e)}),t.isPrimary=e})},t.prototype.Je=function(t){var e=this;return di(t).get(Mn.key).next(function(t){return nr.resolve(e.tn(t))})},t.prototype.en=function(t){return pi(t).delete(this.clientId)},t.prototype.nn=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var t,n,r,i,o=this;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return!this.isPrimary||this.sn(this.Oe,18e5)?[3,2]:(this.Oe=Date.now(),[4,this.runTransaction("maybeGarbageCollectMultiClientState","readwrite-primary",function(t){var e=dr(t,Yn.store);return e.Nt().next(function(t){var n=o.rn(t,18e5),r=t.filter(function(t){return-1===n.indexOf(t)});return nr.forEach(r,function(t){return e.delete(t.clientId)}).next(function(){return r})})}).catch(function(){return[]})]);case 1:if(t=e.sent(),this.Qe)for(n=0,r=t;n<r.length;n++)i=r[n],this.Qe.removeItem(this.on(i.clientId));e.label=2;case 2:return[2]}})})},t.prototype.ze=function(){var t=this;this.$e=this.Se.enqueueAfterDelay("client_metadata_refresh",4e3,function(){return t.je().then(function(){return t.nn()}).then(function(){return t.ze()})})},t.prototype.tn=function(t){return!!t&&t.ownerId===this.clientId},t.prototype.Ye=function(t){var e=this;return this.Ce?nr.resolve(!0):di(t).get(Mn.key).next(function(n){if(null!==n&&e.sn(n.leaseTimestampMs,5e3)&&!e.cn(n.ownerId)){if(e.tn(n)&&e.networkEnabled)return!0;if(!e.tn(n)){if(!n.allowTabSynchronization)throw new u(a.FAILED_PRECONDITION,fi);return!1}}return!(!e.networkEnabled||!e.inForeground)||pi(t).Nt().next(function(t){return void 0===e.rn(t,5e3).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&&f("IndexedDbPersistence","Client "+(t?"is":"is not")+" eligible for a primary lease."),t})},t.prototype.shutdown=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var t=this;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return this.xe=!1,this.un(),this.$e&&(this.$e.cancel(),this.$e=null),this.an(),this.hn(),[4,this.Be.runTransaction("shutdown","readwrite",[Mn.store,Yn.store],function(e){var n=new lr(e,s.o);return t.Xe(n).next(function(){return t.en(n)})})];case 1:return e.sent(),this.Be.close(),this.ln(),[2]}})})},t.prototype.rn=function(t,e){var n=this;return t.filter(function(t){return n.sn(t.updateTimeMs,e)&&!n.cn(t.clientId)})},t.prototype.fn=function(){var t=this;return this.runTransaction("getActiveClients","readonly",function(e){return pi(e).Nt().next(function(e){return t.rn(e,18e5).map(function(t){return t.clientId})})})},Object.defineProperty(t.prototype,"started",{get:function(){return this.xe},enumerable:!1,configurable:!0}),t.prototype.getMutationQueue=function(t){return qr.Qt(t,this.R,this.Ut,this.referenceDelegate)},t.prototype.getTargetCache=function(){return this.qe},t.prototype.getRemoteDocumentCache=function(){return this.Ue},t.prototype.getIndexManager=function(){return this.Ut},t.prototype.getBundleCache=function(){return this.Ke},t.prototype.runTransaction=function(t,e,n){var r=this;f("IndexedDbPersistence","Starting transaction:",t);var i,o="readonly"===e?"readonly":"readwrite";return this.Be.runTransaction(t,o,Jn,function(o){return i=new lr(o,r.Ne?r.Ne.next():s.o),"readwrite-primary"===e?r.Je(i).next(function(t){return!!t||r.Ye(i)}).next(function(e){if(!e)throw l("Failed to obtain primary lease for action '"+t+"'."),r.isPrimary=!1,r.Se.enqueueRetryable(function(){return r.Me(!1)}),new u(a.FAILED_PRECONDITION,Zn);return n(i)}).next(function(t){return r.Ze(i).next(function(){return t})}):r.dn(i).next(function(){return n(i)})}).then(function(t){return i.raiseOnCommittedEvent(),t})},t.prototype.dn=function(t){var e=this;return di(t).get(Mn.key).next(function(t){if(null!==t&&e.sn(t.leaseTimestampMs,5e3)&&!e.cn(t.ownerId)&&!e.tn(t)&&!(e.Ce||e.allowTabSynchronization&&t.allowTabSynchronization))throw new u(a.FAILED_PRECONDITION,fi)})},t.prototype.Ze=function(t){var e=new Mn(this.clientId,this.allowTabSynchronization,Date.now());return di(t).put(Mn.key,e)},t.yt=function(){return ir.yt()},t.prototype.Xe=function(t){var e=this,n=di(t);return n.get(Mn.key).next(function(t){return e.tn(t)?(f("IndexedDbPersistence","Releasing primary lease."),n.delete(Mn.key)):nr.resolve()})},t.prototype.sn=function(t,e){var n=Date.now();return!(t<n-e||t>n&&(l("Detected an update time that is in the future: "+t+" > "+n),1))},t.prototype.We=function(){var t=this;null!==this.document&&"function"==typeof this.document.addEventListener&&(this.Fe=function(){t.Se.enqueueAndForget(function(){return t.inForeground="visible"===t.document.visibilityState,t.je()})},this.document.addEventListener("visibilitychange",this.Fe),this.inForeground="visible"===this.document.visibilityState)},t.prototype.an=function(){this.Fe&&(this.document.removeEventListener("visibilitychange",this.Fe),this.Fe=null)},t.prototype.Ge=function(){var t,e=this;"function"==typeof(null===(t=this.window)||void 0===t?void 0:t.addEventListener)&&(this.ke=function(){e.un(),(0,n.isSafari)()&&navigator.appVersion.match("Version/14")&&e.Se.enterRestrictedMode(!0),e.Se.enqueueAndForget(function(){return e.shutdown()})},this.window.addEventListener("pagehide",this.ke))},t.prototype.hn=function(){this.ke&&(this.window.removeEventListener("pagehide",this.ke),this.ke=null)},t.prototype.cn=function(t){var e;try{var n=null!==(null===(e=this.Qe)||void 0===e?void 0:e.getItem(this.on(t)));return f("IndexedDbPersistence","Client '"+t+"' "+(n?"is":"is not")+" zombied in LocalStorage"),n}catch(t){return l("IndexedDbPersistence","Failed to get zombied client id.",t),!1}},t.prototype.un=function(){if(this.Qe)try{this.Qe.setItem(this.on(this.clientId),String(Date.now()))}catch(t){l("Failed to set zombie client id.",t)}},t.prototype.ln=function(){if(this.Qe)try{this.Qe.removeItem(this.on(this.clientId))}catch(t){}},t.prototype.on=function(t){return"firestore_zombie_"+this.persistenceKey+"_"+t},t}();function di(t){return dr(t,Mn.store)}function pi(t){return dr(t,Yn.store)}function yi(t,e){var n=t.projectId;return t.isDefaultDatabase||(n+="."+t.database),"firestore/"+e+"/"+n+"/"}var vi=function(t,e){this.progress=t,this.wn=e},mi=function(){function t(t,e,n){this.Ue=t,this._n=e,this.Ut=n}return t.prototype.mn=function(t,e){var n=this;return this._n.getAllMutationBatchesAffectingDocumentKey(t,e).next(function(r){return n.yn(t,e,r)})},t.prototype.yn=function(t,e,n){return this.Ue.getEntry(t,e).next(function(t){for(var e=0,r=n;e<r.length;e++)r[e].applyToLocalView(t);return t})},t.prototype.gn=function(t,e){t.forEach(function(t,n){for(var r=0,i=e;r<i.length;r++)i[r].applyToLocalView(n)})},t.prototype.pn=function(t,e){var n=this;return this.Ue.getEntries(t,e).next(function(e){return n.En(t,e).next(function(){return e})})},t.prototype.En=function(t,e){var n=this;return this._n.getAllMutationBatchesAffectingDocumentKeys(t,e).next(function(t){return n.gn(e,t)})},t.prototype.getDocumentsMatchingQuery=function(t,e,n){return function(t){return Q.isDocumentKey(t.path)&&null===t.collectionGroup&&0===t.filters.length}(e)?this.Tn(t,e.path):Pt(e)?this.In(t,e,n):this.An(t,e,n)},t.prototype.Tn=function(t,e){return this.mn(t,new Q(e)).next(function(t){var e=Fe();return t.isFoundDocument()&&(e=e.insert(t.key,t)),e})},t.prototype.In=function(t,e,n){var r=this,i=e.collectionGroup,o=Fe();return this.Ut.getCollectionParents(t,i).next(function(s){return nr.forEach(s,function(s){var a=function(t,e){return new At(e,null,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,t.startAt,t.endAt)}(e,s.child(i));return r.An(t,a,n).next(function(t){t.forEach(function(t,e){o=o.insert(t,e)})})}).next(function(){return o})})},t.prototype.An=function(t,e,n){var r,i,o=this;return this.Ue.getDocumentsMatchingQuery(t,e,n).next(function(n){return r=n,o._n.getAllMutationBatchesAffectingQuery(t,e)}).next(function(e){return i=e,o.Rn(t,i,r).next(function(t){r=t;for(var e=0,n=i;e<n.length;e++)for(var o=n[e],s=0,a=o.mutations;s<a.length;s++){var u=a[s],c=u.key,h=r.get(c);null==h&&(h=at.newInvalidDocument(c),r=r.insert(c,h)),le(u,h,o.localWriteTime),h.isFoundDocument()||(r=r.remove(c))}})}).next(function(){return r.forEach(function(t,n){jt(e,n)||(r=r.remove(t))}),r})},t.prototype.Rn=function(t,e,n){for(var r=Ue(),i=0,o=e;i<o.length;i++)for(var s=0,a=o[i].mutations;s<a.length;s++){var u=a[s];u instanceof me&&null===n.get(u.key)&&(r=r.add(u.key))}var c=n;return this.Ue.getEntries(t,r).next(function(t){return t.forEach(function(t,e){e.isFoundDocument()&&(c=c.insert(t,e))}),c})},t}(),gi=function(){function t(t,e,n,r){this.targetId=t,this.fromCache=e,this.bn=n,this.vn=r}return t.Pn=function(e,n){for(var r=Ue(),i=Ue(),o=0,s=n.docChanges;o<s.length;o++){var a=s[o];switch(a.type){case 0:r=r.add(a.doc.key);break;case 1:i=i.add(a.doc.key)}}return new t(e,n.fromCache,r,i)},t}(),_i=function(){function t(){}return t.prototype.Vn=function(t){this.Sn=t},t.prototype.getDocumentsMatchingQuery=function(t,e,n,i){var o=this;return function(t){return 0===t.filters.length&&null===t.limit&&null==t.startAt&&null==t.endAt&&(0===t.explicitOrderBy.length||1===t.explicitOrderBy.length&&t.explicitOrderBy[0].field.isKeyField())}(e)||n.isEqual(T.min())?this.Dn(t,e):this.Sn.pn(t,i).next(function(s){var a=o.Cn(e,s);return(Ct(e)||Rt(e))&&o.Nn(e.limitType,a,i,n)?o.Dn(t,e):(h()<=r.LogLevel.DEBUG&&f("QueryEngine","Re-using previous result from %s to execute query: %s",n.toString(),Bt(e)),o.Sn.getDocumentsMatchingQuery(t,e,n).next(function(t){return a.forEach(function(e){t=t.insert(e.key,e)}),t}))})},t.prototype.Cn=function(t,e){var n=new Ce(Kt(t));return e.forEach(function(e,r){jt(t,r)&&(n=n.add(r))}),n},t.prototype.Nn=function(t,e,n,r){if(n.size!==e.size)return!0;var i="F"===t?e.last():e.first();return!!i&&(i.hasPendingWrites||i.version.compareTo(r)>0)},t.prototype.Dn=function(t,e){return h()<=r.LogLevel.DEBUG&&f("QueryEngine","Using full collection scan to execute query:",Bt(e)),this.Sn.getDocumentsMatchingQuery(t,e,T.min())},t}(),wi=function(){function t(t,e,n,r){this.persistence=t,this.xn=e,this.R=r,this.kn=new Ae(w),this.Fn=new ni(function(t){return ht(t)},ft),this.$n=T.min(),this._n=t.getMutationQueue(n),this.On=t.getRemoteDocumentCache(),this.qe=t.getTargetCache(),this.Mn=new mi(this.On,this._n,this.persistence.getIndexManager()),this.Ke=t.getBundleCache(),this.xn.Vn(this.Mn)}return t.prototype.collectGarbage=function(t){var e=this;return this.persistence.runTransaction("Collect garbage","readwrite-primary",function(n){return t.collect(n,e.kn)})},t}();function bi(t,e,n,r){return new wi(t,e,n,r)}function Ii(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o,s;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return r=m(t),i=r._n,o=r.Mn,[4,r.persistence.runTransaction("Handle user change","readonly",function(t){var e;return r._n.getAllMutationBatches(t).next(function(s){return e=s,i=r.persistence.getMutationQueue(n),o=new mi(r.On,i,r.persistence.getIndexManager()),i.getAllMutationBatches(t)}).next(function(n){for(var r=[],i=[],s=Ue(),a=0,u=e;a<u.length;a++){var c=u[a];r.push(c.batchId);for(var h=0,f=c.mutations;h<f.length;h++){var l=f[h];s=s.add(l.key)}}for(var d=0,p=n;d<p.length;d++){var y=p[d];i.push(y.batchId);for(var v=0,m=y.mutations;v<m.length;v++){var g=m[v];s=s.add(g.key)}}return o.pn(t,s).next(function(t){return{Ln:t,removedBatchIds:r,addedBatchIds:i}})})})];case 1:return s=e.sent(),[2,(r._n=i,r.Mn=o,r.xn.Vn(r.Mn),s)]}})})}function Ei(t,e){var n=m(t);return n.persistence.runTransaction("Acknowledge batch","readwrite-primary",function(t){var r=e.batch.keys(),i=n.On.newChangeBuffer({trackRemovals:!0});return function(t,e,n,r){var i=n.batch,o=i.keys(),s=nr.resolve();return o.forEach(function(t){s=s.next(function(){return r.getEntry(e,t)}).next(function(e){var o=n.docVersions.get(t);v(null!==o),e.version.compareTo(o)<0&&(i.applyToRemoteDocument(e,n),e.isValidDocument()&&r.addEntry(e,n.commitVersion))})}),s.next(function(){return t._n.removeMutationBatch(e,i)})}(n,t,e,i).next(function(){return i.apply(t)}).next(function(){return n._n.performConsistencyCheck(t)}).next(function(){return n.Mn.pn(t,r)})})}function Ti(t){var e=m(t);return e.persistence.runTransaction("Get last remote snapshot version","readonly",function(t){return e.qe.getLastRemoteSnapshotVersion(t)})}function Si(t,e){var n=m(t),r=e.snapshotVersion,i=n.kn;return n.persistence.runTransaction("Apply remote event","readwrite-primary",function(t){var o=n.On.newChangeBuffer({trackRemovals:!0});i=n.kn;var s=[];e.targetChanges.forEach(function(e,o){var a=i.get(o);if(a){s.push(n.qe.removeMatchingKeys(t,e.removedDocuments,o).next(function(){return n.qe.addMatchingKeys(t,e.addedDocuments,o)}));var u=e.resumeToken;if(u.approximateByteSize()>0){var c=a.withResumeToken(u,r).withSequenceNumber(t.currentSequenceNumber);i=i.insert(o,c),function(t,e,n){return v(e.resumeToken.approximateByteSize()>0),0===t.resumeToken.approximateByteSize()||e.snapshotVersion.toMicroseconds()-t.snapshotVersion.toMicroseconds()>=3e8||n.addedDocuments.size+n.modifiedDocuments.size+n.removedDocuments.size>0}(a,c,e)&&s.push(n.qe.updateTargetData(t,c))}}});var a=Oe();if(e.documentUpdates.forEach(function(r,i){e.resolvedLimboDocuments.has(r)&&s.push(n.persistence.referenceDelegate.updateLimboDocument(t,r))}),s.push(Ni(t,o,e.documentUpdates,r,void 0).next(function(t){a=t})),!r.isEqual(T.min())){var u=n.qe.getLastRemoteSnapshotVersion(t).next(function(e){return n.qe.setTargetsMetadata(t,t.currentSequenceNumber,r)});s.push(u)}return nr.waitFor(s).next(function(){return o.apply(t)}).next(function(){return n.Mn.En(t,a)}).next(function(){return a})}).then(function(t){return n.kn=i,t})}function Ni(t,e,n,r,i){var o=Ue();return n.forEach(function(t){return o=o.add(t)}),e.getEntries(t,o).next(function(t){var o=Oe();return n.forEach(function(n,s){var a=t.get(n),u=(null==i?void 0:i.get(n))||r;s.isNoDocument()&&s.version.isEqual(T.min())?(e.removeEntry(n,u),o=o.insert(n,s)):!a.isValidDocument()||s.version.compareTo(a.version)>0||0===s.version.compareTo(a.version)&&a.hasPendingWrites?(e.addEntry(s,u),o=o.insert(n,s)):f("LocalStore","Ignoring outdated watch update for ",n,". Current version:",a.version," Watch version:",s.version)}),o})}function Di(t,e){var n=m(t);return n.persistence.runTransaction("Get next mutation batch","readonly",function(t){return void 0===e&&(e=-1),n._n.getNextMutationBatchAfterBatchId(t,e)})}function Ai(t,e){var n=m(t);return n.persistence.runTransaction("Allocate target","readwrite",function(t){var r;return n.qe.getTargetData(t,e).next(function(i){return i?(r=i,nr.resolve(r)):n.qe.allocateTargetId(t).next(function(i){return r=new vr(e,i,0,t.currentSequenceNumber),n.qe.addTargetData(t,r).next(function(){return r})})})}).then(function(t){var r=n.kn.get(t.targetId);return(null===r||t.snapshotVersion.compareTo(r.snapshotVersion)>0)&&(n.kn=n.kn.insert(t.targetId,t),n.Fn.set(e,t.targetId)),t})}function xi(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o,s,a;return(0,e.__generator)(this,function(e){switch(e.label){case 0:i=m(t),o=i.kn.get(n),s=r?"readwrite":"readwrite-primary",e.label=1;case 1:return e.trys.push([1,4,,5]),r?[3,3]:[4,i.persistence.runTransaction("Release target",s,function(t){return i.persistence.referenceDelegate.removeTarget(t,o)})];case 2:e.sent(),e.label=3;case 3:return[3,5];case 4:if(!ar(a=e.sent()))throw a;return f("LocalStore","Failed to update sequence numbers for target "+n+": "+a),[3,5];case 5:return i.kn=i.kn.remove(n),i.Fn.delete(o.target),[2]}})})}function ki(t,e,n){var r=m(t),i=T.min(),o=Ue();return r.persistence.runTransaction("Execute query","readonly",function(t){return function(t,e,n){var r=m(t),i=r.Fn.get(n);return void 0!==i?nr.resolve(r.kn.get(i)):r.qe.getTargetData(e,n)}(r,t,Mt(e)).next(function(e){if(e)return i=e.lastLimboFreeSnapshotVersion,r.qe.getMatchingKeysForTargetId(t,e.targetId).next(function(t){o=t})}).next(function(){return r.xn.getDocumentsMatchingQuery(t,e,n?i:T.min(),n?o:Ue())}).next(function(t){return{documents:t,Bn:o}})})}function Ci(t,e){var n=m(t),r=m(n.qe),i=n.kn.get(e);return i?Promise.resolve(i.target):n.persistence.runTransaction("Get target data","readonly",function(t){return r.lt(t,e).next(function(t){return t?t.target:null})})}function Ri(t){var e=m(t);return e.persistence.runTransaction("Get new document changes","readonly",function(t){return function(t,e,n){var r=m(t),i=Oe(),o=wr(n),s=ai(e),a=IDBKeyRange.lowerBound(o,!0);return s.$t({index:Kn.readTimeIndex,range:a},function(t,e){var n=gr(r.R,e);i=i.insert(n.key,n),o=e.readTime}).next(function(){return{wn:i,readTime:br(o)}})}(e.On,t,e.$n)}).then(function(t){var n=t.wn,r=t.readTime;return e.$n=r,n})}function Li(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){return[2,(n=m(t)).persistence.runTransaction("Synchronize last document change read time","readonly",function(t){return function(t){var e=ai(t),n=T.min();return e.$t({index:Kn.readTimeIndex,reverse:!0},function(t,e,r){e.readTime&&(n=br(e.readTime)),r.done()}).next(function(){return n})}(t)}).then(function(t){n.$n=t})]})})}function Oi(t,n,r,i){return(0,e.__awaiter)(this,void 0,void 0,function(){var o,s,a,u,c,h,f,l,d,p;return(0,e.__generator)(this,function(e){switch(e.label){case 0:for(o=m(t),s=Ue(),a=Oe(),u=Ve(),c=0,h=r;c<h.length;c++)f=h[c],l=n.qn(f.metadata.name),f.document&&(s=s.add(l)),a=a.insert(l,n.Un(f)),u=u.insert(l,n.Kn(f.metadata.readTime));return d=o.On.newChangeBuffer({trackRemovals:!0}),[4,Ai(o,function(t){return Mt(kt(x.fromString("__bundle__/docs/"+t)))}(i))];case 1:return p=e.sent(),[2,o.persistence.runTransaction("Apply bundle documents","readwrite",function(t){return Ni(t,d,a,T.min(),u).next(function(e){return d.apply(t),e}).next(function(e){return o.qe.removeMatchingKeysForTargetId(t,p.targetId).next(function(){return o.qe.addMatchingKeys(t,s,p.targetId)}).next(function(){return o.Mn.En(t,e)}).next(function(){return e})})})]}})})}function Pi(t,n,r){return void 0===r&&(r=Ue()),(0,e.__awaiter)(this,void 0,void 0,function(){var i,o;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,Ai(t,Mt(Dr(n.bundledQuery)))];case 1:return i=e.sent(),[2,(o=m(t)).persistence.runTransaction("Save named query","readwrite",function(t){var e=on(n.readTime);if(i.snapshotVersion.compareTo(e)>=0)return o.Ke.saveNamedQuery(t,n);var s=i.withResumeToken(L.EMPTY_BYTE_STRING,e);return o.kn=o.kn.insert(s.targetId,s),o.qe.updateTargetData(t,s).next(function(){return o.qe.removeMatchingKeysForTargetId(t,i.targetId)}).next(function(){return o.qe.addMatchingKeys(t,r,i.targetId)}).next(function(){return o.Ke.saveNamedQuery(t,n)})})]}})})}var Fi=function(){function t(t){this.R=t,this.Qn=new Map,this.jn=new Map}return t.prototype.getBundleMetadata=function(t,e){return nr.resolve(this.Qn.get(e))},t.prototype.saveBundleMetadata=function(t,e){var n;return this.Qn.set(e.id,{id:(n=e).id,version:n.version,createTime:on(n.createTime)}),nr.resolve()},t.prototype.getNamedQuery=function(t,e){return nr.resolve(this.jn.get(e))},t.prototype.saveNamedQuery=function(t,e){return this.jn.set(e.name,function(t){return{name:t.name,query:Dr(t.bundledQuery),readTime:on(t.readTime)}}(e)),nr.resolve()},t}(),Mi=function(){function t(){this.Wn=new Ce(Vi.Gn),this.zn=new Ce(Vi.Hn)}return t.prototype.isEmpty=function(){return this.Wn.isEmpty()},t.prototype.addReference=function(t,e){var n=new Vi(t,e);this.Wn=this.Wn.add(n),this.zn=this.zn.add(n)},t.prototype.Jn=function(t,e){var n=this;t.forEach(function(t){return n.addReference(t,e)})},t.prototype.removeReference=function(t,e){this.Yn(new Vi(t,e))},t.prototype.Xn=function(t,e){var n=this;t.forEach(function(t){return n.removeReference(t,e)})},t.prototype.Zn=function(t){var e=this,n=new Q(new x([])),r=new Vi(n,t),i=new Vi(n,t+1),o=[];return this.zn.forEachInRange([r,i],function(t){e.Yn(t),o.push(t.key)}),o},t.prototype.ts=function(){var t=this;this.Wn.forEach(function(e){return t.Yn(e)})},t.prototype.Yn=function(t){this.Wn=this.Wn.delete(t),this.zn=this.zn.delete(t)},t.prototype.es=function(t){var e=new Q(new x([])),n=new Vi(e,t),r=new Vi(e,t+1),i=Ue();return this.zn.forEachInRange([n,r],function(t){i=i.add(t.key)}),i},t.prototype.containsKey=function(t){var e=new Vi(t,0),n=this.Wn.firstAfterOrEqual(e);return null!==n&&t.isEqual(n.key)},t}(),Vi=function(){function t(t,e){this.key=t,this.ns=e}return t.Gn=function(t,e){return Q.comparator(t.key,e.key)||w(t.ns,e.ns)},t.Hn=function(t,e){return w(t.ns,e.ns)||Q.comparator(t.key,e.key)},t}(),qi=function(){function t(t,e){this.Ut=t,this.referenceDelegate=e,this._n=[],this.ss=1,this.rs=new Ce(Vi.Gn)}return t.prototype.checkEmpty=function(t){return nr.resolve(0===this._n.length)},t.prototype.addMutationBatch=function(t,e,n,r){var i=this.ss;this.ss++,this._n.length>0&&this._n[this._n.length-1];var o=new pr(i,e,n,r);this._n.push(o);for(var s=0,a=r;s<a.length;s++){var u=a[s];this.rs=this.rs.add(new Vi(u.key,i)),this.Ut.addToCollectionParentIndex(t,u.key.path.popLast())}return nr.resolve(o)},t.prototype.lookupMutationBatch=function(t,e){return nr.resolve(this.os(e))},t.prototype.getNextMutationBatchAfterBatchId=function(t,e){var n=e+1,r=this.cs(n),i=r<0?0:r;return nr.resolve(this._n.length>i?this._n[i]:null)},t.prototype.getHighestUnacknowledgedBatchId=function(){return nr.resolve(0===this._n.length?-1:this.ss-1)},t.prototype.getAllMutationBatches=function(t){return nr.resolve(this._n.slice())},t.prototype.getAllMutationBatchesAffectingDocumentKey=function(t,e){var n=this,r=new Vi(e,0),i=new Vi(e,Number.POSITIVE_INFINITY),o=[];return this.rs.forEachInRange([r,i],function(t){var e=n.os(t.ns);o.push(e)}),nr.resolve(o)},t.prototype.getAllMutationBatchesAffectingDocumentKeys=function(t,e){var n=this,r=new Ce(w);return e.forEach(function(t){var e=new Vi(t,0),i=new Vi(t,Number.POSITIVE_INFINITY);n.rs.forEachInRange([e,i],function(t){r=r.add(t.ns)})}),nr.resolve(this.us(r))},t.prototype.getAllMutationBatchesAffectingQuery=function(t,e){var n=e.path,r=n.length+1,i=n;Q.isDocumentKey(i)||(i=i.child(""));var o=new Vi(new Q(i),0),s=new Ce(w);return this.rs.forEachWhile(function(t){var e=t.key.path;return!!n.isPrefixOf(e)&&(e.length===r&&(s=s.add(t.ns)),!0)},o),nr.resolve(this.us(s))},t.prototype.us=function(t){var e=this,n=[];return t.forEach(function(t){var r=e.os(t);null!==r&&n.push(r)}),n},t.prototype.removeMutationBatch=function(t,e){var n=this;v(0===this.hs(e.batchId,"removed")),this._n.shift();var r=this.rs;return nr.forEach(e.mutations,function(i){var o=new Vi(i.key,e.batchId);return r=r.delete(o),n.referenceDelegate.markPotentiallyOrphaned(t,i.key)}).next(function(){n.rs=r})},t.prototype.Gt=function(t){},t.prototype.containsKey=function(t,e){var n=new Vi(e,0),r=this.rs.firstAfterOrEqual(n);return nr.resolve(e.isEqual(r&&r.key))},t.prototype.performConsistencyCheck=function(t){return this._n.length,nr.resolve()},t.prototype.hs=function(t,e){return this.cs(t)},t.prototype.cs=function(t){return 0===this._n.length?0:t-this._n[0].batchId},t.prototype.os=function(t){var e=this.cs(t);return e<0||e>=this._n.length?null:this._n[e]},t}(),Ui=function(){function t(t,e){this.Ut=t,this.ls=e,this.docs=new Ae(Q.comparator),this.size=0}return t.prototype.addEntry=function(t,e,n){var r=e.key,i=this.docs.get(r),o=i?i.size:0,s=this.ls(e);return this.docs=this.docs.insert(r,{document:e.clone(),size:s,readTime:n}),this.size+=s-o,this.Ut.addToCollectionParentIndex(t,r.path.popLast())},t.prototype.removeEntry=function(t){var e=this.docs.get(t);e&&(this.docs=this.docs.remove(t),this.size-=e.size)},t.prototype.getEntry=function(t,e){var n=this.docs.get(e);return nr.resolve(n?n.document.clone():at.newInvalidDocument(e))},t.prototype.getEntries=function(t,e){var n=this,r=Oe();return e.forEach(function(t){var e=n.docs.get(t);r=r.insert(t,e?e.document.clone():at.newInvalidDocument(t))}),nr.resolve(r)},t.prototype.getDocumentsMatchingQuery=function(t,e,n){for(var r=Oe(),i=new Q(e.path.child("")),o=this.docs.getIteratorFrom(i);o.hasNext();){var s=o.getNext(),a=s.key,u=s.value,c=u.document,h=u.readTime;if(!e.path.isPrefixOf(a.path))break;h.compareTo(n)<=0||jt(e,c)&&(r=r.insert(c.key,c.clone()))}return nr.resolve(r)},t.prototype.fs=function(t,e){return nr.forEach(this.docs,function(t){return e(t)})},t.prototype.newChangeBuffer=function(t){return new Bi(this)},t.prototype.getSize=function(t){return nr.resolve(this.size)},t}(),Bi=function(t){function n(e){var n=this;return(n=t.call(this)||this).Ie=e,n}return(0,e.__extends)(n,t),n.prototype.applyChanges=function(t){var e=this,n=[];return this.changes.forEach(function(r,i){i.document.isValidDocument()?n.push(e.Ie.addEntry(t,i.document,e.getReadTime(r))):e.Ie.removeEntry(r)}),nr.waitFor(n)},n.prototype.getFromCache=function(t,e){return this.Ie.getEntry(t,e)},n.prototype.getAllFromCache=function(t,e){return this.Ie.getEntries(t,e)},n}(ri),ji=function(){function t(t){this.persistence=t,this.ds=new ni(function(t){return ht(t)},ft),this.lastRemoteSnapshotVersion=T.min(),this.highestTargetId=0,this.ws=0,this._s=new Mi,this.targetCount=0,this.ys=Qr.Jt()}return t.prototype.forEachTarget=function(t,e){return this.ds.forEach(function(t,n){return e(n)}),nr.resolve()},t.prototype.getLastRemoteSnapshotVersion=function(t){return nr.resolve(this.lastRemoteSnapshotVersion)},t.prototype.getHighestSequenceNumber=function(t){return nr.resolve(this.ws)},t.prototype.allocateTargetId=function(t){return this.highestTargetId=this.ys.next(),nr.resolve(this.highestTargetId)},t.prototype.setTargetsMetadata=function(t,e,n){return n&&(this.lastRemoteSnapshotVersion=n),e>this.ws&&(this.ws=e),nr.resolve()},t.prototype.te=function(t){this.ds.set(t.target,t);var e=t.targetId;e>this.highestTargetId&&(this.ys=new Qr(e),this.highestTargetId=e),t.sequenceNumber>this.ws&&(this.ws=t.sequenceNumber)},t.prototype.addTargetData=function(t,e){return this.te(e),this.targetCount+=1,nr.resolve()},t.prototype.updateTargetData=function(t,e){return this.te(e),nr.resolve()},t.prototype.removeTargetData=function(t,e){return this.ds.delete(e.target),this._s.Zn(e.targetId),this.targetCount-=1,nr.resolve()},t.prototype.removeTargets=function(t,e,n){var r=this,i=0,o=[];return this.ds.forEach(function(s,a){a.sequenceNumber<=e&&null===n.get(a.targetId)&&(r.ds.delete(s),o.push(r.removeMatchingKeysForTargetId(t,a.targetId)),i++)}),nr.waitFor(o).next(function(){return i})},t.prototype.getTargetCount=function(t){return nr.resolve(this.targetCount)},t.prototype.getTargetData=function(t,e){var n=this.ds.get(e)||null;return nr.resolve(n)},t.prototype.addMatchingKeys=function(t,e,n){return this._s.Jn(e,n),nr.resolve()},t.prototype.removeMatchingKeys=function(t,e,n){this._s.Xn(e,n);var r=this.persistence.referenceDelegate,i=[];return r&&e.forEach(function(e){i.push(r.markPotentiallyOrphaned(t,e))}),nr.waitFor(i)},t.prototype.removeMatchingKeysForTargetId=function(t,e){return this._s.Zn(e),nr.resolve()},t.prototype.getMatchingKeysForTargetId=function(t,e){var n=this._s.es(e);return nr.resolve(n)},t.prototype.containsKey=function(t,e){return nr.resolve(this._s.containsKey(e))},t}(),Ki=function(){function t(t,e){var n=this;this.gs={},this.Ne=new s(0),this.xe=!1,this.xe=!0,this.referenceDelegate=t(this),this.qe=new ji(this),this.Ut=new Cr,this.Ue=function(t,e){return new Ui(t,function(t){return n.referenceDelegate.ps(t)})}(this.Ut),this.R=new mr(e),this.Ke=new Fi(this.R)}return t.prototype.start=function(){return Promise.resolve()},t.prototype.shutdown=function(){return this.xe=!1,Promise.resolve()},Object.defineProperty(t.prototype,"started",{get:function(){return this.xe},enumerable:!1,configurable:!0}),t.prototype.setDatabaseDeletedListener=function(){},t.prototype.setNetworkEnabled=function(){},t.prototype.getIndexManager=function(){return this.Ut},t.prototype.getMutationQueue=function(t){var e=this.gs[t.toKey()];return e||(e=new qi(this.Ut,this.referenceDelegate),this.gs[t.toKey()]=e),e},t.prototype.getTargetCache=function(){return this.qe},t.prototype.getRemoteDocumentCache=function(){return this.Ue},t.prototype.getBundleCache=function(){return this.Ke},t.prototype.runTransaction=function(t,e,n){var r=this;f("MemoryPersistence","Starting transaction:",t);var i=new Qi(this.Ne.next());return this.referenceDelegate.Es(),n(i).next(function(t){return r.referenceDelegate.Ts(i).next(function(){return t})}).toPromise().then(function(t){return i.raiseOnCommittedEvent(),t})},t.prototype.Is=function(t,e){return nr.or(Object.values(this.gs).map(function(n){return function(){return n.containsKey(t,e)}}))},t}(),Qi=function(t){function n(e){var n=this;return(n=t.call(this)||this).currentSequenceNumber=e,n}return(0,e.__extends)(n,t),n}(tr),Gi=function(){function t(t){this.persistence=t,this.As=new Mi,this.Rs=null}return t.bs=function(e){return new t(e)},Object.defineProperty(t.prototype,"vs",{get:function(){if(this.Rs)return this.Rs;throw y()},enumerable:!1,configurable:!0}),t.prototype.addReference=function(t,e,n){return this.As.addReference(n,e),this.vs.delete(n.toString()),nr.resolve()},t.prototype.removeReference=function(t,e,n){return this.As.removeReference(n,e),this.vs.add(n.toString()),nr.resolve()},t.prototype.markPotentiallyOrphaned=function(t,e){return this.vs.add(e.toString()),nr.resolve()},t.prototype.removeTarget=function(t,e){var n=this;this.As.Zn(e.targetId).forEach(function(t){return n.vs.add(t.toString())});var r=this.persistence.getTargetCache();return r.getMatchingKeysForTargetId(t,e.targetId).next(function(t){t.forEach(function(t){return n.vs.add(t.toString())})}).next(function(){return r.removeTargetData(t,e)})},t.prototype.Es=function(){this.Rs=new Set},t.prototype.Ts=function(t){var e=this,n=this.persistence.getRemoteDocumentCache().newChangeBuffer();return nr.forEach(this.vs,function(r){var i=Q.fromPath(r);return e.Ps(t,i).next(function(t){t||n.removeEntry(i)})}).next(function(){return e.Rs=null,n.apply(t)})},t.prototype.updateLimboDocument=function(t,e){var n=this;return this.Ps(t,e).next(function(t){t?n.vs.delete(e.toString()):n.vs.add(e.toString())})},t.prototype.ps=function(t){return 0},t.prototype.Ps=function(t,e){var n=this;return nr.or([function(){return nr.resolve(n.As.containsKey(e))},function(){return n.persistence.getTargetCache().containsKey(t,e)},function(){return n.persistence.Is(t,e)}])},t}(),zi=function(){function t(t){this.uid=t}return t.prototype.isAuthenticated=function(){return null!=this.uid},t.prototype.toKey=function(){return this.isAuthenticated()?"uid:"+this.uid:"anonymous-user"},t.prototype.isEqual=function(t){return t.uid===this.uid},t}();function Wi(t,e){return"firestore_clients_"+t+"_"+e}function Hi(t,e,n){var r="firestore_mutations_"+t+"_"+n;return e.isAuthenticated()&&(r+="_"+e.uid),r}function Yi(t,e){return"firestore_targets_"+t+"_"+e}zi.UNAUTHENTICATED=new zi(null),zi.GOOGLE_CREDENTIALS=new zi("google-credentials-uid"),zi.FIRST_PARTY=new zi("first-party-uid"),zi.MOCK_USER=new zi("mock-user");var $i=function(){function t(t,e,n,r){this.user=t,this.batchId=e,this.state=n,this.error=r}return t.Vs=function(e,n,r){var i,s=JSON.parse(r),a="object"==o(s)&&-1!==["pending","acknowledged","rejected"].indexOf(s.state)&&(void 0===s.error||"object"==o(s.error));return a&&s.error&&(a="string"==typeof s.error.message&&"string"==typeof s.error.code)&&(i=new u(s.error.code,s.error.message)),a?new t(e,n,s.state,i):(l("SharedClientState","Failed to parse mutation state for ID '"+n+"': "+r),null)},t.prototype.Ss=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}(),Xi=function(){function t(t,e,n){this.targetId=t,this.state=e,this.error=n}return t.Vs=function(e,n){var r,i=JSON.parse(n),s="object"==o(i)&&-1!==["not-current","current","rejected"].indexOf(i.state)&&(void 0===i.error||"object"==o(i.error));return s&&i.error&&(s="string"==typeof i.error.message&&"string"==typeof i.error.code)&&(r=new u(i.error.code,i.error.message)),s?new t(e,i.state,r):(l("SharedClientState","Failed to parse target state for ID '"+e+"': "+n),null)},t.prototype.Ss=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}(),Ji=function(){function t(t,e){this.clientId=t,this.activeTargetIds=e}return t.Vs=function(e,n){for(var r=JSON.parse(n),i="object"==o(r)&&r.activeTargetIds instanceof Array,s=je(),a=0;i&&a<r.activeTargetIds.length;++a)i=K(r.activeTargetIds[a]),s=s.add(r.activeTargetIds[a]);return i?new t(e,s):(l("SharedClientState","Failed to parse client data for instance '"+e+"': "+n),null)},t}(),Zi=function(){function t(t,e){this.clientId=t,this.onlineState=e}return t.Vs=function(e){var n=JSON.parse(e);return"object"==o(n)&&-1!==["Unknown","Online","Offline"].indexOf(n.onlineState)&&"string"==typeof n.clientId?new t(n.clientId,n.onlineState):(l("SharedClientState","Failed to parse online state: "+e),null)},t}(),to=function(){function t(){this.activeTargetIds=je()}return t.prototype.Ds=function(t){this.activeTargetIds=this.activeTargetIds.add(t)},t.prototype.Cs=function(t){this.activeTargetIds=this.activeTargetIds.delete(t)},t.prototype.Ss=function(){var t={activeTargetIds:this.activeTargetIds.toArray(),updateTimeMs:Date.now()};return JSON.stringify(t)},t}(),eo=function(){function t(t,e,n,r,i){this.window=t,this.Se=e,this.persistenceKey=n,this.Ns=r,this.syncEngine=null,this.onlineStateHandler=null,this.sequenceNumberHandler=null,this.xs=this.ks.bind(this),this.Fs=new Ae(w),this.started=!1,this.$s=[];var o=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");this.storage=this.window.localStorage,this.currentUser=i,this.Os=Wi(this.persistenceKey,this.Ns),this.Ms=function(t){return"firestore_sequence_number_"+t}(this.persistenceKey),this.Fs=this.Fs.insert(this.Ns,new to),this.Ls=new RegExp("^firestore_clients_"+o+"_([^_]*)$"),this.Bs=new RegExp("^firestore_mutations_"+o+"_(\\d+)(?:_(.*))?$"),this.qs=new RegExp("^firestore_targets_"+o+"_(\\d+)$"),this.Us=function(t){return"firestore_online_state_"+t}(this.persistenceKey),this.Ks=function(t){return"firestore_bundle_loaded_"+t}(this.persistenceKey),this.window.addEventListener("storage",this.xs)}return t.yt=function(t){return!(!t||!t.localStorage)},t.prototype.start=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var t,n,r,i,o,s,a,u,c,h,f,l=this;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,this.syncEngine.fn()];case 1:for(t=e.sent(),n=0,r=t;n<r.length;n++)(i=r[n])!==this.Ns&&(o=this.getItem(Wi(this.persistenceKey,i)))&&(s=Ji.Vs(i,o))&&(this.Fs=this.Fs.insert(s.clientId,s));for(this.Qs(),(a=this.storage.getItem(this.Us))&&(u=this.js(a))&&this.Ws(u),c=0,h=this.$s;c<h.length;c++)f=h[c],this.ks(f);return this.$s=[],this.window.addEventListener("pagehide",function(){return l.shutdown()}),this.started=!0,[2]}})})},t.prototype.writeSequenceNumber=function(t){this.setItem(this.Ms,JSON.stringify(t))},t.prototype.getAllActiveQueryTargets=function(){return this.Gs(this.Fs)},t.prototype.isActiveQueryTarget=function(t){var e=!1;return this.Fs.forEach(function(n,r){r.activeTargetIds.has(t)&&(e=!0)}),e},t.prototype.addPendingMutation=function(t){this.zs(t,"pending")},t.prototype.updateMutationState=function(t,e,n){this.zs(t,e,n),this.Hs(t)},t.prototype.addLocalQueryTarget=function(t){var e="not-current";if(this.isActiveQueryTarget(t)){var n=this.storage.getItem(Yi(this.persistenceKey,t));if(n){var r=Xi.Vs(t,n);r&&(e=r.state)}}return this.Js.Ds(t),this.Qs(),e},t.prototype.removeLocalQueryTarget=function(t){this.Js.Cs(t),this.Qs()},t.prototype.isLocalQueryTarget=function(t){return this.Js.activeTargetIds.has(t)},t.prototype.clearQueryState=function(t){this.removeItem(Yi(this.persistenceKey,t))},t.prototype.updateQueryState=function(t,e,n){this.Ys(t,e,n)},t.prototype.handleUserChange=function(t,e,n){var r=this;e.forEach(function(t){r.Hs(t)}),this.currentUser=t,n.forEach(function(t){r.addPendingMutation(t)})},t.prototype.setOnlineState=function(t){this.Xs(t)},t.prototype.notifyBundleLoaded=function(){this.Zs()},t.prototype.shutdown=function(){this.started&&(this.window.removeEventListener("storage",this.xs),this.removeItem(this.Os),this.started=!1)},t.prototype.getItem=function(t){var e=this.storage.getItem(t);return f("SharedClientState","READ",t,e),e},t.prototype.setItem=function(t,e){f("SharedClientState","SET",t,e),this.storage.setItem(t,e)},t.prototype.removeItem=function(t){f("SharedClientState","REMOVE",t),this.storage.removeItem(t)},t.prototype.ks=function(t){var n=this,r=t;if(r.storageArea===this.storage){if(f("SharedClientState","EVENT",r.key,r.newValue),r.key===this.Os)return void l("Received WebStorage notification for local change. Another client might have garbage-collected our state");this.Se.enqueueRetryable(function(){return(0,e.__awaiter)(n,void 0,void 0,function(){var t,n,i,o,a,u;return(0,e.__generator)(this,function(e){if(this.started){if(null!==r.key)if(this.Ls.test(r.key)){if(null==r.newValue)return t=this.ti(r.key),[2,this.ei(t,null)];if(n=this.ni(r.key,r.newValue))return[2,this.ei(n.clientId,n)]}else if(this.Bs.test(r.key)){if(null!==r.newValue&&(i=this.si(r.key,r.newValue)))return[2,this.ii(i)]}else if(this.qs.test(r.key)){if(null!==r.newValue&&(o=this.ri(r.key,r.newValue)))return[2,this.oi(o)]}else if(r.key===this.Us){if(null!==r.newValue&&(a=this.js(r.newValue)))return[2,this.Ws(a)]}else if(r.key===this.Ms)(u=function(t){var e=s.o;if(null!=t)try{var n=JSON.parse(t);v("number"==typeof n),e=n}catch(t){l("SharedClientState","Failed to read sequence number from WebStorage",t)}return e}(r.newValue))!==s.o&&this.sequenceNumberHandler(u);else if(r.key===this.Ks)return[2,this.syncEngine.ci()]}else this.$s.push(r);return[2]})})})}},Object.defineProperty(t.prototype,"Js",{get:function(){return this.Fs.get(this.Ns)},enumerable:!1,configurable:!0}),t.prototype.Qs=function(){this.setItem(this.Os,this.Js.Ss())},t.prototype.zs=function(t,e,n){var r=new $i(this.currentUser,t,e,n),i=Hi(this.persistenceKey,this.currentUser,t);this.setItem(i,r.Ss())},t.prototype.Hs=function(t){var e=Hi(this.persistenceKey,this.currentUser,t);this.removeItem(e)},t.prototype.Xs=function(t){var e={clientId:this.Ns,onlineState:t};this.storage.setItem(this.Us,JSON.stringify(e))},t.prototype.Ys=function(t,e,n){var r=Yi(this.persistenceKey,t),i=new Xi(t,e,n);this.setItem(r,i.Ss())},t.prototype.Zs=function(){this.setItem(this.Ks,"value-not-used")},t.prototype.ti=function(t){var e=this.Ls.exec(t);return e?e[1]:null},t.prototype.ni=function(t,e){var n=this.ti(t);return Ji.Vs(n,e)},t.prototype.si=function(t,e){var n=this.Bs.exec(t),r=Number(n[1]),i=void 0!==n[2]?n[2]:null;return $i.Vs(new zi(i),r,e)},t.prototype.ri=function(t,e){var n=this.qs.exec(t),r=Number(n[1]);return Xi.Vs(r,e)},t.prototype.js=function(t){return Zi.Vs(t)},t.prototype.ii=function(t){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(e){return t.user.uid===this.currentUser.uid?[2,this.syncEngine.ui(t.batchId,t.state,t.error)]:(f("SharedClientState","Ignoring mutation for non-active user "+t.user.uid),[2])})})},t.prototype.oi=function(t){return this.syncEngine.ai(t.targetId,t.state,t.error)},t.prototype.ei=function(t,e){var n=this,r=e?this.Fs.insert(t,e):this.Fs.remove(t),i=this.Gs(this.Fs),o=this.Gs(r),s=[],a=[];return o.forEach(function(t){i.has(t)||s.push(t)}),i.forEach(function(t){o.has(t)||a.push(t)}),this.syncEngine.hi(s,a).then(function(){n.Fs=r})},t.prototype.Ws=function(t){this.Fs.get(t.clientId)&&this.onlineStateHandler(t.onlineState)},t.prototype.Gs=function(t){var e=je();return t.forEach(function(t,n){e=e.unionWith(n.activeTargetIds)}),e},t}(),no=function(){function t(){this.li=new to,this.fi={},this.onlineStateHandler=null,this.sequenceNumberHandler=null}return t.prototype.addPendingMutation=function(t){},t.prototype.updateMutationState=function(t,e,n){},t.prototype.addLocalQueryTarget=function(t){return this.li.Ds(t),this.fi[t]||"not-current"},t.prototype.updateQueryState=function(t,e,n){this.fi[t]=e},t.prototype.removeLocalQueryTarget=function(t){this.li.Cs(t)},t.prototype.isLocalQueryTarget=function(t){return this.li.activeTargetIds.has(t)},t.prototype.clearQueryState=function(t){delete this.fi[t]},t.prototype.getAllActiveQueryTargets=function(){return this.li.activeTargetIds},t.prototype.isActiveQueryTarget=function(t){return this.li.activeTargetIds.has(t)},t.prototype.start=function(){return this.li=new to,Promise.resolve()},t.prototype.handleUserChange=function(t,e,n){},t.prototype.setOnlineState=function(t){},t.prototype.shutdown=function(){},t.prototype.writeSequenceNumber=function(t){},t.prototype.notifyBundleLoaded=function(){},t}(),ro=function(){function t(){}return t.prototype.di=function(t){},t.prototype.shutdown=function(){},t}(),io=function(){function t(){var t=this;this.wi=function(){return t._i()},this.mi=function(){return t.yi()},this.gi=[],this.pi()}return t.prototype.di=function(t){this.gi.push(t)},t.prototype.shutdown=function(){window.removeEventListener("online",this.wi),window.removeEventListener("offline",this.mi)},t.prototype.pi=function(){window.addEventListener("online",this.wi),window.addEventListener("offline",this.mi)},t.prototype._i=function(){f("ConnectivityMonitor","Network connectivity changed: AVAILABLE");for(var t=0,e=this.gi;t<e.length;t++)(0,e[t])(0)},t.prototype.yi=function(){f("ConnectivityMonitor","Network connectivity changed: UNAVAILABLE");for(var t=0,e=this.gi;t<e.length;t++)(0,e[t])(1)},t.yt=function(){return"undefined"!=typeof window&&void 0!==window.addEventListener&&void 0!==window.removeEventListener},t}(),oo={BatchGetDocuments:"batchGet",Commit:"commit",RunQuery:"runQuery"},so=function(){function t(t){this.Ei=t.Ei,this.Ti=t.Ti}return t.prototype.Ii=function(t){this.Ai=t},t.prototype.Ri=function(t){this.bi=t},t.prototype.onMessage=function(t){this.vi=t},t.prototype.close=function(){this.Ti()},t.prototype.send=function(t){this.Ei(t)},t.prototype.Pi=function(){this.Ai()},t.prototype.Vi=function(t){this.bi(t)},t.prototype.Si=function(t){this.vi(t)},t}(),ao=function(t){function r(e){var n=this;return(n=t.call(this,e)||this).forceLongPolling=e.forceLongPolling,n.autoDetectLongPolling=e.autoDetectLongPolling,n.useFetchStreams=e.useFetchStreams,n}return(0,e.__extends)(r,t),r.prototype.Fi=function(t,e,n,r){return new Promise(function(o,s){var c=new i.XhrIo;c.listenOnce(i.EventType.COMPLETE,function(){try{switch(c.getLastErrorCode()){case i.ErrorCode.NO_ERROR:var e=c.getResponseJson();f("Connection","XHR received:",JSON.stringify(e)),o(e);break;case i.ErrorCode.TIMEOUT:f("Connection",'RPC "'+t+'" timed out'),s(new u(a.DEADLINE_EXCEEDED,"Request time out"));break;case i.ErrorCode.HTTP_ERROR:var n=c.getStatus();if(f("Connection",'RPC "'+t+'" failed with status:',n,"response text:",c.getResponseText()),n>0){var r=c.getResponseJson().error;if(r&&r.status&&r.message){var h=function(t){var e=r.status.toLowerCase().replace(/_/g,"-");return Object.values(a).indexOf(e)>=0?e:a.UNKNOWN}();s(new u(h,r.message))}else s(new u(a.UNKNOWN,"Server responded with status "+c.getStatus()))}else s(new u(a.UNAVAILABLE,"Connection failed."));break;default:y()}}finally{f("Connection",'RPC "'+t+'" completed.')}});var h=JSON.stringify(r);c.send(e,"POST",h,n,15)})},r.prototype.Oi=function(t,e){var r=[this.Di,"/","google.firestore.v1.Firestore","/",t,"/channel"],o=(0,i.createWebChannelTransport)(),s=(0,i.getStatEventTarget)(),c={httpSessionIdParam:"gsessionid",initMessageHeaders:{},messageUrlParams:{database:"projects/"+this.databaseId.projectId+"/databases/"+this.databaseId.database},sendRawJson:!0,supportsCrossDomainXhr:!0,internalChannelParams:{forwardChannelRequestTimeoutMs:6e5},forceLongPolling:this.forceLongPolling,detectBufferingProxy:this.autoDetectLongPolling};this.useFetchStreams&&(c.xmlHttpFactory=new i.FetchXmlHttpFactory({})),this.ki(c.initMessageHeaders,e),(0,n.isMobileCordova)()||(0,n.isReactNative)()||(0,n.isElectron)()||(0,n.isIE)()||(0,n.isUWP)()||(0,n.isBrowserExtension)()||(c.httpHeadersOverwriteParam="$httpHeaders");var h=r.join("");f("Connection","Creating WebChannel: "+h,c);var l=o.createWebChannel(h,c),p=!1,y=!1,m=new so({Ei:function(t){y?f("Connection","Not sending because WebChannel is closed:",t):(p||(f("Connection","Opening WebChannel transport."),l.open(),p=!0),f("Connection","WebChannel sending:",t),l.send(t))},Ti:function(){return l.close()}}),g=function(t,e,n){t.listen(e,function(t){try{n(t)}catch(t){setTimeout(function(){throw t},0)}})};return g(l,i.WebChannel.EventType.OPEN,function(){y||f("Connection","WebChannel transport opened.")}),g(l,i.WebChannel.EventType.CLOSE,function(){y||(y=!0,f("Connection","WebChannel transport closed"),m.Vi())}),g(l,i.WebChannel.EventType.ERROR,function(t){y||(y=!0,d("Connection","WebChannel transport errored:",t),m.Vi(new u(a.UNAVAILABLE,"The operation could not be completed")))}),g(l,i.WebChannel.EventType.MESSAGE,function(t){var e;if(!y){var n=t.data[0];v(!!n);var r=n,i=r.error||(null===(e=r[0])||void 0===e?void 0:e.error);if(i){f("Connection","WebChannel received error:",i);var o=i.status,s=function(t){var e=be[o];if(void 0!==e)return De(e)}(),c=i.message;void 0===s&&(s=a.INTERNAL,c="Unknown error status: "+o+" with message "+i.message),y=!0,m.Vi(new u(s,c)),l.close()}else f("Connection","WebChannel received:",n),m.Si(n)}}),g(s,i.Event.STAT_EVENT,function(t){t.stat===i.Stat.PROXY?f("Connection","Detected buffering proxy"):t.stat===i.Stat.NOPROXY&&f("Connection","Detected no buffering proxy")}),setTimeout(function(){m.Pi()},0),m},r}(function(){function t(t){this.databaseInfo=t,this.databaseId=t.databaseId;var e=t.ssl?"https":"http";this.Di=e+"://"+t.host,this.Ci="projects/"+this.databaseId.projectId+"/databases/"+this.databaseId.database+"/documents"}return t.prototype.Ni=function(t,e,n,r){var i=this.xi(t,e);f("RestConnection","Sending: ",i,n);var o={};return this.ki(o,r),this.Fi(t,i,o,n).then(function(t){return f("RestConnection","Received: ",t),t},function(e){throw d("RestConnection",t+" failed with error: ",e,"url: ",i,"request:",n),e})},t.prototype.$i=function(t,e,n,r){return this.Ni(t,e,n,r)},t.prototype.ki=function(t,e){if(t["X-Goog-Api-Client"]="gl-js/ fire/8.10.0",t["Content-Type"]="text/plain",this.databaseInfo.appId&&(t["X-Firebase-GMPID"]=this.databaseInfo.appId),e)for(var n in e.authHeaders)e.authHeaders.hasOwnProperty(n)&&(t[n]=e.authHeaders[n])},t.prototype.xi=function(t,e){var n=oo[t];return this.Di+"/v1/"+e+":"+n},t}());function uo(){return"undefined"!=typeof window?window:null}function co(){return"undefined"!=typeof document?document:null}function ho(t){return new tn(t,!0)}var fo=function(){function t(t,e,n,r,i){void 0===n&&(n=1e3),void 0===r&&(r=1.5),void 0===i&&(i=6e4),this.Se=t,this.timerId=e,this.Mi=n,this.Li=r,this.Bi=i,this.qi=0,this.Ui=null,this.Ki=Date.now(),this.reset()}return t.prototype.reset=function(){this.qi=0},t.prototype.Qi=function(){this.qi=this.Bi},t.prototype.ji=function(t){var e=this;this.cancel();var n=Math.floor(this.qi+this.Wi()),r=Math.max(0,Date.now()-this.Ki),i=Math.max(0,n-r);i>0&&f("ExponentialBackoff","Backing off for "+i+" ms (base delay: "+this.qi+" ms, delay with jitter: "+n+" ms, last attempt: "+r+" ms ago)"),this.Ui=this.Se.enqueueAfterDelay(this.timerId,i,function(){return e.Ki=Date.now(),t()}),this.qi*=this.Li,this.qi<this.Mi&&(this.qi=this.Mi),this.qi>this.Bi&&(this.qi=this.Bi)},t.prototype.Gi=function(){null!==this.Ui&&(this.Ui.skipDelay(),this.Ui=null)},t.prototype.cancel=function(){null!==this.Ui&&(this.Ui.cancel(),this.Ui=null)},t.prototype.Wi=function(){return(Math.random()-.5)*this.qi},t}(),lo=function(){function t(t,e,n,r,i,o){this.Se=t,this.zi=n,this.Hi=r,this.Ji=i,this.listener=o,this.state=0,this.Yi=0,this.Xi=null,this.stream=null,this.Zi=new fo(t,e)}return t.prototype.tr=function(){return 1===this.state||2===this.state||4===this.state},t.prototype.er=function(){return 2===this.state},t.prototype.start=function(){3!==this.state?this.auth():this.nr()},t.prototype.stop=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(t){switch(t.label){case 0:return this.tr()?[4,this.close(0)]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}})})},t.prototype.sr=function(){this.state=0,this.Zi.reset()},t.prototype.ir=function(){var t=this;this.er()&&null===this.Xi&&(this.Xi=this.Se.enqueueAfterDelay(this.zi,6e4,function(){return t.rr()}))},t.prototype.cr=function(t){this.ur(),this.stream.send(t)},t.prototype.rr=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(t){return this.er()?[2,this.close(0)]:[2]})})},t.prototype.ur=function(){this.Xi&&(this.Xi.cancel(),this.Xi=null)},t.prototype.close=function(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return this.ur(),this.Zi.cancel(),this.Yi++,3!==t?this.Zi.reset():n&&n.code===a.RESOURCE_EXHAUSTED?(l(n.toString()),l("Using maximum backoff delay to prevent overloading the backend."),this.Zi.Qi()):n&&n.code===a.UNAUTHENTICATED&&this.Ji.invalidateToken(),null!==this.stream&&(this.ar(),this.stream.close(),this.stream=null),this.state=t,[4,this.listener.Ri(n)];case 1:return e.sent(),[2]}})})},t.prototype.ar=function(){},t.prototype.auth=function(){var t=this;this.state=1;var e=this.hr(this.Yi),n=this.Yi;this.Ji.getToken().then(function(e){t.Yi===n&&t.lr(e)},function(n){e(function(){var e=new u(a.UNKNOWN,"Fetching auth token failed: "+n.message);return t.dr(e)})})},t.prototype.lr=function(t){var e=this,n=this.hr(this.Yi);this.stream=this.wr(t),this.stream.Ii(function(){n(function(){return e.state=2,e.listener.Ii()})}),this.stream.Ri(function(t){n(function(){return e.dr(t)})}),this.stream.onMessage(function(t){n(function(){return e.onMessage(t)})})},t.prototype.nr=function(){var t=this;this.state=4,this.Zi.ji(function(){return(0,e.__awaiter)(t,void 0,void 0,function(){return(0,e.__generator)(this,function(t){return this.state=0,this.start(),[2]})})})},t.prototype.dr=function(t){return f("PersistentStream","close with error: "+t),this.stream=null,this.close(3,t)},t.prototype.hr=function(t){var e=this;return function(n){e.Se.enqueueAndForget(function(){return e.Yi===t?n():(f("PersistentStream","stream callback skipped by getCloseGuardedDispatcher."),Promise.resolve())})}},t}(),po=function(t){function n(e,n,r,i,o){var s=this;return(s=t.call(this,e,"listen_stream_connection_backoff","listen_stream_idle",n,r,o)||this).R=i,s}return(0,e.__extends)(n,t),n.prototype.wr=function(t){return this.Hi.Oi("Listen",t)},n.prototype.onMessage=function(t){this.Zi.reset();var e=function(t,e){var n;if("targetChange"in e){e.targetChange;var r=function(t){return"NO_CHANGE"===t?0:"ADD"===t?1:"REMOVE"===t?2:"CURRENT"===t?3:"RESET"===t?4:y()}(e.targetChange.targetChangeType||"NO_CHANGE"),i=e.targetChange.targetIds||[],o=function(t,e){return t.I?(v(void 0===e||"string"==typeof e),L.fromBase64String(e||"")):(v(void 0===e||e instanceof Uint8Array),L.fromUint8Array(e||new Uint8Array))}(t,e.targetChange.resumeToken),s=(c=e.targetChange.cause)&&function(t){var e=void 0===t.code?a.UNKNOWN:De(t.code);return new u(e,t.message||"")}(c);n=new We(r,i,o,s||null)}else if("documentChange"in e){e.documentChange,(r=e.documentChange).document,r.document.name,r.document.updateTime,i=cn(t,r.document.name),o=on(r.document.updateTime);var c=new ot({mapValue:{fields:r.document.fields}}),h=(s=at.newFoundDocument(i,o,c),r.targetIds||[]),f=r.removedTargetIds||[];n=new Ge(h,f,s.key,s)}else if("documentDelete"in e)e.documentDelete,(r=e.documentDelete).document,i=cn(t,r.document),o=r.readTime?on(r.readTime):T.min(),c=at.newNoDocument(i,o),s=r.removedTargetIds||[],n=new Ge([],s,c.key,c);else if("documentRemove"in e)e.documentRemove,(r=e.documentRemove).document,i=cn(t,r.document),o=r.removedTargetIds||[],n=new Ge([],o,i,null);else{if(!("filter"in e))return y();e.filter;var l=e.filter;l.targetId,r=l.count||0,i=new Se(r),o=l.targetId,n=new ze(o,i)}return n}(this.R,t),n=function(t){if(!("targetChange"in t))return T.min();var e=t.targetChange;return e.targetIds&&e.targetIds.length?T.min():e.readTime?on(e.readTime):T.min()}(t);return this.listener._r(e,n)},n.prototype.mr=function(t){var e={};e.database=ln(this.R),e.addTarget=function(t,e){var n,r=e.target;return(n=lt(r)?{documents:gn(t,r)}:{query:_n(t,r)}).targetId=e.targetId,e.resumeToken.approximateByteSize()>0?n.resumeToken=nn(t,e.resumeToken):e.snapshotVersion.compareTo(T.min())>0&&(n.readTime=en(t,e.snapshotVersion.toTimestamp())),n}(this.R,t);var n=function(t,e){var n=function(t,e){switch(e){case 0:return null;case 1:return"existence-filter-mismatch";case 2:return"limbo-document";default:return y()}}(0,e.purpose);return null==n?null:{"goog-listen-tags":n}}(this.R,t);n&&(e.labels=n),this.cr(e)},n.prototype.yr=function(t){var e={};e.database=ln(this.R),e.removeTarget=t,this.cr(e)},n}(lo),yo=function(t){function n(e,n,r,i,o){var s=this;return(s=t.call(this,e,"write_stream_connection_backoff","write_stream_idle",n,r,o)||this).R=i,s.gr=!1,s}return(0,e.__extends)(n,t),Object.defineProperty(n.prototype,"pr",{get:function(){return this.gr},enumerable:!1,configurable:!0}),n.prototype.start=function(){this.gr=!1,this.lastStreamToken=void 0,t.prototype.start.call(this)},n.prototype.ar=function(){this.gr&&this.Er([])},n.prototype.wr=function(t){return this.Hi.Oi("Write",t)},n.prototype.onMessage=function(t){if(v(!!t.streamToken),this.lastStreamToken=t.streamToken,this.gr){this.Zi.reset();var e=function(t,e){return t&&t.length>0?(v(void 0!==e),t.map(function(t){return function(t,e){var n=t.updateTime?on(t.updateTime):on(e);return n.isEqual(T.min())&&(n=on(e)),new ae(n,t.transformResults||[])}(t,e)})):[]}(t.writeResults,t.commitTime),n=on(t.commitTime);return this.listener.Tr(n,e)}return v(!t.writeResults||0===t.writeResults.length),this.gr=!0,this.listener.Ir()},n.prototype.Ar=function(){var t={};t.database=ln(this.R),this.cr(t)},n.prototype.Er=function(t){var e=this,n={streamToken:this.lastStreamToken,writes:t.map(function(t){return vn(e.R,t)})};this.cr(n)},n}(lo),vo=function(t){function n(e,n,r){var i=this;return(i=t.call(this)||this).credentials=e,i.Hi=n,i.R=r,i.Rr=!1,i}return(0,e.__extends)(n,t),n.prototype.br=function(){if(this.Rr)throw new u(a.FAILED_PRECONDITION,"The client has already been terminated.")},n.prototype.Ni=function(t,e,n){var r=this;return this.br(),this.credentials.getToken().then(function(i){return r.Hi.Ni(t,e,n,i)}).catch(function(t){throw"FirebaseError"===t.name?(t.code===a.UNAUTHENTICATED&&r.credentials.invalidateToken(),t):new u(a.UNKNOWN,t.toString())})},n.prototype.$i=function(t,e,n){var r=this;return this.br(),this.credentials.getToken().then(function(i){return r.Hi.$i(t,e,n,i)}).catch(function(t){throw"FirebaseError"===t.name?(t.code===a.UNAUTHENTICATED&&r.credentials.invalidateToken(),t):new u(a.UNKNOWN,t.toString())})},n.prototype.terminate=function(){this.Rr=!0},n}(function(){}),mo=function(){function t(t,e){this.asyncQueue=t,this.onlineStateHandler=e,this.state="Unknown",this.vr=0,this.Pr=null,this.Vr=!0}return t.prototype.Sr=function(){var t=this;0===this.vr&&(this.Dr("Unknown"),this.Pr=this.asyncQueue.enqueueAfterDelay("online_state_timeout",1e4,function(){return t.Pr=null,t.Cr("Backend didn't respond within 10 seconds."),t.Dr("Offline"),Promise.resolve()}))},t.prototype.Nr=function(t){"Online"===this.state?this.Dr("Unknown"):(this.vr++,this.vr>=1&&(this.kr(),this.Cr("Connection failed 1 times. Most recent error: "+t.toString()),this.Dr("Offline")))},t.prototype.set=function(t){this.kr(),this.vr=0,"Online"===t&&(this.Vr=!1),this.Dr(t)},t.prototype.Dr=function(t){t!==this.state&&(this.state=t,this.onlineStateHandler(t))},t.prototype.Cr=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.Vr?(l(e),this.Vr=!1):f("OnlineStateTracker",e)},t.prototype.kr=function(){null!==this.Pr&&(this.Pr.cancel(),this.Pr=null)},t}(),go=function(t,n,r,i,o){var s=this;this.localStore=t,this.datastore=n,this.asyncQueue=r,this.remoteSyncer={},this.Fr=[],this.$r=new Map,this.Or=new Set,this.Mr=[],this.Lr=o,this.Lr.di(function(t){r.enqueueAndForget(function(){return(0,e.__awaiter)(s,void 0,void 0,function(){return(0,e.__generator)(this,function(t){switch(t.label){case 0:return Do(this)?(f("RemoteStore","Restarting streams for network reachability change."),[4,function(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return(n=m(t)).Or.add(4),[4,wo(n)];case 1:return e.sent(),n.Br.set("Unknown"),n.Or.delete(4),[4,_o(n)];case 2:return e.sent(),[2]}})})}(this)]):[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}})})})}),this.Br=new mo(r,i)};function _o(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n,r;return(0,e.__generator)(this,function(e){switch(e.label){case 0:if(!Do(t))return[3,4];n=0,r=t.Mr,e.label=1;case 1:return n<r.length?[4,(0,r[n])(!0)]:[3,4];case 2:e.sent(),e.label=3;case 3:return n++,[3,1];case 4:return[2]}})})}function wo(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n,r;return(0,e.__generator)(this,function(e){switch(e.label){case 0:n=0,r=t.Mr,e.label=1;case 1:return n<r.length?[4,(0,r[n])(!1)]:[3,4];case 2:e.sent(),e.label=3;case 3:return n++,[3,1];case 4:return[2]}})})}function bo(t,e){var n=m(t);n.$r.has(e.targetId)||(n.$r.set(e.targetId,e),No(n)?So(n):jo(n).er()&&Eo(n,e))}function Io(t,e){var n=m(t),r=jo(n);n.$r.delete(e),r.er()&&To(n,e),0===n.$r.size&&(r.er()?r.ir():Do(n)&&n.Br.set("Unknown"))}function Eo(t,e){t.qr.U(e.targetId),jo(t).mr(e)}function To(t,e){t.qr.U(e),jo(t).yr(e)}function So(t){t.qr=new Ye({getRemoteKeysForTarget:function(e){return t.remoteSyncer.getRemoteKeysForTarget(e)},lt:function(e){return t.$r.get(e)||null}}),jo(t).start(),t.Br.Sr()}function No(t){return Do(t)&&!jo(t).tr()&&t.$r.size>0}function Do(t){return 0===m(t).Or.size}function Ao(t){t.qr=void 0}function xo(t){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(e){return t.$r.forEach(function(e,n){Eo(t,e)}),[2]})})}function ko(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(e){return Ao(t),No(t)?(t.Br.Nr(n),So(t)):t.Br.set("Unknown"),[2]})})}function Co(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o,s;return(0,e.__generator)(this,function(a){switch(a.label){case 0:if(t.Br.set("Online"),!(n instanceof We&&2===n.state&&n.cause))return[3,6];a.label=1;case 1:return a.trys.push([1,3,,5]),[4,function(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o,s;return(0,e.__generator)(this,function(e){switch(e.label){case 0:r=n.cause,i=0,o=n.targetIds,e.label=1;case 1:return i<o.length?(s=o[i],t.$r.has(s)?[4,t.remoteSyncer.rejectListen(s,r)]:[3,3]):[3,5];case 2:e.sent(),t.$r.delete(s),t.qr.removeTarget(s),e.label=3;case 3:e.label=4;case 4:return i++,[3,1];case 5:return[2]}})})}(t,n)];case 2:return a.sent(),[3,5];case 3:return i=a.sent(),f("RemoteStore","Failed to remove targets %s: %s ",n.targetIds.join(","),i),[4,Ro(t,i)];case 4:return a.sent(),[3,5];case 5:return[3,13];case 6:if(n instanceof Ge?t.qr.X(n):n instanceof ze?t.qr.rt(n):t.qr.et(n),r.isEqual(T.min()))return[3,13];a.label=7;case 7:return a.trys.push([7,11,,13]),[4,Ti(t.localStore)];case 8:return o=a.sent(),r.compareTo(o)>=0?[4,function(t,e){var n=t.qr.ut(e);return n.targetChanges.forEach(function(n,r){if(n.resumeToken.approximateByteSize()>0){var i=t.$r.get(r);i&&t.$r.set(r,i.withResumeToken(n.resumeToken,e))}}),n.targetMismatches.forEach(function(e){var n=t.$r.get(e);if(n){t.$r.set(e,n.withResumeToken(L.EMPTY_BYTE_STRING,n.snapshotVersion)),To(t,e);var r=new vr(n.target,e,1,n.sequenceNumber);Eo(t,r)}}),t.remoteSyncer.applyRemoteEvent(n)}(t,r)]:[3,10];case 9:a.sent(),a.label=10;case 10:return[3,13];case 11:return f("RemoteStore","Failed to raise snapshot:",s=a.sent()),[4,Ro(t,s)];case 12:return a.sent(),[3,13];case 13:return[2]}})})}function Ro(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i=this;return(0,e.__generator)(this,function(o){switch(o.label){case 0:if(!ar(n))throw n;return t.Or.add(1),[4,wo(t)];case 1:return o.sent(),t.Br.set("Offline"),r||(r=function(){return Ti(t.localStore)}),t.asyncQueue.enqueueRetryable(function(){return(0,e.__awaiter)(i,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return f("RemoteStore","Retrying IndexedDB access"),[4,r()];case 1:return e.sent(),t.Or.delete(1),[4,_o(t)];case 2:return e.sent(),[2]}})})}),[2]}})})}function Lo(t,e){return e().catch(function(n){return Ro(t,n,e)})}function Oo(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n,r,i,o,s;return(0,e.__generator)(this,function(e){switch(e.label){case 0:n=m(t),r=Ko(n),i=n.Fr.length>0?n.Fr[n.Fr.length-1].batchId:-1,e.label=1;case 1:if(!function(t){return Do(t)&&t.Fr.length<10}(n))return[3,7];e.label=2;case 2:return e.trys.push([2,4,,6]),[4,Di(n.localStore,i)];case 3:return null===(o=e.sent())?(0===n.Fr.length&&r.ir(),[3,7]):(i=o.batchId,function(t,e){t.Fr.push(e);var n=Ko(t);n.er()&&n.pr&&n.Er(e.mutations)}(n,o),[3,6]);case 4:return s=e.sent(),[4,Ro(n,s)];case 5:return e.sent(),[3,6];case 6:return[3,1];case 7:return Po(n)&&Fo(n),[2]}})})}function Po(t){return Do(t)&&!Ko(t).tr()&&t.Fr.length>0}function Fo(t){Ko(t).start()}function Mo(t){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(e){return Ko(t).Ar(),[2]})})}function Vo(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n,r,i,o;return(0,e.__generator)(this,function(e){for(n=Ko(t),r=0,i=t.Fr;r<i.length;r++)o=i[r],n.Er(o.mutations);return[2]})})}function qo(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return i=t.Fr.shift(),o=yr.from(i,n,r),[4,Lo(t,function(){return t.remoteSyncer.applySuccessfulWrite(o)})];case 1:return e.sent(),[4,Oo(t)];case 2:return e.sent(),[2]}})})}function Uo(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(r){switch(r.label){case 0:return n&&Ko(t).pr?[4,function(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return Ne(i=n.code)&&i!==a.ABORTED?(r=t.Fr.shift(),Ko(t).sr(),[4,Lo(t,function(){return t.remoteSyncer.rejectFailedWrite(r.batchId,n)})]):[3,3];case 1:return e.sent(),[4,Oo(t)];case 2:e.sent(),e.label=3;case 3:return[2]}})})}(t,n)]:[3,2];case 1:r.sent(),r.label=2;case 2:return Po(t)&&Fo(t),[2]}})})}function Bo(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return r=m(t),n?(r.Or.delete(2),[4,_o(r)]):[3,2];case 1:return e.sent(),[3,5];case 2:return n?[3,4]:(r.Or.add(2),[4,wo(r)]);case 3:e.sent(),r.Br.set("Unknown"),e.label=4;case 4:e.label=5;case 5:return[2]}})})}function jo(t){var n=this;return t.Ur||(t.Ur=function(t,e,n){var r=m(t);return r.br(),new po(e,r.Hi,r.credentials,r.R,n)}(t.datastore,t.asyncQueue,{Ii:xo.bind(null,t),Ri:ko.bind(null,t),_r:Co.bind(null,t)}),t.Mr.push(function(r){return(0,e.__awaiter)(n,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return r?(t.Ur.sr(),No(t)?So(t):t.Br.set("Unknown"),[3,3]):[3,1];case 1:return[4,t.Ur.stop()];case 2:e.sent(),Ao(t),e.label=3;case 3:return[2]}})})})),t.Ur}function Ko(t){var n=this;return t.Kr||(t.Kr=function(t,e,n){var r=m(t);return r.br(),new yo(e,r.Hi,r.credentials,r.R,n)}(t.datastore,t.asyncQueue,{Ii:Mo.bind(null,t),Ri:Uo.bind(null,t),Ir:Vo.bind(null,t),Tr:qo.bind(null,t)}),t.Mr.push(function(r){return(0,e.__awaiter)(n,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return r?(t.Kr.sr(),[4,Oo(t)]):[3,2];case 1:return e.sent(),[3,4];case 2:return[4,t.Kr.stop()];case 3:e.sent(),t.Fr.length>0&&(f("RemoteStore","Stopping write stream with "+t.Fr.length+" pending writes"),t.Fr=[]),e.label=4;case 4:return[2]}})})})),t.Kr}var Qo=function(){function t(t,e,n,r,i){this.asyncQueue=t,this.timerId=e,this.targetTimeMs=n,this.op=r,this.removalCallback=i,this.deferred=new er,this.then=this.deferred.promise.then.bind(this.deferred.promise),this.deferred.promise.catch(function(t){})}return t.createAndSchedule=function(e,n,r,i,o){var s=new t(e,n,Date.now()+r,i,o);return s.start(r),s},t.prototype.start=function(t){var e=this;this.timerHandle=setTimeout(function(){return e.handleDelayElapsed()},t)},t.prototype.skipDelay=function(){return this.handleDelayElapsed()},t.prototype.cancel=function(t){null!==this.timerHandle&&(this.clearTimeout(),this.deferred.reject(new u(a.CANCELLED,"Operation cancelled"+(t?": "+t:""))))},t.prototype.handleDelayElapsed=function(){var t=this;this.asyncQueue.enqueueAndForget(function(){return null!==t.timerHandle?(t.clearTimeout(),t.op().then(function(e){return t.deferred.resolve(e)})):Promise.resolve()})},t.prototype.clearTimeout=function(){null!==this.timerHandle&&(this.removalCallback(this),clearTimeout(this.timerHandle),this.timerHandle=null)},t}();function Go(t,e){if(l("AsyncQueue",e+": "+t),ar(t))return new u(a.UNAVAILABLE,e+": "+t);throw t}var zo=function(){function t(t){this.comparator=t?function(e,n){return t(e,n)||Q.comparator(e.key,n.key)}:function(t,e){return Q.comparator(t.key,e.key)},this.keyedMap=Fe(),this.sortedSet=new Ae(this.comparator)}return t.emptySet=function(e){return new t(e.comparator)},t.prototype.has=function(t){return null!=this.keyedMap.get(t)},t.prototype.get=function(t){return this.keyedMap.get(t)},t.prototype.first=function(){return this.sortedSet.minKey()},t.prototype.last=function(){return this.sortedSet.maxKey()},t.prototype.isEmpty=function(){return this.sortedSet.isEmpty()},t.prototype.indexOf=function(t){var e=this.keyedMap.get(t);return e?this.sortedSet.indexOf(e):-1},Object.defineProperty(t.prototype,"size",{get:function(){return this.sortedSet.size},enumerable:!1,configurable:!0}),t.prototype.forEach=function(t){this.sortedSet.inorderTraversal(function(e,n){return t(e),!1})},t.prototype.add=function(t){var e=this.delete(t.key);return e.copy(e.keyedMap.insert(t.key,t),e.sortedSet.insert(t,null))},t.prototype.delete=function(t){var e=this.get(t);return e?this.copy(this.keyedMap.remove(t),this.sortedSet.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.sortedSet.getIterator(),r=e.sortedSet.getIterator();n.hasNext();){var i=n.getNext().key,o=r.getNext().key;if(!i.isEqual(o))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.copy=function(e,n){var r=new t;return r.comparator=this.comparator,r.keyedMap=e,r.sortedSet=n,r},t}(),Wo=function(){function t(){this.Qr=new Ae(Q.comparator)}return t.prototype.track=function(t){var e=t.doc.key,n=this.Qr.get(e);n?0!==t.type&&3===n.type?this.Qr=this.Qr.insert(e,t):3===t.type&&1!==n.type?this.Qr=this.Qr.insert(e,{type:n.type,doc:t.doc}):2===t.type&&2===n.type?this.Qr=this.Qr.insert(e,{type:2,doc:t.doc}):2===t.type&&0===n.type?this.Qr=this.Qr.insert(e,{type:0,doc:t.doc}):1===t.type&&0===n.type?this.Qr=this.Qr.remove(e):1===t.type&&2===n.type?this.Qr=this.Qr.insert(e,{type:1,doc:n.doc}):0===t.type&&1===n.type?this.Qr=this.Qr.insert(e,{type:2,doc:t.doc}):y():this.Qr=this.Qr.insert(e,t)},t.prototype.jr=function(){var t=[];return this.Qr.inorderTraversal(function(e,n){t.push(n)}),t},t}(),Ho=function(){function t(t,e,n,r,i,o,s,a){this.query=t,this.docs=e,this.oldDocs=n,this.docChanges=r,this.mutatedKeys=i,this.fromCache=o,this.syncStateChanged=s,this.excludesMetadataChanges=a}return t.fromInitialDocuments=function(e,n,r,i){var o=[];return n.forEach(function(t){o.push({type:0,doc:t})}),new t(e,n,zo.emptySet(n),o,r,i,!0,!1)},Object.defineProperty(t.prototype,"hasPendingWrites",{get:function(){return!this.mutatedKeys.isEmpty()},enumerable:!1,configurable:!0}),t.prototype.isEqual=function(t){if(!(this.fromCache===t.fromCache&&this.syncStateChanged===t.syncStateChanged&&this.mutatedKeys.isEqual(t.mutatedKeys)&&qt(this.query,t.query)&&this.docs.isEqual(t.docs)&&this.oldDocs.isEqual(t.oldDocs)))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}(),Yo=function(){this.Wr=void 0,this.listeners=[]},$o=function(){this.queries=new ni(function(t){return Ut(t)},qt),this.onlineState="Unknown",this.Gr=new Set};function Xo(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o,s,a,u,c;return(0,e.__generator)(this,function(e){switch(e.label){case 0:if(r=m(t),i=n.query,o=!1,(s=r.queries.get(i))||(o=!0,s=new Yo),!o)return[3,4];e.label=1;case 1:return e.trys.push([1,3,,4]),a=s,[4,r.onListen(i)];case 2:return a.Wr=e.sent(),[3,4];case 3:return u=e.sent(),c=Go(u,"Initialization of query '"+Bt(n.query)+"' failed"),[2,void n.onError(c)];case 4:return r.queries.set(i,s),s.listeners.push(n),n.zr(r.onlineState),s.Wr&&n.Hr(s.Wr)&&es(r),[2]}})})}function Jo(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o,s,a;return(0,e.__generator)(this,function(e){return r=m(t),i=n.query,o=!1,(s=r.queries.get(i))&&(a=s.listeners.indexOf(n))>=0&&(s.listeners.splice(a,1),o=0===s.listeners.length),o?[2,(r.queries.delete(i),r.onUnlisten(i))]:[2]})})}function Zo(t,e){for(var n=m(t),r=!1,i=0,o=e;i<o.length;i++){var s=o[i],a=s.query,u=n.queries.get(a);if(u){for(var c=0,h=u.listeners;c<h.length;c++)h[c].Hr(s)&&(r=!0);u.Wr=s}}r&&es(n)}function ts(t,e,n){var r=m(t),i=r.queries.get(e);if(i)for(var o=0,s=i.listeners;o<s.length;o++)s[o].onError(n);r.queries.delete(e)}function es(t){t.Gr.forEach(function(t){t.next()})}var ns=function(){function t(t,e,n){this.query=t,this.Jr=e,this.Yr=!1,this.Xr=null,this.onlineState="Unknown",this.options=n||{}}return t.prototype.Hr=function(t){if(!this.options.includeMetadataChanges){for(var e=[],n=0,r=t.docChanges;n<r.length;n++){var i=r[n];3!==i.type&&e.push(i)}t=new Ho(t.query,t.docs,t.oldDocs,e,t.mutatedKeys,t.fromCache,t.syncStateChanged,!0)}var o=!1;return this.Yr?this.Zr(t)&&(this.Jr.next(t),o=!0):this.eo(t,this.onlineState)&&(this.no(t),o=!0),this.Xr=t,o},t.prototype.onError=function(t){this.Jr.error(t)},t.prototype.zr=function(t){this.onlineState=t;var e=!1;return this.Xr&&!this.Yr&&this.eo(this.Xr,t)&&(this.no(this.Xr),e=!0),e},t.prototype.eo=function(t,e){if(!t.fromCache)return!0;var n="Offline"!==e;return!(this.options.so&&n||t.docs.isEmpty()&&"Offline"!==e)},t.prototype.Zr=function(t){if(t.docChanges.length>0)return!0;var e=this.Xr&&this.Xr.hasPendingWrites!==t.hasPendingWrites;return!(!t.syncStateChanged&&!e)&&!0===this.options.includeMetadataChanges},t.prototype.no=function(t){t=Ho.fromInitialDocuments(t.query,t.docs,t.mutatedKeys,t.fromCache),this.Yr=!0,this.Jr.next(t)},t}(),rs=function(){function t(t,e){this.payload=t,this.byteLength=e}return t.prototype.io=function(){return"metadata"in this.payload},t}(),is=function(){function t(t){this.R=t}return t.prototype.qn=function(t){return cn(this.R,t)},t.prototype.Un=function(t){return t.metadata.exists?yn(this.R,t.document,!1):at.newNoDocument(this.qn(t.metadata.name),this.Kn(t.metadata.readTime))},t.prototype.Kn=function(t){return on(t)},t}(),os=function(){function t(t,e,n){this.ro=t,this.localStore=e,this.R=n,this.queries=[],this.documents=[],this.progress=ss(t)}return t.prototype.oo=function(t){this.progress.bytesLoaded+=t.byteLength;var e=this.progress.documentsLoaded;return t.payload.namedQuery?this.queries.push(t.payload.namedQuery):t.payload.documentMetadata?(this.documents.push({metadata:t.payload.documentMetadata}),t.payload.documentMetadata.exists||++e):t.payload.document&&(this.documents[this.documents.length-1].document=t.payload.document,++e),e!==this.progress.documentsLoaded?(this.progress.documentsLoaded=e,Object.assign({},this.progress)):null},t.prototype.co=function(t){for(var e=new Map,n=new is(this.R),r=0,i=t;r<i.length;r++){var o=i[r];if(o.metadata.queries)for(var s=n.qn(o.metadata.name),a=0,u=o.metadata.queries;a<u.length;a++){var c=u[a],h=(e.get(c)||Ue()).add(s);e.set(c,h)}}return e},t.prototype.complete=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var t,n,r,i,o;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,Oi(this.localStore,new is(this.R),this.documents,this.ro.id)];case 1:t=e.sent(),n=this.co(this.documents),r=0,i=this.queries,e.label=2;case 2:return r<i.length?(o=i[r],[4,Pi(this.localStore,o,n.get(o.name))]):[3,5];case 3:e.sent(),e.label=4;case 4:return r++,[3,2];case 5:return[2,(this.progress.taskState="Success",new vi(Object.assign({},this.progress),t))]}})})},t}();function ss(t){return{taskState:"Running",documentsLoaded:0,bytesLoaded:0,totalDocuments:t.totalDocuments,totalBytes:t.totalBytes}}var as=function(t){this.key=t},us=function(t){this.key=t},cs=function(){function t(t,e){this.query=t,this.uo=e,this.ao=null,this.current=!1,this.ho=Ue(),this.mutatedKeys=Ue(),this.lo=Kt(t),this.fo=new zo(this.lo)}return Object.defineProperty(t.prototype,"wo",{get:function(){return this.uo},enumerable:!1,configurable:!0}),t.prototype._o=function(t,e){var n=this,r=e?e.mo:new Wo,i=e?e.fo:this.fo,o=e?e.mutatedKeys:this.mutatedKeys,s=i,a=!1,u=Ct(this.query)&&i.size===this.query.limit?i.last():null,c=Rt(this.query)&&i.size===this.query.limit?i.first():null;if(t.inorderTraversal(function(t,e){var h=i.get(t),f=jt(n.query,e)?e:null,l=!!h&&n.mutatedKeys.has(h.key),d=!!f&&(f.hasLocalMutations||n.mutatedKeys.has(f.key)&&f.hasCommittedMutations),p=!1;h&&f?h.data.isEqual(f.data)?l!==d&&(r.track({type:3,doc:f}),p=!0):n.yo(h,f)||(r.track({type:2,doc:f}),p=!0,(u&&n.lo(f,u)>0||c&&n.lo(f,c)<0)&&(a=!0)):!h&&f?(r.track({type:0,doc:f}),p=!0):h&&!f&&(r.track({type:1,doc:h}),p=!0,(u||c)&&(a=!0)),p&&(f?(s=s.add(f),o=d?o.add(t):o.delete(t)):(s=s.delete(t),o=o.delete(t)))}),Ct(this.query)||Rt(this.query))for(;s.size>this.query.limit;){var h=Ct(this.query)?s.last():s.first();s=s.delete(h.key),o=o.delete(h.key),r.track({type:1,doc:h})}return{fo:s,mo:r,Nn:a,mutatedKeys:o}},t.prototype.yo=function(t,e){return t.hasLocalMutations&&e.hasCommittedMutations&&!e.hasLocalMutations},t.prototype.applyChanges=function(t,e,n){var r=this,i=this.fo;this.fo=t.fo,this.mutatedKeys=t.mutatedKeys;var o=t.mo.jr();o.sort(function(t,e){return function(t,e){var n=function(t){switch(t){case 0:return 1;case 2:case 3:return 2;case 1:return 0;default:return y()}};return n(t)-n(e)}(t.type,e.type)||r.lo(t.doc,e.doc)}),this.po(n);var s=e?this.Eo():[],a=0===this.ho.size&&this.current?1:0,u=a!==this.ao;return this.ao=a,0!==o.length||u?{snapshot:new Ho(this.query,t.fo,i,o,t.mutatedKeys,0===a,u,!1),To:s}:{To:s}},t.prototype.zr=function(t){return this.current&&"Offline"===t?(this.current=!1,this.applyChanges({fo:this.fo,mo:new Wo,mutatedKeys:this.mutatedKeys,Nn:!1},!1)):{To:[]}},t.prototype.Io=function(t){return!this.uo.has(t)&&!!this.fo.has(t)&&!this.fo.get(t).hasLocalMutations},t.prototype.po=function(t){var e=this;t&&(t.addedDocuments.forEach(function(t){return e.uo=e.uo.add(t)}),t.modifiedDocuments.forEach(function(t){}),t.removedDocuments.forEach(function(t){return e.uo=e.uo.delete(t)}),this.current=t.current)},t.prototype.Eo=function(){var t=this;if(!this.current)return[];var e=this.ho;this.ho=Ue(),this.fo.forEach(function(e){t.Io(e.key)&&(t.ho=t.ho.add(e.key))});var n=[];return e.forEach(function(e){t.ho.has(e)||n.push(new us(e))}),this.ho.forEach(function(t){e.has(t)||n.push(new as(t))}),n},t.prototype.Ao=function(t){this.uo=t.Bn,this.ho=Ue();var e=this._o(t.documents);return this.applyChanges(e,!0)},t.prototype.Ro=function(){return Ho.fromInitialDocuments(this.query,this.fo,this.mutatedKeys,0===this.ao)},t}(),hs=function(t,e,n){this.query=t,this.targetId=e,this.view=n},fs=function(t){this.key=t,this.bo=!1},ls=function(){function t(t,e,n,r,i,o){this.localStore=t,this.remoteStore=e,this.eventManager=n,this.sharedClientState=r,this.currentUser=i,this.maxConcurrentLimboResolutions=o,this.vo={},this.Po=new ni(function(t){return Ut(t)},qt),this.Vo=new Map,this.So=new Set,this.Do=new Ae(Q.comparator),this.Co=new Map,this.No=new Mi,this.xo={},this.ko=new Map,this.Fo=Qr.Yt(),this.onlineState="Unknown",this.$o=void 0}return Object.defineProperty(t.prototype,"isPrimaryClient",{get:function(){return!0===this.$o},enumerable:!1,configurable:!0}),t}();function ds(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o,s,a,u;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return r=js(t),(s=r.Po.get(n))?(i=s.targetId,r.sharedClientState.addLocalQueryTarget(i),o=s.view.Ro(),[3,4]):[3,1];case 1:return[4,Ai(r.localStore,Mt(n))];case 2:return a=e.sent(),u=r.sharedClientState.addLocalQueryTarget(a.targetId),i=a.targetId,[4,ps(r,n,i,"current"===u)];case 3:o=e.sent(),r.isPrimaryClient&&bo(r.remoteStore,a),e.label=4;case 4:return[2,o]}})})}function ps(t,n,r,i){return(0,e.__awaiter)(this,void 0,void 0,function(){var o,s,a,u,c,h;return(0,e.__generator)(this,function(f){switch(f.label){case 0:return t.Oo=function(n,r,i){return function(t,n,r,i){return(0,e.__awaiter)(this,void 0,void 0,function(){var o,s,a;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return(o=n.view._o(r)).Nn?[4,ki(t.localStore,n.query,!1).then(function(t){var e=t.documents;return n.view._o(e,o)})]:[3,2];case 1:o=e.sent(),e.label=2;case 2:return s=i&&i.targetChanges.get(n.targetId),a=n.view.applyChanges(o,t.isPrimaryClient,s),[2,(Ds(t,n.targetId,a.To),a.snapshot)]}})})}(t,n,r,i)},[4,ki(t.localStore,n,!0)];case 1:return o=f.sent(),s=new cs(n,o.Bn),a=s._o(o.documents),u=Qe.createSynthesizedTargetChangeForCurrentChange(r,i&&"Offline"!==t.onlineState),c=s.applyChanges(a,t.isPrimaryClient,u),Ds(t,r,c.To),h=new hs(n,r,s),[2,(t.Po.set(n,h),t.Vo.has(r)?t.Vo.get(r).push(n):t.Vo.set(r,[n]),c.snapshot)]}})})}function ys(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return r=m(t),i=r.Po.get(n),(o=r.Vo.get(i.targetId)).length>1?[2,(r.Vo.set(i.targetId,o.filter(function(t){return!qt(t,n)})),void r.Po.delete(n))]:r.isPrimaryClient?(r.sharedClientState.removeLocalQueryTarget(i.targetId),r.sharedClientState.isActiveQueryTarget(i.targetId)?[3,2]:[4,xi(r.localStore,i.targetId,!1).then(function(){r.sharedClientState.clearQueryState(i.targetId),Io(r.remoteStore,i.targetId),Ss(r,i.targetId)}).catch(Yr)]):[3,3];case 1:e.sent(),e.label=2;case 2:return[3,5];case 3:return Ss(r,i.targetId),[4,xi(r.localStore,i.targetId,!0)];case 4:e.sent(),e.label=5;case 5:return[2]}})})}function vs(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o,s,a;return(0,e.__generator)(this,function(e){switch(e.label){case 0:i=Ks(t),e.label=1;case 1:return e.trys.push([1,5,,6]),[4,function(t,e){var n,r=m(t),i=E.now(),o=e.reduce(function(t,e){return t.add(e.key)},Ue());return r.persistence.runTransaction("Locally write mutations","readwrite",function(t){return r.Mn.pn(t,o).next(function(o){n=o;for(var s=[],a=0,u=e;a<u.length;a++){var c=u[a],h=de(c,n.get(c.key));null!=h&&s.push(new me(c.key,h,st(h.value.mapValue),ue.exists(!0)))}return r._n.addMutationBatch(t,i,s,e)})}).then(function(t){return t.applyToLocalDocumentSet(n),{batchId:t.batchId,changes:n}})}(i.localStore,n)];case 2:return o=e.sent(),i.sharedClientState.addPendingMutation(o.batchId),function(t,e,n){var r=t.xo[t.currentUser.toKey()];r||(r=new Ae(w)),r=r.insert(e,n),t.xo[t.currentUser.toKey()]=r}(i,o.batchId,r),[4,ks(i,o.changes)];case 3:return e.sent(),[4,Oo(i.remoteStore)];case 4:return e.sent(),[3,6];case 5:return s=e.sent(),a=Go(s,"Failed to persist write"),r.reject(a),[3,6];case 6:return[2]}})})}function ms(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i;return(0,e.__generator)(this,function(e){switch(e.label){case 0:r=m(t),e.label=1;case 1:return e.trys.push([1,4,,6]),[4,Si(r.localStore,n)];case 2:return i=e.sent(),n.targetChanges.forEach(function(t,e){var n=r.Co.get(e);n&&(v(t.addedDocuments.size+t.modifiedDocuments.size+t.removedDocuments.size<=1),t.addedDocuments.size>0?n.bo=!0:t.modifiedDocuments.size>0?v(n.bo):t.removedDocuments.size>0&&(v(n.bo),n.bo=!1))}),[4,ks(r,i,n)];case 3:return e.sent(),[3,6];case 4:return[4,Yr(e.sent())];case 5:return e.sent(),[3,6];case 6:return[2]}})})}function gs(t,e,n){var r=m(t);if(r.isPrimaryClient&&0===n||!r.isPrimaryClient&&1===n){var i=[];r.Po.forEach(function(t,n){var r=n.view.zr(e);r.snapshot&&i.push(r.snapshot)}),function(t,e){var n=m(t);n.onlineState=e;var r=!1;n.queries.forEach(function(t,n){for(var i=0,o=n.listeners;i<o.length;i++)o[i].zr(e)&&(r=!0)}),r&&es(n)}(r.eventManager,e),i.length&&r.vo._r(i),r.onlineState=e,r.isPrimaryClient&&r.sharedClientState.setOnlineState(e)}}function _s(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o,s,a,u,c;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return(i=m(t)).sharedClientState.updateQueryState(n,"rejected",r),o=i.Co.get(n),(s=o&&o.key)?(a=(a=new Ae(Q.comparator)).insert(s,at.newNoDocument(s,T.min())),u=Ue().add(s),c=new Ke(T.min(),new Map,new Ce(w),a,u),[4,ms(i,c)]):[3,2];case 1:return e.sent(),i.Do=i.Do.remove(s),i.Co.delete(n),xs(i),[3,4];case 2:return[4,xi(i.localStore,n,!1).then(function(){return Ss(i,n,r)}).catch(Yr)];case 3:e.sent(),e.label=4;case 4:return[2]}})})}function ws(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o;return(0,e.__generator)(this,function(e){switch(e.label){case 0:r=m(t),i=n.batch.batchId,e.label=1;case 1:return e.trys.push([1,4,,6]),[4,Ei(r.localStore,n)];case 2:return o=e.sent(),Ts(r,i,null),Es(r,i),r.sharedClientState.updateMutationState(i,"acknowledged"),[4,ks(r,o)];case 3:return e.sent(),[3,6];case 4:return[4,Yr(e.sent())];case 5:return e.sent(),[3,6];case 6:return[2]}})})}function bs(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o;return(0,e.__generator)(this,function(e){switch(e.label){case 0:i=m(t),e.label=1;case 1:return e.trys.push([1,4,,6]),[4,function(t,e){var n=m(t);return n.persistence.runTransaction("Reject batch","readwrite-primary",function(t){var r;return n._n.lookupMutationBatch(t,e).next(function(e){return v(null!==e),r=e.keys(),n._n.removeMutationBatch(t,e)}).next(function(){return n._n.performConsistencyCheck(t)}).next(function(){return n.Mn.pn(t,r)})})}(i.localStore,n)];case 2:return o=e.sent(),Ts(i,n,r),Es(i,n),i.sharedClientState.updateMutationState(n,"rejected",r),[4,ks(i,o)];case 3:return e.sent(),[3,6];case 4:return[4,Yr(e.sent())];case 5:return e.sent(),[3,6];case 6:return[2]}})})}function Is(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o,s,a;return(0,e.__generator)(this,function(e){switch(e.label){case 0:Do((r=m(t)).remoteStore)||f("SyncEngine","The network is disabled. The task returned by 'awaitPendingWrites()' will not complete until the network is enabled."),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,function(t){var e=m(r.localStore);return e.persistence.runTransaction("Get highest unacknowledged batch id","readonly",function(t){return e._n.getHighestUnacknowledgedBatchId(t)})}()];case 2:return-1===(i=e.sent())?[2,void n.resolve()]:((o=r.ko.get(i)||[]).push(n),r.ko.set(i,o),[3,4]);case 3:return s=e.sent(),a=Go(s,"Initialization of waitForPendingWrites() operation failed"),n.reject(a),[3,4];case 4:return[2]}})})}function Es(t,e){(t.ko.get(e)||[]).forEach(function(t){t.resolve()}),t.ko.delete(e)}function Ts(t,e,n){var r=m(t),i=r.xo[r.currentUser.toKey()];if(i){var o=i.get(e);o&&(n?o.reject(n):o.resolve(),i=i.remove(e)),r.xo[r.currentUser.toKey()]=i}}function Ss(t,e,n){void 0===n&&(n=null),t.sharedClientState.removeLocalQueryTarget(e);for(var r=0,i=t.Vo.get(e);r<i.length;r++){var o=i[r];t.Po.delete(o),n&&t.vo.Mo(o,n)}t.Vo.delete(e),t.isPrimaryClient&&t.No.Zn(e).forEach(function(e){t.No.containsKey(e)||Ns(t,e)})}function Ns(t,e){t.So.delete(e.path.canonicalString());var n=t.Do.get(e);null!==n&&(Io(t.remoteStore,n),t.Do=t.Do.remove(e),t.Co.delete(n),xs(t))}function Ds(t,e,n){for(var r=0,i=n;r<i.length;r++){var o=i[r];o instanceof as?(t.No.addReference(o.key,e),As(t,o)):o instanceof us?(f("SyncEngine","Document no longer in limbo: "+o.key),t.No.removeReference(o.key,e),t.No.containsKey(o.key)||Ns(t,o.key)):y()}}function As(t,e){var n=e.key,r=n.path.canonicalString();t.Do.get(n)||t.So.has(r)||(f("SyncEngine","New document in limbo: "+n),t.So.add(r),xs(t))}function xs(t){for(;t.So.size>0&&t.Do.size<t.maxConcurrentLimboResolutions;){var e=t.So.values().next().value;t.So.delete(e);var n=new Q(x.fromString(e)),r=t.Fo.next();t.Co.set(r,new fs(n)),t.Do=t.Do.insert(n,r),bo(t.remoteStore,new vr(Mt(kt(n.path)),r,2,s.o))}}function ks(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o,s,a;return(0,e.__generator)(this,function(u){switch(u.label){case 0:return i=m(t),o=[],s=[],a=[],i.Po.isEmpty()?[3,3]:(i.Po.forEach(function(t,e){a.push(i.Oo(e,n,r).then(function(t){if(t){i.isPrimaryClient&&i.sharedClientState.updateQueryState(e.targetId,t.fromCache?"not-current":"current"),o.push(t);var n=gi.Pn(e.targetId,t);s.push(n)}}))}),[4,Promise.all(a)]);case 1:return u.sent(),i.vo._r(o),[4,function(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o,s,a,u,c,h,l;return(0,e.__generator)(this,function(e){switch(e.label){case 0:r=m(t),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,r.persistence.runTransaction("notifyLocalViewChanges","readwrite",function(t){return nr.forEach(n,function(e){return nr.forEach(e.bn,function(n){return r.persistence.referenceDelegate.addReference(t,e.targetId,n)}).next(function(){return nr.forEach(e.vn,function(n){return r.persistence.referenceDelegate.removeReference(t,e.targetId,n)})})})})];case 2:return e.sent(),[3,4];case 3:if(!ar(i=e.sent()))throw i;return f("LocalStore","Failed to update sequence numbers: "+i),[3,4];case 4:for(o=0,s=n;o<s.length;o++)a=s[o],u=a.targetId,a.fromCache||(c=r.kn.get(u),h=c.snapshotVersion,l=c.withLastLimboFreeSnapshotVersion(h),r.kn=r.kn.insert(u,l));return[2]}})})}(i.localStore,s)];case 2:u.sent(),u.label=3;case 3:return[2]}})})}function Cs(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return(r=m(t)).currentUser.isEqual(n)?[3,3]:(f("SyncEngine","User change. New user:",n.toKey()),[4,Ii(r.localStore,n)]);case 1:return i=e.sent(),r.currentUser=n,function(t,e){t.ko.forEach(function(t){t.forEach(function(t){t.reject(new u(a.CANCELLED,"'waitForPendingWrites' promise is rejected due to a user change."))})}),t.ko.clear()}(r),r.sharedClientState.handleUserChange(n,i.removedBatchIds,i.addedBatchIds),[4,ks(r,i.Ln)];case 2:e.sent(),e.label=3;case 3:return[2]}})})}function Rs(t,e){var n=m(t),r=n.Co.get(e);if(r&&r.bo)return Ue().add(r.key);var i=Ue(),o=n.Vo.get(e);if(!o)return i;for(var s=0,a=o;s<a.length;s++){var u=a[s],c=n.Po.get(u);i=i.unionWith(c.view.wo)}return i}function Ls(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,ki((r=m(t)).localStore,n.query,!0)];case 1:return i=e.sent(),o=n.view.Ao(i),[2,(r.isPrimaryClient&&Ds(r,n.targetId,o.To),o)]}})})}function Os(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){return[2,Ri((n=m(t)).localStore).then(function(t){return ks(n,t)})]})})}function Ps(t,n,r,i){return(0,e.__awaiter)(this,void 0,void 0,function(){var o,s;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,function(t,e){var n=m(t),r=m(n._n);return n.persistence.runTransaction("Lookup mutation documents","readonly",function(t){return r.jt(t,e).next(function(e){return e?n.Mn.pn(t,e):nr.resolve(null)})})}((o=m(t)).localStore,n)];case 1:return null===(s=e.sent())?[3,6]:"pending"!==r?[3,3]:[4,Oo(o.remoteStore)];case 2:return e.sent(),[3,4];case 3:"acknowledged"===r||"rejected"===r?(Ts(o,n,i||null),Es(o,n),function(t,e){m(m(t)._n).Gt(e)}(o.localStore,n)):y(),e.label=4;case 4:return[4,ks(o,s)];case 5:return e.sent(),[3,7];case 6:f("SyncEngine","Cannot apply mutation batch with id: "+n),e.label=7;case 7:return[2]}})})}function Fs(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o,s,a,u,c,h;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return js(r=m(t)),Ks(r),!0!==n||!0===r.$o?[3,3]:(i=r.sharedClientState.getAllActiveQueryTargets(),[4,Ms(r,i.toArray())]);case 1:return o=e.sent(),r.$o=!0,[4,Bo(r.remoteStore,!0)];case 2:for(e.sent(),s=0,a=o;s<a.length;s++)u=a[s],bo(r.remoteStore,u);return[3,7];case 3:return!1!==n||!1===r.$o?[3,7]:(c=[],h=Promise.resolve(),r.Vo.forEach(function(t,e){r.sharedClientState.isLocalQueryTarget(e)?c.push(e):h=h.then(function(){return Ss(r,e),xi(r.localStore,e,!0)}),Io(r.remoteStore,e)}),[4,h]);case 4:return e.sent(),[4,Ms(r,c)];case 5:return e.sent(),function(t){var e=m(r);e.Co.forEach(function(t,n){Io(e.remoteStore,n)}),e.No.ts(),e.Co=new Map,e.Do=new Ae(Q.comparator)}(),r.$o=!1,[4,Bo(r.remoteStore,!1)];case 6:e.sent(),e.label=7;case 7:return[2]}})})}function Ms(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o,s,a,u,c,h,f,l,d,p,y,v;return(0,e.__generator)(this,function(e){switch(e.label){case 0:r=m(t),i=[],o=[],s=0,a=n,e.label=1;case 1:return s<a.length?(u=a[s],c=void 0,(h=r.Vo.get(u))&&0!==h.length?[4,Ai(r.localStore,Mt(h[0]))]:[3,7]):[3,13];case 2:c=e.sent(),f=0,l=h,e.label=3;case 3:return f<l.length?(d=l[f],p=r.Po.get(d),[4,Ls(r,p)]):[3,6];case 4:(y=e.sent()).snapshot&&o.push(y.snapshot),e.label=5;case 5:return f++,[3,3];case 6:return[3,11];case 7:return[4,Ci(r.localStore,u)];case 8:return v=e.sent(),[4,Ai(r.localStore,v)];case 9:return c=e.sent(),[4,ps(r,Vs(v),u,!1)];case 10:e.sent(),e.label=11;case 11:i.push(c),e.label=12;case 12:return s++,[3,1];case 13:return[2,(r.vo._r(o),i)]}})})}function Vs(t){return xt(t.path,t.collectionGroup,t.orderBy,t.filters,t.limit,"F",t.startAt,t.endAt)}function qs(t){var e=m(t);return m(m(e.localStore).persistence).fn()}function Us(t,n,r,i){return(0,e.__awaiter)(this,void 0,void 0,function(){var o,s,a;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return(o=m(t)).$o?(f("SyncEngine","Ignoring unexpected query state notification."),[3,8]):[3,1];case 1:if(!o.Vo.has(n))return[3,8];switch(r){case"current":case"not-current":return[3,2];case"rejected":return[3,5]}return[3,7];case 2:return[4,Ri(o.localStore)];case 3:return s=e.sent(),a=Ke.createSynthesizedRemoteEventForCurrentChange(n,"current"===r),[4,ks(o,s,a)];case 4:return e.sent(),[3,8];case 5:return[4,xi(o.localStore,n,!0)];case 6:return e.sent(),Ss(o,n,i),[3,8];case 7:y(),e.label=8;case 8:return[2]}})})}function Bs(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o,s,a,u,c,h,l,d,p;return(0,e.__generator)(this,function(y){switch(y.label){case 0:if(!(i=js(t)).$o)return[3,10];o=0,s=n,y.label=1;case 1:return o<s.length?(a=s[o],i.Vo.has(a)?(f("SyncEngine","Adding an already active target "+a),[3,5]):[4,Ci(i.localStore,a)]):[3,6];case 2:return u=y.sent(),[4,Ai(i.localStore,u)];case 3:return c=y.sent(),[4,ps(i,Vs(u),c.targetId,!1)];case 4:y.sent(),bo(i.remoteStore,c),y.label=5;case 5:return o++,[3,1];case 6:h=function(t){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return i.Vo.has(t)?[4,xi(i.localStore,t,!1).then(function(){Io(i.remoteStore,t),Ss(i,t)}).catch(Yr)]:[3,2];case 1:e.sent(),e.label=2;case 2:return[2]}})},l=0,d=r,y.label=7;case 7:return l<d.length?(p=d[l],[5,h(p)]):[3,10];case 8:y.sent(),y.label=9;case 9:return l++,[3,7];case 10:return[2]}})})}function js(t){var e=m(t);return e.remoteStore.remoteSyncer.applyRemoteEvent=ms.bind(null,e),e.remoteStore.remoteSyncer.getRemoteKeysForTarget=Rs.bind(null,e),e.remoteStore.remoteSyncer.rejectListen=_s.bind(null,e),e.vo._r=Zo.bind(null,e.eventManager),e.vo.Mo=ts.bind(null,e.eventManager),e}function Ks(t){var e=m(t);return e.remoteStore.remoteSyncer.applySuccessfulWrite=ws.bind(null,e),e.remoteStore.remoteSyncer.rejectFailedWrite=bs.bind(null,e),e}function Qs(t,n,r){var i=m(t);(function(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o,s,a,u,c;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return e.trys.push([0,14,,15]),[4,n.getMetadata()];case 1:return i=e.sent(),[4,function(t,e){var n=m(t),r=on(e.createTime);return n.persistence.runTransaction("hasNewerBundle","readonly",function(t){return n.Ke.getBundleMetadata(t,e.id)}).then(function(t){return!!t&&t.createTime.compareTo(r)>=0})}(t.localStore,i)];case 2:return e.sent()?[4,n.close()]:[3,4];case 3:return[2,(e.sent(),void r._completeWith(function(t){return{taskState:"Success",documentsLoaded:t.totalDocuments,bytesLoaded:t.totalBytes,totalDocuments:t.totalDocuments,totalBytes:t.totalBytes}}(i)))];case 4:return r._updateProgress(ss(i)),o=new os(i,t.localStore,n.R),[4,n.Lo()];case 5:s=e.sent(),e.label=6;case 6:return s?[4,o.oo(s)]:[3,10];case 7:return(a=e.sent())&&r._updateProgress(a),[4,n.Lo()];case 8:s=e.sent(),e.label=9;case 9:return[3,6];case 10:return[4,o.complete()];case 11:return u=e.sent(),[4,ks(t,u.wn,void 0)];case 12:return e.sent(),[4,function(t,e){var n=m(t);return n.persistence.runTransaction("Save bundle","readwrite",function(t){return n.Ke.saveBundleMetadata(t,e)})}(t.localStore,i)];case 13:return e.sent(),r._completeWith(u.progress),[3,15];case 14:return d("SyncEngine","Loading bundle failed with "+(c=e.sent())),r._failWith(c),[3,15];case 15:return[2]}})})})(i,n,r).then(function(){i.sharedClientState.notifyBundleLoaded()})}var Gs=function(){function t(){this.synchronizeTabs=!1}return t.prototype.initialize=function(t){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return this.R=ho(t.databaseInfo.databaseId),this.sharedClientState=this.Bo(t),this.persistence=this.qo(t),[4,this.persistence.start()];case 1:return e.sent(),this.gcScheduler=this.Uo(t),this.localStore=this.Ko(t),[2]}})})},t.prototype.Uo=function(t){return null},t.prototype.Ko=function(t){return bi(this.persistence,new _i,t.initialUser,this.R)},t.prototype.qo=function(t){return new Ki(Gi.bs,this.R)},t.prototype.Bo=function(t){return new no},t.prototype.terminate=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(t){switch(t.label){case 0:return this.gcScheduler&&this.gcScheduler.stop(),[4,this.sharedClientState.shutdown()];case 1:return t.sent(),[4,this.persistence.shutdown()];case 2:return t.sent(),[2]}})})},t}(),zs=function(t){function n(e,n,r){var i=this;return(i=t.call(this)||this).Qo=e,i.cacheSizeBytes=n,i.forceOwnership=r,i.synchronizeTabs=!1,i}return(0,e.__extends)(n,t),n.prototype.initialize=function(n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r=this;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,t.prototype.initialize.call(this,n)];case 1:return e.sent(),[4,Li(this.localStore)];case 2:return e.sent(),[4,this.Qo.initialize(this,n)];case 3:return e.sent(),[4,Ks(this.Qo.syncEngine)];case 4:return e.sent(),[4,Oo(this.Qo.remoteStore)];case 5:return e.sent(),[4,this.persistence.He(function(){return r.gcScheduler&&!r.gcScheduler.started&&r.gcScheduler.start(r.localStore),Promise.resolve()})];case 6:return e.sent(),[2]}})})},n.prototype.Ko=function(t){return bi(this.persistence,new _i,t.initialUser,this.R)},n.prototype.Uo=function(t){var e=this.persistence.referenceDelegate.garbageCollector;return new Jr(e,t.asyncQueue)},n.prototype.qo=function(t){var e=yi(t.databaseInfo.databaseId,t.databaseInfo.persistenceKey),n=void 0!==this.cacheSizeBytes?Fr.withCacheSize(this.cacheSizeBytes):Fr.DEFAULT;return new li(this.synchronizeTabs,e,t.clientId,n,t.asyncQueue,uo(),co(),this.R,this.sharedClientState,!!this.forceOwnership)},n.prototype.Bo=function(t){return new no},n}(Gs),Ws=function(t){function n(e,n){var r=this;return(r=t.call(this,e,n,!1)||this).Qo=e,r.cacheSizeBytes=n,r.synchronizeTabs=!0,r}return(0,e.__extends)(n,t),n.prototype.initialize=function(n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i=this;return(0,e.__generator)(this,function(o){switch(o.label){case 0:return[4,t.prototype.initialize.call(this,n)];case 1:return o.sent(),r=this.Qo.syncEngine,this.sharedClientState instanceof eo?(this.sharedClientState.syncEngine={ui:Ps.bind(null,r),ai:Us.bind(null,r),hi:Bs.bind(null,r),fn:qs.bind(null,r),ci:Os.bind(null,r)},[4,this.sharedClientState.start()]):[3,3];case 2:o.sent(),o.label=3;case 3:return[4,this.persistence.He(function(t){return(0,e.__awaiter)(i,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,Fs(this.Qo.syncEngine,t)];case 1:return e.sent(),this.gcScheduler&&(t&&!this.gcScheduler.started?this.gcScheduler.start(this.localStore):t||this.gcScheduler.stop()),[2]}})})})];case 4:return o.sent(),[2]}})})},n.prototype.Bo=function(t){var e=uo();if(!eo.yt(e))throw new u(a.UNIMPLEMENTED,"IndexedDB persistence is only available on platforms that support LocalStorage.");var n=yi(t.databaseInfo.databaseId,t.databaseInfo.persistenceKey);return new eo(e,t.asyncQueue,n,t.clientId,t.initialUser)},n}(zs),Hs=function(){function t(){}return t.prototype.initialize=function(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r=this;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return this.localStore?[3,2]:(this.localStore=t.localStore,this.sharedClientState=t.sharedClientState,this.datastore=this.createDatastore(n),this.remoteStore=this.createRemoteStore(n),this.eventManager=this.createEventManager(n),this.syncEngine=this.createSyncEngine(n,!t.synchronizeTabs),this.sharedClientState.onlineStateHandler=function(t){return gs(r.syncEngine,t,1)},this.remoteStore.remoteSyncer.handleCredentialChange=Cs.bind(null,this.syncEngine),[4,Bo(this.remoteStore,this.syncEngine.isPrimaryClient)]);case 1:e.sent(),e.label=2;case 2:return[2]}})})},t.prototype.createEventManager=function(t){return new $o},t.prototype.createDatastore=function(t){var e,n=ho(t.databaseInfo.databaseId),r=(e=t.databaseInfo,new ao(e));return function(t,e,n){return new vo(t,r,n)}(t.credentials,0,n)},t.prototype.createRemoteStore=function(t){var e,n,r,i,o,s=this;return e=this.localStore,n=this.datastore,r=t.asyncQueue,i=function(t){return gs(s.syncEngine,t,0)},o=io.yt()?new io:new ro,new go(e,n,r,i,o)},t.prototype.createSyncEngine=function(t,e){return function(t,e,n,r,i,o,s){var a=new ls(t,e,n,r,i,o);return s&&(a.$o=!0),a}(this.localStore,this.remoteStore,this.eventManager,this.sharedClientState,t.initialUser,t.maxConcurrentLimboResolutions,e)},t.prototype.terminate=function(){return function(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return n=m(t),f("RemoteStore","RemoteStore shutting down."),n.Or.add(5),[4,wo(n)];case 1:return e.sent(),n.Lr.shutdown(),n.Br.set("Unknown"),[2]}})})}(this.remoteStore)},t}();function Ys(t,n){void 0===n&&(n=10240);var r=0;return{read:function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var i;return(0,e.__generator)(this,function(e){return r<t.byteLength?(i={value:t.slice(r,r+n),done:!1},[2,(r+=n,i)]):[2,{done:!0}]})})},cancel:function(){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(t){return[2]})})},releaseLock:function(){},closed:Promise.reject("unimplemented")}}var $s=function(){function t(t){this.observer=t,this.muted=!1}return t.prototype.next=function(t){this.observer.next&&this.jo(this.observer.next,t)},t.prototype.error=function(t){this.observer.error?this.jo(this.observer.error,t):console.error("Uncaught Error in snapshot listener:",t)},t.prototype.Wo=function(){this.muted=!0},t.prototype.jo=function(t,e){var n=this;this.muted||setTimeout(function(){n.muted||t(e)},0)},t}(),Xs=function(){function t(t,e){var n=this;this.Go=t,this.R=e,this.metadata=new er,this.buffer=new Uint8Array,this.zo=new TextDecoder("utf-8"),this.Ho().then(function(t){t&&t.io()?n.metadata.resolve(t.payload.metadata):n.metadata.reject(new Error("The first element of the bundle is not a metadata, it is\n "+JSON.stringify(null==t?void 0:t.payload)))},function(t){return n.metadata.reject(t)})}return t.prototype.close=function(){return this.Go.cancel()},t.prototype.getMetadata=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(t){return[2,this.metadata.promise]})})},t.prototype.Lo=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(t){switch(t.label){case 0:return[4,this.getMetadata()];case 1:return[2,(t.sent(),this.Ho())]}})})},t.prototype.Ho=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var t,n,r,i;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,this.Jo()];case 1:return null===(t=e.sent())?[2,null]:(n=this.zo.decode(t),r=Number(n),isNaN(r)&&this.Yo("length string ("+n+") is not valid number"),[4,this.Xo(r)]);case 2:return i=e.sent(),[2,new rs(JSON.parse(i),t.length+r)]}})})},t.prototype.Zo=function(){return this.buffer.findIndex(function(t){return t==="{".charCodeAt(0)})},t.prototype.Jo=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var t,n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return this.Zo()<0?[4,this.tc()]:[3,3];case 1:if(e.sent())return[3,3];e.label=2;case 2:return[3,0];case 3:return 0===this.buffer.length?[2,null]:((t=this.Zo())<0&&this.Yo("Reached the end of bundle when a length string is expected."),n=this.buffer.slice(0,t),[2,(this.buffer=this.buffer.slice(t),n)])}})})},t.prototype.Xo=function(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return this.buffer.length<t?[4,this.tc()]:[3,3];case 1:e.sent()&&this.Yo("Reached the end of bundle when more is expected."),e.label=2;case 2:return[3,0];case 3:return n=this.zo.decode(this.buffer.slice(0,t)),[2,(this.buffer=this.buffer.slice(t),n)]}})})},t.prototype.Yo=function(t){throw this.Go.cancel(),new Error("Invalid bundle format: "+t)},t.prototype.tc=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var t,n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,this.Go.read()];case 1:return(t=e.sent()).done||((n=new Uint8Array(this.buffer.length+t.value.length)).set(this.buffer),n.set(t.value,this.buffer.length),this.buffer=n),[2,t.done]}})})},t}(),Js=function(){function t(t){this.datastore=t,this.readVersions=new Map,this.mutations=[],this.committed=!1,this.lastWriteError=null,this.writtenDocs=new Set}return t.prototype.lookup=function(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n,r=this;return(0,e.__generator)(this,function(i){switch(i.label){case 0:if(this.ensureCommitNotCalled(),this.mutations.length>0)throw new u(a.INVALID_ARGUMENT,"Firestore transactions require all reads to be executed before all writes.");return[4,function(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o,s,a,u;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return r=m(t),i=ln(r.R)+"/documents",o={documents:n.map(function(t){return un(r.R,t)})},[4,r.$i("BatchGetDocuments",i,o)];case 1:return s=e.sent(),a=new Map,s.forEach(function(t){var e=function(t,e){return"found"in e?function(t,e){v(!!e.found),e.found.name,e.found.updateTime;var n=cn(t,e.found.name),r=on(e.found.updateTime),i=new ot({mapValue:{fields:e.found.fields}});return at.newFoundDocument(n,r,i)}(t,e):"missing"in e?function(t,e){v(!!e.missing),v(!!e.readTime);var n=cn(t,e.missing),r=on(e.readTime);return at.newNoDocument(n,r)}(t,e):y()}(r.R,t);a.set(e.key.toString(),e)}),u=[],[2,(n.forEach(function(t){var e=a.get(t.toString());v(!!e),u.push(e)}),u)]}})})}(this.datastore,t)];case 1:return[2,((n=i.sent()).forEach(function(t){return r.recordVersion(t)}),n)]}})})},t.prototype.set=function(t,e){this.write(e.toMutation(t,this.precondition(t))),this.writtenDocs.add(t.toString())},t.prototype.update=function(t,e){try{this.write(e.toMutation(t,this.preconditionForUpdate(t)))}catch(t){this.lastWriteError=t}this.writtenDocs.add(t.toString())},t.prototype.delete=function(t){this.write(new Ee(t,this.precondition(t))),this.writtenDocs.add(t.toString())},t.prototype.commit=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var t,n=this;return(0,e.__generator)(this,function(r){switch(r.label){case 0:if(this.ensureCommitNotCalled(),this.lastWriteError)throw this.lastWriteError;return t=this.readVersions,this.mutations.forEach(function(e){t.delete(e.key.toString())}),t.forEach(function(t,e){var r=Q.fromPath(e);n.mutations.push(new Te(r,n.precondition(r)))}),[4,function(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return r=m(t),i=ln(r.R)+"/documents",o={writes:n.map(function(t){return vn(r.R,t)})},[4,r.Ni("Commit",i,o)];case 1:return e.sent(),[2]}})})}(this.datastore,this.mutations)];case 1:return r.sent(),this.committed=!0,[2]}})})},t.prototype.recordVersion=function(t){var e;if(t.isFoundDocument())e=t.version;else{if(!t.isNoDocument())throw y();e=T.min()}var n=this.readVersions.get(t.key.toString());if(n){if(!e.isEqual(n))throw new u(a.ABORTED,"Document version changed between two reads.")}else this.readVersions.set(t.key.toString(),e)},t.prototype.precondition=function(t){var e=this.readVersions.get(t.toString());return!this.writtenDocs.has(t.toString())&&e?ue.updateTime(e):ue.none()},t.prototype.preconditionForUpdate=function(t){var e=this.readVersions.get(t.toString());if(!this.writtenDocs.has(t.toString())&&e){if(e.isEqual(T.min()))throw new u(a.INVALID_ARGUMENT,"Can't update a document that doesn't exist.");return ue.updateTime(e)}return ue.exists(!0)},t.prototype.write=function(t){this.ensureCommitNotCalled(),this.mutations.push(t)},t.prototype.ensureCommitNotCalled=function(){},t}(),Zs=function(){function t(t,e,n,r){this.asyncQueue=t,this.datastore=e,this.updateFunction=n,this.deferred=r,this.ec=5,this.Zi=new fo(this.asyncQueue,"transaction_retry")}return t.prototype.run=function(){this.ec-=1,this.nc()},t.prototype.nc=function(){var t=this;this.Zi.ji(function(){return(0,e.__awaiter)(t,void 0,void 0,function(){var t,n,r=this;return(0,e.__generator)(this,function(e){return t=new Js(this.datastore),(n=this.sc(t))&&n.then(function(e){r.asyncQueue.enqueueAndForget(function(){return t.commit().then(function(){r.deferred.resolve(e)}).catch(function(t){r.ic(t)})})}).catch(function(t){r.ic(t)}),[2]})})})},t.prototype.sc=function(t){try{var e=this.updateFunction(t);return!B(e)&&e.catch&&e.then?e:(this.deferred.reject(Error("Transaction callback must return a Promise")),null)}catch(t){return this.deferred.reject(t),null}},t.prototype.ic=function(t){var e=this;this.ec>0&&this.rc(t)?(this.ec-=1,this.asyncQueue.enqueueAndForget(function(){return e.nc(),Promise.resolve()})):this.deferred.reject(t)},t.prototype.rc=function(t){if("FirebaseError"===t.name){var e=t.code;return"aborted"===e||"failed-precondition"===e||!Ne(e)}return!1},t}(),ta=function(){function t(t,n,r){var i=this;this.credentials=t,this.asyncQueue=n,this.databaseInfo=r,this.user=zi.UNAUTHENTICATED,this.clientId=_.u(),this.credentialListener=function(){return Promise.resolve()},this.credentials.setChangeListener(n,function(t){return(0,e.__awaiter)(i,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return f("FirestoreClient","Received user=",t.uid),[4,this.credentialListener(t)];case 1:return e.sent(),this.user=t,[2]}})})})}return t.prototype.getConfiguration=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(t){return[2,{asyncQueue:this.asyncQueue,databaseInfo:this.databaseInfo,clientId:this.clientId,credentials:this.credentials,initialUser:this.user,maxConcurrentLimboResolutions:100}]})})},t.prototype.setCredentialChangeListener=function(t){this.credentialListener=t},t.prototype.verifyNotTerminated=function(){if(this.asyncQueue.isShuttingDown)throw new u(a.FAILED_PRECONDITION,"The client has already been terminated.")},t.prototype.terminate=function(){var t=this;this.asyncQueue.enterRestrictedMode();var n=new er;return this.asyncQueue.enqueueAndForgetEvenWhileRestricted(function(){return(0,e.__awaiter)(t,void 0,void 0,function(){var t,r;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return e.trys.push([0,5,,6]),this.onlineComponents?[4,this.onlineComponents.terminate()]:[3,2];case 1:e.sent(),e.label=2;case 2:return this.offlineComponents?[4,this.offlineComponents.terminate()]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.credentials.removeChangeListener(),n.resolve(),[3,6];case 5:return t=e.sent(),r=Go(t,"Failed to shutdown persistence"),n.reject(r),[3,6];case 6:return[2]}})})}),n.promise},t}();function ea(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o=this;return(0,e.__generator)(this,function(s){switch(s.label){case 0:return t.asyncQueue.verifyOperationInProgress(),f("FirestoreClient","Initializing OfflineComponentProvider"),[4,t.getConfiguration()];case 1:return r=s.sent(),[4,n.initialize(r)];case 2:return s.sent(),i=r.initialUser,t.setCredentialChangeListener(function(t){return(0,e.__awaiter)(o,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return i.isEqual(t)?[3,2]:[4,Ii(n.localStore,t)];case 1:e.sent(),i=t,e.label=2;case 2:return[2]}})})}),n.persistence.setDatabaseDeletedListener(function(){return t.terminate()}),t.offlineComponents=n,[2]}})})}function na(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i;return(0,e.__generator)(this,function(o){switch(o.label){case 0:return t.asyncQueue.verifyOperationInProgress(),[4,ra(t)];case 1:return r=o.sent(),f("FirestoreClient","Initializing OnlineComponentProvider"),[4,t.getConfiguration()];case 2:return i=o.sent(),[4,n.initialize(r,i)];case 3:return o.sent(),t.setCredentialChangeListener(function(t){return function(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return(r=m(t)).asyncQueue.verifyOperationInProgress(),f("RemoteStore","RemoteStore received new credentials"),i=Do(r),r.Or.add(3),[4,wo(r)];case 1:return e.sent(),i&&r.Br.set("Unknown"),[4,r.remoteSyncer.handleCredentialChange(n)];case 2:return e.sent(),r.Or.delete(3),[4,_o(r)];case 3:return e.sent(),[2]}})})}(n.remoteStore,t)}),t.onlineComponents=n,[2]}})})}function ra(t){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return t.offlineComponents?[3,2]:(f("FirestoreClient","Using default OfflineComponentProvider"),[4,ea(t,new Gs)]);case 1:e.sent(),e.label=2;case 2:return[2,t.offlineComponents]}})})}function ia(t){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return t.onlineComponents?[3,2]:(f("FirestoreClient","Using default OnlineComponentProvider"),[4,na(t,new Hs)]);case 1:e.sent(),e.label=2;case 2:return[2,t.onlineComponents]}})})}function oa(t){return ra(t).then(function(t){return t.persistence})}function sa(t){return ra(t).then(function(t){return t.localStore})}function aa(t){return ia(t).then(function(t){return t.remoteStore})}function ua(t){return ia(t).then(function(t){return t.syncEngine})}function ca(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n,r;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,ia(t)];case 1:return n=e.sent(),[2,((r=n.eventManager).onListen=ds.bind(null,n.syncEngine),r.onUnlisten=ys.bind(null,n.syncEngine),r)]}})})}function ha(t,n,r){var i=this;void 0===r&&(r={});var o=new er;return t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(i,void 0,void 0,function(){var i;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return i=function(t,e,n,r,i){var o=new $s({next:function(o){e.enqueueAndForget(function(){return Jo(t,s)});var c=o.docs.has(n);!c&&o.fromCache?i.reject(new u(a.UNAVAILABLE,"Failed to get document because the client is offline.")):c&&o.fromCache&&r&&"server"===r.source?i.reject(new u(a.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.)')):i.resolve(o)},error:function(t){return i.reject(t)}}),s=new ns(kt(n.path),o,{includeMetadataChanges:!0,so:!0});return Xo(t,s)},[4,ca(t)];case 1:return[2,i.apply(void 0,[e.sent(),t.asyncQueue,n,r,o])]}})})}),o.promise}function fa(t,n,r){var i=this;void 0===r&&(r={});var o=new er;return t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(i,void 0,void 0,function(){var i;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return i=function(t,e,n,r,i){var o=new $s({next:function(n){e.enqueueAndForget(function(){return Jo(t,s)}),n.fromCache&&"server"===r.source?i.reject(new u(a.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.)')):i.resolve(n)},error:function(t){return i.reject(t)}}),s=new ns(n,o,{includeMetadataChanges:!0,so:!0});return Xo(t,s)},[4,ca(t)];case 1:return[2,i.apply(void 0,[e.sent(),t.asyncQueue,n,r,o])]}})})}),o.promise}var la=function(t,e,n,r,i,o,s,a){this.databaseId=t,this.appId=e,this.persistenceKey=n,this.host=r,this.ssl=i,this.forceLongPolling=o,this.autoDetectLongPolling=s,this.useFetchStreams=a},da=function(){function t(t,e){this.projectId=t,this.database=e||"(default)"}return Object.defineProperty(t.prototype,"isDefaultDatabase",{get:function(){return"(default)"===this.database},enumerable:!1,configurable:!0}),t.prototype.isEqual=function(e){return e instanceof t&&e.projectId===this.projectId&&e.database===this.database},t}(),pa=new Map,ya=function(t,e){this.user=e,this.type="OAuth",this.authHeaders={},this.authHeaders.Authorization="Bearer "+t},va=function(){function t(){this.changeListener=null}return t.prototype.getToken=function(){return Promise.resolve(null)},t.prototype.invalidateToken=function(){},t.prototype.setChangeListener=function(t,e){this.changeListener=e,t.enqueueRetryable(function(){return e(zi.UNAUTHENTICATED)})},t.prototype.removeChangeListener=function(){this.changeListener=null},t}(),ma=function(){function t(t){this.token=t,this.changeListener=null}return t.prototype.getToken=function(){return Promise.resolve(this.token)},t.prototype.invalidateToken=function(){},t.prototype.setChangeListener=function(t,e){var n=this;this.changeListener=e,t.enqueueRetryable(function(){return e(n.token.user)})},t.prototype.removeChangeListener=function(){this.changeListener=null},t}(),ga=function(){function t(t){var e=this;this.currentUser=zi.UNAUTHENTICATED,this.oc=new er,this.cc=0,this.forceRefresh=!1,this.auth=null,this.asyncQueue=null,this.uc=function(){e.cc++,e.currentUser=e.ac(),e.oc.resolve(),e.changeListener&&e.asyncQueue.enqueueRetryable(function(){return e.changeListener(e.currentUser)})};var n=function(t){f("FirebaseCredentialsProvider","Auth detected"),e.auth=t,e.auth.addAuthTokenListener(e.uc)};t.onInit(function(t){return n(t)}),setTimeout(function(){if(!e.auth){var r=t.getImmediate({optional:!0});r?n(r):(f("FirebaseCredentialsProvider","Auth not yet detected"),e.oc.resolve())}},0)}return t.prototype.getToken=function(){var t=this,e=this.cc,n=this.forceRefresh;return this.forceRefresh=!1,this.auth?this.auth.getToken(n).then(function(n){return t.cc!==e?(f("FirebaseCredentialsProvider","getToken aborted due to token change."),t.getToken()):n?(v("string"==typeof n.accessToken),new ya(n.accessToken,t.currentUser)):null}):Promise.resolve(null)},t.prototype.invalidateToken=function(){this.forceRefresh=!0},t.prototype.setChangeListener=function(t,n){var r=this;this.asyncQueue=t,this.asyncQueue.enqueueRetryable(function(){return(0,e.__awaiter)(r,void 0,void 0,function(){return(0,e.__generator)(this,function(t){switch(t.label){case 0:return[4,this.oc.promise];case 1:return t.sent(),[4,n(this.currentUser)];case 2:return t.sent(),this.changeListener=n,[2]}})})})},t.prototype.removeChangeListener=function(){this.auth&&this.auth.removeAuthTokenListener(this.uc),this.changeListener=function(){return Promise.resolve()}},t.prototype.ac=function(){var t=this.auth&&this.auth.getUid();return v(null===t||"string"==typeof t),new zi(t)},t}(),_a=function(){function t(t,e,n){this.hc=t,this.lc=e,this.fc=n,this.type="FirstParty",this.user=zi.FIRST_PARTY}return Object.defineProperty(t.prototype,"authHeaders",{get:function(){var t={"X-Goog-AuthUser":this.lc},e=this.hc.auth.getAuthHeaderValueForFirstParty([]);return e&&(t.Authorization=e),this.fc&&(t["X-Goog-Iam-Authorization-Token"]=this.fc),t},enumerable:!1,configurable:!0}),t}(),wa=function(){function t(t,e,n){this.hc=t,this.lc=e,this.fc=n}return t.prototype.getToken=function(){return Promise.resolve(new _a(this.hc,this.lc,this.fc))},t.prototype.setChangeListener=function(t,e){t.enqueueRetryable(function(){return e(zi.FIRST_PARTY)})},t.prototype.removeChangeListener=function(){},t.prototype.invalidateToken=function(){},t}();function ba(t,e,n){if(!n)throw new u(a.INVALID_ARGUMENT,"Function "+t+"() cannot be called with an empty "+e+".")}function Ia(t,e){if(void 0===e)return{merge:!1};if(void 0!==e.mergeFields&&void 0!==e.merge)throw new u(a.INVALID_ARGUMENT,"Invalid options passed to function "+t+'(): You cannot specify both "merge" and "mergeFields".');return e}function Ea(t,e,n,r){if(!0===e&&!0===r)throw new u(a.INVALID_ARGUMENT,t+" and "+n+" cannot be used together.")}function Ta(t){if(!Q.isDocumentKey(t))throw new u(a.INVALID_ARGUMENT,"Invalid document reference. Document references must have an even number of segments, but "+t+" has "+t.length+".")}function Sa(t){if(Q.isDocumentKey(t))throw new u(a.INVALID_ARGUMENT,"Invalid collection reference. Collection references must have an odd number of segments, but "+t+" has "+t.length+".")}function Na(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"==o(t)){if(t instanceof Array)return"an array";var e=function(t){if(t.constructor){var e=/function\s+([^\s(]+)\s*\(/.exec(t.constructor.toString());if(e&&e.length>1)return e[1]}return null}(t);return e?"a custom "+e+" object":"an object"}return"function"==typeof t?"a function":y()}function Da(t,e){if("_delegate"in t&&(t=t._delegate),!(t instanceof e)){if(e.name===t.constructor.name)throw new u(a.INVALID_ARGUMENT,"Type does not match the expected instance. Did you pass a reference from a different Firestore SDK?");var n=Na(t);throw new u(a.INVALID_ARGUMENT,"Expected type '"+e.name+"', but it was: "+n)}return t}function Aa(t,e){if(e<=0)throw new u(a.INVALID_ARGUMENT,"Function "+t+"() requires a positive number, but it was: "+e+".")}var xa=function(){function t(t){var e;if(void 0===t.host){if(void 0!==t.ssl)throw new u(a.INVALID_ARGUMENT,"Can't provide ssl option if host option is not set");this.host="firestore.googleapis.com",this.ssl=!0}else this.host=t.host,this.ssl=null===(e=t.ssl)||void 0===e||e;if(this.credentials=t.credentials,this.ignoreUndefinedProperties=!!t.ignoreUndefinedProperties,void 0===t.cacheSizeBytes)this.cacheSizeBytes=41943040;else{if(-1!==t.cacheSizeBytes&&t.cacheSizeBytes<1048576)throw new u(a.INVALID_ARGUMENT,"cacheSizeBytes must be at least 1048576");this.cacheSizeBytes=t.cacheSizeBytes}this.experimentalForceLongPolling=!!t.experimentalForceLongPolling,this.experimentalAutoDetectLongPolling=!!t.experimentalAutoDetectLongPolling,this.useFetchStreams=!!t.useFetchStreams,Ea("experimentalForceLongPolling",t.experimentalForceLongPolling,"experimentalAutoDetectLongPolling",t.experimentalAutoDetectLongPolling)}return t.prototype.isEqual=function(t){return this.host===t.host&&this.ssl===t.ssl&&this.credentials===t.credentials&&this.cacheSizeBytes===t.cacheSizeBytes&&this.experimentalForceLongPolling===t.experimentalForceLongPolling&&this.experimentalAutoDetectLongPolling===t.experimentalAutoDetectLongPolling&&this.ignoreUndefinedProperties===t.ignoreUndefinedProperties&&this.useFetchStreams===t.useFetchStreams},t}(),ka=function(){function t(t,e){this.type="firestore-lite",this._persistenceKey="(lite)",this._settings=new xa({}),this._settingsFrozen=!1,t instanceof da?(this._databaseId=t,this._credentials=new va):(this._app=t,this._databaseId=function(t){if(!Object.prototype.hasOwnProperty.apply(t.options,["projectId"]))throw new u(a.INVALID_ARGUMENT,'"projectId" not provided in firebase.initializeApp.');return new da(t.options.projectId)}(t),this._credentials=new ga(e))}return Object.defineProperty(t.prototype,"app",{get:function(){if(!this._app)throw new u(a.FAILED_PRECONDITION,"Firestore was not initialized using the Firebase SDK. 'app' is not available");return this._app},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"_initialized",{get:function(){return this._settingsFrozen},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"_terminated",{get:function(){return void 0!==this._terminateTask},enumerable:!1,configurable:!0}),t.prototype._setSettings=function(t){if(this._settingsFrozen)throw new u(a.FAILED_PRECONDITION,"Firestore has already been started and its settings can no longer be changed. You can only modify settings before calling any other methods on a Firestore object.");this._settings=new xa(t),void 0!==t.credentials&&(this._credentials=function(t){if(!t)return new va;switch(t.type){case"gapi":var e=t.client;return v(!("object"!=o(e)||null===e||!e.auth||!e.auth.getAuthHeaderValueForFirstParty)),new wa(e,t.sessionIndex||"0",t.iamToken||null);case"provider":return t.client;default:throw new u(a.INVALID_ARGUMENT,"makeCredentialsProvider failed due to invalid credential type")}}(t.credentials))},t.prototype._getSettings=function(){return this._settings},t.prototype._freezeSettings=function(){return this._settingsFrozen=!0,this._settings},t.prototype._delete=function(){return this._terminateTask||(this._terminateTask=this._terminate()),this._terminateTask},t.prototype.toJSON=function(){return{app:this._app,databaseId:this._databaseId,settings:this._settings}},t.prototype._terminate=function(){return this,(t=pa.get(this))&&(f("ComponentProvider","Removing Datastore"),pa.delete(this),t.terminate()),Promise.resolve();var t},t}(),Ca=function(){function t(t,e,n){this.converter=e,this._key=n,this.type="document",this.firestore=t}return Object.defineProperty(t.prototype,"_path",{get:function(){return this._key.path},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"id",{get:function(){return this._key.path.lastSegment()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"path",{get:function(){return this._key.path.canonicalString()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"parent",{get:function(){return new La(this.firestore,this.converter,this._key.path.popLast())},enumerable:!1,configurable:!0}),t.prototype.withConverter=function(e){return new t(this.firestore,e,this._key)},t}(),Ra=function(){function t(t,e,n){this.converter=e,this._query=n,this.type="query",this.firestore=t}return t.prototype.withConverter=function(e){return new t(this.firestore,e,this._query)},t}(),La=function(t){function n(e,n,r){var i=this;return(i=t.call(this,e,n,kt(r))||this)._path=r,i.type="collection",i}return(0,e.__extends)(n,t),Object.defineProperty(n.prototype,"id",{get:function(){return this._query.path.lastSegment()},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"path",{get:function(){return this._query.path.canonicalString()},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"parent",{get:function(){var t=this._path.popLast();return t.isEmpty()?null:new Ca(this.firestore,null,new Q(t))},enumerable:!1,configurable:!0}),n.prototype.withConverter=function(t){return new n(this.firestore,t,this._path)},n}(Ra);function Oa(t,r){for(var i,o=[],s=2;s<arguments.length;s++)o[s-2]=arguments[s];if(t=(0,n.getModularInstance)(t),ba("collection","path",r),t instanceof ka)return Sa(i=x.fromString.apply(x,(0,e.__spreadArray)([r],o))),new La(t,null,i);if(!(t instanceof Ca||t instanceof La))throw new u(a.INVALID_ARGUMENT,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");return Sa(i=x.fromString.apply(x,(0,e.__spreadArray)([t.path],o)).child(x.fromString(r))),new La(t.firestore,null,i)}function Pa(t,r){for(var i,o=[],s=2;s<arguments.length;s++)o[s-2]=arguments[s];if(t=(0,n.getModularInstance)(t),1===arguments.length&&(r=_.u()),ba("doc","path",r),t instanceof ka)return Ta(i=x.fromString.apply(x,(0,e.__spreadArray)([r],o))),new Ca(t,null,new Q(i));if(!(t instanceof Ca||t instanceof La))throw new u(a.INVALID_ARGUMENT,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");return Ta(i=t._path.child(x.fromString.apply(x,(0,e.__spreadArray)([r],o)))),new Ca(t.firestore,t instanceof La?t.converter:null,new Q(i))}function Fa(t,e){return t=(0,n.getModularInstance)(t),e=(0,n.getModularInstance)(e),(t instanceof Ca||t instanceof La)&&(e instanceof Ca||e instanceof La)&&t.firestore===e.firestore&&t.path===e.path&&t.converter===e.converter}function Ma(t,e){return t=(0,n.getModularInstance)(t),e=(0,n.getModularInstance)(e),t instanceof Ra&&e instanceof Ra&&t.firestore===e.firestore&&qt(t._query,e._query)&&t.converter===e.converter}var Va=function(){function t(){var t=this;this.dc=Promise.resolve(),this.wc=[],this._c=!1,this.mc=[],this.yc=null,this.gc=!1,this.Ec=!1,this.Tc=[],this.Zi=new fo(this,"async_queue_retry"),this.Ic=function(){var e=co();e&&f("AsyncQueue","Visibility state changed to "+e.visibilityState),t.Zi.Gi()};var e=co();e&&"function"==typeof e.addEventListener&&e.addEventListener("visibilitychange",this.Ic)}return Object.defineProperty(t.prototype,"isShuttingDown",{get:function(){return this._c},enumerable:!1,configurable:!0}),t.prototype.enqueueAndForget=function(t){this.enqueue(t)},t.prototype.enqueueAndForgetEvenWhileRestricted=function(t){this.Ac(),this.Rc(t)},t.prototype.enterRestrictedMode=function(t){if(!this._c){this._c=!0,this.Ec=t||!1;var e=co();e&&"function"==typeof e.removeEventListener&&e.removeEventListener("visibilitychange",this.Ic)}},t.prototype.enqueue=function(t){var e=this;if(this.Ac(),this._c)return new Promise(function(){});var n=new er;return this.Rc(function(){return e._c&&e.Ec?Promise.resolve():(t().then(n.resolve,n.reject),n.promise)}).then(function(){return n.promise})},t.prototype.enqueueRetryable=function(t){var e=this;this.enqueueAndForget(function(){return e.wc.push(t),e.bc()})},t.prototype.bc=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var t,n=this;return(0,e.__generator)(this,function(e){switch(e.label){case 0:if(0===this.wc.length)return[3,5];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.wc[0]()];case 2:return e.sent(),this.wc.shift(),this.Zi.reset(),[3,4];case 3:if(!ar(t=e.sent()))throw t;return f("AsyncQueue","Operation failed with retryable error: "+t),[3,4];case 4:this.wc.length>0&&this.Zi.ji(function(){return n.bc()}),e.label=5;case 5:return[2]}})})},t.prototype.Rc=function(t){var e=this,n=this.dc.then(function(){return e.gc=!0,t().catch(function(t){throw e.yc=t,e.gc=!1,l("INTERNAL UNHANDLED ERROR: ",function(t){var e=t.message||"";return t.stack&&(e=t.stack.includes(t.message)?t.stack:t.message+"\n"+t.stack),e}(t)),t}).then(function(t){return e.gc=!1,t})});return this.dc=n,n},t.prototype.enqueueAfterDelay=function(t,e,n){var r=this;this.Ac(),this.Tc.indexOf(t)>-1&&(e=0);var i=Qo.createAndSchedule(this,t,e,n,function(t){return r.vc(t)});return this.mc.push(i),i},t.prototype.Ac=function(){this.yc&&y()},t.prototype.verifyOperationInProgress=function(){},t.prototype.Pc=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var t;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,t=this.dc];case 1:e.sent(),e.label=2;case 2:if(t!==this.dc)return[3,0];e.label=3;case 3:return[2]}})})},t.prototype.Vc=function(t){for(var e=0,n=this.mc;e<n.length;e++)if(n[e].timerId===t)return!0;return!1},t.prototype.Sc=function(t){var e=this;return this.Pc().then(function(){e.mc.sort(function(t,e){return t.targetTimeMs-e.targetTimeMs});for(var n=0,r=e.mc;n<r.length;n++){var i=r[n];if(i.skipDelay(),"all"!==t&&i.timerId===t)break}return e.Pc()})},t.prototype.Dc=function(t){this.Tc.push(t)},t.prototype.vc=function(t){var e=this.mc.indexOf(t);this.mc.splice(e,1)},t}();function qa(t){return function(t,e){if("object"!=o(t)||null===t)return!1;for(var n=t,r=0,i=["next","error","complete"];r<i.length;r++){var s=i[r];if(s in n&&"function"==typeof n[s])return!0}return!1}(t)}var Ua=function(){function t(){this._progressObserver={},this._taskCompletionResolver=new er,this._lastProgress={taskState:"Running",totalBytes:0,totalDocuments:0,bytesLoaded:0,documentsLoaded:0}}return t.prototype.onProgress=function(t,e,n){this._progressObserver={next:t,error:e,complete:n}},t.prototype.catch=function(t){return this._taskCompletionResolver.promise.catch(t)},t.prototype.then=function(t,e){return this._taskCompletionResolver.promise.then(t,e)},t.prototype._completeWith=function(t){this._updateProgress(t),this._progressObserver.complete&&this._progressObserver.complete(),this._taskCompletionResolver.resolve(t)},t.prototype._failWith=function(t){this._lastProgress.taskState="Error",this._progressObserver.next&&this._progressObserver.next(this._lastProgress),this._progressObserver.error&&this._progressObserver.error(t),this._taskCompletionResolver.reject(t)},t.prototype._updateProgress=function(t){this._lastProgress=t,this._progressObserver.next&&this._progressObserver.next(t)},t}(),Ba=-1,ja=function(t){function n(e,n){var r=this;return(r=t.call(this,e,n)||this).type="firestore",r._queue=new Va,r._persistenceKey="name"in e?e.name:"[DEFAULT]",r}return(0,e.__extends)(n,t),n.prototype._terminate=function(){return this._firestoreClient||Qa(this),this._firestoreClient.terminate()},n}(ka);function Ka(t){return t._firestoreClient||Qa(t),t._firestoreClient.verifyNotTerminated(),t._firestoreClient}function Qa(t){var e,n=t._freezeSettings(),r=function(t,e,n,r){return new la(t,e,n,r.host,r.ssl,r.experimentalForceLongPolling,r.experimentalAutoDetectLongPolling,r.useFetchStreams)}(t._databaseId,(null===(e=t._app)||void 0===e?void 0:e.options.appId)||"",t._persistenceKey,n);t._firestoreClient=new ta(t._credentials,t._queue,r)}function Ga(t,n,r){var i=this,o=new er;return t.asyncQueue.enqueue(function(){return(0,e.__awaiter)(i,void 0,void 0,function(){var i;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),[4,ea(t,r)];case 1:return e.sent(),[4,na(t,n)];case 2:return e.sent(),o.resolve(),[3,4];case 3:if(!function(t){return"FirebaseError"===t.name?t.code===a.FAILED_PRECONDITION||t.code===a.UNIMPLEMENTED:!("undefined"!=typeof DOMException&&t instanceof DOMException)||22===t.code||20===t.code||11===t.code}(i=e.sent()))throw i;return console.warn("Error enabling offline persistence. Falling back to persistence disabled: "+i),o.reject(i),[3,4];case 4:return[2]}})})}).then(function(){return o.promise})}function za(t){if(t._initialized||t._terminated)throw new u(a.FAILED_PRECONDITION,"Firestore has already been started and persistence can no longer be enabled. You can only enable persistence before calling any other methods on a Firestore object.")}exports.T=ja,exports.E=Ba;var Wa=function(){function t(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];for(var n=0;n<t.length;++n)if(0===t[n].length)throw new u(a.INVALID_ARGUMENT,"Invalid field name at argument $(i + 1). Field names must not be empty.");this._internalPath=new C(t)}return t.prototype.isEqual=function(t){return this._internalPath.isEqual(t._internalPath)},t}(),Ha=function(){function t(t){this._byteString=t}return t.fromBase64String=function(e){try{return new t(L.fromBase64String(e))}catch(e){throw new u(a.INVALID_ARGUMENT,"Failed to construct data from Base64 string: "+e)}},t.fromUint8Array=function(e){return new t(L.fromUint8Array(e))},t.prototype.toBase64=function(){return this._byteString.toBase64()},t.prototype.toUint8Array=function(){return this._byteString.toUint8Array()},t.prototype.toString=function(){return"Bytes(base64: "+this.toBase64()+")"},t.prototype.isEqual=function(t){return this._byteString.isEqual(t._byteString)},t}(),Ya=function(t){this._methodName=t},$a=function(){function t(t,e){if(!isFinite(t)||t<-90||t>90)throw new u(a.INVALID_ARGUMENT,"Latitude must be a number between -90 and 90, but was: "+t);if(!isFinite(e)||e<-180||e>180)throw new u(a.INVALID_ARGUMENT,"Longitude must be a number between -180 and 180, but was: "+e);this._lat=t,this._long=e}return Object.defineProperty(t.prototype,"latitude",{get:function(){return this._lat},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"longitude",{get:function(){return this._long},enumerable:!1,configurable:!0}),t.prototype.isEqual=function(t){return this._lat===t._lat&&this._long===t._long},t.prototype.toJSON=function(){return{latitude:this._lat,longitude:this._long}},t.prototype._compareTo=function(t){return w(this._lat,t._lat)||w(this._long,t._long)},t}(),Xa=/^__.*__$/,Ja=function(){function t(t,e,n){this.data=t,this.fieldMask=e,this.fieldTransforms=n}return t.prototype.toMutation=function(t,e){return null!==this.fieldMask?new me(t,this.data,this.fieldMask,e,this.fieldTransforms):new ve(t,this.data,e,this.fieldTransforms)},t}(),Za=function(){function t(t,e,n){this.data=t,this.fieldMask=e,this.fieldTransforms=n}return t.prototype.toMutation=function(t,e){return new me(t,this.data,this.fieldMask,e,this.fieldTransforms)},t}();function tu(t){switch(t){case 0:case 2:case 1:return!0;case 3:case 4:return!1;default:throw y()}}exports.C=$a;var eu=function(){function t(t,e,n,r,i,o){this.settings=t,this.databaseId=e,this.R=n,this.ignoreUndefinedProperties=r,void 0===i&&this.Cc(),this.fieldTransforms=i||[],this.fieldMask=o||[]}return Object.defineProperty(t.prototype,"path",{get:function(){return this.settings.path},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Nc",{get:function(){return this.settings.Nc},enumerable:!1,configurable:!0}),t.prototype.xc=function(e){return new t(Object.assign(Object.assign({},this.settings),e),this.databaseId,this.R,this.ignoreUndefinedProperties,this.fieldTransforms,this.fieldMask)},t.prototype.kc=function(t){var e,n=null===(e=this.path)||void 0===e?void 0:e.child(t),r=this.xc({path:n,Fc:!1});return r.$c(t),r},t.prototype.Oc=function(t){var e,n=null===(e=this.path)||void 0===e?void 0:e.child(t),r=this.xc({path:n,Fc:!1});return r.Cc(),r},t.prototype.Mc=function(t){return this.xc({path:void 0,Fc:!0})},t.prototype.Lc=function(t){return bu(t,this.settings.methodName,this.settings.Bc||!1,this.path,this.settings.qc)},t.prototype.contains=function(t){return void 0!==this.fieldMask.find(function(e){return t.isPrefixOf(e)})||void 0!==this.fieldTransforms.find(function(e){return t.isPrefixOf(e.field)})},t.prototype.Cc=function(){if(this.path)for(var t=0;t<this.path.length;t++)this.$c(this.path.get(t))},t.prototype.$c=function(t){if(0===t.length)throw this.Lc("Document fields must not be empty");if(tu(this.Nc)&&Xa.test(t))throw this.Lc('Document fields cannot begin and end with "__"')},t}(),nu=function(){function t(t,e,n){this.databaseId=t,this.ignoreUndefinedProperties=e,this.R=n||ho(t)}return t.prototype.Uc=function(t,e,n,r){return void 0===r&&(r=!1),new eu({Nc:t,methodName:e,qc:n,path:C.emptyPath(),Fc:!1,Bc:r},this.databaseId,this.R,this.ignoreUndefinedProperties)},t}();function ru(t){var e=t._freezeSettings(),n=ho(t._databaseId);return new nu(t._databaseId,!!e.ignoreUndefinedProperties,n)}function iu(t,e,n,r,i,o){void 0===o&&(o={});var s=t.Uc(o.merge||o.mergeFields?2:0,e,n,i);mu("Data must be an object, but it was:",s,r);var c,h,f=yu(r,s);if(o.merge)c=new R(s.fieldMask),h=s.fieldTransforms;else if(o.mergeFields){for(var l=[],d=0,p=o.mergeFields;d<p.length;d++){var y=gu(e,p[d],n);if(!s.contains(y))throw new u(a.INVALID_ARGUMENT,"Field '"+y+"' is specified in your field mask but missing from your input data.");Iu(l,y)||l.push(y)}c=new R(l),h=s.fieldTransforms.filter(function(t){return c.covers(t.field)})}else c=null,h=s.fieldTransforms;return new Ja(new ot(f),c,h)}var ou=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return(0,e.__extends)(n,t),n.prototype._toFieldTransform=function(t){if(2!==t.Nc)throw 1===t.Nc?t.Lc(this._methodName+"() can only appear at the top level of your update data"):t.Lc(this._methodName+"() cannot be used with set() unless you pass {merge:true}");return t.fieldMask.push(t.path),null},n.prototype.isEqual=function(t){return t instanceof n},n}(Ya);function su(t,e,n){return new eu({Nc:3,qc:e.settings.qc,methodName:t._methodName,Fc:n},e.databaseId,e.R,e.ignoreUndefinedProperties)}var au=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return(0,e.__extends)(n,t),n.prototype._toFieldTransform=function(t){return new se(t.path,new Jt)},n.prototype.isEqual=function(t){return t instanceof n},n}(Ya),uu=function(t){function n(e,n){var r=this;return(r=t.call(this,e)||this).Kc=n,r}return(0,e.__extends)(n,t),n.prototype._toFieldTransform=function(t){var e=su(this,t,!0),n=this.Kc.map(function(t){return pu(t,e)}),r=new Zt(n);return new se(t.path,r)},n.prototype.isEqual=function(t){return this===t},n}(Ya),cu=function(t){function n(e,n){var r=this;return(r=t.call(this,e)||this).Kc=n,r}return(0,e.__extends)(n,t),n.prototype._toFieldTransform=function(t){var e=su(this,t,!0),n=this.Kc.map(function(t){return pu(t,e)}),r=new ee(n);return new se(t.path,r)},n.prototype.isEqual=function(t){return this===t},n}(Ya),hu=function(t){function n(e,n){var r=this;return(r=t.call(this,e)||this).Qc=n,r}return(0,e.__extends)(n,t),n.prototype._toFieldTransform=function(t){var e=new re(t.R,Wt(t.R,this.Qc));return new se(t.path,e)},n.prototype.isEqual=function(t){return this===t},n}(Ya);function fu(t,e,r,i){var o=t.Uc(1,e,r);mu("Data must be an object, but it was:",o,i);var s=[],a=ot.empty();N(i,function(t,i){var u=wu(e,t,r);i=(0,n.getModularInstance)(i);var c=o.Oc(u);if(i instanceof ou)s.push(u);else{var h=pu(i,c);null!=h&&(s.push(u),a.set(u,h))}});var u=new R(s);return new Za(a,u,o.fieldTransforms)}function lu(t,e,r,i,o,s){var c=t.Uc(1,e,r),h=[gu(e,i,r)],f=[o];if(s.length%2!=0)throw new u(a.INVALID_ARGUMENT,"Function "+e+"() needs to be called with an even number of arguments that alternate between field names and values.");for(var l=0;l<s.length;l+=2)h.push(gu(e,s[l])),f.push(s[l+1]);for(var d=[],p=ot.empty(),y=h.length-1;y>=0;--y)if(!Iu(d,h[y])){var v=h[y],m=f[y];m=(0,n.getModularInstance)(m);var g=c.Oc(v);if(m instanceof ou)d.push(v);else{var _=pu(m,g);null!=_&&(d.push(v),p.set(v,_))}}var w=new R(d);return new Za(p,w,c.fieldTransforms)}function du(t,e,n,r){return void 0===r&&(r=!1),pu(n,t.Uc(r?4:3,e))}function pu(t,e){if(vu(t=(0,n.getModularInstance)(t)))return mu("Unsupported field value:",e,t),yu(t,e);if(t instanceof Ya)return function(t,e){if(!tu(e.Nc))throw e.Lc(t._methodName+"() can only be used with update() and set()");if(!e.path)throw e.Lc(t._methodName+"() is not currently supported inside arrays");var n=t._toFieldTransform(e);n&&e.fieldTransforms.push(n)}(t,e),null;if(void 0===t&&e.ignoreUndefinedProperties)return null;if(e.path&&e.fieldMask.push(e.path),t instanceof Array){if(e.settings.Fc&&4!==e.Nc)throw e.Lc("Nested arrays are not supported");return function(t,e){for(var n=[],r=0,i=0,o=t;i<o.length;i++){var s=pu(o[i],e.Mc(r));null==s&&(s={nullValue:"NULL_VALUE"}),n.push(s),r++}return{arrayValue:{values:n}}}(t,e)}return function(t,e){if(null===(t=(0,n.getModularInstance)(t)))return{nullValue:"NULL_VALUE"};if("number"==typeof t)return Wt(e.R,t);if("boolean"==typeof t)return{booleanValue:t};if("string"==typeof t)return{stringValue:t};if(t instanceof Date){var r=E.fromDate(t);return{timestampValue:en(e.R,r)}}if(t instanceof E)return r=new E(t.seconds,1e3*Math.floor(t.nanoseconds/1e3)),{timestampValue:en(e.R,r)};if(t instanceof $a)return{geoPointValue:{latitude:t.latitude,longitude:t.longitude}};if(t instanceof Ha)return{bytesValue:nn(e.R,t._byteString)};if(t instanceof Ca){r=e.databaseId;var i=t.firestore._databaseId;if(!i.isEqual(r))throw e.Lc("Document reference is for database "+i.projectId+"/"+i.database+" but should be for database "+r.projectId+"/"+r.database);return{referenceValue:sn(t.firestore._databaseId||e.databaseId,t._key.path)}}throw e.Lc("Unsupported field value: "+Na(t))}(t,e)}function yu(t,e){var n={};return D(t)?e.path&&e.path.length>0&&e.fieldMask.push(e.path):N(t,function(t,r){var i=pu(r,e.kc(t));null!=i&&(n[t]=i)}),{mapValue:{fields:n}}}function vu(t){return!("object"!=o(t)||null===t||t instanceof Array||t instanceof Date||t instanceof E||t instanceof $a||t instanceof Ha||t instanceof Ca||t instanceof Ya)}function mu(t,e,n){if(!vu(n)||!function(t){return"object"==o(t)&&null!==t&&(Object.getPrototypeOf(t)===Object.prototype||null===Object.getPrototypeOf(t))}(n)){var r=Na(n);throw"an object"===r?e.Lc(t+" a custom object"):e.Lc(t+" "+r)}}function gu(t,e,r){if((e=(0,n.getModularInstance)(e))instanceof Wa)return e._internalPath;if("string"==typeof e)return wu(t,e);throw bu("Field path arguments must be of type string or FieldPath.",t,!1,void 0,r)}var _u=new RegExp("[~\\*/\\[\\]]");function wu(t,n,r){if(n.search(_u)>=0)throw bu("Invalid field path ("+n+"). Paths must not contain '~', '*', '/', '[', or ']'",t,!1,void 0,r);try{return(new(Wa.bind.apply(Wa,(0,e.__spreadArray)([void 0],n.split(".")))))._internalPath}catch(i){throw bu("Invalid field path ("+n+"). Paths must not be empty, begin with '.', end with '.', or contain '..'",t,!1,void 0,r)}}function bu(t,e,n,r,i){var o=r&&!r.isEmpty(),s=void 0!==i,c="Function "+e+"() called with invalid data";n&&(c+=" (via `toFirestore()`)");var h="";return(o||s)&&(h+=" (found",o&&(h+=" in field "+r),s&&(h+=" in document "+i),h+=")"),new u(a.INVALID_ARGUMENT,(c+=". ")+t+h)}function Iu(t,e){return t.some(function(t){return t.isEqual(e)})}var Eu=function(){function t(t,e,n,r,i){this._firestore=t,this._userDataWriter=e,this._key=n,this._document=r,this._converter=i}return Object.defineProperty(t.prototype,"id",{get:function(){return this._key.path.lastSegment()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"ref",{get:function(){return new Ca(this._firestore,this._converter,this._key)},enumerable:!1,configurable:!0}),t.prototype.exists=function(){return null!==this._document},t.prototype.data=function(){if(this._document){if(this._converter){var t=new Tu(this._firestore,this._userDataWriter,this._key,this._document,null);return this._converter.fromFirestore(t)}return this._userDataWriter.convertValue(this._document.data.value)}},t.prototype.get=function(t){if(this._document){var e=this._document.data.field(Su("DocumentSnapshot.get",t));if(null!==e)return this._userDataWriter.convertValue(e)}},t}(),Tu=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return(0,e.__extends)(n,t),n.prototype.data=function(){return t.prototype.data.call(this)},n}(Eu);function Su(t,e){return"string"==typeof e?wu(t,e):e instanceof Wa?e._internalPath:e._delegate._internalPath}var Nu=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}(),Du=function(t){function n(e,n,r,i,o,s){var a=this;return(a=t.call(this,e,n,r,i,s)||this)._firestore=e,a._firestoreImpl=e,a.metadata=o,a}return(0,e.__extends)(n,t),n.prototype.exists=function(){return t.prototype.exists.call(this)},n.prototype.data=function(t){if(void 0===t&&(t={}),this._document){if(this._converter){var e=new Au(this._firestore,this._userDataWriter,this._key,this._document,this.metadata,null);return this._converter.fromFirestore(e,t)}return this._userDataWriter.convertValue(this._document.data.value,t.serverTimestamps)}},n.prototype.get=function(t,e){if(void 0===e&&(e={}),this._document){var n=this._document.data.field(Su("DocumentSnapshot.get",t));if(null!==n)return this._userDataWriter.convertValue(n,e.serverTimestamps)}},n}(Eu),Au=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return(0,e.__extends)(n,t),n.prototype.data=function(e){return void 0===e&&(e={}),t.prototype.data.call(this,e)},n}(Du),xu=function(){function t(t,e,n,r){this._firestore=t,this._userDataWriter=e,this._snapshot=r,this.metadata=new Nu(r.hasPendingWrites,r.fromCache),this.query=n}return Object.defineProperty(t.prototype,"docs",{get:function(){var t=[];return this.forEach(function(e){return t.push(e)}),t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"size",{get:function(){return this._snapshot.docs.size},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"empty",{get:function(){return 0===this.size},enumerable:!1,configurable:!0}),t.prototype.forEach=function(t,e){var n=this;this._snapshot.docs.forEach(function(r){t.call(e,new Au(n._firestore,n._userDataWriter,r.key,r,new Nu(n._snapshot.mutatedKeys.has(r.key),n._snapshot.fromCache),n.query.converter))})},t.prototype.docChanges=function(t){void 0===t&&(t={});var e=!!t.includeMetadataChanges;if(e&&this._snapshot.excludesMetadataChanges)throw new u(a.INVALID_ARGUMENT,"To include metadata changes with your document changes, you must also pass { includeMetadataChanges:true } to onSnapshot().");return this._cachedChanges&&this._cachedChangesIncludeMetadataChanges===e||(this._cachedChanges=function(t,e){if(t._snapshot.oldDocs.isEmpty()){var n=0;return t._snapshot.docChanges.map(function(e){return{type:"added",doc:new Au(t._firestore,t._userDataWriter,e.doc.key,e.doc,new Nu(t._snapshot.mutatedKeys.has(e.doc.key),t._snapshot.fromCache),t.query.converter),oldIndex:-1,newIndex:n++}})}var r=t._snapshot.oldDocs;return t._snapshot.docChanges.filter(function(t){return e||3!==t.type}).map(function(e){var n=new Au(t._firestore,t._userDataWriter,e.doc.key,e.doc,new Nu(t._snapshot.mutatedKeys.has(e.doc.key),t._snapshot.fromCache),t.query.converter),i=-1,o=-1;return 0!==e.type&&(i=r.indexOf(e.doc.key),r=r.delete(e.doc.key)),1!==e.type&&(o=(r=r.add(e.doc)).indexOf(e.doc.key)),{type:ku(e.type),doc:n,oldIndex:i,newIndex:o}})}(this,e),this._cachedChangesIncludeMetadataChanges=e),this._cachedChanges},t}();function ku(t){switch(t){case 0:return"added";case 2:case 3:return"modified";case 1:return"removed";default:return y()}}function Cu(t,e){return t instanceof Du&&e instanceof Du?t._firestore===e._firestore&&t._key.isEqual(e._key)&&(null===t._document?null===e._document:t._document.isEqual(e._document))&&t._converter===e._converter:t instanceof xu&&e instanceof xu&&t._firestore===e._firestore&&Ma(t.query,e.query)&&t.metadata.isEqual(e.metadata)&&t._snapshot.isEqual(e._snapshot)}function Ru(t){if(Rt(t)&&0===t.explicitOrderBy.length)throw new u(a.UNIMPLEMENTED,"limitToLast() queries require specifying at least one orderBy() clause")}var Lu=function(){};function Ou(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];for(var r=0,i=e;r<i.length;r++){t=i[r]._apply(t)}return t}var Pu=function(t){function n(e,n,r){var i=this;return(i=t.call(this)||this).jc=e,i.Wc=n,i.Gc=r,i.type="where",i}return(0,e.__extends)(n,t),n.prototype._apply=function(t){var e=ru(t.firestore),n=function(t,e,n,r,i,o,s){var c;if(i.isKeyField()){if("array-contains"===o||"array-contains-any"===o)throw new u(a.INVALID_ARGUMENT,"Invalid Query. You can't perform '"+o+"' queries on FieldPath.documentId().");if("in"===o||"not-in"===o){ju(s,o);for(var h=[],f=0,l=s;f<l.length;f++){var d=l[f];h.push(Bu(r,t,d))}c={arrayValue:{values:h}}}else c=Bu(r,t,s)}else"in"!==o&&"not-in"!==o&&"array-contains-any"!==o||ju(s,o),c=du(n,"where",s,"in"===o||"not-in"===o);var p=dt.create(i,o,c);return function(t,e){if(e.g()){var n=Ot(t);if(null!==n&&!n.isEqual(e.field))throw new u(a.INVALID_ARGUMENT,"Invalid query. All where filters with an inequality (<, <=, !=, not-in, >, or >=) must be on the same field. But you have inequality filters on '"+n.toString()+"' and '"+e.field.toString()+"'");var r=Lt(t);null!==r&&Ku(t,e.field,r)}var i=function(t,e){for(var n=0,r=t.filters;n<r.length;n++){var i=r[n];if(e.indexOf(i.op)>=0)return i.op}return null}(t,function(t){switch(e.op){case"!=":return["!=","not-in"];case"array-contains":return["array-contains","array-contains-any","not-in"];case"in":return["array-contains-any","in","not-in"];case"array-contains-any":return["array-contains","array-contains-any","in","not-in"];case"not-in":return["array-contains","array-contains-any","in","not-in","!="];default:return[]}}());if(null!==i)throw i===e.op?new u(a.INVALID_ARGUMENT,"Invalid query. You cannot use more than one '"+e.op.toString()+"' filter."):new u(a.INVALID_ARGUMENT,"Invalid query. You cannot use '"+e.op.toString()+"' filters with '"+i.toString()+"' filters.")}(t,p),p}(t._query,0,e,t.firestore._databaseId,this.jc,this.Wc,this.Gc);return new Ra(t.firestore,t.converter,function(t,e){var n=t.filters.concat([e]);return new At(t.path,t.collectionGroup,t.explicitOrderBy.slice(),n,t.limit,t.limitType,t.startAt,t.endAt)}(t._query,n))},n}(Lu),Fu=function(t){function n(e,n){var r=this;return(r=t.call(this)||this).jc=e,r.zc=n,r.type="orderBy",r}return(0,e.__extends)(n,t),n.prototype._apply=function(t){var e=function(t,e,n){if(null!==t.startAt)throw new u(a.INVALID_ARGUMENT,"Invalid query. You must not call startAt() or startAfter() before calling orderBy().");if(null!==t.endAt)throw new u(a.INVALID_ARGUMENT,"Invalid query. You must not call endAt() or endBefore() before calling orderBy().");var r=new Tt(e,n);return function(t,e){if(null===Lt(t)){var n=Ot(t);null!==n&&Ku(t,n,e.field)}}(t,r),r}(t._query,this.jc,this.zc);return new Ra(t.firestore,t.converter,function(t,e){var n=t.explicitOrderBy.concat([e]);return new At(t.path,t.collectionGroup,n,t.filters.slice(),t.limit,t.limitType,t.startAt,t.endAt)}(t._query,e))},n}(Lu),Mu=function(t){function n(e,n,r){var i=this;return(i=t.call(this)||this).type=e,i.Hc=n,i.Jc=r,i}return(0,e.__extends)(n,t),n.prototype._apply=function(t){return new Ra(t.firestore,t.converter,Vt(t._query,this.Hc,this.Jc))},n}(Lu),Vu=function(t){function n(e,n,r){var i=this;return(i=t.call(this)||this).type=e,i.Yc=n,i.Xc=r,i}return(0,e.__extends)(n,t),n.prototype._apply=function(t){var e=Uu(t,this.type,this.Yc,this.Xc);return new Ra(t.firestore,t.converter,function(t,e){return new At(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,e,t.endAt)}(t._query,e))},n}(Lu),qu=function(t){function n(e,n,r){var i=this;return(i=t.call(this)||this).type=e,i.Yc=n,i.Xc=r,i}return(0,e.__extends)(n,t),n.prototype._apply=function(t){var e=Uu(t,this.type,this.Yc,this.Xc);return new Ra(t.firestore,t.converter,function(t,e){return new At(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,t.startAt,e)}(t._query,e))},n}(Lu);function Uu(t,e,r,i){if(r[0]=(0,n.getModularInstance)(r[0]),r[0]instanceof Eu)return function(t,e,n,r,i){if(!r)throw new u(a.NOT_FOUND,"Can't use a DocumentSnapshot that doesn't exist for "+n+"().");for(var o=[],s=0,c=Ft(t);s<c.length;s++){var h=c[s];if(h.field.isKeyField())o.push(J(e,r.key));else{var f=r.data.field(h.field);if(V(f))throw new u(a.INVALID_ARGUMENT,'Invalid query. You are trying to start or end a query using a document for which the field "'+h.field+'" is an uncommitted server timestamp. (Since the value of this field is unknown, you cannot start/end a query with it.)');if(null===f){var l=h.field.canonicalString();throw new u(a.INVALID_ARGUMENT,"Invalid query. You are trying to start or end a query using a document for which the field '"+l+"' (used as the orderBy) does not exist.")}o.push(f)}}return new It(o,i)}(t._query,t.firestore._databaseId,e,r[0]._document,i);var s=ru(t.firestore);return function(t,e,n,r,i,s){var c=t.explicitOrderBy;if(i.length>c.length)throw new u(a.INVALID_ARGUMENT,"Too many arguments provided to "+r+"(). The number of arguments must be less than or equal to the number of orderBy() clauses");for(var h=[],f=0;f<i.length;f++){var l=i[f];if(c[f].field.isKeyField()){if("string"!=typeof l)throw new u(a.INVALID_ARGUMENT,"Invalid query. Expected a string for document ID in "+r+"(), but got a "+o(l));if(!Pt(t)&&-1!==l.indexOf("/"))throw new u(a.INVALID_ARGUMENT,"Invalid query. When querying a collection and ordering by FieldPath.documentId(), the value passed to "+r+"() must be a plain document ID, but '"+l+"' contains a slash.");var d=t.path.child(x.fromString(l));if(!Q.isDocumentKey(d))throw new u(a.INVALID_ARGUMENT,"Invalid query. When querying a collection group and ordering by FieldPath.documentId(), the value passed to "+r+"() must result in a valid document path, but '"+d+"' is not because it contains an odd number of segments.");var p=new Q(d);h.push(J(e,p))}else{var y=du(n,r,l);h.push(y)}}return new It(h,s)}(t._query,t.firestore._databaseId,s,e,r,i)}function Bu(t,e,r){if("string"==typeof(r=(0,n.getModularInstance)(r))){if(""===r)throw new u(a.INVALID_ARGUMENT,"Invalid query. When querying with FieldPath.documentId(), you must provide a valid document ID, but it was an empty string.");if(!Pt(e)&&-1!==r.indexOf("/"))throw new u(a.INVALID_ARGUMENT,"Invalid query. When querying a collection by FieldPath.documentId(), you must provide a plain document ID, but '"+r+"' contains a '/' character.");var i=e.path.child(x.fromString(r));if(!Q.isDocumentKey(i))throw new u(a.INVALID_ARGUMENT,"Invalid query. When querying a collection group by FieldPath.documentId(), the value provided must result in a valid document path, but '"+i+"' is not because it has an odd number of segments ("+i.length+").");return J(t,new Q(i))}if(r instanceof Ca)return J(t,r._key);throw new u(a.INVALID_ARGUMENT,"Invalid query. When querying with FieldPath.documentId(), you must provide a valid string or a DocumentReference, but it was: "+Na(r)+".")}function ju(t,e){if(!Array.isArray(t)||0===t.length)throw new u(a.INVALID_ARGUMENT,"Invalid Query. A non-empty array is required for '"+e.toString()+"' filters.");if(t.length>10)throw new u(a.INVALID_ARGUMENT,"Invalid Query. '"+e.toString()+"' filters support a maximum of 10 elements in the value array.")}function Ku(t,e,n){if(!n.isEqual(e))throw new u(a.INVALID_ARGUMENT,"Invalid query. You have a where filter with an inequality (<, <=, !=, not-in, >, or >=) on field '"+e.toString()+"' and so you must also use '"+e.toString()+"' as your first argument to orderBy(), but your first orderBy() is on field '"+n.toString()+"' instead.")}var Qu=function(){function t(){}return t.prototype.convertValue=function(t,e){switch(void 0===e&&(e="none"),G(t)){case 0:return null;case 1:return t.booleanValue;case 2:return F(t.integerValue||t.doubleValue);case 3:return this.convertTimestamp(t.timestampValue);case 4:return this.convertServerTimestamp(t,e);case 5:return t.stringValue;case 6:return this.convertBytes(M(t.bytesValue));case 7:return this.convertReference(t.referenceValue);case 8:return this.convertGeoPoint(t.geoPointValue);case 9:return this.convertArray(t.arrayValue,e);case 10:return this.convertObject(t.mapValue,e);default:throw y()}},t.prototype.convertObject=function(t,e){var n=this,r={};return N(t.fields,function(t,i){r[t]=n.convertValue(i,e)}),r},t.prototype.convertGeoPoint=function(t){return new $a(F(t.latitude),F(t.longitude))},t.prototype.convertArray=function(t,e){var n=this;return(t.values||[]).map(function(t){return n.convertValue(t,e)})},t.prototype.convertServerTimestamp=function(t,e){switch(e){case"previous":var n=q(t);return null==n?null:this.convertValue(n,e);case"estimate":return this.convertTimestamp(U(t));default:return null}},t.prototype.convertTimestamp=function(t){var e=P(t);return new E(e.seconds,e.nanos)},t.prototype.convertDocumentKey=function(t,e){var n=x.fromString(t);v(Cn(n));var r=new da(n.get(1),n.get(3)),i=new Q(n.popFirst(5));return r.isEqual(e)||l("Document "+i+" contains a document reference within a different database ("+r.projectId+"/"+r.database+") which is not supported. It will be treated as a reference in the current database ("+e.projectId+"/"+e.database+") instead."),i},t}();function Gu(t,e,n){return t?n&&(n.merge||n.mergeFields)?t.toFirestore(e,n):t.toFirestore(e):e}var zu=function(t){function n(e){var n=this;return(n=t.call(this)||this).firestore=e,n}return(0,e.__extends)(n,t),n.prototype.convertBytes=function(t){return new Ha(t)},n.prototype.convertReference=function(t){var e=this.convertDocumentKey(t,this.firestore._databaseId);return new Ca(this.firestore,null,e)},n}(Qu),Wu=function(){function t(t,e){this._firestore=t,this._commitHandler=e,this._mutations=[],this._committed=!1,this._dataReader=ru(t)}return t.prototype.set=function(t,e,n){this._verifyNotCommitted();var r=Hu(t,this._firestore),i=Gu(r.converter,e,n),o=iu(this._dataReader,"WriteBatch.set",r._key,i,null!==r.converter,n);return this._mutations.push(o.toMutation(r._key,ue.none())),this},t.prototype.update=function(t,e,r){for(var i=[],o=3;o<arguments.length;o++)i[o-3]=arguments[o];this._verifyNotCommitted();var s,a=Hu(t,this._firestore);return s="string"==typeof(e=(0,n.getModularInstance)(e))||e instanceof Wa?lu(this._dataReader,"WriteBatch.update",a._key,e,r,i):fu(this._dataReader,"WriteBatch.update",a._key,e),this._mutations.push(s.toMutation(a._key,ue.exists(!0))),this},t.prototype.delete=function(t){this._verifyNotCommitted();var e=Hu(t,this._firestore);return this._mutations=this._mutations.concat(new Ee(e._key,ue.none())),this},t.prototype.commit=function(){return this._verifyNotCommitted(),this._committed=!0,this._mutations.length>0?this._commitHandler(this._mutations):Promise.resolve()},t.prototype._verifyNotCommitted=function(){if(this._committed)throw new u(a.FAILED_PRECONDITION,"A write batch can no longer be used after commit() has been called.")},t}();function Hu(t,e){if((t=(0,n.getModularInstance)(t)).firestore!==e)throw new u(a.INVALID_ARGUMENT,"Provided document reference is from a different Firestore instance.");return t}var Yu=function(t){function n(e){var n=this;return(n=t.call(this)||this).firestore=e,n}return(0,e.__extends)(n,t),n.prototype.convertBytes=function(t){return new Ha(t)},n.prototype.convertReference=function(t){var e=this.convertDocumentKey(t,this.firestore._databaseId);return new Ca(this.firestore,null,e)},n}(Qu);function $u(t,e,r){for(var i=[],o=3;o<arguments.length;o++)i[o-3]=arguments[o];t=Da(t,Ca);var s=Da(t.firestore,ja),a=ru(s);return Ju(s,[("string"==typeof(e=(0,n.getModularInstance)(e))||e instanceof Wa?lu(a,"updateDoc",t._key,e,r,i):fu(a,"updateDoc",t._key,e)).toMutation(t._key,ue.exists(!0))])}function Xu(t){for(var r,i,s,a=[],u=1;u<arguments.length;u++)a[u-1]=arguments[u];t=(0,n.getModularInstance)(t);var c={includeMetadataChanges:!1},h=0;"object"!=o(a[h])||qa(a[h])||(c=a[h],h++);var f,l,d,p={includeMetadataChanges:c.includeMetadataChanges};if(qa(a[h])){var y=a[h];a[h]=null===(r=y.next)||void 0===r?void 0:r.bind(y),a[h+1]=null===(i=y.error)||void 0===i?void 0:i.bind(y),a[h+2]=null===(s=y.complete)||void 0===s?void 0:s.bind(y)}if(t instanceof Ca)l=Da(t.firestore,ja),d=kt(t._key.path),f={next:function(e){a[h]&&a[h](Zu(l,t,e))},error:a[h+1],complete:a[h+2]};else{var v=Da(t,Ra);l=Da(v.firestore,ja),d=v._query;var m=new Yu(l);f={next:function(t){a[h]&&a[h](new xu(l,m,v,t))},error:a[h+1],complete:a[h+2]},Ru(t._query)}return function(t,n,r,i){var o=this,s=new $s(f),a=new ns(n,s,r);return t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(o,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return n=Xo,[4,ca(t)];case 1:return[2,n.apply(void 0,[e.sent(),a])]}})})}),function(){s.Wo(),t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(o,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return n=Jo,[4,ca(t)];case 1:return[2,n.apply(void 0,[e.sent(),a])]}})})})}}(Ka(l),d,p)}function Ju(t,n){return function(t,n){var r=this,i=new er;return t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(r,void 0,void 0,function(){var r;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return r=vs,[4,ua(t)];case 1:return[2,r.apply(void 0,[e.sent(),n,i])]}})})}),i.promise}(Ka(t),n)}function Zu(t,e,n){var r=n.docs.get(e._key),i=new Yu(t);return new Du(t,i,e._key,r,new Nu(n.hasPendingWrites,n.fromCache),e.converter)}var tc=function(t){function n(e,n){var r=this;return(r=t.call(this,e,n)||this)._firestore=e,r}return(0,e.__extends)(n,t),n.prototype.get=function(e){var n=this,r=Hu(e,this._firestore),i=new Yu(this._firestore);return t.prototype.get.call(this,e).then(function(t){return new Du(n._firestore,i,r._key,t._document,new Nu(!1,!1),r.converter)})},n}(function(){function t(t,e){this._firestore=t,this._transaction=e,this._dataReader=ru(t)}return t.prototype.get=function(t){var e=this,n=Hu(t,this._firestore),r=new zu(this._firestore);return this._transaction.lookup([n._key]).then(function(t){if(!t||1!==t.length)return y();var i=t[0];if(i.isFoundDocument())return new Eu(e._firestore,r,i.key,i,n.converter);if(i.isNoDocument())return new Eu(e._firestore,r,n._key,null,n.converter);throw y()})},t.prototype.set=function(t,e,n){var r=Hu(t,this._firestore),i=Gu(r.converter,e,n),o=iu(this._dataReader,"Transaction.set",r._key,i,null!==r.converter,n);return this._transaction.set(r._key,o),this},t.prototype.update=function(t,e,r){for(var i=[],o=3;o<arguments.length;o++)i[o-3]=arguments[o];var s,a=Hu(t,this._firestore);return s="string"==typeof(e=(0,n.getModularInstance)(e))||e instanceof Wa?lu(this._dataReader,"Transaction.update",a._key,e,r,i):fu(this._dataReader,"Transaction.update",a._key,e),this._transaction.update(a._key,s),this},t.prototype.delete=function(t){var e=Hu(t,this._firestore);return this._transaction.delete(e._key),this},t}());function ec(){if("undefined"==typeof Uint8Array)throw new u(a.UNIMPLEMENTED,"Uint8Arrays are not available in this environment.")}function nc(){if("undefined"==typeof atob)throw new u(a.UNIMPLEMENTED,"Blobs are unavailable in Firestore in this environment.")}var rc=function(){function t(t){this._delegate=t}return t.fromBase64String=function(e){return nc(),new t(Ha.fromBase64String(e))},t.fromUint8Array=function(e){return ec(),new t(Ha.fromUint8Array(e))},t.prototype.toBase64=function(){return nc(),this._delegate.toBase64()},t.prototype.toUint8Array=function(){return ec(),this._delegate.toUint8Array()},t.prototype.isEqual=function(t){return this._delegate.isEqual(t._delegate)},t.prototype.toString=function(){return"Blob(base64: "+this.toBase64()+")"},t}(),ic=function(){function t(){}return t.prototype.enableIndexedDbPersistence=function(t,e){return function(t,e){za(t=Da(t,ja));var n=Ka(t),r=t._freezeSettings(),i=new Hs;return Ga(n,i,new zs(i,r.cacheSizeBytes,null==e?void 0:e.forceOwnership))}(t._delegate,{forceOwnership:e})},t.prototype.enableMultiTabIndexedDbPersistence=function(t){return function(t){za(t=Da(t,ja));var e=Ka(t),n=t._freezeSettings(),r=new Hs;return Ga(e,r,new Ws(r,n.cacheSizeBytes))}(t._delegate)},t.prototype.clearIndexedDbPersistence=function(t){return function(t){var n=this;if(t._initialized&&!t._terminated)throw new u(a.FAILED_PRECONDITION,"Persistence can only be cleared before a Firestore instance is initialized or after it is terminated.");var r=new er;return t._queue.enqueueAndForgetEvenWhileRestricted(function(){return(0,e.__awaiter)(n,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,function(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return ir.yt()?(n=t+"main",[4,ir.delete(n)]):[2,Promise.resolve()];case 1:return e.sent(),[2]}})})}(yi(t._databaseId,t._persistenceKey))];case 1:return i.sent(),r.resolve(),[3,3];case 2:return n=i.sent(),r.reject(n),[3,3];case 3:return[2]}})})}),r.promise}(t._delegate)},t}(),oc=function(){function t(t,e,n){var r=this;this._delegate=e,this.Zc=n,this.INTERNAL={delete:function(){return r.terminate()}},t instanceof da||(this.tu=t)}return Object.defineProperty(t.prototype,"_databaseId",{get:function(){return this._delegate._databaseId},enumerable:!1,configurable:!0}),t.prototype.settings=function(t){var e=this._delegate._getSettings();t.merge||e.host===t.host||d("You are overriding the original host. If you did not intend to override your settings, use {merge: true}."),t.merge&&delete(t=Object.assign(Object.assign({},e),t)).merge,this._delegate._setSettings(t)},t.prototype.useEmulator=function(t,e,r){void 0===r&&(r={}),function(t,e,r,i){var o;void 0===i&&(i={});var s=(t=Da(t,ka))._getSettings();if("firestore.googleapis.com"!==s.host&&s.host!==e&&d("Host has been set in both settings() and useEmulator(), emulator host will be used"),t._setSettings(Object.assign(Object.assign({},s),{host:e+":"+r,ssl:!1})),i.mockUserToken){var c,h;if("string"==typeof i.mockUserToken)c=i.mockUserToken,h=zi.MOCK_USER;else{c=(0,n.createMockUserToken)(i.mockUserToken,null===(o=t._app)||void 0===o?void 0:o.options.projectId);var f=i.mockUserToken.sub||i.mockUserToken.user_id;if(!f)throw new u(a.INVALID_ARGUMENT,"mockUserToken must contain 'sub' or 'user_id' field!");h=new zi(f)}t._credentials=new ma(new ya(c,h))}}(this._delegate,t,e,r)},t.prototype.enableNetwork=function(){return function(t){var n=this;return t.asyncQueue.enqueue(function(){return(0,e.__awaiter)(n,void 0,void 0,function(){var n,r;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,oa(t)];case 1:return n=e.sent(),[4,aa(t)];case 2:return r=e.sent(),[2,(n.setNetworkEnabled(!0),function(t){var e=m(r);return e.Or.delete(0),_o(e)}())]}})})})}(Ka(Da(this._delegate,ja)))},t.prototype.disableNetwork=function(){return function(t){var n=this;return t.asyncQueue.enqueue(function(){return(0,e.__awaiter)(n,void 0,void 0,function(){var n,r;return(0,e.__generator)(this,function(i){switch(i.label){case 0:return[4,oa(t)];case 1:return n=i.sent(),[4,aa(t)];case 2:return r=i.sent(),[2,(n.setNetworkEnabled(!1),function(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return(n=m(t)).Or.add(0),[4,wo(n)];case 1:return e.sent(),n.Br.set("Offline"),[2]}})})}(r))]}})})})}(Ka(Da(this._delegate,ja)))},t.prototype.enablePersistence=function(t){var e=!1,n=!1;return t&&Ea("synchronizeTabs",e=!!t.synchronizeTabs,"experimentalForceOwningTab",n=!!t.experimentalForceOwningTab),e?this.Zc.enableMultiTabIndexedDbPersistence(this):this.Zc.enableIndexedDbPersistence(this,n)},t.prototype.clearPersistence=function(){return this.Zc.clearIndexedDbPersistence(this)},t.prototype.terminate=function(){return this.tu&&(this.tu._removeServiceInstance("firestore"),this.tu._removeServiceInstance("firestore-exp")),this._delegate._delete()},t.prototype.waitForPendingWrites=function(){return function(t){var n=this,r=new er;return t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(n,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return n=Is,[4,ua(t)];case 1:return[2,n.apply(void 0,[e.sent(),r])]}})})}),r.promise}(Ka(Da(this._delegate,ja)))},t.prototype.onSnapshotsInSync=function(t){return function(t,n){return function(t,n){var r=this,i=new $s(n);return t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(r,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return n=function(t,e){m(t).Gr.add(e),e.next()},[4,ca(t)];case 1:return[2,n.apply(void 0,[e.sent(),i])]}})})}),function(){i.Wo(),t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(r,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return n=function(t,e){m(t).Gr.delete(e)},[4,ca(t)];case 1:return[2,n.apply(void 0,[e.sent(),i])]}})})})}}(Ka(t=Da(t,ja)),qa(n)?n:{next:n})}(this._delegate,t)},Object.defineProperty(t.prototype,"app",{get:function(){if(!this.tu)throw new u(a.FAILED_PRECONDITION,"Firestore was not initialized using the Firebase SDK. 'app' is not available");return this.tu},enumerable:!1,configurable:!0}),t.prototype.collection=function(t){try{return new wc(this,Oa(this._delegate,t))}catch(t){throw lc(t,"collection()","Firestore.collection()")}},t.prototype.doc=function(t){try{return new fc(this,Pa(this._delegate,t))}catch(t){throw lc(t,"doc()","Firestore.doc()")}},t.prototype.collectionGroup=function(t){try{return new mc(this,function(t,e){if(t=Da(t,ka),ba("collectionGroup","collection id",e),e.indexOf("/")>=0)throw new u(a.INVALID_ARGUMENT,"Invalid collection ID '"+e+"' passed to function collectionGroup(). Collection IDs must not contain '/'.");return new Ra(t,null,function(t){return new At(x.emptyPath(),t)}(e))}(this._delegate,t))}catch(t){throw lc(t,"collectionGroup()","Firestore.collectionGroup()")}},t.prototype.runTransaction=function(t){var n=this;return function(t,n){return function(t,n){var r=this,i=new er;return t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(r,void 0,void 0,function(){var r;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,function(t){return ia(t).then(function(t){return t.datastore})}(t)];case 1:return r=e.sent(),new Zs(t.asyncQueue,r,n,i).run(),[2]}})})}),i.promise}(Ka(t),function(e){return n(new tc(t,e))})}(this._delegate,function(e){return t(new uc(n,e))})},t.prototype.batch=function(){var t=this;return Ka(this._delegate),new cc(new Wu(this._delegate,function(e){return Ju(t._delegate,e)}))},t.prototype.loadBundle=function(t){throw new u(a.FAILED_PRECONDITION,'"loadBundle()" does not exist, have you imported "firebase/firestore/bundle"?')},t.prototype.namedQuery=function(t){throw new u(a.FAILED_PRECONDITION,'"namedQuery()" does not exist, have you imported "firebase/firestore/bundle"?')},t}(),sc=function(t){function n(e){var n=this;return(n=t.call(this)||this).firestore=e,n}return(0,e.__extends)(n,t),n.prototype.convertBytes=function(t){return new rc(new Ha(t))},n.prototype.convertReference=function(t){var e=this.convertDocumentKey(t,this.firestore._databaseId);return fc.eu(e,this.firestore,null)},n}(Qu);function ac(t){var e;e=t,c.setLogLevel(e)}exports.U=oc,exports.q=ic,exports.a=rc;var uc=function(){function t(t,e){this._firestore=t,this._delegate=e,this._userDataWriter=new sc(t)}return t.prototype.get=function(t){var e=this,n=bc(t);return this._delegate.get(n).then(function(t){return new yc(e._firestore,new Du(e._firestore._delegate,e._userDataWriter,t._key,t._document,t.metadata,n.converter))})},t.prototype.set=function(t,e,n){var r=bc(t);return n?(Ia("Transaction.set",n),this._delegate.set(r,e,n)):this._delegate.set(r,e),this},t.prototype.update=function(t,n,r){for(var i,o=[],s=3;s<arguments.length;s++)o[s-3]=arguments[s];var a=bc(t);return 2===arguments.length?this._delegate.update(a,n):(i=this._delegate).update.apply(i,(0,e.__spreadArray)([a,n,r],o)),this},t.prototype.delete=function(t){var e=bc(t);return this._delegate.delete(e),this},t}(),cc=function(){function t(t){this._delegate=t}return t.prototype.set=function(t,e,n){var r=bc(t);return n?(Ia("WriteBatch.set",n),this._delegate.set(r,e,n)):this._delegate.set(r,e),this},t.prototype.update=function(t,n,r){for(var i,o=[],s=3;s<arguments.length;s++)o[s-3]=arguments[s];var a=bc(t);return 2===arguments.length?this._delegate.update(a,n):(i=this._delegate).update.apply(i,(0,e.__spreadArray)([a,n,r],o)),this},t.prototype.delete=function(t){var e=bc(t);return this._delegate.delete(e),this},t.prototype.commit=function(){return this._delegate.commit()},t}(),hc=function(){function t(t,e,n){this._firestore=t,this._userDataWriter=e,this._delegate=n}return t.prototype.fromFirestore=function(t,e){var n=new Au(this._firestore._delegate,this._userDataWriter,t._key,t._document,t.metadata,null);return this._delegate.fromFirestore(new vc(this._firestore,n),null!=e?e:{})},t.prototype.toFirestore=function(t,e){return e?this._delegate.toFirestore(t,e):this._delegate.toFirestore(t)},t.nu=function(e,n){var r=t.su,i=r.get(e);i||(i=new WeakMap,r.set(e,i));var o=i.get(n);return o||(o=new t(e,new sc(e),n),i.set(n,o)),o},t}();exports.W=cc,exports.j=uc,hc.su=new WeakMap;var fc=function(){function t(t,e){this.firestore=t,this._delegate=e,this._userDataWriter=new sc(t)}return t.iu=function(e,n,r){if(e.length%2!=0)throw new u(a.INVALID_ARGUMENT,"Invalid document reference. Document references must have an even number of segments, but "+e.canonicalString()+" has "+e.length);return new t(n,new Ca(n._delegate,r,new Q(e)))},t.eu=function(e,n,r){return new t(n,new Ca(n._delegate,r,e))},Object.defineProperty(t.prototype,"id",{get:function(){return this._delegate.id},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"parent",{get:function(){return new wc(this.firestore,this._delegate.parent)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"path",{get:function(){return this._delegate.path},enumerable:!1,configurable:!0}),t.prototype.collection=function(t){try{return new wc(this.firestore,Oa(this._delegate,t))}catch(t){throw lc(t,"collection()","DocumentReference.collection()")}},t.prototype.isEqual=function(t){return(t=(0,n.getModularInstance)(t))instanceof Ca&&Fa(this._delegate,t)},t.prototype.set=function(t,e){e=Ia("DocumentReference.set",e);try{return function(t,e,n){t=Da(t,Ca);var r=Da(t.firestore,ja),i=Gu(t.converter,e,n);return Ju(r,[iu(ru(r),"setDoc",t._key,i,null!==t.converter,n).toMutation(t._key,ue.none())])}(this._delegate,t,e)}catch(t){throw lc(t,"setDoc()","DocumentReference.set()")}},t.prototype.update=function(t,n){for(var r=[],i=2;i<arguments.length;i++)r[i-2]=arguments[i];try{return 1===arguments.length?$u(this._delegate,t):$u.apply(void 0,(0,e.__spreadArray)([this._delegate,t,n],r))}catch(t){throw lc(t,"updateDoc()","DocumentReference.update()")}},t.prototype.delete=function(){return Ju(Da((t=this._delegate).firestore,ja),[new Ee(t._key,ue.none())]);var t},t.prototype.onSnapshot=function(){for(var t=this,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=dc(e),i=pc(e,function(e){return new yc(t.firestore,new Du(t.firestore._delegate,t._userDataWriter,e._key,e._document,e.metadata,t._delegate.converter))});return Xu(this._delegate,r,i)},t.prototype.get=function(t){var n=this;return("cache"===(null==t?void 0:t.source)?function(t){t=Da(t,Ca);var n=Da(t.firestore,ja),r=Ka(n),i=new Yu(n);return function(t,n){var r=this,i=new er;return t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(r,void 0,void 0,function(){var r;return(0,e.__generator)(this,function(o){switch(o.label){case 0:return r=function(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,function(t,e){var n=m(t);return n.persistence.runTransaction("read document","readonly",function(t){return n.Mn.mn(t,e)})}(t,n)];case 1:return(o=e.sent()).isFoundDocument()?r.resolve(o):o.isNoDocument()?r.resolve(null):r.reject(new u(a.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.)")),[3,3];case 2:return i=e.sent(),o=Go(i,"Failed to get document '"+n+" from cache"),r.reject(o),[3,3];case 3:return[2]}})})},[4,sa(t)];case 1:return[2,r.apply(void 0,[o.sent(),n,i])]}})})}),i.promise}(r,t._key).then(function(e){return new Du(n,i,t._key,e,new Nu(null!==e&&e.hasLocalMutations,!0),t.converter)})}(this._delegate):"server"===(null==t?void 0:t.source)?function(t){t=Da(t,Ca);var e=Da(t.firestore,ja);return ha(Ka(e),t._key,{source:"server"}).then(function(n){return Zu(e,t,n)})}(this._delegate):function(t){t=Da(t,Ca);var e=Da(t.firestore,ja);return ha(Ka(e),t._key).then(function(n){return Zu(e,t,n)})}(this._delegate)).then(function(t){return new yc(n.firestore,new Du(n.firestore._delegate,n._userDataWriter,t._key,t._document,t.metadata,n._delegate.converter))})},t.prototype.withConverter=function(e){return new t(this.firestore,e?this._delegate.withConverter(hc.nu(this.firestore,e)):this._delegate.withConverter(null))},t}();function lc(t,e,n){return t.message=t.message.replace(e,n),t}function dc(t){for(var e=0,n=t;e<n.length;e++){var r=n[e];if("object"==o(r)&&!qa(r))return r}return{}}function pc(t,e){var n,r,i;return{next:function(t){i.next&&i.next(e(t))},error:null===(n=(i=qa(t[0])?t[0]:qa(t[1])?t[1]:"function"==typeof t[0]?{next:t[0],error:t[1],complete:t[2]}:{next:t[1],error:t[2],complete:t[3]}).error)||void 0===n?void 0:n.bind(i),complete:null===(r=i.complete)||void 0===r?void 0:r.bind(i)}}exports.z=fc;var yc=function(){function t(t,e){this._firestore=t,this._delegate=e}return Object.defineProperty(t.prototype,"ref",{get:function(){return new fc(this._firestore,this._delegate.ref)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"id",{get:function(){return this._delegate.id},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"metadata",{get:function(){return this._delegate.metadata},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"exists",{get:function(){return this._delegate.exists()},enumerable:!1,configurable:!0}),t.prototype.data=function(t){return this._delegate.data(t)},t.prototype.get=function(t,e){return this._delegate.get(t,e)},t.prototype.isEqual=function(t){return Cu(this._delegate,t._delegate)},t}(),vc=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return(0,e.__extends)(n,t),n.prototype.data=function(t){return this._delegate.data(t)},n}(yc),mc=function(){function t(t,e){this.firestore=t,this._delegate=e,this._userDataWriter=new sc(t)}return t.prototype.where=function(e,n,r){try{return new t(this.firestore,Ou(this._delegate,function(t,e,n){var r=e,i=Su("where",t);return new Pu(i,r,n)}(e,n,r)))}catch(e){throw lc(e,/(orderBy|where)\(\)/,"Query.$1()")}},t.prototype.orderBy=function(e,n){try{return new t(this.firestore,Ou(this._delegate,function(t,e){void 0===e&&(e="asc");var n=e,r=Su("orderBy",t);return new Fu(r,n)}(e,n)))}catch(e){throw lc(e,/(orderBy|where)\(\)/,"Query.$1()")}},t.prototype.limit=function(e){try{return new t(this.firestore,Ou(this._delegate,function(t){return Aa("limit",t),new Mu("limit",t,"F")}(e)))}catch(e){throw lc(e,"limit()","Query.limit()")}},t.prototype.limitToLast=function(e){try{return new t(this.firestore,Ou(this._delegate,function(t){return Aa("limitToLast",t),new Mu("limitToLast",t,"L")}(e)))}catch(e){throw lc(e,"limitToLast()","Query.limitToLast()")}},t.prototype.startAt=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];try{return new t(this.firestore,Ou(this._delegate,function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return new Vu("startAt",t,!0)}.apply(void 0,e)))}catch(e){throw lc(e,"startAt()","Query.startAt()")}},t.prototype.startAfter=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];try{return new t(this.firestore,Ou(this._delegate,function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return new Vu("startAfter",t,!1)}.apply(void 0,e)))}catch(e){throw lc(e,"startAfter()","Query.startAfter()")}},t.prototype.endBefore=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];try{return new t(this.firestore,Ou(this._delegate,function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return new qu("endBefore",t,!0)}.apply(void 0,e)))}catch(e){throw lc(e,"endBefore()","Query.endBefore()")}},t.prototype.endAt=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];try{return new t(this.firestore,Ou(this._delegate,function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return new qu("endAt",t,!1)}.apply(void 0,e)))}catch(e){throw lc(e,"endAt()","Query.endAt()")}},t.prototype.isEqual=function(t){return Ma(this._delegate,t._delegate)},t.prototype.get=function(t){var n=this;return("cache"===(null==t?void 0:t.source)?function(t){t=Da(t,Ra);var n=Da(t.firestore,ja),r=Ka(n),i=new Yu(n);return function(t,n){var r=this,i=new er;return t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(r,void 0,void 0,function(){var r;return(0,e.__generator)(this,function(o){switch(o.label){case 0:return r=function(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o,s,a,u;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,ki(t,n,!0)];case 1:return u=e.sent(),i=new cs(n,u.Bn),o=i._o(u.documents),s=i.applyChanges(o,!1),r.resolve(s.snapshot),[3,3];case 2:return a=e.sent(),u=Go(a,"Failed to execute query '"+n+" against cache"),r.reject(u),[3,3];case 3:return[2]}})})},[4,sa(t)];case 1:return[2,r.apply(void 0,[o.sent(),n,i])]}})})}),i.promise}(r,t._query).then(function(e){return new xu(n,i,t,e)})}(this._delegate):"server"===(null==t?void 0:t.source)?function(t){t=Da(t,Ra);var e=Da(t.firestore,ja),n=Ka(e),r=new Yu(e);return fa(n,t._query,{source:"server"}).then(function(n){return new xu(e,r,t,n)})}(this._delegate):function(t){t=Da(t,Ra);var e=Da(t.firestore,ja),n=Ka(e),r=new Yu(e);return Ru(t._query),fa(n,t._query).then(function(n){return new xu(e,r,t,n)})}(this._delegate)).then(function(t){return new _c(n.firestore,new xu(n.firestore._delegate,n._userDataWriter,n._delegate,t._snapshot))})},t.prototype.onSnapshot=function(){for(var t=this,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=dc(e),i=pc(e,function(e){return new _c(t.firestore,new xu(t.firestore._delegate,t._userDataWriter,t._delegate,e._snapshot))});return Xu(this._delegate,r,i)},t.prototype.withConverter=function(e){return new t(this.firestore,e?this._delegate.withConverter(hc.nu(this.firestore,e)):this._delegate.withConverter(null))},t}(),gc=function(){function t(t,e){this._firestore=t,this._delegate=e}return Object.defineProperty(t.prototype,"type",{get:function(){return this._delegate.type},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"doc",{get:function(){return new vc(this._firestore,this._delegate.doc)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"oldIndex",{get:function(){return this._delegate.oldIndex},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"newIndex",{get:function(){return this._delegate.newIndex},enumerable:!1,configurable:!0}),t}(),_c=function(){function t(t,e){this._firestore=t,this._delegate=e}return Object.defineProperty(t.prototype,"query",{get:function(){return new mc(this._firestore,this._delegate.query)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"metadata",{get:function(){return this._delegate.metadata},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"size",{get:function(){return this._delegate.size},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"empty",{get:function(){return this._delegate.empty},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"docs",{get:function(){var t=this;return this._delegate.docs.map(function(e){return new vc(t._firestore,e)})},enumerable:!1,configurable:!0}),t.prototype.docChanges=function(t){var e=this;return this._delegate.docChanges(t).map(function(t){return new gc(e._firestore,t)})},t.prototype.forEach=function(t,e){var n=this;this._delegate.forEach(function(r){t.call(e,new vc(n._firestore,r))})},t.prototype.isEqual=function(t){return Cu(this._delegate,t._delegate)},t}(),wc=function(t){function n(e,n){var r=this;return(r=t.call(this,e,n)||this).firestore=e,r._delegate=n,r}return(0,e.__extends)(n,t),Object.defineProperty(n.prototype,"id",{get:function(){return this._delegate.id},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"path",{get:function(){return this._delegate.path},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"parent",{get:function(){var t=this._delegate.parent;return t?new fc(this.firestore,t):null},enumerable:!1,configurable:!0}),n.prototype.doc=function(t){try{return new fc(this.firestore,void 0===t?Pa(this._delegate):Pa(this._delegate,t))}catch(t){throw lc(t,"doc()","CollectionReference.doc()")}},n.prototype.add=function(t){var e=this;return function(t,e){var n=Da(t.firestore,ja),r=Pa(t),i=Gu(t.converter,e);return Ju(n,[iu(ru(t.firestore),"addDoc",r._key,i,null!==t.converter,{}).toMutation(r._key,ue.exists(!1))]).then(function(){return r})}(this._delegate,t).then(function(t){return new fc(e.firestore,t)})},n.prototype.isEqual=function(t){return Fa(this._delegate,t._delegate)},n.prototype.withConverter=function(t){return new n(this.firestore,t?this._delegate.withConverter(hc.nu(this.firestore,t)):this._delegate.withConverter(null))},n}(mc);function bc(t){return Da(t,Ca)}exports.s=wc,exports.n=_c,exports.t=mc,exports.Z=vc,exports.X=yc;var Ic=function(){function t(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];this._delegate=new(Wa.bind.apply(Wa,(0,e.__spreadArray)([void 0],t)))}return t.documentId=function(){return new t(C.keyField().canonicalString())},t.prototype.isEqual=function(t){return(t=(0,n.getModularInstance)(t))instanceof Wa&&this._delegate._internalPath.isEqual(t._internalPath)},t}(),Ec=function(){function t(t){this._delegate=t}return t.serverTimestamp=function(){var e=new au("serverTimestamp");return e._methodName="FieldValue.serverTimestamp",new t(e)},t.delete=function(){var e=new ou("deleteField");return e._methodName="FieldValue.delete",new t(e)},t.arrayUnion=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return new uu("arrayUnion",t)}.apply(void 0,e);return r._methodName="FieldValue.arrayUnion",new t(r)},t.arrayRemove=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return new cu("arrayRemove",t)}.apply(void 0,e);return r._methodName="FieldValue.arrayRemove",new t(r)},t.increment=function(e){var n=new hu("increment",e);return n._methodName="FieldValue.increment",new t(n)},t.prototype.isEqual=function(t){return this._delegate.isEqual(t._delegate)},t}();function Tc(t){return function(t,n){var r=Ka(t=Da(t,ja)),i=new Ua;return function(t,n,r,i){var o=this,s=function(t,e){return function(t,e){return new Xs(t,e)}(function(t,e){if(t instanceof Uint8Array)return Ys(t,e);if(t instanceof ArrayBuffer)return Ys(new Uint8Array(t),e);if(t instanceof ReadableStream)return t.getReader();throw new Error("Source of `toByteStreamReader` has to be a ArrayBuffer or ReadableStream")}("string"==typeof t?(new TextEncoder).encode(t):t),e)}(r,ho(n));t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(o,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return n=Qs,[4,ua(t)];case 1:return n.apply(void 0,[e.sent(),s,i]),[2]}})})})}(r,t._databaseId,n,i),i}(this._delegate,t)}function Sc(t){var n,r,i=this;return(n=this._delegate,r=t,function(t,n){var r=this;return t.asyncQueue.enqueue(function(){return(0,e.__awaiter)(r,void 0,void 0,function(){var r;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return r=function(t,e){var n=m(t);return n.persistence.runTransaction("Get named query","readonly",function(t){return n.Ke.getNamedQuery(t,e)})},[4,sa(t)];case 1:return[2,r.apply(void 0,[e.sent(),n])]}})})})}(Ka(n=Da(n,ja)),r).then(function(t){return t?new Ra(n,null,t.query):null})).then(function(t){return t?new mc(i,t):null})}exports.o=Ec,exports.r=Ic;
494
- },{"tslib":"f2sD","@firebase/util":"KxmD","@firebase/logger":"TUpU","@firebase/webchannel-wrapper":"ueHA","process":"pBGv"}],"oyBH":[function(require,module,exports) {
495
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.registerFirestore=o;var e=i(require("@firebase/app")),r=require("./prebuilt-306f43d8-45d6f0b9.js"),t=require("@firebase/component");function i(e){return e&&e.__esModule?e:{default:e}}require("tslib"),require("@firebase/util"),require("@firebase/logger"),require("@firebase/webchannel-wrapper");var n={Firestore:r.U,GeoPoint:r.C,Timestamp:r.M,Blob:r.a,Transaction:r.j,WriteBatch:r.W,DocumentReference:r.z,DocumentSnapshot:r.X,Query:r.t,QueryDocumentSnapshot:r.Z,QuerySnapshot:r.n,CollectionReference:r.s,FieldPath:r.r,FieldValue:r.o,setLogLevel:r.Q,CACHE_SIZE_UNLIMITED:r.E};function o(e){!function(e,i){e.INTERNAL.registerComponent(new t.Component("firestore",function(e){return function(e,t){return new r.U(e,new r.T(e,t),new r.q)}(e.getProvider("app").getImmediate(),e.getProvider("auth-internal"))},"PUBLIC").setServiceProps(Object.assign({},n)))}(e),e.registerVersion("@firebase/firestore","2.4.0")}o(e.default);
496
- },{"@firebase/app":"VxYX","./prebuilt-306f43d8-45d6f0b9.js":"Emx5","@firebase/component":"sLOu","tslib":"f2sD","@firebase/util":"KxmD","@firebase/logger":"TUpU","@firebase/webchannel-wrapper":"ueHA"}],"vHL5":[function(require,module,exports) {
493
+ var t=require("process");Object.defineProperty(exports,"__esModule",{value:!0}),exports.Z=exports.W=exports.U=exports.T=exports.M=exports.L=exports.K=exports.H=exports.G=exports.E=exports.C=void 0,exports.a=Nc,exports.i=exports.e=exports.c=void 0,exports.j=uc,exports.t=exports.s=exports.o=void 0,exports.u=Sc;var e=require("tslib"),n=require("@firebase/util"),r=require("@firebase/logger"),i=require("@firebase/webchannel-wrapper");function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var s=function(){function t(t,e){var n=this;this.previousValue=t,e&&(e.sequenceNumberHandler=function(t){return n.t(t)},this.i=function(t){return e.writeSequenceNumber(t)})}return t.prototype.t=function(t){return this.previousValue=Math.max(t,this.previousValue),this.previousValue},t.prototype.next=function(){var t=++this.previousValue;return this.i&&this.i(t),t},t}();s.o=-1;var a={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"},u=function(t){function n(e,n){var r=this;return(r=t.call(this,n)||this).code=e,r.message=n,r.name="FirebaseError",r.toString=function(){return r.name+": [code="+r.code+"]: "+r.message},r}return(0,e.__extends)(n,t),n}(Error),c=new r.Logger("@firebase/firestore");function h(){return c.logLevel}function f(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];if(c.logLevel<=r.LogLevel.DEBUG){var o=n.map(p);c.debug.apply(c,(0,e.__spreadArray)(["Firestore (8.10.1): "+t],o))}}function l(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];if(c.logLevel<=r.LogLevel.ERROR){var o=n.map(p);c.error.apply(c,(0,e.__spreadArray)(["Firestore (8.10.1): "+t],o))}}function d(t){for(var n=[],i=1;i<arguments.length;i++)n[i-1]=arguments[i];if(c.logLevel<=r.LogLevel.WARN){var o=n.map(p);c.warn.apply(c,(0,e.__spreadArray)(["Firestore (8.10.1): "+t],o))}}function p(t){if("string"==typeof t)return t;try{return e=t,JSON.stringify(e)}catch(e){return t}var e}function y(t){void 0===t&&(t="Unexpected state");var e="FIRESTORE (8.10.1) INTERNAL ASSERTION FAILED: "+t;throw l(e),new Error(e)}function v(t,e){t||y()}function m(t,e){return t}function g(t){var e="undefined"!=typeof self&&(self.crypto||self.msCrypto),n=new Uint8Array(t);if(e&&"function"==typeof e.getRandomValues)e.getRandomValues(n);else for(var r=0;r<t;r++)n[r]=Math.floor(256*Math.random());return n}var _=function(){function t(){}return t.u=function(){for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",e=Math.floor(256/t.length)*t.length,n="";n.length<20;)for(var r=g(40),i=0;i<r.length;++i)n.length<20&&r[i]<e&&(n+=t.charAt(r[i]%t.length));return n},t}();function w(t,e){return t<e?-1:t>e?1:0}function b(t,e,n){return t.length===e.length&&t.every(function(t,r){return n(t,e[r])})}function I(t){return t+"\0"}var E=function(){function t(t,e){if(this.seconds=t,this.nanoseconds=e,e<0)throw new u(a.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+e);if(e>=1e9)throw new u(a.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+e);if(t<-62135596800)throw new u(a.INVALID_ARGUMENT,"Timestamp seconds out of range: "+t);if(t>=253402300800)throw new u(a.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,Math.floor(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._compareTo=function(t){return this.seconds===t.seconds?w(this.nanoseconds,t.nanoseconds):w(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.prototype.toJSON=function(){return{seconds:this.seconds,nanoseconds:this.nanoseconds}},t.prototype.valueOf=function(){var t=this.seconds- -62135596800;return String(t).padStart(12,"0")+"."+String(this.nanoseconds).padStart(9,"0")},t}(),T=function(){function t(t){this.timestamp=t}return t.fromTimestamp=function(e){return new t(e)},t.min=function(){return new t(new E(0,0))},t.prototype.compareTo=function(t){return this.timestamp._compareTo(t.timestamp)},t.prototype.isEqual=function(t){return this.timestamp.isEqual(t.timestamp)},t.prototype.toMicroseconds=function(){return 1e6*this.timestamp.seconds+this.timestamp.nanoseconds/1e3},t.prototype.toString=function(){return"SnapshotVersion("+this.timestamp.toString()+")"},t.prototype.toTimestamp=function(){return this.timestamp},t}();function S(t){var e=0;for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e++;return e}function N(t,e){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e(n,t[n])}function D(t){for(var e in t)if(Object.prototype.hasOwnProperty.call(t,e))return!1;return!0}exports.M=E;var A=function(){function t(t,e,n){void 0===e?e=0:e>t.length&&y(),void 0===n?n=t.length-e:n>t.length-e&&y(),this.segments=t,this.offset=e,this.len=n}return Object.defineProperty(t.prototype,"length",{get:function(){return this.len},enumerable:!1,configurable:!0}),t.prototype.isEqual=function(e){return 0===t.comparator(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.construct(n)},t.prototype.limit=function(){return this.offset+this.length},t.prototype.popFirst=function(t){return t=void 0===t?1:t,this.construct(this.segments,this.offset+t,this.length-t)},t.prototype.popLast=function(){return this.construct(this.segments,this.offset,this.length-1)},t.prototype.firstSegment=function(){return this.segments[this.offset]},t.prototype.lastSegment=function(){return this.get(this.length-1)},t.prototype.get=function(t){return this.segments[this.offset+t]},t.prototype.isEmpty=function(){return 0===this.length},t.prototype.isPrefixOf=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.isImmediateParentOf=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.toArray=function(){return this.segments.slice(this.offset,this.limit())},t.comparator=function(t,e){for(var n=Math.min(t.length,e.length),r=0;r<n;r++){var i=t.get(r),o=e.get(r);if(i<o)return-1;if(i>o)return 1}return t.length<e.length?-1:t.length>e.length?1:0},t}(),x=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return(0,e.__extends)(n,t),n.prototype.construct=function(t,e,r){return new n(t,e,r)},n.prototype.canonicalString=function(){return this.toArray().join("/")},n.prototype.toString=function(){return this.canonicalString()},n.fromString=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];for(var r=[],i=0,o=t;i<o.length;i++){var s=o[i];if(s.indexOf("//")>=0)throw new u(a.INVALID_ARGUMENT,"Invalid segment ("+s+"). Paths must not contain // in them.");r.push.apply(r,s.split("/").filter(function(t){return t.length>0}))}return new n(r)},n.emptyPath=function(){return new n([])},n}(A),k=/^[_a-zA-Z][_a-zA-Z0-9]*$/,C=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return(0,e.__extends)(n,t),n.prototype.construct=function(t,e,r){return new n(t,e,r)},n.isValidIdentifier=function(t){return k.test(t)},n.prototype.canonicalString=function(){return this.toArray().map(function(t){return t=t.replace(/\\/g,"\\\\").replace(/`/g,"\\`"),n.isValidIdentifier(t)||(t="`"+t+"`"),t}).join(".")},n.prototype.toString=function(){return this.canonicalString()},n.prototype.isKeyField=function(){return 1===this.length&&"__name__"===this.get(0)},n.keyField=function(){return new n(["__name__"])},n.fromServerFormat=function(t){for(var e=[],r="",i=0,o=function(){if(0===r.length)throw new u(a.INVALID_ARGUMENT,"Invalid field path ("+t+"). Paths must not be empty, begin with '.', end with '.', or contain '..'");e.push(r),r=""},s=!1;i<t.length;){var c=t[i];if("\\"===c){if(i+1===t.length)throw new u(a.INVALID_ARGUMENT,"Path has trailing escape character: "+t);var h=t[i+1];if("\\"!==h&&"."!==h&&"`"!==h)throw new u(a.INVALID_ARGUMENT,"Path has invalid escape sequence: "+t);r+=h,i+=2}else"`"===c?(s=!s,i++):"."!==c||s?(r+=c,i++):(o(),i++)}if(o(),s)throw new u(a.INVALID_ARGUMENT,"Unterminated ` in path: "+t);return new n(e)},n.emptyPath=function(){return new n([])},n}(A),R=function(){function t(t){this.fields=t,t.sort(C.comparator)}return t.prototype.covers=function(t){for(var e=0,n=this.fields;e<n.length;e++)if(n[e].isPrefixOf(t))return!0;return!1},t.prototype.isEqual=function(t){return b(this.fields,t.fields,function(t,e){return t.isEqual(e)})},t}(),L=function(){function t(t){this.binaryString=t}return t.fromBase64String=function(e){return new t(atob(e))},t.fromUint8Array=function(e){return new t(function(t){for(var e="",n=0;n<t.length;++n)e+=String.fromCharCode(t[n]);return e}(e))},t.prototype.toBase64=function(){return t=this.binaryString,btoa(t);var t},t.prototype.toUint8Array=function(){return function(t){for(var e=new Uint8Array(t.length),n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return e}(this.binaryString)},t.prototype.approximateByteSize=function(){return 2*this.binaryString.length},t.prototype.compareTo=function(t){return w(this.binaryString,t.binaryString)},t.prototype.isEqual=function(t){return this.binaryString===t.binaryString},t}();L.EMPTY_BYTE_STRING=new L("");var O=new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);function P(t){if(v(!!t),"string"==typeof t){var e=0,n=O.exec(t);if(v(!!n),n[1]){var r=n[1];r=(r+"000000000").substr(0,9),e=Number(r)}var i=new Date(t);return{seconds:Math.floor(i.getTime()/1e3),nanos:e}}return{seconds:F(t.seconds),nanos:F(t.nanos)}}function F(t){return"number"==typeof t?t:"string"==typeof t?Number(t):0}function M(t){return"string"==typeof t?L.fromBase64String(t):L.fromUint8Array(t)}function V(t){var e,n;return"server_timestamp"===(null===(n=((null===(e=null==t?void 0:t.mapValue)||void 0===e?void 0:e.fields)||{}).__type__)||void 0===n?void 0:n.stringValue)}function q(t){var e=t.mapValue.fields.__previous_value__;return V(e)?q(e):e}function U(t){var e=P(t.mapValue.fields.__local_write_time__.timestampValue);return new E(e.seconds,e.nanos)}function B(t){return null==t}function j(t){return 0===t&&1/t==-1/0}function K(t){return"number"==typeof t&&Number.isInteger(t)&&!j(t)&&t<=Number.MAX_SAFE_INTEGER&&t>=Number.MIN_SAFE_INTEGER}var G=function(){function t(t){this.path=t}return t.fromPath=function(e){return new t(x.fromString(e))},t.fromName=function(e){return new t(x.fromString(e).popFirst(5))},t.prototype.hasCollectionId=function(t){return this.path.length>=2&&this.path.get(this.path.length-2)===t},t.prototype.isEqual=function(t){return null!==t&&0===x.comparator(this.path,t.path)},t.prototype.toString=function(){return this.path.toString()},t.comparator=function(t,e){return x.comparator(t.path,e.path)},t.isDocumentKey=function(t){return t.length%2==0},t.fromSegments=function(e){return new t(new x(e.slice()))},t}();function Q(t){return"nullValue"in t?0:"booleanValue"in t?1:"integerValue"in t||"doubleValue"in t?2:"timestampValue"in t?3:"stringValue"in t?5:"bytesValue"in t?6:"referenceValue"in t?7:"geoPointValue"in t?8:"arrayValue"in t?9:"mapValue"in t?V(t)?4:10:y()}function z(t,e){var n=Q(t);if(n!==Q(e))return!1;switch(n){case 0:return!0;case 1:return t.booleanValue===e.booleanValue;case 4:return U(t).isEqual(U(e));case 3:return function(t,e){if("string"==typeof t.timestampValue&&"string"==typeof e.timestampValue&&t.timestampValue.length===e.timestampValue.length)return t.timestampValue===e.timestampValue;var n=P(t.timestampValue),r=P(e.timestampValue);return n.seconds===r.seconds&&n.nanos===r.nanos}(t,e);case 5:return t.stringValue===e.stringValue;case 6:return function(t,e){return M(t.bytesValue).isEqual(M(e.bytesValue))}(t,e);case 7:return t.referenceValue===e.referenceValue;case 8:return function(t,e){return F(t.geoPointValue.latitude)===F(e.geoPointValue.latitude)&&F(t.geoPointValue.longitude)===F(e.geoPointValue.longitude)}(t,e);case 2:return function(t,e){if("integerValue"in t&&"integerValue"in e)return F(t.integerValue)===F(e.integerValue);if("doubleValue"in t&&"doubleValue"in e){var n=F(t.doubleValue),r=F(e.doubleValue);return n===r?j(n)===j(r):isNaN(n)&&isNaN(r)}return!1}(t,e);case 9:return b(t.arrayValue.values||[],e.arrayValue.values||[],z);case 10:return function(t,e){var n=t.mapValue.fields||{},r=e.mapValue.fields||{};if(S(n)!==S(r))return!1;for(var i in n)if(n.hasOwnProperty(i)&&(void 0===r[i]||!z(n[i],r[i])))return!1;return!0}(t,e);default:return y()}}function W(t,e){return void 0!==(t.values||[]).find(function(t){return z(t,e)})}function H(t,e){var n=Q(t),r=Q(e);if(n!==r)return w(n,r);switch(n){case 0:return 0;case 1:return w(t.booleanValue,e.booleanValue);case 2:return function(t,e){var n=F(t.integerValue||t.doubleValue),r=F(e.integerValue||e.doubleValue);return n<r?-1:n>r?1:n===r?0:isNaN(n)?isNaN(r)?0:-1:1}(t,e);case 3:return Y(t.timestampValue,e.timestampValue);case 4:return Y(U(t),U(e));case 5:return w(t.stringValue,e.stringValue);case 6:return function(t,e){var n=M(t),r=M(e);return n.compareTo(r)}(t.bytesValue,e.bytesValue);case 7:return function(t,e){for(var n=t.split("/"),r=e.split("/"),i=0;i<n.length&&i<r.length;i++){var o=w(n[i],r[i]);if(0!==o)return o}return w(n.length,r.length)}(t.referenceValue,e.referenceValue);case 8:return function(t,e){var n=w(F(t.latitude),F(e.latitude));return 0!==n?n:w(F(t.longitude),F(e.longitude))}(t.geoPointValue,e.geoPointValue);case 9:return function(t,e){for(var n=t.values||[],r=e.values||[],i=0;i<n.length&&i<r.length;++i){var o=H(n[i],r[i]);if(o)return o}return w(n.length,r.length)}(t.arrayValue,e.arrayValue);case 10:return function(t,e){var n=t.fields||{},r=Object.keys(n),i=e.fields||{},o=Object.keys(i);r.sort(),o.sort();for(var s=0;s<r.length&&s<o.length;++s){var a=w(r[s],o[s]);if(0!==a)return a;var u=H(n[r[s]],i[o[s]]);if(0!==u)return u}return w(r.length,o.length)}(t.mapValue,e.mapValue);default:throw y()}}function Y(t,e){if("string"==typeof t&&"string"==typeof e&&t.length===e.length)return w(t,e);var n=P(t),r=P(e),i=w(n.seconds,r.seconds);return 0!==i?i:w(n.nanos,r.nanos)}function $(t){return X(t)}function X(t){return"nullValue"in t?"null":"booleanValue"in t?""+t.booleanValue:"integerValue"in t?""+t.integerValue:"doubleValue"in t?""+t.doubleValue:"timestampValue"in t?function(t){var e=P(t);return"time("+e.seconds+","+e.nanos+")"}(t.timestampValue):"stringValue"in t?t.stringValue:"bytesValue"in t?M(t.bytesValue).toBase64():"referenceValue"in t?(n=t.referenceValue,G.fromName(n).toString()):"geoPointValue"in t?"geo("+(e=t.geoPointValue).latitude+","+e.longitude+")":"arrayValue"in t?function(t){for(var e="[",n=!0,r=0,i=t.values||[];r<i.length;r++)n?n=!1:e+=",",e+=X(i[r]);return e+"]"}(t.arrayValue):"mapValue"in t?function(t){for(var e="{",n=!0,r=0,i=Object.keys(t.fields||{}).sort();r<i.length;r++){var o=i[r];n?n=!1:e+=",",e+=o+":"+X(t.fields[o])}return e+"}"}(t.mapValue):y();var e,n}function J(t,e){return{referenceValue:"projects/"+t.projectId+"/databases/"+t.database+"/documents/"+e.path.canonicalString()}}function Z(t){return!!t&&"integerValue"in t}function tt(t){return!!t&&"arrayValue"in t}function et(t){return!!t&&"nullValue"in t}function nt(t){return!!t&&"doubleValue"in t&&isNaN(Number(t.doubleValue))}function rt(t){return!!t&&"mapValue"in t}function it(t){if(t.geoPointValue)return{geoPointValue:Object.assign({},t.geoPointValue)};if(t.timestampValue&&"object"==o(t.timestampValue))return{timestampValue:Object.assign({},t.timestampValue)};if(t.mapValue){var e={mapValue:{fields:{}}};return N(t.mapValue.fields,function(t,n){return e.mapValue.fields[t]=it(n)}),e}if(t.arrayValue){for(var n={arrayValue:{values:[]}},r=0;r<(t.arrayValue.values||[]).length;++r)n.arrayValue.values[r]=it(t.arrayValue.values[r]);return n}return Object.assign({},t)}var ot=function(){function t(t){this.value=t}return t.empty=function(){return new t({mapValue:{}})},t.prototype.field=function(t){if(t.isEmpty())return this.value;for(var e=this.value,n=0;n<t.length-1;++n)if(!rt(e=(e.mapValue.fields||{})[t.get(n)]))return null;return(e=(e.mapValue.fields||{})[t.lastSegment()])||null},t.prototype.set=function(t,e){this.getFieldsMap(t.popLast())[t.lastSegment()]=it(e)},t.prototype.setAll=function(t){var e=this,n=C.emptyPath(),r={},i=[];t.forEach(function(t,o){if(!n.isImmediateParentOf(o)){var s=e.getFieldsMap(n);e.applyChanges(s,r,i),r={},i=[],n=o.popLast()}t?r[o.lastSegment()]=it(t):i.push(o.lastSegment())});var o=this.getFieldsMap(n);this.applyChanges(o,r,i)},t.prototype.delete=function(t){var e=this.field(t.popLast());rt(e)&&e.mapValue.fields&&delete e.mapValue.fields[t.lastSegment()]},t.prototype.isEqual=function(t){return z(this.value,t.value)},t.prototype.getFieldsMap=function(t){var e=this.value;e.mapValue.fields||(e.mapValue={fields:{}});for(var n=0;n<t.length;++n){var r=e.mapValue.fields[t.get(n)];rt(r)&&r.mapValue.fields||(r={mapValue:{fields:{}}},e.mapValue.fields[t.get(n)]=r),e=r}return e.mapValue.fields},t.prototype.applyChanges=function(t,e,n){N(e,function(e,n){return t[e]=n});for(var r=0,i=n;r<i.length;r++){var o=i[r];delete t[o]}},t.prototype.clone=function(){return new t(it(this.value))},t}();function st(t){var e=[];return N(t.fields,function(t,n){var r=new C([t]);if(rt(n)){var i=st(n.mapValue).fields;if(0===i.length)e.push(r);else for(var o=0,s=i;o<s.length;o++){var a=s[o];e.push(r.child(a))}}else e.push(r)}),new R(e)}var at=function(){function t(t,e,n,r,i){this.key=t,this.documentType=e,this.version=n,this.data=r,this.documentState=i}return t.newInvalidDocument=function(e){return new t(e,0,T.min(),ot.empty(),0)},t.newFoundDocument=function(e,n,r){return new t(e,1,n,r,0)},t.newNoDocument=function(e,n){return new t(e,2,n,ot.empty(),0)},t.newUnknownDocument=function(e,n){return new t(e,3,n,ot.empty(),2)},t.prototype.convertToFoundDocument=function(t,e){return this.version=t,this.documentType=1,this.data=e,this.documentState=0,this},t.prototype.convertToNoDocument=function(t){return this.version=t,this.documentType=2,this.data=ot.empty(),this.documentState=0,this},t.prototype.convertToUnknownDocument=function(t){return this.version=t,this.documentType=3,this.data=ot.empty(),this.documentState=2,this},t.prototype.setHasCommittedMutations=function(){return this.documentState=2,this},t.prototype.setHasLocalMutations=function(){return this.documentState=1,this},Object.defineProperty(t.prototype,"hasLocalMutations",{get:function(){return 1===this.documentState},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hasCommittedMutations",{get:function(){return 2===this.documentState},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"hasPendingWrites",{get:function(){return this.hasLocalMutations||this.hasCommittedMutations},enumerable:!1,configurable:!0}),t.prototype.isValidDocument=function(){return 0!==this.documentType},t.prototype.isFoundDocument=function(){return 1===this.documentType},t.prototype.isNoDocument=function(){return 2===this.documentType},t.prototype.isUnknownDocument=function(){return 3===this.documentType},t.prototype.isEqual=function(e){return e instanceof t&&this.key.isEqual(e.key)&&this.version.isEqual(e.version)&&this.documentType===e.documentType&&this.documentState===e.documentState&&this.data.isEqual(e.data)},t.prototype.clone=function(){return new t(this.key,this.documentType,this.version,this.data.clone(),this.documentState)},t.prototype.toString=function(){return"Document("+this.key+", "+this.version+", "+JSON.stringify(this.data.value)+", {documentType: "+this.documentType+"}), {documentState: "+this.documentState+"})"},t}(),ut=function(t,e,n,r,i,o,s){void 0===e&&(e=null),void 0===n&&(n=[]),void 0===r&&(r=[]),void 0===i&&(i=null),void 0===o&&(o=null),void 0===s&&(s=null),this.path=t,this.collectionGroup=e,this.orderBy=n,this.filters=r,this.limit=i,this.startAt=o,this.endAt=s,this.h=null};function ct(t,e,n,r,i,o,s){return void 0===e&&(e=null),void 0===n&&(n=[]),void 0===r&&(r=[]),void 0===i&&(i=null),void 0===o&&(o=null),void 0===s&&(s=null),new ut(t,e,n,r,i,o,s)}function ht(t){var e=m(t);if(null===e.h){var n=e.path.canonicalString();null!==e.collectionGroup&&(n+="|cg:"+e.collectionGroup),n+="|f:",n+=e.filters.map(function(t){return function(t){return t.field.canonicalString()+t.op.toString()+$(t.value)}(t)}).join(","),n+="|ob:",n+=e.orderBy.map(function(t){return function(t){return t.field.canonicalString()+t.dir}(t)}).join(","),B(e.limit)||(n+="|l:",n+=e.limit),e.startAt&&(n+="|lb:",n+=Et(e.startAt)),e.endAt&&(n+="|ub:",n+=Et(e.endAt)),e.h=n}return e.h}function ft(t,e){if(t.limit!==e.limit)return!1;if(t.orderBy.length!==e.orderBy.length)return!1;for(var n=0;n<t.orderBy.length;n++)if(!St(t.orderBy[n],e.orderBy[n]))return!1;if(t.filters.length!==e.filters.length)return!1;for(var r=0;r<t.filters.length;r++)if(i=t.filters[r],o=e.filters[r],i.op!==o.op||!i.field.isEqual(o.field)||!z(i.value,o.value))return!1;var i,o;return t.collectionGroup===e.collectionGroup&&!!t.path.isEqual(e.path)&&!!Dt(t.startAt,e.startAt)&&Dt(t.endAt,e.endAt)}function lt(t){return G.isDocumentKey(t.path)&&null===t.collectionGroup&&0===t.filters.length}var dt=function(t){function n(e,n,r){var i=this;return(i=t.call(this)||this).field=e,i.op=n,i.value=r,i}return(0,e.__extends)(n,t),n.create=function(t,e,r){return t.isKeyField()?"in"===e||"not-in"===e?this.l(t,e,r):new pt(t,e,r):"array-contains"===e?new gt(t,r):"in"===e?new _t(t,r):"not-in"===e?new wt(t,r):"array-contains-any"===e?new bt(t,r):new n(t,e,r)},n.l=function(t,e,n){return"in"===e?new yt(t,n):new vt(t,n)},n.prototype.matches=function(t){var e=t.data.field(this.field);return"!="===this.op?null!==e&&this.m(H(e,this.value)):null!==e&&Q(this.value)===Q(e)&&this.m(H(e,this.value))},n.prototype.m=function(t){switch(this.op){case"<":return t<0;case"<=":return t<=0;case"==":return 0===t;case"!=":return 0!==t;case">":return t>0;case">=":return t>=0;default:return y()}},n.prototype.g=function(){return["<","<=",">",">=","!=","not-in"].indexOf(this.op)>=0},n}(function(){}),pt=function(t){function n(e,n,r){var i=this;return(i=t.call(this,e,n,r)||this).key=G.fromName(r.referenceValue),i}return(0,e.__extends)(n,t),n.prototype.matches=function(t){var e=G.comparator(t.key,this.key);return this.m(e)},n}(dt),yt=function(t){function n(e,n){var r=this;return(r=t.call(this,e,"in",n)||this).keys=mt("in",n),r}return(0,e.__extends)(n,t),n.prototype.matches=function(t){return this.keys.some(function(e){return e.isEqual(t.key)})},n}(dt),vt=function(t){function n(e,n){var r=this;return(r=t.call(this,e,"not-in",n)||this).keys=mt("not-in",n),r}return(0,e.__extends)(n,t),n.prototype.matches=function(t){return!this.keys.some(function(e){return e.isEqual(t.key)})},n}(dt);function mt(t,e){var n;return((null===(n=e.arrayValue)||void 0===n?void 0:n.values)||[]).map(function(t){return G.fromName(t.referenceValue)})}var gt=function(t){function n(e,n){return t.call(this,e,"array-contains",n)||this}return(0,e.__extends)(n,t),n.prototype.matches=function(t){var e=t.data.field(this.field);return tt(e)&&W(e.arrayValue,this.value)},n}(dt),_t=function(t){function n(e,n){return t.call(this,e,"in",n)||this}return(0,e.__extends)(n,t),n.prototype.matches=function(t){var e=t.data.field(this.field);return null!==e&&W(this.value.arrayValue,e)},n}(dt),wt=function(t){function n(e,n){return t.call(this,e,"not-in",n)||this}return(0,e.__extends)(n,t),n.prototype.matches=function(t){if(W(this.value.arrayValue,{nullValue:"NULL_VALUE"}))return!1;var e=t.data.field(this.field);return null!==e&&!W(this.value.arrayValue,e)},n}(dt),bt=function(t){function n(e,n){return t.call(this,e,"array-contains-any",n)||this}return(0,e.__extends)(n,t),n.prototype.matches=function(t){var e=this,n=t.data.field(this.field);return!(!tt(n)||!n.arrayValue.values)&&n.arrayValue.values.some(function(t){return W(e.value.arrayValue,t)})},n}(dt),It=function(t,e){this.position=t,this.before=e};function Et(t){return(t.before?"b":"a")+":"+t.position.map(function(t){return $(t)}).join(",")}var Tt=function(t,e){void 0===e&&(e="asc"),this.field=t,this.dir=e};function St(t,e){return t.dir===e.dir&&t.field.isEqual(e.field)}function Nt(t,e,n){for(var r=0,i=0;i<t.position.length;i++){var o=e[i],s=t.position[i];if(r=o.field.isKeyField()?G.comparator(G.fromName(s.referenceValue),n.key):H(s,n.data.field(o.field)),"desc"===o.dir&&(r*=-1),0!==r)break}return t.before?r<=0:r<0}function Dt(t,e){if(null===t)return null===e;if(null===e)return!1;if(t.before!==e.before||t.position.length!==e.position.length)return!1;for(var n=0;n<t.position.length;n++)if(!z(t.position[n],e.position[n]))return!1;return!0}var At=function(t,e,n,r,i,o,s,a){void 0===e&&(e=null),void 0===n&&(n=[]),void 0===r&&(r=[]),void 0===i&&(i=null),void 0===o&&(o="F"),void 0===s&&(s=null),void 0===a&&(a=null),this.path=t,this.collectionGroup=e,this.explicitOrderBy=n,this.filters=r,this.limit=i,this.limitType=o,this.startAt=s,this.endAt=a,this.p=null,this.T=null,this.startAt,this.endAt};function xt(t,e,n,r,i,o,s,a){return new At(t,e,n,r,i,o,s,a)}function kt(t){return new At(t)}function Ct(t){return!B(t.limit)&&"F"===t.limitType}function Rt(t){return!B(t.limit)&&"L"===t.limitType}function Lt(t){return t.explicitOrderBy.length>0?t.explicitOrderBy[0].field:null}function Ot(t){for(var e=0,n=t.filters;e<n.length;e++){var r=n[e];if(r.g())return r.field}return null}function Pt(t){return null!==t.collectionGroup}function Ft(t){var e=m(t);if(null===e.p){e.p=[];var n=Ot(e),r=Lt(e);if(null!==n&&null===r)n.isKeyField()||e.p.push(new Tt(n)),e.p.push(new Tt(C.keyField(),"asc"));else{for(var i=!1,o=0,s=e.explicitOrderBy;o<s.length;o++){var a=s[o];e.p.push(a),a.field.isKeyField()&&(i=!0)}if(!i){var u=e.explicitOrderBy.length>0?e.explicitOrderBy[e.explicitOrderBy.length-1].dir:"asc";e.p.push(new Tt(C.keyField(),u))}}}return e.p}function Mt(t){var e=m(t);if(!e.T)if("F"===e.limitType)e.T=ct(e.path,e.collectionGroup,Ft(e),e.filters,e.limit,e.startAt,e.endAt);else{for(var n=[],r=0,i=Ft(e);r<i.length;r++){var o=i[r],s="desc"===o.dir?"asc":"desc";n.push(new Tt(o.field,s))}var a=e.endAt?new It(e.endAt.position,!e.endAt.before):null,u=e.startAt?new It(e.startAt.position,!e.startAt.before):null;e.T=ct(e.path,e.collectionGroup,n,e.filters,e.limit,a,u)}return e.T}function Vt(t,e,n){return new At(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),e,n,t.startAt,t.endAt)}function qt(t,e){return ft(Mt(t),Mt(e))&&t.limitType===e.limitType}function Ut(t){return ht(Mt(t))+"|lt:"+t.limitType}function Bt(t){return"Query(target="+function(t){var e=t.path.canonicalString();return null!==t.collectionGroup&&(e+=" collectionGroup="+t.collectionGroup),t.filters.length>0&&(e+=", filters: ["+t.filters.map(function(t){return(e=t).field.canonicalString()+" "+e.op+" "+$(e.value);var e}).join(", ")+"]"),B(t.limit)||(e+=", limit: "+t.limit),t.orderBy.length>0&&(e+=", orderBy: ["+t.orderBy.map(function(t){return function(t){return t.field.canonicalString()+" ("+t.dir+")"}(t)}).join(", ")+"]"),t.startAt&&(e+=", startAt: "+Et(t.startAt)),t.endAt&&(e+=", endAt: "+Et(t.endAt)),"Target("+e+")"}(Mt(t))+"; limitType="+t.limitType+")"}function jt(t,e){return e.isFoundDocument()&&function(t,e){var n=e.key.path;return null!==t.collectionGroup?e.key.hasCollectionId(t.collectionGroup)&&t.path.isPrefixOf(n):G.isDocumentKey(t.path)?t.path.isEqual(n):t.path.isImmediateParentOf(n)}(t,e)&&function(t,e){for(var n=0,r=t.explicitOrderBy;n<r.length;n++){var i=r[n];if(!i.field.isKeyField()&&null===e.data.field(i.field))return!1}return!0}(t,e)&&function(t,e){for(var n=0,r=t.filters;n<r.length;n++)if(!r[n].matches(e))return!1;return!0}(t,e)&&function(t,e){return!(t.startAt&&!Nt(t.startAt,Ft(t),e)||t.endAt&&Nt(t.endAt,Ft(t),e))}(t,e)}function Kt(t){return function(e,n){for(var r=!1,i=0,o=Ft(t);i<o.length;i++){var s=o[i],a=Gt(s,e,n);if(0!==a)return a;r=r||s.field.isKeyField()}return 0}}function Gt(t,e,n){var r=t.field.isKeyField()?G.comparator(e.key,n.key):function(t,e,n){var r=e.data.field(t),i=n.data.field(t);return null!==r&&null!==i?H(r,i):y()}(t.field,e,n);switch(t.dir){case"asc":return r;case"desc":return-1*r;default:return y()}}function Qt(t,e){if(t.I){if(isNaN(e))return{doubleValue:"NaN"};if(e===1/0)return{doubleValue:"Infinity"};if(e===-1/0)return{doubleValue:"-Infinity"}}return{doubleValue:j(e)?"-0":e}}function zt(t){return{integerValue:""+t}}function Wt(t,e){return K(e)?zt(e):Qt(t,e)}var Ht=function(){this._=void 0};function Yt(t,e,n){return t instanceof Jt?function(t,e){var n={fields:{__type__:{stringValue:"server_timestamp"},__local_write_time__:{timestampValue:{seconds:t.seconds,nanos:t.nanoseconds}}}};return e&&(n.fields.__previous_value__=e),{mapValue:n}}(n,e):t instanceof Zt?te(t,e):t instanceof ee?ne(t,e):function(t,e){var n=Xt(t,e),r=ie(n)+ie(t.A);return Z(n)&&Z(t.A)?zt(r):Qt(t.R,r)}(t,e)}function $t(t,e,n){return t instanceof Zt?te(t,e):t instanceof ee?ne(t,e):n}function Xt(t,e){return t instanceof re?Z(n=e)||n&&"doubleValue"in n?e:{integerValue:0}:null;var n}var Jt=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return(0,e.__extends)(n,t),n}(Ht),Zt=function(t){function n(e){var n=this;return(n=t.call(this)||this).elements=e,n}return(0,e.__extends)(n,t),n}(Ht);function te(t,e){for(var n=oe(e),r=function(t){n.some(function(e){return z(e,t)})||n.push(t)},i=0,o=t.elements;i<o.length;i++)r(o[i]);return{arrayValue:{values:n}}}var ee=function(t){function n(e){var n=this;return(n=t.call(this)||this).elements=e,n}return(0,e.__extends)(n,t),n}(Ht);function ne(t,e){for(var n=oe(e),r=function(t){n=n.filter(function(e){return!z(e,t)})},i=0,o=t.elements;i<o.length;i++)r(o[i]);return{arrayValue:{values:n}}}var re=function(t){function n(e,n){var r=this;return(r=t.call(this)||this).R=e,r.A=n,r}return(0,e.__extends)(n,t),n}(Ht);function ie(t){return F(t.integerValue||t.doubleValue)}function oe(t){return tt(t)&&t.arrayValue.values?t.arrayValue.values.slice():[]}var se=function(t,e){this.field=t,this.transform=e},ae=function(t,e){this.version=t,this.transformResults=e},ue=function(){function t(t,e){this.updateTime=t,this.exists=e}return t.none=function(){return new t},t.exists=function(e){return new t(void 0,e)},t.updateTime=function(e){return new t(e)},Object.defineProperty(t.prototype,"isNone",{get:function(){return void 0===this.updateTime&&void 0===this.exists},enumerable:!1,configurable:!0}),t.prototype.isEqual=function(t){return this.exists===t.exists&&(this.updateTime?!!t.updateTime&&this.updateTime.isEqual(t.updateTime):!t.updateTime)},t}();function ce(t,e){return void 0!==t.updateTime?e.isFoundDocument()&&e.version.isEqual(t.updateTime):void 0===t.exists||t.exists===e.isFoundDocument()}var he=function(){};function fe(t,e,n){t instanceof ve?function(t,e,n){var r=t.value.clone(),i=_e(t.fieldTransforms,e,n.transformResults);r.setAll(i),e.convertToFoundDocument(n.version,r).setHasCommittedMutations()}(t,e,n):t instanceof me?function(t,e,n){if(ce(t.precondition,e)){var r=_e(t.fieldTransforms,e,n.transformResults),i=e.data;i.setAll(ge(t)),i.setAll(r),e.convertToFoundDocument(n.version,i).setHasCommittedMutations()}else e.convertToUnknownDocument(n.version)}(t,e,n):function(t,e,n){e.convertToNoDocument(n.version).setHasCommittedMutations()}(0,e,n)}function le(t,e,n){t instanceof ve?function(t,e,n){if(ce(t.precondition,e)){var r=t.value.clone(),i=we(t.fieldTransforms,n,e);r.setAll(i),e.convertToFoundDocument(ye(e),r).setHasLocalMutations()}}(t,e,n):t instanceof me?function(t,e,n){if(ce(t.precondition,e)){var r=we(t.fieldTransforms,n,e),i=e.data;i.setAll(ge(t)),i.setAll(r),e.convertToFoundDocument(ye(e),i).setHasLocalMutations()}}(t,e,n):function(t,e){ce(t.precondition,e)&&e.convertToNoDocument(T.min())}(t,e)}function de(t,e){for(var n=null,r=0,i=t.fieldTransforms;r<i.length;r++){var o=i[r],s=e.data.field(o.field),a=Xt(o.transform,s||null);null!=a&&(null==n&&(n=ot.empty()),n.set(o.field,a))}return n||null}function pe(t,e){return t.type===e.type&&!!t.key.isEqual(e.key)&&!!t.precondition.isEqual(e.precondition)&&!!function(t,e){return void 0===t&&void 0===e||!(!t||!e)&&b(t,e,function(t,e){return function(t,e){return t.field.isEqual(e.field)&&function(t,e){return t instanceof Zt&&e instanceof Zt||t instanceof ee&&e instanceof ee?b(t.elements,e.elements,z):t instanceof re&&e instanceof re?z(t.A,e.A):t instanceof Jt&&e instanceof Jt}(t.transform,e.transform)}(t,e)})}(t.fieldTransforms,e.fieldTransforms)&&(0===t.type?t.value.isEqual(e.value):1!==t.type||t.data.isEqual(e.data)&&t.fieldMask.isEqual(e.fieldMask))}function ye(t){return t.isFoundDocument()?t.version:T.min()}var ve=function(t){function n(e,n,r,i){void 0===i&&(i=[]);var o=this;return(o=t.call(this)||this).key=e,o.value=n,o.precondition=r,o.fieldTransforms=i,o.type=0,o}return(0,e.__extends)(n,t),n}(he),me=function(t){function n(e,n,r,i,o){void 0===o&&(o=[]);var s=this;return(s=t.call(this)||this).key=e,s.data=n,s.fieldMask=r,s.precondition=i,s.fieldTransforms=o,s.type=1,s}return(0,e.__extends)(n,t),n}(he);function ge(t){var e=new Map;return t.fieldMask.fields.forEach(function(n){if(!n.isEmpty()){var r=t.data.field(n);e.set(n,r)}}),e}function _e(t,e,n){var r=new Map;v(t.length===n.length);for(var i=0;i<n.length;i++){var o=t[i],s=o.transform,a=e.data.field(o.field);r.set(o.field,$t(s,a,n[i]))}return r}function we(t,e,n){for(var r=new Map,i=0,o=t;i<o.length;i++){var s=o[i],a=s.transform,u=n.data.field(s.field);r.set(s.field,Yt(a,u,e))}return r}var be,Ie,Ee=function(t){function n(e,n){var r=this;return(r=t.call(this)||this).key=e,r.precondition=n,r.type=2,r.fieldTransforms=[],r}return(0,e.__extends)(n,t),n}(he),Te=function(t){function n(e,n){var r=this;return(r=t.call(this)||this).key=e,r.precondition=n,r.type=3,r.fieldTransforms=[],r}return(0,e.__extends)(n,t),n}(he),Se=function(t){this.count=t};function Ne(t){switch(t){case a.OK:return y();case a.CANCELLED:case a.UNKNOWN:case a.DEADLINE_EXCEEDED:case a.RESOURCE_EXHAUSTED:case a.INTERNAL:case a.UNAVAILABLE:case a.UNAUTHENTICATED:return!1;case a.INVALID_ARGUMENT:case a.NOT_FOUND:case a.ALREADY_EXISTS:case a.PERMISSION_DENIED:case a.FAILED_PRECONDITION:case a.ABORTED:case a.OUT_OF_RANGE:case a.UNIMPLEMENTED:case a.DATA_LOSS:return!0;default:return y()}}function De(t){if(void 0===t)return l("GRPC error has no .code"),a.UNKNOWN;switch(t){case be.OK:return a.OK;case be.CANCELLED:return a.CANCELLED;case be.UNKNOWN:return a.UNKNOWN;case be.DEADLINE_EXCEEDED:return a.DEADLINE_EXCEEDED;case be.RESOURCE_EXHAUSTED:return a.RESOURCE_EXHAUSTED;case be.INTERNAL:return a.INTERNAL;case be.UNAVAILABLE:return a.UNAVAILABLE;case be.UNAUTHENTICATED:return a.UNAUTHENTICATED;case be.INVALID_ARGUMENT:return a.INVALID_ARGUMENT;case be.NOT_FOUND:return a.NOT_FOUND;case be.ALREADY_EXISTS:return a.ALREADY_EXISTS;case be.PERMISSION_DENIED:return a.PERMISSION_DENIED;case be.FAILED_PRECONDITION:return a.FAILED_PRECONDITION;case be.ABORTED:return a.ABORTED;case be.OUT_OF_RANGE:return a.OUT_OF_RANGE;case be.UNIMPLEMENTED:return a.UNIMPLEMENTED;case be.DATA_LOSS:return a.DATA_LOSS;default:return y()}}(Ie=be||(be={}))[Ie.OK=0]="OK",Ie[Ie.CANCELLED=1]="CANCELLED",Ie[Ie.UNKNOWN=2]="UNKNOWN",Ie[Ie.INVALID_ARGUMENT=3]="INVALID_ARGUMENT",Ie[Ie.DEADLINE_EXCEEDED=4]="DEADLINE_EXCEEDED",Ie[Ie.NOT_FOUND=5]="NOT_FOUND",Ie[Ie.ALREADY_EXISTS=6]="ALREADY_EXISTS",Ie[Ie.PERMISSION_DENIED=7]="PERMISSION_DENIED",Ie[Ie.UNAUTHENTICATED=16]="UNAUTHENTICATED",Ie[Ie.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",Ie[Ie.FAILED_PRECONDITION=9]="FAILED_PRECONDITION",Ie[Ie.ABORTED=10]="ABORTED",Ie[Ie.OUT_OF_RANGE=11]="OUT_OF_RANGE",Ie[Ie.UNIMPLEMENTED=12]="UNIMPLEMENTED",Ie[Ie.INTERNAL=13]="INTERNAL",Ie[Ie.UNAVAILABLE=14]="UNAVAILABLE",Ie[Ie.DATA_LOSS=15]="DATA_LOSS";var Ae=function(){function t(t,e){this.comparator=t,this.root=e||ke.EMPTY}return t.prototype.insert=function(e,n){return new t(this.comparator,this.root.insert(e,n,this.comparator).copy(null,null,ke.BLACK,null,null))},t.prototype.remove=function(e){return new t(this.comparator,this.root.remove(e,this.comparator).copy(null,null,ke.BLACK,null,null))},t.prototype.get=function(t){for(var e=this.root;!e.isEmpty();){var n=this.comparator(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.isEmpty();){var r=this.comparator(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.isEmpty=function(){return this.root.isEmpty()},Object.defineProperty(t.prototype,"size",{get:function(){return this.root.size},enumerable:!1,configurable:!0}),t.prototype.minKey=function(){return this.root.minKey()},t.prototype.maxKey=function(){return this.root.maxKey()},t.prototype.inorderTraversal=function(t){return this.root.inorderTraversal(t)},t.prototype.forEach=function(t){this.inorderTraversal(function(e,n){return t(e,n),!1})},t.prototype.toString=function(){var t=[];return this.inorderTraversal(function(e,n){return t.push(e+":"+n),!1}),"{"+t.join(", ")+"}"},t.prototype.reverseTraversal=function(t){return this.root.reverseTraversal(t)},t.prototype.getIterator=function(){return new xe(this.root,null,this.comparator,!1)},t.prototype.getIteratorFrom=function(t){return new xe(this.root,t,this.comparator,!1)},t.prototype.getReverseIterator=function(){return new xe(this.root,null,this.comparator,!0)},t.prototype.getReverseIteratorFrom=function(t){return new xe(this.root,t,this.comparator,!0)},t}(),xe=function(){function t(t,e,n,r){this.isReverse=r,this.nodeStack=[];for(var i=1;!t.isEmpty();)if(i=e?n(t.key,e):1,r&&(i*=-1),i<0)t=this.isReverse?t.left:t.right;else{if(0===i){this.nodeStack.push(t);break}this.nodeStack.push(t),t=this.isReverse?t.right:t.left}}return t.prototype.getNext=function(){var t=this.nodeStack.pop(),e={key:t.key,value:t.value};if(this.isReverse)for(t=t.left;!t.isEmpty();)this.nodeStack.push(t),t=t.right;else for(t=t.right;!t.isEmpty();)this.nodeStack.push(t),t=t.left;return e},t.prototype.hasNext=function(){return this.nodeStack.length>0},t.prototype.peek=function(){if(0===this.nodeStack.length)return null;var t=this.nodeStack[this.nodeStack.length-1];return{key:t.key,value:t.value}},t}(),ke=function(){function t(e,n,r,i,o){this.key=e,this.value=n,this.color=null!=r?r:t.RED,this.left=null!=i?i:t.EMPTY,this.right=null!=o?o:t.EMPTY,this.size=this.left.size+1+this.right.size}return t.prototype.copy=function(e,n,r,i,o){return new t(null!=e?e:this.key,null!=n?n:this.value,null!=r?r:this.color,null!=i?i:this.left,null!=o?o:this.right)},t.prototype.isEmpty=function(){return!1},t.prototype.inorderTraversal=function(t){return this.left.inorderTraversal(t)||t(this.key,this.value)||this.right.inorderTraversal(t)},t.prototype.reverseTraversal=function(t){return this.right.reverseTraversal(t)||t(this.key,this.value)||this.left.reverseTraversal(t)},t.prototype.min=function(){return this.left.isEmpty()?this:this.left.min()},t.prototype.minKey=function(){return this.min().key},t.prototype.maxKey=function(){return this.right.isEmpty()?this.key:this.right.maxKey()},t.prototype.insert=function(t,e,n){var r=this,i=n(t,r.key);return(r=i<0?r.copy(null,null,null,r.left.insert(t,e,n),null):0===i?r.copy(null,e,null,null,null):r.copy(null,null,null,null,r.right.insert(t,e,n))).fixUp()},t.prototype.removeMin=function(){if(this.left.isEmpty())return t.EMPTY;var e=this;return e.left.isRed()||e.left.left.isRed()||(e=e.moveRedLeft()),(e=e.copy(null,null,null,e.left.removeMin(),null)).fixUp()},t.prototype.remove=function(e,n){var r,i=this;if(n(e,i.key)<0)i.left.isEmpty()||i.left.isRed()||i.left.left.isRed()||(i=i.moveRedLeft()),i=i.copy(null,null,null,i.left.remove(e,n),null);else{if(i.left.isRed()&&(i=i.rotateRight()),i.right.isEmpty()||i.right.isRed()||i.right.left.isRed()||(i=i.moveRedRight()),0===n(e,i.key)){if(i.right.isEmpty())return t.EMPTY;r=i.right.min(),i=i.copy(r.key,r.value,null,null,i.right.removeMin())}i=i.copy(null,null,null,null,i.right.remove(e,n))}return i.fixUp()},t.prototype.isRed=function(){return this.color},t.prototype.fixUp=function(){var t=this;return t.right.isRed()&&!t.left.isRed()&&(t=t.rotateLeft()),t.left.isRed()&&t.left.left.isRed()&&(t=t.rotateRight()),t.left.isRed()&&t.right.isRed()&&(t=t.colorFlip()),t},t.prototype.moveRedLeft=function(){var t=this.colorFlip();return t.right.left.isRed()&&(t=(t=(t=t.copy(null,null,null,null,t.right.rotateRight())).rotateLeft()).colorFlip()),t},t.prototype.moveRedRight=function(){var t=this.colorFlip();return t.left.left.isRed()&&(t=(t=t.rotateRight()).colorFlip()),t},t.prototype.rotateLeft=function(){var e=this.copy(null,null,t.RED,null,this.right.left);return this.right.copy(null,null,this.color,e,null)},t.prototype.rotateRight=function(){var e=this.copy(null,null,t.RED,this.left.right,null);return this.left.copy(null,null,this.color,null,e)},t.prototype.colorFlip=function(){var t=this.left.copy(null,null,!this.left.color,null,null),e=this.right.copy(null,null,!this.right.color,null,null);return this.copy(null,null,!this.color,t,e)},t.prototype.checkMaxDepth=function(){var t=this.check();return Math.pow(2,t)<=this.size+1},t.prototype.check=function(){if(this.isRed()&&this.left.isRed())throw y();if(this.right.isRed())throw y();var t=this.left.check();if(t!==this.right.check())throw y();return t+(this.isRed()?0:1)},t}();ke.EMPTY=null,ke.RED=!0,ke.BLACK=!1,ke.EMPTY=new(function(){function t(){this.size=0}return Object.defineProperty(t.prototype,"key",{get:function(){throw y()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"value",{get:function(){throw y()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"color",{get:function(){throw y()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"left",{get:function(){throw y()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"right",{get:function(){throw y()},enumerable:!1,configurable:!0}),t.prototype.copy=function(t,e,n,r,i){return this},t.prototype.insert=function(t,e,n){return new ke(t,e)},t.prototype.remove=function(t,e){return this},t.prototype.isEmpty=function(){return!0},t.prototype.inorderTraversal=function(t){return!1},t.prototype.reverseTraversal=function(t){return!1},t.prototype.minKey=function(){return null},t.prototype.maxKey=function(){return null},t.prototype.isRed=function(){return!1},t.prototype.checkMaxDepth=function(){return!0},t.prototype.check=function(){return 0},t}());var Ce=function(){function t(t){this.comparator=t,this.data=new Ae(this.comparator)}return t.prototype.has=function(t){return null!==this.data.get(t)},t.prototype.first=function(){return this.data.minKey()},t.prototype.last=function(){return this.data.maxKey()},Object.defineProperty(t.prototype,"size",{get:function(){return this.data.size},enumerable:!1,configurable:!0}),t.prototype.indexOf=function(t){return this.data.indexOf(t)},t.prototype.forEach=function(t){this.data.inorderTraversal(function(e,n){return t(e),!1})},t.prototype.forEachInRange=function(t,e){for(var n=this.data.getIteratorFrom(t[0]);n.hasNext();){var r=n.getNext();if(this.comparator(r.key,t[1])>=0)return;e(r.key)}},t.prototype.forEachWhile=function(t,e){var n;for(n=void 0!==e?this.data.getIteratorFrom(e):this.data.getIterator();n.hasNext();)if(!t(n.getNext().key))return},t.prototype.firstAfterOrEqual=function(t){var e=this.data.getIteratorFrom(t);return e.hasNext()?e.getNext().key:null},t.prototype.getIterator=function(){return new Re(this.data.getIterator())},t.prototype.getIteratorFrom=function(t){return new Re(this.data.getIteratorFrom(t))},t.prototype.add=function(t){return this.copy(this.data.remove(t).insert(t,!0))},t.prototype.delete=function(t){return this.has(t)?this.copy(this.data.remove(t)):this},t.prototype.isEmpty=function(){return this.data.isEmpty()},t.prototype.unionWith=function(t){var e=this;return e.size<t.size&&(e=t,t=this),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.getIterator(),r=e.data.getIterator();n.hasNext();){var i=n.getNext().key,o=r.getNext().key;if(0!==this.comparator(i,o))return!1}return!0},t.prototype.toArray=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.copy=function(e){var n=new t(this.comparator);return n.data=e,n},t}(),Re=function(){function t(t){this.iter=t}return t.prototype.getNext=function(){return this.iter.getNext().key},t.prototype.hasNext=function(){return this.iter.hasNext()},t}(),Le=new Ae(G.comparator);function Oe(){return Le}var Pe=new Ae(G.comparator);function Fe(){return Pe}var Me=new Ae(G.comparator);function Ve(){return Me}var qe=new Ce(G.comparator);function Ue(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];for(var n=qe,r=0,i=t;r<i.length;r++){var o=i[r];n=n.add(o)}return n}var Be=new Ce(w);function je(){return Be}var Ke=function(){function t(t,e,n,r,i){this.snapshotVersion=t,this.targetChanges=e,this.targetMismatches=n,this.documentUpdates=r,this.resolvedLimboDocuments=i}return t.createSynthesizedRemoteEventForCurrentChange=function(e,n){var r=new Map;return r.set(e,Ge.createSynthesizedTargetChangeForCurrentChange(e,n)),new t(T.min(),r,je(),Oe(),Ue())},t}(),Ge=function(){function t(t,e,n,r,i){this.resumeToken=t,this.current=e,this.addedDocuments=n,this.modifiedDocuments=r,this.removedDocuments=i}return t.createSynthesizedTargetChangeForCurrentChange=function(e,n){return new t(L.EMPTY_BYTE_STRING,n,Ue(),Ue(),Ue())},t}(),Qe=function(t,e,n,r){this.v=t,this.removedTargetIds=e,this.key=n,this.P=r},ze=function(t,e){this.targetId=t,this.V=e},We=function(t,e,n,r){void 0===n&&(n=L.EMPTY_BYTE_STRING),void 0===r&&(r=null),this.state=t,this.targetIds=e,this.resumeToken=n,this.cause=r},He=function(){function t(){this.S=0,this.D=Xe(),this.C=L.EMPTY_BYTE_STRING,this.N=!1,this.k=!0}return Object.defineProperty(t.prototype,"current",{get:function(){return this.N},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"resumeToken",{get:function(){return this.C},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"F",{get:function(){return 0!==this.S},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"$",{get:function(){return this.k},enumerable:!1,configurable:!0}),t.prototype.O=function(t){t.approximateByteSize()>0&&(this.k=!0,this.C=t)},t.prototype.M=function(){var t=Ue(),e=Ue(),n=Ue();return this.D.forEach(function(r,i){switch(i){case 0:t=t.add(r);break;case 2:e=e.add(r);break;case 1:n=n.add(r);break;default:y()}}),new Ge(this.C,this.N,t,e,n)},t.prototype.L=function(){this.k=!1,this.D=Xe()},t.prototype.B=function(t,e){this.k=!0,this.D=this.D.insert(t,e)},t.prototype.q=function(t){this.k=!0,this.D=this.D.remove(t)},t.prototype.U=function(){this.S+=1},t.prototype.K=function(){this.S-=1},t.prototype.j=function(){this.k=!0,this.N=!0},t}(),Ye=function(){function t(t){this.W=t,this.G=new Map,this.H=Oe(),this.J=$e(),this.Y=new Ce(w)}return t.prototype.X=function(t){for(var e=0,n=t.v;e<n.length;e++){var r=n[e];t.P&&t.P.isFoundDocument()?this.Z(r,t.P):this.tt(r,t.key,t.P)}for(var i=0,o=t.removedTargetIds;i<o.length;i++)r=o[i],this.tt(r,t.key,t.P)},t.prototype.et=function(t){var e=this;this.forEachTarget(t,function(n){var r=e.nt(n);switch(t.state){case 0:e.st(n)&&r.O(t.resumeToken);break;case 1:r.K(),r.F||r.L(),r.O(t.resumeToken);break;case 2:r.K(),r.F||e.removeTarget(n);break;case 3:e.st(n)&&(r.j(),r.O(t.resumeToken));break;case 4:e.st(n)&&(e.it(n),r.O(t.resumeToken));break;default:y()}})},t.prototype.forEachTarget=function(t,e){var n=this;t.targetIds.length>0?t.targetIds.forEach(e):this.G.forEach(function(t,r){n.st(r)&&e(r)})},t.prototype.rt=function(t){var e=t.targetId,n=t.V.count,r=this.ot(e);if(r){var i=r.target;if(lt(i))if(0===n){var o=new G(i.path);this.tt(e,o,at.newNoDocument(o,T.min()))}else v(1===n);else this.ct(e)!==n&&(this.it(e),this.Y=this.Y.add(e))}},t.prototype.ut=function(t){var e=this,n=new Map;this.G.forEach(function(r,i){var o=e.ot(i);if(o){if(r.current&&lt(o.target)){var s=new G(o.target.path);null!==e.H.get(s)||e.at(i,s)||e.tt(i,s,at.newNoDocument(s,t))}r.$&&(n.set(i,r.M()),r.L())}});var r=Ue();this.J.forEach(function(t,n){var i=!0;n.forEachWhile(function(t){var n=e.ot(t);return!n||2===n.purpose||(i=!1,!1)}),i&&(r=r.add(t))});var i=new Ke(t,n,this.Y,this.H,r);return this.H=Oe(),this.J=$e(),this.Y=new Ce(w),i},t.prototype.Z=function(t,e){if(this.st(t)){var n=this.at(t,e.key)?2:0;this.nt(t).B(e.key,n),this.H=this.H.insert(e.key,e),this.J=this.J.insert(e.key,this.ht(e.key).add(t))}},t.prototype.tt=function(t,e,n){if(this.st(t)){var r=this.nt(t);this.at(t,e)?r.B(e,1):r.q(e),this.J=this.J.insert(e,this.ht(e).delete(t)),n&&(this.H=this.H.insert(e,n))}},t.prototype.removeTarget=function(t){this.G.delete(t)},t.prototype.ct=function(t){var e=this.nt(t).M();return this.W.getRemoteKeysForTarget(t).size+e.addedDocuments.size-e.removedDocuments.size},t.prototype.U=function(t){this.nt(t).U()},t.prototype.nt=function(t){var e=this.G.get(t);return e||(e=new He,this.G.set(t,e)),e},t.prototype.ht=function(t){var e=this.J.get(t);return e||(e=new Ce(w),this.J=this.J.insert(t,e)),e},t.prototype.st=function(t){var e=null!==this.ot(t);return e||f("WatchChangeAggregator","Detected inactive target",t),e},t.prototype.ot=function(t){var e=this.G.get(t);return e&&e.F?null:this.W.lt(t)},t.prototype.it=function(t){var e=this;this.G.set(t,new He),this.W.getRemoteKeysForTarget(t).forEach(function(n){e.tt(t,n,null)})},t.prototype.at=function(t,e){return this.W.getRemoteKeysForTarget(t).has(e)},t}();function $e(){return new Ae(G.comparator)}function Xe(){return new Ae(G.comparator)}var Je={asc:"ASCENDING",desc:"DESCENDING"},Ze={"<":"LESS_THAN","<=":"LESS_THAN_OR_EQUAL",">":"GREATER_THAN",">=":"GREATER_THAN_OR_EQUAL","==":"EQUAL","!=":"NOT_EQUAL","array-contains":"ARRAY_CONTAINS",in:"IN","not-in":"NOT_IN","array-contains-any":"ARRAY_CONTAINS_ANY"},tn=function(t,e){this.databaseId=t,this.I=e};function en(t,e){return t.I?new Date(1e3*e.seconds).toISOString().replace(/\.\d*/,"").replace("Z","")+"."+("000000000"+e.nanoseconds).slice(-9)+"Z":{seconds:""+e.seconds,nanos:e.nanoseconds}}function nn(t,e){return t.I?e.toBase64():e.toUint8Array()}function rn(t,e){return en(t,e.toTimestamp())}function on(t){return v(!!t),T.fromTimestamp(function(t){var e=P(t);return new E(e.seconds,e.nanos)}(t))}function sn(t,e){return function(t){return new x(["projects",t.projectId,"databases",t.database])}(t).child("documents").child(e).canonicalString()}function an(t){var e=x.fromString(t);return v(Cn(e)),e}function un(t,e){return sn(t.databaseId,e.path)}function cn(t,e){var n=an(e);if(n.get(1)!==t.databaseId.projectId)throw new u(a.INVALID_ARGUMENT,"Tried to deserialize key from different project: "+n.get(1)+" vs "+t.databaseId.projectId);if(n.get(3)!==t.databaseId.database)throw new u(a.INVALID_ARGUMENT,"Tried to deserialize key from different database: "+n.get(3)+" vs "+t.databaseId.database);return new G(dn(n))}function hn(t,e){return sn(t.databaseId,e)}function fn(t){var e=an(t);return 4===e.length?x.emptyPath():dn(e)}function ln(t){return new x(["projects",t.databaseId.projectId,"databases",t.databaseId.database]).canonicalString()}function dn(t){return v(t.length>4&&"documents"===t.get(4)),t.popFirst(5)}function pn(t,e,n){return{name:un(t,e),fields:n.value.mapValue.fields}}function yn(t,e,n){var r=cn(t,e.name),i=on(e.updateTime),o=new ot({mapValue:{fields:e.fields}}),s=at.newFoundDocument(r,i,o);return n&&s.setHasCommittedMutations(),n?s.setHasCommittedMutations():s}function vn(t,e){var n;if(e instanceof ve)n={update:pn(t,e.key,e.value)};else if(e instanceof Ee)n={delete:un(t,e.key)};else if(e instanceof me)n={update:pn(t,e.key,e.data),updateMask:kn(e.fieldMask)};else{if(!(e instanceof Te))return y();n={verify:un(t,e.key)}}return e.fieldTransforms.length>0&&(n.updateTransforms=e.fieldTransforms.map(function(t){return function(t,e){var n=e.transform;if(n instanceof Jt)return{fieldPath:e.field.canonicalString(),setToServerValue:"REQUEST_TIME"};if(n instanceof Zt)return{fieldPath:e.field.canonicalString(),appendMissingElements:{values:n.elements}};if(n instanceof ee)return{fieldPath:e.field.canonicalString(),removeAllFromArray:{values:n.elements}};if(n instanceof re)return{fieldPath:e.field.canonicalString(),increment:n.A};throw y()}(0,t)})),e.precondition.isNone||(n.currentDocument=function(t,e){return void 0!==e.updateTime?{updateTime:rn(t,e.updateTime)}:void 0!==e.exists?{exists:e.exists}:y()}(t,e.precondition)),n}function mn(t,e){var n=e.currentDocument?function(t){return void 0!==t.updateTime?ue.updateTime(on(t.updateTime)):void 0!==t.exists?ue.exists(t.exists):ue.none()}(e.currentDocument):ue.none(),r=e.updateTransforms?e.updateTransforms.map(function(e){return function(t,e){var n=null;if("setToServerValue"in e)v("REQUEST_TIME"===e.setToServerValue),n=new Jt;else if("appendMissingElements"in e){var r=e.appendMissingElements.values||[];n=new Zt(r)}else if("removeAllFromArray"in e){var i=e.removeAllFromArray.values||[];n=new ee(i)}else"increment"in e?n=new re(t,e.increment):y();var o=C.fromServerFormat(e.fieldPath);return new se(o,n)}(t,e)}):[];if(e.update){e.update.name;var i=cn(t,e.update.name),o=new ot({mapValue:{fields:e.update.fields}});if(e.updateMask){var s=function(t){var e=t.fieldPaths||[];return new R(e.map(function(t){return C.fromServerFormat(t)}))}(e.updateMask);return new me(i,o,s,n,r)}return new ve(i,o,n,r)}if(e.delete){var a=cn(t,e.delete);return new Ee(a,n)}if(e.verify){var u=cn(t,e.verify);return new Te(u,n)}return y()}function gn(t,e){return{documents:[hn(t,e.path)]}}function _n(t,e){var n={structuredQuery:{}},r=e.path;null!==e.collectionGroup?(n.parent=hn(t,r),n.structuredQuery.from=[{collectionId:e.collectionGroup,allDescendants:!0}]):(n.parent=hn(t,r.popLast()),n.structuredQuery.from=[{collectionId:r.lastSegment()}]);var i=function(t){if(0!==t.length){var e=t.map(function(t){return function(t){if("=="===t.op){if(nt(t.value))return{unaryFilter:{field:Nn(t.field),op:"IS_NAN"}};if(et(t.value))return{unaryFilter:{field:Nn(t.field),op:"IS_NULL"}}}else if("!="===t.op){if(nt(t.value))return{unaryFilter:{field:Nn(t.field),op:"IS_NOT_NAN"}};if(et(t.value))return{unaryFilter:{field:Nn(t.field),op:"IS_NOT_NULL"}}}return{fieldFilter:{field:Nn(t.field),op:Sn(t.op),value:t.value}}}(t)});return 1===e.length?e[0]:{compositeFilter:{op:"AND",filters:e}}}}(e.filters);i&&(n.structuredQuery.where=i);var o=function(t){if(0!==t.length)return t.map(function(t){return function(t){return{field:Nn(t.field),direction:Tn(t.dir)}}(t)})}(e.orderBy);o&&(n.structuredQuery.orderBy=o);var s=function(t,e){return t.I||B(e)?e:{value:e}}(t,e.limit);return null!==s&&(n.structuredQuery.limit=s),e.startAt&&(n.structuredQuery.startAt=In(e.startAt)),e.endAt&&(n.structuredQuery.endAt=In(e.endAt)),n}function wn(t){var e=fn(t.parent),n=t.structuredQuery,r=n.from?n.from.length:0,i=null;if(r>0){v(1===r);var s=n.from[0];s.allDescendants?i=s.collectionId:e=e.child(s.collectionId)}var a=[];n.where&&(a=bn(n.where));var u=[];n.orderBy&&(u=n.orderBy.map(function(t){return function(t){return new Tt(Dn(t.field),function(t){switch(t){case"ASCENDING":return"asc";case"DESCENDING":return"desc";default:return}}(t.direction))}(t)}));var c=null;n.limit&&(c=function(t){var e;return B(e="object"==o(t)?t.value:t)?null:e}(n.limit));var h=null;n.startAt&&(h=En(n.startAt));var f=null;return n.endAt&&(f=En(n.endAt)),xt(e,i,u,a,c,"F",h,f)}function bn(t){return t?void 0!==t.unaryFilter?[xn(t)]:void 0!==t.fieldFilter?[An(t)]:void 0!==t.compositeFilter?t.compositeFilter.filters.map(function(t){return bn(t)}).reduce(function(t,e){return t.concat(e)}):y():[]}function In(t){return{before:t.before,values:t.position}}function En(t){var e=!!t.before,n=t.values||[];return new It(n,e)}function Tn(t){return Je[t]}function Sn(t){return Ze[t]}function Nn(t){return{fieldPath:t.canonicalString()}}function Dn(t){return C.fromServerFormat(t.fieldPath)}function An(t){return dt.create(Dn(t.fieldFilter.field),function(t){switch(t){case"EQUAL":return"==";case"NOT_EQUAL":return"!=";case"GREATER_THAN":return">";case"GREATER_THAN_OR_EQUAL":return">=";case"LESS_THAN":return"<";case"LESS_THAN_OR_EQUAL":return"<=";case"ARRAY_CONTAINS":return"array-contains";case"IN":return"in";case"NOT_IN":return"not-in";case"ARRAY_CONTAINS_ANY":return"array-contains-any";case"OPERATOR_UNSPECIFIED":default:return y()}}(t.fieldFilter.op),t.fieldFilter.value)}function xn(t){switch(t.unaryFilter.op){case"IS_NAN":var e=Dn(t.unaryFilter.field);return dt.create(e,"==",{doubleValue:NaN});case"IS_NULL":var n=Dn(t.unaryFilter.field);return dt.create(n,"==",{nullValue:"NULL_VALUE"});case"IS_NOT_NAN":var r=Dn(t.unaryFilter.field);return dt.create(r,"!=",{doubleValue:NaN});case"IS_NOT_NULL":var i=Dn(t.unaryFilter.field);return dt.create(i,"!=",{nullValue:"NULL_VALUE"});case"OPERATOR_UNSPECIFIED":default:return y()}}function kn(t){var e=[];return t.fields.forEach(function(t){return e.push(t.canonicalString())}),{fieldPaths:e}}function Cn(t){return t.length>=4&&"projects"===t.get(0)&&"databases"===t.get(2)}function Rn(t){for(var e="",n=0;n<t.length;n++)e.length>0&&(e=On(e)),e=Ln(t.get(n),e);return On(e)}function Ln(t,e){for(var n=e,r=t.length,i=0;i<r;i++){var o=t.charAt(i);switch(o){case"\0":n+="";break;case"":n+="";break;default:n+=o}}return n}function On(t){return t+""}function Pn(t){var e=t.length;if(v(e>=2),2===e)return v(""===t.charAt(0)&&""===t.charAt(1)),x.emptyPath();for(var n=e-2,r=[],i="",o=0;o<e;){var s=t.indexOf("",o);switch((s<0||s>n)&&y(),t.charAt(s+1)){case"":var a=t.substring(o,s),u=void 0;0===i.length?u=a:(u=i+=a,i=""),r.push(u);break;case"":i+=t.substring(o,s),i+="\0";break;case"":i+=t.substring(o,s+1);break;default:y()}o=s+2}return new x(r)}var Fn=function(t,e){this.seconds=t,this.nanoseconds=e},Mn=function(t,e,n){this.ownerId=t,this.allowTabSynchronization=e,this.leaseTimestampMs=n};Mn.store="owner",Mn.key="owner";var Vn=function(t,e,n){this.userId=t,this.lastAcknowledgedBatchId=e,this.lastStreamToken=n};Vn.store="mutationQueues",Vn.keyPath="userId";var qn=function(t,e,n,r,i){this.userId=t,this.batchId=e,this.localWriteTimeMs=n,this.baseMutations=r,this.mutations=i};qn.store="mutations",qn.keyPath="batchId",qn.userMutationsIndex="userMutationsIndex",qn.userMutationsKeyPath=["userId","batchId"];var Un=function(){function t(){}return t.prefixForUser=function(t){return[t]},t.prefixForPath=function(t,e){return[t,Rn(e)]},t.key=function(t,e,n){return[t,Rn(e),n]},t}();Un.store="documentMutations",Un.PLACEHOLDER=new Un;var Bn=function(t,e){this.path=t,this.readTime=e},jn=function(t,e){this.path=t,this.version=e},Kn=function(t,e,n,r,i,o){this.unknownDocument=t,this.noDocument=e,this.document=n,this.hasCommittedMutations=r,this.readTime=i,this.parentPath=o};Kn.store="remoteDocuments",Kn.readTimeIndex="readTimeIndex",Kn.readTimeIndexPath="readTime",Kn.collectionReadTimeIndex="collectionReadTimeIndex",Kn.collectionReadTimeIndexPath=["parentPath","readTime"];var Gn=function(t){this.byteSize=t};Gn.store="remoteDocumentGlobal",Gn.key="remoteDocumentGlobalKey";var Qn=function(t,e,n,r,i,o,s){this.targetId=t,this.canonicalId=e,this.readTime=n,this.resumeToken=r,this.lastListenSequenceNumber=i,this.lastLimboFreeSnapshotVersion=o,this.query=s};Qn.store="targets",Qn.keyPath="targetId",Qn.queryTargetsIndexName="queryTargetsIndex",Qn.queryTargetsKeyPath=["canonicalId","targetId"];var zn=function(t,e,n){this.targetId=t,this.path=e,this.sequenceNumber=n};zn.store="targetDocuments",zn.keyPath=["targetId","path"],zn.documentTargetsIndex="documentTargetsIndex",zn.documentTargetsKeyPath=["path","targetId"];var Wn=function(t,e,n,r){this.highestTargetId=t,this.highestListenSequenceNumber=e,this.lastRemoteSnapshotVersion=n,this.targetCount=r};Wn.key="targetGlobalKey",Wn.store="targetGlobal";var Hn=function(t,e){this.collectionId=t,this.parent=e};Hn.store="collectionParents",Hn.keyPath=["collectionId","parent"];var Yn=function(t,e,n,r){this.clientId=t,this.updateTimeMs=e,this.networkEnabled=n,this.inForeground=r};Yn.store="clientMetadata",Yn.keyPath="clientId";var $n=function(t,e,n){this.bundleId=t,this.createTime=e,this.version=n};$n.store="bundles",$n.keyPath="bundleId";var Xn=function(t,e,n){this.name=t,this.readTime=e,this.bundledQuery=n};Xn.store="namedQueries",Xn.keyPath="name";var Jn=(0,e.__spreadArray)((0,e.__spreadArray)([],(0,e.__spreadArray)((0,e.__spreadArray)([],(0,e.__spreadArray)((0,e.__spreadArray)([],(0,e.__spreadArray)((0,e.__spreadArray)([],[Vn.store,qn.store,Un.store,Kn.store,Qn.store,Mn.store,Wn.store,zn.store]),[Yn.store])),[Gn.store])),[Hn.store])),[$n.store,Xn.store]),Zn="The current tab is not in the required state to perform this operation. It might be necessary to refresh the browser tab.",tr=function(){function t(){this.onCommittedListeners=[]}return t.prototype.addOnCommittedListener=function(t){this.onCommittedListeners.push(t)},t.prototype.raiseOnCommittedEvent=function(){this.onCommittedListeners.forEach(function(t){return t()})},t}(),er=function(){var t=this;this.promise=new Promise(function(e,n){t.resolve=e,t.reject=n})},nr=function(){function t(t){var e=this;this.nextCallback=null,this.catchCallback=null,this.result=void 0,this.error=void 0,this.isDone=!1,this.callbackAttached=!1,t(function(t){e.isDone=!0,e.result=t,e.nextCallback&&e.nextCallback(t)},function(t){e.isDone=!0,e.error=t,e.catchCallback&&e.catchCallback(t)})}return t.prototype.catch=function(t){return this.next(void 0,t)},t.prototype.next=function(e,n){var r=this;return this.callbackAttached&&y(),this.callbackAttached=!0,this.isDone?this.error?this.wrapFailure(n,this.error):this.wrapSuccess(e,this.result):new t(function(t,i){r.nextCallback=function(n){r.wrapSuccess(e,n).next(t,i)},r.catchCallback=function(e){r.wrapFailure(n,e).next(t,i)}})},t.prototype.toPromise=function(){var t=this;return new Promise(function(e,n){t.next(e,n)})},t.prototype.wrapUserFunction=function(e){try{var n=e();return n instanceof t?n:t.resolve(n)}catch(e){return t.reject(e)}},t.prototype.wrapSuccess=function(e,n){return e?this.wrapUserFunction(function(){return e(n)}):t.resolve(n)},t.prototype.wrapFailure=function(e,n){return e?this.wrapUserFunction(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.waitFor=function(e){return new t(function(t,n){var r=0,i=0,o=!1;e.forEach(function(e){++r,e.next(function(){++i,o&&i===r&&t()},function(t){return n(t)})}),o=!0,i===r&&t()})},t.or=function(e){for(var n=t.resolve(!1),r=function(e){n=n.next(function(n){return n?t.resolve(n):e()})},i=0,o=e;i<o.length;i++)r(o[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.waitFor(r)},t}(),rr=function(){function t(t,e){var n=this;this.action=t,this.transaction=e,this.aborted=!1,this.ft=new er,this.transaction.oncomplete=function(){n.ft.resolve()},this.transaction.onabort=function(){e.error?n.ft.reject(new sr(t,e.error)):n.ft.resolve()},this.transaction.onerror=function(e){var r=fr(e.target.error);n.ft.reject(new sr(t,r))}}return t.open=function(e,n,r,i){try{return new t(n,e.transaction(i,r))}catch(e){throw new sr(n,e)}},Object.defineProperty(t.prototype,"dt",{get:function(){return this.ft.promise},enumerable:!1,configurable:!0}),t.prototype.abort=function(t){t&&this.ft.reject(t),this.aborted||(f("SimpleDb","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 new ur(e)},t}(),ir=function(){function r(t,e,i){this.name=t,this.version=e,this.wt=i,12.2===r._t((0,n.getUA)())&&l("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 r.delete=function(t){return f("SimpleDb","Removing database:",t),cr(window.indexedDB.deleteDatabase(t)).toPromise()},r.yt=function(){if("undefined"==typeof indexedDB)return!1;if(r.gt())return!0;var t=(0,n.getUA)(),e=r._t(t),i=0<e&&e<10,o=r.Et(t),s=0<o&&o<4.5;return!(t.indexOf("MSIE ")>0||t.indexOf("Trident/")>0||t.indexOf("Edge/")>0||i||s)},r.gt=function(){var e;return void 0!==t&&"YES"===(null===(e=t.env)||void 0===e?void 0:e.Tt)},r.It=function(t,e){return t.store(e)},r._t=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)},r.Et=function(t){var e=t.match(/Android ([\d.]+)/i),n=e?e[1].split(".").slice(0,2).join("."):"-1";return Number(n)},r.prototype.At=function(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n,r=this;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return this.db?[3,2]:(f("SimpleDb","Opening database:",this.name),n=this,[4,new Promise(function(e,n){var i=indexedDB.open(r.name,r.version);i.onsuccess=function(t){var n=t.target.result;e(n)},i.onblocked=function(){n(new sr(t,"Cannot upgrade IndexedDB schema while another tab is open. Close all tabs that access Firestore and reload this page to proceed."))},i.onerror=function(e){var r=e.target.error;"VersionError"===r.name?n(new u(a.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.")):n(new sr(t,r))},i.onupgradeneeded=function(t){f("SimpleDb",'Database "'+r.name+'" requires upgrade from version:',t.oldVersion);var e=t.target.result;r.wt.Rt(e,i.transaction,t.oldVersion,r.version).next(function(){f("SimpleDb","Database upgrade to version "+r.version+" complete")})}})]);case 1:n.db=e.sent(),e.label=2;case 2:return[2,(this.bt&&(this.db.onversionchange=function(t){return r.bt(t)}),this.db)]}})})},r.prototype.vt=function(t){this.bt=t,this.db&&(this.db.onversionchange=function(e){return t(e)})},r.prototype.runTransaction=function(t,n,r,i){return(0,e.__awaiter)(this,void 0,void 0,function(){var s,a,u,c,h;return(0,e.__generator)(this,function(l){switch(l.label){case 0:s="readonly"===n,a=0,u=function(){var n,o,u,h,l;return(0,e.__generator)(this,function(e){switch(e.label){case 0:++a,e.label=1;case 1:return e.trys.push([1,4,,5]),[4,c.At(t)];case 2:return c.db=e.sent(),n=rr.open(c.db,t,s?"readonly":"readwrite",r),o=i(n).catch(function(t){return n.abort(t),nr.reject(t)}).toPromise(),u={},o.catch(function(){}),[4,n.dt];case 3:return[2,(u.value=(e.sent(),o),u)];case 4:return h=e.sent(),l="FirebaseError"!==h.name&&a<3,f("SimpleDb","Transaction failed with error:",h.message,"Retrying:",l),c.close(),l?[3,5]:[2,{value:Promise.reject(h)}];case 5:return[2]}})},c=this,l.label=1;case 1:return[5,u()];case 2:if("object"==o(h=l.sent()))return[2,h.value];l.label=3;case 3:return[3,1];case 4:return[2]}})})},r.prototype.close=function(){this.db&&this.db.close(),this.db=void 0},r}(),or=function(){function t(t){this.Pt=t,this.Vt=!1,this.St=null}return Object.defineProperty(t.prototype,"isDone",{get:function(){return this.Vt},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Dt",{get:function(){return this.St},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"cursor",{set:function(t){this.Pt=t},enumerable:!1,configurable:!0}),t.prototype.done=function(){this.Vt=!0},t.prototype.Ct=function(t){this.St=t},t.prototype.delete=function(){return cr(this.Pt.delete())},t}(),sr=function(t){function n(e,n){var r=this;return(r=t.call(this,a.UNAVAILABLE,"IndexedDB transaction '"+e+"' failed: "+n)||this).name="IndexedDbTransactionError",r}return(0,e.__extends)(n,t),n}(u);function ar(t){return"IndexedDbTransactionError"===t.name}var ur=function(){function t(t){this.store=t}return t.prototype.put=function(t,e){var n;return void 0!==e?(f("SimpleDb","PUT",this.store.name,t,e),n=this.store.put(e,t)):(f("SimpleDb","PUT",this.store.name,"<auto-key>",t),n=this.store.put(t)),cr(n)},t.prototype.add=function(t){return f("SimpleDb","ADD",this.store.name,t,t),cr(this.store.add(t))},t.prototype.get=function(t){var e=this;return cr(this.store.get(t)).next(function(n){return void 0===n&&(n=null),f("SimpleDb","GET",e.store.name,t,n),n})},t.prototype.delete=function(t){return f("SimpleDb","DELETE",this.store.name,t),cr(this.store.delete(t))},t.prototype.count=function(){return f("SimpleDb","COUNT",this.store.name),cr(this.store.count())},t.prototype.Nt=function(t,e){var n=this.cursor(this.options(t,e)),r=[];return this.xt(n,function(t,e){r.push(e)}).next(function(){return r})},t.prototype.kt=function(t,e){f("SimpleDb","DELETE ALL",this.store.name);var n=this.options(t,e);n.Ft=!1;var r=this.cursor(n);return this.xt(r,function(t,e,n){return n.delete()})},t.prototype.$t=function(t,e){var n;e?n=t:(n={},e=t);var r=this.cursor(n);return this.xt(r,e)},t.prototype.Ot=function(t){var e=this.cursor({});return new nr(function(n,r){e.onerror=function(t){var e=fr(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.xt=function(t,e){var n=[];return new nr(function(r,i){t.onerror=function(t){i(t.target.error)},t.onsuccess=function(t){var i=t.target.result;if(i){var o=new or(i),s=e(i.primaryKey,i.value,o);if(s instanceof nr){var a=s.catch(function(t){return o.done(),nr.reject(t)});n.push(a)}o.isDone?r():null===o.Dt?i.continue():i.continue(o.Dt)}else r()}}).next(function(){return nr.waitFor(n)})},t.prototype.options=function(t,e){var n;return void 0!==t&&("string"==typeof t?n=t: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.Ft?n.openKeyCursor(t.range,e):n.openCursor(t.range,e)}return this.store.openCursor(t.range,e)},t}();function cr(t){return new nr(function(e,n){t.onsuccess=function(t){var n=t.target.result;e(n)},t.onerror=function(t){var e=fr(t.target.error);n(e)}})}var hr=!1;function fr(t){var e=ir._t((0,n.getUA)());if(e>=12.2&&e<13){var r="An internal error was encountered in the Indexed Database server";if(t.message.indexOf(r)>=0){var i=new u("internal","IOS_INDEXEDDB_BUG1: IndexedDb has thrown '"+r+"'. This is likely due to an unavoidable bug in iOS. See https://stackoverflow.com/q/56496296/110915 for details and a potential workaround.");return hr||(hr=!0,setTimeout(function(){throw i},0)),i}}return t}var lr=function(t){function n(e,n){var r=this;return(r=t.call(this)||this).Mt=e,r.currentSequenceNumber=n,r}return(0,e.__extends)(n,t),n}(tr);function dr(t,e){var n=m(t);return ir.It(n.Mt,e)}var pr=function(){function t(t,e,n,r){this.batchId=t,this.localWriteTime=e,this.baseMutations=n,this.mutations=r}return t.prototype.applyToRemoteDocument=function(t,e){for(var n=e.mutationResults,r=0;r<this.mutations.length;r++){var i=this.mutations[r];i.key.isEqual(t.key)&&fe(i,t,n[r])}},t.prototype.applyToLocalView=function(t){for(var e=0,n=this.baseMutations;e<n.length;e++)(o=n[e]).key.isEqual(t.key)&&le(o,t,this.localWriteTime);for(var r=0,i=this.mutations;r<i.length;r++){var o;(o=i[r]).key.isEqual(t.key)&&le(o,t,this.localWriteTime)}},t.prototype.applyToLocalDocumentSet=function(t){var e=this;this.mutations.forEach(function(n){var r=t.get(n.key),i=r;e.applyToLocalView(i),r.isValidDocument()||i.convertToNoDocument(T.min())})},t.prototype.keys=function(){return this.mutations.reduce(function(t,e){return t.add(e.key)},Ue())},t.prototype.isEqual=function(t){return this.batchId===t.batchId&&b(this.mutations,t.mutations,function(t,e){return pe(t,e)})&&b(this.baseMutations,t.baseMutations,function(t,e){return pe(t,e)})},t}(),yr=function(){function t(t,e,n,r){this.batch=t,this.commitVersion=e,this.mutationResults=n,this.docVersions=r}return t.from=function(e,n,r){v(e.mutations.length===r.length);for(var i=Ve(),o=e.mutations,s=0;s<o.length;s++)i=i.insert(o[s].key,r[s].version);return new t(e,n,r,i)},t}(),vr=function(){function t(t,e,n,r,i,o,s){void 0===i&&(i=T.min()),void 0===o&&(o=T.min()),void 0===s&&(s=L.EMPTY_BYTE_STRING),this.target=t,this.targetId=e,this.purpose=n,this.sequenceNumber=r,this.snapshotVersion=i,this.lastLimboFreeSnapshotVersion=o,this.resumeToken=s}return t.prototype.withSequenceNumber=function(e){return new t(this.target,this.targetId,this.purpose,e,this.snapshotVersion,this.lastLimboFreeSnapshotVersion,this.resumeToken)},t.prototype.withResumeToken=function(e,n){return new t(this.target,this.targetId,this.purpose,this.sequenceNumber,n,this.lastLimboFreeSnapshotVersion,e)},t.prototype.withLastLimboFreeSnapshotVersion=function(e){return new t(this.target,this.targetId,this.purpose,this.sequenceNumber,this.snapshotVersion,e,this.resumeToken)},t}(),mr=function(t){this.Lt=t};function gr(t,e){if(e.document)return yn(t.Lt,e.document,!!e.hasCommittedMutations);if(e.noDocument){var n=G.fromSegments(e.noDocument.path),r=Er(e.noDocument.readTime),i=at.newNoDocument(n,r);return e.hasCommittedMutations?i.setHasCommittedMutations():i}if(e.unknownDocument){var o=G.fromSegments(e.unknownDocument.path);return r=Er(e.unknownDocument.version),at.newUnknownDocument(o,r)}return y()}function _r(t,e,n){var r=wr(n),i=e.key.path.popLast().toArray();if(e.isFoundDocument()){var o=function(t,e){return{name:un(t,e.key),fields:e.data.value.mapValue.fields,updateTime:en(t,e.version.toTimestamp())}}(t.Lt,e),s=e.hasCommittedMutations;return new Kn(null,null,o,s,r,i)}if(e.isNoDocument()){var a=e.key.path.toArray(),u=Ir(e.version);return s=e.hasCommittedMutations,new Kn(null,new Bn(a,u),null,s,r,i)}if(e.isUnknownDocument()){var c=e.key.path.toArray(),h=Ir(e.version);return new Kn(new jn(c,h),null,null,!0,r,i)}return y()}function wr(t){var e=t.toTimestamp();return[e.seconds,e.nanoseconds]}function br(t){var e=new E(t[0],t[1]);return T.fromTimestamp(e)}function Ir(t){var e=t.toTimestamp();return new Fn(e.seconds,e.nanoseconds)}function Er(t){var e=new E(t.seconds,t.nanoseconds);return T.fromTimestamp(e)}function Tr(t,e){for(var n=(e.baseMutations||[]).map(function(e){return mn(t.Lt,e)}),r=0;r<e.mutations.length-1;++r){var i=e.mutations[r];if(r+1<e.mutations.length&&void 0!==e.mutations[r+1].transform){var o=e.mutations[r+1];i.updateTransforms=o.transform.fieldTransforms,e.mutations.splice(r+1,1),++r}}var s=e.mutations.map(function(e){return mn(t.Lt,e)}),a=E.fromMillis(e.localWriteTimeMs);return new pr(e.batchId,a,n,s)}function Sr(t){var e,n,r=Er(t.readTime),i=void 0!==t.lastLimboFreeSnapshotVersion?Er(t.lastLimboFreeSnapshotVersion):T.min();return void 0!==t.query.documents?(v(1===(n=t.query).documents.length),e=Mt(kt(fn(n.documents[0])))):e=function(t){return Mt(wn(t))}(t.query),new vr(e,t.targetId,0,t.lastListenSequenceNumber,r,i,L.fromBase64String(t.resumeToken))}function Nr(t,e){var n,r=Ir(e.snapshotVersion),i=Ir(e.lastLimboFreeSnapshotVersion);n=lt(e.target)?gn(t.Lt,e.target):_n(t.Lt,e.target);var o=e.resumeToken.toBase64();return new Qn(e.targetId,ht(e.target),r,o,e.sequenceNumber,i,n)}function Dr(t){var e=wn({parent:t.parent,structuredQuery:t.structuredQuery});return"LAST"===t.limitType?Vt(e,e.limit,"L"):e}var Ar=function(){function t(){}return t.prototype.getBundleMetadata=function(t,e){return xr(t).get(e).next(function(t){if(t)return{id:(e=t).bundleId,createTime:Er(e.createTime),version:e.version};var e})},t.prototype.saveBundleMetadata=function(t,e){return xr(t).put({bundleId:(n=e).id,createTime:Ir(on(n.createTime)),version:n.version});var n},t.prototype.getNamedQuery=function(t,e){return kr(t).get(e).next(function(t){if(t)return{name:(e=t).name,query:Dr(e.bundledQuery),readTime:Er(e.readTime)};var e})},t.prototype.saveNamedQuery=function(t,e){return kr(t).put(function(t){return{name:t.name,readTime:Ir(on(t.readTime)),bundledQuery:t.bundledQuery}}(e))},t}();function xr(t){return dr(t,$n.store)}function kr(t){return dr(t,Xn.store)}var Cr=function(){function t(){this.Bt=new Rr}return t.prototype.addToCollectionParentIndex=function(t,e){return this.Bt.add(e),nr.resolve()},t.prototype.getCollectionParents=function(t,e){return nr.resolve(this.Bt.getEntries(e))},t}(),Rr=function(){function t(){this.index={}}return t.prototype.add=function(t){var e=t.lastSegment(),n=t.popLast(),r=this.index[e]||new Ce(x.comparator),i=!r.has(n);return this.index[e]=r.add(n),i},t.prototype.has=function(t){var e=t.lastSegment(),n=t.popLast(),r=this.index[e];return r&&r.has(n)},t.prototype.getEntries=function(t){return(this.index[t]||new Ce(x.comparator)).toArray()},t}(),Lr=function(){function t(){this.qt=new Rr}return t.prototype.addToCollectionParentIndex=function(t,e){var n=this;if(!this.qt.has(e)){var r=e.lastSegment(),i=e.popLast();t.addOnCommittedListener(function(){n.qt.add(e)});var o={collectionId:r,parent:Rn(i)};return Or(t).put(o)}return nr.resolve()},t.prototype.getCollectionParents=function(t,e){var n=[],r=IDBKeyRange.bound([e,""],[I(e),""],!1,!0);return Or(t).Nt(r).next(function(t){for(var r=0,i=t;r<i.length;r++){var o=i[r];if(o.collectionId!==e)break;n.push(Pn(o.parent))}return n})},t}();function Or(t){return dr(t,Hn.store)}var Pr={didRun:!1,sequenceNumbersCollected:0,targetsRemoved:0,documentsRemoved:0},Fr=function(){function t(t,e,n){this.cacheSizeCollectionThreshold=t,this.percentileToCollect=e,this.maximumSequenceNumbersToCollect=n}return t.withCacheSize=function(e){return new t(e,t.DEFAULT_COLLECTION_PERCENTILE,t.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT)},t}();function Mr(t,e,n){var r=t.store(qn.store),i=t.store(Un.store),o=[],s=IDBKeyRange.only(n.batchId),a=0,u=r.$t({range:s},function(t,e,n){return a++,n.delete()});o.push(u.next(function(){v(1===a)}));for(var c=[],h=0,f=n.mutations;h<f.length;h++){var l=f[h],d=Un.key(e,l.key.path,n.batchId);o.push(i.delete(d)),c.push(l.key)}return nr.waitFor(o).next(function(){return c})}function Vr(t){if(!t)return 0;var e;if(t.document)e=t.document;else if(t.unknownDocument)e=t.unknownDocument;else{if(!t.noDocument)throw y();e=t.noDocument}return JSON.stringify(e).length}Fr.DEFAULT_COLLECTION_PERCENTILE=10,Fr.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT=1e3,Fr.DEFAULT=new Fr(41943040,Fr.DEFAULT_COLLECTION_PERCENTILE,Fr.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT),Fr.DISABLED=new Fr(-1,0,0);var qr=function(){function t(t,e,n,r){this.userId=t,this.R=e,this.Ut=n,this.referenceDelegate=r,this.Kt={}}return t.Qt=function(e,n,r,i){return v(""!==e.uid),new t(e.isAuthenticated()?e.uid:"",n,r,i)},t.prototype.checkEmpty=function(t){var e=!0,n=IDBKeyRange.bound([this.userId,Number.NEGATIVE_INFINITY],[this.userId,Number.POSITIVE_INFINITY]);return Br(t).$t({index:qn.userMutationsIndex,range:n},function(t,n,r){e=!1,r.done()}).next(function(){return e})},t.prototype.addMutationBatch=function(t,e,n,r){var i=this,o=jr(t),s=Br(t);return s.add({}).next(function(a){v("number"==typeof a);for(var u=new pr(a,e,n,r),c=function(t,e,n){var r=n.baseMutations.map(function(e){return vn(t.Lt,e)}),i=n.mutations.map(function(e){return vn(t.Lt,e)});return new qn(e,n.batchId,n.localWriteTime.toMillis(),r,i)}(i.R,i.userId,u),h=[],f=new Ce(function(t,e){return w(t.canonicalString(),e.canonicalString())}),l=0,d=r;l<d.length;l++){var p=d[l],y=Un.key(i.userId,p.key.path,a);f=f.add(p.key.path.popLast()),h.push(s.put(c)),h.push(o.put(y,Un.PLACEHOLDER))}return f.forEach(function(e){h.push(i.Ut.addToCollectionParentIndex(t,e))}),t.addOnCommittedListener(function(){i.Kt[a]=u.keys()}),nr.waitFor(h).next(function(){return u})})},t.prototype.lookupMutationBatch=function(t,e){var n=this;return Br(t).get(e).next(function(t){return t?(v(t.userId===n.userId),Tr(n.R,t)):null})},t.prototype.jt=function(t,e){var n=this;return this.Kt[e]?nr.resolve(this.Kt[e]):this.lookupMutationBatch(t,e).next(function(t){if(t){var r=t.keys();return n.Kt[e]=r,r}return null})},t.prototype.getNextMutationBatchAfterBatchId=function(t,e){var n=this,r=e+1,i=IDBKeyRange.lowerBound([this.userId,r]),o=null;return Br(t).$t({index:qn.userMutationsIndex,range:i},function(t,e,i){e.userId===n.userId&&(v(e.batchId>=r),o=Tr(n.R,e)),i.done()}).next(function(){return o})},t.prototype.getHighestUnacknowledgedBatchId=function(t){var e=IDBKeyRange.upperBound([this.userId,Number.POSITIVE_INFINITY]),n=-1;return Br(t).$t({index:qn.userMutationsIndex,range:e,reverse:!0},function(t,e,r){n=e.batchId,r.done()}).next(function(){return n})},t.prototype.getAllMutationBatches=function(t){var e=this,n=IDBKeyRange.bound([this.userId,-1],[this.userId,Number.POSITIVE_INFINITY]);return Br(t).Nt(qn.userMutationsIndex,n).next(function(t){return t.map(function(t){return Tr(e.R,t)})})},t.prototype.getAllMutationBatchesAffectingDocumentKey=function(t,e){var n=this,r=Un.prefixForPath(this.userId,e.path),i=IDBKeyRange.lowerBound(r),o=[];return jr(t).$t({range:i},function(r,i,s){var a=r[0],u=r[1],c=r[2],h=Pn(u);if(a===n.userId&&e.path.isEqual(h))return Br(t).get(c).next(function(t){if(!t)throw y();v(t.userId===n.userId),o.push(Tr(n.R,t))});s.done()}).next(function(){return o})},t.prototype.getAllMutationBatchesAffectingDocumentKeys=function(t,e){var n=this,r=new Ce(w),i=[];return e.forEach(function(e){var o=Un.prefixForPath(n.userId,e.path),s=IDBKeyRange.lowerBound(o),a=jr(t).$t({range:s},function(t,i,o){var s=t[0],a=t[1],u=t[2],c=Pn(a);s===n.userId&&e.path.isEqual(c)?r=r.add(u):o.done()});i.push(a)}),nr.waitFor(i).next(function(){return n.Wt(t,r)})},t.prototype.getAllMutationBatchesAffectingQuery=function(t,e){var n=this,r=e.path,i=r.length+1,o=Un.prefixForPath(this.userId,r),s=IDBKeyRange.lowerBound(o),a=new Ce(w);return jr(t).$t({range:s},function(t,e,o){var s=t[0],u=t[1],c=t[2],h=Pn(u);s===n.userId&&r.isPrefixOf(h)?h.length===i&&(a=a.add(c)):o.done()}).next(function(){return n.Wt(t,a)})},t.prototype.Wt=function(t,e){var n=this,r=[],i=[];return e.forEach(function(e){i.push(Br(t).get(e).next(function(t){if(null===t)throw y();v(t.userId===n.userId),r.push(Tr(n.R,t))}))}),nr.waitFor(i).next(function(){return r})},t.prototype.removeMutationBatch=function(t,e){var n=this;return Mr(t.Mt,this.userId,e).next(function(r){return t.addOnCommittedListener(function(){n.Gt(e.batchId)}),nr.forEach(r,function(e){return n.referenceDelegate.markPotentiallyOrphaned(t,e)})})},t.prototype.Gt=function(t){delete this.Kt[t]},t.prototype.performConsistencyCheck=function(t){var e=this;return this.checkEmpty(t).next(function(n){if(!n)return nr.resolve();var r=IDBKeyRange.lowerBound(Un.prefixForUser(e.userId)),i=[];return jr(t).$t({range:r},function(t,n,r){if(t[0]===e.userId){var o=Pn(t[1]);i.push(o)}else r.done()}).next(function(){v(0===i.length)})})},t.prototype.containsKey=function(t,e){return Ur(t,this.userId,e)},t.prototype.zt=function(t){var e=this;return Kr(t).get(this.userId).next(function(t){return t||new Vn(e.userId,-1,"")})},t}();function Ur(t,e,n){var r=Un.prefixForPath(e,n.path),i=r[1],o=IDBKeyRange.lowerBound(r),s=!1;return jr(t).$t({range:o,Ft:!0},function(t,n,r){var o=t[0],a=t[1];t[2],o===e&&a===i&&(s=!0),r.done()}).next(function(){return s})}function Br(t){return dr(t,qn.store)}function jr(t){return dr(t,Un.store)}function Kr(t){return dr(t,Vn.store)}var Gr=function(){function t(t){this.Ht=t}return t.prototype.next=function(){return this.Ht+=2,this.Ht},t.Jt=function(){return new t(0)},t.Yt=function(){return new t(-1)},t}(),Qr=function(){function t(t,e){this.referenceDelegate=t,this.R=e}return t.prototype.allocateTargetId=function(t){var e=this;return this.Xt(t).next(function(n){var r=new Gr(n.highestTargetId);return n.highestTargetId=r.next(),e.Zt(t,n).next(function(){return n.highestTargetId})})},t.prototype.getLastRemoteSnapshotVersion=function(t){return this.Xt(t).next(function(t){return T.fromTimestamp(new E(t.lastRemoteSnapshotVersion.seconds,t.lastRemoteSnapshotVersion.nanoseconds))})},t.prototype.getHighestSequenceNumber=function(t){return this.Xt(t).next(function(t){return t.highestListenSequenceNumber})},t.prototype.setTargetsMetadata=function(t,e,n){var r=this;return this.Xt(t).next(function(i){return i.highestListenSequenceNumber=e,n&&(i.lastRemoteSnapshotVersion=n.toTimestamp()),e>i.highestListenSequenceNumber&&(i.highestListenSequenceNumber=e),r.Zt(t,i)})},t.prototype.addTargetData=function(t,e){var n=this;return this.te(t,e).next(function(){return n.Xt(t).next(function(r){return r.targetCount+=1,n.ee(e,r),n.Zt(t,r)})})},t.prototype.updateTargetData=function(t,e){return this.te(t,e)},t.prototype.removeTargetData=function(t,e){var n=this;return this.removeMatchingKeysForTargetId(t,e.targetId).next(function(){return zr(t).delete(e.targetId)}).next(function(){return n.Xt(t)}).next(function(e){return v(e.targetCount>0),e.targetCount-=1,n.Zt(t,e)})},t.prototype.removeTargets=function(t,e,n){var r=this,i=0,o=[];return zr(t).$t(function(s,a){var u=Sr(a);u.sequenceNumber<=e&&null===n.get(u.targetId)&&(i++,o.push(r.removeTargetData(t,u)))}).next(function(){return nr.waitFor(o)}).next(function(){return i})},t.prototype.forEachTarget=function(t,e){return zr(t).$t(function(t,n){var r=Sr(n);e(r)})},t.prototype.Xt=function(t){return Wr(t).get(Wn.key).next(function(t){return v(null!==t),t})},t.prototype.Zt=function(t,e){return Wr(t).put(Wn.key,e)},t.prototype.te=function(t,e){return zr(t).put(Nr(this.R,e))},t.prototype.ee=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.getTargetCount=function(t){return this.Xt(t).next(function(t){return t.targetCount})},t.prototype.getTargetData=function(t,e){var n=ht(e),r=IDBKeyRange.bound([n,Number.NEGATIVE_INFINITY],[n,Number.POSITIVE_INFINITY]),i=null;return zr(t).$t({range:r,index:Qn.queryTargetsIndexName},function(t,n,r){var o=Sr(n);ft(e,o.target)&&(i=o,r.done())}).next(function(){return i})},t.prototype.addMatchingKeys=function(t,e,n){var r=this,i=[],o=Hr(t);return e.forEach(function(e){var s=Rn(e.path);i.push(o.put(new zn(n,s))),i.push(r.referenceDelegate.addReference(t,n,e))}),nr.waitFor(i)},t.prototype.removeMatchingKeys=function(t,e,n){var r=this,i=Hr(t);return nr.forEach(e,function(e){var o=Rn(e.path);return nr.waitFor([i.delete([n,o]),r.referenceDelegate.removeReference(t,n,e)])})},t.prototype.removeMatchingKeysForTargetId=function(t,e){var n=Hr(t),r=IDBKeyRange.bound([e],[e+1],!1,!0);return n.delete(r)},t.prototype.getMatchingKeysForTargetId=function(t,e){var n=IDBKeyRange.bound([e],[e+1],!1,!0),r=Hr(t),i=Ue();return r.$t({range:n,Ft:!0},function(t,e,n){var r=Pn(t[1]),o=new G(r);i=i.add(o)}).next(function(){return i})},t.prototype.containsKey=function(t,e){var n=Rn(e.path),r=IDBKeyRange.bound([n],[I(n)],!1,!0),i=0;return Hr(t).$t({index:zn.documentTargetsIndex,Ft:!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.lt=function(t,e){return zr(t).get(e).next(function(t){return t?Sr(t):null})},t}();function zr(t){return dr(t,Qn.store)}function Wr(t){return dr(t,Wn.store)}function Hr(t){return dr(t,zn.store)}function Yr(t){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(e){if(t.code!==a.FAILED_PRECONDITION||t.message!==Zn)throw t;return f("LocalStore","Unexpectedly lost primary lease"),[2]})})}function $r(t,e){var n=t[0],r=t[1],i=e[0],o=e[1],s=w(n,i);return 0===s?w(r,o):s}var Xr=function(){function t(t){this.ne=t,this.buffer=new Ce($r),this.se=0}return t.prototype.ie=function(){return++this.se},t.prototype.re=function(t){var e=[t,this.ie()];if(this.buffer.size<this.ne)this.buffer=this.buffer.add(e);else{var n=this.buffer.last();$r(e,n)<0&&(this.buffer=this.buffer.delete(n).add(e))}},Object.defineProperty(t.prototype,"maxValue",{get:function(){return this.buffer.last()[0]},enumerable:!1,configurable:!0}),t}(),Jr=function(){function t(t,e){this.garbageCollector=t,this.asyncQueue=e,this.oe=!1,this.ce=null}return t.prototype.start=function(t){-1!==this.garbageCollector.params.cacheSizeCollectionThreshold&&this.ue(t)},t.prototype.stop=function(){this.ce&&(this.ce.cancel(),this.ce=null)},Object.defineProperty(t.prototype,"started",{get:function(){return null!==this.ce},enumerable:!1,configurable:!0}),t.prototype.ue=function(t){var n=this,r=this.oe?3e5:6e4;f("LruGarbageCollector","Garbage collection scheduled in "+r+"ms"),this.ce=this.asyncQueue.enqueueAfterDelay("lru_garbage_collection",r,function(){return(0,e.__awaiter)(n,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:this.ce=null,this.oe=!0,e.label=1;case 1:return e.trys.push([1,3,,7]),[4,t.collectGarbage(this.garbageCollector)];case 2:return e.sent(),[3,7];case 3:return ar(n=e.sent())?(f("LruGarbageCollector","Ignoring IndexedDB error during garbage collection: ",n),[3,6]):[3,4];case 4:return[4,Yr(n)];case 5:e.sent(),e.label=6;case 6:return[3,7];case 7:return[4,this.ue(t)];case 8:return e.sent(),[2]}})})})},t}(),Zr=function(){function t(t,e){this.ae=t,this.params=e}return t.prototype.calculateTargetCount=function(t,e){return this.ae.he(t).next(function(t){return Math.floor(e/100*t)})},t.prototype.nthSequenceNumber=function(t,e){var n=this;if(0===e)return nr.resolve(s.o);var r=new Xr(e);return this.ae.forEachTarget(t,function(t){return r.re(t.sequenceNumber)}).next(function(){return n.ae.le(t,function(t){return r.re(t)})}).next(function(){return r.maxValue})},t.prototype.removeTargets=function(t,e,n){return this.ae.removeTargets(t,e,n)},t.prototype.removeOrphanedDocuments=function(t,e){return this.ae.removeOrphanedDocuments(t,e)},t.prototype.collect=function(t,e){var n=this;return-1===this.params.cacheSizeCollectionThreshold?(f("LruGarbageCollector","Garbage collection skipped; disabled"),nr.resolve(Pr)):this.getCacheSize(t).next(function(r){return r<n.params.cacheSizeCollectionThreshold?(f("LruGarbageCollector","Garbage collection skipped; Cache size "+r+" is lower than threshold "+n.params.cacheSizeCollectionThreshold),Pr):n.fe(t,e)})},t.prototype.getCacheSize=function(t){return this.ae.getCacheSize(t)},t.prototype.fe=function(t,e){var n,i,o,s,a,u,c,l=this,d=Date.now();return this.calculateTargetCount(t,this.params.percentileToCollect).next(function(e){return e>l.params.maximumSequenceNumbersToCollect?(f("LruGarbageCollector","Capping sequence numbers to collect down to the maximum of "+l.params.maximumSequenceNumbersToCollect+" from "+e),i=l.params.maximumSequenceNumbersToCollect):i=e,s=Date.now(),l.nthSequenceNumber(t,i)}).next(function(r){return n=r,a=Date.now(),l.removeTargets(t,n,e)}).next(function(e){return o=e,u=Date.now(),l.removeOrphanedDocuments(t,n)}).next(function(t){return c=Date.now(),h()<=r.LogLevel.DEBUG&&f("LruGarbageCollector","LRU Garbage Collection\n\tCounted targets in "+(s-d)+"ms\n\tDetermined least recently used "+i+" in "+(a-s)+"ms\n\tRemoved "+o+" targets in "+(u-a)+"ms\n\tRemoved "+t+" documents in "+(c-u)+"ms\nTotal Duration: "+(c-d)+"ms"),nr.resolve({didRun:!0,sequenceNumbersCollected:i,targetsRemoved:o,documentsRemoved:t})})},t}(),ti=function(){function t(t,e){this.db=t,this.garbageCollector=function(t,e){return new Zr(t,e)}(this,e)}return t.prototype.he=function(t){var e=this.de(t);return this.db.getTargetCache().getTargetCount(t).next(function(t){return e.next(function(e){return t+e})})},t.prototype.de=function(t){var e=0;return this.le(t,function(t){e++}).next(function(){return e})},t.prototype.forEachTarget=function(t,e){return this.db.getTargetCache().forEachTarget(t,e)},t.prototype.le=function(t,e){return this.we(t,function(t,n){return e(n)})},t.prototype.addReference=function(t,e,n){return ei(t,n)},t.prototype.removeReference=function(t,e,n){return ei(t,n)},t.prototype.removeTargets=function(t,e,n){return this.db.getTargetCache().removeTargets(t,e,n)},t.prototype.markPotentiallyOrphaned=function(t,e){return ei(t,e)},t.prototype._e=function(t,e){return function(t,e){var n=!1;return Kr(t).Ot(function(r){return Ur(t,r,e).next(function(t){return t&&(n=!0),nr.resolve(!t)})}).next(function(){return n})}(t,e)},t.prototype.removeOrphanedDocuments=function(t,e){var n=this,r=this.db.getRemoteDocumentCache().newChangeBuffer(),i=[],o=0;return this.we(t,function(s,a){if(a<=e){var u=n._e(t,s).next(function(e){if(!e)return o++,r.getEntry(t,s).next(function(){return r.removeEntry(s),Hr(t).delete([0,Rn(s.path)])})});i.push(u)}}).next(function(){return nr.waitFor(i)}).next(function(){return r.apply(t)}).next(function(){return o})},t.prototype.removeTarget=function(t,e){var n=e.withSequenceNumber(t.currentSequenceNumber);return this.db.getTargetCache().updateTargetData(t,n)},t.prototype.updateLimboDocument=function(t,e){return ei(t,e)},t.prototype.we=function(t,e){var n,r=Hr(t),i=s.o;return r.$t({index:zn.documentTargetsIndex},function(t,r){var o=t[0];t[1];var a=r.path,u=r.sequenceNumber;0===o?(i!==s.o&&e(new G(Pn(n)),i),i=u,n=a):i=s.o}).next(function(){i!==s.o&&e(new G(Pn(n)),i)})},t.prototype.getCacheSize=function(t){return this.db.getRemoteDocumentCache().getSize(t)},t}();function ei(t,e){return Hr(t).put(function(t,e){return new zn(0,Rn(t.path),e)}(e,t.currentSequenceNumber))}var ni=function(){function t(t,e){this.mapKeyFn=t,this.equalsFn=e,this.inner={}}return t.prototype.get=function(t){var e=this.mapKeyFn(t),n=this.inner[e];if(void 0!==n)for(var r=0,i=n;r<i.length;r++){var o=i[r],s=o[0],a=o[1];if(this.equalsFn(s,t))return a}},t.prototype.has=function(t){return void 0!==this.get(t)},t.prototype.set=function(t,e){var n=this.mapKeyFn(t),r=this.inner[n];if(void 0!==r){for(var i=0;i<r.length;i++)if(this.equalsFn(r[i][0],t))return void(r[i]=[t,e]);r.push([t,e])}else this.inner[n]=[[t,e]]},t.prototype.delete=function(t){var e=this.mapKeyFn(t),n=this.inner[e];if(void 0===n)return!1;for(var r=0;r<n.length;r++)if(this.equalsFn(n[r][0],t))return 1===n.length?delete this.inner[e]:n.splice(r,1),!0;return!1},t.prototype.forEach=function(t){N(this.inner,function(e,n){for(var r=0,i=n;r<i.length;r++){var o=i[r],s=o[0],a=o[1];t(s,a)}})},t.prototype.isEmpty=function(){return D(this.inner)},t}(),ri=function(){function t(){this.changes=new ni(function(t){return t.toString()},function(t,e){return t.isEqual(e)}),this.changesApplied=!1}return t.prototype.getReadTime=function(t){var e=this.changes.get(t);return e?e.readTime:T.min()},t.prototype.addEntry=function(t,e){this.assertNotApplied(),this.changes.set(t.key,{document:t,readTime:e})},t.prototype.removeEntry=function(t,e){void 0===e&&(e=null),this.assertNotApplied(),this.changes.set(t,{document:at.newInvalidDocument(t),readTime:e})},t.prototype.getEntry=function(t,e){this.assertNotApplied();var n=this.changes.get(e);return void 0!==n?nr.resolve(n.document):this.getFromCache(t,e)},t.prototype.getEntries=function(t,e){return this.getAllFromCache(t,e)},t.prototype.apply=function(t){return this.assertNotApplied(),this.changesApplied=!0,this.applyChanges(t)},t.prototype.assertNotApplied=function(){},t}(),ii=function(){function t(t,e){this.R=t,this.Ut=e}return t.prototype.addEntry=function(t,e,n){return ai(t).put(ui(e),n)},t.prototype.removeEntry=function(t,e){var n=ai(t),r=ui(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.me(t,r)})},t.prototype.getEntry=function(t,e){var n=this;return ai(t).get(ui(e)).next(function(t){return n.ye(e,t)})},t.prototype.ge=function(t,e){var n=this;return ai(t).get(ui(e)).next(function(t){return{document:n.ye(e,t),size:Vr(t)}})},t.prototype.getEntries=function(t,e){var n=this,r=Oe();return this.pe(t,e,function(t,e){var i=n.ye(t,e);r=r.insert(t,i)}).next(function(){return r})},t.prototype.Ee=function(t,e){var n=this,r=Oe(),i=new Ae(G.comparator);return this.pe(t,e,function(t,e){var o=n.ye(t,e);r=r.insert(t,o),i=i.insert(t,Vr(e))}).next(function(){return{documents:r,Te:i}})},t.prototype.pe=function(t,e,n){if(e.isEmpty())return nr.resolve();var r=IDBKeyRange.bound(e.first().path.toArray(),e.last().path.toArray()),i=e.getIterator(),o=i.getNext();return ai(t).$t({range:r},function(t,e,r){for(var s=G.fromSegments(t);o&&G.comparator(o,s)<0;)n(o,null),o=i.getNext();o&&o.isEqual(s)&&(n(o,e),o=i.hasNext()?i.getNext():null),o?r.Ct(o.path.toArray()):r.done()}).next(function(){for(;o;)n(o,null),o=i.hasNext()?i.getNext():null})},t.prototype.getDocumentsMatchingQuery=function(t,e,n){var r=this,i=Oe(),o=e.path.length+1,s={};if(n.isEqual(T.min())){var a=e.path.toArray();s.range=IDBKeyRange.lowerBound(a)}else{var u=e.path.toArray(),c=wr(n);s.range=IDBKeyRange.lowerBound([u,c],!0),s.index=Kn.collectionReadTimeIndex}return ai(t).$t(s,function(t,n,s){if(t.length===o){var a=gr(r.R,n);e.path.isPrefixOf(a.key.path)?jt(e,a)&&(i=i.insert(a.key,a)):s.done()}}).next(function(){return i})},t.prototype.newChangeBuffer=function(t){return new oi(this,!!t&&t.trackRemovals)},t.prototype.getSize=function(t){return this.getMetadata(t).next(function(t){return t.byteSize})},t.prototype.getMetadata=function(t){return si(t).get(Gn.key).next(function(t){return v(!!t),t})},t.prototype.me=function(t,e){return si(t).put(Gn.key,e)},t.prototype.ye=function(t,e){if(e){var n=gr(this.R,e);if(!n.isNoDocument()||!n.version.isEqual(T.min()))return n}return at.newInvalidDocument(t)},t}(),oi=function(t){function n(e,n){var r=this;return(r=t.call(this)||this).Ie=e,r.trackRemovals=n,r.Ae=new ni(function(t){return t.toString()},function(t,e){return t.isEqual(e)}),r}return(0,e.__extends)(n,t),n.prototype.applyChanges=function(t){var e=this,n=[],r=0,i=new Ce(function(t,e){return w(t.canonicalString(),e.canonicalString())});return this.changes.forEach(function(o,s){var a=e.Ae.get(o);if(s.document.isValidDocument()){var u=_r(e.Ie.R,s.document,e.getReadTime(o));i=i.add(o.path.popLast());var c=Vr(u);r+=c-a,n.push(e.Ie.addEntry(t,o,u))}else if(r-=a,e.trackRemovals){var h=_r(e.Ie.R,at.newNoDocument(o,T.min()),e.getReadTime(o));n.push(e.Ie.addEntry(t,o,h))}else n.push(e.Ie.removeEntry(t,o))}),i.forEach(function(r){n.push(e.Ie.Ut.addToCollectionParentIndex(t,r))}),n.push(this.Ie.updateMetadata(t,r)),nr.waitFor(n)},n.prototype.getFromCache=function(t,e){var n=this;return this.Ie.ge(t,e).next(function(t){return n.Ae.set(e,t.size),t.document})},n.prototype.getAllFromCache=function(t,e){var n=this;return this.Ie.Ee(t,e).next(function(t){var e=t.documents;return t.Te.forEach(function(t,e){n.Ae.set(t,e)}),e})},n}(ri);function si(t){return dr(t,Gn.store)}function ai(t){return dr(t,Kn.store)}function ui(t){return t.path.toArray()}var ci=function(){function t(t){this.R=t}return t.prototype.Rt=function(t,e,n,r){var i=this;v(n<r&&n>=0&&r<=11);var o=new rr("createOrUpgrade",e);n<1&&r>=1&&(function(t){t.createObjectStore(Mn.store)}(t),function(t){t.createObjectStore(Vn.store,{keyPath:Vn.keyPath}),t.createObjectStore(qn.store,{keyPath:qn.keyPath,autoIncrement:!0}).createIndex(qn.userMutationsIndex,qn.userMutationsKeyPath,{unique:!0}),t.createObjectStore(Un.store)}(t),hi(t),function(t){t.createObjectStore(Kn.store)}(t));var s=nr.resolve();return n<3&&r>=3&&(0!==n&&(function(t){t.deleteObjectStore(zn.store),t.deleteObjectStore(Qn.store),t.deleteObjectStore(Wn.store)}(t),hi(t)),s=s.next(function(){return t=o.store(Wn.store),e=new Wn(0,0,T.min().toTimestamp(),0),t.put(Wn.key,e);var t,e})),n<4&&r>=4&&(0!==n&&(s=s.next(function(){return function(t,e){return e.store(qn.store).Nt().next(function(n){t.deleteObjectStore(qn.store),t.createObjectStore(qn.store,{keyPath:qn.keyPath,autoIncrement:!0}).createIndex(qn.userMutationsIndex,qn.userMutationsKeyPath,{unique:!0});var r=e.store(qn.store),i=n.map(function(t){return r.put(t)});return nr.waitFor(i)})}(t,o)})),s=s.next(function(){!function(t){t.createObjectStore(Yn.store,{keyPath:Yn.keyPath})}(t)})),n<5&&r>=5&&(s=s.next(function(){return i.Re(o)})),n<6&&r>=6&&(s=s.next(function(){return function(t){t.createObjectStore(Gn.store)}(t),i.be(o)})),n<7&&r>=7&&(s=s.next(function(){return i.ve(o)})),n<8&&r>=8&&(s=s.next(function(){return i.Pe(t,o)})),n<9&&r>=9&&(s=s.next(function(){!function(t){t.objectStoreNames.contains("remoteDocumentChanges")&&t.deleteObjectStore("remoteDocumentChanges")}(t),function(t){var e=t.objectStore(Kn.store);e.createIndex(Kn.readTimeIndex,Kn.readTimeIndexPath,{unique:!1}),e.createIndex(Kn.collectionReadTimeIndex,Kn.collectionReadTimeIndexPath,{unique:!1})}(e)})),n<10&&r>=10&&(s=s.next(function(){return i.Ve(o)})),n<11&&r>=11&&(s=s.next(function(){!function(t){t.createObjectStore($n.store,{keyPath:$n.keyPath})}(t),function(t){t.createObjectStore(Xn.store,{keyPath:Xn.keyPath})}(t)})),s},t.prototype.be=function(t){var e=0;return t.store(Kn.store).$t(function(t,n){e+=Vr(n)}).next(function(){var n=new Gn(e);return t.store(Gn.store).put(Gn.key,n)})},t.prototype.Re=function(t){var e=this,n=t.store(Vn.store),r=t.store(qn.store);return n.Nt().next(function(n){return nr.forEach(n,function(n){var i=IDBKeyRange.bound([n.userId,-1],[n.userId,n.lastAcknowledgedBatchId]);return r.Nt(qn.userMutationsIndex,i).next(function(r){return nr.forEach(r,function(r){v(r.userId===n.userId);var i=Tr(e.R,r);return Mr(t,n.userId,i).next(function(){})})})})})},t.prototype.ve=function(t){var e=t.store(zn.store),n=t.store(Kn.store);return t.store(Wn.store).get(Wn.key).next(function(t){var r=[];return n.$t(function(n,i){var o=new x(n),s=[0,Rn(o)];r.push(e.get(s).next(function(n){return n?nr.resolve():function(n){return e.put(new zn(0,Rn(n),t.highestListenSequenceNumber))}(o)}))}).next(function(){return nr.waitFor(r)})})},t.prototype.Pe=function(t,e){t.createObjectStore(Hn.store,{keyPath:Hn.keyPath});var n=e.store(Hn.store),r=new Rr,i=function(t){if(r.add(t)){var e=t.lastSegment(),i=t.popLast();return n.put({collectionId:e,parent:Rn(i)})}};return e.store(Kn.store).$t({Ft:!0},function(t,e){var n=new x(t);return i(n.popLast())}).next(function(){return e.store(Un.store).$t({Ft:!0},function(t,e){t[0];var n=t[1];t[2];var r=Pn(n);return i(r.popLast())})})},t.prototype.Ve=function(t){var e=this,n=t.store(Qn.store);return n.$t(function(t,r){var i=Sr(r),o=Nr(e.R,i);return n.put(o)})},t}();function hi(t){t.createObjectStore(zn.store,{keyPath:zn.keyPath}).createIndex(zn.documentTargetsIndex,zn.documentTargetsKeyPath,{unique:!0}),t.createObjectStore(Qn.store,{keyPath:Qn.keyPath}).createIndex(Qn.queryTargetsIndexName,Qn.queryTargetsKeyPath,{unique:!0}),t.createObjectStore(Wn.store)}var fi="Failed to obtain exclusive access to the persistence layer. To allow shared access, multi-tab synchronization has to be enabled in all tabs. If you are using `experimentalForceOwningTab:true`, make sure that only one tab has persistence enabled at any given time.",li=function(){function t(e,n,r,i,o,s,c,h,f,d){if(this.allowTabSynchronization=e,this.persistenceKey=n,this.clientId=r,this.Se=o,this.window=s,this.document=c,this.De=f,this.Ce=d,this.Ne=null,this.xe=!1,this.isPrimary=!1,this.networkEnabled=!0,this.ke=null,this.inForeground=!1,this.Fe=null,this.$e=null,this.Oe=Number.NEGATIVE_INFINITY,this.Me=function(t){return Promise.resolve()},!t.yt())throw new u(a.UNIMPLEMENTED,"This platform is either missing IndexedDB or is known to have an incomplete implementation. Offline persistence has been disabled.");this.referenceDelegate=new ti(this,i),this.Le=n+"main",this.R=new mr(h),this.Be=new ir(this.Le,11,new ci(this.R)),this.qe=new Qr(this.referenceDelegate,this.R),this.Ut=new Lr,this.Ue=function(t,e){return new ii(t,e)}(this.R,this.Ut),this.Ke=new Ar,this.window&&this.window.localStorage?this.Qe=this.window.localStorage:(this.Qe=null,!1===d&&l("IndexedDbPersistence","LocalStorage is unavailable. As a result, persistence may not work reliably. In particular enablePersistence() could fail immediately after refreshing the page."))}return t.prototype.start=function(){var t=this;return this.je().then(function(){if(!t.isPrimary&&!t.allowTabSynchronization)throw new u(a.FAILED_PRECONDITION,fi);return t.We(),t.Ge(),t.ze(),t.runTransaction("getHighestListenSequenceNumber","readonly",function(e){return t.qe.getHighestSequenceNumber(e)})}).then(function(e){t.Ne=new s(e,t.De)}).then(function(){t.xe=!0}).catch(function(e){return t.Be&&t.Be.close(),Promise.reject(e)})},t.prototype.He=function(t){var n=this;return this.Me=function(r){return(0,e.__awaiter)(n,void 0,void 0,function(){return(0,e.__generator)(this,function(e){return this.started?[2,t(r)]:[2]})})},t(this.isPrimary)},t.prototype.setDatabaseDeletedListener=function(t){var n=this;this.Be.vt(function(r){return(0,e.__awaiter)(n,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return null===r.newVersion?[4,t()]:[3,2];case 1:e.sent(),e.label=2;case 2:return[2]}})})})},t.prototype.setNetworkEnabled=function(t){var n=this;this.networkEnabled!==t&&(this.networkEnabled=t,this.Se.enqueueAndForget(function(){return(0,e.__awaiter)(n,void 0,void 0,function(){return(0,e.__generator)(this,function(t){switch(t.label){case 0:return this.started?[4,this.je()]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}})})}))},t.prototype.je=function(){var t=this;return this.runTransaction("updateClientMetadataAndTryBecomePrimary","readwrite",function(e){return pi(e).put(new Yn(t.clientId,Date.now(),t.networkEnabled,t.inForeground)).next(function(){if(t.isPrimary)return t.Je(e).next(function(e){e||(t.isPrimary=!1,t.Se.enqueueRetryable(function(){return t.Me(!1)}))})}).next(function(){return t.Ye(e)}).next(function(n){return t.isPrimary&&!n?t.Xe(e).next(function(){return!1}):!!n&&t.Ze(e).next(function(){return!0})})}).catch(function(e){if(ar(e))return f("IndexedDbPersistence","Failed to extend owner lease: ",e),t.isPrimary;if(!t.allowTabSynchronization)throw e;return f("IndexedDbPersistence","Releasing owner lease after error during lease refresh",e),!1}).then(function(e){t.isPrimary!==e&&t.Se.enqueueRetryable(function(){return t.Me(e)}),t.isPrimary=e})},t.prototype.Je=function(t){var e=this;return di(t).get(Mn.key).next(function(t){return nr.resolve(e.tn(t))})},t.prototype.en=function(t){return pi(t).delete(this.clientId)},t.prototype.nn=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var t,n,r,i,o=this;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return!this.isPrimary||this.sn(this.Oe,18e5)?[3,2]:(this.Oe=Date.now(),[4,this.runTransaction("maybeGarbageCollectMultiClientState","readwrite-primary",function(t){var e=dr(t,Yn.store);return e.Nt().next(function(t){var n=o.rn(t,18e5),r=t.filter(function(t){return-1===n.indexOf(t)});return nr.forEach(r,function(t){return e.delete(t.clientId)}).next(function(){return r})})}).catch(function(){return[]})]);case 1:if(t=e.sent(),this.Qe)for(n=0,r=t;n<r.length;n++)i=r[n],this.Qe.removeItem(this.on(i.clientId));e.label=2;case 2:return[2]}})})},t.prototype.ze=function(){var t=this;this.$e=this.Se.enqueueAfterDelay("client_metadata_refresh",4e3,function(){return t.je().then(function(){return t.nn()}).then(function(){return t.ze()})})},t.prototype.tn=function(t){return!!t&&t.ownerId===this.clientId},t.prototype.Ye=function(t){var e=this;return this.Ce?nr.resolve(!0):di(t).get(Mn.key).next(function(n){if(null!==n&&e.sn(n.leaseTimestampMs,5e3)&&!e.cn(n.ownerId)){if(e.tn(n)&&e.networkEnabled)return!0;if(!e.tn(n)){if(!n.allowTabSynchronization)throw new u(a.FAILED_PRECONDITION,fi);return!1}}return!(!e.networkEnabled||!e.inForeground)||pi(t).Nt().next(function(t){return void 0===e.rn(t,5e3).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&&f("IndexedDbPersistence","Client "+(t?"is":"is not")+" eligible for a primary lease."),t})},t.prototype.shutdown=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var t=this;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return this.xe=!1,this.un(),this.$e&&(this.$e.cancel(),this.$e=null),this.an(),this.hn(),[4,this.Be.runTransaction("shutdown","readwrite",[Mn.store,Yn.store],function(e){var n=new lr(e,s.o);return t.Xe(n).next(function(){return t.en(n)})})];case 1:return e.sent(),this.Be.close(),this.ln(),[2]}})})},t.prototype.rn=function(t,e){var n=this;return t.filter(function(t){return n.sn(t.updateTimeMs,e)&&!n.cn(t.clientId)})},t.prototype.fn=function(){var t=this;return this.runTransaction("getActiveClients","readonly",function(e){return pi(e).Nt().next(function(e){return t.rn(e,18e5).map(function(t){return t.clientId})})})},Object.defineProperty(t.prototype,"started",{get:function(){return this.xe},enumerable:!1,configurable:!0}),t.prototype.getMutationQueue=function(t){return qr.Qt(t,this.R,this.Ut,this.referenceDelegate)},t.prototype.getTargetCache=function(){return this.qe},t.prototype.getRemoteDocumentCache=function(){return this.Ue},t.prototype.getIndexManager=function(){return this.Ut},t.prototype.getBundleCache=function(){return this.Ke},t.prototype.runTransaction=function(t,e,n){var r=this;f("IndexedDbPersistence","Starting transaction:",t);var i,o="readonly"===e?"readonly":"readwrite";return this.Be.runTransaction(t,o,Jn,function(o){return i=new lr(o,r.Ne?r.Ne.next():s.o),"readwrite-primary"===e?r.Je(i).next(function(t){return!!t||r.Ye(i)}).next(function(e){if(!e)throw l("Failed to obtain primary lease for action '"+t+"'."),r.isPrimary=!1,r.Se.enqueueRetryable(function(){return r.Me(!1)}),new u(a.FAILED_PRECONDITION,Zn);return n(i)}).next(function(t){return r.Ze(i).next(function(){return t})}):r.dn(i).next(function(){return n(i)})}).then(function(t){return i.raiseOnCommittedEvent(),t})},t.prototype.dn=function(t){var e=this;return di(t).get(Mn.key).next(function(t){if(null!==t&&e.sn(t.leaseTimestampMs,5e3)&&!e.cn(t.ownerId)&&!e.tn(t)&&!(e.Ce||e.allowTabSynchronization&&t.allowTabSynchronization))throw new u(a.FAILED_PRECONDITION,fi)})},t.prototype.Ze=function(t){var e=new Mn(this.clientId,this.allowTabSynchronization,Date.now());return di(t).put(Mn.key,e)},t.yt=function(){return ir.yt()},t.prototype.Xe=function(t){var e=this,n=di(t);return n.get(Mn.key).next(function(t){return e.tn(t)?(f("IndexedDbPersistence","Releasing primary lease."),n.delete(Mn.key)):nr.resolve()})},t.prototype.sn=function(t,e){var n=Date.now();return!(t<n-e||t>n&&(l("Detected an update time that is in the future: "+t+" > "+n),1))},t.prototype.We=function(){var t=this;null!==this.document&&"function"==typeof this.document.addEventListener&&(this.Fe=function(){t.Se.enqueueAndForget(function(){return t.inForeground="visible"===t.document.visibilityState,t.je()})},this.document.addEventListener("visibilitychange",this.Fe),this.inForeground="visible"===this.document.visibilityState)},t.prototype.an=function(){this.Fe&&(this.document.removeEventListener("visibilitychange",this.Fe),this.Fe=null)},t.prototype.Ge=function(){var t,e=this;"function"==typeof(null===(t=this.window)||void 0===t?void 0:t.addEventListener)&&(this.ke=function(){e.un(),(0,n.isSafari)()&&navigator.appVersion.match("Version/14")&&e.Se.enterRestrictedMode(!0),e.Se.enqueueAndForget(function(){return e.shutdown()})},this.window.addEventListener("pagehide",this.ke))},t.prototype.hn=function(){this.ke&&(this.window.removeEventListener("pagehide",this.ke),this.ke=null)},t.prototype.cn=function(t){var e;try{var n=null!==(null===(e=this.Qe)||void 0===e?void 0:e.getItem(this.on(t)));return f("IndexedDbPersistence","Client '"+t+"' "+(n?"is":"is not")+" zombied in LocalStorage"),n}catch(t){return l("IndexedDbPersistence","Failed to get zombied client id.",t),!1}},t.prototype.un=function(){if(this.Qe)try{this.Qe.setItem(this.on(this.clientId),String(Date.now()))}catch(t){l("Failed to set zombie client id.",t)}},t.prototype.ln=function(){if(this.Qe)try{this.Qe.removeItem(this.on(this.clientId))}catch(t){}},t.prototype.on=function(t){return"firestore_zombie_"+this.persistenceKey+"_"+t},t}();function di(t){return dr(t,Mn.store)}function pi(t){return dr(t,Yn.store)}function yi(t,e){var n=t.projectId;return t.isDefaultDatabase||(n+="."+t.database),"firestore/"+e+"/"+n+"/"}var vi=function(t,e){this.progress=t,this.wn=e},mi=function(){function t(t,e,n){this.Ue=t,this._n=e,this.Ut=n}return t.prototype.mn=function(t,e){var n=this;return this._n.getAllMutationBatchesAffectingDocumentKey(t,e).next(function(r){return n.yn(t,e,r)})},t.prototype.yn=function(t,e,n){return this.Ue.getEntry(t,e).next(function(t){for(var e=0,r=n;e<r.length;e++)r[e].applyToLocalView(t);return t})},t.prototype.gn=function(t,e){t.forEach(function(t,n){for(var r=0,i=e;r<i.length;r++)i[r].applyToLocalView(n)})},t.prototype.pn=function(t,e){var n=this;return this.Ue.getEntries(t,e).next(function(e){return n.En(t,e).next(function(){return e})})},t.prototype.En=function(t,e){var n=this;return this._n.getAllMutationBatchesAffectingDocumentKeys(t,e).next(function(t){return n.gn(e,t)})},t.prototype.getDocumentsMatchingQuery=function(t,e,n){return function(t){return G.isDocumentKey(t.path)&&null===t.collectionGroup&&0===t.filters.length}(e)?this.Tn(t,e.path):Pt(e)?this.In(t,e,n):this.An(t,e,n)},t.prototype.Tn=function(t,e){return this.mn(t,new G(e)).next(function(t){var e=Fe();return t.isFoundDocument()&&(e=e.insert(t.key,t)),e})},t.prototype.In=function(t,e,n){var r=this,i=e.collectionGroup,o=Fe();return this.Ut.getCollectionParents(t,i).next(function(s){return nr.forEach(s,function(s){var a=function(t,e){return new At(e,null,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,t.startAt,t.endAt)}(e,s.child(i));return r.An(t,a,n).next(function(t){t.forEach(function(t,e){o=o.insert(t,e)})})}).next(function(){return o})})},t.prototype.An=function(t,e,n){var r,i,o=this;return this.Ue.getDocumentsMatchingQuery(t,e,n).next(function(n){return r=n,o._n.getAllMutationBatchesAffectingQuery(t,e)}).next(function(e){return i=e,o.Rn(t,i,r).next(function(t){r=t;for(var e=0,n=i;e<n.length;e++)for(var o=n[e],s=0,a=o.mutations;s<a.length;s++){var u=a[s],c=u.key,h=r.get(c);null==h&&(h=at.newInvalidDocument(c),r=r.insert(c,h)),le(u,h,o.localWriteTime),h.isFoundDocument()||(r=r.remove(c))}})}).next(function(){return r.forEach(function(t,n){jt(e,n)||(r=r.remove(t))}),r})},t.prototype.Rn=function(t,e,n){for(var r=Ue(),i=0,o=e;i<o.length;i++)for(var s=0,a=o[i].mutations;s<a.length;s++){var u=a[s];u instanceof me&&null===n.get(u.key)&&(r=r.add(u.key))}var c=n;return this.Ue.getEntries(t,r).next(function(t){return t.forEach(function(t,e){e.isFoundDocument()&&(c=c.insert(t,e))}),c})},t}(),gi=function(){function t(t,e,n,r){this.targetId=t,this.fromCache=e,this.bn=n,this.vn=r}return t.Pn=function(e,n){for(var r=Ue(),i=Ue(),o=0,s=n.docChanges;o<s.length;o++){var a=s[o];switch(a.type){case 0:r=r.add(a.doc.key);break;case 1:i=i.add(a.doc.key)}}return new t(e,n.fromCache,r,i)},t}(),_i=function(){function t(){}return t.prototype.Vn=function(t){this.Sn=t},t.prototype.getDocumentsMatchingQuery=function(t,e,n,i){var o=this;return function(t){return 0===t.filters.length&&null===t.limit&&null==t.startAt&&null==t.endAt&&(0===t.explicitOrderBy.length||1===t.explicitOrderBy.length&&t.explicitOrderBy[0].field.isKeyField())}(e)||n.isEqual(T.min())?this.Dn(t,e):this.Sn.pn(t,i).next(function(s){var a=o.Cn(e,s);return(Ct(e)||Rt(e))&&o.Nn(e.limitType,a,i,n)?o.Dn(t,e):(h()<=r.LogLevel.DEBUG&&f("QueryEngine","Re-using previous result from %s to execute query: %s",n.toString(),Bt(e)),o.Sn.getDocumentsMatchingQuery(t,e,n).next(function(t){return a.forEach(function(e){t=t.insert(e.key,e)}),t}))})},t.prototype.Cn=function(t,e){var n=new Ce(Kt(t));return e.forEach(function(e,r){jt(t,r)&&(n=n.add(r))}),n},t.prototype.Nn=function(t,e,n,r){if(n.size!==e.size)return!0;var i="F"===t?e.last():e.first();return!!i&&(i.hasPendingWrites||i.version.compareTo(r)>0)},t.prototype.Dn=function(t,e){return h()<=r.LogLevel.DEBUG&&f("QueryEngine","Using full collection scan to execute query:",Bt(e)),this.Sn.getDocumentsMatchingQuery(t,e,T.min())},t}(),wi=function(){function t(t,e,n,r){this.persistence=t,this.xn=e,this.R=r,this.kn=new Ae(w),this.Fn=new ni(function(t){return ht(t)},ft),this.$n=T.min(),this._n=t.getMutationQueue(n),this.On=t.getRemoteDocumentCache(),this.qe=t.getTargetCache(),this.Mn=new mi(this.On,this._n,this.persistence.getIndexManager()),this.Ke=t.getBundleCache(),this.xn.Vn(this.Mn)}return t.prototype.collectGarbage=function(t){var e=this;return this.persistence.runTransaction("Collect garbage","readwrite-primary",function(n){return t.collect(n,e.kn)})},t}();function bi(t,e,n,r){return new wi(t,e,n,r)}function Ii(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o,s;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return r=m(t),i=r._n,o=r.Mn,[4,r.persistence.runTransaction("Handle user change","readonly",function(t){var e;return r._n.getAllMutationBatches(t).next(function(s){return e=s,i=r.persistence.getMutationQueue(n),o=new mi(r.On,i,r.persistence.getIndexManager()),i.getAllMutationBatches(t)}).next(function(n){for(var r=[],i=[],s=Ue(),a=0,u=e;a<u.length;a++){var c=u[a];r.push(c.batchId);for(var h=0,f=c.mutations;h<f.length;h++){var l=f[h];s=s.add(l.key)}}for(var d=0,p=n;d<p.length;d++){var y=p[d];i.push(y.batchId);for(var v=0,m=y.mutations;v<m.length;v++){var g=m[v];s=s.add(g.key)}}return o.pn(t,s).next(function(t){return{Ln:t,removedBatchIds:r,addedBatchIds:i}})})})];case 1:return s=e.sent(),[2,(r._n=i,r.Mn=o,r.xn.Vn(r.Mn),s)]}})})}function Ei(t,e){var n=m(t);return n.persistence.runTransaction("Acknowledge batch","readwrite-primary",function(t){var r=e.batch.keys(),i=n.On.newChangeBuffer({trackRemovals:!0});return function(t,e,n,r){var i=n.batch,o=i.keys(),s=nr.resolve();return o.forEach(function(t){s=s.next(function(){return r.getEntry(e,t)}).next(function(e){var o=n.docVersions.get(t);v(null!==o),e.version.compareTo(o)<0&&(i.applyToRemoteDocument(e,n),e.isValidDocument()&&r.addEntry(e,n.commitVersion))})}),s.next(function(){return t._n.removeMutationBatch(e,i)})}(n,t,e,i).next(function(){return i.apply(t)}).next(function(){return n._n.performConsistencyCheck(t)}).next(function(){return n.Mn.pn(t,r)})})}function Ti(t){var e=m(t);return e.persistence.runTransaction("Get last remote snapshot version","readonly",function(t){return e.qe.getLastRemoteSnapshotVersion(t)})}function Si(t,e){var n=m(t),r=e.snapshotVersion,i=n.kn;return n.persistence.runTransaction("Apply remote event","readwrite-primary",function(t){var o=n.On.newChangeBuffer({trackRemovals:!0});i=n.kn;var s=[];e.targetChanges.forEach(function(e,o){var a=i.get(o);if(a){s.push(n.qe.removeMatchingKeys(t,e.removedDocuments,o).next(function(){return n.qe.addMatchingKeys(t,e.addedDocuments,o)}));var u=e.resumeToken;if(u.approximateByteSize()>0){var c=a.withResumeToken(u,r).withSequenceNumber(t.currentSequenceNumber);i=i.insert(o,c),function(t,e,n){return v(e.resumeToken.approximateByteSize()>0),0===t.resumeToken.approximateByteSize()||e.snapshotVersion.toMicroseconds()-t.snapshotVersion.toMicroseconds()>=3e8||n.addedDocuments.size+n.modifiedDocuments.size+n.removedDocuments.size>0}(a,c,e)&&s.push(n.qe.updateTargetData(t,c))}}});var a=Oe();if(e.documentUpdates.forEach(function(r,i){e.resolvedLimboDocuments.has(r)&&s.push(n.persistence.referenceDelegate.updateLimboDocument(t,r))}),s.push(Ni(t,o,e.documentUpdates,r,void 0).next(function(t){a=t})),!r.isEqual(T.min())){var u=n.qe.getLastRemoteSnapshotVersion(t).next(function(e){return n.qe.setTargetsMetadata(t,t.currentSequenceNumber,r)});s.push(u)}return nr.waitFor(s).next(function(){return o.apply(t)}).next(function(){return n.Mn.En(t,a)}).next(function(){return a})}).then(function(t){return n.kn=i,t})}function Ni(t,e,n,r,i){var o=Ue();return n.forEach(function(t){return o=o.add(t)}),e.getEntries(t,o).next(function(t){var o=Oe();return n.forEach(function(n,s){var a=t.get(n),u=(null==i?void 0:i.get(n))||r;s.isNoDocument()&&s.version.isEqual(T.min())?(e.removeEntry(n,u),o=o.insert(n,s)):!a.isValidDocument()||s.version.compareTo(a.version)>0||0===s.version.compareTo(a.version)&&a.hasPendingWrites?(e.addEntry(s,u),o=o.insert(n,s)):f("LocalStore","Ignoring outdated watch update for ",n,". Current version:",a.version," Watch version:",s.version)}),o})}function Di(t,e){var n=m(t);return n.persistence.runTransaction("Get next mutation batch","readonly",function(t){return void 0===e&&(e=-1),n._n.getNextMutationBatchAfterBatchId(t,e)})}function Ai(t,e){var n=m(t);return n.persistence.runTransaction("Allocate target","readwrite",function(t){var r;return n.qe.getTargetData(t,e).next(function(i){return i?(r=i,nr.resolve(r)):n.qe.allocateTargetId(t).next(function(i){return r=new vr(e,i,0,t.currentSequenceNumber),n.qe.addTargetData(t,r).next(function(){return r})})})}).then(function(t){var r=n.kn.get(t.targetId);return(null===r||t.snapshotVersion.compareTo(r.snapshotVersion)>0)&&(n.kn=n.kn.insert(t.targetId,t),n.Fn.set(e,t.targetId)),t})}function xi(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o,s,a;return(0,e.__generator)(this,function(e){switch(e.label){case 0:i=m(t),o=i.kn.get(n),s=r?"readwrite":"readwrite-primary",e.label=1;case 1:return e.trys.push([1,4,,5]),r?[3,3]:[4,i.persistence.runTransaction("Release target",s,function(t){return i.persistence.referenceDelegate.removeTarget(t,o)})];case 2:e.sent(),e.label=3;case 3:return[3,5];case 4:if(!ar(a=e.sent()))throw a;return f("LocalStore","Failed to update sequence numbers for target "+n+": "+a),[3,5];case 5:return i.kn=i.kn.remove(n),i.Fn.delete(o.target),[2]}})})}function ki(t,e,n){var r=m(t),i=T.min(),o=Ue();return r.persistence.runTransaction("Execute query","readonly",function(t){return function(t,e,n){var r=m(t),i=r.Fn.get(n);return void 0!==i?nr.resolve(r.kn.get(i)):r.qe.getTargetData(e,n)}(r,t,Mt(e)).next(function(e){if(e)return i=e.lastLimboFreeSnapshotVersion,r.qe.getMatchingKeysForTargetId(t,e.targetId).next(function(t){o=t})}).next(function(){return r.xn.getDocumentsMatchingQuery(t,e,n?i:T.min(),n?o:Ue())}).next(function(t){return{documents:t,Bn:o}})})}function Ci(t,e){var n=m(t),r=m(n.qe),i=n.kn.get(e);return i?Promise.resolve(i.target):n.persistence.runTransaction("Get target data","readonly",function(t){return r.lt(t,e).next(function(t){return t?t.target:null})})}function Ri(t){var e=m(t);return e.persistence.runTransaction("Get new document changes","readonly",function(t){return function(t,e,n){var r=m(t),i=Oe(),o=wr(n),s=ai(e),a=IDBKeyRange.lowerBound(o,!0);return s.$t({index:Kn.readTimeIndex,range:a},function(t,e){var n=gr(r.R,e);i=i.insert(n.key,n),o=e.readTime}).next(function(){return{wn:i,readTime:br(o)}})}(e.On,t,e.$n)}).then(function(t){var n=t.wn,r=t.readTime;return e.$n=r,n})}function Li(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){return[2,(n=m(t)).persistence.runTransaction("Synchronize last document change read time","readonly",function(t){return function(t){var e=ai(t),n=T.min();return e.$t({index:Kn.readTimeIndex,reverse:!0},function(t,e,r){e.readTime&&(n=br(e.readTime)),r.done()}).next(function(){return n})}(t)}).then(function(t){n.$n=t})]})})}function Oi(t,n,r,i){return(0,e.__awaiter)(this,void 0,void 0,function(){var o,s,a,u,c,h,f,l,d,p;return(0,e.__generator)(this,function(e){switch(e.label){case 0:for(o=m(t),s=Ue(),a=Oe(),u=Ve(),c=0,h=r;c<h.length;c++)f=h[c],l=n.qn(f.metadata.name),f.document&&(s=s.add(l)),a=a.insert(l,n.Un(f)),u=u.insert(l,n.Kn(f.metadata.readTime));return d=o.On.newChangeBuffer({trackRemovals:!0}),[4,Ai(o,function(t){return Mt(kt(x.fromString("__bundle__/docs/"+t)))}(i))];case 1:return p=e.sent(),[2,o.persistence.runTransaction("Apply bundle documents","readwrite",function(t){return Ni(t,d,a,T.min(),u).next(function(e){return d.apply(t),e}).next(function(e){return o.qe.removeMatchingKeysForTargetId(t,p.targetId).next(function(){return o.qe.addMatchingKeys(t,s,p.targetId)}).next(function(){return o.Mn.En(t,e)}).next(function(){return e})})})]}})})}function Pi(t,n,r){return void 0===r&&(r=Ue()),(0,e.__awaiter)(this,void 0,void 0,function(){var i,o;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,Ai(t,Mt(Dr(n.bundledQuery)))];case 1:return i=e.sent(),[2,(o=m(t)).persistence.runTransaction("Save named query","readwrite",function(t){var e=on(n.readTime);if(i.snapshotVersion.compareTo(e)>=0)return o.Ke.saveNamedQuery(t,n);var s=i.withResumeToken(L.EMPTY_BYTE_STRING,e);return o.kn=o.kn.insert(s.targetId,s),o.qe.updateTargetData(t,s).next(function(){return o.qe.removeMatchingKeysForTargetId(t,i.targetId)}).next(function(){return o.qe.addMatchingKeys(t,r,i.targetId)}).next(function(){return o.Ke.saveNamedQuery(t,n)})})]}})})}var Fi=function(){function t(t){this.R=t,this.Qn=new Map,this.jn=new Map}return t.prototype.getBundleMetadata=function(t,e){return nr.resolve(this.Qn.get(e))},t.prototype.saveBundleMetadata=function(t,e){var n;return this.Qn.set(e.id,{id:(n=e).id,version:n.version,createTime:on(n.createTime)}),nr.resolve()},t.prototype.getNamedQuery=function(t,e){return nr.resolve(this.jn.get(e))},t.prototype.saveNamedQuery=function(t,e){return this.jn.set(e.name,function(t){return{name:t.name,query:Dr(t.bundledQuery),readTime:on(t.readTime)}}(e)),nr.resolve()},t}(),Mi=function(){function t(){this.Wn=new Ce(Vi.Gn),this.zn=new Ce(Vi.Hn)}return t.prototype.isEmpty=function(){return this.Wn.isEmpty()},t.prototype.addReference=function(t,e){var n=new Vi(t,e);this.Wn=this.Wn.add(n),this.zn=this.zn.add(n)},t.prototype.Jn=function(t,e){var n=this;t.forEach(function(t){return n.addReference(t,e)})},t.prototype.removeReference=function(t,e){this.Yn(new Vi(t,e))},t.prototype.Xn=function(t,e){var n=this;t.forEach(function(t){return n.removeReference(t,e)})},t.prototype.Zn=function(t){var e=this,n=new G(new x([])),r=new Vi(n,t),i=new Vi(n,t+1),o=[];return this.zn.forEachInRange([r,i],function(t){e.Yn(t),o.push(t.key)}),o},t.prototype.ts=function(){var t=this;this.Wn.forEach(function(e){return t.Yn(e)})},t.prototype.Yn=function(t){this.Wn=this.Wn.delete(t),this.zn=this.zn.delete(t)},t.prototype.es=function(t){var e=new G(new x([])),n=new Vi(e,t),r=new Vi(e,t+1),i=Ue();return this.zn.forEachInRange([n,r],function(t){i=i.add(t.key)}),i},t.prototype.containsKey=function(t){var e=new Vi(t,0),n=this.Wn.firstAfterOrEqual(e);return null!==n&&t.isEqual(n.key)},t}(),Vi=function(){function t(t,e){this.key=t,this.ns=e}return t.Gn=function(t,e){return G.comparator(t.key,e.key)||w(t.ns,e.ns)},t.Hn=function(t,e){return w(t.ns,e.ns)||G.comparator(t.key,e.key)},t}(),qi=function(){function t(t,e){this.Ut=t,this.referenceDelegate=e,this._n=[],this.ss=1,this.rs=new Ce(Vi.Gn)}return t.prototype.checkEmpty=function(t){return nr.resolve(0===this._n.length)},t.prototype.addMutationBatch=function(t,e,n,r){var i=this.ss;this.ss++,this._n.length>0&&this._n[this._n.length-1];var o=new pr(i,e,n,r);this._n.push(o);for(var s=0,a=r;s<a.length;s++){var u=a[s];this.rs=this.rs.add(new Vi(u.key,i)),this.Ut.addToCollectionParentIndex(t,u.key.path.popLast())}return nr.resolve(o)},t.prototype.lookupMutationBatch=function(t,e){return nr.resolve(this.os(e))},t.prototype.getNextMutationBatchAfterBatchId=function(t,e){var n=e+1,r=this.cs(n),i=r<0?0:r;return nr.resolve(this._n.length>i?this._n[i]:null)},t.prototype.getHighestUnacknowledgedBatchId=function(){return nr.resolve(0===this._n.length?-1:this.ss-1)},t.prototype.getAllMutationBatches=function(t){return nr.resolve(this._n.slice())},t.prototype.getAllMutationBatchesAffectingDocumentKey=function(t,e){var n=this,r=new Vi(e,0),i=new Vi(e,Number.POSITIVE_INFINITY),o=[];return this.rs.forEachInRange([r,i],function(t){var e=n.os(t.ns);o.push(e)}),nr.resolve(o)},t.prototype.getAllMutationBatchesAffectingDocumentKeys=function(t,e){var n=this,r=new Ce(w);return e.forEach(function(t){var e=new Vi(t,0),i=new Vi(t,Number.POSITIVE_INFINITY);n.rs.forEachInRange([e,i],function(t){r=r.add(t.ns)})}),nr.resolve(this.us(r))},t.prototype.getAllMutationBatchesAffectingQuery=function(t,e){var n=e.path,r=n.length+1,i=n;G.isDocumentKey(i)||(i=i.child(""));var o=new Vi(new G(i),0),s=new Ce(w);return this.rs.forEachWhile(function(t){var e=t.key.path;return!!n.isPrefixOf(e)&&(e.length===r&&(s=s.add(t.ns)),!0)},o),nr.resolve(this.us(s))},t.prototype.us=function(t){var e=this,n=[];return t.forEach(function(t){var r=e.os(t);null!==r&&n.push(r)}),n},t.prototype.removeMutationBatch=function(t,e){var n=this;v(0===this.hs(e.batchId,"removed")),this._n.shift();var r=this.rs;return nr.forEach(e.mutations,function(i){var o=new Vi(i.key,e.batchId);return r=r.delete(o),n.referenceDelegate.markPotentiallyOrphaned(t,i.key)}).next(function(){n.rs=r})},t.prototype.Gt=function(t){},t.prototype.containsKey=function(t,e){var n=new Vi(e,0),r=this.rs.firstAfterOrEqual(n);return nr.resolve(e.isEqual(r&&r.key))},t.prototype.performConsistencyCheck=function(t){return this._n.length,nr.resolve()},t.prototype.hs=function(t,e){return this.cs(t)},t.prototype.cs=function(t){return 0===this._n.length?0:t-this._n[0].batchId},t.prototype.os=function(t){var e=this.cs(t);return e<0||e>=this._n.length?null:this._n[e]},t}(),Ui=function(){function t(t,e){this.Ut=t,this.ls=e,this.docs=new Ae(G.comparator),this.size=0}return t.prototype.addEntry=function(t,e,n){var r=e.key,i=this.docs.get(r),o=i?i.size:0,s=this.ls(e);return this.docs=this.docs.insert(r,{document:e.clone(),size:s,readTime:n}),this.size+=s-o,this.Ut.addToCollectionParentIndex(t,r.path.popLast())},t.prototype.removeEntry=function(t){var e=this.docs.get(t);e&&(this.docs=this.docs.remove(t),this.size-=e.size)},t.prototype.getEntry=function(t,e){var n=this.docs.get(e);return nr.resolve(n?n.document.clone():at.newInvalidDocument(e))},t.prototype.getEntries=function(t,e){var n=this,r=Oe();return e.forEach(function(t){var e=n.docs.get(t);r=r.insert(t,e?e.document.clone():at.newInvalidDocument(t))}),nr.resolve(r)},t.prototype.getDocumentsMatchingQuery=function(t,e,n){for(var r=Oe(),i=new G(e.path.child("")),o=this.docs.getIteratorFrom(i);o.hasNext();){var s=o.getNext(),a=s.key,u=s.value,c=u.document,h=u.readTime;if(!e.path.isPrefixOf(a.path))break;h.compareTo(n)<=0||jt(e,c)&&(r=r.insert(c.key,c.clone()))}return nr.resolve(r)},t.prototype.fs=function(t,e){return nr.forEach(this.docs,function(t){return e(t)})},t.prototype.newChangeBuffer=function(t){return new Bi(this)},t.prototype.getSize=function(t){return nr.resolve(this.size)},t}(),Bi=function(t){function n(e){var n=this;return(n=t.call(this)||this).Ie=e,n}return(0,e.__extends)(n,t),n.prototype.applyChanges=function(t){var e=this,n=[];return this.changes.forEach(function(r,i){i.document.isValidDocument()?n.push(e.Ie.addEntry(t,i.document,e.getReadTime(r))):e.Ie.removeEntry(r)}),nr.waitFor(n)},n.prototype.getFromCache=function(t,e){return this.Ie.getEntry(t,e)},n.prototype.getAllFromCache=function(t,e){return this.Ie.getEntries(t,e)},n}(ri),ji=function(){function t(t){this.persistence=t,this.ds=new ni(function(t){return ht(t)},ft),this.lastRemoteSnapshotVersion=T.min(),this.highestTargetId=0,this.ws=0,this._s=new Mi,this.targetCount=0,this.ys=Gr.Jt()}return t.prototype.forEachTarget=function(t,e){return this.ds.forEach(function(t,n){return e(n)}),nr.resolve()},t.prototype.getLastRemoteSnapshotVersion=function(t){return nr.resolve(this.lastRemoteSnapshotVersion)},t.prototype.getHighestSequenceNumber=function(t){return nr.resolve(this.ws)},t.prototype.allocateTargetId=function(t){return this.highestTargetId=this.ys.next(),nr.resolve(this.highestTargetId)},t.prototype.setTargetsMetadata=function(t,e,n){return n&&(this.lastRemoteSnapshotVersion=n),e>this.ws&&(this.ws=e),nr.resolve()},t.prototype.te=function(t){this.ds.set(t.target,t);var e=t.targetId;e>this.highestTargetId&&(this.ys=new Gr(e),this.highestTargetId=e),t.sequenceNumber>this.ws&&(this.ws=t.sequenceNumber)},t.prototype.addTargetData=function(t,e){return this.te(e),this.targetCount+=1,nr.resolve()},t.prototype.updateTargetData=function(t,e){return this.te(e),nr.resolve()},t.prototype.removeTargetData=function(t,e){return this.ds.delete(e.target),this._s.Zn(e.targetId),this.targetCount-=1,nr.resolve()},t.prototype.removeTargets=function(t,e,n){var r=this,i=0,o=[];return this.ds.forEach(function(s,a){a.sequenceNumber<=e&&null===n.get(a.targetId)&&(r.ds.delete(s),o.push(r.removeMatchingKeysForTargetId(t,a.targetId)),i++)}),nr.waitFor(o).next(function(){return i})},t.prototype.getTargetCount=function(t){return nr.resolve(this.targetCount)},t.prototype.getTargetData=function(t,e){var n=this.ds.get(e)||null;return nr.resolve(n)},t.prototype.addMatchingKeys=function(t,e,n){return this._s.Jn(e,n),nr.resolve()},t.prototype.removeMatchingKeys=function(t,e,n){this._s.Xn(e,n);var r=this.persistence.referenceDelegate,i=[];return r&&e.forEach(function(e){i.push(r.markPotentiallyOrphaned(t,e))}),nr.waitFor(i)},t.prototype.removeMatchingKeysForTargetId=function(t,e){return this._s.Zn(e),nr.resolve()},t.prototype.getMatchingKeysForTargetId=function(t,e){var n=this._s.es(e);return nr.resolve(n)},t.prototype.containsKey=function(t,e){return nr.resolve(this._s.containsKey(e))},t}(),Ki=function(){function t(t,e){var n=this;this.gs={},this.Ne=new s(0),this.xe=!1,this.xe=!0,this.referenceDelegate=t(this),this.qe=new ji(this),this.Ut=new Cr,this.Ue=function(t,e){return new Ui(t,function(t){return n.referenceDelegate.ps(t)})}(this.Ut),this.R=new mr(e),this.Ke=new Fi(this.R)}return t.prototype.start=function(){return Promise.resolve()},t.prototype.shutdown=function(){return this.xe=!1,Promise.resolve()},Object.defineProperty(t.prototype,"started",{get:function(){return this.xe},enumerable:!1,configurable:!0}),t.prototype.setDatabaseDeletedListener=function(){},t.prototype.setNetworkEnabled=function(){},t.prototype.getIndexManager=function(){return this.Ut},t.prototype.getMutationQueue=function(t){var e=this.gs[t.toKey()];return e||(e=new qi(this.Ut,this.referenceDelegate),this.gs[t.toKey()]=e),e},t.prototype.getTargetCache=function(){return this.qe},t.prototype.getRemoteDocumentCache=function(){return this.Ue},t.prototype.getBundleCache=function(){return this.Ke},t.prototype.runTransaction=function(t,e,n){var r=this;f("MemoryPersistence","Starting transaction:",t);var i=new Gi(this.Ne.next());return this.referenceDelegate.Es(),n(i).next(function(t){return r.referenceDelegate.Ts(i).next(function(){return t})}).toPromise().then(function(t){return i.raiseOnCommittedEvent(),t})},t.prototype.Is=function(t,e){return nr.or(Object.values(this.gs).map(function(n){return function(){return n.containsKey(t,e)}}))},t}(),Gi=function(t){function n(e){var n=this;return(n=t.call(this)||this).currentSequenceNumber=e,n}return(0,e.__extends)(n,t),n}(tr),Qi=function(){function t(t){this.persistence=t,this.As=new Mi,this.Rs=null}return t.bs=function(e){return new t(e)},Object.defineProperty(t.prototype,"vs",{get:function(){if(this.Rs)return this.Rs;throw y()},enumerable:!1,configurable:!0}),t.prototype.addReference=function(t,e,n){return this.As.addReference(n,e),this.vs.delete(n.toString()),nr.resolve()},t.prototype.removeReference=function(t,e,n){return this.As.removeReference(n,e),this.vs.add(n.toString()),nr.resolve()},t.prototype.markPotentiallyOrphaned=function(t,e){return this.vs.add(e.toString()),nr.resolve()},t.prototype.removeTarget=function(t,e){var n=this;this.As.Zn(e.targetId).forEach(function(t){return n.vs.add(t.toString())});var r=this.persistence.getTargetCache();return r.getMatchingKeysForTargetId(t,e.targetId).next(function(t){t.forEach(function(t){return n.vs.add(t.toString())})}).next(function(){return r.removeTargetData(t,e)})},t.prototype.Es=function(){this.Rs=new Set},t.prototype.Ts=function(t){var e=this,n=this.persistence.getRemoteDocumentCache().newChangeBuffer();return nr.forEach(this.vs,function(r){var i=G.fromPath(r);return e.Ps(t,i).next(function(t){t||n.removeEntry(i)})}).next(function(){return e.Rs=null,n.apply(t)})},t.prototype.updateLimboDocument=function(t,e){var n=this;return this.Ps(t,e).next(function(t){t?n.vs.delete(e.toString()):n.vs.add(e.toString())})},t.prototype.ps=function(t){return 0},t.prototype.Ps=function(t,e){var n=this;return nr.or([function(){return nr.resolve(n.As.containsKey(e))},function(){return n.persistence.getTargetCache().containsKey(t,e)},function(){return n.persistence.Is(t,e)}])},t}(),zi=function(){function t(t){this.uid=t}return t.prototype.isAuthenticated=function(){return null!=this.uid},t.prototype.toKey=function(){return this.isAuthenticated()?"uid:"+this.uid:"anonymous-user"},t.prototype.isEqual=function(t){return t.uid===this.uid},t}();function Wi(t,e){return"firestore_clients_"+t+"_"+e}function Hi(t,e,n){var r="firestore_mutations_"+t+"_"+n;return e.isAuthenticated()&&(r+="_"+e.uid),r}function Yi(t,e){return"firestore_targets_"+t+"_"+e}zi.UNAUTHENTICATED=new zi(null),zi.GOOGLE_CREDENTIALS=new zi("google-credentials-uid"),zi.FIRST_PARTY=new zi("first-party-uid"),zi.MOCK_USER=new zi("mock-user");var $i=function(){function t(t,e,n,r){this.user=t,this.batchId=e,this.state=n,this.error=r}return t.Vs=function(e,n,r){var i,s=JSON.parse(r),a="object"==o(s)&&-1!==["pending","acknowledged","rejected"].indexOf(s.state)&&(void 0===s.error||"object"==o(s.error));return a&&s.error&&(a="string"==typeof s.error.message&&"string"==typeof s.error.code)&&(i=new u(s.error.code,s.error.message)),a?new t(e,n,s.state,i):(l("SharedClientState","Failed to parse mutation state for ID '"+n+"': "+r),null)},t.prototype.Ss=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}(),Xi=function(){function t(t,e,n){this.targetId=t,this.state=e,this.error=n}return t.Vs=function(e,n){var r,i=JSON.parse(n),s="object"==o(i)&&-1!==["not-current","current","rejected"].indexOf(i.state)&&(void 0===i.error||"object"==o(i.error));return s&&i.error&&(s="string"==typeof i.error.message&&"string"==typeof i.error.code)&&(r=new u(i.error.code,i.error.message)),s?new t(e,i.state,r):(l("SharedClientState","Failed to parse target state for ID '"+e+"': "+n),null)},t.prototype.Ss=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}(),Ji=function(){function t(t,e){this.clientId=t,this.activeTargetIds=e}return t.Vs=function(e,n){for(var r=JSON.parse(n),i="object"==o(r)&&r.activeTargetIds instanceof Array,s=je(),a=0;i&&a<r.activeTargetIds.length;++a)i=K(r.activeTargetIds[a]),s=s.add(r.activeTargetIds[a]);return i?new t(e,s):(l("SharedClientState","Failed to parse client data for instance '"+e+"': "+n),null)},t}(),Zi=function(){function t(t,e){this.clientId=t,this.onlineState=e}return t.Vs=function(e){var n=JSON.parse(e);return"object"==o(n)&&-1!==["Unknown","Online","Offline"].indexOf(n.onlineState)&&"string"==typeof n.clientId?new t(n.clientId,n.onlineState):(l("SharedClientState","Failed to parse online state: "+e),null)},t}(),to=function(){function t(){this.activeTargetIds=je()}return t.prototype.Ds=function(t){this.activeTargetIds=this.activeTargetIds.add(t)},t.prototype.Cs=function(t){this.activeTargetIds=this.activeTargetIds.delete(t)},t.prototype.Ss=function(){var t={activeTargetIds:this.activeTargetIds.toArray(),updateTimeMs:Date.now()};return JSON.stringify(t)},t}(),eo=function(){function t(t,e,n,r,i){this.window=t,this.Se=e,this.persistenceKey=n,this.Ns=r,this.syncEngine=null,this.onlineStateHandler=null,this.sequenceNumberHandler=null,this.xs=this.ks.bind(this),this.Fs=new Ae(w),this.started=!1,this.$s=[];var o=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");this.storage=this.window.localStorage,this.currentUser=i,this.Os=Wi(this.persistenceKey,this.Ns),this.Ms=function(t){return"firestore_sequence_number_"+t}(this.persistenceKey),this.Fs=this.Fs.insert(this.Ns,new to),this.Ls=new RegExp("^firestore_clients_"+o+"_([^_]*)$"),this.Bs=new RegExp("^firestore_mutations_"+o+"_(\\d+)(?:_(.*))?$"),this.qs=new RegExp("^firestore_targets_"+o+"_(\\d+)$"),this.Us=function(t){return"firestore_online_state_"+t}(this.persistenceKey),this.Ks=function(t){return"firestore_bundle_loaded_"+t}(this.persistenceKey),this.window.addEventListener("storage",this.xs)}return t.yt=function(t){return!(!t||!t.localStorage)},t.prototype.start=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var t,n,r,i,o,s,a,u,c,h,f,l=this;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,this.syncEngine.fn()];case 1:for(t=e.sent(),n=0,r=t;n<r.length;n++)(i=r[n])!==this.Ns&&(o=this.getItem(Wi(this.persistenceKey,i)))&&(s=Ji.Vs(i,o))&&(this.Fs=this.Fs.insert(s.clientId,s));for(this.Qs(),(a=this.storage.getItem(this.Us))&&(u=this.js(a))&&this.Ws(u),c=0,h=this.$s;c<h.length;c++)f=h[c],this.ks(f);return this.$s=[],this.window.addEventListener("pagehide",function(){return l.shutdown()}),this.started=!0,[2]}})})},t.prototype.writeSequenceNumber=function(t){this.setItem(this.Ms,JSON.stringify(t))},t.prototype.getAllActiveQueryTargets=function(){return this.Gs(this.Fs)},t.prototype.isActiveQueryTarget=function(t){var e=!1;return this.Fs.forEach(function(n,r){r.activeTargetIds.has(t)&&(e=!0)}),e},t.prototype.addPendingMutation=function(t){this.zs(t,"pending")},t.prototype.updateMutationState=function(t,e,n){this.zs(t,e,n),this.Hs(t)},t.prototype.addLocalQueryTarget=function(t){var e="not-current";if(this.isActiveQueryTarget(t)){var n=this.storage.getItem(Yi(this.persistenceKey,t));if(n){var r=Xi.Vs(t,n);r&&(e=r.state)}}return this.Js.Ds(t),this.Qs(),e},t.prototype.removeLocalQueryTarget=function(t){this.Js.Cs(t),this.Qs()},t.prototype.isLocalQueryTarget=function(t){return this.Js.activeTargetIds.has(t)},t.prototype.clearQueryState=function(t){this.removeItem(Yi(this.persistenceKey,t))},t.prototype.updateQueryState=function(t,e,n){this.Ys(t,e,n)},t.prototype.handleUserChange=function(t,e,n){var r=this;e.forEach(function(t){r.Hs(t)}),this.currentUser=t,n.forEach(function(t){r.addPendingMutation(t)})},t.prototype.setOnlineState=function(t){this.Xs(t)},t.prototype.notifyBundleLoaded=function(){this.Zs()},t.prototype.shutdown=function(){this.started&&(this.window.removeEventListener("storage",this.xs),this.removeItem(this.Os),this.started=!1)},t.prototype.getItem=function(t){var e=this.storage.getItem(t);return f("SharedClientState","READ",t,e),e},t.prototype.setItem=function(t,e){f("SharedClientState","SET",t,e),this.storage.setItem(t,e)},t.prototype.removeItem=function(t){f("SharedClientState","REMOVE",t),this.storage.removeItem(t)},t.prototype.ks=function(t){var n=this,r=t;if(r.storageArea===this.storage){if(f("SharedClientState","EVENT",r.key,r.newValue),r.key===this.Os)return void l("Received WebStorage notification for local change. Another client might have garbage-collected our state");this.Se.enqueueRetryable(function(){return(0,e.__awaiter)(n,void 0,void 0,function(){var t,n,i,o,a,u;return(0,e.__generator)(this,function(e){if(this.started){if(null!==r.key)if(this.Ls.test(r.key)){if(null==r.newValue)return t=this.ti(r.key),[2,this.ei(t,null)];if(n=this.ni(r.key,r.newValue))return[2,this.ei(n.clientId,n)]}else if(this.Bs.test(r.key)){if(null!==r.newValue&&(i=this.si(r.key,r.newValue)))return[2,this.ii(i)]}else if(this.qs.test(r.key)){if(null!==r.newValue&&(o=this.ri(r.key,r.newValue)))return[2,this.oi(o)]}else if(r.key===this.Us){if(null!==r.newValue&&(a=this.js(r.newValue)))return[2,this.Ws(a)]}else if(r.key===this.Ms)(u=function(t){var e=s.o;if(null!=t)try{var n=JSON.parse(t);v("number"==typeof n),e=n}catch(t){l("SharedClientState","Failed to read sequence number from WebStorage",t)}return e}(r.newValue))!==s.o&&this.sequenceNumberHandler(u);else if(r.key===this.Ks)return[2,this.syncEngine.ci()]}else this.$s.push(r);return[2]})})})}},Object.defineProperty(t.prototype,"Js",{get:function(){return this.Fs.get(this.Ns)},enumerable:!1,configurable:!0}),t.prototype.Qs=function(){this.setItem(this.Os,this.Js.Ss())},t.prototype.zs=function(t,e,n){var r=new $i(this.currentUser,t,e,n),i=Hi(this.persistenceKey,this.currentUser,t);this.setItem(i,r.Ss())},t.prototype.Hs=function(t){var e=Hi(this.persistenceKey,this.currentUser,t);this.removeItem(e)},t.prototype.Xs=function(t){var e={clientId:this.Ns,onlineState:t};this.storage.setItem(this.Us,JSON.stringify(e))},t.prototype.Ys=function(t,e,n){var r=Yi(this.persistenceKey,t),i=new Xi(t,e,n);this.setItem(r,i.Ss())},t.prototype.Zs=function(){this.setItem(this.Ks,"value-not-used")},t.prototype.ti=function(t){var e=this.Ls.exec(t);return e?e[1]:null},t.prototype.ni=function(t,e){var n=this.ti(t);return Ji.Vs(n,e)},t.prototype.si=function(t,e){var n=this.Bs.exec(t),r=Number(n[1]),i=void 0!==n[2]?n[2]:null;return $i.Vs(new zi(i),r,e)},t.prototype.ri=function(t,e){var n=this.qs.exec(t),r=Number(n[1]);return Xi.Vs(r,e)},t.prototype.js=function(t){return Zi.Vs(t)},t.prototype.ii=function(t){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(e){return t.user.uid===this.currentUser.uid?[2,this.syncEngine.ui(t.batchId,t.state,t.error)]:(f("SharedClientState","Ignoring mutation for non-active user "+t.user.uid),[2])})})},t.prototype.oi=function(t){return this.syncEngine.ai(t.targetId,t.state,t.error)},t.prototype.ei=function(t,e){var n=this,r=e?this.Fs.insert(t,e):this.Fs.remove(t),i=this.Gs(this.Fs),o=this.Gs(r),s=[],a=[];return o.forEach(function(t){i.has(t)||s.push(t)}),i.forEach(function(t){o.has(t)||a.push(t)}),this.syncEngine.hi(s,a).then(function(){n.Fs=r})},t.prototype.Ws=function(t){this.Fs.get(t.clientId)&&this.onlineStateHandler(t.onlineState)},t.prototype.Gs=function(t){var e=je();return t.forEach(function(t,n){e=e.unionWith(n.activeTargetIds)}),e},t}(),no=function(){function t(){this.li=new to,this.fi={},this.onlineStateHandler=null,this.sequenceNumberHandler=null}return t.prototype.addPendingMutation=function(t){},t.prototype.updateMutationState=function(t,e,n){},t.prototype.addLocalQueryTarget=function(t){return this.li.Ds(t),this.fi[t]||"not-current"},t.prototype.updateQueryState=function(t,e,n){this.fi[t]=e},t.prototype.removeLocalQueryTarget=function(t){this.li.Cs(t)},t.prototype.isLocalQueryTarget=function(t){return this.li.activeTargetIds.has(t)},t.prototype.clearQueryState=function(t){delete this.fi[t]},t.prototype.getAllActiveQueryTargets=function(){return this.li.activeTargetIds},t.prototype.isActiveQueryTarget=function(t){return this.li.activeTargetIds.has(t)},t.prototype.start=function(){return this.li=new to,Promise.resolve()},t.prototype.handleUserChange=function(t,e,n){},t.prototype.setOnlineState=function(t){},t.prototype.shutdown=function(){},t.prototype.writeSequenceNumber=function(t){},t.prototype.notifyBundleLoaded=function(){},t}(),ro=function(){function t(){}return t.prototype.di=function(t){},t.prototype.shutdown=function(){},t}(),io=function(){function t(){var t=this;this.wi=function(){return t._i()},this.mi=function(){return t.yi()},this.gi=[],this.pi()}return t.prototype.di=function(t){this.gi.push(t)},t.prototype.shutdown=function(){window.removeEventListener("online",this.wi),window.removeEventListener("offline",this.mi)},t.prototype.pi=function(){window.addEventListener("online",this.wi),window.addEventListener("offline",this.mi)},t.prototype._i=function(){f("ConnectivityMonitor","Network connectivity changed: AVAILABLE");for(var t=0,e=this.gi;t<e.length;t++)(0,e[t])(0)},t.prototype.yi=function(){f("ConnectivityMonitor","Network connectivity changed: UNAVAILABLE");for(var t=0,e=this.gi;t<e.length;t++)(0,e[t])(1)},t.yt=function(){return"undefined"!=typeof window&&void 0!==window.addEventListener&&void 0!==window.removeEventListener},t}(),oo={BatchGetDocuments:"batchGet",Commit:"commit",RunQuery:"runQuery"},so=function(){function t(t){this.Ei=t.Ei,this.Ti=t.Ti}return t.prototype.Ii=function(t){this.Ai=t},t.prototype.Ri=function(t){this.bi=t},t.prototype.onMessage=function(t){this.vi=t},t.prototype.close=function(){this.Ti()},t.prototype.send=function(t){this.Ei(t)},t.prototype.Pi=function(){this.Ai()},t.prototype.Vi=function(t){this.bi(t)},t.prototype.Si=function(t){this.vi(t)},t}(),ao=function(t){function r(e){var n=this;return(n=t.call(this,e)||this).forceLongPolling=e.forceLongPolling,n.autoDetectLongPolling=e.autoDetectLongPolling,n.useFetchStreams=e.useFetchStreams,n}return(0,e.__extends)(r,t),r.prototype.Fi=function(t,e,n,r){return new Promise(function(o,s){var c=new i.XhrIo;c.listenOnce(i.EventType.COMPLETE,function(){try{switch(c.getLastErrorCode()){case i.ErrorCode.NO_ERROR:var e=c.getResponseJson();f("Connection","XHR received:",JSON.stringify(e)),o(e);break;case i.ErrorCode.TIMEOUT:f("Connection",'RPC "'+t+'" timed out'),s(new u(a.DEADLINE_EXCEEDED,"Request time out"));break;case i.ErrorCode.HTTP_ERROR:var n=c.getStatus();if(f("Connection",'RPC "'+t+'" failed with status:',n,"response text:",c.getResponseText()),n>0){var r=c.getResponseJson().error;if(r&&r.status&&r.message){var h=function(t){var e=r.status.toLowerCase().replace(/_/g,"-");return Object.values(a).indexOf(e)>=0?e:a.UNKNOWN}();s(new u(h,r.message))}else s(new u(a.UNKNOWN,"Server responded with status "+c.getStatus()))}else s(new u(a.UNAVAILABLE,"Connection failed."));break;default:y()}}finally{f("Connection",'RPC "'+t+'" completed.')}});var h=JSON.stringify(r);c.send(e,"POST",h,n,15)})},r.prototype.Oi=function(t,e){var r=[this.Di,"/","google.firestore.v1.Firestore","/",t,"/channel"],o=(0,i.createWebChannelTransport)(),s=(0,i.getStatEventTarget)(),c={httpSessionIdParam:"gsessionid",initMessageHeaders:{},messageUrlParams:{database:"projects/"+this.databaseId.projectId+"/databases/"+this.databaseId.database},sendRawJson:!0,supportsCrossDomainXhr:!0,internalChannelParams:{forwardChannelRequestTimeoutMs:6e5},forceLongPolling:this.forceLongPolling,detectBufferingProxy:this.autoDetectLongPolling};this.useFetchStreams&&(c.xmlHttpFactory=new i.FetchXmlHttpFactory({})),this.ki(c.initMessageHeaders,e),(0,n.isMobileCordova)()||(0,n.isReactNative)()||(0,n.isElectron)()||(0,n.isIE)()||(0,n.isUWP)()||(0,n.isBrowserExtension)()||(c.httpHeadersOverwriteParam="$httpHeaders");var h=r.join("");f("Connection","Creating WebChannel: "+h,c);var l=o.createWebChannel(h,c),p=!1,y=!1,m=new so({Ei:function(t){y?f("Connection","Not sending because WebChannel is closed:",t):(p||(f("Connection","Opening WebChannel transport."),l.open(),p=!0),f("Connection","WebChannel sending:",t),l.send(t))},Ti:function(){return l.close()}}),g=function(t,e,n){t.listen(e,function(t){try{n(t)}catch(t){setTimeout(function(){throw t},0)}})};return g(l,i.WebChannel.EventType.OPEN,function(){y||f("Connection","WebChannel transport opened.")}),g(l,i.WebChannel.EventType.CLOSE,function(){y||(y=!0,f("Connection","WebChannel transport closed"),m.Vi())}),g(l,i.WebChannel.EventType.ERROR,function(t){y||(y=!0,d("Connection","WebChannel transport errored:",t),m.Vi(new u(a.UNAVAILABLE,"The operation could not be completed")))}),g(l,i.WebChannel.EventType.MESSAGE,function(t){var e;if(!y){var n=t.data[0];v(!!n);var r=n,i=r.error||(null===(e=r[0])||void 0===e?void 0:e.error);if(i){f("Connection","WebChannel received error:",i);var o=i.status,s=function(t){var e=be[o];if(void 0!==e)return De(e)}(),c=i.message;void 0===s&&(s=a.INTERNAL,c="Unknown error status: "+o+" with message "+i.message),y=!0,m.Vi(new u(s,c)),l.close()}else f("Connection","WebChannel received:",n),m.Si(n)}}),g(s,i.Event.STAT_EVENT,function(t){t.stat===i.Stat.PROXY?f("Connection","Detected buffering proxy"):t.stat===i.Stat.NOPROXY&&f("Connection","Detected no buffering proxy")}),setTimeout(function(){m.Pi()},0),m},r}(function(){function t(t){this.databaseInfo=t,this.databaseId=t.databaseId;var e=t.ssl?"https":"http";this.Di=e+"://"+t.host,this.Ci="projects/"+this.databaseId.projectId+"/databases/"+this.databaseId.database+"/documents"}return t.prototype.Ni=function(t,e,n,r){var i=this.xi(t,e);f("RestConnection","Sending: ",i,n);var o={};return this.ki(o,r),this.Fi(t,i,o,n).then(function(t){return f("RestConnection","Received: ",t),t},function(e){throw d("RestConnection",t+" failed with error: ",e,"url: ",i,"request:",n),e})},t.prototype.$i=function(t,e,n,r){return this.Ni(t,e,n,r)},t.prototype.ki=function(t,e){if(t["X-Goog-Api-Client"]="gl-js/ fire/8.10.1",t["Content-Type"]="text/plain",this.databaseInfo.appId&&(t["X-Firebase-GMPID"]=this.databaseInfo.appId),e)for(var n in e.authHeaders)e.authHeaders.hasOwnProperty(n)&&(t[n]=e.authHeaders[n])},t.prototype.xi=function(t,e){var n=oo[t];return this.Di+"/v1/"+e+":"+n},t}());function uo(){return"undefined"!=typeof window?window:null}function co(){return"undefined"!=typeof document?document:null}function ho(t){return new tn(t,!0)}var fo=function(){function t(t,e,n,r,i){void 0===n&&(n=1e3),void 0===r&&(r=1.5),void 0===i&&(i=6e4),this.Se=t,this.timerId=e,this.Mi=n,this.Li=r,this.Bi=i,this.qi=0,this.Ui=null,this.Ki=Date.now(),this.reset()}return t.prototype.reset=function(){this.qi=0},t.prototype.Qi=function(){this.qi=this.Bi},t.prototype.ji=function(t){var e=this;this.cancel();var n=Math.floor(this.qi+this.Wi()),r=Math.max(0,Date.now()-this.Ki),i=Math.max(0,n-r);i>0&&f("ExponentialBackoff","Backing off for "+i+" ms (base delay: "+this.qi+" ms, delay with jitter: "+n+" ms, last attempt: "+r+" ms ago)"),this.Ui=this.Se.enqueueAfterDelay(this.timerId,i,function(){return e.Ki=Date.now(),t()}),this.qi*=this.Li,this.qi<this.Mi&&(this.qi=this.Mi),this.qi>this.Bi&&(this.qi=this.Bi)},t.prototype.Gi=function(){null!==this.Ui&&(this.Ui.skipDelay(),this.Ui=null)},t.prototype.cancel=function(){null!==this.Ui&&(this.Ui.cancel(),this.Ui=null)},t.prototype.Wi=function(){return(Math.random()-.5)*this.qi},t}(),lo=function(){function t(t,e,n,r,i,o){this.Se=t,this.zi=n,this.Hi=r,this.Ji=i,this.listener=o,this.state=0,this.Yi=0,this.Xi=null,this.stream=null,this.Zi=new fo(t,e)}return t.prototype.tr=function(){return 1===this.state||2===this.state||4===this.state},t.prototype.er=function(){return 2===this.state},t.prototype.start=function(){3!==this.state?this.auth():this.nr()},t.prototype.stop=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(t){switch(t.label){case 0:return this.tr()?[4,this.close(0)]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}})})},t.prototype.sr=function(){this.state=0,this.Zi.reset()},t.prototype.ir=function(){var t=this;this.er()&&null===this.Xi&&(this.Xi=this.Se.enqueueAfterDelay(this.zi,6e4,function(){return t.rr()}))},t.prototype.cr=function(t){this.ur(),this.stream.send(t)},t.prototype.rr=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(t){return this.er()?[2,this.close(0)]:[2]})})},t.prototype.ur=function(){this.Xi&&(this.Xi.cancel(),this.Xi=null)},t.prototype.close=function(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return this.ur(),this.Zi.cancel(),this.Yi++,3!==t?this.Zi.reset():n&&n.code===a.RESOURCE_EXHAUSTED?(l(n.toString()),l("Using maximum backoff delay to prevent overloading the backend."),this.Zi.Qi()):n&&n.code===a.UNAUTHENTICATED&&this.Ji.invalidateToken(),null!==this.stream&&(this.ar(),this.stream.close(),this.stream=null),this.state=t,[4,this.listener.Ri(n)];case 1:return e.sent(),[2]}})})},t.prototype.ar=function(){},t.prototype.auth=function(){var t=this;this.state=1;var e=this.hr(this.Yi),n=this.Yi;this.Ji.getToken().then(function(e){t.Yi===n&&t.lr(e)},function(n){e(function(){var e=new u(a.UNKNOWN,"Fetching auth token failed: "+n.message);return t.dr(e)})})},t.prototype.lr=function(t){var e=this,n=this.hr(this.Yi);this.stream=this.wr(t),this.stream.Ii(function(){n(function(){return e.state=2,e.listener.Ii()})}),this.stream.Ri(function(t){n(function(){return e.dr(t)})}),this.stream.onMessage(function(t){n(function(){return e.onMessage(t)})})},t.prototype.nr=function(){var t=this;this.state=4,this.Zi.ji(function(){return(0,e.__awaiter)(t,void 0,void 0,function(){return(0,e.__generator)(this,function(t){return this.state=0,this.start(),[2]})})})},t.prototype.dr=function(t){return f("PersistentStream","close with error: "+t),this.stream=null,this.close(3,t)},t.prototype.hr=function(t){var e=this;return function(n){e.Se.enqueueAndForget(function(){return e.Yi===t?n():(f("PersistentStream","stream callback skipped by getCloseGuardedDispatcher."),Promise.resolve())})}},t}(),po=function(t){function n(e,n,r,i,o){var s=this;return(s=t.call(this,e,"listen_stream_connection_backoff","listen_stream_idle",n,r,o)||this).R=i,s}return(0,e.__extends)(n,t),n.prototype.wr=function(t){return this.Hi.Oi("Listen",t)},n.prototype.onMessage=function(t){this.Zi.reset();var e=function(t,e){var n;if("targetChange"in e){e.targetChange;var r=function(t){return"NO_CHANGE"===t?0:"ADD"===t?1:"REMOVE"===t?2:"CURRENT"===t?3:"RESET"===t?4:y()}(e.targetChange.targetChangeType||"NO_CHANGE"),i=e.targetChange.targetIds||[],o=function(t,e){return t.I?(v(void 0===e||"string"==typeof e),L.fromBase64String(e||"")):(v(void 0===e||e instanceof Uint8Array),L.fromUint8Array(e||new Uint8Array))}(t,e.targetChange.resumeToken),s=(c=e.targetChange.cause)&&function(t){var e=void 0===t.code?a.UNKNOWN:De(t.code);return new u(e,t.message||"")}(c);n=new We(r,i,o,s||null)}else if("documentChange"in e){e.documentChange,(r=e.documentChange).document,r.document.name,r.document.updateTime,i=cn(t,r.document.name),o=on(r.document.updateTime);var c=new ot({mapValue:{fields:r.document.fields}}),h=(s=at.newFoundDocument(i,o,c),r.targetIds||[]),f=r.removedTargetIds||[];n=new Qe(h,f,s.key,s)}else if("documentDelete"in e)e.documentDelete,(r=e.documentDelete).document,i=cn(t,r.document),o=r.readTime?on(r.readTime):T.min(),c=at.newNoDocument(i,o),s=r.removedTargetIds||[],n=new Qe([],s,c.key,c);else if("documentRemove"in e)e.documentRemove,(r=e.documentRemove).document,i=cn(t,r.document),o=r.removedTargetIds||[],n=new Qe([],o,i,null);else{if(!("filter"in e))return y();e.filter;var l=e.filter;l.targetId,r=l.count||0,i=new Se(r),o=l.targetId,n=new ze(o,i)}return n}(this.R,t),n=function(t){if(!("targetChange"in t))return T.min();var e=t.targetChange;return e.targetIds&&e.targetIds.length?T.min():e.readTime?on(e.readTime):T.min()}(t);return this.listener._r(e,n)},n.prototype.mr=function(t){var e={};e.database=ln(this.R),e.addTarget=function(t,e){var n,r=e.target;return(n=lt(r)?{documents:gn(t,r)}:{query:_n(t,r)}).targetId=e.targetId,e.resumeToken.approximateByteSize()>0?n.resumeToken=nn(t,e.resumeToken):e.snapshotVersion.compareTo(T.min())>0&&(n.readTime=en(t,e.snapshotVersion.toTimestamp())),n}(this.R,t);var n=function(t,e){var n=function(t,e){switch(e){case 0:return null;case 1:return"existence-filter-mismatch";case 2:return"limbo-document";default:return y()}}(0,e.purpose);return null==n?null:{"goog-listen-tags":n}}(this.R,t);n&&(e.labels=n),this.cr(e)},n.prototype.yr=function(t){var e={};e.database=ln(this.R),e.removeTarget=t,this.cr(e)},n}(lo),yo=function(t){function n(e,n,r,i,o){var s=this;return(s=t.call(this,e,"write_stream_connection_backoff","write_stream_idle",n,r,o)||this).R=i,s.gr=!1,s}return(0,e.__extends)(n,t),Object.defineProperty(n.prototype,"pr",{get:function(){return this.gr},enumerable:!1,configurable:!0}),n.prototype.start=function(){this.gr=!1,this.lastStreamToken=void 0,t.prototype.start.call(this)},n.prototype.ar=function(){this.gr&&this.Er([])},n.prototype.wr=function(t){return this.Hi.Oi("Write",t)},n.prototype.onMessage=function(t){if(v(!!t.streamToken),this.lastStreamToken=t.streamToken,this.gr){this.Zi.reset();var e=function(t,e){return t&&t.length>0?(v(void 0!==e),t.map(function(t){return function(t,e){var n=t.updateTime?on(t.updateTime):on(e);return n.isEqual(T.min())&&(n=on(e)),new ae(n,t.transformResults||[])}(t,e)})):[]}(t.writeResults,t.commitTime),n=on(t.commitTime);return this.listener.Tr(n,e)}return v(!t.writeResults||0===t.writeResults.length),this.gr=!0,this.listener.Ir()},n.prototype.Ar=function(){var t={};t.database=ln(this.R),this.cr(t)},n.prototype.Er=function(t){var e=this,n={streamToken:this.lastStreamToken,writes:t.map(function(t){return vn(e.R,t)})};this.cr(n)},n}(lo),vo=function(t){function n(e,n,r){var i=this;return(i=t.call(this)||this).credentials=e,i.Hi=n,i.R=r,i.Rr=!1,i}return(0,e.__extends)(n,t),n.prototype.br=function(){if(this.Rr)throw new u(a.FAILED_PRECONDITION,"The client has already been terminated.")},n.prototype.Ni=function(t,e,n){var r=this;return this.br(),this.credentials.getToken().then(function(i){return r.Hi.Ni(t,e,n,i)}).catch(function(t){throw"FirebaseError"===t.name?(t.code===a.UNAUTHENTICATED&&r.credentials.invalidateToken(),t):new u(a.UNKNOWN,t.toString())})},n.prototype.$i=function(t,e,n){var r=this;return this.br(),this.credentials.getToken().then(function(i){return r.Hi.$i(t,e,n,i)}).catch(function(t){throw"FirebaseError"===t.name?(t.code===a.UNAUTHENTICATED&&r.credentials.invalidateToken(),t):new u(a.UNKNOWN,t.toString())})},n.prototype.terminate=function(){this.Rr=!0},n}(function(){}),mo=function(){function t(t,e){this.asyncQueue=t,this.onlineStateHandler=e,this.state="Unknown",this.vr=0,this.Pr=null,this.Vr=!0}return t.prototype.Sr=function(){var t=this;0===this.vr&&(this.Dr("Unknown"),this.Pr=this.asyncQueue.enqueueAfterDelay("online_state_timeout",1e4,function(){return t.Pr=null,t.Cr("Backend didn't respond within 10 seconds."),t.Dr("Offline"),Promise.resolve()}))},t.prototype.Nr=function(t){"Online"===this.state?this.Dr("Unknown"):(this.vr++,this.vr>=1&&(this.kr(),this.Cr("Connection failed 1 times. Most recent error: "+t.toString()),this.Dr("Offline")))},t.prototype.set=function(t){this.kr(),this.vr=0,"Online"===t&&(this.Vr=!1),this.Dr(t)},t.prototype.Dr=function(t){t!==this.state&&(this.state=t,this.onlineStateHandler(t))},t.prototype.Cr=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.Vr?(l(e),this.Vr=!1):f("OnlineStateTracker",e)},t.prototype.kr=function(){null!==this.Pr&&(this.Pr.cancel(),this.Pr=null)},t}(),go=function(t,n,r,i,o){var s=this;this.localStore=t,this.datastore=n,this.asyncQueue=r,this.remoteSyncer={},this.Fr=[],this.$r=new Map,this.Or=new Set,this.Mr=[],this.Lr=o,this.Lr.di(function(t){r.enqueueAndForget(function(){return(0,e.__awaiter)(s,void 0,void 0,function(){return(0,e.__generator)(this,function(t){switch(t.label){case 0:return Do(this)?(f("RemoteStore","Restarting streams for network reachability change."),[4,function(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return(n=m(t)).Or.add(4),[4,wo(n)];case 1:return e.sent(),n.Br.set("Unknown"),n.Or.delete(4),[4,_o(n)];case 2:return e.sent(),[2]}})})}(this)]):[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}})})})}),this.Br=new mo(r,i)};function _o(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n,r;return(0,e.__generator)(this,function(e){switch(e.label){case 0:if(!Do(t))return[3,4];n=0,r=t.Mr,e.label=1;case 1:return n<r.length?[4,(0,r[n])(!0)]:[3,4];case 2:e.sent(),e.label=3;case 3:return n++,[3,1];case 4:return[2]}})})}function wo(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n,r;return(0,e.__generator)(this,function(e){switch(e.label){case 0:n=0,r=t.Mr,e.label=1;case 1:return n<r.length?[4,(0,r[n])(!1)]:[3,4];case 2:e.sent(),e.label=3;case 3:return n++,[3,1];case 4:return[2]}})})}function bo(t,e){var n=m(t);n.$r.has(e.targetId)||(n.$r.set(e.targetId,e),No(n)?So(n):jo(n).er()&&Eo(n,e))}function Io(t,e){var n=m(t),r=jo(n);n.$r.delete(e),r.er()&&To(n,e),0===n.$r.size&&(r.er()?r.ir():Do(n)&&n.Br.set("Unknown"))}function Eo(t,e){t.qr.U(e.targetId),jo(t).mr(e)}function To(t,e){t.qr.U(e),jo(t).yr(e)}function So(t){t.qr=new Ye({getRemoteKeysForTarget:function(e){return t.remoteSyncer.getRemoteKeysForTarget(e)},lt:function(e){return t.$r.get(e)||null}}),jo(t).start(),t.Br.Sr()}function No(t){return Do(t)&&!jo(t).tr()&&t.$r.size>0}function Do(t){return 0===m(t).Or.size}function Ao(t){t.qr=void 0}function xo(t){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(e){return t.$r.forEach(function(e,n){Eo(t,e)}),[2]})})}function ko(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(e){return Ao(t),No(t)?(t.Br.Nr(n),So(t)):t.Br.set("Unknown"),[2]})})}function Co(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o,s;return(0,e.__generator)(this,function(a){switch(a.label){case 0:if(t.Br.set("Online"),!(n instanceof We&&2===n.state&&n.cause))return[3,6];a.label=1;case 1:return a.trys.push([1,3,,5]),[4,function(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o,s;return(0,e.__generator)(this,function(e){switch(e.label){case 0:r=n.cause,i=0,o=n.targetIds,e.label=1;case 1:return i<o.length?(s=o[i],t.$r.has(s)?[4,t.remoteSyncer.rejectListen(s,r)]:[3,3]):[3,5];case 2:e.sent(),t.$r.delete(s),t.qr.removeTarget(s),e.label=3;case 3:e.label=4;case 4:return i++,[3,1];case 5:return[2]}})})}(t,n)];case 2:return a.sent(),[3,5];case 3:return i=a.sent(),f("RemoteStore","Failed to remove targets %s: %s ",n.targetIds.join(","),i),[4,Ro(t,i)];case 4:return a.sent(),[3,5];case 5:return[3,13];case 6:if(n instanceof Qe?t.qr.X(n):n instanceof ze?t.qr.rt(n):t.qr.et(n),r.isEqual(T.min()))return[3,13];a.label=7;case 7:return a.trys.push([7,11,,13]),[4,Ti(t.localStore)];case 8:return o=a.sent(),r.compareTo(o)>=0?[4,function(t,e){var n=t.qr.ut(e);return n.targetChanges.forEach(function(n,r){if(n.resumeToken.approximateByteSize()>0){var i=t.$r.get(r);i&&t.$r.set(r,i.withResumeToken(n.resumeToken,e))}}),n.targetMismatches.forEach(function(e){var n=t.$r.get(e);if(n){t.$r.set(e,n.withResumeToken(L.EMPTY_BYTE_STRING,n.snapshotVersion)),To(t,e);var r=new vr(n.target,e,1,n.sequenceNumber);Eo(t,r)}}),t.remoteSyncer.applyRemoteEvent(n)}(t,r)]:[3,10];case 9:a.sent(),a.label=10;case 10:return[3,13];case 11:return f("RemoteStore","Failed to raise snapshot:",s=a.sent()),[4,Ro(t,s)];case 12:return a.sent(),[3,13];case 13:return[2]}})})}function Ro(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i=this;return(0,e.__generator)(this,function(o){switch(o.label){case 0:if(!ar(n))throw n;return t.Or.add(1),[4,wo(t)];case 1:return o.sent(),t.Br.set("Offline"),r||(r=function(){return Ti(t.localStore)}),t.asyncQueue.enqueueRetryable(function(){return(0,e.__awaiter)(i,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return f("RemoteStore","Retrying IndexedDB access"),[4,r()];case 1:return e.sent(),t.Or.delete(1),[4,_o(t)];case 2:return e.sent(),[2]}})})}),[2]}})})}function Lo(t,e){return e().catch(function(n){return Ro(t,n,e)})}function Oo(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n,r,i,o,s;return(0,e.__generator)(this,function(e){switch(e.label){case 0:n=m(t),r=Ko(n),i=n.Fr.length>0?n.Fr[n.Fr.length-1].batchId:-1,e.label=1;case 1:if(!function(t){return Do(t)&&t.Fr.length<10}(n))return[3,7];e.label=2;case 2:return e.trys.push([2,4,,6]),[4,Di(n.localStore,i)];case 3:return null===(o=e.sent())?(0===n.Fr.length&&r.ir(),[3,7]):(i=o.batchId,function(t,e){t.Fr.push(e);var n=Ko(t);n.er()&&n.pr&&n.Er(e.mutations)}(n,o),[3,6]);case 4:return s=e.sent(),[4,Ro(n,s)];case 5:return e.sent(),[3,6];case 6:return[3,1];case 7:return Po(n)&&Fo(n),[2]}})})}function Po(t){return Do(t)&&!Ko(t).tr()&&t.Fr.length>0}function Fo(t){Ko(t).start()}function Mo(t){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(e){return Ko(t).Ar(),[2]})})}function Vo(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n,r,i,o;return(0,e.__generator)(this,function(e){for(n=Ko(t),r=0,i=t.Fr;r<i.length;r++)o=i[r],n.Er(o.mutations);return[2]})})}function qo(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return i=t.Fr.shift(),o=yr.from(i,n,r),[4,Lo(t,function(){return t.remoteSyncer.applySuccessfulWrite(o)})];case 1:return e.sent(),[4,Oo(t)];case 2:return e.sent(),[2]}})})}function Uo(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(r){switch(r.label){case 0:return n&&Ko(t).pr?[4,function(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return Ne(i=n.code)&&i!==a.ABORTED?(r=t.Fr.shift(),Ko(t).sr(),[4,Lo(t,function(){return t.remoteSyncer.rejectFailedWrite(r.batchId,n)})]):[3,3];case 1:return e.sent(),[4,Oo(t)];case 2:e.sent(),e.label=3;case 3:return[2]}})})}(t,n)]:[3,2];case 1:r.sent(),r.label=2;case 2:return Po(t)&&Fo(t),[2]}})})}function Bo(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return r=m(t),n?(r.Or.delete(2),[4,_o(r)]):[3,2];case 1:return e.sent(),[3,5];case 2:return n?[3,4]:(r.Or.add(2),[4,wo(r)]);case 3:e.sent(),r.Br.set("Unknown"),e.label=4;case 4:e.label=5;case 5:return[2]}})})}function jo(t){var n=this;return t.Ur||(t.Ur=function(t,e,n){var r=m(t);return r.br(),new po(e,r.Hi,r.credentials,r.R,n)}(t.datastore,t.asyncQueue,{Ii:xo.bind(null,t),Ri:ko.bind(null,t),_r:Co.bind(null,t)}),t.Mr.push(function(r){return(0,e.__awaiter)(n,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return r?(t.Ur.sr(),No(t)?So(t):t.Br.set("Unknown"),[3,3]):[3,1];case 1:return[4,t.Ur.stop()];case 2:e.sent(),Ao(t),e.label=3;case 3:return[2]}})})})),t.Ur}function Ko(t){var n=this;return t.Kr||(t.Kr=function(t,e,n){var r=m(t);return r.br(),new yo(e,r.Hi,r.credentials,r.R,n)}(t.datastore,t.asyncQueue,{Ii:Mo.bind(null,t),Ri:Uo.bind(null,t),Ir:Vo.bind(null,t),Tr:qo.bind(null,t)}),t.Mr.push(function(r){return(0,e.__awaiter)(n,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return r?(t.Kr.sr(),[4,Oo(t)]):[3,2];case 1:return e.sent(),[3,4];case 2:return[4,t.Kr.stop()];case 3:e.sent(),t.Fr.length>0&&(f("RemoteStore","Stopping write stream with "+t.Fr.length+" pending writes"),t.Fr=[]),e.label=4;case 4:return[2]}})})})),t.Kr}var Go=function(){function t(t,e,n,r,i){this.asyncQueue=t,this.timerId=e,this.targetTimeMs=n,this.op=r,this.removalCallback=i,this.deferred=new er,this.then=this.deferred.promise.then.bind(this.deferred.promise),this.deferred.promise.catch(function(t){})}return t.createAndSchedule=function(e,n,r,i,o){var s=new t(e,n,Date.now()+r,i,o);return s.start(r),s},t.prototype.start=function(t){var e=this;this.timerHandle=setTimeout(function(){return e.handleDelayElapsed()},t)},t.prototype.skipDelay=function(){return this.handleDelayElapsed()},t.prototype.cancel=function(t){null!==this.timerHandle&&(this.clearTimeout(),this.deferred.reject(new u(a.CANCELLED,"Operation cancelled"+(t?": "+t:""))))},t.prototype.handleDelayElapsed=function(){var t=this;this.asyncQueue.enqueueAndForget(function(){return null!==t.timerHandle?(t.clearTimeout(),t.op().then(function(e){return t.deferred.resolve(e)})):Promise.resolve()})},t.prototype.clearTimeout=function(){null!==this.timerHandle&&(this.removalCallback(this),clearTimeout(this.timerHandle),this.timerHandle=null)},t}();function Qo(t,e){if(l("AsyncQueue",e+": "+t),ar(t))return new u(a.UNAVAILABLE,e+": "+t);throw t}var zo=function(){function t(t){this.comparator=t?function(e,n){return t(e,n)||G.comparator(e.key,n.key)}:function(t,e){return G.comparator(t.key,e.key)},this.keyedMap=Fe(),this.sortedSet=new Ae(this.comparator)}return t.emptySet=function(e){return new t(e.comparator)},t.prototype.has=function(t){return null!=this.keyedMap.get(t)},t.prototype.get=function(t){return this.keyedMap.get(t)},t.prototype.first=function(){return this.sortedSet.minKey()},t.prototype.last=function(){return this.sortedSet.maxKey()},t.prototype.isEmpty=function(){return this.sortedSet.isEmpty()},t.prototype.indexOf=function(t){var e=this.keyedMap.get(t);return e?this.sortedSet.indexOf(e):-1},Object.defineProperty(t.prototype,"size",{get:function(){return this.sortedSet.size},enumerable:!1,configurable:!0}),t.prototype.forEach=function(t){this.sortedSet.inorderTraversal(function(e,n){return t(e),!1})},t.prototype.add=function(t){var e=this.delete(t.key);return e.copy(e.keyedMap.insert(t.key,t),e.sortedSet.insert(t,null))},t.prototype.delete=function(t){var e=this.get(t);return e?this.copy(this.keyedMap.remove(t),this.sortedSet.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.sortedSet.getIterator(),r=e.sortedSet.getIterator();n.hasNext();){var i=n.getNext().key,o=r.getNext().key;if(!i.isEqual(o))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.copy=function(e,n){var r=new t;return r.comparator=this.comparator,r.keyedMap=e,r.sortedSet=n,r},t}(),Wo=function(){function t(){this.Qr=new Ae(G.comparator)}return t.prototype.track=function(t){var e=t.doc.key,n=this.Qr.get(e);n?0!==t.type&&3===n.type?this.Qr=this.Qr.insert(e,t):3===t.type&&1!==n.type?this.Qr=this.Qr.insert(e,{type:n.type,doc:t.doc}):2===t.type&&2===n.type?this.Qr=this.Qr.insert(e,{type:2,doc:t.doc}):2===t.type&&0===n.type?this.Qr=this.Qr.insert(e,{type:0,doc:t.doc}):1===t.type&&0===n.type?this.Qr=this.Qr.remove(e):1===t.type&&2===n.type?this.Qr=this.Qr.insert(e,{type:1,doc:n.doc}):0===t.type&&1===n.type?this.Qr=this.Qr.insert(e,{type:2,doc:t.doc}):y():this.Qr=this.Qr.insert(e,t)},t.prototype.jr=function(){var t=[];return this.Qr.inorderTraversal(function(e,n){t.push(n)}),t},t}(),Ho=function(){function t(t,e,n,r,i,o,s,a){this.query=t,this.docs=e,this.oldDocs=n,this.docChanges=r,this.mutatedKeys=i,this.fromCache=o,this.syncStateChanged=s,this.excludesMetadataChanges=a}return t.fromInitialDocuments=function(e,n,r,i){var o=[];return n.forEach(function(t){o.push({type:0,doc:t})}),new t(e,n,zo.emptySet(n),o,r,i,!0,!1)},Object.defineProperty(t.prototype,"hasPendingWrites",{get:function(){return!this.mutatedKeys.isEmpty()},enumerable:!1,configurable:!0}),t.prototype.isEqual=function(t){if(!(this.fromCache===t.fromCache&&this.syncStateChanged===t.syncStateChanged&&this.mutatedKeys.isEqual(t.mutatedKeys)&&qt(this.query,t.query)&&this.docs.isEqual(t.docs)&&this.oldDocs.isEqual(t.oldDocs)))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}(),Yo=function(){this.Wr=void 0,this.listeners=[]},$o=function(){this.queries=new ni(function(t){return Ut(t)},qt),this.onlineState="Unknown",this.Gr=new Set};function Xo(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o,s,a,u,c;return(0,e.__generator)(this,function(e){switch(e.label){case 0:if(r=m(t),i=n.query,o=!1,(s=r.queries.get(i))||(o=!0,s=new Yo),!o)return[3,4];e.label=1;case 1:return e.trys.push([1,3,,4]),a=s,[4,r.onListen(i)];case 2:return a.Wr=e.sent(),[3,4];case 3:return u=e.sent(),c=Qo(u,"Initialization of query '"+Bt(n.query)+"' failed"),[2,void n.onError(c)];case 4:return r.queries.set(i,s),s.listeners.push(n),n.zr(r.onlineState),s.Wr&&n.Hr(s.Wr)&&es(r),[2]}})})}function Jo(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o,s,a;return(0,e.__generator)(this,function(e){return r=m(t),i=n.query,o=!1,(s=r.queries.get(i))&&(a=s.listeners.indexOf(n))>=0&&(s.listeners.splice(a,1),o=0===s.listeners.length),o?[2,(r.queries.delete(i),r.onUnlisten(i))]:[2]})})}function Zo(t,e){for(var n=m(t),r=!1,i=0,o=e;i<o.length;i++){var s=o[i],a=s.query,u=n.queries.get(a);if(u){for(var c=0,h=u.listeners;c<h.length;c++)h[c].Hr(s)&&(r=!0);u.Wr=s}}r&&es(n)}function ts(t,e,n){var r=m(t),i=r.queries.get(e);if(i)for(var o=0,s=i.listeners;o<s.length;o++)s[o].onError(n);r.queries.delete(e)}function es(t){t.Gr.forEach(function(t){t.next()})}var ns=function(){function t(t,e,n){this.query=t,this.Jr=e,this.Yr=!1,this.Xr=null,this.onlineState="Unknown",this.options=n||{}}return t.prototype.Hr=function(t){if(!this.options.includeMetadataChanges){for(var e=[],n=0,r=t.docChanges;n<r.length;n++){var i=r[n];3!==i.type&&e.push(i)}t=new Ho(t.query,t.docs,t.oldDocs,e,t.mutatedKeys,t.fromCache,t.syncStateChanged,!0)}var o=!1;return this.Yr?this.Zr(t)&&(this.Jr.next(t),o=!0):this.eo(t,this.onlineState)&&(this.no(t),o=!0),this.Xr=t,o},t.prototype.onError=function(t){this.Jr.error(t)},t.prototype.zr=function(t){this.onlineState=t;var e=!1;return this.Xr&&!this.Yr&&this.eo(this.Xr,t)&&(this.no(this.Xr),e=!0),e},t.prototype.eo=function(t,e){if(!t.fromCache)return!0;var n="Offline"!==e;return!(this.options.so&&n||t.docs.isEmpty()&&"Offline"!==e)},t.prototype.Zr=function(t){if(t.docChanges.length>0)return!0;var e=this.Xr&&this.Xr.hasPendingWrites!==t.hasPendingWrites;return!(!t.syncStateChanged&&!e)&&!0===this.options.includeMetadataChanges},t.prototype.no=function(t){t=Ho.fromInitialDocuments(t.query,t.docs,t.mutatedKeys,t.fromCache),this.Yr=!0,this.Jr.next(t)},t}(),rs=function(){function t(t,e){this.payload=t,this.byteLength=e}return t.prototype.io=function(){return"metadata"in this.payload},t}(),is=function(){function t(t){this.R=t}return t.prototype.qn=function(t){return cn(this.R,t)},t.prototype.Un=function(t){return t.metadata.exists?yn(this.R,t.document,!1):at.newNoDocument(this.qn(t.metadata.name),this.Kn(t.metadata.readTime))},t.prototype.Kn=function(t){return on(t)},t}(),os=function(){function t(t,e,n){this.ro=t,this.localStore=e,this.R=n,this.queries=[],this.documents=[],this.progress=ss(t)}return t.prototype.oo=function(t){this.progress.bytesLoaded+=t.byteLength;var e=this.progress.documentsLoaded;return t.payload.namedQuery?this.queries.push(t.payload.namedQuery):t.payload.documentMetadata?(this.documents.push({metadata:t.payload.documentMetadata}),t.payload.documentMetadata.exists||++e):t.payload.document&&(this.documents[this.documents.length-1].document=t.payload.document,++e),e!==this.progress.documentsLoaded?(this.progress.documentsLoaded=e,Object.assign({},this.progress)):null},t.prototype.co=function(t){for(var e=new Map,n=new is(this.R),r=0,i=t;r<i.length;r++){var o=i[r];if(o.metadata.queries)for(var s=n.qn(o.metadata.name),a=0,u=o.metadata.queries;a<u.length;a++){var c=u[a],h=(e.get(c)||Ue()).add(s);e.set(c,h)}}return e},t.prototype.complete=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var t,n,r,i,o;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,Oi(this.localStore,new is(this.R),this.documents,this.ro.id)];case 1:t=e.sent(),n=this.co(this.documents),r=0,i=this.queries,e.label=2;case 2:return r<i.length?(o=i[r],[4,Pi(this.localStore,o,n.get(o.name))]):[3,5];case 3:e.sent(),e.label=4;case 4:return r++,[3,2];case 5:return[2,(this.progress.taskState="Success",new vi(Object.assign({},this.progress),t))]}})})},t}();function ss(t){return{taskState:"Running",documentsLoaded:0,bytesLoaded:0,totalDocuments:t.totalDocuments,totalBytes:t.totalBytes}}var as=function(t){this.key=t},us=function(t){this.key=t},cs=function(){function t(t,e){this.query=t,this.uo=e,this.ao=null,this.current=!1,this.ho=Ue(),this.mutatedKeys=Ue(),this.lo=Kt(t),this.fo=new zo(this.lo)}return Object.defineProperty(t.prototype,"wo",{get:function(){return this.uo},enumerable:!1,configurable:!0}),t.prototype._o=function(t,e){var n=this,r=e?e.mo:new Wo,i=e?e.fo:this.fo,o=e?e.mutatedKeys:this.mutatedKeys,s=i,a=!1,u=Ct(this.query)&&i.size===this.query.limit?i.last():null,c=Rt(this.query)&&i.size===this.query.limit?i.first():null;if(t.inorderTraversal(function(t,e){var h=i.get(t),f=jt(n.query,e)?e:null,l=!!h&&n.mutatedKeys.has(h.key),d=!!f&&(f.hasLocalMutations||n.mutatedKeys.has(f.key)&&f.hasCommittedMutations),p=!1;h&&f?h.data.isEqual(f.data)?l!==d&&(r.track({type:3,doc:f}),p=!0):n.yo(h,f)||(r.track({type:2,doc:f}),p=!0,(u&&n.lo(f,u)>0||c&&n.lo(f,c)<0)&&(a=!0)):!h&&f?(r.track({type:0,doc:f}),p=!0):h&&!f&&(r.track({type:1,doc:h}),p=!0,(u||c)&&(a=!0)),p&&(f?(s=s.add(f),o=d?o.add(t):o.delete(t)):(s=s.delete(t),o=o.delete(t)))}),Ct(this.query)||Rt(this.query))for(;s.size>this.query.limit;){var h=Ct(this.query)?s.last():s.first();s=s.delete(h.key),o=o.delete(h.key),r.track({type:1,doc:h})}return{fo:s,mo:r,Nn:a,mutatedKeys:o}},t.prototype.yo=function(t,e){return t.hasLocalMutations&&e.hasCommittedMutations&&!e.hasLocalMutations},t.prototype.applyChanges=function(t,e,n){var r=this,i=this.fo;this.fo=t.fo,this.mutatedKeys=t.mutatedKeys;var o=t.mo.jr();o.sort(function(t,e){return function(t,e){var n=function(t){switch(t){case 0:return 1;case 2:case 3:return 2;case 1:return 0;default:return y()}};return n(t)-n(e)}(t.type,e.type)||r.lo(t.doc,e.doc)}),this.po(n);var s=e?this.Eo():[],a=0===this.ho.size&&this.current?1:0,u=a!==this.ao;return this.ao=a,0!==o.length||u?{snapshot:new Ho(this.query,t.fo,i,o,t.mutatedKeys,0===a,u,!1),To:s}:{To:s}},t.prototype.zr=function(t){return this.current&&"Offline"===t?(this.current=!1,this.applyChanges({fo:this.fo,mo:new Wo,mutatedKeys:this.mutatedKeys,Nn:!1},!1)):{To:[]}},t.prototype.Io=function(t){return!this.uo.has(t)&&!!this.fo.has(t)&&!this.fo.get(t).hasLocalMutations},t.prototype.po=function(t){var e=this;t&&(t.addedDocuments.forEach(function(t){return e.uo=e.uo.add(t)}),t.modifiedDocuments.forEach(function(t){}),t.removedDocuments.forEach(function(t){return e.uo=e.uo.delete(t)}),this.current=t.current)},t.prototype.Eo=function(){var t=this;if(!this.current)return[];var e=this.ho;this.ho=Ue(),this.fo.forEach(function(e){t.Io(e.key)&&(t.ho=t.ho.add(e.key))});var n=[];return e.forEach(function(e){t.ho.has(e)||n.push(new us(e))}),this.ho.forEach(function(t){e.has(t)||n.push(new as(t))}),n},t.prototype.Ao=function(t){this.uo=t.Bn,this.ho=Ue();var e=this._o(t.documents);return this.applyChanges(e,!0)},t.prototype.Ro=function(){return Ho.fromInitialDocuments(this.query,this.fo,this.mutatedKeys,0===this.ao)},t}(),hs=function(t,e,n){this.query=t,this.targetId=e,this.view=n},fs=function(t){this.key=t,this.bo=!1},ls=function(){function t(t,e,n,r,i,o){this.localStore=t,this.remoteStore=e,this.eventManager=n,this.sharedClientState=r,this.currentUser=i,this.maxConcurrentLimboResolutions=o,this.vo={},this.Po=new ni(function(t){return Ut(t)},qt),this.Vo=new Map,this.So=new Set,this.Do=new Ae(G.comparator),this.Co=new Map,this.No=new Mi,this.xo={},this.ko=new Map,this.Fo=Gr.Yt(),this.onlineState="Unknown",this.$o=void 0}return Object.defineProperty(t.prototype,"isPrimaryClient",{get:function(){return!0===this.$o},enumerable:!1,configurable:!0}),t}();function ds(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o,s,a,u;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return r=js(t),(s=r.Po.get(n))?(i=s.targetId,r.sharedClientState.addLocalQueryTarget(i),o=s.view.Ro(),[3,4]):[3,1];case 1:return[4,Ai(r.localStore,Mt(n))];case 2:return a=e.sent(),u=r.sharedClientState.addLocalQueryTarget(a.targetId),i=a.targetId,[4,ps(r,n,i,"current"===u)];case 3:o=e.sent(),r.isPrimaryClient&&bo(r.remoteStore,a),e.label=4;case 4:return[2,o]}})})}function ps(t,n,r,i){return(0,e.__awaiter)(this,void 0,void 0,function(){var o,s,a,u,c,h;return(0,e.__generator)(this,function(f){switch(f.label){case 0:return t.Oo=function(n,r,i){return function(t,n,r,i){return(0,e.__awaiter)(this,void 0,void 0,function(){var o,s,a;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return(o=n.view._o(r)).Nn?[4,ki(t.localStore,n.query,!1).then(function(t){var e=t.documents;return n.view._o(e,o)})]:[3,2];case 1:o=e.sent(),e.label=2;case 2:return s=i&&i.targetChanges.get(n.targetId),a=n.view.applyChanges(o,t.isPrimaryClient,s),[2,(Ds(t,n.targetId,a.To),a.snapshot)]}})})}(t,n,r,i)},[4,ki(t.localStore,n,!0)];case 1:return o=f.sent(),s=new cs(n,o.Bn),a=s._o(o.documents),u=Ge.createSynthesizedTargetChangeForCurrentChange(r,i&&"Offline"!==t.onlineState),c=s.applyChanges(a,t.isPrimaryClient,u),Ds(t,r,c.To),h=new hs(n,r,s),[2,(t.Po.set(n,h),t.Vo.has(r)?t.Vo.get(r).push(n):t.Vo.set(r,[n]),c.snapshot)]}})})}function ys(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return r=m(t),i=r.Po.get(n),(o=r.Vo.get(i.targetId)).length>1?[2,(r.Vo.set(i.targetId,o.filter(function(t){return!qt(t,n)})),void r.Po.delete(n))]:r.isPrimaryClient?(r.sharedClientState.removeLocalQueryTarget(i.targetId),r.sharedClientState.isActiveQueryTarget(i.targetId)?[3,2]:[4,xi(r.localStore,i.targetId,!1).then(function(){r.sharedClientState.clearQueryState(i.targetId),Io(r.remoteStore,i.targetId),Ss(r,i.targetId)}).catch(Yr)]):[3,3];case 1:e.sent(),e.label=2;case 2:return[3,5];case 3:return Ss(r,i.targetId),[4,xi(r.localStore,i.targetId,!0)];case 4:e.sent(),e.label=5;case 5:return[2]}})})}function vs(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o,s,a;return(0,e.__generator)(this,function(e){switch(e.label){case 0:i=Ks(t),e.label=1;case 1:return e.trys.push([1,5,,6]),[4,function(t,e){var n,r=m(t),i=E.now(),o=e.reduce(function(t,e){return t.add(e.key)},Ue());return r.persistence.runTransaction("Locally write mutations","readwrite",function(t){return r.Mn.pn(t,o).next(function(o){n=o;for(var s=[],a=0,u=e;a<u.length;a++){var c=u[a],h=de(c,n.get(c.key));null!=h&&s.push(new me(c.key,h,st(h.value.mapValue),ue.exists(!0)))}return r._n.addMutationBatch(t,i,s,e)})}).then(function(t){return t.applyToLocalDocumentSet(n),{batchId:t.batchId,changes:n}})}(i.localStore,n)];case 2:return o=e.sent(),i.sharedClientState.addPendingMutation(o.batchId),function(t,e,n){var r=t.xo[t.currentUser.toKey()];r||(r=new Ae(w)),r=r.insert(e,n),t.xo[t.currentUser.toKey()]=r}(i,o.batchId,r),[4,ks(i,o.changes)];case 3:return e.sent(),[4,Oo(i.remoteStore)];case 4:return e.sent(),[3,6];case 5:return s=e.sent(),a=Qo(s,"Failed to persist write"),r.reject(a),[3,6];case 6:return[2]}})})}function ms(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i;return(0,e.__generator)(this,function(e){switch(e.label){case 0:r=m(t),e.label=1;case 1:return e.trys.push([1,4,,6]),[4,Si(r.localStore,n)];case 2:return i=e.sent(),n.targetChanges.forEach(function(t,e){var n=r.Co.get(e);n&&(v(t.addedDocuments.size+t.modifiedDocuments.size+t.removedDocuments.size<=1),t.addedDocuments.size>0?n.bo=!0:t.modifiedDocuments.size>0?v(n.bo):t.removedDocuments.size>0&&(v(n.bo),n.bo=!1))}),[4,ks(r,i,n)];case 3:return e.sent(),[3,6];case 4:return[4,Yr(e.sent())];case 5:return e.sent(),[3,6];case 6:return[2]}})})}function gs(t,e,n){var r=m(t);if(r.isPrimaryClient&&0===n||!r.isPrimaryClient&&1===n){var i=[];r.Po.forEach(function(t,n){var r=n.view.zr(e);r.snapshot&&i.push(r.snapshot)}),function(t,e){var n=m(t);n.onlineState=e;var r=!1;n.queries.forEach(function(t,n){for(var i=0,o=n.listeners;i<o.length;i++)o[i].zr(e)&&(r=!0)}),r&&es(n)}(r.eventManager,e),i.length&&r.vo._r(i),r.onlineState=e,r.isPrimaryClient&&r.sharedClientState.setOnlineState(e)}}function _s(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o,s,a,u,c;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return(i=m(t)).sharedClientState.updateQueryState(n,"rejected",r),o=i.Co.get(n),(s=o&&o.key)?(a=(a=new Ae(G.comparator)).insert(s,at.newNoDocument(s,T.min())),u=Ue().add(s),c=new Ke(T.min(),new Map,new Ce(w),a,u),[4,ms(i,c)]):[3,2];case 1:return e.sent(),i.Do=i.Do.remove(s),i.Co.delete(n),xs(i),[3,4];case 2:return[4,xi(i.localStore,n,!1).then(function(){return Ss(i,n,r)}).catch(Yr)];case 3:e.sent(),e.label=4;case 4:return[2]}})})}function ws(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o;return(0,e.__generator)(this,function(e){switch(e.label){case 0:r=m(t),i=n.batch.batchId,e.label=1;case 1:return e.trys.push([1,4,,6]),[4,Ei(r.localStore,n)];case 2:return o=e.sent(),Ts(r,i,null),Es(r,i),r.sharedClientState.updateMutationState(i,"acknowledged"),[4,ks(r,o)];case 3:return e.sent(),[3,6];case 4:return[4,Yr(e.sent())];case 5:return e.sent(),[3,6];case 6:return[2]}})})}function bs(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o;return(0,e.__generator)(this,function(e){switch(e.label){case 0:i=m(t),e.label=1;case 1:return e.trys.push([1,4,,6]),[4,function(t,e){var n=m(t);return n.persistence.runTransaction("Reject batch","readwrite-primary",function(t){var r;return n._n.lookupMutationBatch(t,e).next(function(e){return v(null!==e),r=e.keys(),n._n.removeMutationBatch(t,e)}).next(function(){return n._n.performConsistencyCheck(t)}).next(function(){return n.Mn.pn(t,r)})})}(i.localStore,n)];case 2:return o=e.sent(),Ts(i,n,r),Es(i,n),i.sharedClientState.updateMutationState(n,"rejected",r),[4,ks(i,o)];case 3:return e.sent(),[3,6];case 4:return[4,Yr(e.sent())];case 5:return e.sent(),[3,6];case 6:return[2]}})})}function Is(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o,s,a;return(0,e.__generator)(this,function(e){switch(e.label){case 0:Do((r=m(t)).remoteStore)||f("SyncEngine","The network is disabled. The task returned by 'awaitPendingWrites()' will not complete until the network is enabled."),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,function(t){var e=m(r.localStore);return e.persistence.runTransaction("Get highest unacknowledged batch id","readonly",function(t){return e._n.getHighestUnacknowledgedBatchId(t)})}()];case 2:return-1===(i=e.sent())?[2,void n.resolve()]:((o=r.ko.get(i)||[]).push(n),r.ko.set(i,o),[3,4]);case 3:return s=e.sent(),a=Qo(s,"Initialization of waitForPendingWrites() operation failed"),n.reject(a),[3,4];case 4:return[2]}})})}function Es(t,e){(t.ko.get(e)||[]).forEach(function(t){t.resolve()}),t.ko.delete(e)}function Ts(t,e,n){var r=m(t),i=r.xo[r.currentUser.toKey()];if(i){var o=i.get(e);o&&(n?o.reject(n):o.resolve(),i=i.remove(e)),r.xo[r.currentUser.toKey()]=i}}function Ss(t,e,n){void 0===n&&(n=null),t.sharedClientState.removeLocalQueryTarget(e);for(var r=0,i=t.Vo.get(e);r<i.length;r++){var o=i[r];t.Po.delete(o),n&&t.vo.Mo(o,n)}t.Vo.delete(e),t.isPrimaryClient&&t.No.Zn(e).forEach(function(e){t.No.containsKey(e)||Ns(t,e)})}function Ns(t,e){t.So.delete(e.path.canonicalString());var n=t.Do.get(e);null!==n&&(Io(t.remoteStore,n),t.Do=t.Do.remove(e),t.Co.delete(n),xs(t))}function Ds(t,e,n){for(var r=0,i=n;r<i.length;r++){var o=i[r];o instanceof as?(t.No.addReference(o.key,e),As(t,o)):o instanceof us?(f("SyncEngine","Document no longer in limbo: "+o.key),t.No.removeReference(o.key,e),t.No.containsKey(o.key)||Ns(t,o.key)):y()}}function As(t,e){var n=e.key,r=n.path.canonicalString();t.Do.get(n)||t.So.has(r)||(f("SyncEngine","New document in limbo: "+n),t.So.add(r),xs(t))}function xs(t){for(;t.So.size>0&&t.Do.size<t.maxConcurrentLimboResolutions;){var e=t.So.values().next().value;t.So.delete(e);var n=new G(x.fromString(e)),r=t.Fo.next();t.Co.set(r,new fs(n)),t.Do=t.Do.insert(n,r),bo(t.remoteStore,new vr(Mt(kt(n.path)),r,2,s.o))}}function ks(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o,s,a;return(0,e.__generator)(this,function(u){switch(u.label){case 0:return i=m(t),o=[],s=[],a=[],i.Po.isEmpty()?[3,3]:(i.Po.forEach(function(t,e){a.push(i.Oo(e,n,r).then(function(t){if(t){i.isPrimaryClient&&i.sharedClientState.updateQueryState(e.targetId,t.fromCache?"not-current":"current"),o.push(t);var n=gi.Pn(e.targetId,t);s.push(n)}}))}),[4,Promise.all(a)]);case 1:return u.sent(),i.vo._r(o),[4,function(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o,s,a,u,c,h,l;return(0,e.__generator)(this,function(e){switch(e.label){case 0:r=m(t),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,r.persistence.runTransaction("notifyLocalViewChanges","readwrite",function(t){return nr.forEach(n,function(e){return nr.forEach(e.bn,function(n){return r.persistence.referenceDelegate.addReference(t,e.targetId,n)}).next(function(){return nr.forEach(e.vn,function(n){return r.persistence.referenceDelegate.removeReference(t,e.targetId,n)})})})})];case 2:return e.sent(),[3,4];case 3:if(!ar(i=e.sent()))throw i;return f("LocalStore","Failed to update sequence numbers: "+i),[3,4];case 4:for(o=0,s=n;o<s.length;o++)a=s[o],u=a.targetId,a.fromCache||(c=r.kn.get(u),h=c.snapshotVersion,l=c.withLastLimboFreeSnapshotVersion(h),r.kn=r.kn.insert(u,l));return[2]}})})}(i.localStore,s)];case 2:u.sent(),u.label=3;case 3:return[2]}})})}function Cs(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return(r=m(t)).currentUser.isEqual(n)?[3,3]:(f("SyncEngine","User change. New user:",n.toKey()),[4,Ii(r.localStore,n)]);case 1:return i=e.sent(),r.currentUser=n,function(t,e){t.ko.forEach(function(t){t.forEach(function(t){t.reject(new u(a.CANCELLED,"'waitForPendingWrites' promise is rejected due to a user change."))})}),t.ko.clear()}(r),r.sharedClientState.handleUserChange(n,i.removedBatchIds,i.addedBatchIds),[4,ks(r,i.Ln)];case 2:e.sent(),e.label=3;case 3:return[2]}})})}function Rs(t,e){var n=m(t),r=n.Co.get(e);if(r&&r.bo)return Ue().add(r.key);var i=Ue(),o=n.Vo.get(e);if(!o)return i;for(var s=0,a=o;s<a.length;s++){var u=a[s],c=n.Po.get(u);i=i.unionWith(c.view.wo)}return i}function Ls(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,ki((r=m(t)).localStore,n.query,!0)];case 1:return i=e.sent(),o=n.view.Ao(i),[2,(r.isPrimaryClient&&Ds(r,n.targetId,o.To),o)]}})})}function Os(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){return[2,Ri((n=m(t)).localStore).then(function(t){return ks(n,t)})]})})}function Ps(t,n,r,i){return(0,e.__awaiter)(this,void 0,void 0,function(){var o,s;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,function(t,e){var n=m(t),r=m(n._n);return n.persistence.runTransaction("Lookup mutation documents","readonly",function(t){return r.jt(t,e).next(function(e){return e?n.Mn.pn(t,e):nr.resolve(null)})})}((o=m(t)).localStore,n)];case 1:return null===(s=e.sent())?[3,6]:"pending"!==r?[3,3]:[4,Oo(o.remoteStore)];case 2:return e.sent(),[3,4];case 3:"acknowledged"===r||"rejected"===r?(Ts(o,n,i||null),Es(o,n),function(t,e){m(m(t)._n).Gt(e)}(o.localStore,n)):y(),e.label=4;case 4:return[4,ks(o,s)];case 5:return e.sent(),[3,7];case 6:f("SyncEngine","Cannot apply mutation batch with id: "+n),e.label=7;case 7:return[2]}})})}function Fs(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o,s,a,u,c,h;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return js(r=m(t)),Ks(r),!0!==n||!0===r.$o?[3,3]:(i=r.sharedClientState.getAllActiveQueryTargets(),[4,Ms(r,i.toArray())]);case 1:return o=e.sent(),r.$o=!0,[4,Bo(r.remoteStore,!0)];case 2:for(e.sent(),s=0,a=o;s<a.length;s++)u=a[s],bo(r.remoteStore,u);return[3,7];case 3:return!1!==n||!1===r.$o?[3,7]:(c=[],h=Promise.resolve(),r.Vo.forEach(function(t,e){r.sharedClientState.isLocalQueryTarget(e)?c.push(e):h=h.then(function(){return Ss(r,e),xi(r.localStore,e,!0)}),Io(r.remoteStore,e)}),[4,h]);case 4:return e.sent(),[4,Ms(r,c)];case 5:return e.sent(),function(t){var e=m(r);e.Co.forEach(function(t,n){Io(e.remoteStore,n)}),e.No.ts(),e.Co=new Map,e.Do=new Ae(G.comparator)}(),r.$o=!1,[4,Bo(r.remoteStore,!1)];case 6:e.sent(),e.label=7;case 7:return[2]}})})}function Ms(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o,s,a,u,c,h,f,l,d,p,y,v;return(0,e.__generator)(this,function(e){switch(e.label){case 0:r=m(t),i=[],o=[],s=0,a=n,e.label=1;case 1:return s<a.length?(u=a[s],c=void 0,(h=r.Vo.get(u))&&0!==h.length?[4,Ai(r.localStore,Mt(h[0]))]:[3,7]):[3,13];case 2:c=e.sent(),f=0,l=h,e.label=3;case 3:return f<l.length?(d=l[f],p=r.Po.get(d),[4,Ls(r,p)]):[3,6];case 4:(y=e.sent()).snapshot&&o.push(y.snapshot),e.label=5;case 5:return f++,[3,3];case 6:return[3,11];case 7:return[4,Ci(r.localStore,u)];case 8:return v=e.sent(),[4,Ai(r.localStore,v)];case 9:return c=e.sent(),[4,ps(r,Vs(v),u,!1)];case 10:e.sent(),e.label=11;case 11:i.push(c),e.label=12;case 12:return s++,[3,1];case 13:return[2,(r.vo._r(o),i)]}})})}function Vs(t){return xt(t.path,t.collectionGroup,t.orderBy,t.filters,t.limit,"F",t.startAt,t.endAt)}function qs(t){var e=m(t);return m(m(e.localStore).persistence).fn()}function Us(t,n,r,i){return(0,e.__awaiter)(this,void 0,void 0,function(){var o,s,a;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return(o=m(t)).$o?(f("SyncEngine","Ignoring unexpected query state notification."),[3,8]):[3,1];case 1:if(!o.Vo.has(n))return[3,8];switch(r){case"current":case"not-current":return[3,2];case"rejected":return[3,5]}return[3,7];case 2:return[4,Ri(o.localStore)];case 3:return s=e.sent(),a=Ke.createSynthesizedRemoteEventForCurrentChange(n,"current"===r),[4,ks(o,s,a)];case 4:return e.sent(),[3,8];case 5:return[4,xi(o.localStore,n,!0)];case 6:return e.sent(),Ss(o,n,i),[3,8];case 7:y(),e.label=8;case 8:return[2]}})})}function Bs(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o,s,a,u,c,h,l,d,p;return(0,e.__generator)(this,function(y){switch(y.label){case 0:if(!(i=js(t)).$o)return[3,10];o=0,s=n,y.label=1;case 1:return o<s.length?(a=s[o],i.Vo.has(a)?(f("SyncEngine","Adding an already active target "+a),[3,5]):[4,Ci(i.localStore,a)]):[3,6];case 2:return u=y.sent(),[4,Ai(i.localStore,u)];case 3:return c=y.sent(),[4,ps(i,Vs(u),c.targetId,!1)];case 4:y.sent(),bo(i.remoteStore,c),y.label=5;case 5:return o++,[3,1];case 6:h=function(t){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return i.Vo.has(t)?[4,xi(i.localStore,t,!1).then(function(){Io(i.remoteStore,t),Ss(i,t)}).catch(Yr)]:[3,2];case 1:e.sent(),e.label=2;case 2:return[2]}})},l=0,d=r,y.label=7;case 7:return l<d.length?(p=d[l],[5,h(p)]):[3,10];case 8:y.sent(),y.label=9;case 9:return l++,[3,7];case 10:return[2]}})})}function js(t){var e=m(t);return e.remoteStore.remoteSyncer.applyRemoteEvent=ms.bind(null,e),e.remoteStore.remoteSyncer.getRemoteKeysForTarget=Rs.bind(null,e),e.remoteStore.remoteSyncer.rejectListen=_s.bind(null,e),e.vo._r=Zo.bind(null,e.eventManager),e.vo.Mo=ts.bind(null,e.eventManager),e}function Ks(t){var e=m(t);return e.remoteStore.remoteSyncer.applySuccessfulWrite=ws.bind(null,e),e.remoteStore.remoteSyncer.rejectFailedWrite=bs.bind(null,e),e}function Gs(t,n,r){var i=m(t);(function(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o,s,a,u,c;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return e.trys.push([0,14,,15]),[4,n.getMetadata()];case 1:return i=e.sent(),[4,function(t,e){var n=m(t),r=on(e.createTime);return n.persistence.runTransaction("hasNewerBundle","readonly",function(t){return n.Ke.getBundleMetadata(t,e.id)}).then(function(t){return!!t&&t.createTime.compareTo(r)>=0})}(t.localStore,i)];case 2:return e.sent()?[4,n.close()]:[3,4];case 3:return[2,(e.sent(),void r._completeWith(function(t){return{taskState:"Success",documentsLoaded:t.totalDocuments,bytesLoaded:t.totalBytes,totalDocuments:t.totalDocuments,totalBytes:t.totalBytes}}(i)))];case 4:return r._updateProgress(ss(i)),o=new os(i,t.localStore,n.R),[4,n.Lo()];case 5:s=e.sent(),e.label=6;case 6:return s?[4,o.oo(s)]:[3,10];case 7:return(a=e.sent())&&r._updateProgress(a),[4,n.Lo()];case 8:s=e.sent(),e.label=9;case 9:return[3,6];case 10:return[4,o.complete()];case 11:return u=e.sent(),[4,ks(t,u.wn,void 0)];case 12:return e.sent(),[4,function(t,e){var n=m(t);return n.persistence.runTransaction("Save bundle","readwrite",function(t){return n.Ke.saveBundleMetadata(t,e)})}(t.localStore,i)];case 13:return e.sent(),r._completeWith(u.progress),[3,15];case 14:return d("SyncEngine","Loading bundle failed with "+(c=e.sent())),r._failWith(c),[3,15];case 15:return[2]}})})})(i,n,r).then(function(){i.sharedClientState.notifyBundleLoaded()})}var Qs=function(){function t(){this.synchronizeTabs=!1}return t.prototype.initialize=function(t){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return this.R=ho(t.databaseInfo.databaseId),this.sharedClientState=this.Bo(t),this.persistence=this.qo(t),[4,this.persistence.start()];case 1:return e.sent(),this.gcScheduler=this.Uo(t),this.localStore=this.Ko(t),[2]}})})},t.prototype.Uo=function(t){return null},t.prototype.Ko=function(t){return bi(this.persistence,new _i,t.initialUser,this.R)},t.prototype.qo=function(t){return new Ki(Qi.bs,this.R)},t.prototype.Bo=function(t){return new no},t.prototype.terminate=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(t){switch(t.label){case 0:return this.gcScheduler&&this.gcScheduler.stop(),[4,this.sharedClientState.shutdown()];case 1:return t.sent(),[4,this.persistence.shutdown()];case 2:return t.sent(),[2]}})})},t}(),zs=function(t){function n(e,n,r){var i=this;return(i=t.call(this)||this).Qo=e,i.cacheSizeBytes=n,i.forceOwnership=r,i.synchronizeTabs=!1,i}return(0,e.__extends)(n,t),n.prototype.initialize=function(n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r=this;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,t.prototype.initialize.call(this,n)];case 1:return e.sent(),[4,Li(this.localStore)];case 2:return e.sent(),[4,this.Qo.initialize(this,n)];case 3:return e.sent(),[4,Ks(this.Qo.syncEngine)];case 4:return e.sent(),[4,Oo(this.Qo.remoteStore)];case 5:return e.sent(),[4,this.persistence.He(function(){return r.gcScheduler&&!r.gcScheduler.started&&r.gcScheduler.start(r.localStore),Promise.resolve()})];case 6:return e.sent(),[2]}})})},n.prototype.Ko=function(t){return bi(this.persistence,new _i,t.initialUser,this.R)},n.prototype.Uo=function(t){var e=this.persistence.referenceDelegate.garbageCollector;return new Jr(e,t.asyncQueue)},n.prototype.qo=function(t){var e=yi(t.databaseInfo.databaseId,t.databaseInfo.persistenceKey),n=void 0!==this.cacheSizeBytes?Fr.withCacheSize(this.cacheSizeBytes):Fr.DEFAULT;return new li(this.synchronizeTabs,e,t.clientId,n,t.asyncQueue,uo(),co(),this.R,this.sharedClientState,!!this.forceOwnership)},n.prototype.Bo=function(t){return new no},n}(Qs),Ws=function(t){function n(e,n){var r=this;return(r=t.call(this,e,n,!1)||this).Qo=e,r.cacheSizeBytes=n,r.synchronizeTabs=!0,r}return(0,e.__extends)(n,t),n.prototype.initialize=function(n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i=this;return(0,e.__generator)(this,function(o){switch(o.label){case 0:return[4,t.prototype.initialize.call(this,n)];case 1:return o.sent(),r=this.Qo.syncEngine,this.sharedClientState instanceof eo?(this.sharedClientState.syncEngine={ui:Ps.bind(null,r),ai:Us.bind(null,r),hi:Bs.bind(null,r),fn:qs.bind(null,r),ci:Os.bind(null,r)},[4,this.sharedClientState.start()]):[3,3];case 2:o.sent(),o.label=3;case 3:return[4,this.persistence.He(function(t){return(0,e.__awaiter)(i,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,Fs(this.Qo.syncEngine,t)];case 1:return e.sent(),this.gcScheduler&&(t&&!this.gcScheduler.started?this.gcScheduler.start(this.localStore):t||this.gcScheduler.stop()),[2]}})})})];case 4:return o.sent(),[2]}})})},n.prototype.Bo=function(t){var e=uo();if(!eo.yt(e))throw new u(a.UNIMPLEMENTED,"IndexedDB persistence is only available on platforms that support LocalStorage.");var n=yi(t.databaseInfo.databaseId,t.databaseInfo.persistenceKey);return new eo(e,t.asyncQueue,n,t.clientId,t.initialUser)},n}(zs),Hs=function(){function t(){}return t.prototype.initialize=function(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r=this;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return this.localStore?[3,2]:(this.localStore=t.localStore,this.sharedClientState=t.sharedClientState,this.datastore=this.createDatastore(n),this.remoteStore=this.createRemoteStore(n),this.eventManager=this.createEventManager(n),this.syncEngine=this.createSyncEngine(n,!t.synchronizeTabs),this.sharedClientState.onlineStateHandler=function(t){return gs(r.syncEngine,t,1)},this.remoteStore.remoteSyncer.handleCredentialChange=Cs.bind(null,this.syncEngine),[4,Bo(this.remoteStore,this.syncEngine.isPrimaryClient)]);case 1:e.sent(),e.label=2;case 2:return[2]}})})},t.prototype.createEventManager=function(t){return new $o},t.prototype.createDatastore=function(t){var e,n=ho(t.databaseInfo.databaseId),r=(e=t.databaseInfo,new ao(e));return function(t,e,n){return new vo(t,r,n)}(t.credentials,0,n)},t.prototype.createRemoteStore=function(t){var e,n,r,i,o,s=this;return e=this.localStore,n=this.datastore,r=t.asyncQueue,i=function(t){return gs(s.syncEngine,t,0)},o=io.yt()?new io:new ro,new go(e,n,r,i,o)},t.prototype.createSyncEngine=function(t,e){return function(t,e,n,r,i,o,s){var a=new ls(t,e,n,r,i,o);return s&&(a.$o=!0),a}(this.localStore,this.remoteStore,this.eventManager,this.sharedClientState,t.initialUser,t.maxConcurrentLimboResolutions,e)},t.prototype.terminate=function(){return function(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return n=m(t),f("RemoteStore","RemoteStore shutting down."),n.Or.add(5),[4,wo(n)];case 1:return e.sent(),n.Lr.shutdown(),n.Br.set("Unknown"),[2]}})})}(this.remoteStore)},t}();function Ys(t,n){void 0===n&&(n=10240);var r=0;return{read:function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var i;return(0,e.__generator)(this,function(e){return r<t.byteLength?(i={value:t.slice(r,r+n),done:!1},[2,(r+=n,i)]):[2,{done:!0}]})})},cancel:function(){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(t){return[2]})})},releaseLock:function(){},closed:Promise.reject("unimplemented")}}var $s=function(){function t(t){this.observer=t,this.muted=!1}return t.prototype.next=function(t){this.observer.next&&this.jo(this.observer.next,t)},t.prototype.error=function(t){this.observer.error?this.jo(this.observer.error,t):console.error("Uncaught Error in snapshot listener:",t)},t.prototype.Wo=function(){this.muted=!0},t.prototype.jo=function(t,e){var n=this;this.muted||setTimeout(function(){n.muted||t(e)},0)},t}(),Xs=function(){function t(t,e){var n=this;this.Go=t,this.R=e,this.metadata=new er,this.buffer=new Uint8Array,this.zo=new TextDecoder("utf-8"),this.Ho().then(function(t){t&&t.io()?n.metadata.resolve(t.payload.metadata):n.metadata.reject(new Error("The first element of the bundle is not a metadata, it is\n "+JSON.stringify(null==t?void 0:t.payload)))},function(t){return n.metadata.reject(t)})}return t.prototype.close=function(){return this.Go.cancel()},t.prototype.getMetadata=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(t){return[2,this.metadata.promise]})})},t.prototype.Lo=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(t){switch(t.label){case 0:return[4,this.getMetadata()];case 1:return[2,(t.sent(),this.Ho())]}})})},t.prototype.Ho=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var t,n,r,i;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,this.Jo()];case 1:return null===(t=e.sent())?[2,null]:(n=this.zo.decode(t),r=Number(n),isNaN(r)&&this.Yo("length string ("+n+") is not valid number"),[4,this.Xo(r)]);case 2:return i=e.sent(),[2,new rs(JSON.parse(i),t.length+r)]}})})},t.prototype.Zo=function(){return this.buffer.findIndex(function(t){return t==="{".charCodeAt(0)})},t.prototype.Jo=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var t,n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return this.Zo()<0?[4,this.tc()]:[3,3];case 1:if(e.sent())return[3,3];e.label=2;case 2:return[3,0];case 3:return 0===this.buffer.length?[2,null]:((t=this.Zo())<0&&this.Yo("Reached the end of bundle when a length string is expected."),n=this.buffer.slice(0,t),[2,(this.buffer=this.buffer.slice(t),n)])}})})},t.prototype.Xo=function(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return this.buffer.length<t?[4,this.tc()]:[3,3];case 1:e.sent()&&this.Yo("Reached the end of bundle when more is expected."),e.label=2;case 2:return[3,0];case 3:return n=this.zo.decode(this.buffer.slice(0,t)),[2,(this.buffer=this.buffer.slice(t),n)]}})})},t.prototype.Yo=function(t){throw this.Go.cancel(),new Error("Invalid bundle format: "+t)},t.prototype.tc=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var t,n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,this.Go.read()];case 1:return(t=e.sent()).done||((n=new Uint8Array(this.buffer.length+t.value.length)).set(this.buffer),n.set(t.value,this.buffer.length),this.buffer=n),[2,t.done]}})})},t}(),Js=function(){function t(t){this.datastore=t,this.readVersions=new Map,this.mutations=[],this.committed=!1,this.lastWriteError=null,this.writtenDocs=new Set}return t.prototype.lookup=function(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n,r=this;return(0,e.__generator)(this,function(i){switch(i.label){case 0:if(this.ensureCommitNotCalled(),this.mutations.length>0)throw new u(a.INVALID_ARGUMENT,"Firestore transactions require all reads to be executed before all writes.");return[4,function(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o,s,a,u;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return r=m(t),i=ln(r.R)+"/documents",o={documents:n.map(function(t){return un(r.R,t)})},[4,r.$i("BatchGetDocuments",i,o)];case 1:return s=e.sent(),a=new Map,s.forEach(function(t){var e=function(t,e){return"found"in e?function(t,e){v(!!e.found),e.found.name,e.found.updateTime;var n=cn(t,e.found.name),r=on(e.found.updateTime),i=new ot({mapValue:{fields:e.found.fields}});return at.newFoundDocument(n,r,i)}(t,e):"missing"in e?function(t,e){v(!!e.missing),v(!!e.readTime);var n=cn(t,e.missing),r=on(e.readTime);return at.newNoDocument(n,r)}(t,e):y()}(r.R,t);a.set(e.key.toString(),e)}),u=[],[2,(n.forEach(function(t){var e=a.get(t.toString());v(!!e),u.push(e)}),u)]}})})}(this.datastore,t)];case 1:return[2,((n=i.sent()).forEach(function(t){return r.recordVersion(t)}),n)]}})})},t.prototype.set=function(t,e){this.write(e.toMutation(t,this.precondition(t))),this.writtenDocs.add(t.toString())},t.prototype.update=function(t,e){try{this.write(e.toMutation(t,this.preconditionForUpdate(t)))}catch(t){this.lastWriteError=t}this.writtenDocs.add(t.toString())},t.prototype.delete=function(t){this.write(new Ee(t,this.precondition(t))),this.writtenDocs.add(t.toString())},t.prototype.commit=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var t,n=this;return(0,e.__generator)(this,function(r){switch(r.label){case 0:if(this.ensureCommitNotCalled(),this.lastWriteError)throw this.lastWriteError;return t=this.readVersions,this.mutations.forEach(function(e){t.delete(e.key.toString())}),t.forEach(function(t,e){var r=G.fromPath(e);n.mutations.push(new Te(r,n.precondition(r)))}),[4,function(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return r=m(t),i=ln(r.R)+"/documents",o={writes:n.map(function(t){return vn(r.R,t)})},[4,r.Ni("Commit",i,o)];case 1:return e.sent(),[2]}})})}(this.datastore,this.mutations)];case 1:return r.sent(),this.committed=!0,[2]}})})},t.prototype.recordVersion=function(t){var e;if(t.isFoundDocument())e=t.version;else{if(!t.isNoDocument())throw y();e=T.min()}var n=this.readVersions.get(t.key.toString());if(n){if(!e.isEqual(n))throw new u(a.ABORTED,"Document version changed between two reads.")}else this.readVersions.set(t.key.toString(),e)},t.prototype.precondition=function(t){var e=this.readVersions.get(t.toString());return!this.writtenDocs.has(t.toString())&&e?ue.updateTime(e):ue.none()},t.prototype.preconditionForUpdate=function(t){var e=this.readVersions.get(t.toString());if(!this.writtenDocs.has(t.toString())&&e){if(e.isEqual(T.min()))throw new u(a.INVALID_ARGUMENT,"Can't update a document that doesn't exist.");return ue.updateTime(e)}return ue.exists(!0)},t.prototype.write=function(t){this.ensureCommitNotCalled(),this.mutations.push(t)},t.prototype.ensureCommitNotCalled=function(){},t}(),Zs=function(){function t(t,e,n,r){this.asyncQueue=t,this.datastore=e,this.updateFunction=n,this.deferred=r,this.ec=5,this.Zi=new fo(this.asyncQueue,"transaction_retry")}return t.prototype.run=function(){this.ec-=1,this.nc()},t.prototype.nc=function(){var t=this;this.Zi.ji(function(){return(0,e.__awaiter)(t,void 0,void 0,function(){var t,n,r=this;return(0,e.__generator)(this,function(e){return t=new Js(this.datastore),(n=this.sc(t))&&n.then(function(e){r.asyncQueue.enqueueAndForget(function(){return t.commit().then(function(){r.deferred.resolve(e)}).catch(function(t){r.ic(t)})})}).catch(function(t){r.ic(t)}),[2]})})})},t.prototype.sc=function(t){try{var e=this.updateFunction(t);return!B(e)&&e.catch&&e.then?e:(this.deferred.reject(Error("Transaction callback must return a Promise")),null)}catch(t){return this.deferred.reject(t),null}},t.prototype.ic=function(t){var e=this;this.ec>0&&this.rc(t)?(this.ec-=1,this.asyncQueue.enqueueAndForget(function(){return e.nc(),Promise.resolve()})):this.deferred.reject(t)},t.prototype.rc=function(t){if("FirebaseError"===t.name){var e=t.code;return"aborted"===e||"failed-precondition"===e||!Ne(e)}return!1},t}(),ta=function(){function t(t,n,r){var i=this;this.credentials=t,this.asyncQueue=n,this.databaseInfo=r,this.user=zi.UNAUTHENTICATED,this.clientId=_.u(),this.credentialListener=function(){return Promise.resolve()},this.credentials.setChangeListener(n,function(t){return(0,e.__awaiter)(i,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return f("FirestoreClient","Received user=",t.uid),[4,this.credentialListener(t)];case 1:return e.sent(),this.user=t,[2]}})})})}return t.prototype.getConfiguration=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(t){return[2,{asyncQueue:this.asyncQueue,databaseInfo:this.databaseInfo,clientId:this.clientId,credentials:this.credentials,initialUser:this.user,maxConcurrentLimboResolutions:100}]})})},t.prototype.setCredentialChangeListener=function(t){this.credentialListener=t},t.prototype.verifyNotTerminated=function(){if(this.asyncQueue.isShuttingDown)throw new u(a.FAILED_PRECONDITION,"The client has already been terminated.")},t.prototype.terminate=function(){var t=this;this.asyncQueue.enterRestrictedMode();var n=new er;return this.asyncQueue.enqueueAndForgetEvenWhileRestricted(function(){return(0,e.__awaiter)(t,void 0,void 0,function(){var t,r;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return e.trys.push([0,5,,6]),this.onlineComponents?[4,this.onlineComponents.terminate()]:[3,2];case 1:e.sent(),e.label=2;case 2:return this.offlineComponents?[4,this.offlineComponents.terminate()]:[3,4];case 3:e.sent(),e.label=4;case 4:return this.credentials.removeChangeListener(),n.resolve(),[3,6];case 5:return t=e.sent(),r=Qo(t,"Failed to shutdown persistence"),n.reject(r),[3,6];case 6:return[2]}})})}),n.promise},t}();function ea(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i,o=this;return(0,e.__generator)(this,function(s){switch(s.label){case 0:return t.asyncQueue.verifyOperationInProgress(),f("FirestoreClient","Initializing OfflineComponentProvider"),[4,t.getConfiguration()];case 1:return r=s.sent(),[4,n.initialize(r)];case 2:return s.sent(),i=r.initialUser,t.setCredentialChangeListener(function(t){return(0,e.__awaiter)(o,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return i.isEqual(t)?[3,2]:[4,Ii(n.localStore,t)];case 1:e.sent(),i=t,e.label=2;case 2:return[2]}})})}),n.persistence.setDatabaseDeletedListener(function(){return t.terminate()}),t.offlineComponents=n,[2]}})})}function na(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i;return(0,e.__generator)(this,function(o){switch(o.label){case 0:return t.asyncQueue.verifyOperationInProgress(),[4,ra(t)];case 1:return r=o.sent(),f("FirestoreClient","Initializing OnlineComponentProvider"),[4,t.getConfiguration()];case 2:return i=o.sent(),[4,n.initialize(r,i)];case 3:return o.sent(),t.setCredentialChangeListener(function(t){return function(t,n){return(0,e.__awaiter)(this,void 0,void 0,function(){var r,i;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return(r=m(t)).asyncQueue.verifyOperationInProgress(),f("RemoteStore","RemoteStore received new credentials"),i=Do(r),r.Or.add(3),[4,wo(r)];case 1:return e.sent(),i&&r.Br.set("Unknown"),[4,r.remoteSyncer.handleCredentialChange(n)];case 2:return e.sent(),r.Or.delete(3),[4,_o(r)];case 3:return e.sent(),[2]}})})}(n.remoteStore,t)}),t.onlineComponents=n,[2]}})})}function ra(t){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return t.offlineComponents?[3,2]:(f("FirestoreClient","Using default OfflineComponentProvider"),[4,ea(t,new Qs)]);case 1:e.sent(),e.label=2;case 2:return[2,t.offlineComponents]}})})}function ia(t){return(0,e.__awaiter)(this,void 0,void 0,function(){return(0,e.__generator)(this,function(e){switch(e.label){case 0:return t.onlineComponents?[3,2]:(f("FirestoreClient","Using default OnlineComponentProvider"),[4,na(t,new Hs)]);case 1:e.sent(),e.label=2;case 2:return[2,t.onlineComponents]}})})}function oa(t){return ra(t).then(function(t){return t.persistence})}function sa(t){return ra(t).then(function(t){return t.localStore})}function aa(t){return ia(t).then(function(t){return t.remoteStore})}function ua(t){return ia(t).then(function(t){return t.syncEngine})}function ca(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n,r;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,ia(t)];case 1:return n=e.sent(),[2,((r=n.eventManager).onListen=ds.bind(null,n.syncEngine),r.onUnlisten=ys.bind(null,n.syncEngine),r)]}})})}function ha(t,n,r){var i=this;void 0===r&&(r={});var o=new er;return t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(i,void 0,void 0,function(){var i;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return i=function(t,e,n,r,i){var o=new $s({next:function(o){e.enqueueAndForget(function(){return Jo(t,s)});var c=o.docs.has(n);!c&&o.fromCache?i.reject(new u(a.UNAVAILABLE,"Failed to get document because the client is offline.")):c&&o.fromCache&&r&&"server"===r.source?i.reject(new u(a.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.)')):i.resolve(o)},error:function(t){return i.reject(t)}}),s=new ns(kt(n.path),o,{includeMetadataChanges:!0,so:!0});return Xo(t,s)},[4,ca(t)];case 1:return[2,i.apply(void 0,[e.sent(),t.asyncQueue,n,r,o])]}})})}),o.promise}function fa(t,n,r){var i=this;void 0===r&&(r={});var o=new er;return t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(i,void 0,void 0,function(){var i;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return i=function(t,e,n,r,i){var o=new $s({next:function(n){e.enqueueAndForget(function(){return Jo(t,s)}),n.fromCache&&"server"===r.source?i.reject(new u(a.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.)')):i.resolve(n)},error:function(t){return i.reject(t)}}),s=new ns(n,o,{includeMetadataChanges:!0,so:!0});return Xo(t,s)},[4,ca(t)];case 1:return[2,i.apply(void 0,[e.sent(),t.asyncQueue,n,r,o])]}})})}),o.promise}var la=function(t,e,n,r,i,o,s,a){this.databaseId=t,this.appId=e,this.persistenceKey=n,this.host=r,this.ssl=i,this.forceLongPolling=o,this.autoDetectLongPolling=s,this.useFetchStreams=a},da=function(){function t(t,e){this.projectId=t,this.database=e||"(default)"}return Object.defineProperty(t.prototype,"isDefaultDatabase",{get:function(){return"(default)"===this.database},enumerable:!1,configurable:!0}),t.prototype.isEqual=function(e){return e instanceof t&&e.projectId===this.projectId&&e.database===this.database},t}(),pa=new Map,ya=function(t,e){this.user=e,this.type="OAuth",this.authHeaders={},this.authHeaders.Authorization="Bearer "+t},va=function(){function t(){this.changeListener=null}return t.prototype.getToken=function(){return Promise.resolve(null)},t.prototype.invalidateToken=function(){},t.prototype.setChangeListener=function(t,e){this.changeListener=e,t.enqueueRetryable(function(){return e(zi.UNAUTHENTICATED)})},t.prototype.removeChangeListener=function(){this.changeListener=null},t}(),ma=function(){function t(t){this.token=t,this.changeListener=null}return t.prototype.getToken=function(){return Promise.resolve(this.token)},t.prototype.invalidateToken=function(){},t.prototype.setChangeListener=function(t,e){var n=this;this.changeListener=e,t.enqueueRetryable(function(){return e(n.token.user)})},t.prototype.removeChangeListener=function(){this.changeListener=null},t}(),ga=function(){function t(t){var e=this;this.currentUser=zi.UNAUTHENTICATED,this.oc=new er,this.cc=0,this.forceRefresh=!1,this.auth=null,this.asyncQueue=null,this.uc=function(){e.cc++,e.currentUser=e.ac(),e.oc.resolve(),e.changeListener&&e.asyncQueue.enqueueRetryable(function(){return e.changeListener(e.currentUser)})};var n=function(t){f("FirebaseCredentialsProvider","Auth detected"),e.auth=t,e.auth.addAuthTokenListener(e.uc)};t.onInit(function(t){return n(t)}),setTimeout(function(){if(!e.auth){var r=t.getImmediate({optional:!0});r?n(r):(f("FirebaseCredentialsProvider","Auth not yet detected"),e.oc.resolve())}},0)}return t.prototype.getToken=function(){var t=this,e=this.cc,n=this.forceRefresh;return this.forceRefresh=!1,this.auth?this.auth.getToken(n).then(function(n){return t.cc!==e?(f("FirebaseCredentialsProvider","getToken aborted due to token change."),t.getToken()):n?(v("string"==typeof n.accessToken),new ya(n.accessToken,t.currentUser)):null}):Promise.resolve(null)},t.prototype.invalidateToken=function(){this.forceRefresh=!0},t.prototype.setChangeListener=function(t,n){var r=this;this.asyncQueue=t,this.asyncQueue.enqueueRetryable(function(){return(0,e.__awaiter)(r,void 0,void 0,function(){return(0,e.__generator)(this,function(t){switch(t.label){case 0:return[4,this.oc.promise];case 1:return t.sent(),[4,n(this.currentUser)];case 2:return t.sent(),this.changeListener=n,[2]}})})})},t.prototype.removeChangeListener=function(){this.auth&&this.auth.removeAuthTokenListener(this.uc),this.changeListener=function(){return Promise.resolve()}},t.prototype.ac=function(){var t=this.auth&&this.auth.getUid();return v(null===t||"string"==typeof t),new zi(t)},t}(),_a=function(){function t(t,e,n){this.hc=t,this.lc=e,this.fc=n,this.type="FirstParty",this.user=zi.FIRST_PARTY}return Object.defineProperty(t.prototype,"authHeaders",{get:function(){var t={"X-Goog-AuthUser":this.lc},e=this.hc.auth.getAuthHeaderValueForFirstParty([]);return e&&(t.Authorization=e),this.fc&&(t["X-Goog-Iam-Authorization-Token"]=this.fc),t},enumerable:!1,configurable:!0}),t}(),wa=function(){function t(t,e,n){this.hc=t,this.lc=e,this.fc=n}return t.prototype.getToken=function(){return Promise.resolve(new _a(this.hc,this.lc,this.fc))},t.prototype.setChangeListener=function(t,e){t.enqueueRetryable(function(){return e(zi.FIRST_PARTY)})},t.prototype.removeChangeListener=function(){},t.prototype.invalidateToken=function(){},t}();function ba(t,e,n){if(!n)throw new u(a.INVALID_ARGUMENT,"Function "+t+"() cannot be called with an empty "+e+".")}function Ia(t,e){if(void 0===e)return{merge:!1};if(void 0!==e.mergeFields&&void 0!==e.merge)throw new u(a.INVALID_ARGUMENT,"Invalid options passed to function "+t+'(): You cannot specify both "merge" and "mergeFields".');return e}function Ea(t,e,n,r){if(!0===e&&!0===r)throw new u(a.INVALID_ARGUMENT,t+" and "+n+" cannot be used together.")}function Ta(t){if(!G.isDocumentKey(t))throw new u(a.INVALID_ARGUMENT,"Invalid document reference. Document references must have an even number of segments, but "+t+" has "+t.length+".")}function Sa(t){if(G.isDocumentKey(t))throw new u(a.INVALID_ARGUMENT,"Invalid collection reference. Collection references must have an odd number of segments, but "+t+" has "+t.length+".")}function Na(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"==o(t)){if(t instanceof Array)return"an array";var e=function(t){if(t.constructor){var e=/function\s+([^\s(]+)\s*\(/.exec(t.constructor.toString());if(e&&e.length>1)return e[1]}return null}(t);return e?"a custom "+e+" object":"an object"}return"function"==typeof t?"a function":y()}function Da(t,e){if("_delegate"in t&&(t=t._delegate),!(t instanceof e)){if(e.name===t.constructor.name)throw new u(a.INVALID_ARGUMENT,"Type does not match the expected instance. Did you pass a reference from a different Firestore SDK?");var n=Na(t);throw new u(a.INVALID_ARGUMENT,"Expected type '"+e.name+"', but it was: "+n)}return t}function Aa(t,e){if(e<=0)throw new u(a.INVALID_ARGUMENT,"Function "+t+"() requires a positive number, but it was: "+e+".")}var xa=function(){function t(t){var e;if(void 0===t.host){if(void 0!==t.ssl)throw new u(a.INVALID_ARGUMENT,"Can't provide ssl option if host option is not set");this.host="firestore.googleapis.com",this.ssl=!0}else this.host=t.host,this.ssl=null===(e=t.ssl)||void 0===e||e;if(this.credentials=t.credentials,this.ignoreUndefinedProperties=!!t.ignoreUndefinedProperties,void 0===t.cacheSizeBytes)this.cacheSizeBytes=41943040;else{if(-1!==t.cacheSizeBytes&&t.cacheSizeBytes<1048576)throw new u(a.INVALID_ARGUMENT,"cacheSizeBytes must be at least 1048576");this.cacheSizeBytes=t.cacheSizeBytes}this.experimentalForceLongPolling=!!t.experimentalForceLongPolling,this.experimentalAutoDetectLongPolling=!!t.experimentalAutoDetectLongPolling,this.useFetchStreams=!!t.useFetchStreams,Ea("experimentalForceLongPolling",t.experimentalForceLongPolling,"experimentalAutoDetectLongPolling",t.experimentalAutoDetectLongPolling)}return t.prototype.isEqual=function(t){return this.host===t.host&&this.ssl===t.ssl&&this.credentials===t.credentials&&this.cacheSizeBytes===t.cacheSizeBytes&&this.experimentalForceLongPolling===t.experimentalForceLongPolling&&this.experimentalAutoDetectLongPolling===t.experimentalAutoDetectLongPolling&&this.ignoreUndefinedProperties===t.ignoreUndefinedProperties&&this.useFetchStreams===t.useFetchStreams},t}(),ka=function(){function t(t,e){this.type="firestore-lite",this._persistenceKey="(lite)",this._settings=new xa({}),this._settingsFrozen=!1,t instanceof da?(this._databaseId=t,this._credentials=new va):(this._app=t,this._databaseId=function(t){if(!Object.prototype.hasOwnProperty.apply(t.options,["projectId"]))throw new u(a.INVALID_ARGUMENT,'"projectId" not provided in firebase.initializeApp.');return new da(t.options.projectId)}(t),this._credentials=new ga(e))}return Object.defineProperty(t.prototype,"app",{get:function(){if(!this._app)throw new u(a.FAILED_PRECONDITION,"Firestore was not initialized using the Firebase SDK. 'app' is not available");return this._app},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"_initialized",{get:function(){return this._settingsFrozen},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"_terminated",{get:function(){return void 0!==this._terminateTask},enumerable:!1,configurable:!0}),t.prototype._setSettings=function(t){if(this._settingsFrozen)throw new u(a.FAILED_PRECONDITION,"Firestore has already been started and its settings can no longer be changed. You can only modify settings before calling any other methods on a Firestore object.");this._settings=new xa(t),void 0!==t.credentials&&(this._credentials=function(t){if(!t)return new va;switch(t.type){case"gapi":var e=t.client;return v(!("object"!=o(e)||null===e||!e.auth||!e.auth.getAuthHeaderValueForFirstParty)),new wa(e,t.sessionIndex||"0",t.iamToken||null);case"provider":return t.client;default:throw new u(a.INVALID_ARGUMENT,"makeCredentialsProvider failed due to invalid credential type")}}(t.credentials))},t.prototype._getSettings=function(){return this._settings},t.prototype._freezeSettings=function(){return this._settingsFrozen=!0,this._settings},t.prototype._delete=function(){return this._terminateTask||(this._terminateTask=this._terminate()),this._terminateTask},t.prototype.toJSON=function(){return{app:this._app,databaseId:this._databaseId,settings:this._settings}},t.prototype._terminate=function(){return this,(t=pa.get(this))&&(f("ComponentProvider","Removing Datastore"),pa.delete(this),t.terminate()),Promise.resolve();var t},t}(),Ca=function(){function t(t,e,n){this.converter=e,this._key=n,this.type="document",this.firestore=t}return Object.defineProperty(t.prototype,"_path",{get:function(){return this._key.path},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"id",{get:function(){return this._key.path.lastSegment()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"path",{get:function(){return this._key.path.canonicalString()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"parent",{get:function(){return new La(this.firestore,this.converter,this._key.path.popLast())},enumerable:!1,configurable:!0}),t.prototype.withConverter=function(e){return new t(this.firestore,e,this._key)},t}(),Ra=function(){function t(t,e,n){this.converter=e,this._query=n,this.type="query",this.firestore=t}return t.prototype.withConverter=function(e){return new t(this.firestore,e,this._query)},t}(),La=function(t){function n(e,n,r){var i=this;return(i=t.call(this,e,n,kt(r))||this)._path=r,i.type="collection",i}return(0,e.__extends)(n,t),Object.defineProperty(n.prototype,"id",{get:function(){return this._query.path.lastSegment()},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"path",{get:function(){return this._query.path.canonicalString()},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"parent",{get:function(){var t=this._path.popLast();return t.isEmpty()?null:new Ca(this.firestore,null,new G(t))},enumerable:!1,configurable:!0}),n.prototype.withConverter=function(t){return new n(this.firestore,t,this._path)},n}(Ra);function Oa(t,r){for(var i,o=[],s=2;s<arguments.length;s++)o[s-2]=arguments[s];if(t=(0,n.getModularInstance)(t),ba("collection","path",r),t instanceof ka)return Sa(i=x.fromString.apply(x,(0,e.__spreadArray)([r],o))),new La(t,null,i);if(!(t instanceof Ca||t instanceof La))throw new u(a.INVALID_ARGUMENT,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");return Sa(i=x.fromString.apply(x,(0,e.__spreadArray)([t.path],o)).child(x.fromString(r))),new La(t.firestore,null,i)}function Pa(t,r){for(var i,o=[],s=2;s<arguments.length;s++)o[s-2]=arguments[s];if(t=(0,n.getModularInstance)(t),1===arguments.length&&(r=_.u()),ba("doc","path",r),t instanceof ka)return Ta(i=x.fromString.apply(x,(0,e.__spreadArray)([r],o))),new Ca(t,null,new G(i));if(!(t instanceof Ca||t instanceof La))throw new u(a.INVALID_ARGUMENT,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");return Ta(i=t._path.child(x.fromString.apply(x,(0,e.__spreadArray)([r],o)))),new Ca(t.firestore,t instanceof La?t.converter:null,new G(i))}function Fa(t,e){return t=(0,n.getModularInstance)(t),e=(0,n.getModularInstance)(e),(t instanceof Ca||t instanceof La)&&(e instanceof Ca||e instanceof La)&&t.firestore===e.firestore&&t.path===e.path&&t.converter===e.converter}function Ma(t,e){return t=(0,n.getModularInstance)(t),e=(0,n.getModularInstance)(e),t instanceof Ra&&e instanceof Ra&&t.firestore===e.firestore&&qt(t._query,e._query)&&t.converter===e.converter}var Va=function(){function t(){var t=this;this.dc=Promise.resolve(),this.wc=[],this._c=!1,this.mc=[],this.yc=null,this.gc=!1,this.Ec=!1,this.Tc=[],this.Zi=new fo(this,"async_queue_retry"),this.Ic=function(){var e=co();e&&f("AsyncQueue","Visibility state changed to "+e.visibilityState),t.Zi.Gi()};var e=co();e&&"function"==typeof e.addEventListener&&e.addEventListener("visibilitychange",this.Ic)}return Object.defineProperty(t.prototype,"isShuttingDown",{get:function(){return this._c},enumerable:!1,configurable:!0}),t.prototype.enqueueAndForget=function(t){this.enqueue(t)},t.prototype.enqueueAndForgetEvenWhileRestricted=function(t){this.Ac(),this.Rc(t)},t.prototype.enterRestrictedMode=function(t){if(!this._c){this._c=!0,this.Ec=t||!1;var e=co();e&&"function"==typeof e.removeEventListener&&e.removeEventListener("visibilitychange",this.Ic)}},t.prototype.enqueue=function(t){var e=this;if(this.Ac(),this._c)return new Promise(function(){});var n=new er;return this.Rc(function(){return e._c&&e.Ec?Promise.resolve():(t().then(n.resolve,n.reject),n.promise)}).then(function(){return n.promise})},t.prototype.enqueueRetryable=function(t){var e=this;this.enqueueAndForget(function(){return e.wc.push(t),e.bc()})},t.prototype.bc=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var t,n=this;return(0,e.__generator)(this,function(e){switch(e.label){case 0:if(0===this.wc.length)return[3,5];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.wc[0]()];case 2:return e.sent(),this.wc.shift(),this.Zi.reset(),[3,4];case 3:if(!ar(t=e.sent()))throw t;return f("AsyncQueue","Operation failed with retryable error: "+t),[3,4];case 4:this.wc.length>0&&this.Zi.ji(function(){return n.bc()}),e.label=5;case 5:return[2]}})})},t.prototype.Rc=function(t){var e=this,n=this.dc.then(function(){return e.gc=!0,t().catch(function(t){throw e.yc=t,e.gc=!1,l("INTERNAL UNHANDLED ERROR: ",function(t){var e=t.message||"";return t.stack&&(e=t.stack.includes(t.message)?t.stack:t.message+"\n"+t.stack),e}(t)),t}).then(function(t){return e.gc=!1,t})});return this.dc=n,n},t.prototype.enqueueAfterDelay=function(t,e,n){var r=this;this.Ac(),this.Tc.indexOf(t)>-1&&(e=0);var i=Go.createAndSchedule(this,t,e,n,function(t){return r.vc(t)});return this.mc.push(i),i},t.prototype.Ac=function(){this.yc&&y()},t.prototype.verifyOperationInProgress=function(){},t.prototype.Pc=function(){return(0,e.__awaiter)(this,void 0,void 0,function(){var t;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,t=this.dc];case 1:e.sent(),e.label=2;case 2:if(t!==this.dc)return[3,0];e.label=3;case 3:return[2]}})})},t.prototype.Vc=function(t){for(var e=0,n=this.mc;e<n.length;e++)if(n[e].timerId===t)return!0;return!1},t.prototype.Sc=function(t){var e=this;return this.Pc().then(function(){e.mc.sort(function(t,e){return t.targetTimeMs-e.targetTimeMs});for(var n=0,r=e.mc;n<r.length;n++){var i=r[n];if(i.skipDelay(),"all"!==t&&i.timerId===t)break}return e.Pc()})},t.prototype.Dc=function(t){this.Tc.push(t)},t.prototype.vc=function(t){var e=this.mc.indexOf(t);this.mc.splice(e,1)},t}();function qa(t){return function(t,e){if("object"!=o(t)||null===t)return!1;for(var n=t,r=0,i=["next","error","complete"];r<i.length;r++){var s=i[r];if(s in n&&"function"==typeof n[s])return!0}return!1}(t)}var Ua=function(){function t(){this._progressObserver={},this._taskCompletionResolver=new er,this._lastProgress={taskState:"Running",totalBytes:0,totalDocuments:0,bytesLoaded:0,documentsLoaded:0}}return t.prototype.onProgress=function(t,e,n){this._progressObserver={next:t,error:e,complete:n}},t.prototype.catch=function(t){return this._taskCompletionResolver.promise.catch(t)},t.prototype.then=function(t,e){return this._taskCompletionResolver.promise.then(t,e)},t.prototype._completeWith=function(t){this._updateProgress(t),this._progressObserver.complete&&this._progressObserver.complete(),this._taskCompletionResolver.resolve(t)},t.prototype._failWith=function(t){this._lastProgress.taskState="Error",this._progressObserver.next&&this._progressObserver.next(this._lastProgress),this._progressObserver.error&&this._progressObserver.error(t),this._taskCompletionResolver.reject(t)},t.prototype._updateProgress=function(t){this._lastProgress=t,this._progressObserver.next&&this._progressObserver.next(t)},t}(),Ba=-1,ja=function(t){function n(e,n){var r=this;return(r=t.call(this,e,n)||this).type="firestore",r._queue=new Va,r._persistenceKey="name"in e?e.name:"[DEFAULT]",r}return(0,e.__extends)(n,t),n.prototype._terminate=function(){return this._firestoreClient||Ga(this),this._firestoreClient.terminate()},n}(ka);function Ka(t){return t._firestoreClient||Ga(t),t._firestoreClient.verifyNotTerminated(),t._firestoreClient}function Ga(t){var e,n=t._freezeSettings(),r=function(t,e,n,r){return new la(t,e,n,r.host,r.ssl,r.experimentalForceLongPolling,r.experimentalAutoDetectLongPolling,r.useFetchStreams)}(t._databaseId,(null===(e=t._app)||void 0===e?void 0:e.options.appId)||"",t._persistenceKey,n);t._firestoreClient=new ta(t._credentials,t._queue,r)}function Qa(t,n,r){var i=this,o=new er;return t.asyncQueue.enqueue(function(){return(0,e.__awaiter)(i,void 0,void 0,function(){var i;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return e.trys.push([0,3,,4]),[4,ea(t,r)];case 1:return e.sent(),[4,na(t,n)];case 2:return e.sent(),o.resolve(),[3,4];case 3:if(!function(t){return"FirebaseError"===t.name?t.code===a.FAILED_PRECONDITION||t.code===a.UNIMPLEMENTED:!("undefined"!=typeof DOMException&&t instanceof DOMException)||22===t.code||20===t.code||11===t.code}(i=e.sent()))throw i;return console.warn("Error enabling offline persistence. Falling back to persistence disabled: "+i),o.reject(i),[3,4];case 4:return[2]}})})}).then(function(){return o.promise})}function za(t){if(t._initialized||t._terminated)throw new u(a.FAILED_PRECONDITION,"Firestore has already been started and persistence can no longer be enabled. You can only enable persistence before calling any other methods on a Firestore object.")}exports.T=ja,exports.E=Ba;var Wa=function(){function t(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];for(var n=0;n<t.length;++n)if(0===t[n].length)throw new u(a.INVALID_ARGUMENT,"Invalid field name at argument $(i + 1). Field names must not be empty.");this._internalPath=new C(t)}return t.prototype.isEqual=function(t){return this._internalPath.isEqual(t._internalPath)},t}(),Ha=function(){function t(t){this._byteString=t}return t.fromBase64String=function(e){try{return new t(L.fromBase64String(e))}catch(e){throw new u(a.INVALID_ARGUMENT,"Failed to construct data from Base64 string: "+e)}},t.fromUint8Array=function(e){return new t(L.fromUint8Array(e))},t.prototype.toBase64=function(){return this._byteString.toBase64()},t.prototype.toUint8Array=function(){return this._byteString.toUint8Array()},t.prototype.toString=function(){return"Bytes(base64: "+this.toBase64()+")"},t.prototype.isEqual=function(t){return this._byteString.isEqual(t._byteString)},t}(),Ya=function(t){this._methodName=t},$a=function(){function t(t,e){if(!isFinite(t)||t<-90||t>90)throw new u(a.INVALID_ARGUMENT,"Latitude must be a number between -90 and 90, but was: "+t);if(!isFinite(e)||e<-180||e>180)throw new u(a.INVALID_ARGUMENT,"Longitude must be a number between -180 and 180, but was: "+e);this._lat=t,this._long=e}return Object.defineProperty(t.prototype,"latitude",{get:function(){return this._lat},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"longitude",{get:function(){return this._long},enumerable:!1,configurable:!0}),t.prototype.isEqual=function(t){return this._lat===t._lat&&this._long===t._long},t.prototype.toJSON=function(){return{latitude:this._lat,longitude:this._long}},t.prototype._compareTo=function(t){return w(this._lat,t._lat)||w(this._long,t._long)},t}(),Xa=/^__.*__$/,Ja=function(){function t(t,e,n){this.data=t,this.fieldMask=e,this.fieldTransforms=n}return t.prototype.toMutation=function(t,e){return null!==this.fieldMask?new me(t,this.data,this.fieldMask,e,this.fieldTransforms):new ve(t,this.data,e,this.fieldTransforms)},t}(),Za=function(){function t(t,e,n){this.data=t,this.fieldMask=e,this.fieldTransforms=n}return t.prototype.toMutation=function(t,e){return new me(t,this.data,this.fieldMask,e,this.fieldTransforms)},t}();function tu(t){switch(t){case 0:case 2:case 1:return!0;case 3:case 4:return!1;default:throw y()}}exports.C=$a;var eu=function(){function t(t,e,n,r,i,o){this.settings=t,this.databaseId=e,this.R=n,this.ignoreUndefinedProperties=r,void 0===i&&this.Cc(),this.fieldTransforms=i||[],this.fieldMask=o||[]}return Object.defineProperty(t.prototype,"path",{get:function(){return this.settings.path},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Nc",{get:function(){return this.settings.Nc},enumerable:!1,configurable:!0}),t.prototype.xc=function(e){return new t(Object.assign(Object.assign({},this.settings),e),this.databaseId,this.R,this.ignoreUndefinedProperties,this.fieldTransforms,this.fieldMask)},t.prototype.kc=function(t){var e,n=null===(e=this.path)||void 0===e?void 0:e.child(t),r=this.xc({path:n,Fc:!1});return r.$c(t),r},t.prototype.Oc=function(t){var e,n=null===(e=this.path)||void 0===e?void 0:e.child(t),r=this.xc({path:n,Fc:!1});return r.Cc(),r},t.prototype.Mc=function(t){return this.xc({path:void 0,Fc:!0})},t.prototype.Lc=function(t){return bu(t,this.settings.methodName,this.settings.Bc||!1,this.path,this.settings.qc)},t.prototype.contains=function(t){return void 0!==this.fieldMask.find(function(e){return t.isPrefixOf(e)})||void 0!==this.fieldTransforms.find(function(e){return t.isPrefixOf(e.field)})},t.prototype.Cc=function(){if(this.path)for(var t=0;t<this.path.length;t++)this.$c(this.path.get(t))},t.prototype.$c=function(t){if(0===t.length)throw this.Lc("Document fields must not be empty");if(tu(this.Nc)&&Xa.test(t))throw this.Lc('Document fields cannot begin and end with "__"')},t}(),nu=function(){function t(t,e,n){this.databaseId=t,this.ignoreUndefinedProperties=e,this.R=n||ho(t)}return t.prototype.Uc=function(t,e,n,r){return void 0===r&&(r=!1),new eu({Nc:t,methodName:e,qc:n,path:C.emptyPath(),Fc:!1,Bc:r},this.databaseId,this.R,this.ignoreUndefinedProperties)},t}();function ru(t){var e=t._freezeSettings(),n=ho(t._databaseId);return new nu(t._databaseId,!!e.ignoreUndefinedProperties,n)}function iu(t,e,n,r,i,o){void 0===o&&(o={});var s=t.Uc(o.merge||o.mergeFields?2:0,e,n,i);mu("Data must be an object, but it was:",s,r);var c,h,f=yu(r,s);if(o.merge)c=new R(s.fieldMask),h=s.fieldTransforms;else if(o.mergeFields){for(var l=[],d=0,p=o.mergeFields;d<p.length;d++){var y=gu(e,p[d],n);if(!s.contains(y))throw new u(a.INVALID_ARGUMENT,"Field '"+y+"' is specified in your field mask but missing from your input data.");Iu(l,y)||l.push(y)}c=new R(l),h=s.fieldTransforms.filter(function(t){return c.covers(t.field)})}else c=null,h=s.fieldTransforms;return new Ja(new ot(f),c,h)}var ou=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return(0,e.__extends)(n,t),n.prototype._toFieldTransform=function(t){if(2!==t.Nc)throw 1===t.Nc?t.Lc(this._methodName+"() can only appear at the top level of your update data"):t.Lc(this._methodName+"() cannot be used with set() unless you pass {merge:true}");return t.fieldMask.push(t.path),null},n.prototype.isEqual=function(t){return t instanceof n},n}(Ya);function su(t,e,n){return new eu({Nc:3,qc:e.settings.qc,methodName:t._methodName,Fc:n},e.databaseId,e.R,e.ignoreUndefinedProperties)}var au=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return(0,e.__extends)(n,t),n.prototype._toFieldTransform=function(t){return new se(t.path,new Jt)},n.prototype.isEqual=function(t){return t instanceof n},n}(Ya),uu=function(t){function n(e,n){var r=this;return(r=t.call(this,e)||this).Kc=n,r}return(0,e.__extends)(n,t),n.prototype._toFieldTransform=function(t){var e=su(this,t,!0),n=this.Kc.map(function(t){return pu(t,e)}),r=new Zt(n);return new se(t.path,r)},n.prototype.isEqual=function(t){return this===t},n}(Ya),cu=function(t){function n(e,n){var r=this;return(r=t.call(this,e)||this).Kc=n,r}return(0,e.__extends)(n,t),n.prototype._toFieldTransform=function(t){var e=su(this,t,!0),n=this.Kc.map(function(t){return pu(t,e)}),r=new ee(n);return new se(t.path,r)},n.prototype.isEqual=function(t){return this===t},n}(Ya),hu=function(t){function n(e,n){var r=this;return(r=t.call(this,e)||this).Qc=n,r}return(0,e.__extends)(n,t),n.prototype._toFieldTransform=function(t){var e=new re(t.R,Wt(t.R,this.Qc));return new se(t.path,e)},n.prototype.isEqual=function(t){return this===t},n}(Ya);function fu(t,e,r,i){var o=t.Uc(1,e,r);mu("Data must be an object, but it was:",o,i);var s=[],a=ot.empty();N(i,function(t,i){var u=wu(e,t,r);i=(0,n.getModularInstance)(i);var c=o.Oc(u);if(i instanceof ou)s.push(u);else{var h=pu(i,c);null!=h&&(s.push(u),a.set(u,h))}});var u=new R(s);return new Za(a,u,o.fieldTransforms)}function lu(t,e,r,i,o,s){var c=t.Uc(1,e,r),h=[gu(e,i,r)],f=[o];if(s.length%2!=0)throw new u(a.INVALID_ARGUMENT,"Function "+e+"() needs to be called with an even number of arguments that alternate between field names and values.");for(var l=0;l<s.length;l+=2)h.push(gu(e,s[l])),f.push(s[l+1]);for(var d=[],p=ot.empty(),y=h.length-1;y>=0;--y)if(!Iu(d,h[y])){var v=h[y],m=f[y];m=(0,n.getModularInstance)(m);var g=c.Oc(v);if(m instanceof ou)d.push(v);else{var _=pu(m,g);null!=_&&(d.push(v),p.set(v,_))}}var w=new R(d);return new Za(p,w,c.fieldTransforms)}function du(t,e,n,r){return void 0===r&&(r=!1),pu(n,t.Uc(r?4:3,e))}function pu(t,e){if(vu(t=(0,n.getModularInstance)(t)))return mu("Unsupported field value:",e,t),yu(t,e);if(t instanceof Ya)return function(t,e){if(!tu(e.Nc))throw e.Lc(t._methodName+"() can only be used with update() and set()");if(!e.path)throw e.Lc(t._methodName+"() is not currently supported inside arrays");var n=t._toFieldTransform(e);n&&e.fieldTransforms.push(n)}(t,e),null;if(void 0===t&&e.ignoreUndefinedProperties)return null;if(e.path&&e.fieldMask.push(e.path),t instanceof Array){if(e.settings.Fc&&4!==e.Nc)throw e.Lc("Nested arrays are not supported");return function(t,e){for(var n=[],r=0,i=0,o=t;i<o.length;i++){var s=pu(o[i],e.Mc(r));null==s&&(s={nullValue:"NULL_VALUE"}),n.push(s),r++}return{arrayValue:{values:n}}}(t,e)}return function(t,e){if(null===(t=(0,n.getModularInstance)(t)))return{nullValue:"NULL_VALUE"};if("number"==typeof t)return Wt(e.R,t);if("boolean"==typeof t)return{booleanValue:t};if("string"==typeof t)return{stringValue:t};if(t instanceof Date){var r=E.fromDate(t);return{timestampValue:en(e.R,r)}}if(t instanceof E)return r=new E(t.seconds,1e3*Math.floor(t.nanoseconds/1e3)),{timestampValue:en(e.R,r)};if(t instanceof $a)return{geoPointValue:{latitude:t.latitude,longitude:t.longitude}};if(t instanceof Ha)return{bytesValue:nn(e.R,t._byteString)};if(t instanceof Ca){r=e.databaseId;var i=t.firestore._databaseId;if(!i.isEqual(r))throw e.Lc("Document reference is for database "+i.projectId+"/"+i.database+" but should be for database "+r.projectId+"/"+r.database);return{referenceValue:sn(t.firestore._databaseId||e.databaseId,t._key.path)}}throw e.Lc("Unsupported field value: "+Na(t))}(t,e)}function yu(t,e){var n={};return D(t)?e.path&&e.path.length>0&&e.fieldMask.push(e.path):N(t,function(t,r){var i=pu(r,e.kc(t));null!=i&&(n[t]=i)}),{mapValue:{fields:n}}}function vu(t){return!("object"!=o(t)||null===t||t instanceof Array||t instanceof Date||t instanceof E||t instanceof $a||t instanceof Ha||t instanceof Ca||t instanceof Ya)}function mu(t,e,n){if(!vu(n)||!function(t){return"object"==o(t)&&null!==t&&(Object.getPrototypeOf(t)===Object.prototype||null===Object.getPrototypeOf(t))}(n)){var r=Na(n);throw"an object"===r?e.Lc(t+" a custom object"):e.Lc(t+" "+r)}}function gu(t,e,r){if((e=(0,n.getModularInstance)(e))instanceof Wa)return e._internalPath;if("string"==typeof e)return wu(t,e);throw bu("Field path arguments must be of type string or FieldPath.",t,!1,void 0,r)}var _u=new RegExp("[~\\*/\\[\\]]");function wu(t,n,r){if(n.search(_u)>=0)throw bu("Invalid field path ("+n+"). Paths must not contain '~', '*', '/', '[', or ']'",t,!1,void 0,r);try{return(new(Wa.bind.apply(Wa,(0,e.__spreadArray)([void 0],n.split(".")))))._internalPath}catch(i){throw bu("Invalid field path ("+n+"). Paths must not be empty, begin with '.', end with '.', or contain '..'",t,!1,void 0,r)}}function bu(t,e,n,r,i){var o=r&&!r.isEmpty(),s=void 0!==i,c="Function "+e+"() called with invalid data";n&&(c+=" (via `toFirestore()`)");var h="";return(o||s)&&(h+=" (found",o&&(h+=" in field "+r),s&&(h+=" in document "+i),h+=")"),new u(a.INVALID_ARGUMENT,(c+=". ")+t+h)}function Iu(t,e){return t.some(function(t){return t.isEqual(e)})}var Eu=function(){function t(t,e,n,r,i){this._firestore=t,this._userDataWriter=e,this._key=n,this._document=r,this._converter=i}return Object.defineProperty(t.prototype,"id",{get:function(){return this._key.path.lastSegment()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"ref",{get:function(){return new Ca(this._firestore,this._converter,this._key)},enumerable:!1,configurable:!0}),t.prototype.exists=function(){return null!==this._document},t.prototype.data=function(){if(this._document){if(this._converter){var t=new Tu(this._firestore,this._userDataWriter,this._key,this._document,null);return this._converter.fromFirestore(t)}return this._userDataWriter.convertValue(this._document.data.value)}},t.prototype.get=function(t){if(this._document){var e=this._document.data.field(Su("DocumentSnapshot.get",t));if(null!==e)return this._userDataWriter.convertValue(e)}},t}(),Tu=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return(0,e.__extends)(n,t),n.prototype.data=function(){return t.prototype.data.call(this)},n}(Eu);function Su(t,e){return"string"==typeof e?wu(t,e):e instanceof Wa?e._internalPath:e._delegate._internalPath}var Nu=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}(),Du=function(t){function n(e,n,r,i,o,s){var a=this;return(a=t.call(this,e,n,r,i,s)||this)._firestore=e,a._firestoreImpl=e,a.metadata=o,a}return(0,e.__extends)(n,t),n.prototype.exists=function(){return t.prototype.exists.call(this)},n.prototype.data=function(t){if(void 0===t&&(t={}),this._document){if(this._converter){var e=new Au(this._firestore,this._userDataWriter,this._key,this._document,this.metadata,null);return this._converter.fromFirestore(e,t)}return this._userDataWriter.convertValue(this._document.data.value,t.serverTimestamps)}},n.prototype.get=function(t,e){if(void 0===e&&(e={}),this._document){var n=this._document.data.field(Su("DocumentSnapshot.get",t));if(null!==n)return this._userDataWriter.convertValue(n,e.serverTimestamps)}},n}(Eu),Au=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return(0,e.__extends)(n,t),n.prototype.data=function(e){return void 0===e&&(e={}),t.prototype.data.call(this,e)},n}(Du),xu=function(){function t(t,e,n,r){this._firestore=t,this._userDataWriter=e,this._snapshot=r,this.metadata=new Nu(r.hasPendingWrites,r.fromCache),this.query=n}return Object.defineProperty(t.prototype,"docs",{get:function(){var t=[];return this.forEach(function(e){return t.push(e)}),t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"size",{get:function(){return this._snapshot.docs.size},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"empty",{get:function(){return 0===this.size},enumerable:!1,configurable:!0}),t.prototype.forEach=function(t,e){var n=this;this._snapshot.docs.forEach(function(r){t.call(e,new Au(n._firestore,n._userDataWriter,r.key,r,new Nu(n._snapshot.mutatedKeys.has(r.key),n._snapshot.fromCache),n.query.converter))})},t.prototype.docChanges=function(t){void 0===t&&(t={});var e=!!t.includeMetadataChanges;if(e&&this._snapshot.excludesMetadataChanges)throw new u(a.INVALID_ARGUMENT,"To include metadata changes with your document changes, you must also pass { includeMetadataChanges:true } to onSnapshot().");return this._cachedChanges&&this._cachedChangesIncludeMetadataChanges===e||(this._cachedChanges=function(t,e){if(t._snapshot.oldDocs.isEmpty()){var n=0;return t._snapshot.docChanges.map(function(e){return{type:"added",doc:new Au(t._firestore,t._userDataWriter,e.doc.key,e.doc,new Nu(t._snapshot.mutatedKeys.has(e.doc.key),t._snapshot.fromCache),t.query.converter),oldIndex:-1,newIndex:n++}})}var r=t._snapshot.oldDocs;return t._snapshot.docChanges.filter(function(t){return e||3!==t.type}).map(function(e){var n=new Au(t._firestore,t._userDataWriter,e.doc.key,e.doc,new Nu(t._snapshot.mutatedKeys.has(e.doc.key),t._snapshot.fromCache),t.query.converter),i=-1,o=-1;return 0!==e.type&&(i=r.indexOf(e.doc.key),r=r.delete(e.doc.key)),1!==e.type&&(o=(r=r.add(e.doc)).indexOf(e.doc.key)),{type:ku(e.type),doc:n,oldIndex:i,newIndex:o}})}(this,e),this._cachedChangesIncludeMetadataChanges=e),this._cachedChanges},t}();function ku(t){switch(t){case 0:return"added";case 2:case 3:return"modified";case 1:return"removed";default:return y()}}function Cu(t,e){return t instanceof Du&&e instanceof Du?t._firestore===e._firestore&&t._key.isEqual(e._key)&&(null===t._document?null===e._document:t._document.isEqual(e._document))&&t._converter===e._converter:t instanceof xu&&e instanceof xu&&t._firestore===e._firestore&&Ma(t.query,e.query)&&t.metadata.isEqual(e.metadata)&&t._snapshot.isEqual(e._snapshot)}function Ru(t){if(Rt(t)&&0===t.explicitOrderBy.length)throw new u(a.UNIMPLEMENTED,"limitToLast() queries require specifying at least one orderBy() clause")}var Lu=function(){};function Ou(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];for(var r=0,i=e;r<i.length;r++){t=i[r]._apply(t)}return t}var Pu=function(t){function n(e,n,r){var i=this;return(i=t.call(this)||this).jc=e,i.Wc=n,i.Gc=r,i.type="where",i}return(0,e.__extends)(n,t),n.prototype._apply=function(t){var e=ru(t.firestore),n=function(t,e,n,r,i,o,s){var c;if(i.isKeyField()){if("array-contains"===o||"array-contains-any"===o)throw new u(a.INVALID_ARGUMENT,"Invalid Query. You can't perform '"+o+"' queries on FieldPath.documentId().");if("in"===o||"not-in"===o){ju(s,o);for(var h=[],f=0,l=s;f<l.length;f++){var d=l[f];h.push(Bu(r,t,d))}c={arrayValue:{values:h}}}else c=Bu(r,t,s)}else"in"!==o&&"not-in"!==o&&"array-contains-any"!==o||ju(s,o),c=du(n,"where",s,"in"===o||"not-in"===o);var p=dt.create(i,o,c);return function(t,e){if(e.g()){var n=Ot(t);if(null!==n&&!n.isEqual(e.field))throw new u(a.INVALID_ARGUMENT,"Invalid query. All where filters with an inequality (<, <=, !=, not-in, >, or >=) must be on the same field. But you have inequality filters on '"+n.toString()+"' and '"+e.field.toString()+"'");var r=Lt(t);null!==r&&Ku(t,e.field,r)}var i=function(t,e){for(var n=0,r=t.filters;n<r.length;n++){var i=r[n];if(e.indexOf(i.op)>=0)return i.op}return null}(t,function(t){switch(e.op){case"!=":return["!=","not-in"];case"array-contains":return["array-contains","array-contains-any","not-in"];case"in":return["array-contains-any","in","not-in"];case"array-contains-any":return["array-contains","array-contains-any","in","not-in"];case"not-in":return["array-contains","array-contains-any","in","not-in","!="];default:return[]}}());if(null!==i)throw i===e.op?new u(a.INVALID_ARGUMENT,"Invalid query. You cannot use more than one '"+e.op.toString()+"' filter."):new u(a.INVALID_ARGUMENT,"Invalid query. You cannot use '"+e.op.toString()+"' filters with '"+i.toString()+"' filters.")}(t,p),p}(t._query,0,e,t.firestore._databaseId,this.jc,this.Wc,this.Gc);return new Ra(t.firestore,t.converter,function(t,e){var n=t.filters.concat([e]);return new At(t.path,t.collectionGroup,t.explicitOrderBy.slice(),n,t.limit,t.limitType,t.startAt,t.endAt)}(t._query,n))},n}(Lu),Fu=function(t){function n(e,n){var r=this;return(r=t.call(this)||this).jc=e,r.zc=n,r.type="orderBy",r}return(0,e.__extends)(n,t),n.prototype._apply=function(t){var e=function(t,e,n){if(null!==t.startAt)throw new u(a.INVALID_ARGUMENT,"Invalid query. You must not call startAt() or startAfter() before calling orderBy().");if(null!==t.endAt)throw new u(a.INVALID_ARGUMENT,"Invalid query. You must not call endAt() or endBefore() before calling orderBy().");var r=new Tt(e,n);return function(t,e){if(null===Lt(t)){var n=Ot(t);null!==n&&Ku(t,n,e.field)}}(t,r),r}(t._query,this.jc,this.zc);return new Ra(t.firestore,t.converter,function(t,e){var n=t.explicitOrderBy.concat([e]);return new At(t.path,t.collectionGroup,n,t.filters.slice(),t.limit,t.limitType,t.startAt,t.endAt)}(t._query,e))},n}(Lu),Mu=function(t){function n(e,n,r){var i=this;return(i=t.call(this)||this).type=e,i.Hc=n,i.Jc=r,i}return(0,e.__extends)(n,t),n.prototype._apply=function(t){return new Ra(t.firestore,t.converter,Vt(t._query,this.Hc,this.Jc))},n}(Lu),Vu=function(t){function n(e,n,r){var i=this;return(i=t.call(this)||this).type=e,i.Yc=n,i.Xc=r,i}return(0,e.__extends)(n,t),n.prototype._apply=function(t){var e=Uu(t,this.type,this.Yc,this.Xc);return new Ra(t.firestore,t.converter,function(t,e){return new At(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,e,t.endAt)}(t._query,e))},n}(Lu),qu=function(t){function n(e,n,r){var i=this;return(i=t.call(this)||this).type=e,i.Yc=n,i.Xc=r,i}return(0,e.__extends)(n,t),n.prototype._apply=function(t){var e=Uu(t,this.type,this.Yc,this.Xc);return new Ra(t.firestore,t.converter,function(t,e){return new At(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,t.startAt,e)}(t._query,e))},n}(Lu);function Uu(t,e,r,i){if(r[0]=(0,n.getModularInstance)(r[0]),r[0]instanceof Eu)return function(t,e,n,r,i){if(!r)throw new u(a.NOT_FOUND,"Can't use a DocumentSnapshot that doesn't exist for "+n+"().");for(var o=[],s=0,c=Ft(t);s<c.length;s++){var h=c[s];if(h.field.isKeyField())o.push(J(e,r.key));else{var f=r.data.field(h.field);if(V(f))throw new u(a.INVALID_ARGUMENT,'Invalid query. You are trying to start or end a query using a document for which the field "'+h.field+'" is an uncommitted server timestamp. (Since the value of this field is unknown, you cannot start/end a query with it.)');if(null===f){var l=h.field.canonicalString();throw new u(a.INVALID_ARGUMENT,"Invalid query. You are trying to start or end a query using a document for which the field '"+l+"' (used as the orderBy) does not exist.")}o.push(f)}}return new It(o,i)}(t._query,t.firestore._databaseId,e,r[0]._document,i);var s=ru(t.firestore);return function(t,e,n,r,i,s){var c=t.explicitOrderBy;if(i.length>c.length)throw new u(a.INVALID_ARGUMENT,"Too many arguments provided to "+r+"(). The number of arguments must be less than or equal to the number of orderBy() clauses");for(var h=[],f=0;f<i.length;f++){var l=i[f];if(c[f].field.isKeyField()){if("string"!=typeof l)throw new u(a.INVALID_ARGUMENT,"Invalid query. Expected a string for document ID in "+r+"(), but got a "+o(l));if(!Pt(t)&&-1!==l.indexOf("/"))throw new u(a.INVALID_ARGUMENT,"Invalid query. When querying a collection and ordering by FieldPath.documentId(), the value passed to "+r+"() must be a plain document ID, but '"+l+"' contains a slash.");var d=t.path.child(x.fromString(l));if(!G.isDocumentKey(d))throw new u(a.INVALID_ARGUMENT,"Invalid query. When querying a collection group and ordering by FieldPath.documentId(), the value passed to "+r+"() must result in a valid document path, but '"+d+"' is not because it contains an odd number of segments.");var p=new G(d);h.push(J(e,p))}else{var y=du(n,r,l);h.push(y)}}return new It(h,s)}(t._query,t.firestore._databaseId,s,e,r,i)}function Bu(t,e,r){if("string"==typeof(r=(0,n.getModularInstance)(r))){if(""===r)throw new u(a.INVALID_ARGUMENT,"Invalid query. When querying with FieldPath.documentId(), you must provide a valid document ID, but it was an empty string.");if(!Pt(e)&&-1!==r.indexOf("/"))throw new u(a.INVALID_ARGUMENT,"Invalid query. When querying a collection by FieldPath.documentId(), you must provide a plain document ID, but '"+r+"' contains a '/' character.");var i=e.path.child(x.fromString(r));if(!G.isDocumentKey(i))throw new u(a.INVALID_ARGUMENT,"Invalid query. When querying a collection group by FieldPath.documentId(), the value provided must result in a valid document path, but '"+i+"' is not because it has an odd number of segments ("+i.length+").");return J(t,new G(i))}if(r instanceof Ca)return J(t,r._key);throw new u(a.INVALID_ARGUMENT,"Invalid query. When querying with FieldPath.documentId(), you must provide a valid string or a DocumentReference, but it was: "+Na(r)+".")}function ju(t,e){if(!Array.isArray(t)||0===t.length)throw new u(a.INVALID_ARGUMENT,"Invalid Query. A non-empty array is required for '"+e.toString()+"' filters.");if(t.length>10)throw new u(a.INVALID_ARGUMENT,"Invalid Query. '"+e.toString()+"' filters support a maximum of 10 elements in the value array.")}function Ku(t,e,n){if(!n.isEqual(e))throw new u(a.INVALID_ARGUMENT,"Invalid query. You have a where filter with an inequality (<, <=, !=, not-in, >, or >=) on field '"+e.toString()+"' and so you must also use '"+e.toString()+"' as your first argument to orderBy(), but your first orderBy() is on field '"+n.toString()+"' instead.")}var Gu=function(){function t(){}return t.prototype.convertValue=function(t,e){switch(void 0===e&&(e="none"),Q(t)){case 0:return null;case 1:return t.booleanValue;case 2:return F(t.integerValue||t.doubleValue);case 3:return this.convertTimestamp(t.timestampValue);case 4:return this.convertServerTimestamp(t,e);case 5:return t.stringValue;case 6:return this.convertBytes(M(t.bytesValue));case 7:return this.convertReference(t.referenceValue);case 8:return this.convertGeoPoint(t.geoPointValue);case 9:return this.convertArray(t.arrayValue,e);case 10:return this.convertObject(t.mapValue,e);default:throw y()}},t.prototype.convertObject=function(t,e){var n=this,r={};return N(t.fields,function(t,i){r[t]=n.convertValue(i,e)}),r},t.prototype.convertGeoPoint=function(t){return new $a(F(t.latitude),F(t.longitude))},t.prototype.convertArray=function(t,e){var n=this;return(t.values||[]).map(function(t){return n.convertValue(t,e)})},t.prototype.convertServerTimestamp=function(t,e){switch(e){case"previous":var n=q(t);return null==n?null:this.convertValue(n,e);case"estimate":return this.convertTimestamp(U(t));default:return null}},t.prototype.convertTimestamp=function(t){var e=P(t);return new E(e.seconds,e.nanos)},t.prototype.convertDocumentKey=function(t,e){var n=x.fromString(t);v(Cn(n));var r=new da(n.get(1),n.get(3)),i=new G(n.popFirst(5));return r.isEqual(e)||l("Document "+i+" contains a document reference within a different database ("+r.projectId+"/"+r.database+") which is not supported. It will be treated as a reference in the current database ("+e.projectId+"/"+e.database+") instead."),i},t}();function Qu(t,e,n){return t?n&&(n.merge||n.mergeFields)?t.toFirestore(e,n):t.toFirestore(e):e}var zu=function(t){function n(e){var n=this;return(n=t.call(this)||this).firestore=e,n}return(0,e.__extends)(n,t),n.prototype.convertBytes=function(t){return new Ha(t)},n.prototype.convertReference=function(t){var e=this.convertDocumentKey(t,this.firestore._databaseId);return new Ca(this.firestore,null,e)},n}(Gu),Wu=function(){function t(t,e){this._firestore=t,this._commitHandler=e,this._mutations=[],this._committed=!1,this._dataReader=ru(t)}return t.prototype.set=function(t,e,n){this._verifyNotCommitted();var r=Hu(t,this._firestore),i=Qu(r.converter,e,n),o=iu(this._dataReader,"WriteBatch.set",r._key,i,null!==r.converter,n);return this._mutations.push(o.toMutation(r._key,ue.none())),this},t.prototype.update=function(t,e,r){for(var i=[],o=3;o<arguments.length;o++)i[o-3]=arguments[o];this._verifyNotCommitted();var s,a=Hu(t,this._firestore);return s="string"==typeof(e=(0,n.getModularInstance)(e))||e instanceof Wa?lu(this._dataReader,"WriteBatch.update",a._key,e,r,i):fu(this._dataReader,"WriteBatch.update",a._key,e),this._mutations.push(s.toMutation(a._key,ue.exists(!0))),this},t.prototype.delete=function(t){this._verifyNotCommitted();var e=Hu(t,this._firestore);return this._mutations=this._mutations.concat(new Ee(e._key,ue.none())),this},t.prototype.commit=function(){return this._verifyNotCommitted(),this._committed=!0,this._mutations.length>0?this._commitHandler(this._mutations):Promise.resolve()},t.prototype._verifyNotCommitted=function(){if(this._committed)throw new u(a.FAILED_PRECONDITION,"A write batch can no longer be used after commit() has been called.")},t}();function Hu(t,e){if((t=(0,n.getModularInstance)(t)).firestore!==e)throw new u(a.INVALID_ARGUMENT,"Provided document reference is from a different Firestore instance.");return t}var Yu=function(t){function n(e){var n=this;return(n=t.call(this)||this).firestore=e,n}return(0,e.__extends)(n,t),n.prototype.convertBytes=function(t){return new Ha(t)},n.prototype.convertReference=function(t){var e=this.convertDocumentKey(t,this.firestore._databaseId);return new Ca(this.firestore,null,e)},n}(Gu);function $u(t,e,n){t=Da(t,Ca);var r=Da(t.firestore,ja),i=Qu(t.converter,e,n);return Zu(r,[iu(ru(r),"setDoc",t._key,i,null!==t.converter,n).toMutation(t._key,ue.none())])}function Xu(t,e,r){for(var i=[],o=3;o<arguments.length;o++)i[o-3]=arguments[o];t=Da(t,Ca);var s=Da(t.firestore,ja),a=ru(s);return Zu(s,[("string"==typeof(e=(0,n.getModularInstance)(e))||e instanceof Wa?lu(a,"updateDoc",t._key,e,r,i):fu(a,"updateDoc",t._key,e)).toMutation(t._key,ue.exists(!0))])}function Ju(t){for(var r,i,s,a=[],u=1;u<arguments.length;u++)a[u-1]=arguments[u];t=(0,n.getModularInstance)(t);var c={includeMetadataChanges:!1},h=0;"object"!=o(a[h])||qa(a[h])||(c=a[h],h++);var f,l,d,p={includeMetadataChanges:c.includeMetadataChanges};if(qa(a[h])){var y=a[h];a[h]=null===(r=y.next)||void 0===r?void 0:r.bind(y),a[h+1]=null===(i=y.error)||void 0===i?void 0:i.bind(y),a[h+2]=null===(s=y.complete)||void 0===s?void 0:s.bind(y)}if(t instanceof Ca)l=Da(t.firestore,ja),d=kt(t._key.path),f={next:function(e){a[h]&&a[h](tc(l,t,e))},error:a[h+1],complete:a[h+2]};else{var v=Da(t,Ra);l=Da(v.firestore,ja),d=v._query;var m=new Yu(l);f={next:function(t){a[h]&&a[h](new xu(l,m,v,t))},error:a[h+1],complete:a[h+2]},Ru(t._query)}return function(t,n,r,i){var o=this,s=new $s(f),a=new ns(n,s,r);return t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(o,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return n=Xo,[4,ca(t)];case 1:return[2,n.apply(void 0,[e.sent(),a])]}})})}),function(){s.Wo(),t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(o,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return n=Jo,[4,ca(t)];case 1:return[2,n.apply(void 0,[e.sent(),a])]}})})})}}(Ka(l),d,p)}function Zu(t,n){return function(t,n){var r=this,i=new er;return t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(r,void 0,void 0,function(){var r;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return r=vs,[4,ua(t)];case 1:return[2,r.apply(void 0,[e.sent(),n,i])]}})})}),i.promise}(Ka(t),n)}function tc(t,e,n){var r=n.docs.get(e._key),i=new Yu(t);return new Du(t,i,e._key,r,new Nu(n.hasPendingWrites,n.fromCache),e.converter)}var ec=function(t){function n(e,n){var r=this;return(r=t.call(this,e,n)||this)._firestore=e,r}return(0,e.__extends)(n,t),n.prototype.get=function(e){var n=this,r=Hu(e,this._firestore),i=new Yu(this._firestore);return t.prototype.get.call(this,e).then(function(t){return new Du(n._firestore,i,r._key,t._document,new Nu(!1,!1),r.converter)})},n}(function(){function t(t,e){this._firestore=t,this._transaction=e,this._dataReader=ru(t)}return t.prototype.get=function(t){var e=this,n=Hu(t,this._firestore),r=new zu(this._firestore);return this._transaction.lookup([n._key]).then(function(t){if(!t||1!==t.length)return y();var i=t[0];if(i.isFoundDocument())return new Eu(e._firestore,r,i.key,i,n.converter);if(i.isNoDocument())return new Eu(e._firestore,r,n._key,null,n.converter);throw y()})},t.prototype.set=function(t,e,n){var r=Hu(t,this._firestore),i=Qu(r.converter,e,n),o=iu(this._dataReader,"Transaction.set",r._key,i,null!==r.converter,n);return this._transaction.set(r._key,o),this},t.prototype.update=function(t,e,r){for(var i=[],o=3;o<arguments.length;o++)i[o-3]=arguments[o];var s,a=Hu(t,this._firestore);return s="string"==typeof(e=(0,n.getModularInstance)(e))||e instanceof Wa?lu(this._dataReader,"Transaction.update",a._key,e,r,i):fu(this._dataReader,"Transaction.update",a._key,e),this._transaction.update(a._key,s),this},t.prototype.delete=function(t){var e=Hu(t,this._firestore);return this._transaction.delete(e._key),this},t}());function nc(){if("undefined"==typeof Uint8Array)throw new u(a.UNIMPLEMENTED,"Uint8Arrays are not available in this environment.")}function rc(){if("undefined"==typeof atob)throw new u(a.UNIMPLEMENTED,"Blobs are unavailable in Firestore in this environment.")}var ic=function(){function t(t){this._delegate=t}return t.fromBase64String=function(e){return rc(),new t(Ha.fromBase64String(e))},t.fromUint8Array=function(e){return nc(),new t(Ha.fromUint8Array(e))},t.prototype.toBase64=function(){return rc(),this._delegate.toBase64()},t.prototype.toUint8Array=function(){return nc(),this._delegate.toUint8Array()},t.prototype.isEqual=function(t){return this._delegate.isEqual(t._delegate)},t.prototype.toString=function(){return"Blob(base64: "+this.toBase64()+")"},t}(),oc=function(){function t(){}return t.prototype.enableIndexedDbPersistence=function(t,e){return function(t,e){za(t=Da(t,ja));var n=Ka(t),r=t._freezeSettings(),i=new Hs;return Qa(n,i,new zs(i,r.cacheSizeBytes,null==e?void 0:e.forceOwnership))}(t._delegate,{forceOwnership:e})},t.prototype.enableMultiTabIndexedDbPersistence=function(t){return function(t){za(t=Da(t,ja));var e=Ka(t),n=t._freezeSettings(),r=new Hs;return Qa(e,r,new Ws(r,n.cacheSizeBytes))}(t._delegate)},t.prototype.clearIndexedDbPersistence=function(t){return function(t){var n=this;if(t._initialized&&!t._terminated)throw new u(a.FAILED_PRECONDITION,"Persistence can only be cleared before a Firestore instance is initialized or after it is terminated.");var r=new er;return t._queue.enqueueAndForgetEvenWhileRestricted(function(){return(0,e.__awaiter)(n,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,function(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return ir.yt()?(n=t+"main",[4,ir.delete(n)]):[2,Promise.resolve()];case 1:return e.sent(),[2]}})})}(yi(t._databaseId,t._persistenceKey))];case 1:return i.sent(),r.resolve(),[3,3];case 2:return n=i.sent(),r.reject(n),[3,3];case 3:return[2]}})})}),r.promise}(t._delegate)},t}(),sc=function(){function t(t,e,n){var r=this;this._delegate=e,this.Zc=n,this.INTERNAL={delete:function(){return r.terminate()}},t instanceof da||(this.tu=t)}return Object.defineProperty(t.prototype,"_databaseId",{get:function(){return this._delegate._databaseId},enumerable:!1,configurable:!0}),t.prototype.settings=function(t){var e=this._delegate._getSettings();t.merge||e.host===t.host||d("You are overriding the original host. If you did not intend to override your settings, use {merge: true}."),t.merge&&delete(t=Object.assign(Object.assign({},e),t)).merge,this._delegate._setSettings(t)},t.prototype.useEmulator=function(t,e,r){void 0===r&&(r={}),function(t,e,r,i){var o;void 0===i&&(i={});var s=(t=Da(t,ka))._getSettings();if("firestore.googleapis.com"!==s.host&&s.host!==e&&d("Host has been set in both settings() and useEmulator(), emulator host will be used"),t._setSettings(Object.assign(Object.assign({},s),{host:e+":"+r,ssl:!1})),i.mockUserToken){var c,h;if("string"==typeof i.mockUserToken)c=i.mockUserToken,h=zi.MOCK_USER;else{c=(0,n.createMockUserToken)(i.mockUserToken,null===(o=t._app)||void 0===o?void 0:o.options.projectId);var f=i.mockUserToken.sub||i.mockUserToken.user_id;if(!f)throw new u(a.INVALID_ARGUMENT,"mockUserToken must contain 'sub' or 'user_id' field!");h=new zi(f)}t._credentials=new ma(new ya(c,h))}}(this._delegate,t,e,r)},t.prototype.enableNetwork=function(){return function(t){var n=this;return t.asyncQueue.enqueue(function(){return(0,e.__awaiter)(n,void 0,void 0,function(){var n,r;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,oa(t)];case 1:return n=e.sent(),[4,aa(t)];case 2:return r=e.sent(),[2,(n.setNetworkEnabled(!0),function(t){var e=m(r);return e.Or.delete(0),_o(e)}())]}})})})}(Ka(Da(this._delegate,ja)))},t.prototype.disableNetwork=function(){return function(t){var n=this;return t.asyncQueue.enqueue(function(){return(0,e.__awaiter)(n,void 0,void 0,function(){var n,r;return(0,e.__generator)(this,function(i){switch(i.label){case 0:return[4,oa(t)];case 1:return n=i.sent(),[4,aa(t)];case 2:return r=i.sent(),[2,(n.setNetworkEnabled(!1),function(t){return(0,e.__awaiter)(this,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return(n=m(t)).Or.add(0),[4,wo(n)];case 1:return e.sent(),n.Br.set("Offline"),[2]}})})}(r))]}})})})}(Ka(Da(this._delegate,ja)))},t.prototype.enablePersistence=function(t){var e=!1,n=!1;return t&&Ea("synchronizeTabs",e=!!t.synchronizeTabs,"experimentalForceOwningTab",n=!!t.experimentalForceOwningTab),e?this.Zc.enableMultiTabIndexedDbPersistence(this):this.Zc.enableIndexedDbPersistence(this,n)},t.prototype.clearPersistence=function(){return this.Zc.clearIndexedDbPersistence(this)},t.prototype.terminate=function(){return this.tu&&(this.tu._removeServiceInstance("firestore"),this.tu._removeServiceInstance("firestore-exp")),this._delegate._delete()},t.prototype.waitForPendingWrites=function(){return function(t){var n=this,r=new er;return t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(n,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return n=Is,[4,ua(t)];case 1:return[2,n.apply(void 0,[e.sent(),r])]}})})}),r.promise}(Ka(Da(this._delegate,ja)))},t.prototype.onSnapshotsInSync=function(t){return function(t,n){return function(t,n){var r=this,i=new $s(n);return t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(r,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return n=function(t,e){m(t).Gr.add(e),e.next()},[4,ca(t)];case 1:return[2,n.apply(void 0,[e.sent(),i])]}})})}),function(){i.Wo(),t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(r,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return n=function(t,e){m(t).Gr.delete(e)},[4,ca(t)];case 1:return[2,n.apply(void 0,[e.sent(),i])]}})})})}}(Ka(t=Da(t,ja)),qa(n)?n:{next:n})}(this._delegate,t)},Object.defineProperty(t.prototype,"app",{get:function(){if(!this.tu)throw new u(a.FAILED_PRECONDITION,"Firestore was not initialized using the Firebase SDK. 'app' is not available");return this.tu},enumerable:!1,configurable:!0}),t.prototype.collection=function(t){try{return new bc(this,Oa(this._delegate,t))}catch(t){throw dc(t,"collection()","Firestore.collection()")}},t.prototype.doc=function(t){try{return new lc(this,Pa(this._delegate,t))}catch(t){throw dc(t,"doc()","Firestore.doc()")}},t.prototype.collectionGroup=function(t){try{return new gc(this,function(t,e){if(t=Da(t,ka),ba("collectionGroup","collection id",e),e.indexOf("/")>=0)throw new u(a.INVALID_ARGUMENT,"Invalid collection ID '"+e+"' passed to function collectionGroup(). Collection IDs must not contain '/'.");return new Ra(t,null,function(t){return new At(x.emptyPath(),t)}(e))}(this._delegate,t))}catch(t){throw dc(t,"collectionGroup()","Firestore.collectionGroup()")}},t.prototype.runTransaction=function(t){var n=this;return function(t,n){return function(t,n){var r=this,i=new er;return t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(r,void 0,void 0,function(){var r;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return[4,function(t){return ia(t).then(function(t){return t.datastore})}(t)];case 1:return r=e.sent(),new Zs(t.asyncQueue,r,n,i).run(),[2]}})})}),i.promise}(Ka(t),function(e){return n(new ec(t,e))})}(this._delegate,function(e){return t(new cc(n,e))})},t.prototype.batch=function(){var t=this;return Ka(this._delegate),new hc(new Wu(this._delegate,function(e){return Zu(t._delegate,e)}))},t.prototype.loadBundle=function(t){throw new u(a.FAILED_PRECONDITION,'"loadBundle()" does not exist, have you imported "firebase/firestore/bundle"?')},t.prototype.namedQuery=function(t){throw new u(a.FAILED_PRECONDITION,'"namedQuery()" does not exist, have you imported "firebase/firestore/bundle"?')},t}(),ac=function(t){function n(e){var n=this;return(n=t.call(this)||this).firestore=e,n}return(0,e.__extends)(n,t),n.prototype.convertBytes=function(t){return new ic(new Ha(t))},n.prototype.convertReference=function(t){var e=this.convertDocumentKey(t,this.firestore._databaseId);return lc.eu(e,this.firestore,null)},n}(Gu);function uc(t){var e;e=t,c.setLogLevel(e)}exports.K=sc,exports.U=oc,exports.L=ic;var cc=function(){function t(t,e){this._firestore=t,this._delegate=e,this._userDataWriter=new ac(t)}return t.prototype.get=function(t){var e=this,n=Ic(t);return this._delegate.get(n).then(function(t){return new vc(e._firestore,new Du(e._firestore._delegate,e._userDataWriter,t._key,t._document,t.metadata,n.converter))})},t.prototype.set=function(t,e,n){var r=Ic(t);return n?(Ia("Transaction.set",n),this._delegate.set(r,e,n)):this._delegate.set(r,e),this},t.prototype.update=function(t,n,r){for(var i,o=[],s=3;s<arguments.length;s++)o[s-3]=arguments[s];var a=Ic(t);return 2===arguments.length?this._delegate.update(a,n):(i=this._delegate).update.apply(i,(0,e.__spreadArray)([a,n,r],o)),this},t.prototype.delete=function(t){var e=Ic(t);return this._delegate.delete(e),this},t}(),hc=function(){function t(t){this._delegate=t}return t.prototype.set=function(t,e,n){var r=Ic(t);return n?(Ia("WriteBatch.set",n),this._delegate.set(r,e,n)):this._delegate.set(r,e),this},t.prototype.update=function(t,n,r){for(var i,o=[],s=3;s<arguments.length;s++)o[s-3]=arguments[s];var a=Ic(t);return 2===arguments.length?this._delegate.update(a,n):(i=this._delegate).update.apply(i,(0,e.__spreadArray)([a,n,r],o)),this},t.prototype.delete=function(t){var e=Ic(t);return this._delegate.delete(e),this},t.prototype.commit=function(){return this._delegate.commit()},t}(),fc=function(){function t(t,e,n){this._firestore=t,this._userDataWriter=e,this._delegate=n}return t.prototype.fromFirestore=function(t,e){var n=new Au(this._firestore._delegate,this._userDataWriter,t._key,t._document,t.metadata,null);return this._delegate.fromFirestore(new mc(this._firestore,n),null!=e?e:{})},t.prototype.toFirestore=function(t,e){return e?this._delegate.toFirestore(t,e):this._delegate.toFirestore(t)},t.nu=function(e,n){var r=t.su,i=r.get(e);i||(i=new WeakMap,r.set(e,i));var o=i.get(n);return o||(o=new t(e,new ac(e),n),i.set(n,o)),o},t}();exports.G=hc,exports.W=cc,fc.su=new WeakMap;var lc=function(){function t(t,e){this.firestore=t,this._delegate=e,this._userDataWriter=new ac(t)}return t.iu=function(e,n,r){if(e.length%2!=0)throw new u(a.INVALID_ARGUMENT,"Invalid document reference. Document references must have an even number of segments, but "+e.canonicalString()+" has "+e.length);return new t(n,new Ca(n._delegate,r,new G(e)))},t.eu=function(e,n,r){return new t(n,new Ca(n._delegate,r,e))},Object.defineProperty(t.prototype,"id",{get:function(){return this._delegate.id},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"parent",{get:function(){return new bc(this.firestore,this._delegate.parent)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"path",{get:function(){return this._delegate.path},enumerable:!1,configurable:!0}),t.prototype.collection=function(t){try{return new bc(this.firestore,Oa(this._delegate,t))}catch(t){throw dc(t,"collection()","DocumentReference.collection()")}},t.prototype.isEqual=function(t){return(t=(0,n.getModularInstance)(t))instanceof Ca&&Fa(this._delegate,t)},t.prototype.set=function(t,e){e=Ia("DocumentReference.set",e);try{return e?$u(this._delegate,t,e):$u(this._delegate,t)}catch(t){throw dc(t,"setDoc()","DocumentReference.set()")}},t.prototype.update=function(t,n){for(var r=[],i=2;i<arguments.length;i++)r[i-2]=arguments[i];try{return 1===arguments.length?Xu(this._delegate,t):Xu.apply(void 0,(0,e.__spreadArray)([this._delegate,t,n],r))}catch(t){throw dc(t,"updateDoc()","DocumentReference.update()")}},t.prototype.delete=function(){return Zu(Da((t=this._delegate).firestore,ja),[new Ee(t._key,ue.none())]);var t},t.prototype.onSnapshot=function(){for(var t=this,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=pc(e),i=yc(e,function(e){return new vc(t.firestore,new Du(t.firestore._delegate,t._userDataWriter,e._key,e._document,e.metadata,t._delegate.converter))});return Ju(this._delegate,r,i)},t.prototype.get=function(t){var n=this;return("cache"===(null==t?void 0:t.source)?function(t){t=Da(t,Ca);var n=Da(t.firestore,ja),r=Ka(n),i=new Yu(n);return function(t,n){var r=this,i=new er;return t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(r,void 0,void 0,function(){var r;return(0,e.__generator)(this,function(o){switch(o.label){case 0:return r=function(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,function(t,e){var n=m(t);return n.persistence.runTransaction("read document","readonly",function(t){return n.Mn.mn(t,e)})}(t,n)];case 1:return(o=e.sent()).isFoundDocument()?r.resolve(o):o.isNoDocument()?r.resolve(null):r.reject(new u(a.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.)")),[3,3];case 2:return i=e.sent(),o=Qo(i,"Failed to get document '"+n+" from cache"),r.reject(o),[3,3];case 3:return[2]}})})},[4,sa(t)];case 1:return[2,r.apply(void 0,[o.sent(),n,i])]}})})}),i.promise}(r,t._key).then(function(e){return new Du(n,i,t._key,e,new Nu(null!==e&&e.hasLocalMutations,!0),t.converter)})}(this._delegate):"server"===(null==t?void 0:t.source)?function(t){t=Da(t,Ca);var e=Da(t.firestore,ja);return ha(Ka(e),t._key,{source:"server"}).then(function(n){return tc(e,t,n)})}(this._delegate):function(t){t=Da(t,Ca);var e=Da(t.firestore,ja);return ha(Ka(e),t._key).then(function(n){return tc(e,t,n)})}(this._delegate)).then(function(t){return new vc(n.firestore,new Du(n.firestore._delegate,n._userDataWriter,t._key,t._document,t.metadata,n._delegate.converter))})},t.prototype.withConverter=function(e){return new t(this.firestore,e?this._delegate.withConverter(fc.nu(this.firestore,e)):this._delegate.withConverter(null))},t}();function dc(t,e,n){return t.message=t.message.replace(e,n),t}function pc(t){for(var e=0,n=t;e<n.length;e++){var r=n[e];if("object"==o(r)&&!qa(r))return r}return{}}function yc(t,e){var n,r,i;return{next:function(t){i.next&&i.next(e(t))},error:null===(n=(i=qa(t[0])?t[0]:qa(t[1])?t[1]:"function"==typeof t[0]?{next:t[0],error:t[1],complete:t[2]}:{next:t[1],error:t[2],complete:t[3]}).error)||void 0===n?void 0:n.bind(i),complete:null===(r=i.complete)||void 0===r?void 0:r.bind(i)}}exports.H=lc;var vc=function(){function t(t,e){this._firestore=t,this._delegate=e}return Object.defineProperty(t.prototype,"ref",{get:function(){return new lc(this._firestore,this._delegate.ref)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"id",{get:function(){return this._delegate.id},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"metadata",{get:function(){return this._delegate.metadata},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"exists",{get:function(){return this._delegate.exists()},enumerable:!1,configurable:!0}),t.prototype.data=function(t){return this._delegate.data(t)},t.prototype.get=function(t,e){return this._delegate.get(t,e)},t.prototype.isEqual=function(t){return Cu(this._delegate,t._delegate)},t}(),mc=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return(0,e.__extends)(n,t),n.prototype.data=function(t){return this._delegate.data(t)},n}(vc),gc=function(){function t(t,e){this.firestore=t,this._delegate=e,this._userDataWriter=new ac(t)}return t.prototype.where=function(e,n,r){try{return new t(this.firestore,Ou(this._delegate,function(t,e,n){var r=e,i=Su("where",t);return new Pu(i,r,n)}(e,n,r)))}catch(e){throw dc(e,/(orderBy|where)\(\)/,"Query.$1()")}},t.prototype.orderBy=function(e,n){try{return new t(this.firestore,Ou(this._delegate,function(t,e){void 0===e&&(e="asc");var n=e,r=Su("orderBy",t);return new Fu(r,n)}(e,n)))}catch(e){throw dc(e,/(orderBy|where)\(\)/,"Query.$1()")}},t.prototype.limit=function(e){try{return new t(this.firestore,Ou(this._delegate,function(t){return Aa("limit",t),new Mu("limit",t,"F")}(e)))}catch(e){throw dc(e,"limit()","Query.limit()")}},t.prototype.limitToLast=function(e){try{return new t(this.firestore,Ou(this._delegate,function(t){return Aa("limitToLast",t),new Mu("limitToLast",t,"L")}(e)))}catch(e){throw dc(e,"limitToLast()","Query.limitToLast()")}},t.prototype.startAt=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];try{return new t(this.firestore,Ou(this._delegate,function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return new Vu("startAt",t,!0)}.apply(void 0,e)))}catch(e){throw dc(e,"startAt()","Query.startAt()")}},t.prototype.startAfter=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];try{return new t(this.firestore,Ou(this._delegate,function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return new Vu("startAfter",t,!1)}.apply(void 0,e)))}catch(e){throw dc(e,"startAfter()","Query.startAfter()")}},t.prototype.endBefore=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];try{return new t(this.firestore,Ou(this._delegate,function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return new qu("endBefore",t,!0)}.apply(void 0,e)))}catch(e){throw dc(e,"endBefore()","Query.endBefore()")}},t.prototype.endAt=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];try{return new t(this.firestore,Ou(this._delegate,function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return new qu("endAt",t,!1)}.apply(void 0,e)))}catch(e){throw dc(e,"endAt()","Query.endAt()")}},t.prototype.isEqual=function(t){return Ma(this._delegate,t._delegate)},t.prototype.get=function(t){var n=this;return("cache"===(null==t?void 0:t.source)?function(t){t=Da(t,Ra);var n=Da(t.firestore,ja),r=Ka(n),i=new Yu(n);return function(t,n){var r=this,i=new er;return t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(r,void 0,void 0,function(){var r;return(0,e.__generator)(this,function(o){switch(o.label){case 0:return r=function(t,n,r){return(0,e.__awaiter)(this,void 0,void 0,function(){var i,o,s,a,u;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,ki(t,n,!0)];case 1:return u=e.sent(),i=new cs(n,u.Bn),o=i._o(u.documents),s=i.applyChanges(o,!1),r.resolve(s.snapshot),[3,3];case 2:return a=e.sent(),u=Qo(a,"Failed to execute query '"+n+" against cache"),r.reject(u),[3,3];case 3:return[2]}})})},[4,sa(t)];case 1:return[2,r.apply(void 0,[o.sent(),n,i])]}})})}),i.promise}(r,t._query).then(function(e){return new xu(n,i,t,e)})}(this._delegate):"server"===(null==t?void 0:t.source)?function(t){t=Da(t,Ra);var e=Da(t.firestore,ja),n=Ka(e),r=new Yu(e);return fa(n,t._query,{source:"server"}).then(function(n){return new xu(e,r,t,n)})}(this._delegate):function(t){t=Da(t,Ra);var e=Da(t.firestore,ja),n=Ka(e),r=new Yu(e);return Ru(t._query),fa(n,t._query).then(function(n){return new xu(e,r,t,n)})}(this._delegate)).then(function(t){return new wc(n.firestore,new xu(n.firestore._delegate,n._userDataWriter,n._delegate,t._snapshot))})},t.prototype.onSnapshot=function(){for(var t=this,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=pc(e),i=yc(e,function(e){return new wc(t.firestore,new xu(t.firestore._delegate,t._userDataWriter,t._delegate,e._snapshot))});return Ju(this._delegate,r,i)},t.prototype.withConverter=function(e){return new t(this.firestore,e?this._delegate.withConverter(fc.nu(this.firestore,e)):this._delegate.withConverter(null))},t}(),_c=function(){function t(t,e){this._firestore=t,this._delegate=e}return Object.defineProperty(t.prototype,"type",{get:function(){return this._delegate.type},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"doc",{get:function(){return new mc(this._firestore,this._delegate.doc)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"oldIndex",{get:function(){return this._delegate.oldIndex},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"newIndex",{get:function(){return this._delegate.newIndex},enumerable:!1,configurable:!0}),t}(),wc=function(){function t(t,e){this._firestore=t,this._delegate=e}return Object.defineProperty(t.prototype,"query",{get:function(){return new gc(this._firestore,this._delegate.query)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"metadata",{get:function(){return this._delegate.metadata},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"size",{get:function(){return this._delegate.size},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"empty",{get:function(){return this._delegate.empty},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"docs",{get:function(){var t=this;return this._delegate.docs.map(function(e){return new mc(t._firestore,e)})},enumerable:!1,configurable:!0}),t.prototype.docChanges=function(t){var e=this;return this._delegate.docChanges(t).map(function(t){return new _c(e._firestore,t)})},t.prototype.forEach=function(t,e){var n=this;this._delegate.forEach(function(r){t.call(e,new mc(n._firestore,r))})},t.prototype.isEqual=function(t){return Cu(this._delegate,t._delegate)},t}(),bc=function(t){function n(e,n){var r=this;return(r=t.call(this,e,n)||this).firestore=e,r._delegate=n,r}return(0,e.__extends)(n,t),Object.defineProperty(n.prototype,"id",{get:function(){return this._delegate.id},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"path",{get:function(){return this._delegate.path},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"parent",{get:function(){var t=this._delegate.parent;return t?new lc(this.firestore,t):null},enumerable:!1,configurable:!0}),n.prototype.doc=function(t){try{return new lc(this.firestore,void 0===t?Pa(this._delegate):Pa(this._delegate,t))}catch(t){throw dc(t,"doc()","CollectionReference.doc()")}},n.prototype.add=function(t){var e=this;return function(t,e){var n=Da(t.firestore,ja),r=Pa(t),i=Qu(t.converter,e);return Zu(n,[iu(ru(t.firestore),"addDoc",r._key,i,null!==t.converter,{}).toMutation(r._key,ue.exists(!1))]).then(function(){return r})}(this._delegate,t).then(function(t){return new lc(e.firestore,t)})},n.prototype.isEqual=function(t){return Fa(this._delegate,t._delegate)},n.prototype.withConverter=function(t){return new n(this.firestore,t?this._delegate.withConverter(fc.nu(this.firestore,t)):this._delegate.withConverter(null))},n}(gc);function Ic(t){return Da(t,Ca)}exports.i=bc,exports.s=wc,exports.e=gc,exports.t=mc,exports.Z=vc;var Ec=function(){function t(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];this._delegate=new(Wa.bind.apply(Wa,(0,e.__spreadArray)([void 0],t)))}return t.documentId=function(){return new t(C.keyField().canonicalString())},t.prototype.isEqual=function(t){return(t=(0,n.getModularInstance)(t))instanceof Wa&&this._delegate._internalPath.isEqual(t._internalPath)},t}(),Tc=function(){function t(t){this._delegate=t}return t.serverTimestamp=function(){var e=new au("serverTimestamp");return e._methodName="FieldValue.serverTimestamp",new t(e)},t.delete=function(){var e=new ou("deleteField");return e._methodName="FieldValue.delete",new t(e)},t.arrayUnion=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return new uu("arrayUnion",t)}.apply(void 0,e);return r._methodName="FieldValue.arrayUnion",new t(r)},t.arrayRemove=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var r=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return new cu("arrayRemove",t)}.apply(void 0,e);return r._methodName="FieldValue.arrayRemove",new t(r)},t.increment=function(e){var n=new hu("increment",e);return n._methodName="FieldValue.increment",new t(n)},t.prototype.isEqual=function(t){return this._delegate.isEqual(t._delegate)},t}();function Sc(t){return function(t,n){var r=Ka(t=Da(t,ja)),i=new Ua;return function(t,n,r,i){var o=this,s=function(t,e){return function(t,e){return new Xs(t,e)}(function(t,e){if(t instanceof Uint8Array)return Ys(t,e);if(t instanceof ArrayBuffer)return Ys(new Uint8Array(t),e);if(t instanceof ReadableStream)return t.getReader();throw new Error("Source of `toByteStreamReader` has to be a ArrayBuffer or ReadableStream")}("string"==typeof t?(new TextEncoder).encode(t):t),e)}(r,ho(n));t.asyncQueue.enqueueAndForget(function(){return(0,e.__awaiter)(o,void 0,void 0,function(){var n;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return n=Gs,[4,ua(t)];case 1:return n.apply(void 0,[e.sent(),s,i]),[2]}})})})}(r,t._databaseId,n,i),i}(this._delegate,t)}function Nc(t){var n,r,i=this;return(n=this._delegate,r=t,function(t,n){var r=this;return t.asyncQueue.enqueue(function(){return(0,e.__awaiter)(r,void 0,void 0,function(){var r;return(0,e.__generator)(this,function(e){switch(e.label){case 0:return r=function(t,e){var n=m(t);return n.persistence.runTransaction("Get named query","readonly",function(t){return n.Ke.getNamedQuery(t,e)})},[4,sa(t)];case 1:return[2,r.apply(void 0,[e.sent(),n])]}})})})}(Ka(n=Da(n,ja)),r).then(function(t){return t?new Ra(n,null,t.query):null})).then(function(t){return t?new gc(i,t):null})}exports.c=Tc,exports.o=Ec;
494
+ },{"tslib":"vCxL","@firebase/util":"KxmD","@firebase/logger":"TUpU","@firebase/webchannel-wrapper":"ueHA","process":"pBGv"}],"oyBH":[function(require,module,exports) {
495
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.registerFirestore=o;var e=i(require("@firebase/app")),r=require("./prebuilt-2d830653-6eee25bb.js"),t=require("@firebase/component");function i(e){return e&&e.__esModule?e:{default:e}}require("tslib"),require("@firebase/util"),require("@firebase/logger"),require("@firebase/webchannel-wrapper");var n={Firestore:r.K,GeoPoint:r.C,Timestamp:r.M,Blob:r.L,Transaction:r.W,WriteBatch:r.G,DocumentReference:r.H,DocumentSnapshot:r.Z,Query:r.e,QueryDocumentSnapshot:r.t,QuerySnapshot:r.s,CollectionReference:r.i,FieldPath:r.o,FieldValue:r.c,setLogLevel:r.j,CACHE_SIZE_UNLIMITED:r.E};function o(e){!function(e,i){e.INTERNAL.registerComponent(new t.Component("firestore",function(e){return function(e,t){return new r.K(e,new r.T(e,t),new r.U)}(e.getProvider("app").getImmediate(),e.getProvider("auth-internal"))},"PUBLIC").setServiceProps(Object.assign({},n)))}(e),e.registerVersion("@firebase/firestore","2.4.1")}o(e.default);
496
+ },{"@firebase/app":"VxYX","./prebuilt-2d830653-6eee25bb.js":"pbUl","@firebase/component":"sLOu","tslib":"vCxL","@firebase/util":"KxmD","@firebase/logger":"TUpU","@firebase/webchannel-wrapper":"ueHA"}],"vHL5":[function(require,module,exports) {
497
497
  "use strict";require("@firebase/firestore");
498
498
  },{"@firebase/firestore":"oyBH"}],"TX5A":[function(require,module,exports) {
499
499
  "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.config=void 0,exports.config={apiKey:"AIzaSyB0TkZ83Fj0CIzn8AAmE-Osc92s3ER8hy8",authDomain:"neurosity-device.firebaseapp.com",databaseURL:"https://neurosity-device.firebaseio.com",projectId:"neurosity-device",storageBucket:"neurosity-device.appspot.com",messagingSenderId:"212595049674"};
@@ -631,7 +631,7 @@ var global = arguments[3];
631
631
  var t=arguments[3],r=require("base64-js"),e=require("ieee754"),n=require("isarray");function i(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(r){return!1}}function o(){return f.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function u(t,r){if(o()<r)throw new RangeError("Invalid typed array length");return f.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(r)).__proto__=f.prototype:(null===t&&(t=new f(r)),t.length=r),t}function f(t,r,e){if(!(f.TYPED_ARRAY_SUPPORT||this instanceof f))return new f(t,r,e);if("number"==typeof t){if("string"==typeof r)throw new Error("If encoding is specified then the first argument must be a string");return c(this,t)}return s(this,t,r,e)}function s(t,r,e,n){if("number"==typeof r)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&r instanceof ArrayBuffer?g(t,r,e,n):"string"==typeof r?l(t,r,e):y(t,r)}function h(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function a(t,r,e,n){return h(r),r<=0?u(t,r):void 0!==e?"string"==typeof n?u(t,r).fill(e,n):u(t,r).fill(e):u(t,r)}function c(t,r){if(h(r),t=u(t,r<0?0:0|w(r)),!f.TYPED_ARRAY_SUPPORT)for(var e=0;e<r;++e)t[e]=0;return t}function l(t,r,e){if("string"==typeof e&&""!==e||(e="utf8"),!f.isEncoding(e))throw new TypeError('"encoding" must be a valid string encoding');var n=0|v(r,e),i=(t=u(t,n)).write(r,e);return i!==n&&(t=t.slice(0,i)),t}function p(t,r){var e=r.length<0?0:0|w(r.length);t=u(t,e);for(var n=0;n<e;n+=1)t[n]=255&r[n];return t}function g(t,r,e,n){if(r.byteLength,e<0||r.byteLength<e)throw new RangeError("'offset' is out of bounds");if(r.byteLength<e+(n||0))throw new RangeError("'length' is out of bounds");return r=void 0===e&&void 0===n?new Uint8Array(r):void 0===n?new Uint8Array(r,e):new Uint8Array(r,e,n),f.TYPED_ARRAY_SUPPORT?(t=r).__proto__=f.prototype:t=p(t,r),t}function y(t,r){if(f.isBuffer(r)){var e=0|w(r.length);return 0===(t=u(t,e)).length?t:(r.copy(t,0,0,e),t)}if(r){if("undefined"!=typeof ArrayBuffer&&r.buffer instanceof ArrayBuffer||"length"in r)return"number"!=typeof r.length||W(r.length)?u(t,0):p(t,r);if("Buffer"===r.type&&n(r.data))return p(t,r.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}function w(t){if(t>=o())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o().toString(16)+" bytes");return 0|t}function d(t){return+t!=t&&(t=0),f.alloc(+t)}function v(t,r){if(f.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var e=t.length;if(0===e)return 0;for(var n=!1;;)switch(r){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":case void 0:return $(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*e;case"hex":return e>>>1;case"base64":return K(t).length;default:if(n)return $(t).length;r=(""+r).toLowerCase(),n=!0}}function E(t,r,e){var n=!1;if((void 0===r||r<0)&&(r=0),r>this.length)return"";if((void 0===e||e>this.length)&&(e=this.length),e<=0)return"";if((e>>>=0)<=(r>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return x(this,r,e);case"utf8":case"utf-8":return Y(this,r,e);case"ascii":return L(this,r,e);case"latin1":case"binary":return D(this,r,e);case"base64":return S(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function b(t,r,e){var n=t[r];t[r]=t[e],t[e]=n}function R(t,r,e,n,i){if(0===t.length)return-1;if("string"==typeof e?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,isNaN(e)&&(e=i?0:t.length-1),e<0&&(e=t.length+e),e>=t.length){if(i)return-1;e=t.length-1}else if(e<0){if(!i)return-1;e=0}if("string"==typeof r&&(r=f.from(r,n)),f.isBuffer(r))return 0===r.length?-1:_(t,r,e,n,i);if("number"==typeof r)return r&=255,f.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,r,e):Uint8Array.prototype.lastIndexOf.call(t,r,e):_(t,[r],e,n,i);throw new TypeError("val must be string, number or Buffer")}function _(t,r,e,n,i){var o,u=1,f=t.length,s=r.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||r.length<2)return-1;u=2,f/=2,s/=2,e/=2}function h(t,r){return 1===u?t[r]:t.readUInt16BE(r*u)}if(i){var a=-1;for(o=e;o<f;o++)if(h(t,o)===h(r,-1===a?0:o-a)){if(-1===a&&(a=o),o-a+1===s)return a*u}else-1!==a&&(o-=o-a),a=-1}else for(e+s>f&&(e=f-s),o=e;o>=0;o--){for(var c=!0,l=0;l<s;l++)if(h(t,o+l)!==h(r,l)){c=!1;break}if(c)return o}return-1}function A(t,r,e,n){e=Number(e)||0;var i=t.length-e;n?(n=Number(n))>i&&(n=i):n=i;var o=r.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var u=0;u<n;++u){var f=parseInt(r.substr(2*u,2),16);if(isNaN(f))return u;t[e+u]=f}return u}function m(t,r,e,n){return Q($(r,t.length-e),t,e,n)}function P(t,r,e,n){return Q(G(r),t,e,n)}function T(t,r,e,n){return P(t,r,e,n)}function B(t,r,e,n){return Q(K(r),t,e,n)}function U(t,r,e,n){return Q(H(r,t.length-e),t,e,n)}function S(t,e,n){return 0===e&&n===t.length?r.fromByteArray(t):r.fromByteArray(t.slice(e,n))}function Y(t,r,e){e=Math.min(t.length,e);for(var n=[],i=r;i<e;){var o,u,f,s,h=t[i],a=null,c=h>239?4:h>223?3:h>191?2:1;if(i+c<=e)switch(c){case 1:h<128&&(a=h);break;case 2:128==(192&(o=t[i+1]))&&(s=(31&h)<<6|63&o)>127&&(a=s);break;case 3:o=t[i+1],u=t[i+2],128==(192&o)&&128==(192&u)&&(s=(15&h)<<12|(63&o)<<6|63&u)>2047&&(s<55296||s>57343)&&(a=s);break;case 4:o=t[i+1],u=t[i+2],f=t[i+3],128==(192&o)&&128==(192&u)&&128==(192&f)&&(s=(15&h)<<18|(63&o)<<12|(63&u)<<6|63&f)>65535&&s<1114112&&(a=s)}null===a?(a=65533,c=1):a>65535&&(a-=65536,n.push(a>>>10&1023|55296),a=56320|1023&a),n.push(a),i+=c}return O(n)}exports.Buffer=f,exports.SlowBuffer=d,exports.INSPECT_MAX_BYTES=50,f.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:i(),exports.kMaxLength=o(),f.poolSize=8192,f._augment=function(t){return t.__proto__=f.prototype,t},f.from=function(t,r,e){return s(null,t,r,e)},f.TYPED_ARRAY_SUPPORT&&(f.prototype.__proto__=Uint8Array.prototype,f.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&f[Symbol.species]===f&&Object.defineProperty(f,Symbol.species,{value:null,configurable:!0})),f.alloc=function(t,r,e){return a(null,t,r,e)},f.allocUnsafe=function(t){return c(null,t)},f.allocUnsafeSlow=function(t){return c(null,t)},f.isBuffer=function(t){return!(null==t||!t._isBuffer)},f.compare=function(t,r){if(!f.isBuffer(t)||!f.isBuffer(r))throw new TypeError("Arguments must be Buffers");if(t===r)return 0;for(var e=t.length,n=r.length,i=0,o=Math.min(e,n);i<o;++i)if(t[i]!==r[i]){e=t[i],n=r[i];break}return e<n?-1:n<e?1:0},f.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},f.concat=function(t,r){if(!n(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return f.alloc(0);var e;if(void 0===r)for(r=0,e=0;e<t.length;++e)r+=t[e].length;var i=f.allocUnsafe(r),o=0;for(e=0;e<t.length;++e){var u=t[e];if(!f.isBuffer(u))throw new TypeError('"list" argument must be an Array of Buffers');u.copy(i,o),o+=u.length}return i},f.byteLength=v,f.prototype._isBuffer=!0,f.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var r=0;r<t;r+=2)b(this,r,r+1);return this},f.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var r=0;r<t;r+=4)b(this,r,r+3),b(this,r+1,r+2);return this},f.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var r=0;r<t;r+=8)b(this,r,r+7),b(this,r+1,r+6),b(this,r+2,r+5),b(this,r+3,r+4);return this},f.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?Y(this,0,t):E.apply(this,arguments)},f.prototype.equals=function(t){if(!f.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===f.compare(this,t)},f.prototype.inspect=function(){var t="",r=exports.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(t+=" ... ")),"<Buffer "+t+">"},f.prototype.compare=function(t,r,e,n,i){if(!f.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===r&&(r=0),void 0===e&&(e=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),r<0||e>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&r>=e)return 0;if(n>=i)return-1;if(r>=e)return 1;if(this===t)return 0;for(var o=(i>>>=0)-(n>>>=0),u=(e>>>=0)-(r>>>=0),s=Math.min(o,u),h=this.slice(n,i),a=t.slice(r,e),c=0;c<s;++c)if(h[c]!==a[c]){o=h[c],u=a[c];break}return o<u?-1:u<o?1:0},f.prototype.includes=function(t,r,e){return-1!==this.indexOf(t,r,e)},f.prototype.indexOf=function(t,r,e){return R(this,t,r,e,!0)},f.prototype.lastIndexOf=function(t,r,e){return R(this,t,r,e,!1)},f.prototype.write=function(t,r,e,n){if(void 0===r)n="utf8",e=this.length,r=0;else if(void 0===e&&"string"==typeof r)n=r,e=this.length,r=0;else{if(!isFinite(r))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");r|=0,isFinite(e)?(e|=0,void 0===n&&(n="utf8")):(n=e,e=void 0)}var i=this.length-r;if((void 0===e||e>i)&&(e=i),t.length>0&&(e<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return A(this,t,r,e);case"utf8":case"utf-8":return m(this,t,r,e);case"ascii":return P(this,t,r,e);case"latin1":case"binary":return T(this,t,r,e);case"base64":return B(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return U(this,t,r,e);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},f.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var I=4096;function O(t){var r=t.length;if(r<=I)return String.fromCharCode.apply(String,t);for(var e="",n=0;n<r;)e+=String.fromCharCode.apply(String,t.slice(n,n+=I));return e}function L(t,r,e){var n="";e=Math.min(t.length,e);for(var i=r;i<e;++i)n+=String.fromCharCode(127&t[i]);return n}function D(t,r,e){var n="";e=Math.min(t.length,e);for(var i=r;i<e;++i)n+=String.fromCharCode(t[i]);return n}function x(t,r,e){var n=t.length;(!r||r<0)&&(r=0),(!e||e<0||e>n)&&(e=n);for(var i="",o=r;o<e;++o)i+=Z(t[o]);return i}function C(t,r,e){for(var n=t.slice(r,e),i="",o=0;o<n.length;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function M(t,r,e){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+r>e)throw new RangeError("Trying to access beyond buffer length")}function k(t,r,e,n,i,o){if(!f.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>i||r<o)throw new RangeError('"value" argument is out of bounds');if(e+n>t.length)throw new RangeError("Index out of range")}function N(t,r,e,n){r<0&&(r=65535+r+1);for(var i=0,o=Math.min(t.length-e,2);i<o;++i)t[e+i]=(r&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function z(t,r,e,n){r<0&&(r=4294967295+r+1);for(var i=0,o=Math.min(t.length-e,4);i<o;++i)t[e+i]=r>>>8*(n?i:3-i)&255}function F(t,r,e,n,i,o){if(e+n>t.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function j(t,r,n,i,o){return o||F(t,r,n,4,3.4028234663852886e38,-3.4028234663852886e38),e.write(t,r,n,i,23,4),n+4}function q(t,r,n,i,o){return o||F(t,r,n,8,1.7976931348623157e308,-1.7976931348623157e308),e.write(t,r,n,i,52,8),n+8}f.prototype.slice=function(t,r){var e,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(r=void 0===r?n:~~r)<0?(r+=n)<0&&(r=0):r>n&&(r=n),r<t&&(r=t),f.TYPED_ARRAY_SUPPORT)(e=this.subarray(t,r)).__proto__=f.prototype;else{var i=r-t;e=new f(i,void 0);for(var o=0;o<i;++o)e[o]=this[o+t]}return e},f.prototype.readUIntLE=function(t,r,e){t|=0,r|=0,e||M(t,r,this.length);for(var n=this[t],i=1,o=0;++o<r&&(i*=256);)n+=this[t+o]*i;return n},f.prototype.readUIntBE=function(t,r,e){t|=0,r|=0,e||M(t,r,this.length);for(var n=this[t+--r],i=1;r>0&&(i*=256);)n+=this[t+--r]*i;return n},f.prototype.readUInt8=function(t,r){return r||M(t,1,this.length),this[t]},f.prototype.readUInt16LE=function(t,r){return r||M(t,2,this.length),this[t]|this[t+1]<<8},f.prototype.readUInt16BE=function(t,r){return r||M(t,2,this.length),this[t]<<8|this[t+1]},f.prototype.readUInt32LE=function(t,r){return r||M(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},f.prototype.readUInt32BE=function(t,r){return r||M(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},f.prototype.readIntLE=function(t,r,e){t|=0,r|=0,e||M(t,r,this.length);for(var n=this[t],i=1,o=0;++o<r&&(i*=256);)n+=this[t+o]*i;return n>=(i*=128)&&(n-=Math.pow(2,8*r)),n},f.prototype.readIntBE=function(t,r,e){t|=0,r|=0,e||M(t,r,this.length);for(var n=r,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*r)),o},f.prototype.readInt8=function(t,r){return r||M(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},f.prototype.readInt16LE=function(t,r){r||M(t,2,this.length);var e=this[t]|this[t+1]<<8;return 32768&e?4294901760|e:e},f.prototype.readInt16BE=function(t,r){r||M(t,2,this.length);var e=this[t+1]|this[t]<<8;return 32768&e?4294901760|e:e},f.prototype.readInt32LE=function(t,r){return r||M(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},f.prototype.readInt32BE=function(t,r){return r||M(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},f.prototype.readFloatLE=function(t,r){return r||M(t,4,this.length),e.read(this,t,!0,23,4)},f.prototype.readFloatBE=function(t,r){return r||M(t,4,this.length),e.read(this,t,!1,23,4)},f.prototype.readDoubleLE=function(t,r){return r||M(t,8,this.length),e.read(this,t,!0,52,8)},f.prototype.readDoubleBE=function(t,r){return r||M(t,8,this.length),e.read(this,t,!1,52,8)},f.prototype.writeUIntLE=function(t,r,e,n){(t=+t,r|=0,e|=0,n)||k(this,t,r,e,Math.pow(2,8*e)-1,0);var i=1,o=0;for(this[r]=255&t;++o<e&&(i*=256);)this[r+o]=t/i&255;return r+e},f.prototype.writeUIntBE=function(t,r,e,n){(t=+t,r|=0,e|=0,n)||k(this,t,r,e,Math.pow(2,8*e)-1,0);var i=e-1,o=1;for(this[r+i]=255&t;--i>=0&&(o*=256);)this[r+i]=t/o&255;return r+e},f.prototype.writeUInt8=function(t,r,e){return t=+t,r|=0,e||k(this,t,r,1,255,0),f.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[r]=255&t,r+1},f.prototype.writeUInt16LE=function(t,r,e){return t=+t,r|=0,e||k(this,t,r,2,65535,0),f.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):N(this,t,r,!0),r+2},f.prototype.writeUInt16BE=function(t,r,e){return t=+t,r|=0,e||k(this,t,r,2,65535,0),f.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):N(this,t,r,!1),r+2},f.prototype.writeUInt32LE=function(t,r,e){return t=+t,r|=0,e||k(this,t,r,4,4294967295,0),f.TYPED_ARRAY_SUPPORT?(this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=255&t):z(this,t,r,!0),r+4},f.prototype.writeUInt32BE=function(t,r,e){return t=+t,r|=0,e||k(this,t,r,4,4294967295,0),f.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):z(this,t,r,!1),r+4},f.prototype.writeIntLE=function(t,r,e,n){if(t=+t,r|=0,!n){var i=Math.pow(2,8*e-1);k(this,t,r,e,i-1,-i)}var o=0,u=1,f=0;for(this[r]=255&t;++o<e&&(u*=256);)t<0&&0===f&&0!==this[r+o-1]&&(f=1),this[r+o]=(t/u>>0)-f&255;return r+e},f.prototype.writeIntBE=function(t,r,e,n){if(t=+t,r|=0,!n){var i=Math.pow(2,8*e-1);k(this,t,r,e,i-1,-i)}var o=e-1,u=1,f=0;for(this[r+o]=255&t;--o>=0&&(u*=256);)t<0&&0===f&&0!==this[r+o+1]&&(f=1),this[r+o]=(t/u>>0)-f&255;return r+e},f.prototype.writeInt8=function(t,r,e){return t=+t,r|=0,e||k(this,t,r,1,127,-128),f.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[r]=255&t,r+1},f.prototype.writeInt16LE=function(t,r,e){return t=+t,r|=0,e||k(this,t,r,2,32767,-32768),f.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):N(this,t,r,!0),r+2},f.prototype.writeInt16BE=function(t,r,e){return t=+t,r|=0,e||k(this,t,r,2,32767,-32768),f.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):N(this,t,r,!1),r+2},f.prototype.writeInt32LE=function(t,r,e){return t=+t,r|=0,e||k(this,t,r,4,2147483647,-2147483648),f.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24):z(this,t,r,!0),r+4},f.prototype.writeInt32BE=function(t,r,e){return t=+t,r|=0,e||k(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),f.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):z(this,t,r,!1),r+4},f.prototype.writeFloatLE=function(t,r,e){return j(this,t,r,!0,e)},f.prototype.writeFloatBE=function(t,r,e){return j(this,t,r,!1,e)},f.prototype.writeDoubleLE=function(t,r,e){return q(this,t,r,!0,e)},f.prototype.writeDoubleBE=function(t,r,e){return q(this,t,r,!1,e)},f.prototype.copy=function(t,r,e,n){if(e||(e=0),n||0===n||(n=this.length),r>=t.length&&(r=t.length),r||(r=0),n>0&&n<e&&(n=e),n===e)return 0;if(0===t.length||0===this.length)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(e<0||e>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-r<n-e&&(n=t.length-r+e);var i,o=n-e;if(this===t&&e<r&&r<n)for(i=o-1;i>=0;--i)t[i+r]=this[i+e];else if(o<1e3||!f.TYPED_ARRAY_SUPPORT)for(i=0;i<o;++i)t[i+r]=this[i+e];else Uint8Array.prototype.set.call(t,this.subarray(e,e+o),r);return o},f.prototype.fill=function(t,r,e,n){if("string"==typeof t){if("string"==typeof r?(n=r,r=0,e=this.length):"string"==typeof e&&(n=e,e=this.length),1===t.length){var i=t.charCodeAt(0);i<256&&(t=i)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!f.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof t&&(t&=255);if(r<0||this.length<r||this.length<e)throw new RangeError("Out of range index");if(e<=r)return this;var o;if(r>>>=0,e=void 0===e?this.length:e>>>0,t||(t=0),"number"==typeof t)for(o=r;o<e;++o)this[o]=t;else{var u=f.isBuffer(t)?t:$(new f(t,n).toString()),s=u.length;for(o=0;o<e-r;++o)this[o+r]=u[o%s]}return this};var V=/[^+\/0-9A-Za-z-_]/g;function X(t){if((t=J(t).replace(V,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}function J(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function Z(t){return t<16?"0"+t.toString(16):t.toString(16)}function $(t,r){var e;r=r||1/0;for(var n=t.length,i=null,o=[],u=0;u<n;++u){if((e=t.charCodeAt(u))>55295&&e<57344){if(!i){if(e>56319){(r-=3)>-1&&o.push(239,191,189);continue}if(u+1===n){(r-=3)>-1&&o.push(239,191,189);continue}i=e;continue}if(e<56320){(r-=3)>-1&&o.push(239,191,189),i=e;continue}e=65536+(i-55296<<10|e-56320)}else i&&(r-=3)>-1&&o.push(239,191,189);if(i=null,e<128){if((r-=1)<0)break;o.push(e)}else if(e<2048){if((r-=2)<0)break;o.push(e>>6|192,63&e|128)}else if(e<65536){if((r-=3)<0)break;o.push(e>>12|224,e>>6&63|128,63&e|128)}else{if(!(e<1114112))throw new Error("Invalid code point");if((r-=4)<0)break;o.push(e>>18|240,e>>12&63|128,e>>6&63|128,63&e|128)}}return o}function G(t){for(var r=[],e=0;e<t.length;++e)r.push(255&t.charCodeAt(e));return r}function H(t,r){for(var e,n,i,o=[],u=0;u<t.length&&!((r-=2)<0);++u)n=(e=t.charCodeAt(u))>>8,i=e%256,o.push(i),o.push(n);return o}function K(t){return r.toByteArray(X(t))}function Q(t,r,e,n){for(var i=0;i<n&&!(i+e>=r.length||i>=t.length);++i)r[i+e]=t[i];return i}function W(t){return t!=t}
632
632
  },{"base64-js":"yh9p","ieee754":"JgNJ","isarray":"wvRa","buffer":"peL6"}],"dskh":[function(require,module,exports) {
633
633
 
634
- console.log("********* buffer start *********");const t=require("base64-js"),e=require("ieee754"),r="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;exports.Buffer=f,exports.SlowBuffer=d,exports.INSPECT_MAX_BYTES=50;const n=2147483647;function o(){try{const e=new Uint8Array(1),r={foo:function(){return 42}};return Object.setPrototypeOf(r,Uint8Array.prototype),Object.setPrototypeOf(e,r),42===e.foo()}catch(t){return!1}}function i(t){if(t>n)throw new RangeError('The value "'+t+'" is invalid for option "size"');const e=new Uint8Array(t);return Object.setPrototypeOf(e,f.prototype),e}function f(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return c(t)}return s(t,e,r)}function s(t,e,r){if("string"==typeof t)return l(t,e);if(ArrayBuffer.isView(t))return p(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(nt(t,ArrayBuffer)||t&&nt(t.buffer,ArrayBuffer))return g(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(nt(t,SharedArrayBuffer)||t&&nt(t.buffer,SharedArrayBuffer)))return g(t,e,r);if(console.log("********* buffer line 142 *********"),"number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return f.from(n,e,r);const o=y(t);if(o)return o;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return f.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function u(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function h(t,e,r){return u(t),t<=0?i(t):void 0!==e?"string"==typeof r?i(t).fill(e,r):i(t).fill(e):i(t)}function c(t){return u(t),i(t<0?0:0|w(t))}function l(t,e){if("string"==typeof e&&""!==e||(e="utf8"),!f.isEncoding(e))throw new TypeError("Unknown encoding: "+e);const r=0|b(t,e);let n=i(r);const o=n.write(t,e);return o!==r&&(n=n.slice(0,o)),n}function a(t){const e=t.length<0?0:0|w(t.length),r=i(e);for(let n=0;n<e;n+=1)r[n]=255&t[n];return r}function p(t){if(nt(t,Uint8Array)){const e=new Uint8Array(t);return g(e.buffer,e.byteOffset,e.byteLength)}return a(t)}function g(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r),Object.setPrototypeOf(n,f.prototype),n}function y(t){if(f.isBuffer(t)){const e=0|w(t.length),r=i(e);return 0===r.length?r:(t.copy(r,0,0,e),r)}return void 0!==t.length?"number"!=typeof t.length||ot(t.length)?i(0):a(t):"Buffer"===t.type&&Array.isArray(t.data)?a(t.data):void 0}function w(t){if(t>=n)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+n.toString(16)+" bytes");return 0|t}function d(t){return+t!=t&&(t=0),f.alloc(+t)}function b(t,e){if(f.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||nt(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);const r=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let o=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return K(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return et(t).length;default:if(o)return n?-1:K(t).length;e=(""+e).toLowerCase(),o=!0}}function B(t,e,r){let n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return P(this,e,r);case"utf8":case"utf-8":return L(this,e,r);case"ascii":return x(this,e,r);case"latin1":case"binary":return $(this,e,r);case"base64":return O(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function E(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}function m(t,e,r,n,o){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),ot(r=+r)&&(r=o?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(o)return-1;r=t.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof e&&(e=f.from(e,n)),f.isBuffer(e))return 0===e.length?-1:I(t,e,r,n,o);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):I(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function I(t,e,r,n,o){let i,f=1,s=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;f=2,s/=2,u/=2,r/=2}function h(t,e){return 1===f?t[e]:t.readUInt16BE(e*f)}if(o){let n=-1;for(i=r;i<s;i++)if(h(t,i)===h(e,-1===n?0:i-n)){if(-1===n&&(n=i),i-n+1===u)return n*f}else-1!==n&&(i-=i-n),n=-1}else for(r+u>s&&(r=s-u),i=r;i>=0;i--){let r=!0;for(let n=0;n<u;n++)if(h(t,i+n)!==h(e,n)){r=!1;break}if(r)return i}return-1}function U(t,e,r,n){r=Number(r)||0;const o=t.length-r;n?(n=Number(n))>o&&(n=o):n=o;const i=e.length;let f;for(n>i/2&&(n=i/2),f=0;f<n;++f){const n=parseInt(e.substr(2*f,2),16);if(ot(n))return f;t[r+f]=n}return f}function A(t,e,r,n){return rt(K(e,t.length-r),t,r,n)}function v(t,e,r,n){return rt(Q(e),t,r,n)}function R(t,e,r,n){return rt(et(e),t,r,n)}function T(t,e,r,n){return rt(tt(e,t.length-r),t,r,n)}function O(e,r,n){return 0===r&&n===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(r,n))}function L(t,e,r){r=Math.min(t.length,r);const n=[];let o=e;for(;o<r;){const e=t[o];let i=null,f=e>239?4:e>223?3:e>191?2:1;if(o+f<=r){let r,n,s,u;switch(f){case 1:e<128&&(i=e);break;case 2:128==(192&(r=t[o+1]))&&(u=(31&e)<<6|63&r)>127&&(i=u);break;case 3:r=t[o+1],n=t[o+2],128==(192&r)&&128==(192&n)&&(u=(15&e)<<12|(63&r)<<6|63&n)>2047&&(u<55296||u>57343)&&(i=u);break;case 4:r=t[o+1],n=t[o+2],s=t[o+3],128==(192&r)&&128==(192&n)&&128==(192&s)&&(u=(15&e)<<18|(63&r)<<12|(63&n)<<6|63&s)>65535&&u<1114112&&(i=u)}}null===i?(i=65533,f=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|1023&i),n.push(i),o+=f}return _(n)}exports.kMaxLength=n,f.TYPED_ARRAY_SUPPORT=o(),f.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(f.prototype,"parent",{enumerable:!0,get:function(){if(f.isBuffer(this))return this.buffer}}),Object.defineProperty(f.prototype,"offset",{enumerable:!0,get:function(){if(f.isBuffer(this))return this.byteOffset}}),f.poolSize=8192,f.from=function(t,e,r){return s(t,e,r)},Object.setPrototypeOf(f.prototype,Uint8Array.prototype),Object.setPrototypeOf(f,Uint8Array),f.alloc=function(t,e,r){return h(t,e,r)},f.allocUnsafe=function(t){return c(t)},f.allocUnsafeSlow=function(t){return c(t)},console.log("********* buffer line 327 *********"),f.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==f.prototype},f.compare=function(t,e){if(nt(t,Uint8Array)&&(t=f.from(t,t.offset,t.byteLength)),nt(e,Uint8Array)&&(e=f.from(e,e.offset,e.byteLength)),!f.isBuffer(t)||!f.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let r=t.length,n=e.length;for(let o=0,i=Math.min(r,n);o<i;++o)if(t[o]!==e[o]){r=t[o],n=e[o];break}return r<n?-1:n<r?1:0},f.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},f.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return f.alloc(0);let r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;const n=f.allocUnsafe(e);let o=0;for(r=0;r<t.length;++r){let e=t[r];if(nt(e,Uint8Array))o+e.length>n.length?(f.isBuffer(e)||(e=f.from(e)),e.copy(n,o)):Uint8Array.prototype.set.call(n,e,o);else{if(!f.isBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(n,o)}o+=e.length}return n},console.log("********* buffer line 440 *********"),f.byteLength=b,f.prototype._isBuffer=!0,f.prototype.swap16=function(){const t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)E(this,e,e+1);return this},f.prototype.swap32=function(){const t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)E(this,e,e+3),E(this,e+1,e+2);return this},f.prototype.swap64=function(){const t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)E(this,e,e+7),E(this,e+1,e+6),E(this,e+2,e+5),E(this,e+3,e+4);return this},f.prototype.toString=function(){const t=this.length;return 0===t?"":0===arguments.length?L(this,0,t):B.apply(this,arguments)},f.prototype.toLocaleString=f.prototype.toString,f.prototype.equals=function(t){if(!f.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===f.compare(this,t)},f.prototype.inspect=function(){let t="";const e=exports.INSPECT_MAX_BYTES;return t=this.toString("hex",0,e).replace(/(.{2})/g,"$1 ").trim(),this.length>e&&(t+=" ... "),"<Buffer "+t+">"},r&&(f.prototype[r]=f.prototype.inspect),f.prototype.compare=function(t,e,r,n,o){if(nt(t,Uint8Array)&&(t=f.from(t,t.offset,t.byteLength)),!f.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),e<0||r>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&e>=r)return 0;if(n>=o)return-1;if(e>=r)return 1;if(this===t)return 0;let i=(o>>>=0)-(n>>>=0),s=(r>>>=0)-(e>>>=0);const u=Math.min(i,s),h=this.slice(n,o),c=t.slice(e,r);for(let f=0;f<u;++f)if(h[f]!==c[f]){i=h[f],s=c[f];break}return i<s?-1:s<i?1:0},f.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},f.prototype.indexOf=function(t,e,r){return m(this,t,e,r,!0)},f.prototype.lastIndexOf=function(t,e,r){return m(this,t,e,r,!1)},f.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const o=this.length-e;if((void 0===r||r>o)&&(r=o),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let i=!1;for(;;)switch(n){case"hex":return U(this,t,e,r);case"utf8":case"utf-8":return A(this,t,e,r);case"ascii":case"latin1":case"binary":return v(this,t,e,r);case"base64":return R(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,t,e,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},f.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},console.log("********* buffer line 1039 *********");const S=4096;function _(t){const e=t.length;if(e<=S)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=S));return r}function x(t,e,r){let n="";r=Math.min(t.length,r);for(let o=e;o<r;++o)n+=String.fromCharCode(127&t[o]);return n}function $(t,e,r){let n="";r=Math.min(t.length,r);for(let o=e;o<r;++o)n+=String.fromCharCode(t[o]);return n}function P(t,e,r){const n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let o="";for(let i=e;i<r;++i)o+=it[t[i]];return o}function C(t,e,r){const n=t.slice(e,r);let o="";for(let i=0;i<n.length-1;i+=2)o+=String.fromCharCode(n[i]+256*n[i+1]);return o}function k(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function N(t,e,r,n,o,i){if(!f.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<i)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function F(t,e,r,n,o){W(e,n,o,t,r,7);let i=Number(e&BigInt(4294967295));t[r++]=i,i>>=8,t[r++]=i,i>>=8,t[r++]=i,i>>=8,t[r++]=i;let f=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=f,f>>=8,t[r++]=f,f>>=8,t[r++]=f,f>>=8,t[r++]=f,r}function M(t,e,r,n,o){W(e,n,o,t,r,7);let i=Number(e&BigInt(4294967295));t[r+7]=i,i>>=8,t[r+6]=i,i>>=8,t[r+5]=i,i>>=8,t[r+4]=i;let f=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=f,f>>=8,t[r+2]=f,f>>=8,t[r+1]=f,f>>=8,t[r]=f,r+8}function j(t,e,r,n,o,i){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function D(t,r,n,o,i){return r=+r,n>>>=0,i||j(t,r,n,4,3.4028234663852886e38,-3.4028234663852886e38),e.write(t,r,n,o,23,4),n+4}function z(t,r,n,o,i){return r=+r,n>>>=0,i||j(t,r,n,8,1.7976931348623157e308,-1.7976931348623157e308),e.write(t,r,n,o,52,8),n+8}f.prototype.slice=function(t,e){const r=this.length;(t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t);const n=this.subarray(t,e);return Object.setPrototypeOf(n,f.prototype),n},f.prototype.readUintLE=f.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||k(t,e,this.length);let n=this[t],o=1,i=0;for(;++i<e&&(o*=256);)n+=this[t+i]*o;return n},f.prototype.readUintBE=f.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||k(t,e,this.length);let n=this[t+--e],o=1;for(;e>0&&(o*=256);)n+=this[t+--e]*o;return n},f.prototype.readUint8=f.prototype.readUInt8=function(t,e){return t>>>=0,e||k(t,1,this.length),this[t]},f.prototype.readUint16LE=f.prototype.readUInt16LE=function(t,e){return t>>>=0,e||k(t,2,this.length),this[t]|this[t+1]<<8},f.prototype.readUint16BE=f.prototype.readUInt16BE=function(t,e){return t>>>=0,e||k(t,2,this.length),this[t]<<8|this[t+1]},f.prototype.readUint32LE=f.prototype.readUInt32LE=function(t,e){return t>>>=0,e||k(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},f.prototype.readUint32BE=f.prototype.readUInt32BE=function(t,e){return t>>>=0,e||k(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},f.prototype.readBigUInt64LE=ft(function(t){X(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||J(t,this.length-8);const n=e+256*this[++t]+65536*this[++t]+this[++t]*2**24,o=this[++t]+256*this[++t]+65536*this[++t]+r*2**24;return BigInt(n)+(BigInt(o)<<BigInt(32))}),console.log("********* buffer line 1241 *********"),console.log("beofre readBigUInt64BE!"),f.prototype.readBigUInt64BE=ft(function(t){X(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||J(t,this.length-8);const n=e*2**24+65536*this[++t]+256*this[++t]+this[++t],o=this[++t]*2**24+65536*this[++t]+256*this[++t]+r;return(BigInt(n)<<BigInt(32))+BigInt(o)}),f.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||k(t,e,this.length);let n=this[t],o=1,i=0;for(;++i<e&&(o*=256);)n+=this[t+i]*o;return n>=(o*=128)&&(n-=Math.pow(2,8*e)),n},f.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||k(t,e,this.length);let n=e,o=1,i=this[t+--n];for(;n>0&&(o*=256);)i+=this[t+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*e)),i},f.prototype.readInt8=function(t,e){return t>>>=0,e||k(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},f.prototype.readInt16LE=function(t,e){t>>>=0,e||k(t,2,this.length);const r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},f.prototype.readInt16BE=function(t,e){t>>>=0,e||k(t,2,this.length);const r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},f.prototype.readInt32LE=function(t,e){return t>>>=0,e||k(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},f.prototype.readInt32BE=function(t,e){return t>>>=0,e||k(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},f.prototype.readBigInt64LE=ft(function(t){X(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||J(t,this.length-8);const n=this[t+4]+256*this[t+5]+65536*this[t+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(e+256*this[++t]+65536*this[++t]+this[++t]*2**24)}),f.prototype.readBigInt64BE=ft(function(t){X(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||J(t,this.length-8);const n=(e<<24)+65536*this[++t]+256*this[++t]+this[++t];return(BigInt(n)<<BigInt(32))+BigInt(this[++t]*2**24+65536*this[++t]+256*this[++t]+r)}),f.prototype.readFloatLE=function(t,r){return t>>>=0,r||k(t,4,this.length),e.read(this,t,!0,23,4)},f.prototype.readFloatBE=function(t,r){return t>>>=0,r||k(t,4,this.length),e.read(this,t,!1,23,4)},f.prototype.readDoubleLE=function(t,r){return t>>>=0,r||k(t,8,this.length),e.read(this,t,!0,52,8)},f.prototype.readDoubleBE=function(t,r){return t>>>=0,r||k(t,8,this.length),e.read(this,t,!1,52,8)},f.prototype.writeUintLE=f.prototype.writeUIntLE=function(t,e,r,n){if(t=+t,e>>>=0,r>>>=0,!n){N(this,t,e,r,Math.pow(2,8*r)-1,0)}let o=1,i=0;for(this[e]=255&t;++i<r&&(o*=256);)this[e+i]=t/o&255;return e+r},f.prototype.writeUintBE=f.prototype.writeUIntBE=function(t,e,r,n){if(t=+t,e>>>=0,r>>>=0,!n){N(this,t,e,r,Math.pow(2,8*r)-1,0)}let o=r-1,i=1;for(this[e+o]=255&t;--o>=0&&(i*=256);)this[e+o]=t/i&255;return e+r},f.prototype.writeUint8=f.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||N(this,t,e,1,255,0),this[e]=255&t,e+1},f.prototype.writeUint16LE=f.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||N(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},f.prototype.writeUint16BE=f.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||N(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},f.prototype.writeUint32LE=f.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||N(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},f.prototype.writeUint32BE=f.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||N(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},f.prototype.writeBigUInt64LE=ft(function(t,e=0){return F(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))}),f.prototype.writeBigUInt64BE=ft(function(t,e=0){return M(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))}),f.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);N(this,t,e,r,n-1,-n)}let o=0,i=1,f=0;for(this[e]=255&t;++o<r&&(i*=256);)t<0&&0===f&&0!==this[e+o-1]&&(f=1),this[e+o]=(t/i>>0)-f&255;return e+r},f.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);N(this,t,e,r,n-1,-n)}let o=r-1,i=1,f=0;for(this[e+o]=255&t;--o>=0&&(i*=256);)t<0&&0===f&&0!==this[e+o+1]&&(f=1),this[e+o]=(t/i>>0)-f&255;return e+r},f.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||N(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},f.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||N(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},f.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||N(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},f.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||N(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},f.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||N(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},f.prototype.writeBigInt64LE=ft(function(t,e=0){return F(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),f.prototype.writeBigInt64BE=ft(function(t,e=0){return M(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),f.prototype.writeFloatLE=function(t,e,r){return D(this,t,e,!0,r)},f.prototype.writeFloatBE=function(t,e,r){return D(this,t,e,!1,r)},f.prototype.writeDoubleLE=function(t,e,r){return z(this,t,e,!0,r)},f.prototype.writeDoubleBE=function(t,e,r){return z(this,t,e,!1,r)},f.prototype.copy=function(t,e,r,n){if(!f.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);const o=n-r;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,r,n):Uint8Array.prototype.set.call(t,this.subarray(r,n),e),o},f.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!f.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===t.length){const e=t.charCodeAt(0);("utf8"===n&&e<128||"latin1"===n)&&(t=e)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;let o;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(o=e;o<r;++o)this[o]=t;else{const i=f.isBuffer(t)?t:f.from(t,n),s=i.length;if(0===s)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(o=0;o<r-e;++o)this[o+e]=i[o%s]}return this};const Y={};function G(t,e,r){Y[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(t){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:t,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}function q(t){let e="",r=t.length;const n="-"===t[0]?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function V(t,e,r){X(e,"offset"),void 0!==t[e]&&void 0!==t[e+r]||J(e,t.length-(r+1))}function W(t,e,r,n,o,i){if(t>r||t<e){const n="bigint"==typeof e?"n":"";let o;throw o=i>3?0===e||e===BigInt(0)?`>= 0${n} and < 2${n} ** ${8*(i+1)}${n}`:`>= -(2${n} ** ${8*(i+1)-1}${n}) and < 2 ** `+`${8*(i+1)-1}${n}`:`>= ${e}${n} and <= ${r}${n}`,new Y.ERR_OUT_OF_RANGE("value",o,t)}V(n,o,i)}function X(t,e){if("number"!=typeof t)throw new Y.ERR_INVALID_ARG_TYPE(e,"number",t)}function J(t,e,r){if(Math.floor(t)!==t)throw X(t,r),new Y.ERR_OUT_OF_RANGE(r||"offset","an integer",t);if(e<0)throw new Y.ERR_BUFFER_OUT_OF_BOUNDS;throw new Y.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}G("ERR_BUFFER_OUT_OF_BOUNDS",function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),G("ERR_INVALID_ARG_TYPE",function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`},TypeError),G("ERR_OUT_OF_RANGE",function(t,e,r){let n=`The value of "${t}" is out of range.`,o=r;return Number.isInteger(r)&&Math.abs(r)>2**32?o=q(String(r)):"bigint"==typeof r&&(o=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(o=q(o)),o+="n"),n+=` It must be ${e}. Received ${o}`},RangeError);const Z=/[^+/0-9A-Za-z-_]/g;function H(t){if((t=(t=t.split("=")[0]).trim().replace(Z,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}function K(t,e){let r;e=e||1/0;const n=t.length;let o=null;const i=[];for(let f=0;f<n;++f){if((r=t.charCodeAt(f))>55295&&r<57344){if(!o){if(r>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(f+1===n){(e-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(e-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((e-=1)<0)break;i.push(r)}else if(r<2048){if((e-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function Q(t){const e=[];for(let r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}function tt(t,e){let r,n,o;const i=[];for(let f=0;f<t.length&&!((e-=2)<0);++f)n=(r=t.charCodeAt(f))>>8,o=r%256,i.push(o),i.push(n);return i}function et(e){return t.toByteArray(H(e))}function rt(t,e,r,n){let o;for(o=0;o<n&&!(o+r>=e.length||o>=t.length);++o)e[o+r]=t[o];return o}function nt(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function ot(t){return t!=t}const it=function(){const t=new Array(256);for(let e=0;e<16;++e){const r=16*e;for(let n=0;n<16;++n)t[r+n]="0123456789abcdef"[e]+"0123456789abcdef"[n]}return t}();function ft(t){return"undefined"==typeof BigInt?st:t}function st(){throw new Error("BigInt not supported")}
634
+ "use strict";const t=require("base64-js"),e=require("ieee754"),r="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;exports.Buffer=f,exports.SlowBuffer=d,exports.INSPECT_MAX_BYTES=50;const n=2147483647;function i(){try{const e=new Uint8Array(1),r={foo:function(){return 42}};return Object.setPrototypeOf(r,Uint8Array.prototype),Object.setPrototypeOf(e,r),42===e.foo()}catch(t){return!1}}function o(t){if(t>n)throw new RangeError('The value "'+t+'" is invalid for option "size"');const e=new Uint8Array(t);return Object.setPrototypeOf(e,f.prototype),e}function f(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return c(t)}return s(t,e,r)}function s(t,e,r){if("string"==typeof t)return a(t,e);if(ArrayBuffer.isView(t))return l(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(nt(t,ArrayBuffer)||t&&nt(t.buffer,ArrayBuffer))return g(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(nt(t,SharedArrayBuffer)||t&&nt(t.buffer,SharedArrayBuffer)))return g(t,e,r);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return f.from(n,e,r);const i=y(t);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return f.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function u(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function h(t,e,r){return u(t),t<=0?o(t):void 0!==e?"string"==typeof r?o(t).fill(e,r):o(t).fill(e):o(t)}function c(t){return u(t),o(t<0?0:0|w(t))}function a(t,e){if("string"==typeof e&&""!==e||(e="utf8"),!f.isEncoding(e))throw new TypeError("Unknown encoding: "+e);const r=0|b(t,e);let n=o(r);const i=n.write(t,e);return i!==r&&(n=n.slice(0,i)),n}function p(t){const e=t.length<0?0:0|w(t.length),r=o(e);for(let n=0;n<e;n+=1)r[n]=255&t[n];return r}function l(t){if(nt(t,Uint8Array)){const e=new Uint8Array(t);return g(e.buffer,e.byteOffset,e.byteLength)}return p(t)}function g(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r),Object.setPrototypeOf(n,f.prototype),n}function y(t){if(f.isBuffer(t)){const e=0|w(t.length),r=o(e);return 0===r.length?r:(t.copy(r,0,0,e),r)}return void 0!==t.length?"number"!=typeof t.length||it(t.length)?o(0):p(t):"Buffer"===t.type&&Array.isArray(t.data)?p(t.data):void 0}function w(t){if(t>=n)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+n.toString(16)+" bytes");return 0|t}function d(t){return+t!=t&&(t=0),f.alloc(+t)}function b(t,e){if(f.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||nt(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);const r=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return K(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return et(t).length;default:if(i)return n?-1:K(t).length;e=(""+e).toLowerCase(),i=!0}}function B(t,e,r){let n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return P(this,e,r);case"utf8":case"utf-8":return L(this,e,r);case"ascii":return x(this,e,r);case"latin1":case"binary":return $(this,e,r);case"base64":return O(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function E(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}function m(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),it(r=+r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=f.from(e,n)),f.isBuffer(e))return 0===e.length?-1:I(t,e,r,n,i);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):I(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function I(t,e,r,n,i){let o,f=1,s=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;f=2,s/=2,u/=2,r/=2}function h(t,e){return 1===f?t[e]:t.readUInt16BE(e*f)}if(i){let n=-1;for(o=r;o<s;o++)if(h(t,o)===h(e,-1===n?0:o-n)){if(-1===n&&(n=o),o-n+1===u)return n*f}else-1!==n&&(o-=o-n),n=-1}else for(r+u>s&&(r=s-u),o=r;o>=0;o--){let r=!0;for(let n=0;n<u;n++)if(h(t,o+n)!==h(e,n)){r=!1;break}if(r)return o}return-1}function U(t,e,r,n){r=Number(r)||0;const i=t.length-r;n?(n=Number(n))>i&&(n=i):n=i;const o=e.length;let f;for(n>o/2&&(n=o/2),f=0;f<n;++f){const n=parseInt(e.substr(2*f,2),16);if(it(n))return f;t[r+f]=n}return f}function A(t,e,r,n){return rt(K(e,t.length-r),t,r,n)}function v(t,e,r,n){return rt(Q(e),t,r,n)}function R(t,e,r,n){return rt(et(e),t,r,n)}function T(t,e,r,n){return rt(tt(e,t.length-r),t,r,n)}function O(e,r,n){return 0===r&&n===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(r,n))}function L(t,e,r){r=Math.min(t.length,r);const n=[];let i=e;for(;i<r;){const e=t[i];let o=null,f=e>239?4:e>223?3:e>191?2:1;if(i+f<=r){let r,n,s,u;switch(f){case 1:e<128&&(o=e);break;case 2:128==(192&(r=t[i+1]))&&(u=(31&e)<<6|63&r)>127&&(o=u);break;case 3:r=t[i+1],n=t[i+2],128==(192&r)&&128==(192&n)&&(u=(15&e)<<12|(63&r)<<6|63&n)>2047&&(u<55296||u>57343)&&(o=u);break;case 4:r=t[i+1],n=t[i+2],s=t[i+3],128==(192&r)&&128==(192&n)&&128==(192&s)&&(u=(15&e)<<18|(63&r)<<12|(63&n)<<6|63&s)>65535&&u<1114112&&(o=u)}}null===o?(o=65533,f=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|1023&o),n.push(o),i+=f}return _(n)}exports.kMaxLength=n,f.TYPED_ARRAY_SUPPORT=i(),f.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(f.prototype,"parent",{enumerable:!0,get:function(){if(f.isBuffer(this))return this.buffer}}),Object.defineProperty(f.prototype,"offset",{enumerable:!0,get:function(){if(f.isBuffer(this))return this.byteOffset}}),f.poolSize=8192,f.from=function(t,e,r){return s(t,e,r)},Object.setPrototypeOf(f.prototype,Uint8Array.prototype),Object.setPrototypeOf(f,Uint8Array),f.alloc=function(t,e,r){return h(t,e,r)},f.allocUnsafe=function(t){return c(t)},f.allocUnsafeSlow=function(t){return c(t)},f.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==f.prototype},f.compare=function(t,e){if(nt(t,Uint8Array)&&(t=f.from(t,t.offset,t.byteLength)),nt(e,Uint8Array)&&(e=f.from(e,e.offset,e.byteLength)),!f.isBuffer(t)||!f.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let r=t.length,n=e.length;for(let i=0,o=Math.min(r,n);i<o;++i)if(t[i]!==e[i]){r=t[i],n=e[i];break}return r<n?-1:n<r?1:0},f.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},f.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return f.alloc(0);let r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;const n=f.allocUnsafe(e);let i=0;for(r=0;r<t.length;++r){let e=t[r];if(nt(e,Uint8Array))i+e.length>n.length?(f.isBuffer(e)||(e=f.from(e)),e.copy(n,i)):Uint8Array.prototype.set.call(n,e,i);else{if(!f.isBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(n,i)}i+=e.length}return n},f.byteLength=b,f.prototype._isBuffer=!0,f.prototype.swap16=function(){const t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)E(this,e,e+1);return this},f.prototype.swap32=function(){const t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)E(this,e,e+3),E(this,e+1,e+2);return this},f.prototype.swap64=function(){const t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)E(this,e,e+7),E(this,e+1,e+6),E(this,e+2,e+5),E(this,e+3,e+4);return this},f.prototype.toString=function(){const t=this.length;return 0===t?"":0===arguments.length?L(this,0,t):B.apply(this,arguments)},f.prototype.toLocaleString=f.prototype.toString,f.prototype.equals=function(t){if(!f.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===f.compare(this,t)},f.prototype.inspect=function(){let t="";const e=exports.INSPECT_MAX_BYTES;return t=this.toString("hex",0,e).replace(/(.{2})/g,"$1 ").trim(),this.length>e&&(t+=" ... "),"<Buffer "+t+">"},r&&(f.prototype[r]=f.prototype.inspect),f.prototype.compare=function(t,e,r,n,i){if(nt(t,Uint8Array)&&(t=f.from(t,t.offset,t.byteLength)),!f.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;let o=(i>>>=0)-(n>>>=0),s=(r>>>=0)-(e>>>=0);const u=Math.min(o,s),h=this.slice(n,i),c=t.slice(e,r);for(let f=0;f<u;++f)if(h[f]!==c[f]){o=h[f],s=c[f];break}return o<s?-1:s<o?1:0},f.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},f.prototype.indexOf=function(t,e,r){return m(this,t,e,r,!0)},f.prototype.lastIndexOf=function(t,e,r){return m(this,t,e,r,!1)},f.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let o=!1;for(;;)switch(n){case"hex":return U(this,t,e,r);case"utf8":case"utf-8":return A(this,t,e,r);case"ascii":case"latin1":case"binary":return v(this,t,e,r);case"base64":return R(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},f.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const S=4096;function _(t){const e=t.length;if(e<=S)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=S));return r}function x(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(127&t[i]);return n}function $(t,e,r){let n="";r=Math.min(t.length,r);for(let i=e;i<r;++i)n+=String.fromCharCode(t[i]);return n}function P(t,e,r){const n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let i="";for(let o=e;o<r;++o)i+=ot[t[o]];return i}function C(t,e,r){const n=t.slice(e,r);let i="";for(let o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function k(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function N(t,e,r,n,i,o){if(!f.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function F(t,e,r,n,i){W(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o,o>>=8,t[r++]=o;let f=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=f,f>>=8,t[r++]=f,f>>=8,t[r++]=f,f>>=8,t[r++]=f,r}function M(t,e,r,n,i){W(e,n,i,t,r,7);let o=Number(e&BigInt(4294967295));t[r+7]=o,o>>=8,t[r+6]=o,o>>=8,t[r+5]=o,o>>=8,t[r+4]=o;let f=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=f,f>>=8,t[r+2]=f,f>>=8,t[r+1]=f,f>>=8,t[r]=f,r+8}function j(t,e,r,n,i,o){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function D(t,r,n,i,o){return r=+r,n>>>=0,o||j(t,r,n,4,3.4028234663852886e38,-3.4028234663852886e38),e.write(t,r,n,i,23,4),n+4}function z(t,r,n,i,o){return r=+r,n>>>=0,o||j(t,r,n,8,1.7976931348623157e308,-1.7976931348623157e308),e.write(t,r,n,i,52,8),n+8}f.prototype.slice=function(t,e){const r=this.length;(t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t);const n=this.subarray(t,e);return Object.setPrototypeOf(n,f.prototype),n},f.prototype.readUintLE=f.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||k(t,e,this.length);let n=this[t],i=1,o=0;for(;++o<e&&(i*=256);)n+=this[t+o]*i;return n},f.prototype.readUintBE=f.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||k(t,e,this.length);let n=this[t+--e],i=1;for(;e>0&&(i*=256);)n+=this[t+--e]*i;return n},f.prototype.readUint8=f.prototype.readUInt8=function(t,e){return t>>>=0,e||k(t,1,this.length),this[t]},f.prototype.readUint16LE=f.prototype.readUInt16LE=function(t,e){return t>>>=0,e||k(t,2,this.length),this[t]|this[t+1]<<8},f.prototype.readUint16BE=f.prototype.readUInt16BE=function(t,e){return t>>>=0,e||k(t,2,this.length),this[t]<<8|this[t+1]},f.prototype.readUint32LE=f.prototype.readUInt32LE=function(t,e){return t>>>=0,e||k(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},f.prototype.readUint32BE=f.prototype.readUInt32BE=function(t,e){return t>>>=0,e||k(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},f.prototype.readBigUInt64LE=ft(function(t){X(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||J(t,this.length-8);const n=e+256*this[++t]+65536*this[++t]+this[++t]*2**24,i=this[++t]+256*this[++t]+65536*this[++t]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))}),f.prototype.readBigUInt64BE=ft(function(t){X(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||J(t,this.length-8);const n=e*2**24+65536*this[++t]+256*this[++t]+this[++t],i=this[++t]*2**24+65536*this[++t]+256*this[++t]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)}),f.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||k(t,e,this.length);let n=this[t],i=1,o=0;for(;++o<e&&(i*=256);)n+=this[t+o]*i;return n>=(i*=128)&&(n-=Math.pow(2,8*e)),n},f.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||k(t,e,this.length);let n=e,i=1,o=this[t+--n];for(;n>0&&(i*=256);)o+=this[t+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*e)),o},f.prototype.readInt8=function(t,e){return t>>>=0,e||k(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},f.prototype.readInt16LE=function(t,e){t>>>=0,e||k(t,2,this.length);const r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},f.prototype.readInt16BE=function(t,e){t>>>=0,e||k(t,2,this.length);const r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},f.prototype.readInt32LE=function(t,e){return t>>>=0,e||k(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},f.prototype.readInt32BE=function(t,e){return t>>>=0,e||k(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},f.prototype.readBigInt64LE=ft(function(t){X(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||J(t,this.length-8);const n=this[t+4]+256*this[t+5]+65536*this[t+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(e+256*this[++t]+65536*this[++t]+this[++t]*2**24)}),f.prototype.readBigInt64BE=ft(function(t){X(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||J(t,this.length-8);const n=(e<<24)+65536*this[++t]+256*this[++t]+this[++t];return(BigInt(n)<<BigInt(32))+BigInt(this[++t]*2**24+65536*this[++t]+256*this[++t]+r)}),f.prototype.readFloatLE=function(t,r){return t>>>=0,r||k(t,4,this.length),e.read(this,t,!0,23,4)},f.prototype.readFloatBE=function(t,r){return t>>>=0,r||k(t,4,this.length),e.read(this,t,!1,23,4)},f.prototype.readDoubleLE=function(t,r){return t>>>=0,r||k(t,8,this.length),e.read(this,t,!0,52,8)},f.prototype.readDoubleBE=function(t,r){return t>>>=0,r||k(t,8,this.length),e.read(this,t,!1,52,8)},f.prototype.writeUintLE=f.prototype.writeUIntLE=function(t,e,r,n){if(t=+t,e>>>=0,r>>>=0,!n){N(this,t,e,r,Math.pow(2,8*r)-1,0)}let i=1,o=0;for(this[e]=255&t;++o<r&&(i*=256);)this[e+o]=t/i&255;return e+r},f.prototype.writeUintBE=f.prototype.writeUIntBE=function(t,e,r,n){if(t=+t,e>>>=0,r>>>=0,!n){N(this,t,e,r,Math.pow(2,8*r)-1,0)}let i=r-1,o=1;for(this[e+i]=255&t;--i>=0&&(o*=256);)this[e+i]=t/o&255;return e+r},f.prototype.writeUint8=f.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||N(this,t,e,1,255,0),this[e]=255&t,e+1},f.prototype.writeUint16LE=f.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||N(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},f.prototype.writeUint16BE=f.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||N(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},f.prototype.writeUint32LE=f.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||N(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},f.prototype.writeUint32BE=f.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||N(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},f.prototype.writeBigUInt64LE=ft(function(t,e=0){return F(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))}),f.prototype.writeBigUInt64BE=ft(function(t,e=0){return M(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))}),f.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);N(this,t,e,r,n-1,-n)}let i=0,o=1,f=0;for(this[e]=255&t;++i<r&&(o*=256);)t<0&&0===f&&0!==this[e+i-1]&&(f=1),this[e+i]=(t/o>>0)-f&255;return e+r},f.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);N(this,t,e,r,n-1,-n)}let i=r-1,o=1,f=0;for(this[e+i]=255&t;--i>=0&&(o*=256);)t<0&&0===f&&0!==this[e+i+1]&&(f=1),this[e+i]=(t/o>>0)-f&255;return e+r},f.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||N(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},f.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||N(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},f.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||N(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},f.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||N(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},f.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||N(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},f.prototype.writeBigInt64LE=ft(function(t,e=0){return F(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),f.prototype.writeBigInt64BE=ft(function(t,e=0){return M(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),f.prototype.writeFloatLE=function(t,e,r){return D(this,t,e,!0,r)},f.prototype.writeFloatBE=function(t,e,r){return D(this,t,e,!1,r)},f.prototype.writeDoubleLE=function(t,e,r){return z(this,t,e,!0,r)},f.prototype.writeDoubleBE=function(t,e,r){return z(this,t,e,!1,r)},f.prototype.copy=function(t,e,r,n){if(!f.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);const i=n-r;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,r,n):Uint8Array.prototype.set.call(t,this.subarray(r,n),e),i},f.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!f.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===t.length){const e=t.charCodeAt(0);("utf8"===n&&e<128||"latin1"===n)&&(t=e)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;let i;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(i=e;i<r;++i)this[i]=t;else{const o=f.isBuffer(t)?t:f.from(t,n),s=o.length;if(0===s)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(i=0;i<r-e;++i)this[i+e]=o[i%s]}return this};const Y={};function G(t,e,r){Y[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(t){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:t,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}function q(t){let e="",r=t.length;const n="-"===t[0]?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function V(t,e,r){X(e,"offset"),void 0!==t[e]&&void 0!==t[e+r]||J(e,t.length-(r+1))}function W(t,e,r,n,i,o){if(t>r||t<e){const n="bigint"==typeof e?"n":"";let i;throw i=o>3?0===e||e===BigInt(0)?`>= 0${n} and < 2${n} ** ${8*(o+1)}${n}`:`>= -(2${n} ** ${8*(o+1)-1}${n}) and < 2 ** `+`${8*(o+1)-1}${n}`:`>= ${e}${n} and <= ${r}${n}`,new Y.ERR_OUT_OF_RANGE("value",i,t)}V(n,i,o)}function X(t,e){if("number"!=typeof t)throw new Y.ERR_INVALID_ARG_TYPE(e,"number",t)}function J(t,e,r){if(Math.floor(t)!==t)throw X(t,r),new Y.ERR_OUT_OF_RANGE(r||"offset","an integer",t);if(e<0)throw new Y.ERR_BUFFER_OUT_OF_BOUNDS;throw new Y.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}G("ERR_BUFFER_OUT_OF_BOUNDS",function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),G("ERR_INVALID_ARG_TYPE",function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`},TypeError),G("ERR_OUT_OF_RANGE",function(t,e,r){let n=`The value of "${t}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=q(String(r)):"bigint"==typeof r&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=q(i)),i+="n"),n+=` It must be ${e}. Received ${i}`},RangeError);const Z=/[^+/0-9A-Za-z-_]/g;function H(t){if((t=(t=t.split("=")[0]).trim().replace(Z,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}function K(t,e){let r;e=e||1/0;const n=t.length;let i=null;const o=[];for(let f=0;f<n;++f){if((r=t.charCodeAt(f))>55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(f+1===n){(e-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;o.push(r)}else if(r<2048){if((e-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function Q(t){const e=[];for(let r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}function tt(t,e){let r,n,i;const o=[];for(let f=0;f<t.length&&!((e-=2)<0);++f)n=(r=t.charCodeAt(f))>>8,i=r%256,o.push(i),o.push(n);return o}function et(e){return t.toByteArray(H(e))}function rt(t,e,r,n){let i;for(i=0;i<n&&!(i+r>=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function nt(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function it(t){return t!=t}const ot=function(){const t=new Array(256);for(let e=0;e<16;++e){const r=16*e;for(let n=0;n<16;++n)t[r+n]="0123456789abcdef"[e]+"0123456789abcdef"[n]}return t}();function ft(t){return"undefined"==typeof BigInt?st:t}function st(){throw new Error("BigInt not supported")}
635
635
  },{"base64-js":"yh9p","ieee754":"JgNJ","buffer":"peL6"}],"iwtf":[function(require,module,exports) {
636
636
  "use strict";var N,e;Object.defineProperty(exports,"__esModule",{value:!0}),exports.TRANSPORT_TYPE=exports.BLUETOOTH_CONNECTION=void 0,function(N){N.SCANNING="scanning",N.CONNECTED="connected",N.CONNECTING="connecting",N.DISCONNECTING="disconnecting",N.DISCONNECTED="disconnected"}(N=exports.BLUETOOTH_CONNECTION||(exports.BLUETOOTH_CONNECTION={})),function(N){N.WEB="web",N.REACT_NATIVE="reactNative"}(e=exports.TRANSPORT_TYPE||(exports.TRANSPORT_TYPE={}));
637
637
  },{}],"mUrw":[function(require,module,exports) {