@firebase/app 0.9.29-canary.9ca1a4e4f → 0.9.29-canary.c8a2568dd

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.
@@ -1,7 +1,7 @@
1
1
  import { Component, ComponentContainer } from '@firebase/component';
2
- import { __values, __assign, __awaiter, __generator, __spreadArray, __read } from 'tslib';
2
+ import { __values, __assign, __extends, __awaiter, __generator, __spreadArray, __read } from 'tslib';
3
3
  import { Logger, setUserLogHandler, setLogLevel as setLogLevel$1 } from '@firebase/logger';
4
- import { ErrorFactory, getDefaultAppConfig, deepEqual, FirebaseError, base64urlEncodeWithoutPadding, isIndexedDBAvailable, validateIndexedDBOpenable } from '@firebase/util';
4
+ import { ErrorFactory, getDefaultAppConfig, deepEqual, isBrowser, FirebaseError, base64urlEncodeWithoutPadding, isIndexedDBAvailable, validateIndexedDBOpenable } from '@firebase/util';
5
5
  export { FirebaseError } from '@firebase/util';
6
6
  import { openDB } from 'idb';
7
7
 
@@ -60,7 +60,7 @@ function isVersionServiceProvider(provider) {
60
60
  }
61
61
 
62
62
  var name$o = "@firebase/app";
63
- var version$1 = "0.9.29-canary.9ca1a4e4f";
63
+ var version$1 = "0.9.29-canary.c8a2568dd";
64
64
 
65
65
  /**
66
66
  * @license
@@ -127,7 +127,7 @@ var name$2 = "@firebase/firestore";
127
127
  var name$1 = "@firebase/firestore-compat";
128
128
 
129
129
  var name = "firebase";
130
- var version = "10.9.0-canary.9ca1a4e4f";
130
+ var version = "10.9.0-canary.c8a2568dd";
131
131
 
132
132
  /**
133
133
  * @license
@@ -201,6 +201,10 @@ var PLATFORM_LOG_STRING = (_a$1 = {},
201
201
  * @internal
202
202
  */
203
203
  var _apps = new Map();
204
+ /**
205
+ * @internal
206
+ */
207
+ var _serverApps = new Map();
204
208
  /**
205
209
  * Registered components.
206
210
  *
@@ -236,7 +240,7 @@ function _addOrOverwriteComponent(app, component) {
236
240
  * @internal
237
241
  */
