1
1
import { InjectionToken , NgZone , NgModule , Optional } from '@angular/core' ;
2
+ import { app , auth , apps , database , firestore , functions , initializeApp , messaging , storage } from 'firebase/app' ;
2
3
3
- import { FirebaseOptionsToken , FirebaseNameOrConfigToken } from './angularfire2' ;
4
+ // Public types don't expose FirebaseOptions or FirebaseAppConfig
5
+ export type FirebaseOptions = { [ key :string ] : any } ;
6
+ export type FirebaseAppConfig = { [ key :string ] : any } ;
4
7
5
- import firebase from '@firebase/app' ;
6
- import { FirebaseApp as _FirebaseApp , FirebaseOptions , FirebaseAppConfig } from '@firebase/app-types' ;
7
- import { FirebaseAuth } from '@firebase/auth-types' ;
8
- import { FirebaseDatabase } from '@firebase/database-types' ;
9
- import { FirebaseMessaging } from '@firebase/messaging-types' ;
10
- import { FirebaseStorage } from '@firebase/storage-types' ;
11
- import { FirebaseFirestore } from '@firebase/firestore-types' ;
12
- import { FirebaseFunctions } from '@firebase/functions-types' ;
8
+ export const FirebaseOptionsToken = new InjectionToken < FirebaseOptions > ( 'angularfire2.app.options' ) ;
9
+ export const FirebaseNameOrConfigToken = new InjectionToken < string | FirebaseAppConfig | undefined > ( 'angularfire2.app.nameOrConfig' )
13
10
14
- export class FirebaseApp implements _FirebaseApp {
11
+ export type FirebaseDatabase = database . Database ;
12
+ export type FirebaseAuth = auth . Auth ;
13
+ export type FirebaseMessaging = messaging . Messaging ;
14
+ export type FirebaseStorage = storage . Storage ;
15
+ export type FirebaseFirestore = firestore . Firestore ;
16
+ export type FirebaseFunctions = functions . Functions ;
17
+
18
+ export class FirebaseApp implements app . App {
15
19
name : string ;
16
- automaticDataCollectionEnabled : boolean ;
17
20
options : { } ;
18
21
auth : ( ) => FirebaseAuth ;
22
+ // app.App database() doesn't take a databaseURL arg in the public types?
19
23
database : ( databaseURL ?: string ) => FirebaseDatabase ;
24
+ // automaticDataCollectionEnabled is now private? _automaticDataCollectionEnabled?
25
+ // automaticDataCollectionEnabled: true,
20
26
messaging : ( ) => FirebaseMessaging ;
21
27
storage : ( storageBucket ?: string ) => FirebaseStorage ;
22
28
delete : ( ) => Promise < void > ;
@@ -28,8 +34,9 @@ export function _firebaseAppFactory(options: FirebaseOptions, nameOrConfig?: str
28
34
const name = typeof nameOrConfig === 'string' && nameOrConfig || '[DEFAULT]' ;
29
35
const config = typeof nameOrConfig === 'object' && nameOrConfig || { } ;
30
36
config . name = config . name || name ;
31
- const existingApp = firebase . apps . filter ( app => app . name === config . name ) [ 0 ] ;
32
- return ( existingApp || firebase . initializeApp ( options , config ) ) as FirebaseApp ;
37
+ const existingApp = apps . filter ( app => app && app . name === config . name ) [ 0 ] ;
38
+ // We support FirebaseConfig, initializeApp's public type only accepts string; need to cast as any
39
+ return ( existingApp || ( initializeApp as any ) ( options , config ) ) as FirebaseApp ;
33
40
}
34
41
35
42
const FirebaseAppProvider = {
0 commit comments