1
1
import {
2
2
Inject , InjectionToken , isDevMode , ModuleWithProviders , NgModule , NgZone , Optional , PLATFORM_ID , VERSION as NG_VERSION , Version
3
3
} from '@angular/core' ;
4
- import firebase from 'firebase/app' ;
4
+ import { FirebaseApp as FirebaseAppType , getApps , initializeApp , registerVersion } from 'firebase/app' ;
5
+ import { Analytics } from 'firebase/analytics' ;
6
+ import { Database } from 'firebase/database' ;
7
+ import { Auth } from 'firebase/auth' ;
8
+ import { FirebaseMessaging } from 'firebase/messaging' ;
9
+ import { FirebasePerformance } from 'firebase/performance' ;
10
+ import { StorageService } from 'firebase/storage' ;
11
+ import { FirebaseFirestore } from 'firebase/firestore' ;
12
+ import { Functions } from 'firebase/functions' ;
13
+ import { RemoteConfig } from 'firebase/remote-config' ;
5
14
6
15
// INVESTIGATE Public types don't expose FirebaseOptions or FirebaseAppConfig, is this the case anylonger?
7
16
export interface FirebaseOptions {
@@ -17,19 +26,19 @@ export const FIREBASE_APP_NAME = new InjectionToken<string | FirebaseAppConfig |
17
26
18
27
// Have to implement as we need to return a class from the provider, we should consider exporting
19
28
// this in the firebase/app types as this is our highest risk of breaks
20
- export class FirebaseApp implements Partial < firebase . app . App > {
29
+ export class FirebaseApp implements Partial < FirebaseAppType > {
21
30
name : string ;
22
31
options : { } ;
23
- analytics : ( ) => firebase . analytics . Analytics ;
24
- auth : ( ) => firebase . auth . Auth ;
25
- database : ( databaseURL ?: string ) => firebase . database . Database ;
26
- messaging : ( ) => firebase . messaging . Messaging ;
27
- performance : ( ) => firebase . performance . Performance ;
28
- storage : ( storageBucket ?: string ) => firebase . storage . Storage ;
32
+ analytics : ( ) => Analytics ;
33
+ auth : ( ) => Auth ;
34
+ database : ( databaseURL ?: string ) => Database ;
35
+ messaging : ( ) => FirebaseMessaging ;
36
+ performance : ( ) => FirebasePerformance ;
37
+ storage : ( storageBucket ?: string ) => StorageService ;
29
38
delete : ( ) => Promise < void > ;
30
- firestore : ( ) => firebase . firestore . Firestore ;
31
- functions : ( region ?: string ) => firebase . functions . Functions ;
32
- remoteConfig : ( ) => firebase . remoteConfig . RemoteConfig ;
39
+ firestore : ( ) => FirebaseFirestore ;
40
+ functions : ( region ?: string ) => Functions ;
41
+ remoteConfig : ( ) => RemoteConfig ;
33
42
}
34
43
35
44
export const VERSION = new Version ( 'ANGULARFIRE2_VERSION' ) ;
@@ -39,10 +48,10 @@ export function ɵfirebaseAppFactory(options: FirebaseOptions, zone: NgZone, nam
39
48
const config = typeof nameOrConfig === 'object' && nameOrConfig || { } ;
40
49
config . name = config . name || name ;
41
50
// Added any due to some inconsistency between @firebase /app and firebase types
42
- const existingApp = firebase . apps . filter ( app => app && app . name === config . name ) [ 0 ] as any ;
51
+ const existingApp = getApps ( ) . filter ( app => app && app . name === config . name ) [ 0 ] as any ;
43
52
// We support FirebaseConfig, initializeApp's public type only accepts string; need to cast as any
44
53
// Could be solved with https://github.com/firebase/firebase-js-sdk/pull/1206
45
- const app = ( existingApp || zone . runOutsideAngular ( ( ) => firebase . initializeApp ( options , config as any ) ) ) as FirebaseApp ;
54
+ const app = ( existingApp || zone . runOutsideAngular ( ( ) => initializeApp ( options , config as any ) ) ) as FirebaseApp ;
46
55
try {
47
56
if ( JSON . stringify ( options ) !== JSON . stringify ( app . options ) ) {
48
57
const hmr = ! ! ( module as any ) . hot ;
@@ -115,7 +124,7 @@ export class AngularFireModule {
115
124
116
125
// tslint:disable-next-line:ban-types
117
126
constructor ( @Inject ( PLATFORM_ID ) platformId : Object ) {
118
- firebase . registerVersion ( 'angularfire' , VERSION . full , platformId . toString ( ) ) ;
119
- firebase . registerVersion ( 'angular' , NG_VERSION . full ) ;
127
+ registerVersion ( 'angularfire' , VERSION . full , platformId . toString ( ) ) ;
128
+ registerVersion ( 'angular' , NG_VERSION . full ) ;
120
129
}
121
130
}
0 commit comments