@firebase/database-compat 2.0.1 → 2.0.2-canary.01f36ea41

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.
@@ -11,9 +11,9 @@ var require$$2$1 = require('url');
11
11
  var require$$0$2 = require('assert');
12
12
  var require$$1$2 = require('net');
13
13
  var require$$2$2 = require('tls');
14
- var require$$1$3 = require('@firebase/util');
15
- var require$$2$3 = require('@firebase/logger');
16
- var require$$3 = require('@firebase/component');
14
+ var require$$2$3 = require('@firebase/util');
15
+ var require$$1$3 = require('@firebase/logger');
16
+ var require$$0$3 = require('@firebase/component');
17
17
 
18
18
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
19
19
 
@@ -26,9 +26,24 @@ var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
26
26
  var require$$0__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$0$2);
27
27
  var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
28
28
  var require$$2__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$2$2);
29
- var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
30
29
  var require$$2__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$2$3);
31
- var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
30
+ var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
31
+ var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$3);
32
+
33
+ function getAugmentedNamespace(n) {
34
+ if (n.__esModule) return n;
35
+ var a = Object.defineProperty({}, '__esModule', {value: true});
36
+ Object.keys(n).forEach(function (k) {
37
+ var d = Object.getOwnPropertyDescriptor(n, k);
38
+ Object.defineProperty(a, k, d.get ? d : {
39
+ enumerable: true,
40
+ get: function () {
41
+ return n[k];
42
+ }
43
+ });
44
+ });
45
+ return a;
46
+ }
32
47
 
33
48
  var index_standalone = {};
34
49
 
@@ -2217,7 +2232,7 @@ var Buffer$4 = safeBuffer.exports.Buffer,
2217
2232
 
2218
2233
  var PORTS = { 'ws:': 80, 'wss:': 443 };
2219
2234
 
