@firebase/app 0.9.29 → 0.10.0-canary.0068ed5ab

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