123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431 |
- import { ErrorFactory, contains, deepExtend, createSubscribe, isBrowser } from '@firebase/util';
- import { Component } from '@firebase/component';
- import * as modularAPIs from '@firebase/app';
- import { _addComponent, deleteApp, _DEFAULT_ENTRY_NAME, _addOrOverwriteComponent, registerVersion } from '@firebase/app';
- import { Logger } from '@firebase/logger';
-
- /**
- * @license
- * Copyright 2020 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- /**
- * Global context object for a collection of services using
- * a shared authentication state.
- *
- * marked as internal because it references internal types exported from @firebase/app
- * @internal
- */
- class FirebaseAppImpl {
- constructor(_delegate, firebase) {
- this._delegate = _delegate;
- this.firebase = firebase;
- // add itself to container
- _addComponent(_delegate, new Component('app-compat', () => this, "PUBLIC" /* ComponentType.PUBLIC */));
- this.container = _delegate.container;
- }
- get automaticDataCollectionEnabled() {
- return this._delegate.automaticDataCollectionEnabled;
- }
- set automaticDataCollectionEnabled(val) {
- this._delegate.automaticDataCollectionEnabled = val;
- }
- get name() {
- return this._delegate.name;
- }
- get options() {
- return this._delegate.options;
- }
- delete() {
- return new Promise(resolve => {
- this._delegate.checkDestroyed();
- resolve();
- }).then(() => {
- this.firebase.INTERNAL.removeApp(this.name);
- return deleteApp(this._delegate);
- });
- }
- /**
- * Return a service instance associated with this app (creating it
- * on demand), identified by the passed instanceIdentifier.
- *
- * NOTE: Currently storage and functions are the only ones that are leveraging this
- * functionality. They invoke it by calling:
- *
- * ```javascript
- * firebase.app().storage('STORAGE BUCKET ID')
- * ```
- *
- * The service name is passed to this already
- * @internal
- */
- _getService(name, instanceIdentifier = _DEFAULT_ENTRY_NAME) {
- var _a;
- this._delegate.checkDestroyed();
- // Initialize instance if InstatiationMode is `EXPLICIT`.
- const provider = this._delegate.container.getProvider(name);
- if (!provider.isInitialized() &&
- ((_a = provider.getComponent()) === null || _a === void 0 ? void 0 : _a.instantiationMode) === "EXPLICIT" /* InstantiationMode.EXPLICIT */) {
- provider.initialize();
- }
- // getImmediate will always succeed because _getService is only called for registered components.
- return provider.getImmediate({
- identifier: instanceIdentifier
- });
- }
- /**
- * Remove a service instance from the cache, so we will create a new instance for this service
- * when people try to get it again.
- *
- * NOTE: currently only firestore uses this functionality to support firestore shutdown.
- *
- * @param name The service name
- * @param instanceIdentifier instance identifier in case multiple instances are allowed
- * @internal
- */
- _removeServiceInstance(name, instanceIdentifier = _DEFAULT_ENTRY_NAME) {
- this._delegate.container
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- .getProvider(name)
- .clearInstance(instanceIdentifier);
- }
- /**
- * @param component the component being added to this app's container
- * @internal
- */
- _addComponent(component) {
- _addComponent(this._delegate, component);
- }
- _addOrOverwriteComponent(component) {
- _addOrOverwriteComponent(this._delegate, component);
- }
- toJSON() {
- return {
- name: this.name,
- automaticDataCollectionEnabled: this.automaticDataCollectionEnabled,
- options: this.options
- };
- }
- }
- // TODO: investigate why the following needs to be commented out
- // Prevent dead-code elimination of these methods w/o invalid property
- // copying.
- // (FirebaseAppImpl.prototype.name && FirebaseAppImpl.prototype.options) ||
- // FirebaseAppImpl.prototype.delete ||
- // console.log('dc');
-
- /**
- * @license
- * Copyright 2019 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- const ERRORS = {
- ["no-app" /* AppError.NO_APP */]: "No Firebase App '{$appName}' has been created - " +
- 'call Firebase App.initializeApp()',
- ["invalid-app-argument" /* AppError.INVALID_APP_ARGUMENT */]: 'firebase.{$appName}() takes either no argument or a ' +
- 'Firebase App instance.'
- };
- const ERROR_FACTORY = new ErrorFactory('app-compat', 'Firebase', ERRORS);
-
- /**
- * @license
- * Copyright 2019 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- /**
- * Because auth can't share code with other components, we attach the utility functions
- * in an internal namespace to share code.
- * This function return a firebase namespace object without
- * any utility functions, so it can be shared between the regular firebaseNamespace and
- * the lite version.
- */
- function createFirebaseNamespaceCore(firebaseAppImpl) {
- const apps = {};
- // // eslint-disable-next-line @typescript-eslint/no-explicit-any
- // const components = new Map<string, Component<any>>();
- // A namespace is a plain JavaScript Object.
- const namespace = {
- // Hack to prevent Babel from modifying the object returned
- // as the firebase namespace.
- // @ts-ignore
- __esModule: true,
- initializeApp: initializeAppCompat,
- // @ts-ignore
- app,
- registerVersion: modularAPIs.registerVersion,
- setLogLevel: modularAPIs.setLogLevel,
- onLog: modularAPIs.onLog,
- // @ts-ignore
- apps: null,
- SDK_VERSION: modularAPIs.SDK_VERSION,
- INTERNAL: {
- registerComponent: registerComponentCompat,
- removeApp,
- useAsService,
- modularAPIs
- }
- };
- // Inject a circular default export to allow Babel users who were previously
- // using:
- //
- // import firebase from 'firebase';
- // which becomes: var firebase = require('firebase').default;
- //
- // instead of
- //
- // import * as firebase from 'firebase';
- // which becomes: var firebase = require('firebase');
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- namespace['default'] = namespace;
- // firebase.apps is a read-only getter.
- Object.defineProperty(namespace, 'apps', {
- get: getApps
- });
- /**
- * Called by App.delete() - but before any services associated with the App
- * are deleted.
- */
- function removeApp(name) {
- delete apps[name];
- }
- /**
- * Get the App object for a given name (or DEFAULT).
- */
- function app(name) {
- name = name || modularAPIs._DEFAULT_ENTRY_NAME;
- if (!contains(apps, name)) {
- throw ERROR_FACTORY.create("no-app" /* AppError.NO_APP */, { appName: name });
- }
- return apps[name];
- }
- // @ts-ignore
- app['App'] = firebaseAppImpl;
- /**
- * Create a new App instance (name must be unique).
- *
- * This function is idempotent. It can be called more than once and return the same instance using the same options and config.
- */
- function initializeAppCompat(options, rawConfig = {}) {
- const app = modularAPIs.initializeApp(options, rawConfig);
- if (contains(apps, app.name)) {
- return apps[app.name];
- }
- const appCompat = new firebaseAppImpl(app, namespace);
- apps[app.name] = appCompat;
- return appCompat;
- }
- /*
- * Return an array of all the non-deleted FirebaseApps.
- */
- function getApps() {
- // Make a copy so caller cannot mutate the apps list.
- return Object.keys(apps).map(name => apps[name]);
- }
- function registerComponentCompat(component) {
- const componentName = component.name;
- const componentNameWithoutCompat = componentName.replace('-compat', '');
- if (modularAPIs._registerComponent(component) &&
- component.type === "PUBLIC" /* ComponentType.PUBLIC */) {
- // create service namespace for public components
- // The Service namespace is an accessor function ...
- const serviceNamespace = (appArg = app()) => {
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- if (typeof appArg[componentNameWithoutCompat] !== 'function') {
- // Invalid argument.
- // This happens in the following case: firebase.storage('gs:/')
- throw ERROR_FACTORY.create("invalid-app-argument" /* AppError.INVALID_APP_ARGUMENT */, {
- appName: componentName
- });
- }
- // Forward service instance lookup to the FirebaseApp.
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- return appArg[componentNameWithoutCompat]();
- };
- // ... and a container for service-level properties.
- if (component.serviceProps !== undefined) {
- deepExtend(serviceNamespace, component.serviceProps);
- }
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- namespace[componentNameWithoutCompat] = serviceNamespace;
- // Patch the FirebaseAppImpl prototype
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- firebaseAppImpl.prototype[componentNameWithoutCompat] =
- // TODO: The eslint disable can be removed and the 'ignoreRestArgs'
- // option added to the no-explicit-any rule when ESlint releases it.
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- function (...args) {
- const serviceFxn = this._getService.bind(this, componentName);
- return serviceFxn.apply(this, component.multipleInstances ? args : []);
- };
- }
- return component.type === "PUBLIC" /* ComponentType.PUBLIC */
- ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
- namespace[componentNameWithoutCompat]
- : null;
- }
- // Map the requested service to a registered service name
- // (used to map auth to serverAuth service when needed).
- function useAsService(app, name) {
- if (name === 'serverAuth') {
- return null;
- }
- const useService = name;
- return useService;
- }
- return namespace;
- }
-
- /**
- * @license
- * Copyright 2019 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- /**
- * Return a firebase namespace object.
- *
- * In production, this will be called exactly once and the result
- * assigned to the 'firebase' global. It may be called multiple times
- * in unit tests.
- */
- function createFirebaseNamespace() {
- const namespace = createFirebaseNamespaceCore(FirebaseAppImpl);
- namespace.INTERNAL = Object.assign(Object.assign({}, namespace.INTERNAL), { createFirebaseNamespace,
- extendNamespace,
- createSubscribe,
- ErrorFactory,
- deepExtend });
- /**
- * Patch the top-level firebase namespace with additional properties.
- *
- * firebase.INTERNAL.extendNamespace()
- */
- function extendNamespace(props) {
- deepExtend(namespace, props);
- }
- return namespace;
- }
- const firebase$1 = createFirebaseNamespace();
-
- /**
- * @license
- * Copyright 2019 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- const logger = new Logger('@firebase/app-compat');
-
- const name = "@firebase/app-compat";
- const version = "0.2.1";
-
- /**
- * @license
- * Copyright 2019 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- function registerCoreComponents(variant) {
- // Register `app` package.
- registerVersion(name, version, variant);
- }
-
- /**
- * @license
- * Copyright 2020 Google LLC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- // Firebase Lite detection
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- if (isBrowser() && self.firebase !== undefined) {
- logger.warn(`
- Warning: Firebase is already defined in the global scope. Please make sure
- Firebase library is only loaded once.
- `);
- // eslint-disable-next-line
- const sdkVersion = self.firebase.SDK_VERSION;
- if (sdkVersion && sdkVersion.indexOf('LITE') >= 0) {
- logger.warn(`
- Warning: You are trying to load Firebase while using Firebase Performance standalone script.
- You should load Firebase Performance with this instance of Firebase to avoid loading duplicate code.
- `);
- }
- }
- const firebase = firebase$1;
- registerCoreComponents();
-
- export { firebase as default };
- //# sourceMappingURL=index.esm2017.js.map
|