238
242
  function _registerComponent(component) {
239
- var e_1, _a;
243
+ var e_1, _a, e_2, _b;
240
244
  var componentName = component.name;
241
245
  if (_components.has(componentName)) {
242
246
  logger.debug("There were multiple attempts to register component ".concat(componentName, "."));
@@ -245,18 +249,31 @@ function _registerComponent(component) {
245
249
  _components.set(componentName, component);
246
250
  try {
247
251
  // add the component to existing app instances
248
- for (var _b = __values(_apps.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
249
- var app = _c.value;
252
+ for (var _c = __values(_apps.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
253
+ var app = _d.value;
250
254
  _addComponent(app, component);
251
255
  }
252
256
  }
253
257
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
254
258
  finally {
255
259
  try {
256
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
260
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
257
261
  }
258
262
  finally { if (e_1) throw e_1.error; }
259
263
  }
264
+ try {
265
+ for (var _e = __values(_serverApps.values()), _f = _e.next(); !_f.done; _f = _e.next()) {
266
+ var serverApp = _f.value;
267
+ _addComponent(serverApp, component);
268
+ }
269
+ }
270
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
271
+ finally {
272
+ try {
273
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
274
+ }
275
+ finally { if (e_2) throw e_2.error; }
276
+ }
260
277
  return true;
261
278
  }
262
279
  /**
@@ -289,6 +306,28 @@ function _removeServiceInstance(app, name, instanceIdentifier) {
289
306
  if (instanceIdentifier === void 0) { instanceIdentifier = DEFAULT_ENTRY_NAME; }
290
307
  _getProvider(app, name).clearInstance(instanceIdentifier);
291
308
  }
309
+ /**
310
+ *
311
+ * @param obj - an object of type FirebaseApp or FirebaseOptions.
312
+ *
313
+ * @returns true if the provide object is of type FirebaseApp.
314
+ *
315
+ * @internal
316
+ */
317
+ function _isFirebaseApp(obj) {
318
+ return obj.options !== undefined;
319
+ }
320
+ /**
321
+ *
322
+ * @param obj - an object of type FirebaseApp.
323
+ *
324
+ * @returns true if the provided object is of type FirebaseServerAppImpl.
325
+ *
326
+ * @internal
327
+ */
328
+ function _isFirebaseServerApp(obj) {
329
+ return obj.settings !== undefined;
330
+ }
292
331
  /**
293
332
  * Test only
294
333
  *
@@ -318,9 +357,10 @@ var _a;
318
357
  var ERRORS = (_a = {},
319
358
  _a["no-app" /* AppError.NO_APP */] = "No Firebase App '{$appName}' has been created - " +
320
359
  'call initializeApp() first',
321
- _a["bad-app-name" /* AppError.BAD_APP_NAME */] = "Illegal App name: '{$appName}",
360
+ _a["bad-app-name" /* AppError.BAD_APP_NAME */] = "Illegal App name: '{$appName}'",
322
361
  _a["duplicate-app" /* AppError.DUPLICATE_APP */] = "Firebase App named '{$appName}' already exists with different options or config",
323
362
  _a["app-deleted" /* AppError.APP_DELETED */] = "Firebase App named '{$appName}' already deleted",
363
+ _a["server-app-deleted" /* AppError.SERVER_APP_DELETED */] = 'Firebase Server App has been deleted',
324
364
  _a["no-options" /* AppError.NO_OPTIONS */] = 'Need to provide options, when not being deployed to hosting via source.',
325
365
  _a["invalid-app-argument" /* AppError.INVALID_APP_ARGUMENT */] = 'firebase.{$appName}() takes either no argument or a ' +
326
366
  'Firebase App instance.',
@@ -329,6 +369,8 @@ var ERRORS = (_a = {},
329
369
  _a["idb-get" /* AppError.IDB_GET */] = 'Error thrown when reading from IndexedDB. Original error: {$originalErrorMessage}.',
330
370
  _a["idb-set" /* AppError.IDB_WRITE */] = 'Error thrown when writing to IndexedDB. Original error: {$originalErrorMessage}.',
331
371
  _a["idb-delete" /* AppError.IDB_DELETE */] = 'Error thrown when deleting from IndexedDB. Original error: {$originalErrorMessage}.',
372
+ _a["finalization-registry-not-supported" /* AppError.FINALIZATION_REGISTRY_NOT_SUPPORTED */] = 'FirebaseServerApp deleteOnDeref field defined but the JS runtime does not support FinalizationRegistry.',
373
+ _a["invalid-server-app-environment" /* AppError.INVALID_SERVER_APP_ENVIRONMENT */] = 'FirebaseServerApp is not for use in browser environments.',
332
374
  _a);
333
375
  var ERROR_FACTORY = new ErrorFactory('app', 'Firebase', ERRORS);
334
376
 
@@ -425,6 +467,108 @@ var FirebaseAppImpl = /** @class */ (function () {
425
467
  return FirebaseAppImpl;
426
468
  }());
427
469
 
470
+ /**
471
+ * @license
472
+ * Copyright 2023 Google LLC
473
+ *
474
+ * Licensed under the Apache License, Version 2.0 (the "License");
475
+ * you may not use this file except in compliance with the License.
476
+ * You may obtain a copy of the License at
477
+ *
478
+ * http://www.apache.org/licenses/LICENSE-2.0
479
+ *
480
+ * Unless required by applicable law or agreed to in writing, software
481
+ * distributed under the License is distributed on an "AS IS" BASIS,
482
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
483
+ * See the License for the specific language governing permissions and
484
+ * limitations under the License.
485
+ */
486
+ var FirebaseServerAppImpl = /** @class */ (function (_super) {
487
+ __extends(FirebaseServerAppImpl, _super);
488
+ function FirebaseServerAppImpl(options, serverConfig, name, container) {
489
+ var _this = this;
490
+ // Build configuration parameters for the FirebaseAppImpl base class.
491
+ var automaticDataCollectionEnabled = serverConfig.automaticDataCollectionEnabled !== undefined
492
+ ? serverConfig.automaticDataCollectionEnabled
493
+ : false;
494
+ // Create the FirebaseAppSettings object for the FirebaseAppImp constructor.
495
+ var config = {
496
+ name: name,
497
+ automaticDataCollectionEnabled: automaticDataCollectionEnabled
498
+ };
499
+ if (options.apiKey !== undefined) {
500
+ // Construct the parent FirebaseAppImp object.
501
+ _this = _super.call(this, options, config, container) || this;
502
+ }
503
+ else {
504
+ var appImpl = options;
505
+ _this = _super.call(this, appImpl.options, config, container) || this;
506
+ }
507
+ // Now construct the data for the FirebaseServerAppImpl.
508
+ _this._serverConfig = __assign({ automaticDataCollectionEnabled: automaticDataCollectionEnabled }, serverConfig);
509
+ _this._finalizationRegistry = new FinalizationRegistry(function () {
510
+ _this.automaticCleanup();
511
+ });
512
+ _this._refCount = 0;
513
+ _this.incRefCount(_this._serverConfig.releaseOnDeref);
514
+ // Do not retain a hard reference to the dref object, otherwise the FinalizationRegisry
515
+ // will never trigger.
516
+ _this._serverConfig.releaseOnDeref = undefined;
517
+ serverConfig.releaseOnDeref = undefined;
518
+ registerVersion(name$o, version$1, 'serverapp');
519
+ return _this;
520
+ }
521
+ Object.defineProperty(FirebaseServerAppImpl.prototype, "refCount", {
522
+ get: function () {
523
+ return this._refCount;
524
+ },
525
+ enumerable: false,
526
+ configurable: true
527
+ });
528
+ // Increment the reference count of this server app. If an object is provided, register it
529
+ // with the finalization registry.
530
+ FirebaseServerAppImpl.prototype.incRefCount = function (obj) {
531
+ if (this.isDeleted) {
532
+ return;
533
+ }
534
+ this._refCount++;
535
+ if (obj !== undefined) {
536
+ this._finalizationRegistry.register(obj, this);
537
+ }
538
+ };
539
+ // Decrement the reference count.
540
+ FirebaseServerAppImpl.prototype.decRefCount = function () {
541
+ if (this.isDeleted) {
542
+ return 0;
543
+ }
544
+ return --this._refCount;
545
+ };
546
+ // Invoked by the FinalizationRegistry callback to note that this app should go through its
547
+ // reference counts and delete itself if no reference count remain. The coordinating logic that
548
+ // handles this is in deleteApp(...).
549
+ FirebaseServerAppImpl.prototype.automaticCleanup = function () {
550
+ void deleteApp(this);
551
+ };
552
+ Object.defineProperty(FirebaseServerAppImpl.prototype, "settings", {
553
+ get: function () {
554
+ this.checkDestroyed();
555
+ return this._serverConfig;
556
+ },
557
+ enumerable: false,
558
+ configurable: true
559
+ });
560
+ /**
561
+ * This function will throw an Error if the App has already been deleted -
562
+ * use before performing API actions on the App.
563
+ */
564
+ FirebaseServerAppImpl.prototype.checkDestroyed = function () {
565
+ if (this.isDeleted) {
566
+ throw ERROR_FACTORY.create("server-app-deleted" /* AppError.SERVER_APP_DELETED */);
567
+ }
568
+ };
569
+ return FirebaseServerAppImpl;
570
+ }(FirebaseAppImpl));
571
+
428
572
  /**
429
573
  * @license
430
574
  * Copyright 2019 Google LLC
@@ -495,6 +639,61 @@ function initializeApp(_options, rawConfig) {
495
639
  _apps.set(name, newApp);
496
640
  return newApp;
497
641
  }
642
+ function initializeServerApp(_options, _serverAppConfig) {
643
+ var e_2, _a;
644
+ if (isBrowser()) {
645
+ // FirebaseServerApp isn't designed to be run in browsers.
646
+ throw ERROR_FACTORY.create("invalid-server-app-environment" /* AppError.INVALID_SERVER_APP_ENVIRONMENT */);
647
+ }
648
+ if (_serverAppConfig.automaticDataCollectionEnabled === undefined) {
649
+ _serverAppConfig.automaticDataCollectionEnabled = false;
650
+ }
651
+ var appOptions;
652
+ if (_isFirebaseApp(_options)) {
653
+ appOptions = _options.options;
654
+ }
655
+ else {
656
+ appOptions = _options;
657
+ }
658
+ // Build an app name based on a hash of the configuration options.
659
+ var nameObj = __assign(__assign({}, _serverAppConfig), appOptions);
660
+ // However, Do not mangle the name based on releaseOnDeref, since it will vary between the
661
+ // construction of FirebaseServerApp instances. For example, if the object is the request headers.
662
+ if (nameObj.releaseOnDeref !== undefined) {
663
+ delete nameObj.releaseOnDeref;
664
+ }
665
+ var hashCode = function (s) {
666
+ return __spreadArray([], __read(s), false).reduce(function (hash, c) { return (Math.imul(31, hash) + c.charCodeAt(0)) | 0; }, 0);
667
+ };
668
+ if (_serverAppConfig.releaseOnDeref !== undefined) {
669
+ if (typeof FinalizationRegistry === 'undefined') {
670
+ throw ERROR_FACTORY.create("finalization-registry-not-supported" /* AppError.FINALIZATION_REGISTRY_NOT_SUPPORTED */, {});
671
+ }
672
+ }
673
+ var nameString = '' + hashCode(JSON.stringify(nameObj));
674
+ var existingApp = _serverApps.get(nameString);
675
+ if (existingApp) {
676
+ existingApp.incRefCount(_serverAppConfig.releaseOnDeref);
677
+ return existingApp;
678
+ }
679
+ var container = new ComponentContainer(nameString);
680
+ try {
681
+ for (var _b = __values(_components.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
682
+ var component = _c.value;
683
+ container.addComponent(component);
684
+ }
685
+ }
686
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
687
+ finally {
688
+ try {
689
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
690
+ }
691
+ finally { if (e_2) throw e_2.error; }
692
+ }
693
+ var newApp = new FirebaseServerAppImpl(appOptions, _serverAppConfig, nameString, container);
694
+ _serverApps.set(nameString, newApp);
695
+ return newApp;
696
+ }
498
697
  /**
499
698
  * Retrieves a {@link @firebase/app#FirebaseApp} instance.
500
699
  *
@@ -561,13 +760,24 @@ function getApps() {
561
760
  */
562
761
  function deleteApp(app) {
563
762
  return __awaiter(this, void 0, void 0, function () {
564
- var name;
763
+ var cleanupProviders, name, firebaseServerApp;
565
764
  return __generator(this, function (_a) {
566
765
  switch (_a.label) {
567
766
  case 0:
767
+ cleanupProviders = false;
568
768
  name = app.name;
569
- if (!_apps.has(name)) return [3 /*break*/, 2];
570
- _apps.delete(name);
769
+ if (_apps.has(name)) {
770
+ cleanupProviders = true;
771
+ _apps.delete(name);
772
+ }
773
+ else if (_serverApps.has(name)) {
774
+ firebaseServerApp = app;
775
+ if (firebaseServerApp.decRefCount() <= 0) {
776
+ _serverApps.delete(name);
777
+ cleanupProviders = true;
778
+ }
779
+ }
780
+ if (!cleanupProviders) return [3 /*break*/, 2];
571
781
  return [4 /*yield*/, Promise.all(app.container
572
782
  .getProviders()
573
783
  .map(function (provider) { return provider.delete(); }))];
@@ -1120,5 +1330,5 @@ function registerCoreComponents(variant) {
1120
1330
  */
1121
1331
  registerCoreComponents('');
1122
1332
 
1123
- export { SDK_VERSION, DEFAULT_ENTRY_NAME as _DEFAULT_ENTRY_NAME, _addComponent, _addOrOverwriteComponent, _apps, _clearComponents, _components, _getProvider, _registerComponent, _removeServiceInstance, deleteApp, getApp, getApps, initializeApp, onLog, registerVersion, setLogLevel };
1333
+ export { SDK_VERSION, DEFAULT_ENTRY_NAME as _DEFAULT_ENTRY_NAME, _addComponent, _addOrOverwriteComponent, _apps, _clearComponents, _components, _getProvider, _isFirebaseApp, _isFirebaseServerApp, _registerComponent, _removeServiceInstance, _serverApps, deleteApp, getApp, getApps, initializeApp, initializeServerApp, onLog, registerVersion, setLogLevel };
1124
1334
  //# sourceMappingURL=index.esm5.js.map