{"version":3,"file":"angular-fire-app.mjs","sources":["../../../src/app/app.ts","../../../src/app/app.module.ts","../../../src/app/firebase.ts","../../../src/app/angular-fire-app.ts"],"sourcesContent":["import { FirebaseApp as IFirebaseApp, getApps } from 'firebase/app';\nimport { from, timer } from 'rxjs';\nimport { concatMap, distinct } from 'rxjs/operators';\n\n// Need to turn the FirebaseApp interface exported by firebase/app into a class\n// as types don't work in Angular DI. We want developers to be able to inject FirebaseApp like so\n//   constructor(app: FirebaseApp)\n// the cleanest way to achieve this that I found is to export a new interface and class\n// the interface just extends the interface you want to turn into the class. This informs tyepscript\n// that the class has all the same methods/properties as the interface you want to extend without\n// breaking if Firebase adds/removes APIs in future releases. This was a big problem for @angular/fire\n// back when we constructed our own class. Then in the \"new class\" we just return the FirebaseApp in the\n// constructor, this also has the added benefit of Firebase methods taking our DI class without\n// casting. E.g,\n//   constructor(private app: FirebaseApp) { }\n//   ngOnDestroy() { deleteApp(this.app); }\n//\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface FirebaseApp extends IFirebaseApp {}\n\nexport class FirebaseApp {\n  constructor(app: IFirebaseApp) {\n    return app;\n  }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface FirebaseApps extends Array<IFirebaseApp> {}\n\nexport class FirebaseApps {\n  constructor() {\n    return getApps();\n  }\n}\n\nexport const firebaseApp$ = timer(0, 300).pipe(\n  concatMap(() => from(getApps())),\n  distinct(),\n);\n","import {\n  EnvironmentProviders,\n  Inject,\n  InjectionToken,\n  Injector,\n  VERSION as NG_VERSION,\n  NgModule,\n  NgZone,\n  Optional,\n  PLATFORM_ID,\n  makeEnvironmentProviders,\n} from '@angular/core';\nimport { VERSION, ɵAngularFireSchedulers } from '@angular/fire';\nimport { FirebaseApp as IFirebaseApp, getApp, registerVersion } from 'firebase/app';\nimport { FirebaseApp, FirebaseApps } from './app';\n\nexport function defaultFirebaseAppFactory(provided: FirebaseApp[]|undefined) {\n  // Use the provided app, if there is only one, otherwise fetch the default app\n  if (provided && provided.length === 1) { return provided[0]; }\n  return new FirebaseApp(getApp());\n}\n\n// With FIREBASE_APPS I wanted to capture the default app instance, if it is initialized by\n// the reserved URL; ɵPROVIDED_FIREBASE_APPS is not for public consumption and serves to ensure that all\n// provideFirebaseApp(...) calls are satisfied before FirebaseApp$ or FirebaseApp is resolved\nexport const PROVIDED_FIREBASE_APPS = new InjectionToken<FirebaseApp[]>('angularfire2._apps');\n\n// Injecting FirebaseApp will now only inject the default Firebase App\n// this allows allows beginners to import /__/firebase/init.js to auto initialize Firebase App\n// from the reserved URL.\nconst DEFAULT_FIREBASE_APP_PROVIDER = {\n  provide: FirebaseApp,\n  useFactory: defaultFirebaseAppFactory,\n  deps: [\n    [new Optional(), PROVIDED_FIREBASE_APPS ],\n  ],\n};\n\nconst FIREBASE_APPS_PROVIDER = {\n  provide: FirebaseApps,\n  deps: [\n    [new Optional(), PROVIDED_FIREBASE_APPS ],\n  ],\n};\n\nexport function firebaseAppFactory(fn: (injector: Injector) => IFirebaseApp) {\n  return (zone: NgZone, injector: Injector) => {\n    const platformId = injector.get(PLATFORM_ID);\n    registerVersion('angularfire', VERSION.full, 'core');\n    registerVersion('angularfire', VERSION.full, 'app');\n    // eslint-disable-next-line @typescript-eslint/no-base-to-string\n    registerVersion('angular', NG_VERSION.full, platformId.toString());\n\n    const app = zone.runOutsideAngular(() => fn(injector));\n    return new FirebaseApp(app);\n  };\n}\n\n@NgModule({\n  providers: [\n    DEFAULT_FIREBASE_APP_PROVIDER,\n    FIREBASE_APPS_PROVIDER,\n  ]\n})\nexport class FirebaseAppModule {\n  // eslint-disable-next-line @typescript-eslint/ban-types\n  constructor(@Inject(PLATFORM_ID) platformId: Object) {\n    registerVersion('angularfire', VERSION.full, 'core');\n    registerVersion('angularfire', VERSION.full, 'app');\n    // eslint-disable-next-line @typescript-eslint/no-base-to-string\n    registerVersion('angular', NG_VERSION.full, platformId.toString());\n  }\n}\n\n// Calling initializeApp({ ... }, 'name') multiple times will add more FirebaseApps into the FIREBASE_APPS\n// injection scope. This allows developers to more easily work with multiple Firebase Applications. Downside\n// is that DI for app name and options doesn't really make sense anymore.\nexport function provideFirebaseApp(fn: (injector: Injector) => IFirebaseApp, ...deps: any[]): EnvironmentProviders {\n  return makeEnvironmentProviders([\n    DEFAULT_FIREBASE_APP_PROVIDER,\n    FIREBASE_APPS_PROVIDER,\n    {\n      provide: PROVIDED_FIREBASE_APPS,\n      useFactory: firebaseAppFactory(fn),\n      multi: true,\n      deps: [\n        NgZone,\n        Injector,\n        ɵAngularFireSchedulers,\n        ...deps,\n      ],\n    }\n  ])\n}\n","// DO NOT MODIFY, this file is autogenerated by tools/build.ts\nexport * from 'firebase/app';\nimport { ɵzoneWrap } from '@angular/fire';\nimport {\n  deleteApp as _deleteApp,\n  getApp as _getApp,\n  getApps as _getApps,\n  initializeApp as _initializeApp,\n  initializeServerApp as _initializeServerApp,\n  onLog as _onLog,\n  registerVersion as _registerVersion,\n  setLogLevel as _setLogLevel\n} from 'firebase/app';\n\nexport const deleteApp = ɵzoneWrap(_deleteApp, true);\nexport const getApp = ɵzoneWrap(_getApp, true);\nexport const getApps = ɵzoneWrap(_getApps, true);\nexport const initializeApp = ɵzoneWrap(_initializeApp, true);\nexport const initializeServerApp = ɵzoneWrap(_initializeServerApp, true);\nexport const onLog = ɵzoneWrap(_onLog, true);\nexport const registerVersion = ɵzoneWrap(_registerVersion, true);\nexport const setLogLevel = ɵzoneWrap(_setLogLevel, true);\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":["getApps","getApp","registerVersion","NG_VERSION","ɵAngularFireSchedulers","ɵzoneWrap","_deleteApp","_getApp","_getApps","_initializeApp","_initializeServerApp","_onLog","_registerVersion","_setLogLevel"],"mappings":";;;;;;;;MAoBa,WAAW,CAAA;AACtB,IAAA,WAAA,CAAY,GAAiB,EAAA;AAC3B,QAAA,OAAO,GAAG;;AAEb;MAKY,YAAY,CAAA;AACvB,IAAA,W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