2220
- var Proxy$1 = function(client, origin, options) {
2235
+ var Proxy$2 = function(client, origin, options) {
2221
2236
  this._client = client;
2222
2237
  this._http = new HttpParser$2('response');
2223
2238
  this._origin = (typeof client.url === 'object') ? client.url : url$2.parse(client.url);
@@ -2236,7 +2251,7 @@ var Proxy$1 = function(client, origin, options) {
2236
2251
  var auth = this._url.auth && Buffer$4.from(this._url.auth, 'utf8').toString('base64');
2237
2252
  if (auth) this._headers.set('Proxy-Authorization', 'Basic ' + auth);
2238
2253
  };
2239
- util$9.inherits(Proxy$1, Stream$2);
2254
+ util$9.inherits(Proxy$2, Stream$2);
2240
2255
 
2241
2256
  var instance$6 = {
2242
2257
  setHeader: function(name, value) {
@@ -2301,9 +2316,9 @@ var instance$6 = {
2301
2316
  };
2302
2317
 
2303
2318
  for (var key$6 in instance$6)
2304
- Proxy$1.prototype[key$6] = instance$6[key$6];
2319
+ Proxy$2.prototype[key$6] = instance$6[key$6];
2305
2320
 
2306
- var proxy = Proxy$1;
2321
+ var proxy = Proxy$2;
2307
2322
 
2308
2323
  var Buffer$3 = safeBuffer.exports.Buffer,
2309
2324
  crypto$1 = require$$1__default$1["default"],
@@ -2312,7 +2327,7 @@ var Buffer$3 = safeBuffer.exports.Buffer,
2312
2327
  HttpParser$1 = http_parser,
2313
2328
  Base$4 = base,
2314
2329
  Hybi$1 = hybi,
2315
- Proxy = proxy;
2330
+ Proxy$1 = proxy;
2316
2331
 
2317
2332
  var Client$2 = function(_url, options) {
2318
2333
  this.version = 'hybi-' + Hybi$1.VERSION;
@@ -2353,7 +2368,7 @@ var instance$5 = {
2353
2368
  VALID_PROTOCOLS: ['ws:', 'wss:'],
2354
2369
 
2355
2370
  proxy: function(origin, options) {
2356
- return new Proxy(this, origin, options);
2371
+ return new Proxy$1(this, origin, options);
2357
2372
  },
2358
2373
 
2359
2374
  start: function() {
@@ -3345,50 +3360,305 @@ WebSocket$1.EventSource = eventsource;
3345
3360
 
3346
3361
  var websocket = WebSocket$1;
3347
3362
 
3348
- Object.defineProperty(index_standalone, '__esModule', { value: true });
3363
+ var index_cjs = {};
3364
+
3365
+ const instanceOfAny = (object, constructors) => constructors.some((c) => object instanceof c);
3366
+
3367
+ let idbProxyableTypes;
3368
+ let cursorAdvanceMethods;
3369
+ // This is a function to prevent it throwing up in node environments.
3370
+ function getIdbProxyableTypes() {
3371
+ return (idbProxyableTypes ||
3372
+ (idbProxyableTypes = [
3373
+ IDBDatabase,
3374
+ IDBObjectStore,
3375
+ IDBIndex,
3376
+ IDBCursor,
3377
+ IDBTransaction,
3378
+ ]));
3379
+ }
3380
+ // This is a function to prevent it throwing up in node environments.
3381
+ function getCursorAdvanceMethods() {
3382
+ return (cursorAdvanceMethods ||
3383
+ (cursorAdvanceMethods = [
3384
+ IDBCursor.prototype.advance,
3385
+ IDBCursor.prototype.continue,
3386
+ IDBCursor.prototype.continuePrimaryKey,
3387
+ ]));
3388
+ }
3389
+ const cursorRequestMap = new WeakMap();
3390
+ const transactionDoneMap = new WeakMap();
3391
+ const transactionStoreNamesMap = new WeakMap();
3392
+ const transformCache = new WeakMap();
3393
+ const reverseTransformCache = new WeakMap();
3394
+ function promisifyRequest(request) {
3395
+ const promise = new Promise((resolve, reject) => {
3396
+ const unlisten = () => {
3397
+ request.removeEventListener('success', success);
3398
+ request.removeEventListener('error', error);
3399
+ };
3400
+ const success = () => {
3401
+ resolve(wrap(request.result));
3402
+ unlisten();
3403
+ };
3404
+ const error = () => {
3405
+ reject(request.error);
3406
+ unlisten();
3407
+ };
3408
+ request.addEventListener('success', success);
3409
+ request.addEventListener('error', error);
3410
+ });
3411
+ promise
3412
+ .then((value) => {
3413
+ // Since cursoring reuses the IDBRequest (*sigh*), we cache it for later retrieval
3414
+ // (see wrapFunction).
3415
+ if (value instanceof IDBCursor) {
3416
+ cursorRequestMap.set(value, request);
3417
+ }
3418
+ // Catching to avoid "Uncaught Promise exceptions"
3419
+ })
3420
+ .catch(() => { });
3421
+ // This mapping exists in reverseTransformCache but doesn't doesn't exist in transformCache. This
3422
+ // is because we create many promises from a single IDBRequest.
3423
+ reverseTransformCache.set(promise, request);
3424
+ return promise;
3425
+ }
3426
+ function cacheDonePromiseForTransaction(tx) {
3427
+ // Early bail if we've already created a done promise for this transaction.
3428
+ if (transactionDoneMap.has(tx))
3429
+ return;
3430
+ const done = new Promise((resolve, reject) => {
3431
+ const unlisten = () => {
3432
+ tx.removeEventListener('complete', complete);
3433
+ tx.removeEventListener('error', error);
3434
+ tx.removeEventListener('abort', error);
3435
+ };
3436
+ const complete = () => {
3437
+ resolve();
3438
+ unlisten();
3439
+ };
3440
+ const error = () => {
3441
+ reject(tx.error || new DOMException('AbortError', 'AbortError'));
3442
+ unlisten();
3443
+ };
3444
+ tx.addEventListener('complete', complete);
3445
+ tx.addEventListener('error', error);
3446
+ tx.addEventListener('abort', error);
3447
+ });
3448
+ // Cache it for later retrieval.
3449
+ transactionDoneMap.set(tx, done);
3450
+ }
3451
+ let idbProxyTraps = {
3452
+ get(target, prop, receiver) {
3453
+ if (target instanceof IDBTransaction) {
3454
+ // Special handling for transaction.done.
3455
+ if (prop === 'done')
3456
+ return transactionDoneMap.get(target);
3457
+ // Polyfill for objectStoreNames because of Edge.
3458
+ if (prop === 'objectStoreNames') {
3459
+ return target.objectStoreNames || transactionStoreNamesMap.get(target);
3460
+ }
3461
+ // Make tx.store return the only store in the transaction, or undefined if there are many.
3462
+ if (prop === 'store') {
3463
+ return receiver.objectStoreNames[1]
3464
+ ? undefined
3465
+ : receiver.objectStore(receiver.objectStoreNames[0]);
3466
+ }
3467
+ }
3468
+ // Else transform whatever we get back.
3469
+ return wrap(target[prop]);
3470
+ },
3471
+ set(target, prop, value) {
3472
+ target[prop] = value;
3473
+ return true;
3474
+ },
3475
+ has(target, prop) {
3476
+ if (target instanceof IDBTransaction &&
3477
+ (prop === 'done' || prop === 'store')) {
3478
+ return true;
3479
+ }
3480
+ return prop in target;
3481
+ },
3482
+ };
3483
+ function replaceTraps(callback) {
3484
+ idbProxyTraps = callback(idbProxyTraps);
3485
+ }
3486
+ function wrapFunction(func) {
3487
+ // Due to expected object equality (which is enforced by the caching in `wrap`), we
3488
+ // only create one new func per func.
3489
+ // Edge doesn't support objectStoreNames (booo), so we polyfill it here.
3490
+ if (func === IDBDatabase.prototype.transaction &&
3491
+ !('objectStoreNames' in IDBTransaction.prototype)) {
3492
+ return function (storeNames, ...args) {
3493
+ const tx = func.call(unwrap(this), storeNames, ...args);
3494
+ transactionStoreNamesMap.set(tx, storeNames.sort ? storeNames.sort() : [storeNames]);
3495
+ return wrap(tx);
3496
+ };
3497
+ }
3498
+ // Cursor methods are special, as the behaviour is a little more different to standard IDB. In
3499
+ // IDB, you advance the cursor and wait for a new 'success' on the IDBRequest that gave you the
3500
+ // cursor. It's kinda like a promise that can resolve with many values. That doesn't make sense
3501
+ // with real promises, so each advance methods returns a new promise for the cursor object, or
3502
+ // undefined if the end of the cursor has been reached.
3503
+ if (getCursorAdvanceMethods().includes(func)) {
3504
+ return function (...args) {
3505
+ // Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
3506
+ // the original object.
3507
+ func.apply(unwrap(this), args);
3508
+ return wrap(cursorRequestMap.get(this));
3509
+ };
3510
+ }
3511
+ return function (...args) {
3512
+ // Calling the original function with the proxy as 'this' causes ILLEGAL INVOCATION, so we use
3513
+ // the original object.
3514
+ return wrap(func.apply(unwrap(this), args));
3515
+ };
3516
+ }
3517
+ function transformCachableValue(value) {
3518
+ if (typeof value === 'function')
3519
+ return wrapFunction(value);
3520
+ // This doesn't return, it just creates a 'done' promise for the transaction,
3521
+ // which is later returned for transaction.done (see idbObjectHandler).
3522
+ if (value instanceof IDBTransaction)
3523
+ cacheDonePromiseForTransaction(value);
3524
+ if (instanceOfAny(value, getIdbProxyableTypes()))
3525
+ return new Proxy(value, idbProxyTraps);
3526
+ // Return the same value back if we're not going to transform it.
3527
+ return value;
3528
+ }
3529
+ function wrap(value) {
3530
+ // We sometimes generate multiple promises from a single IDBRequest (eg when cursoring), because
3531
+ // IDB is weird and a single IDBRequest can yield many responses, so these can't be cached.
3532
+ if (value instanceof IDBRequest)
3533
+ return promisifyRequest(value);
3534
+ // If we've already transformed this value before, reuse the transformed value.
3535
+ // This is faster, but it also provides object equality.
3536
+ if (transformCache.has(value))
3537
+ return transformCache.get(value);
3538
+ const newValue = transformCachableValue(value);
3539
+ // Not all types are transformed.
3540
+ // These may be primitive types, so they can't be WeakMap keys.
3541
+ if (newValue !== value) {
3542
+ transformCache.set(value, newValue);
3543
+ reverseTransformCache.set(newValue, value);
3544
+ }
3545
+ return newValue;
3546
+ }
3547
+ const unwrap = (value) => reverseTransformCache.get(value);
3548
+
3549
+ /**
3550
+ * Open a database.
3551
+ *
3552
+ * @param name Name of the database.
3553
+ * @param version Schema version.
3554
+ * @param callbacks Additional callbacks.
3555
+ */
3556
+ function openDB(name, version, { blocked, upgrade, blocking, terminated } = {}) {
3557
+ const request = indexedDB.open(name, version);
3558
+ const openPromise = wrap(request);
3559
+ if (upgrade) {
3560
+ request.addEventListener('upgradeneeded', (event) => {
3561
+ upgrade(wrap(request.result), event.oldVersion, event.newVersion, wrap(request.transaction), event);
3562
+ });
3563
+ }
3564
+ if (blocked) {
3565
+ request.addEventListener('blocked', (event) => blocked(
3566
+ // Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405
3567
+ event.oldVersion, event.newVersion, event));
3568
+ }
3569
+ openPromise
3570
+ .then((db) => {
3571
+ if (terminated)
3572
+ db.addEventListener('close', () => terminated());
3573
+ if (blocking) {
3574
+ db.addEventListener('versionchange', (event) => blocking(event.oldVersion, event.newVersion, event));
3575
+ }
3576
+ })
3577
+ .catch(() => { });
3578
+ return openPromise;
3579
+ }
3580
+ /**
3581
+ * Delete a database.
3582
+ *
3583
+ * @param name Name of the database.
3584
+ */
3585
+ function deleteDB(name, { blocked } = {}) {
3586
+ const request = indexedDB.deleteDatabase(name);
3587
+ if (blocked) {
3588
+ request.addEventListener('blocked', (event) => blocked(
3589
+ // Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405
3590
+ event.oldVersion, event));
3591
+ }
3592
+ return wrap(request).then(() => undefined);
3593
+ }
3349
3594
 
3350
- var Websocket = websocket;
3351
- var util = require$$1__default$3["default"];
3352
- var logger$1 = require$$2__default$3["default"];
3353
- var component = require$$3__default["default"];
3595
+ const readMethods = ['get', 'getKey', 'getAll', 'getAllKeys', 'count'];
3596
+ const writeMethods = ['put', 'add', 'delete', 'clear'];
3597
+ const cachedMethods = new Map();
3598
+ function getMethod(target, prop) {
3599
+ if (!(target instanceof IDBDatabase &&
3600
+ !(prop in target) &&
3601
+ typeof prop === 'string')) {
3602
+ return;
3603
+ }
3604
+ if (cachedMethods.get(prop))
3605
+ return cachedMethods.get(prop);
3606
+ const targetFuncName = prop.replace(/FromIndex$/, '');
3607
+ const useIndex = prop !== targetFuncName;
3608
+ const isWrite = writeMethods.includes(targetFuncName);
3609
+ if (
3610
+ // Bail if the target doesn't exist on the target. Eg, getAll isn't in Edge.
3611
+ !(targetFuncName in (useIndex ? IDBIndex : IDBObjectStore).prototype) ||
3612
+ !(isWrite || readMethods.includes(targetFuncName))) {
3613
+ return;
3614
+ }
3615
+ const method = async function (storeName, ...args) {
3616
+ // isWrite ? 'readwrite' : undefined gzipps better, but fails in Edge :(
3617
+ const tx = this.transaction(storeName, isWrite ? 'readwrite' : 'readonly');
3618
+ let target = tx.store;
3619
+ if (useIndex)
3620
+ target = target.index(args.shift());
3621
+ // Must reject if op rejects.
3622
+ // If it's a write operation, must reject if tx.done rejects.
3623
+ // Must reject with op rejection first.
3624
+ // Must resolve with op value.
3625
+ // Must handle both promises (no unhandled rejections)
3626
+ return (await Promise.all([
3627
+ target[targetFuncName](...args),
3628
+ isWrite && tx.done,
3629
+ ]))[0];
3630
+ };
3631
+ cachedMethods.set(prop, method);
3632
+ return method;
3633
+ }
3634
+ replaceTraps((oldTraps) => ({
3635
+ ...oldTraps,
3636
+ get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get(target, prop, receiver),
3637
+ has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop),
3638
+ }));
3639
+
3640
+ var build = /*#__PURE__*/Object.freeze({
3641
+ __proto__: null,
3642
+ deleteDB: deleteDB,
3643
+ openDB: openDB,
3644
+ unwrap: unwrap,
3645
+ wrap: wrap
3646
+ });
3354
3647
 
3355
- function _interopDefaultLegacy$1 (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
3648
+ var require$$3 = /*@__PURE__*/getAugmentedNamespace(build);
3356
3649
 
3357
- var Websocket__default = /*#__PURE__*/_interopDefaultLegacy$1(Websocket);
3650
+ (function (exports) {
3358
3651
 
3359
- /**
3360
- * @license
3361
- * Copyright 2017 Google LLC
3362
- *
3363
- * Licensed under the Apache License, Version 2.0 (the "License");
3364
- * you may not use this file except in compliance with the License.
3365
- * You may obtain a copy of the License at
3366
- *
3367
- * http://www.apache.org/licenses/LICENSE-2.0
3368
- *
3369
- * Unless required by applicable law or agreed to in writing, software
3370
- * distributed under the License is distributed on an "AS IS" BASIS,
3371
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3372
- * See the License for the specific language governing permissions and
3373
- * limitations under the License.
3374
- */
3375
- const PROTOCOL_VERSION = '5';
3376
- const VERSION_PARAM = 'v';
3377
- const TRANSPORT_SESSION_PARAM = 's';
3378
- const REFERER_PARAM = 'r';
3379
- const FORGE_REF = 'f';
3380
- // Matches console.firebase.google.com, firebase-console-*.corp.google.com and
3381
- // firebase.corp.google.com
3382
- const FORGE_DOMAIN_RE = /(console\.firebase|firebase-console-\w+\.corp|firebase\.corp)\.google\.com/;
3383
- const LAST_SESSION_PARAM = 'ls';
3384
- const APPLICATION_ID_PARAM = 'p';
3385
- const APP_CHECK_TOKEN_PARAM = 'ac';
3386
- const WEBSOCKET = 'websocket';
3387
- const LONG_POLLING = 'long_polling';
3652
+ Object.defineProperty(exports, '__esModule', { value: true });
3653
+
3654
+ var component = require$$0__default$3["default"];
3655
+ var logger$1 = require$$1__default$3["default"];
3656
+ var util = require$$2__default$3["default"];
3657
+ var idb = require$$3;
3388
3658
 
3389
3659
  /**
3390
3660
  * @license
3391
- * Copyright 2017 Google LLC
3661
+ * Copyright 2019 Google LLC
3392
3662
  *
3393
3663
  * Licensed under the Apache License, Version 2.0 (the "License");
3394
3664
  * you may not use this file except in compliance with the License.
@@ -3402,62 +3672,49 @@ const LONG_POLLING = 'long_polling';
3402
3672
  * See the License for the specific language governing permissions and
3403
3673
  * limitations under the License.
3404
3674
  */
3675
+ class PlatformLoggerServiceImpl {
3676
+ constructor(container) {
3677
+ this.container = container;
3678
+ }
3679
+ // In initial implementation, this will be called by installations on
3680
+ // auth token refresh, and installations will send this string.
3681
+ getPlatformInfoString() {
3682
+ const providers = this.container.getProviders();
3683
+ // Loop through providers and get library/version pairs from any that are
3684
+ // version components.
3685
+ return providers
3686
+ .map(provider => {
3687
+ if (isVersionServiceProvider(provider)) {
3688
+ const service = provider.getImmediate();
3689
+ return `${service.library}/${service.version}`;
3690
+ }
3691
+ else {
3692
+ return null;
3693
+ }
3694
+ })
3695
+ .filter(logString => logString)
3696
+ .join(' ');
3697
+ }
3698
+ }
3405
3699
  /**
3406
- * Wraps a DOM Storage object and:
3407
- * - automatically encode objects as JSON strings before storing them to allow us to store arbitrary types.
3408
- * - prefixes names with "firebase:" to avoid collisions with app data.
3409
3700
  *
3410
- * We automatically (see storage.js) create two such wrappers, one for sessionStorage,
3411
- * and one for localStorage.
3701
+ * @param provider check if this provider provides a VersionService
3412
3702
  *
3703
+ * NOTE: Using Provider<'app-version'> is a hack to indicate that the provider
3704
+ * provides VersionService. The provider is not necessarily a 'app-version'
3705
+ * provider.
3413
3706
  */
3414
- class DOMStorageWrapper {
3415
- /**
3416
- * @param domStorage_ - The underlying storage object (e.g. localStorage or sessionStorage)
3417
- */
3418
- constructor(domStorage_) {
3419
- this.domStorage_ = domStorage_;
3420
- // Use a prefix to avoid collisions with other stuff saved by the app.
3421
- this.prefix_ = 'firebase:';
3422
- }
3423
- /**
3424
- * @param key - The key to save the value under
3425
- * @param value - The value being stored, or null to remove the key.
3426
- */
3427
- set(key, value) {
3428
- if (value == null) {
3429
- this.domStorage_.removeItem(this.prefixedName_(key));
3430
- }
3431
- else {
3432
- this.domStorage_.setItem(this.prefixedName_(key), util.stringify(value));
3433
- }
3434
- }
3435
- /**
3436
- * @returns The value that was stored under this key, or null
3437
- */
3438
- get(key) {
3439
- const storedVal = this.domStorage_.getItem(this.prefixedName_(key));
3440
- if (storedVal == null) {
3441
- return null;
3442
- }
3443
- else {
3444
- return util.jsonEval(storedVal);
3445
- }
3446
- }
3447
- remove(key) {
3448
- this.domStorage_.removeItem(this.prefixedName_(key));
3449
- }
3450
- prefixedName_(name) {
3451
- return this.prefix_ + name;
3452
- }
3453
- toString() {
3454
- return this.domStorage_.toString();
3455
- }
3707
+ function isVersionServiceProvider(provider) {
3708
+ const component = provider.getComponent();
3709
+ return (component === null || component === void 0 ? void 0 : component.type) === "VERSION" /* ComponentType.VERSION */;
3456
3710
  }
3457
3711
 
3712
+ const name$q = "@firebase/app";
3713
+ const version$1 = "0.10.18-canary.01f36ea41";
3714
+
3458
3715
  /**
3459
3716
  * @license
3460
- * Copyright 2017 Google LLC
3717
+ * Copyright 2019 Google LLC
3461
3718
  *
3462
3719
  * Licensed under the Apache License, Version 2.0 (the "License");
3463
3720
  * you may not use this file except in compliance with the License.
@@ -3471,37 +3728,64 @@ class DOMStorageWrapper {
3471
3728
  * See the License for the specific language governing permissions and
3472
3729
  * limitations under the License.
3473
3730
  */
3474
- /**
3475
- * An in-memory storage implementation that matches the API of DOMStorageWrapper
3476
- * (TODO: create interface for both to implement).
3477
- */
3478
- class MemoryStorage {
3479
- constructor() {
3480
- this.cache_ = {};
3481
- this.isInMemoryStorage = true;
3482
- }
3483
- set(key, value) {
3484
- if (value == null) {
3485
- delete this.cache_[key];
3486
- }
3487
- else {
3488
- this.cache_[key] = value;
3489
- }
3490
- }
3491
- get(key) {
3492
- if (util.contains(this.cache_, key)) {
3493
- return this.cache_[key];
3494
- }
3495
- return null;
3496
- }
3497
- remove(key) {
3498
- delete this.cache_[key];
3499
- }
3500
- }
3731
+ const logger = new logger$1.Logger('@firebase/app');
3732
+
3733
+ const name$p = "@firebase/app-compat";
3734
+
3735
+ const name$o = "@firebase/analytics-compat";
3736
+
3737
+ const name$n = "@firebase/analytics";
3738
+
3739
+ const name$m = "@firebase/app-check-compat";
3740
+
3741
+ const name$l = "@firebase/app-check";
3742
+
3743
+ const name$k = "@firebase/auth";
3744
+
3745
+ const name$j = "@firebase/auth-compat";
3746
+
3747
+ const name$i = "@firebase/database";
3748
+
3749
+ const name$h = "@firebase/data-connect";
3750
+
3751
+ const name$g = "@firebase/database-compat";
3752
+
3753
+ const name$f = "@firebase/functions";
3754
+
3755
+ const name$e = "@firebase/functions-compat";
3756
+
3757
+ const name$d = "@firebase/installations";
3758
+
3759
+ const name$c = "@firebase/installations-compat";
3760
+
3761
+ const name$b = "@firebase/messaging";
3762
+
3763
+ const name$a = "@firebase/messaging-compat";
3764
+
3765
+ const name$9 = "@firebase/performance";
3766
+
3767
+ const name$8 = "@firebase/performance-compat";
3768
+
3769
+ const name$7 = "@firebase/remote-config";
3770
+
3771
+ const name$6 = "@firebase/remote-config-compat";
3772
+
3773
+ const name$5 = "@firebase/storage";
3774
+
3775
+ const name$4 = "@firebase/storage-compat";
3776
+
3777
+ const name$3 = "@firebase/firestore";
3778
+
3779
+ const name$2 = "@firebase/vertexai";
3780
+
3781
+ const name$1 = "@firebase/firestore-compat";
3782
+
3783
+ const name = "firebase";
3784
+ const version = "11.2.0-canary.01f36ea41";
3501
3785
 
3502
3786
  /**
3503
3787
  * @license
3504
- * Copyright 2017 Google LLC
3788
+ * Copyright 2019 Google LLC
3505
3789
  *
3506
3790
  * Licensed under the Apache License, Version 2.0 (the "License");
3507
3791
  * you may not use this file except in compliance with the License.
@@ -3516,40 +3800,45 @@ class MemoryStorage {
3516
3800
  * limitations under the License.
3517
3801
  */
3518
3802
  /**
3519
- * Helper to create a DOMStorageWrapper or else fall back to MemoryStorage.
3520
- * TODO: Once MemoryStorage and DOMStorageWrapper have a shared interface this method annotation should change
3521
- * to reflect this type
3803
+ * The default app name
3522
3804
  *
3523
- * @param domStorageName - Name of the underlying storage object
3524
- * (e.g. 'localStorage' or 'sessionStorage').
3525
- * @returns Turning off type information until a common interface is defined.
3805
+ * @internal
3526
3806
  */
3527
- const createStoragefor = function (domStorageName) {
3528
- try {
3529
- // NOTE: just accessing "localStorage" or "window['localStorage']" may throw a security exception,
3530
- // so it must be inside the try/catch.
3531
- if (typeof window !== 'undefined' &&
3532
- typeof window[domStorageName] !== 'undefined') {
3533
- // Need to test cache. Just because it's here doesn't mean it works
3534
- const domStorage = window[domStorageName];
3535
- domStorage.setItem('firebase:sentinel', 'cache');
3536
- domStorage.removeItem('firebase:sentinel');
3537
- return new DOMStorageWrapper(domStorage);
3538
- }
3539
- }
3540
- catch (e) { }
3541
- // Failed to create wrapper. Just return in-memory storage.
3542
- // TODO: log?
3543
- return new MemoryStorage();
3807
+ const DEFAULT_ENTRY_NAME = '[DEFAULT]';
3808
+ const PLATFORM_LOG_STRING = {
3809
+ [name$q]: 'fire-core',
3810
+ [name$p]: 'fire-core-compat',
3811
+ [name$n]: 'fire-analytics',
3812
+ [name$o]: 'fire-analytics-compat',
3813
+ [name$l]: 'fire-app-check',
3814
+ [name$m]: 'fire-app-check-compat',
3815
+ [name$k]: 'fire-auth',
3816
+ [name$j]: 'fire-auth-compat',
3817
+ [name$i]: 'fire-rtdb',
3818
+ [name$h]: 'fire-data-connect',
3819
+ [name$g]: 'fire-rtdb-compat',
3820
+ [name$f]: 'fire-fn',
3821
+ [name$e]: 'fire-fn-compat',
3822
+ [name$d]: 'fire-iid',
3823
+ [name$c]: 'fire-iid-compat',
3824
+ [name$b]: 'fire-fcm',
3825
+ [name$a]: 'fire-fcm-compat',
3826
+ [name$9]: 'fire-perf',
3827
+ [name$8]: 'fire-perf-compat',
3828
+ [name$7]: 'fire-rc',
3829
+ [name$6]: 'fire-rc-compat',
3830
+ [name$5]: 'fire-gcs',
3831
+ [name$4]: 'fire-gcs-compat',
3832
+ [name$3]: 'fire-fst',
3833
+ [name$1]: 'fire-fst-compat',
3834
+ [name$2]: 'fire-vertex',
3835
+ 'fire-js': 'fire-js', // Platform identifier for JS SDK.
3836
+ [name]: 'fire-js-all'
3544
3837
  };
3545
- /** A storage object that lasts across sessions */
3546
- const PersistentStorage = createStoragefor('localStorage');
3547
- /** A storage object that only lasts one session */
3548
- const SessionStorage = createStoragefor('sessionStorage');
3549
3838
 
3550
3839
  /**
3551
3840
  * @license
3552
- * Copyright 2017 Google LLC
3841
+ * Copyright 2019 Google LLC
3553
3842
  *
3554
3843
  * Licensed under the Apache License, Version 2.0 (the "License");
3555
3844
  * you may not use this file except in compliance with the License.
@@ -3563,45 +3852,1291 @@ const SessionStorage = createStoragefor('sessionStorage');
3563
3852
  * See the License for the specific language governing permissions and
3564
3853
  * limitations under the License.
3565
3854
  */
3566
- const logClient$1 = new logger$1.Logger('@firebase/database');
3567
3855
  /**
3568
- * Returns a locally-unique ID (generated by just incrementing up from 0 each time its called).
3856
+ * @internal
3569
3857
  */
3570
- const LUIDGenerator = (function () {
3571
- let id = 1;
3572
- return function () {
3573
- return id++;
3574
- };
3575
- })();
3858
+ const _apps = new Map();
3576
3859
  /**
3577
- * Sha1 hash of the input string
3578
- * @param str - The string to hash
3579
- * @returns {!string} The resulting hash
3860
+ * @internal
3580
3861
  */
3581
- const sha1 = function (str) {
3582
- const utf8Bytes = util.stringToByteArray(str);
3583
- const sha1 = new util.Sha1();
3584
- sha1.update(utf8Bytes);
3585
- const sha1Bytes = sha1.digest();
3586
- return util.base64.encodeByteArray(sha1Bytes);
3587
- };
3588
- const buildLogMessage_ = function (...varArgs) {
3589
- let message = '';
3590
- for (let i = 0; i < varArgs.length; i++) {
3591
- const arg = varArgs[i];
3592
- if (Array.isArray(arg) ||
3593
- (arg &&
3594
- typeof arg === 'object' &&
3595
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3596
- typeof arg.length === 'number')) {
3597
- message += buildLogMessage_.apply(null, arg);
3598
- }
3599
- else if (typeof arg === 'object') {
3600
- message += util.stringify(arg);
3601
- }
3602
- else {
3603
- message += arg;
3604
- }
3862
+ const _serverApps = new Map();
3863
+ /**
3864
+ * Registered components.
3865
+ *
3866
+ * @internal
3867
+ */
3868
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3869
+ const _components = new Map();
3870
+ /**
3871
+ * @param component - the component being added to this app's container
3872
+ *
3873
+ * @internal
3874
+ */
3875
+ function _addComponent(app, component) {
3876
+ try {
3877
+ app.container.addComponent(component);
3878
+ }
3879
+ catch (e) {
3880
+ logger.debug(`Component ${component.name} failed to register with FirebaseApp ${app.name}`, e);
3881
+ }
3882
+ }
3883
+ /**
3884
+ *
3885
+ * @internal
3886
+ */
3887
+ function _addOrOverwriteComponent(app, component) {
3888
+ app.container.addOrOverwriteComponent(component);
3889
+ }
3890
+ /**
3891
+ *
3892
+ * @param component - the component to register
3893
+ * @returns whether or not the component is registered successfully
3894
+ *
3895
+ * @internal
3896
+ */
3897
+ function _registerComponent(component) {
3898
+ const componentName = component.name;
3899
+ if (_components.has(componentName)) {
3900
+ logger.debug(`There were multiple attempts to register component ${componentName}.`);
3901
+ return false;
3902
+ }
3903
+ _components.set(componentName, component);
3904
+ // add the component to existing app instances
3905
+ for (const app of _apps.values()) {
3906
+ _addComponent(app, component);
3907
+ }
3908
+ for (const serverApp of _serverApps.values()) {
3909
+ _addComponent(serverApp, component);
3910
+ }
3911
+ return true;
3912
+ }
3913
+ /**
3914
+ *
3915
+ * @param app - FirebaseApp instance
3916
+ * @param name - service name
3917
+ *
3918
+ * @returns the provider for the service with the matching name
3919
+ *
3920
+ * @internal
3921
+ */
3922
+ function _getProvider(app, name) {
3923
+ const heartbeatController = app.container
3924
+ .getProvider('heartbeat')
3925
+ .getImmediate({ optional: true });
3926
+ if (heartbeatController) {
3927
+ void heartbeatController.triggerHeartbeat();
3928
+ }
3929
+ return app.container.getProvider(name);
3930
+ }
3931
+ /**
3932
+ *
3933
+ * @param app - FirebaseApp instance
3934
+ * @param name - service name
3935
+ * @param instanceIdentifier - service instance identifier in case the service supports multiple instances
3936
+ *
3937
+ * @internal
3938
+ */
3939
+ function _removeServiceInstance(app, name, instanceIdentifier = DEFAULT_ENTRY_NAME) {
3940
+ _getProvider(app, name).clearInstance(instanceIdentifier);
3941
+ }
3942
+ /**
3943
+ *
3944
+ * @param obj - an object of type FirebaseApp or FirebaseOptions.
3945
+ *
3946
+ * @returns true if the provide object is of type FirebaseApp.
3947
+ *
3948
+ * @internal
3949
+ */
3950
+ function _isFirebaseApp(obj) {
3951
+ return obj.options !== undefined;
3952
+ }
3953
+ /**
3954
+ *
3955
+ * @param obj - an object of type FirebaseApp.
3956
+ *
3957
+ * @returns true if the provided object is of type FirebaseServerAppImpl.
3958
+ *
3959
+ * @internal
3960
+ */
3961
+ function _isFirebaseServerApp(obj) {
3962
+ if (obj === null || obj === undefined) {
3963
+ return false;
3964
+ }
3965
+ return obj.settings !== undefined;
3966
+ }
3967
+ /**
3968
+ * Test only
3969
+ *
3970
+ * @internal
3971
+ */
3972
+ function _clearComponents() {
3973
+ _components.clear();
3974
+ }
3975
+
3976
+ /**
3977
+ * @license
3978
+ * Copyright 2019 Google LLC
3979
+ *
3980
+ * Licensed under the Apache License, Version 2.0 (the "License");
3981
+ * you may not use this file except in compliance with the License.
3982
+ * You may obtain a copy of the License at
3983
+ *
3984
+ * http://www.apache.org/licenses/LICENSE-2.0
3985
+ *
3986
+ * Unless required by applicable law or agreed to in writing, software
3987
+ * distributed under the License is distributed on an "AS IS" BASIS,
3988
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3989
+ * See the License for the specific language governing permissions and
3990
+ * limitations under the License.
3991
+ */
3992
+ const ERRORS = {
3993
+ ["no-app" /* AppError.NO_APP */]: "No Firebase App '{$appName}' has been created - " +
3994
+ 'call initializeApp() first',
3995
+ ["bad-app-name" /* AppError.BAD_APP_NAME */]: "Illegal App name: '{$appName}'",
3996
+ ["duplicate-app" /* AppError.DUPLICATE_APP */]: "Firebase App named '{$appName}' already exists with different options or config",
3997
+ ["app-deleted" /* AppError.APP_DELETED */]: "Firebase App named '{$appName}' already deleted",
3998
+ ["server-app-deleted" /* AppError.SERVER_APP_DELETED */]: 'Firebase Server App has been deleted',
3999
+ ["no-options" /* AppError.NO_OPTIONS */]: 'Need to provide options, when not being deployed to hosting via source.',
4000
+ ["invalid-app-argument" /* AppError.INVALID_APP_ARGUMENT */]: 'firebase.{$appName}() takes either no argument or a ' +
4001
+ 'Firebase App instance.',
4002
+ ["invalid-log-argument" /* AppError.INVALID_LOG_ARGUMENT */]: 'First argument to `onLog` must be null or a function.',
4003
+ ["idb-open" /* AppError.IDB_OPEN */]: 'Error thrown when opening IndexedDB. Original error: {$originalErrorMessage}.',
4004
+ ["idb-get" /* AppError.IDB_GET */]: 'Error thrown when reading from IndexedDB. Original error: {$originalErrorMessage}.',
4005
+ ["idb-set" /* AppError.IDB_WRITE */]: 'Error thrown when writing to IndexedDB. Original error: {$originalErrorMessage}.',
4006
+ ["idb-delete" /* AppError.IDB_DELETE */]: 'Error thrown when deleting from IndexedDB. Original error: {$originalErrorMessage}.',
4007
+ ["finalization-registry-not-supported" /* AppError.FINALIZATION_REGISTRY_NOT_SUPPORTED */]: 'FirebaseServerApp deleteOnDeref field defined but the JS runtime does not support FinalizationRegistry.',
4008
+ ["invalid-server-app-environment" /* AppError.INVALID_SERVER_APP_ENVIRONMENT */]: 'FirebaseServerApp is not for use in browser environments.'
4009
+ };
4010
+ const ERROR_FACTORY = new util.ErrorFactory('app', 'Firebase', ERRORS);
4011
+
4012
+ /**
4013
+ * @license
4014
+ * Copyright 2019 Google LLC
4015
+ *
4016
+ * Licensed under the Apache License, Version 2.0 (the "License");
4017
+ * you may not use this file except in compliance with the License.
4018
+ * You may obtain a copy of the License at
4019
+ *
4020
+ * http://www.apache.org/licenses/LICENSE-2.0
4021
+ *
4022
+ * Unless required by applicable law or agreed to in writing, software
4023
+ * distributed under the License is distributed on an "AS IS" BASIS,
4024
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4025
+ * See the License for the specific language governing permissions and
4026
+ * limitations under the License.
4027
+ */
4028
+ class FirebaseAppImpl {
4029
+ constructor(options, config, container) {
4030
+ this._isDeleted = false;
4031
+ this._options = Object.assign({}, options);
4032
+ this._config = Object.assign({}, config);
4033
+ this._name = config.name;
4034
+ this._automaticDataCollectionEnabled =
4035
+ config.automaticDataCollectionEnabled;
4036
+ this._container = container;
4037
+ this.container.addComponent(new component.Component('app', () => this, "PUBLIC" /* ComponentType.PUBLIC */));
4038
+ }
4039
+ get automaticDataCollectionEnabled() {
4040
+ this.checkDestroyed();
4041
+ return this._automaticDataCollectionEnabled;
4042
+ }
4043
+ set automaticDataCollectionEnabled(val) {
4044
+ this.checkDestroyed();
4045
+ this._automaticDataCollectionEnabled = val;
4046
+ }
4047
+ get name() {
4048
+ this.checkDestroyed();
4049
+ return this._name;
4050
+ }
4051
+ get options() {
4052
+ this.checkDestroyed();
4053
+ return this._options;
4054
+ }
4055
+ get config() {
4056
+ this.checkDestroyed();
4057
+ return this._config;
4058
+ }
4059
+ get container() {
4060
+ return this._container;
4061
+ }
4062
+ get isDeleted() {
4063
+ return this._isDeleted;
4064
+ }
4065
+ set isDeleted(val) {
4066
+ this._isDeleted = val;
4067
+ }
4068
+ /**
4069
+ * This function will throw an Error if the App has already been deleted -
4070
+ * use before performing API actions on the App.
4071
+ */
4072
+ checkDestroyed() {
4073
+ if (this.isDeleted) {
4074
+ throw ERROR_FACTORY.create("app-deleted" /* AppError.APP_DELETED */, { appName: this._name });
4075
+ }
4076
+ }
4077
+ }
4078
+
4079
+ /**
4080
+ * @license
4081
+ * Copyright 2023 Google LLC
4082
+ *
4083
+ * Licensed under the Apache License, Version 2.0 (the "License");
4084
+ * you may not use this file except in compliance with the License.
4085
+ * You may obtain a copy of the License at
4086
+ *
4087
+ * http://www.apache.org/licenses/LICENSE-2.0
4088
+ *
4089
+ * Unless required by applicable law or agreed to in writing, software
4090
+ * distributed under the License is distributed on an "AS IS" BASIS,
4091
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4092
+ * See the License for the specific language governing permissions and
4093
+ * limitations under the License.
4094
+ */
4095
+ // Parse the token and check to see if the `exp` claim is in the future.
4096
+ // Reports an error to the console if the token or claim could not be parsed, or if `exp` is in
4097
+ // the past.
4098
+ function validateTokenTTL(base64Token, tokenName) {
4099
+ const secondPart = util.base64Decode(base64Token.split('.')[1]);
4100
+ if (secondPart === null) {
4101
+ console.error(`FirebaseServerApp ${tokenName} is invalid: second part could not be parsed.`);
4102
+ return;
4103
+ }
4104
+ const expClaim = JSON.parse(secondPart).exp;
4105
+ if (expClaim === undefined) {
4106
+ console.error(`FirebaseServerApp ${tokenName} is invalid: expiration claim could not be parsed`);
4107
+ return;
4108
+ }
4109
+ const exp = JSON.parse(secondPart).exp * 1000;
4110
+ const now = new Date().getTime();
4111
+ const diff = exp - now;
4112
+ if (diff <= 0) {
4113
+ console.error(`FirebaseServerApp ${tokenName} is invalid: the token has expired.`);
4114
+ }
4115
+ }
4116
+ class FirebaseServerAppImpl extends FirebaseAppImpl {
4117
+ constructor(options, serverConfig, name, container) {
4118
+ // Build configuration parameters for the FirebaseAppImpl base class.
4119
+ const automaticDataCollectionEnabled = serverConfig.automaticDataCollectionEnabled !== undefined
4120
+ ? serverConfig.automaticDataCollectionEnabled
4121
+ : false;
4122
+ // Create the FirebaseAppSettings object for the FirebaseAppImp constructor.
4123
+ const config = {
4124
+ name,
4125
+ automaticDataCollectionEnabled
4126
+ };
4127
+ if (options.apiKey !== undefined) {
4128
+ // Construct the parent FirebaseAppImp object.
4129
+ super(options, config, container);
4130
+ }
4131
+ else {
4132
+ const appImpl = options;
4133
+ super(appImpl.options, config, container);
4134
+ }
4135
+ // Now construct the data for the FirebaseServerAppImpl.
4136
+ this._serverConfig = Object.assign({ automaticDataCollectionEnabled }, serverConfig);
4137
+ // Ensure that the current time is within the `authIdtoken` window of validity.
4138
+ if (this._serverConfig.authIdToken) {
4139
+ validateTokenTTL(this._serverConfig.authIdToken, 'authIdToken');
4140
+ }
4141
+ // Ensure that the current time is within the `appCheckToken` window of validity.
4142
+ if (this._serverConfig.appCheckToken) {
4143
+ validateTokenTTL(this._serverConfig.appCheckToken, 'appCheckToken');
4144
+ }
4145
+ this._finalizationRegistry = null;
4146
+ if (typeof FinalizationRegistry !== 'undefined') {
4147
+ this._finalizationRegistry = new FinalizationRegistry(() => {
4148
+ this.automaticCleanup();
4149
+ });
4150
+ }
4151
+ this._refCount = 0;
4152
+ this.incRefCount(this._serverConfig.releaseOnDeref);
4153
+ // Do not retain a hard reference to the dref object, otherwise the FinalizationRegistry
4154
+ // will never trigger.
4155
+ this._serverConfig.releaseOnDeref = undefined;
4156
+ serverConfig.releaseOnDeref = undefined;
4157
+ registerVersion(name$q, version$1, 'serverapp');
4158
+ }
4159
+ toJSON() {
4160
+ return undefined;
4161
+ }
4162
+ get refCount() {
4163
+ return this._refCount;
4164
+ }
4165
+ // Increment the reference count of this server app. If an object is provided, register it
4166
+ // with the finalization registry.
4167
+ incRefCount(obj) {
4168
+ if (this.isDeleted) {
4169
+ return;
4170
+ }
4171
+ this._refCount++;
4172
+ if (obj !== undefined && this._finalizationRegistry !== null) {
4173
+ this._finalizationRegistry.register(obj, this);
4174
+ }
4175
+ }
4176
+ // Decrement the reference count.
4177
+ decRefCount() {
4178
+ if (this.isDeleted) {
4179
+ return 0;
4180
+ }
4181
+ return --this._refCount;
4182
+ }
4183
+ // Invoked by the FinalizationRegistry callback to note that this app should go through its
4184
+ // reference counts and delete itself if no reference count remain. The coordinating logic that
4185
+ // handles this is in deleteApp(...).
4186
+ automaticCleanup() {
4187
+ void deleteApp(this);
4188
+ }
4189
+ get settings() {
4190
+ this.checkDestroyed();
4191
+ return this._serverConfig;
4192
+ }
4193
+ /**
4194
+ * This function will throw an Error if the App has already been deleted -
4195
+ * use before performing API actions on the App.
4196
+ */
4197
+ checkDestroyed() {
4198
+ if (this.isDeleted) {
4199
+ throw ERROR_FACTORY.create("server-app-deleted" /* AppError.SERVER_APP_DELETED */);
4200
+ }
4201
+ }
4202
+ }
4203
+
4204
+ /**
4205
+ * @license
4206
+ * Copyright 2019 Google LLC
4207
+ *
4208
+ * Licensed under the Apache License, Version 2.0 (the "License");
4209
+ * you may not use this file except in compliance with the License.
4210
+ * You may obtain a copy of the License at
4211
+ *
4212
+ * http://www.apache.org/licenses/LICENSE-2.0
4213
+ *
4214
+ * Unless required by applicable law or agreed to in writing, software
4215
+ * distributed under the License is distributed on an "AS IS" BASIS,
4216
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4217
+ * See the License for the specific language governing permissions and
4218
+ * limitations under the License.
4219
+ */
4220
+ /**
4221
+ * The current SDK version.
4222
+ *
4223
+ * @public
4224
+ */
4225
+ const SDK_VERSION = version;
4226
+ function initializeApp(_options, rawConfig = {}) {
4227
+ let options = _options;
4228
+ if (typeof rawConfig !== 'object') {
4229
+ const name = rawConfig;
4230
+ rawConfig = { name };
4231
+ }
4232
+ const config = Object.assign({ name: DEFAULT_ENTRY_NAME, automaticDataCollectionEnabled: false }, rawConfig);
4233
+ const name = config.name;
4234
+ if (typeof name !== 'string' || !name) {
4235
+ throw ERROR_FACTORY.create("bad-app-name" /* AppError.BAD_APP_NAME */, {
4236
+ appName: String(name)
4237
+ });
4238
+ }
4239
+ options || (options = util.getDefaultAppConfig());
4240
+ if (!options) {
4241
+ throw ERROR_FACTORY.create("no-options" /* AppError.NO_OPTIONS */);
4242
+ }
4243
+ const existingApp = _apps.get(name);
4244
+ if (existingApp) {
4245
+ // return the existing app if options and config deep equal the ones in the existing app.
4246
+ if (util.deepEqual(options, existingApp.options) &&
4247
+ util.deepEqual(config, existingApp.config)) {
4248
+ return existingApp;
4249
+ }
4250
+ else {
4251
+ throw ERROR_FACTORY.create("duplicate-app" /* AppError.DUPLICATE_APP */, { appName: name });
4252
+ }
4253
+ }
4254
+ const container = new component.ComponentContainer(name);
4255
+ for (const component of _components.values()) {
4256
+ container.addComponent(component);
4257
+ }
4258
+ const newApp = new FirebaseAppImpl(options, config, container);
4259
+ _apps.set(name, newApp);
4260
+ return newApp;
4261
+ }
4262
+ function initializeServerApp(_options, _serverAppConfig) {
4263
+ if (util.isBrowser() && !util.isWebWorker()) {
4264
+ // FirebaseServerApp isn't designed to be run in browsers.
4265
+ throw ERROR_FACTORY.create("invalid-server-app-environment" /* AppError.INVALID_SERVER_APP_ENVIRONMENT */);
4266
+ }
4267
+ if (_serverAppConfig.automaticDataCollectionEnabled === undefined) {
4268
+ _serverAppConfig.automaticDataCollectionEnabled = false;
4269
+ }
4270
+ let appOptions;
4271
+ if (_isFirebaseApp(_options)) {
4272
+ appOptions = _options.options;
4273
+ }
4274
+ else {
4275
+ appOptions = _options;
4276
+ }
4277
+ // Build an app name based on a hash of the configuration options.
4278
+ const nameObj = Object.assign(Object.assign({}, _serverAppConfig), appOptions);
4279
+ // However, Do not mangle the name based on releaseOnDeref, since it will vary between the
4280
+ // construction of FirebaseServerApp instances. For example, if the object is the request headers.
4281
+ if (nameObj.releaseOnDeref !== undefined) {
4282
+ delete nameObj.releaseOnDeref;
4283
+ }
4284
+ const hashCode = (s) => {
4285
+ return [...s].reduce((hash, c) => (Math.imul(31, hash) + c.charCodeAt(0)) | 0, 0);
4286
+ };
4287
+ if (_serverAppConfig.releaseOnDeref !== undefined) {
4288
+ if (typeof FinalizationRegistry === 'undefined') {
4289
+ throw ERROR_FACTORY.create("finalization-registry-not-supported" /* AppError.FINALIZATION_REGISTRY_NOT_SUPPORTED */, {});
4290
+ }
4291
+ }
4292
+ const nameString = '' + hashCode(JSON.stringify(nameObj));
4293
+ const existingApp = _serverApps.get(nameString);
4294
+ if (existingApp) {
4295
+ existingApp.incRefCount(_serverAppConfig.releaseOnDeref);
4296
+ return existingApp;
4297
+ }
4298
+ const container = new component.ComponentContainer(nameString);
4299
+ for (const component of _components.values()) {
4300
+ container.addComponent(component);
4301
+ }
4302
+ const newApp = new FirebaseServerAppImpl(appOptions, _serverAppConfig, nameString, container);
4303
+ _serverApps.set(nameString, newApp);
4304
+ return newApp;
4305
+ }
4306
+ /**
4307
+ * Retrieves a {@link @firebase/app#FirebaseApp} instance.
4308
+ *
4309
+ * When called with no arguments, the default app is returned. When an app name
4310
+ * is provided, the app corresponding to that name is returned.
4311
+ *
4312
+ * An exception is thrown if the app being retrieved has not yet been
4313
+ * initialized.
4314
+ *
4315
+ * @example
4316
+ * ```javascript
4317
+ * // Return the default app
4318
+ * const app = getApp();
4319
+ * ```
4320
+ *
4321
+ * @example
4322
+ * ```javascript
4323
+ * // Return a named app
4324
+ * const otherApp = getApp("otherApp");
4325
+ * ```
4326
+ *
4327
+ * @param name - Optional name of the app to return. If no name is
4328
+ * provided, the default is `"[DEFAULT]"`.
4329
+ *
4330
+ * @returns The app corresponding to the provided app name.
4331
+ * If no app name is provided, the default app is returned.
4332
+ *
4333
+ * @public
4334
+ */
4335
+ function getApp(name = DEFAULT_ENTRY_NAME) {
4336
+ const app = _apps.get(name);
4337
+ if (!app && name === DEFAULT_ENTRY_NAME && util.getDefaultAppConfig()) {
4338
+ return initializeApp();
4339
+ }
4340
+ if (!app) {
4341
+ throw ERROR_FACTORY.create("no-app" /* AppError.NO_APP */, { appName: name });
4342
+ }
4343
+ return app;
4344
+ }
4345
+ /**
4346
+ * A (read-only) array of all initialized apps.
4347
+ * @public
4348
+ */
4349
+ function getApps() {
4350
+ return Array.from(_apps.values());
4351
+ }
4352
+ /**
4353
+ * Renders this app unusable and frees the resources of all associated
4354
+ * services.
4355
+ *
4356
+ * @example
4357
+ * ```javascript
4358
+ * deleteApp(app)
4359
+ * .then(function() {
4360
+ * console.log("App deleted successfully");
4361
+ * })
4362
+ * .catch(function(error) {
4363
+ * console.log("Error deleting app:", error);
4364
+ * });
4365
+ * ```
4366
+ *
4367
+ * @public
4368
+ */
4369
+ async function deleteApp(app) {
4370
+ let cleanupProviders = false;
4371
+ const name = app.name;
4372
+ if (_apps.has(name)) {
4373
+ cleanupProviders = true;
4374
+ _apps.delete(name);
4375
+ }
4376
+ else if (_serverApps.has(name)) {
4377
+ const firebaseServerApp = app;
4378
+ if (firebaseServerApp.decRefCount() <= 0) {
4379
+ _serverApps.delete(name);
4380
+ cleanupProviders = true;
4381
+ }
4382
+ }
4383
+ if (cleanupProviders) {
4384
+ await Promise.all(app.container
4385
+ .getProviders()
4386
+ .map(provider => provider.delete()));
4387
+ app.isDeleted = true;
4388
+ }
4389
+ }
4390
+ /**
4391
+ * Registers a library's name and version for platform logging purposes.
4392
+ * @param library - Name of 1p or 3p library (e.g. firestore, angularfire)
4393
+ * @param version - Current version of that library.
4394
+ * @param variant - Bundle variant, e.g., node, rn, etc.
4395
+ *
4396
+ * @public
4397
+ */
4398
+ function registerVersion(libraryKeyOrName, version, variant) {
4399
+ var _a;
4400
+ // TODO: We can use this check to whitelist strings when/if we set up
4401
+ // a good whitelist system.
4402
+ let library = (_a = PLATFORM_LOG_STRING[libraryKeyOrName]) !== null && _a !== void 0 ? _a : libraryKeyOrName;
4403
+ if (variant) {
4404
+ library += `-${variant}`;
4405
+ }
4406
+ const libraryMismatch = library.match(/\s|\//);
4407
+ const versionMismatch = version.match(/\s|\//);
4408
+ if (libraryMismatch || versionMismatch) {
4409
+ const warning = [
4410
+ `Unable to register library "${library}" with version "${version}":`
4411
+ ];
4412
+ if (libraryMismatch) {
4413
+ warning.push(`library name "${library}" contains illegal characters (whitespace or "/")`);
4414
+ }
4415
+ if (libraryMismatch && versionMismatch) {
4416
+ warning.push('and');
4417
+ }
4418
+ if (versionMismatch) {
4419
+ warning.push(`version name "${version}" contains illegal characters (whitespace or "/")`);
4420
+ }
4421
+ logger.warn(warning.join(' '));
4422
+ return;
4423
+ }
4424
+ _registerComponent(new component.Component(`${library}-version`, () => ({ library, version }), "VERSION" /* ComponentType.VERSION */));
4425
+ }
4426
+ /**
4427
+ * Sets log handler for all Firebase SDKs.
4428
+ * @param logCallback - An optional custom log handler that executes user code whenever
4429
+ * the Firebase SDK makes a logging call.
4430
+ *
4431
+ * @public
4432
+ */
4433
+ function onLog(logCallback, options) {
4434
+ if (logCallback !== null && typeof logCallback !== 'function') {
4435
+ throw ERROR_FACTORY.create("invalid-log-argument" /* AppError.INVALID_LOG_ARGUMENT */);
4436
+ }
4437
+ logger$1.setUserLogHandler(logCallback, options);
4438
+ }
4439
+ /**
4440
+ * Sets log level for all Firebase SDKs.
4441
+ *
4442
+ * All of the log types above the current log level are captured (i.e. if
4443
+ * you set the log level to `info`, errors are logged, but `debug` and
4444
+ * `verbose` logs are not).
4445
+ *
4446
+ * @public
4447
+ */
4448
+ function setLogLevel(logLevel) {
4449
+ logger$1.setLogLevel(logLevel);
4450
+ }
4451
+
4452
+ /**
4453
+ * @license
4454
+ * Copyright 2021 Google LLC
4455
+ *
4456
+ * Licensed under the Apache License, Version 2.0 (the "License");
4457
+ * you may not use this file except in compliance with the License.
4458
+ * You may obtain a copy of the License at
4459
+ *
4460
+ * http://www.apache.org/licenses/LICENSE-2.0
4461
+ *
4462
+ * Unless required by applicable law or agreed to in writing, software
4463
+ * distributed under the License is distributed on an "AS IS" BASIS,
4464
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4465
+ * See the License for the specific language governing permissions and
4466
+ * limitations under the License.
4467
+ */
4468
+ const DB_NAME = 'firebase-heartbeat-database';
4469
+ const DB_VERSION = 1;
4470
+ const STORE_NAME = 'firebase-heartbeat-store';
4471
+ let dbPromise = null;
4472
+ function getDbPromise() {
4473
+ if (!dbPromise) {
4474
+ dbPromise = idb.openDB(DB_NAME, DB_VERSION, {
4475
+ upgrade: (db, oldVersion) => {
4476
+ // We don't use 'break' in this switch statement, the fall-through
4477
+ // behavior is what we want, because if there are multiple versions between
4478
+ // the old version and the current version, we want ALL the migrations
4479
+ // that correspond to those versions to run, not only the last one.
4480
+ // eslint-disable-next-line default-case
4481
+ switch (oldVersion) {
4482
+ case 0:
4483
+ try {
4484
+ db.createObjectStore(STORE_NAME);
4485
+ }
4486
+ catch (e) {
4487
+ // Safari/iOS browsers throw occasional exceptions on
4488
+ // db.createObjectStore() that may be a bug. Avoid blocking
4489
+ // the rest of the app functionality.
4490
+ console.warn(e);
4491
+ }
4492
+ }
4493
+ }
4494
+ }).catch(e => {
4495
+ throw ERROR_FACTORY.create("idb-open" /* AppError.IDB_OPEN */, {
4496
+ originalErrorMessage: e.message
4497
+ });
4498
+ });
4499
+ }
4500
+ return dbPromise;
4501
+ }
4502
+ async function readHeartbeatsFromIndexedDB(app) {
4503
+ try {
4504
+ const db = await getDbPromise();
4505
+ const tx = db.transaction(STORE_NAME);
4506
+ const result = await tx.objectStore(STORE_NAME).get(computeKey(app));
4507
+ // We already have the value but tx.done can throw,
4508
+ // so we need to await it here to catch errors
4509
+ await tx.done;
4510
+ return result;
4511
+ }
4512
+ catch (e) {
4513
+ if (e instanceof util.FirebaseError) {
4514
+ logger.warn(e.message);
4515
+ }
4516
+ else {
4517
+ const idbGetError = ERROR_FACTORY.create("idb-get" /* AppError.IDB_GET */, {
4518
+ originalErrorMessage: e === null || e === void 0 ? void 0 : e.message
4519
+ });
4520
+ logger.warn(idbGetError.message);
4521
+ }
4522
+ }
4523
+ }
4524
+ async function writeHeartbeatsToIndexedDB(app, heartbeatObject) {
4525
+ try {
4526
+ const db = await getDbPromise();
4527
+ const tx = db.transaction(STORE_NAME, 'readwrite');
4528
+ const objectStore = tx.objectStore(STORE_NAME);
4529
+ await objectStore.put(heartbeatObject, computeKey(app));
4530
+ await tx.done;
4531
+ }
4532
+ catch (e) {
4533
+ if (e instanceof util.FirebaseError) {
4534
+ logger.warn(e.message);
4535
+ }
4536
+ else {
4537
+ const idbGetError = ERROR_FACTORY.create("idb-set" /* AppError.IDB_WRITE */, {
4538
+ originalErrorMessage: e === null || e === void 0 ? void 0 : e.message
4539
+ });
4540
+ logger.warn(idbGetError.message);
4541
+ }
4542
+ }
4543
+ }
4544
+ function computeKey(app) {
4545
+ return `${app.name}!${app.options.appId}`;
4546
+ }
4547
+
4548
+ /**
4549
+ * @license
4550
+ * Copyright 2021 Google LLC
4551
+ *
4552
+ * Licensed under the Apache License, Version 2.0 (the "License");
4553
+ * you may not use this file except in compliance with the License.
4554
+ * You may obtain a copy of the License at
4555
+ *
4556
+ * http://www.apache.org/licenses/LICENSE-2.0
4557
+ *
4558
+ * Unless required by applicable law or agreed to in writing, software
4559
+ * distributed under the License is distributed on an "AS IS" BASIS,
4560
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4561
+ * See the License for the specific language governing permissions and
4562
+ * limitations under the License.
4563
+ */
4564
+ const MAX_HEADER_BYTES = 1024;
4565
+ const MAX_NUM_STORED_HEARTBEATS = 30;
4566
+ class HeartbeatServiceImpl {
4567
+ constructor(container) {
4568
+ this.container = container;
4569
+ /**
4570
+ * In-memory cache for heartbeats, used by getHeartbeatsHeader() to generate
4571
+ * the header string.
4572
+ * Stores one record per date. This will be consolidated into the standard
4573
+ * format of one record per user agent string before being sent as a header.
4574
+ * Populated from indexedDB when the controller is instantiated and should
4575
+ * be kept in sync with indexedDB.
4576
+ * Leave public for easier testing.
4577
+ */
4578
+ this._heartbeatsCache = null;
4579
+ const app = this.container.getProvider('app').getImmediate();
4580
+ this._storage = new HeartbeatStorageImpl(app);
4581
+ this._heartbeatsCachePromise = this._storage.read().then(result => {
4582
+ this._heartbeatsCache = result;
4583
+ return result;
4584
+ });
4585
+ }
4586
+ /**
4587
+ * Called to report a heartbeat. The function will generate
4588
+ * a HeartbeatsByUserAgent object, update heartbeatsCache, and persist it
4589
+ * to IndexedDB.
4590
+ * Note that we only store one heartbeat per day. So if a heartbeat for today is
4591
+ * already logged, subsequent calls to this function in the same day will be ignored.
4592
+ */
4593
+ async triggerHeartbeat() {
4594
+ var _a, _b;
4595
+ try {
4596
+ const platformLogger = this.container
4597
+ .getProvider('platform-logger')
4598
+ .getImmediate();
4599
+ // This is the "Firebase user agent" string from the platform logger
4600
+ // service, not the browser user agent.
4601
+ const agent = platformLogger.getPlatformInfoString();
4602
+ const date = getUTCDateString();
4603
+ if (((_a = this._heartbeatsCache) === null || _a === void 0 ? void 0 : _a.heartbeats) == null) {
4604
+ this._heartbeatsCache = await this._heartbeatsCachePromise;
4605
+ // If we failed to construct a heartbeats cache, then return immediately.
4606
+ if (((_b = this._heartbeatsCache) === null || _b === void 0 ? void 0 : _b.heartbeats) == null) {
4607
+ return;
4608
+ }
4609
+ }
4610
+ // Do not store a heartbeat if one is already stored for this day
4611
+ // or if a header has already been sent today.
4612
+ if (this._heartbeatsCache.lastSentHeartbeatDate === date ||
4613
+ this._heartbeatsCache.heartbeats.some(singleDateHeartbeat => singleDateHeartbeat.date === date)) {
4614
+ return;
4615
+ }
4616
+ else {
4617
+ // There is no entry for this date. Create one.
4618
+ this._heartbeatsCache.heartbeats.push({ date, agent });
4619
+ // If the number of stored heartbeats exceeds the maximum number of stored heartbeats, remove the heartbeat with the earliest date.
4620
+ // Since this is executed each time a heartbeat is pushed, the limit can only be exceeded by one, so only one needs to be removed.
4621
+ if (this._heartbeatsCache.heartbeats.length > MAX_NUM_STORED_HEARTBEATS) {
4622
+ const earliestHeartbeatIdx = getEarliestHeartbeatIdx(this._heartbeatsCache.heartbeats);
4623
+ this._heartbeatsCache.heartbeats.splice(earliestHeartbeatIdx, 1);
4624
+ }
4625
+ }
4626
+ return this._storage.overwrite(this._heartbeatsCache);
4627
+ }
4628
+ catch (e) {
4629
+ logger.warn(e);
4630
+ }
4631
+ }
4632
+ /**
4633
+ * Returns a base64 encoded string which can be attached to the heartbeat-specific header directly.
4634
+ * It also clears all heartbeats from memory as well as in IndexedDB.
4635
+ *
4636
+ * NOTE: Consuming product SDKs should not send the header if this method
4637
+ * returns an empty string.
4638
+ */
4639
+ async getHeartbeatsHeader() {
4640
+ var _a;
4641
+ try {
4642
+ if (this._heartbeatsCache === null) {
4643
+ await this._heartbeatsCachePromise;
4644
+ }
4645
+ // If it's still null or the array is empty, there is no data to send.
4646
+ if (((_a = this._heartbeatsCache) === null || _a === void 0 ? void 0 : _a.heartbeats) == null ||
4647
+ this._heartbeatsCache.heartbeats.length === 0) {
4648
+ return '';
4649
+ }
4650
+ const date = getUTCDateString();
4651
+ // Extract as many heartbeats from the cache as will fit under the size limit.
4652
+ const { heartbeatsToSend, unsentEntries } = extractHeartbeatsForHeader(this._heartbeatsCache.heartbeats);
4653
+ const headerString = util.base64urlEncodeWithoutPadding(JSON.stringify({ version: 2, heartbeats: heartbeatsToSend }));
4654
+ // Store last sent date to prevent another being logged/sent for the same day.
4655
+ this._heartbeatsCache.lastSentHeartbeatDate = date;
4656
+ if (unsentEntries.length > 0) {
4657
+ // Store any unsent entries if they exist.
4658
+ this._heartbeatsCache.heartbeats = unsentEntries;
4659
+ // This seems more likely than emptying the array (below) to lead to some odd state
4660
+ // since the cache isn't empty and this will be called again on the next request,
4661
+ // and is probably safest if we await it.
4662
+ await this._storage.overwrite(this._heartbeatsCache);
4663
+ }
4664
+ else {
4665
+ this._heartbeatsCache.heartbeats = [];
4666
+ // Do not wait for this, to reduce latency.
4667
+ void this._storage.overwrite(this._heartbeatsCache);
4668
+ }
4669
+ return headerString;
4670
+ }
4671
+ catch (e) {
4672
+ logger.warn(e);
4673
+ return '';
4674
+ }
4675
+ }
4676
+ }
4677
+ function getUTCDateString() {
4678
+ const today = new Date();
4679
+ // Returns date format 'YYYY-MM-DD'
4680
+ return today.toISOString().substring(0, 10);
4681
+ }
4682
+ function extractHeartbeatsForHeader(heartbeatsCache, maxSize = MAX_HEADER_BYTES) {
4683
+ // Heartbeats grouped by user agent in the standard format to be sent in
4684
+ // the header.
4685
+ const heartbeatsToSend = [];
4686
+ // Single date format heartbeats that are not sent.
4687
+ let unsentEntries = heartbeatsCache.slice();
4688
+ for (const singleDateHeartbeat of heartbeatsCache) {
4689
+ // Look for an existing entry with the same user agent.
4690
+ const heartbeatEntry = heartbeatsToSend.find(hb => hb.agent === singleDateHeartbeat.agent);
4691
+ if (!heartbeatEntry) {
4692
+ // If no entry for this user agent exists, create one.
4693
+ heartbeatsToSend.push({
4694
+ agent: singleDateHeartbeat.agent,
4695
+ dates: [singleDateHeartbeat.date]
4696
+ });
4697
+ if (countBytes(heartbeatsToSend) > maxSize) {
4698
+ // If the header would exceed max size, remove the added heartbeat
4699
+ // entry and stop adding to the header.
4700
+ heartbeatsToSend.pop();
4701
+ break;
4702
+ }
4703
+ }
4704
+ else {
4705
+ heartbeatEntry.dates.push(singleDateHeartbeat.date);
4706
+ // If the header would exceed max size, remove the added date
4707
+ // and stop adding to the header.
4708
+ if (countBytes(heartbeatsToSend) > maxSize) {
4709
+ heartbeatEntry.dates.pop();
4710
+ break;
4711
+ }
4712
+ }
4713
+ // Pop unsent entry from queue. (Skipped if adding the entry exceeded
4714
+ // quota and the loop breaks early.)
4715
+ unsentEntries = unsentEntries.slice(1);
4716
+ }
4717
+ return {
4718
+ heartbeatsToSend,
4719
+ unsentEntries
4720
+ };
4721
+ }
4722
+ class HeartbeatStorageImpl {
4723
+ constructor(app) {
4724
+ this.app = app;
4725
+ this._canUseIndexedDBPromise = this.runIndexedDBEnvironmentCheck();
4726
+ }
4727
+ async runIndexedDBEnvironmentCheck() {
4728
+ if (!util.isIndexedDBAvailable()) {
4729
+ return false;
4730
+ }
4731
+ else {
4732
+ return util.validateIndexedDBOpenable()
4733
+ .then(() => true)
4734
+ .catch(() => false);
4735
+ }
4736
+ }
4737
+ /**
4738
+ * Read all heartbeats.
4739
+ */
4740
+ async read() {
4741
+ const canUseIndexedDB = await this._canUseIndexedDBPromise;
4742
+ if (!canUseIndexedDB) {
4743
+ return { heartbeats: [] };
4744
+ }
4745
+ else {
4746
+ const idbHeartbeatObject = await readHeartbeatsFromIndexedDB(this.app);
4747
+ if (idbHeartbeatObject === null || idbHeartbeatObject === void 0 ? void 0 : idbHeartbeatObject.heartbeats) {
4748
+ return idbHeartbeatObject;
4749
+ }
4750
+ else {
4751
+ return { heartbeats: [] };
4752
+ }
4753
+ }
4754
+ }
4755
+ // overwrite the storage with the provided heartbeats
4756
+ async overwrite(heartbeatsObject) {
4757
+ var _a;
4758
+ const canUseIndexedDB = await this._canUseIndexedDBPromise;
4759
+ if (!canUseIndexedDB) {
4760
+ return;
4761
+ }
4762
+ else {
4763
+ const existingHeartbeatsObject = await this.read();
4764
+ return writeHeartbeatsToIndexedDB(this.app, {
4765
+ lastSentHeartbeatDate: (_a = heartbeatsObject.lastSentHeartbeatDate) !== null && _a !== void 0 ? _a : existingHeartbeatsObject.lastSentHeartbeatDate,
4766
+ heartbeats: heartbeatsObject.heartbeats
4767
+ });
4768
+ }
4769
+ }
4770
+ // add heartbeats
4771
+ async add(heartbeatsObject) {
4772
+ var _a;
4773
+ const canUseIndexedDB = await this._canUseIndexedDBPromise;
4774
+ if (!canUseIndexedDB) {
4775
+ return;
4776
+ }
4777
+ else {
4778
+ const existingHeartbeatsObject = await this.read();
4779
+ return writeHeartbeatsToIndexedDB(this.app, {
4780
+ lastSentHeartbeatDate: (_a = heartbeatsObject.lastSentHeartbeatDate) !== null && _a !== void 0 ? _a : existingHeartbeatsObject.lastSentHeartbeatDate,
4781
+ heartbeats: [
4782
+ ...existingHeartbeatsObject.heartbeats,
4783
+ ...heartbeatsObject.heartbeats
4784
+ ]
4785
+ });
4786
+ }
4787
+ }
4788
+ }
4789
+ /**
4790
+ * Calculate bytes of a HeartbeatsByUserAgent array after being wrapped
4791
+ * in a platform logging header JSON object, stringified, and converted
4792
+ * to base 64.
4793
+ */
4794
+ function countBytes(heartbeatsCache) {
4795
+ // base64 has a restricted set of characters, all of which should be 1 byte.
4796
+ return util.base64urlEncodeWithoutPadding(
4797
+ // heartbeatsCache wrapper properties
4798
+ JSON.stringify({ version: 2, heartbeats: heartbeatsCache })).length;
4799
+ }
4800
+ /**
4801
+ * Returns the index of the heartbeat with the earliest date.
4802
+ * If the heartbeats array is empty, -1 is returned.
4803
+ */
4804
+ function getEarliestHeartbeatIdx(heartbeats) {
4805
+ if (heartbeats.length === 0) {
4806
+ return -1;
4807
+ }
4808
+ let earliestHeartbeatIdx = 0;
4809
+ let earliestHeartbeatDate = heartbeats[0].date;
4810
+ for (let i = 1; i < heartbeats.length; i++) {
4811
+ if (heartbeats[i].date < earliestHeartbeatDate) {
4812
+ earliestHeartbeatDate = heartbeats[i].date;
4813
+ earliestHeartbeatIdx = i;
4814
+ }
4815
+ }
4816
+ return earliestHeartbeatIdx;
4817
+ }
4818
+
4819
+ /**
4820
+ * @license
4821
+ * Copyright 2019 Google LLC
4822
+ *
4823
+ * Licensed under the Apache License, Version 2.0 (the "License");
4824
+ * you may not use this file except in compliance with the License.
4825
+ * You may obtain a copy of the License at
4826
+ *
4827
+ * http://www.apache.org/licenses/LICENSE-2.0
4828
+ *
4829
+ * Unless required by applicable law or agreed to in writing, software
4830
+ * distributed under the License is distributed on an "AS IS" BASIS,
4831
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4832
+ * See the License for the specific language governing permissions and
4833
+ * limitations under the License.
4834
+ */
4835
+ function registerCoreComponents(variant) {
4836
+ _registerComponent(new component.Component('platform-logger', container => new PlatformLoggerServiceImpl(container), "PRIVATE" /* ComponentType.PRIVATE */));
4837
+ _registerComponent(new component.Component('heartbeat', container => new HeartbeatServiceImpl(container), "PRIVATE" /* ComponentType.PRIVATE */));
4838
+ // Register `app` package.
4839
+ registerVersion(name$q, version$1, variant);
4840
+ // BUILD_TARGET will be replaced by values like esm2017, cjs2017, etc during the compilation
4841
+ registerVersion(name$q, version$1, 'cjs2017');
4842
+ // Register platform SDK identifier (no version).
4843
+ registerVersion('fire-js', '');
4844
+ }
4845
+
4846
+ /**
4847
+ * Firebase App
4848
+ *
4849
+ * @remarks This package coordinates the communication between the different Firebase components
4850
+ * @packageDocumentation
4851
+ */
4852
+ registerCoreComponents('node');
4853
+
4854
+ Object.defineProperty(exports, 'FirebaseError', {
4855
+ enumerable: true,
4856
+ get: function () { return util.FirebaseError; }
4857
+ });
4858
+ exports.SDK_VERSION = SDK_VERSION;
4859
+ exports._DEFAULT_ENTRY_NAME = DEFAULT_ENTRY_NAME;
4860
+ exports._addComponent = _addComponent;
4861
+ exports._addOrOverwriteComponent = _addOrOverwriteComponent;
4862
+ exports._apps = _apps;
4863
+ exports._clearComponents = _clearComponents;
4864
+ exports._components = _components;
4865
+ exports._getProvider = _getProvider;
4866
+ exports._isFirebaseApp = _isFirebaseApp;
4867
+ exports._isFirebaseServerApp = _isFirebaseServerApp;
4868
+ exports._registerComponent = _registerComponent;
4869
+ exports._removeServiceInstance = _removeServiceInstance;
4870
+ exports._serverApps = _serverApps;
4871
+ exports.deleteApp = deleteApp;
4872
+ exports.getApp = getApp;
4873
+ exports.getApps = getApps;
4874
+ exports.initializeApp = initializeApp;
4875
+ exports.initializeServerApp = initializeServerApp;
4876
+ exports.onLog = onLog;
4877
+ exports.registerVersion = registerVersion;
4878
+ exports.setLogLevel = setLogLevel;
4879
+
4880
+ }(index_cjs));
4881
+
4882
+ Object.defineProperty(index_standalone, '__esModule', { value: true });
4883
+
4884
+ var Websocket = websocket;
4885
+ var util = require$$2__default$3["default"];
4886
+ var logger$1 = require$$1__default$3["default"];
4887
+ var app = index_cjs;
4888
+ var component = require$$0__default$3["default"];
4889
+
4890
+ function _interopDefaultLegacy$1 (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
4891
+
4892
+ var Websocket__default = /*#__PURE__*/_interopDefaultLegacy$1(Websocket);
4893
+
4894
+ /**
4895
+ * @license
4896
+ * Copyright 2017 Google LLC
4897
+ *
4898
+ * Licensed under the Apache License, Version 2.0 (the "License");
4899
+ * you may not use this file except in compliance with the License.
4900
+ * You may obtain a copy of the License at
4901
+ *
4902
+ * http://www.apache.org/licenses/LICENSE-2.0
4903
+ *
4904
+ * Unless required by applicable law or agreed to in writing, software
4905
+ * distributed under the License is distributed on an "AS IS" BASIS,
4906
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4907
+ * See the License for the specific language governing permissions and
4908
+ * limitations under the License.
4909
+ */
4910
+ const PROTOCOL_VERSION = '5';
4911
+ const VERSION_PARAM = 'v';
4912
+ const TRANSPORT_SESSION_PARAM = 's';
4913
+ const REFERER_PARAM = 'r';
4914
+ const FORGE_REF = 'f';
4915
+ // Matches console.firebase.google.com, firebase-console-*.corp.google.com and
4916
+ // firebase.corp.google.com
4917
+ const FORGE_DOMAIN_RE = /(console\.firebase|firebase-console-\w+\.corp|firebase\.corp)\.google\.com/;
4918
+ const LAST_SESSION_PARAM = 'ls';
4919
+ const APPLICATION_ID_PARAM = 'p';
4920
+ const APP_CHECK_TOKEN_PARAM = 'ac';
4921
+ const WEBSOCKET = 'websocket';
4922
+ const LONG_POLLING = 'long_polling';
4923
+
4924
+ /**
4925
+ * @license
4926
+ * Copyright 2017 Google LLC
4927
+ *
4928
+ * Licensed under the Apache License, Version 2.0 (the "License");
4929
+ * you may not use this file except in compliance with the License.
4930
+ * You may obtain a copy of the License at
4931
+ *
4932
+ * http://www.apache.org/licenses/LICENSE-2.0
4933
+ *
4934
+ * Unless required by applicable law or agreed to in writing, software
4935
+ * distributed under the License is distributed on an "AS IS" BASIS,
4936
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4937
+ * See the License for the specific language governing permissions and
4938
+ * limitations under the License.
4939
+ */
4940
+ /**
4941
+ * Wraps a DOM Storage object and:
4942
+ * - automatically encode objects as JSON strings before storing them to allow us to store arbitrary types.
4943
+ * - prefixes names with "firebase:" to avoid collisions with app data.
4944
+ *
4945
+ * We automatically (see storage.js) create two such wrappers, one for sessionStorage,
4946
+ * and one for localStorage.
4947
+ *
4948
+ */
4949
+ class DOMStorageWrapper {
4950
+ /**
4951
+ * @param domStorage_ - The underlying storage object (e.g. localStorage or sessionStorage)
4952
+ */
4953
+ constructor(domStorage_) {
4954
+ this.domStorage_ = domStorage_;
4955
+ // Use a prefix to avoid collisions with other stuff saved by the app.
4956
+ this.prefix_ = 'firebase:';
4957
+ }
4958
+ /**
4959
+ * @param key - The key to save the value under
4960
+ * @param value - The value being stored, or null to remove the key.
4961
+ */
4962
+ set(key, value) {
4963
+ if (value == null) {
4964
+ this.domStorage_.removeItem(this.prefixedName_(key));
4965
+ }
4966
+ else {
4967
+ this.domStorage_.setItem(this.prefixedName_(key), util.stringify(value));
4968
+ }
4969
+ }
4970
+ /**
4971
+ * @returns The value that was stored under this key, or null
4972
+ */
4973
+ get(key) {
4974
+ const storedVal = this.domStorage_.getItem(this.prefixedName_(key));
4975
+ if (storedVal == null) {
4976
+ return null;
4977
+ }
4978
+ else {
4979
+ return util.jsonEval(storedVal);
4980
+ }
4981
+ }
4982
+ remove(key) {
4983
+ this.domStorage_.removeItem(this.prefixedName_(key));
4984
+ }
4985
+ prefixedName_(name) {
4986
+ return this.prefix_ + name;
4987
+ }
4988
+ toString() {
4989
+ return this.domStorage_.toString();
4990
+ }
4991
+ }
4992
+
4993
+ /**
4994
+ * @license
4995
+ * Copyright 2017 Google LLC
4996
+ *
4997
+ * Licensed under the Apache License, Version 2.0 (the "License");
4998
+ * you may not use this file except in compliance with the License.
4999
+ * You may obtain a copy of the License at
5000
+ *
5001
+ * http://www.apache.org/licenses/LICENSE-2.0
5002
+ *
5003
+ * Unless required by applicable law or agreed to in writing, software
5004
+ * distributed under the License is distributed on an "AS IS" BASIS,
5005
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5006
+ * See the License for the specific language governing permissions and
5007
+ * limitations under the License.
5008
+ */
5009
+ /**
5010
+ * An in-memory storage implementation that matches the API of DOMStorageWrapper
5011
+ * (TODO: create interface for both to implement).
5012
+ */
5013
+ class MemoryStorage {
5014
+ constructor() {
5015
+ this.cache_ = {};
5016
+ this.isInMemoryStorage = true;
5017
+ }
5018
+ set(key, value) {
5019
+ if (value == null) {
5020
+ delete this.cache_[key];
5021
+ }
5022
+ else {
5023
+ this.cache_[key] = value;
5024
+ }
5025
+ }
5026
+ get(key) {
5027
+ if (util.contains(this.cache_, key)) {
5028
+ return this.cache_[key];
5029
+ }
5030
+ return null;
5031
+ }
5032
+ remove(key) {
5033
+ delete this.cache_[key];
5034
+ }
5035
+ }
5036
+
5037
+ /**
5038
+ * @license
5039
+ * Copyright 2017 Google LLC
5040
+ *
5041
+ * Licensed under the Apache License, Version 2.0 (the "License");
5042
+ * you may not use this file except in compliance with the License.
5043
+ * You may obtain a copy of the License at
5044
+ *
5045
+ * http://www.apache.org/licenses/LICENSE-2.0
5046
+ *
5047
+ * Unless required by applicable law or agreed to in writing, software
5048
+ * distributed under the License is distributed on an "AS IS" BASIS,
5049
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5050
+ * See the License for the specific language governing permissions and
5051
+ * limitations under the License.
5052
+ */
5053
+ /**
5054
+ * Helper to create a DOMStorageWrapper or else fall back to MemoryStorage.
5055
+ * TODO: Once MemoryStorage and DOMStorageWrapper have a shared interface this method annotation should change
5056
+ * to reflect this type
5057
+ *
5058
+ * @param domStorageName - Name of the underlying storage object
5059
+ * (e.g. 'localStorage' or 'sessionStorage').
5060
+ * @returns Turning off type information until a common interface is defined.
5061
+ */
5062
+ const createStoragefor = function (domStorageName) {
5063
+ try {
5064
+ // NOTE: just accessing "localStorage" or "window['localStorage']" may throw a security exception,
5065
+ // so it must be inside the try/catch.
5066
+ if (typeof window !== 'undefined' &&
5067
+ typeof window[domStorageName] !== 'undefined') {
5068
+ // Need to test cache. Just because it's here doesn't mean it works
5069
+ const domStorage = window[domStorageName];
5070
+ domStorage.setItem('firebase:sentinel', 'cache');
5071
+ domStorage.removeItem('firebase:sentinel');
5072
+ return new DOMStorageWrapper(domStorage);
5073
+ }
5074
+ }
5075
+ catch (e) { }
5076
+ // Failed to create wrapper. Just return in-memory storage.
5077
+ // TODO: log?
5078
+ return new MemoryStorage();
5079
+ };
5080
+ /** A storage object that lasts across sessions */
5081
+ const PersistentStorage = createStoragefor('localStorage');
5082
+ /** A storage object that only lasts one session */
5083
+ const SessionStorage = createStoragefor('sessionStorage');
5084
+
5085
+ /**
5086
+ * @license
5087
+ * Copyright 2017 Google LLC
5088
+ *
5089
+ * Licensed under the Apache License, Version 2.0 (the "License");
5090
+ * you may not use this file except in compliance with the License.
5091
+ * You may obtain a copy of the License at
5092
+ *
5093
+ * http://www.apache.org/licenses/LICENSE-2.0
5094
+ *
5095
+ * Unless required by applicable law or agreed to in writing, software
5096
+ * distributed under the License is distributed on an "AS IS" BASIS,
5097
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5098
+ * See the License for the specific language governing permissions and
5099
+ * limitations under the License.
5100
+ */
5101
+ const logClient$1 = new logger$1.Logger('@firebase/database');
5102
+ /**
5103
+ * Returns a locally-unique ID (generated by just incrementing up from 0 each time its called).
5104
+ */
5105
+ const LUIDGenerator = (function () {
5106
+ let id = 1;
5107
+ return function () {
5108
+ return id++;
5109
+ };
5110
+ })();
5111
+ /**
5112
+ * Sha1 hash of the input string
5113
+ * @param str - The string to hash
5114
+ * @returns {!string} The resulting hash
5115
+ */
5116
+ const sha1 = function (str) {
5117
+ const utf8Bytes = util.stringToByteArray(str);
5118
+ const sha1 = new util.Sha1();
5119
+ sha1.update(utf8Bytes);
5120
+ const sha1Bytes = sha1.digest();
5121
+ return util.base64.encodeByteArray(sha1Bytes);
5122
+ };
5123
+ const buildLogMessage_ = function (...varArgs) {
5124
+ let message = '';
5125
+ for (let i = 0; i < varArgs.length; i++) {
5126
+ const arg = varArgs[i];
5127
+ if (Array.isArray(arg) ||
5128
+ (arg &&
5129
+ typeof arg === 'object' &&
5130
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5131
+ typeof arg.length === 'number')) {
5132
+ message += buildLogMessage_.apply(null, arg);
5133
+ }
5134
+ else if (typeof arg === 'object') {
5135
+ message += util.stringify(arg);
5136
+ }
5137
+ else {
5138
+ message += arg;
5139
+ }
3605
5140
  message += ' ';
3606
5141
  }
3607
5142
  return message;
@@ -4622,15 +6157,24 @@ WebSocketConnection.healthyTimeout = 30000;
4622
6157
  * Abstraction around AppCheck's token fetching capabilities.
4623
6158
  */
4624
6159
  class AppCheckTokenProvider {
4625
- constructor(appName_, appCheckProvider) {
4626
- this.appName_ = appName_;
6160
+ constructor(app$1, appCheckProvider) {
4627
6161
  this.appCheckProvider = appCheckProvider;
6162
+ this.appName = app$1.name;
6163
+ if (app._isFirebaseServerApp(app$1) && app$1.settings.appCheckToken) {
6164
+ this.serverAppAppCheckToken = app$1.settings.appCheckToken;
6165
+ }
4628
6166
  this.appCheck = appCheckProvider === null || appCheckProvider === void 0 ? void 0 : appCheckProvider.getImmediate({ optional: true });
4629
6167
  if (!this.appCheck) {
4630
6168
  appCheckProvider === null || appCheckProvider === void 0 ? void 0 : appCheckProvider.get().then(appCheck => (this.appCheck = appCheck));
4631
6169
  }
4632
6170
  }
4633
6171
  getToken(forceRefresh) {
6172
+ if (this.serverAppAppCheckToken) {
6173
+ if (forceRefresh) {
6174
+ throw new Error('Attempted reuse of `FirebaseServerApp.appCheckToken` after previous usage failed.');
6175
+ }
6176
+ return Promise.resolve({ token: this.serverAppAppCheckToken });
6177
+ }
4634
6178
  if (!this.appCheck) {
4635
6179
  return new Promise((resolve, reject) => {
4636
6180
  // Support delayed initialization of FirebaseAppCheck. This allows our
@@ -4654,7 +6198,7 @@ class AppCheckTokenProvider {
4654
6198
  (_a = this.appCheckProvider) === null || _a === void 0 ? void 0 : _a.get().then(appCheck => appCheck.addTokenListener(listener));
4655
6199
  }
4656
6200
  notifyForInvalidToken() {
4657
- warn$1(`Provided AppCheck credentials for the app named "${this.appName_}" ` +
6201
+ warn$1(`Provided AppCheck credentials for the app named "${this.appName}" ` +
4658
6202
  'are invalid. This usually indicates your app was not initialized correctly.');
4659
6203
  }
4660
6204
  }
@@ -7085,7 +8629,7 @@ class PersistentConnection extends ServerActions {
7085
8629
  }
7086
8630
  this.lastConnectionEstablishedTime_ = null;
7087
8631
  }
7088
- const timeSinceLastConnectAttempt = new Date().getTime() - this.lastConnectionAttemptTime_;
8632
+ const timeSinceLastConnectAttempt = Math.max(0, new Date().getTime() - this.lastConnectionAttemptTime_);
7089
8633
  let reconnectDelay = Math.max(0, this.reconnectDelay_ - timeSinceLastConnectAttempt);
7090
8634
  reconnectDelay = Math.random() * reconnectDelay;
7091
8635
  this.log_('Trying to reconnect in ' + reconnectDelay + 'ms');
@@ -16876,7 +18420,7 @@ function repoManagerDatabaseFromApp(app, authProvider, appCheckProvider, url, no
16876
18420
  fatal('Database URL must point to the root of a Firebase Database ' +
16877
18421
  '(not including a child path).');
16878
18422
  }
16879
- const repo = repoManagerCreateRepo(repoInfo, app, authTokenProvider, new AppCheckTokenProvider(app.name, appCheckProvider));
18423
+ const repo = repoManagerCreateRepo(repoInfo, app, authTokenProvider, new AppCheckTokenProvider(app, appCheckProvider));
16880
18424
  return new Database$1(repo, app);
16881
18425
  }
16882
18426
  /**
@@ -17362,7 +18906,7 @@ var update_1 = index_standalone.update = update;
17362
18906
  * See the License for the specific language governing permissions and
17363
18907
  * limitations under the License.
17364
18908
  */
17365
- const logClient = new require$$2$3.Logger('@firebase/database-compat');
18909
+ const logClient = new require$$1$3.Logger('@firebase/database-compat');
17366
18910
  const warn = function (msg) {
17367
18911
  const message = 'FIREBASE WARNING: ' + msg;
17368
18912
  logClient.warn(message);
@@ -17389,7 +18933,7 @@ const validateBoolean = function (fnName, argumentName, bool, optional) {
17389
18933
  return;
17390
18934
  }
17391
18935
  if (typeof bool !== 'boolean') {
17392
- throw new Error(require$$1$3.errorPrefix(fnName, argumentName) + 'must be a boolean.');
18936
+ throw new Error(require$$2$3.errorPrefix(fnName, argumentName) + 'must be a boolean.');
17393
18937
  }
17394
18938
  };
17395
18939
  const validateEventType = function (fnName, eventType, optional) {
@@ -17404,7 +18948,7 @@ const validateEventType = function (fnName, eventType, optional) {
17404
18948
  case 'child_moved':
17405
18949
  break;
17406
18950
  default:
17407
- throw new Error(require$$1$3.errorPrefix(fnName, 'eventType') +
18951
+ throw new Error(require$$2$3.errorPrefix(fnName, 'eventType') +
17408
18952
  'must be a valid event type = "value", "child_added", "child_removed", ' +
17409
18953
  '"child_changed", or "child_moved".');
17410
18954
  }
@@ -17431,8 +18975,8 @@ class OnDisconnect {
17431
18975
  this._delegate = _delegate;
17432
18976
  }
17433
18977
  cancel(onComplete) {
17434
- require$$1$3.validateArgCount('OnDisconnect.cancel', 0, 1, arguments.length);
17435
- require$$1$3.validateCallback('OnDisconnect.cancel', 'onComplete', onComplete, true);
18978
+ require$$2$3.validateArgCount('OnDisconnect.cancel', 0, 1, arguments.length);
18979
+ require$$2$3.validateCallback('OnDisconnect.cancel', 'onComplete', onComplete, true);
17436
18980
  const result = this._delegate.cancel();
17437
18981
  if (onComplete) {
17438
18982
  result.then(() => onComplete(null), error => onComplete(error));
@@ -17440,8 +18984,8 @@ class OnDisconnect {
17440
18984
  return result;
17441
18985
  }
17442
18986
  remove(onComplete) {
17443
- require$$1$3.validateArgCount('OnDisconnect.remove', 0, 1, arguments.length);
17444
- require$$1$3.validateCallback('OnDisconnect.remove', 'onComplete', onComplete, true);
18987
+ require$$2$3.validateArgCount('OnDisconnect.remove', 0, 1, arguments.length);
18988
+ require$$2$3.validateCallback('OnDisconnect.remove', 'onComplete', onComplete, true);
17445
18989
  const result = this._delegate.remove();
17446
18990
  if (onComplete) {
17447
18991
  result.then(() => onComplete(null), error => onComplete(error));
@@ -17449,8 +18993,8 @@ class OnDisconnect {
17449
18993
  return result;
17450
18994
  }
17451
18995
  set(value, onComplete) {
17452
- require$$1$3.validateArgCount('OnDisconnect.set', 1, 2, arguments.length);
17453
- require$$1$3.validateCallback('OnDisconnect.set', 'onComplete', onComplete, true);
18996
+ require$$2$3.validateArgCount('OnDisconnect.set', 1, 2, arguments.length);
18997
+ require$$2$3.validateCallback('OnDisconnect.set', 'onComplete', onComplete, true);
17454
18998
  const result = this._delegate.set(value);
17455
18999
  if (onComplete) {
17456
19000
  result.then(() => onComplete(null), error => onComplete(error));
@@ -17458,8 +19002,8 @@ class OnDisconnect {
17458
19002
  return result;
17459
19003
  }
17460
19004
  setWithPriority(value, priority, onComplete) {
17461
- require$$1$3.validateArgCount('OnDisconnect.setWithPriority', 2, 3, arguments.length);
17462
- require$$1$3.validateCallback('OnDisconnect.setWithPriority', 'onComplete', onComplete, true);
19005
+ require$$2$3.validateArgCount('OnDisconnect.setWithPriority', 2, 3, arguments.length);
19006
+ require$$2$3.validateCallback('OnDisconnect.setWithPriority', 'onComplete', onComplete, true);
17463
19007
  const result = this._delegate.setWithPriority(value, priority);
17464
19008
  if (onComplete) {
17465
19009
  result.then(() => onComplete(null), error => onComplete(error));
@@ -17467,7 +19011,7 @@ class OnDisconnect {
17467
19011
  return result;
17468
19012
  }
17469
19013
  update(objectToMerge, onComplete) {
17470
- require$$1$3.validateArgCount('OnDisconnect.update', 1, 2, arguments.length);
19014
+ require$$2$3.validateArgCount('OnDisconnect.update', 1, 2, arguments.length);
17471
19015
  if (Array.isArray(objectToMerge)) {
17472
19016
  const newObjectToMerge = {};
17473
19017
  for (let i = 0; i < objectToMerge.length; ++i) {
@@ -17477,7 +19021,7 @@ class OnDisconnect {
17477
19021
  warn('Passing an Array to firebase.database.onDisconnect().update() is deprecated. Use set() if you want to overwrite the ' +
17478
19022
  'existing data, or an Object with integer keys if you really do want to only update some of the children.');
17479
19023
  }
17480
- require$$1$3.validateCallback('OnDisconnect.update', 'onComplete', onComplete, true);
19024
+ require$$2$3.validateCallback('OnDisconnect.update', 'onComplete', onComplete, true);
17481
19025
  const result = this._delegate.update(objectToMerge);
17482
19026
  if (onComplete) {
17483
19027
  result.then(() => onComplete(null), error => onComplete(error));
@@ -17513,7 +19057,7 @@ class TransactionResult {
17513
19057
  // Do not create public documentation. This is intended to make JSON serialization work but is otherwise unnecessary
17514
19058
  // for end-users
17515
19059
  toJSON() {
17516
- require$$1$3.validateArgCount('TransactionResult.toJSON', 0, 1, arguments.length);
19060
+ require$$2$3.validateArgCount('TransactionResult.toJSON', 0, 1, arguments.length);
17517
19061
  return { committed: this.committed, snapshot: this.snapshot.toJSON() };
17518
19062
  }
17519
19063
  }
@@ -17550,7 +19094,7 @@ class DataSnapshot {
17550
19094
  * @returns JSON representation of the DataSnapshot contents, or null if empty.
17551
19095
  */
17552
19096
  val() {
17553
- require$$1$3.validateArgCount('DataSnapshot.val', 0, 0, arguments.length);
19097
+ require$$2$3.validateArgCount('DataSnapshot.val', 0, 0, arguments.length);
17554
19098
  return this._delegate.val();
17555
19099
  }
17556
19100
  /**
@@ -17559,14 +19103,14 @@ class DataSnapshot {
17559
19103
  * @returns JSON representation of the DataSnapshot contents, or null if empty.
17560
19104
  */
17561
19105
  exportVal() {
17562
- require$$1$3.validateArgCount('DataSnapshot.exportVal', 0, 0, arguments.length);
19106
+ require$$2$3.validateArgCount('DataSnapshot.exportVal', 0, 0, arguments.length);
17563
19107
  return this._delegate.exportVal();
17564
19108
  }
17565
19109
  // Do not create public documentation. This is intended to make JSON serialization work but is otherwise unnecessary
17566
19110
  // for end-users
17567
19111
  toJSON() {
17568
19112
  // Optional spacer argument is unnecessary because we're depending on recursion rather than stringifying the content
17569
- require$$1$3.validateArgCount('DataSnapshot.toJSON', 0, 1, arguments.length);
19113
+ require$$2$3.validateArgCount('DataSnapshot.toJSON', 0, 1, arguments.length);
17570
19114
  return this._delegate.toJSON();
17571
19115
  }
17572
19116
  /**
@@ -17575,7 +19119,7 @@ class DataSnapshot {
17575
19119
  * @returns Whether the snapshot contains a non-null value, or is empty.
17576
19120
  */
17577
19121
  exists() {
17578
- require$$1$3.validateArgCount('DataSnapshot.exists', 0, 0, arguments.length);
19122
+ require$$2$3.validateArgCount('DataSnapshot.exists', 0, 0, arguments.length);
17579
19123
  return this._delegate.exists();
17580
19124
  }
17581
19125
  /**
@@ -17585,7 +19129,7 @@ class DataSnapshot {
17585
19129
  * @returns DataSnapshot for child node.
17586
19130
  */
17587
19131
  child(path) {
17588
- require$$1$3.validateArgCount('DataSnapshot.child', 0, 1, arguments.length);
19132
+ require$$2$3.validateArgCount('DataSnapshot.child', 0, 1, arguments.length);
17589
19133
  // Ensure the childPath is a string (can be a number)
17590
19134
  path = String(path);
17591
19135
  _validatePathString('DataSnapshot.child', 'path', path, false);
@@ -17598,7 +19142,7 @@ class DataSnapshot {
17598
19142
  * @returns Whether the child exists.
17599
19143
  */
17600
19144
  hasChild(path) {
17601
- require$$1$3.validateArgCount('DataSnapshot.hasChild', 1, 1, arguments.length);
19145
+ require$$2$3.validateArgCount('DataSnapshot.hasChild', 1, 1, arguments.length);
17602
19146
  _validatePathString('DataSnapshot.hasChild', 'path', path, false);
17603
19147
  return this._delegate.hasChild(path);
17604
19148
  }
@@ -17608,7 +19152,7 @@ class DataSnapshot {
17608
19152
  * @returns The priority.
17609
19153
  */
17610
19154
  getPriority() {
17611
- require$$1$3.validateArgCount('DataSnapshot.getPriority', 0, 0, arguments.length);
19155
+ require$$2$3.validateArgCount('DataSnapshot.getPriority', 0, 0, arguments.length);
17612
19156
  return this._delegate.priority;
17613
19157
  }
17614
19158
  /**
@@ -17620,8 +19164,8 @@ class DataSnapshot {
17620
19164
  * one of the child nodes.
17621
19165
  */
17622
19166
  forEach(action) {
17623
- require$$1$3.validateArgCount('DataSnapshot.forEach', 1, 1, arguments.length);
17624
- require$$1$3.validateCallback('DataSnapshot.forEach', 'action', action, false);
19167
+ require$$2$3.validateArgCount('DataSnapshot.forEach', 1, 1, arguments.length);
19168
+ require$$2$3.validateCallback('DataSnapshot.forEach', 'action', action, false);
17625
19169
  return this._delegate.forEach(expDataSnapshot => action(new DataSnapshot(this._database, expDataSnapshot)));
17626
19170
  }
17627
19171
  /**
@@ -17629,7 +19173,7 @@ class DataSnapshot {
17629
19173
  * @returns True if the DataSnapshot contains 1 or more child nodes.
17630
19174
  */
17631
19175
  hasChildren() {
17632
- require$$1$3.validateArgCount('DataSnapshot.hasChildren', 0, 0, arguments.length);
19176
+ require$$2$3.validateArgCount('DataSnapshot.hasChildren', 0, 0, arguments.length);
17633
19177
  return this._delegate.hasChildren();
17634
19178
  }
17635
19179
  get key() {
@@ -17640,7 +19184,7 @@ class DataSnapshot {
17640
19184
  * @returns The number of children that this DataSnapshot contains.
17641
19185
  */
17642
19186
  numChildren() {
17643
- require$$1$3.validateArgCount('DataSnapshot.numChildren', 0, 0, arguments.length);
19187
+ require$$2$3.validateArgCount('DataSnapshot.numChildren', 0, 0, arguments.length);
17644
19188
  return this._delegate.size;
17645
19189
  }
17646
19190
  /**
@@ -17648,7 +19192,7 @@ class DataSnapshot {
17648
19192
  * from.
17649
19193
  */
17650
19194
  getRef() {
17651
- require$$1$3.validateArgCount('DataSnapshot.ref', 0, 0, arguments.length);
19195
+ require$$2$3.validateArgCount('DataSnapshot.ref', 0, 0, arguments.length);
17652
19196
  return new Reference(this._database, this._delegate.ref);
17653
19197
  }
17654
19198
  get ref() {
@@ -17668,8 +19212,8 @@ class Query {
17668
19212
  }
17669
19213
  on(eventType, callback, cancelCallbackOrContext, context) {
17670
19214
  var _a;
17671
- require$$1$3.validateArgCount('Query.on', 2, 4, arguments.length);
17672
- require$$1$3.validateCallback('Query.on', 'callback', callback, false);
19215
+ require$$2$3.validateArgCount('Query.on', 2, 4, arguments.length);
19216
+ require$$2$3.validateCallback('Query.on', 'callback', callback, false);
17673
19217
  const ret = Query.getCancelAndContextArgs_('Query.on', cancelCallbackOrContext, context);
17674
19218
  const valueCallback = (expSnapshot, previousChildName) => {
17675
19219
  callback.call(ret.context, new DataSnapshot(this.database, expSnapshot), previousChildName);
@@ -17694,16 +19238,16 @@ class Query {
17694
19238
  onChildMoved_1(this._delegate, valueCallback, cancelCallback);
17695
19239
  return callback;
17696
19240
  default:
17697
- throw new Error(require$$1$3.errorPrefix('Query.on', 'eventType') +
19241
+ throw new Error(require$$2$3.errorPrefix('Query.on', 'eventType') +
17698
19242
  'must be a valid event type = "value", "child_added", "child_removed", ' +
17699
19243
  '"child_changed", or "child_moved".');
17700
19244
  }
17701
19245
  }
17702
19246
  off(eventType, callback, context) {
17703
- require$$1$3.validateArgCount('Query.off', 0, 3, arguments.length);
19247
+ require$$2$3.validateArgCount('Query.off', 0, 3, arguments.length);
17704
19248
  validateEventType('Query.off', eventType, true);
17705
- require$$1$3.validateCallback('Query.off', 'callback', callback, true);
17706
- require$$1$3.validateContextObject('Query.off', 'context', context, true);
19249
+ require$$2$3.validateCallback('Query.off', 'callback', callback, true);
19250
+ require$$2$3.validateContextObject('Query.off', 'context', context, true);
17707
19251
  if (callback) {
17708
19252
  const valueCallback = () => { };
17709
19253
  valueCallback.userCallback = callback;
@@ -17726,10 +19270,10 @@ class Query {
17726
19270
  * Attaches a listener, waits for the first event, and then removes the listener
17727
19271
  */
17728
19272
  once(eventType, callback, failureCallbackOrContext, context) {
17729
- require$$1$3.validateArgCount('Query.once', 1, 4, arguments.length);
17730
- require$$1$3.validateCallback('Query.once', 'callback', callback, true);
19273
+ require$$2$3.validateArgCount('Query.once', 1, 4, arguments.length);
19274
+ require$$2$3.validateCallback('Query.once', 'callback', callback, true);
17731
19275
  const ret = Query.getCancelAndContextArgs_('Query.once', failureCallbackOrContext, context);
17732
- const deferred = new require$$1$3.Deferred();
19276
+ const deferred = new require$$2$3.Deferred();
17733
19277
  const valueCallback = (expSnapshot, previousChildName) => {
17734
19278
  const result = new DataSnapshot(this.database, expSnapshot);
17735
19279
  if (callback) {
@@ -17772,7 +19316,7 @@ class Query {
17772
19316
  });
17773
19317
  break;
17774
19318
  default:
17775
- throw new Error(require$$1$3.errorPrefix('Query.once', 'eventType') +
19319
+ throw new Error(require$$2$3.errorPrefix('Query.once', 'eventType') +
17776
19320
  'must be a valid event type = "value", "child_added", "child_removed", ' +
17777
19321
  '"child_changed", or "child_moved".');
17778
19322
  }
@@ -17782,58 +19326,58 @@ class Query {
17782
19326
  * Set a limit and anchor it to the start of the window.
17783
19327
  */
17784
19328
  limitToFirst(limit) {
17785
- require$$1$3.validateArgCount('Query.limitToFirst', 1, 1, arguments.length);
19329
+ require$$2$3.validateArgCount('Query.limitToFirst', 1, 1, arguments.length);
17786
19330
  return new Query(this.database, query_1(this._delegate, limitToFirst_1(limit)));
17787
19331
  }
17788
19332
  /**
17789
19333
  * Set a limit and anchor it to the end of the window.
17790
19334
  */
17791
19335
  limitToLast(limit) {
17792
- require$$1$3.validateArgCount('Query.limitToLast', 1, 1, arguments.length);
19336
+ require$$2$3.validateArgCount('Query.limitToLast', 1, 1, arguments.length);
17793
19337
  return new Query(this.database, query_1(this._delegate, limitToLast_1(limit)));
17794
19338
  }
17795
19339
  /**
17796
19340
  * Given a child path, return a new query ordered by the specified grandchild path.
17797
19341
  */
17798
19342
  orderByChild(path) {
17799
- require$$1$3.validateArgCount('Query.orderByChild', 1, 1, arguments.length);
19343
+ require$$2$3.validateArgCount('Query.orderByChild', 1, 1, arguments.length);
17800
19344
  return new Query(this.database, query_1(this._delegate, orderByChild_1(path)));
17801
19345
  }
17802
19346
  /**
17803
19347
  * Return a new query ordered by the KeyIndex
17804
19348
  */
17805
19349
  orderByKey() {
17806
- require$$1$3.validateArgCount('Query.orderByKey', 0, 0, arguments.length);
19350
+ require$$2$3.validateArgCount('Query.orderByKey', 0, 0, arguments.length);
17807
19351
  return new Query(this.database, query_1(this._delegate, orderByKey_1()));
17808
19352
  }
17809
19353
  /**
17810
19354
  * Return a new query ordered by the PriorityIndex
17811
19355
  */
17812
19356
  orderByPriority() {
17813
- require$$1$3.validateArgCount('Query.orderByPriority', 0, 0, arguments.length);
19357
+ require$$2$3.validateArgCount('Query.orderByPriority', 0, 0, arguments.length);
17814
19358
  return new Query(this.database, query_1(this._delegate, orderByPriority_1()));
17815
19359
  }
17816
19360
  /**
17817
19361
  * Return a new query ordered by the ValueIndex
17818
19362
  */
17819
19363
  orderByValue() {
17820
- require$$1$3.validateArgCount('Query.orderByValue', 0, 0, arguments.length);
19364
+ require$$2$3.validateArgCount('Query.orderByValue', 0, 0, arguments.length);
17821
19365
  return new Query(this.database, query_1(this._delegate, orderByValue_1()));
17822
19366
  }
17823
19367
  startAt(value = null, name) {
17824
- require$$1$3.validateArgCount('Query.startAt', 0, 2, arguments.length);
19368
+ require$$2$3.validateArgCount('Query.startAt', 0, 2, arguments.length);
17825
19369
  return new Query(this.database, query_1(this._delegate, startAt_1(value, name)));
17826
19370
  }
17827
19371
  startAfter(value = null, name) {
17828
- require$$1$3.validateArgCount('Query.startAfter', 0, 2, arguments.length);
19372
+ require$$2$3.validateArgCount('Query.startAfter', 0, 2, arguments.length);
17829
19373
  return new Query(this.database, query_1(this._delegate, startAfter_1(value, name)));
17830
19374
  }
17831
19375
  endAt(value = null, name) {
17832
- require$$1$3.validateArgCount('Query.endAt', 0, 2, arguments.length);
19376
+ require$$2$3.validateArgCount('Query.endAt', 0, 2, arguments.length);
17833
19377
  return new Query(this.database, query_1(this._delegate, endAt_1(value, name)));
17834
19378
  }
17835
19379
  endBefore(value = null, name) {
17836
- require$$1$3.validateArgCount('Query.endBefore', 0, 2, arguments.length);
19380
+ require$$2$3.validateArgCount('Query.endBefore', 0, 2, arguments.length);
17837
19381
  return new Query(this.database, query_1(this._delegate, endBefore_1(value, name)));
17838
19382
  }
17839
19383
  /**
@@ -17841,28 +19385,28 @@ class Query {
17841
19385
  * the specified name.
17842
19386
  */
17843
19387
  equalTo(value, name) {
17844
- require$$1$3.validateArgCount('Query.equalTo', 1, 2, arguments.length);
19388
+ require$$2$3.validateArgCount('Query.equalTo', 1, 2, arguments.length);
17845
19389
  return new Query(this.database, query_1(this._delegate, equalTo_1(value, name)));
17846
19390
  }
17847
19391
  /**
17848
19392
  * @returns URL for this location.
17849
19393
  */
17850
19394
  toString() {
17851
- require$$1$3.validateArgCount('Query.toString', 0, 0, arguments.length);
19395
+ require$$2$3.validateArgCount('Query.toString', 0, 0, arguments.length);
17852
19396
  return this._delegate.toString();
17853
19397
  }
17854
19398
  // Do not create public documentation. This is intended to make JSON serialization work but is otherwise unnecessary
17855
19399
  // for end-users.
17856
19400
  toJSON() {
17857
19401
  // An optional spacer argument is unnecessary for a string.
17858
- require$$1$3.validateArgCount('Query.toJSON', 0, 1, arguments.length);
19402
+ require$$2$3.validateArgCount('Query.toJSON', 0, 1, arguments.length);
17859
19403
  return this._delegate.toJSON();
17860
19404
  }
17861
19405
  /**
17862
19406
  * Return true if this query and the provided query are equivalent; otherwise, return false.
17863
19407
  */
17864
19408
  isEqual(other) {
17865
- require$$1$3.validateArgCount('Query.isEqual', 1, 1, arguments.length);
19409
+ require$$2$3.validateArgCount('Query.isEqual', 1, 1, arguments.length);
17866
19410
  if (!(other instanceof Query)) {
17867
19411
  const error = 'Query.isEqual failed: First argument must be an instance of firebase.database.Query.';
17868
19412
  throw new Error(error);
@@ -17878,9 +19422,9 @@ class Query {
17878
19422
  const ret = { cancel: undefined, context: undefined };
17879
19423
  if (cancelOrContext && context) {
17880
19424
  ret.cancel = cancelOrContext;
17881
- require$$1$3.validateCallback(fnName, 'cancel', ret.cancel, true);
19425
+ require$$2$3.validateCallback(fnName, 'cancel', ret.cancel, true);
17882
19426
  ret.context = context;
17883
- require$$1$3.validateContextObject(fnName, 'context', ret.context, true);
19427
+ require$$2$3.validateContextObject(fnName, 'context', ret.context, true);
17884
19428
  }
17885
19429
  else if (cancelOrContext) {
17886
19430
  // we have either a cancel callback or a context.
@@ -17892,7 +19436,7 @@ class Query {
17892
19436
  ret.cancel = cancelOrContext;
17893
19437
  }
17894
19438
  else {
17895
- throw new Error(require$$1$3.errorPrefix(fnName, 'cancelOrContext') +
19439
+ throw new Error(require$$2$3.errorPrefix(fnName, 'cancelOrContext') +
17896
19440
  ' must either be a cancel callback or a context object.');
17897
19441
  }
17898
19442
  }
@@ -17917,11 +19461,11 @@ class Reference extends Query {
17917
19461
  }
17918
19462
  /** @returns {?string} */
17919
19463
  getKey() {
17920
- require$$1$3.validateArgCount('Reference.key', 0, 0, arguments.length);
19464
+ require$$2$3.validateArgCount('Reference.key', 0, 0, arguments.length);
17921
19465
  return this._delegate.key;
17922
19466
  }
17923
19467
  child(pathString) {
17924
- require$$1$3.validateArgCount('Reference.child', 1, 1, arguments.length);
19468
+ require$$2$3.validateArgCount('Reference.child', 1, 1, arguments.length);
17925
19469
  if (typeof pathString === 'number') {
17926
19470
  pathString = String(pathString);
17927
19471
  }
@@ -17929,18 +19473,18 @@ class Reference extends Query {
17929
19473
  }
17930
19474
  /** @returns {?Reference} */
17931
19475
  getParent() {
17932
- require$$1$3.validateArgCount('Reference.parent', 0, 0, arguments.length);
19476
+ require$$2$3.validateArgCount('Reference.parent', 0, 0, arguments.length);
17933
19477
  const parent = this._delegate.parent;
17934
19478
  return parent ? new Reference(this.database, parent) : null;
17935
19479
  }
17936
19480
  /** @returns {!Reference} */
17937
19481
  getRoot() {
17938
- require$$1$3.validateArgCount('Reference.root', 0, 0, arguments.length);
19482
+ require$$2$3.validateArgCount('Reference.root', 0, 0, arguments.length);
17939
19483
  return new Reference(this.database, this._delegate.root);
17940
19484
  }
17941
19485
  set(newVal, onComplete) {
17942
- require$$1$3.validateArgCount('Reference.set', 1, 2, arguments.length);
17943
- require$$1$3.validateCallback('Reference.set', 'onComplete', onComplete, true);
19486
+ require$$2$3.validateArgCount('Reference.set', 1, 2, arguments.length);
19487
+ require$$2$3.validateCallback('Reference.set', 'onComplete', onComplete, true);
17944
19488
  const result = set_1(this._delegate, newVal);
17945
19489
  if (onComplete) {
17946
19490
  result.then(() => onComplete(null), error => onComplete(error));
@@ -17948,7 +19492,7 @@ class Reference extends Query {
17948
19492
  return result;
17949
19493
  }
17950
19494
  update(values, onComplete) {
17951
- require$$1$3.validateArgCount('Reference.update', 1, 2, arguments.length);
19495
+ require$$2$3.validateArgCount('Reference.update', 1, 2, arguments.length);
17952
19496
  if (Array.isArray(values)) {
17953
19497
  const newObjectToMerge = {};
17954
19498
  for (let i = 0; i < values.length; ++i) {
@@ -17961,7 +19505,7 @@ class Reference extends Query {
17961
19505
  'only update some of the children.');
17962
19506
  }
17963
19507
  _validateWritablePath('Reference.update', this._delegate._path);
17964
- require$$1$3.validateCallback('Reference.update', 'onComplete', onComplete, true);
19508
+ require$$2$3.validateCallback('Reference.update', 'onComplete', onComplete, true);
17965
19509
  const result = update_1(this._delegate, values);
17966
19510
  if (onComplete) {
17967
19511
  result.then(() => onComplete(null), error => onComplete(error));
@@ -17969,8 +19513,8 @@ class Reference extends Query {
17969
19513
  return result;
17970
19514
  }
17971
19515
  setWithPriority(newVal, newPriority, onComplete) {
17972
- require$$1$3.validateArgCount('Reference.setWithPriority', 2, 3, arguments.length);
17973
- require$$1$3.validateCallback('Reference.setWithPriority', 'onComplete', onComplete, true);
19516
+ require$$2$3.validateArgCount('Reference.setWithPriority', 2, 3, arguments.length);
19517
+ require$$2$3.validateCallback('Reference.setWithPriority', 'onComplete', onComplete, true);
17974
19518
  const result = setWithPriority_1(this._delegate, newVal, newPriority);
17975
19519
  if (onComplete) {
17976
19520
  result.then(() => onComplete(null), error => onComplete(error));
@@ -17978,8 +19522,8 @@ class Reference extends Query {
17978
19522
  return result;
17979
19523
  }
17980
19524
  remove(onComplete) {
17981
- require$$1$3.validateArgCount('Reference.remove', 0, 1, arguments.length);
17982
- require$$1$3.validateCallback('Reference.remove', 'onComplete', onComplete, true);
19525
+ require$$2$3.validateArgCount('Reference.remove', 0, 1, arguments.length);
19526
+ require$$2$3.validateCallback('Reference.remove', 'onComplete', onComplete, true);
17983
19527
  const result = remove_1(this._delegate);
17984
19528
  if (onComplete) {
17985
19529
  result.then(() => onComplete(null), error => onComplete(error));
@@ -17987,9 +19531,9 @@ class Reference extends Query {
17987
19531
  return result;
17988
19532
  }
17989
19533
  transaction(transactionUpdate, onComplete, applyLocally) {
17990
- require$$1$3.validateArgCount('Reference.transaction', 1, 3, arguments.length);
17991
- require$$1$3.validateCallback('Reference.transaction', 'transactionUpdate', transactionUpdate, false);
17992
- require$$1$3.validateCallback('Reference.transaction', 'onComplete', onComplete, true);
19534
+ require$$2$3.validateArgCount('Reference.transaction', 1, 3, arguments.length);
19535
+ require$$2$3.validateCallback('Reference.transaction', 'transactionUpdate', transactionUpdate, false);
19536
+ require$$2$3.validateCallback('Reference.transaction', 'onComplete', onComplete, true);
17993
19537
  validateBoolean('Reference.transaction', 'applyLocally', applyLocally, true);
17994
19538
  const result = runTransaction_1(this._delegate, transactionUpdate, {
17995
19539
  applyLocally
@@ -18000,8 +19544,8 @@ class Reference extends Query {
18000
19544
  return result;
18001
19545
  }
18002
19546
  setPriority(priority, onComplete) {
18003
- require$$1$3.validateArgCount('Reference.setPriority', 1, 2, arguments.length);
18004
- require$$1$3.validateCallback('Reference.setPriority', 'onComplete', onComplete, true);
19547
+ require$$2$3.validateArgCount('Reference.setPriority', 1, 2, arguments.length);
19548
+ require$$2$3.validateCallback('Reference.setPriority', 'onComplete', onComplete, true);
18005
19549
  const result = setPriority_1(this._delegate, priority);
18006
19550
  if (onComplete) {
18007
19551
  result.then(() => onComplete(null), error => onComplete(error));
@@ -18009,8 +19553,8 @@ class Reference extends Query {
18009
19553
  return result;
18010
19554
  }
18011
19555
  push(value, onComplete) {
18012
- require$$1$3.validateArgCount('Reference.push', 0, 2, arguments.length);
18013
- require$$1$3.validateCallback('Reference.push', 'onComplete', onComplete, true);
19556
+ require$$2$3.validateArgCount('Reference.push', 0, 2, arguments.length);
19557
+ require$$2$3.validateCallback('Reference.push', 'onComplete', onComplete, true);
18014
19558
  const expPromise = push_1(this._delegate, value);
18015
19559
  const promise = expPromise.then(expRef => new Reference(this.database, expRef));
18016
19560
  if (onComplete) {
@@ -18081,7 +19625,7 @@ class Database {
18081
19625
  connectDatabaseEmulator_1(this._delegate, host, port, options);
18082
19626
  }
18083
19627
  ref(path) {
18084
- require$$1$3.validateArgCount('database.ref', 0, 1, arguments.length);
19628
+ require$$2$3.validateArgCount('database.ref', 0, 1, arguments.length);
18085
19629
  if (path instanceof Reference) {
18086
19630
  const childRef = refFromURL_1(this._delegate, path.toString());
18087
19631
  return new Reference(this, childRef);
@@ -18099,17 +19643,17 @@ class Database {
18099
19643
  */
18100
19644
  refFromURL(url) {
18101
19645
  const apiName = 'database.refFromURL';
18102
- require$$1$3.validateArgCount(apiName, 1, 1, arguments.length);
19646
+ require$$2$3.validateArgCount(apiName, 1, 1, arguments.length);
18103
19647
  const childRef = refFromURL_1(this._delegate, url);
18104
19648
  return new Reference(this, childRef);
18105
19649
  }
18106
19650
  // Make individual repo go offline.
18107
19651
  goOffline() {
18108
- require$$1$3.validateArgCount('database.goOffline', 0, 0, arguments.length);
19652
+ require$$2$3.validateArgCount('database.goOffline', 0, 0, arguments.length);
18109
19653
  return goOffline_1(this._delegate);
18110
19654
  }
18111
19655
  goOnline() {
18112
- require$$1$3.validateArgCount('database.goOnline', 0, 0, arguments.length);
19656
+ require$$2$3.validateArgCount('database.goOnline', 0, 0, arguments.length);
18113
19657
  return goOnline_1(this._delegate);
18114
19658
  }
18115
19659
  }
@@ -18129,17 +19673,17 @@ Database.ServerValue = {
18129
19673
  */
18130
19674
  function initStandalone$1({ app, url, version, customAuthImpl, customAppCheckImpl, namespace, nodeAdmin = false }) {
18131
19675
  _setSDKVersion(version);
18132
- const container = new require$$3.ComponentContainer('database-standalone');
19676
+ const container = new require$$0$3.ComponentContainer('database-standalone');
18133
19677
  /**
18134
19678
  * ComponentContainer('database-standalone') is just a placeholder that doesn't perform
18135
19679
  * any actual function.
18136
19680
  */
18137
- const authProvider = new require$$3.Provider('auth-internal', container);
18138
- authProvider.setComponent(new require$$3.Component('auth-internal', () => customAuthImpl, "PRIVATE" /* ComponentType.PRIVATE */));
19681
+ const authProvider = new require$$0$3.Provider('auth-internal', container);
19682
+ authProvider.setComponent(new require$$0$3.Component('auth-internal', () => customAuthImpl, "PRIVATE" /* ComponentType.PRIVATE */));
18139
19683
  let appCheckProvider = undefined;
18140
19684
  if (customAppCheckImpl) {
18141
- appCheckProvider = new require$$3.Provider('app-check-internal', container);
18142
- appCheckProvider.setComponent(new require$$3.Component('app-check-internal', () => customAppCheckImpl, "PRIVATE" /* ComponentType.PRIVATE */));
19685
+ appCheckProvider = new require$$0$3.Provider('app-check-internal', container);
19686
+ appCheckProvider.setComponent(new require$$0$3.Component('app-check-internal', () => customAppCheckImpl, "PRIVATE" /* ComponentType.PRIVATE */));
18143
19687
  }
18144
19688
  return {
18145
19689
  instance: new Database(_repoManagerDatabaseFromApp(app, authProvider, appCheckProvider, url, nodeAdmin), app),
@@ -18148,8 +19692,8 @@ function initStandalone$1({ app, url, version, customAuthImpl, customAppCheckImp
18148
19692
  }
18149
19693
 
18150
19694
  var INTERNAL = /*#__PURE__*/Object.freeze({
18151
- __proto__: null,
18152
- initStandalone: initStandalone$1
19695
+ __proto__: null,
19696
+ initStandalone: initStandalone$1
18153
19697
  });
18154
19698
 
18155
19699
  /**
@@ -18179,7 +19723,7 @@ const ServerValue = Database.ServerValue;
18179
19723
  * @param nodeAdmin - true if the SDK is being initialized from Firebase Admin.
18180
19724
  */
18181
19725
  function initStandalone(app, url, version, nodeAdmin = true) {
18182
- require$$1$3.CONSTANTS.NODE_ADMIN = nodeAdmin;
19726
+ require$$2$3.CONSTANTS.NODE_ADMIN = nodeAdmin;
18183
19727
  return initStandalone$1({
18184
19728
  app,
18185
19729
  url,