diff --git a/src/auth/auth.ts b/src/auth/auth.ts index 092bfcfe1..b36d2361f 100644 --- a/src/auth/auth.ts +++ b/src/auth/auth.ts @@ -37,7 +37,7 @@ export class AngularFireAuth { const scheduler = new FirebaseZoneScheduler(zone, platformId); this.auth = zone.runOutsideAngular(() => { const app = _firebaseAppFactory(options, name, config); - return app.auth(); + return app.auth!(); }); this.authState = scheduler.keepUnstableUntilFirst( diff --git a/src/core/firebase.app.module.ts b/src/core/firebase.app.module.ts index 3a3e1afee..51fdf5883 100644 --- a/src/core/firebase.app.module.ts +++ b/src/core/firebase.app.module.ts @@ -1,26 +1,9 @@ import { InjectionToken, NgZone, NgModule } from '@angular/core'; - import { FirebaseOptionsToken, FirebaseAppNameToken, FirebaseAppConfigToken } from './angularfire2'; - import firebase from '@firebase/app'; import { FirebaseApp as _FirebaseApp, FirebaseOptions, FirebaseAppConfig } from '@firebase/app-types'; -import { FirebaseAuth } from '@firebase/auth-types'; -import { FirebaseDatabase } from '@firebase/database-types'; -import { FirebaseMessaging } from '@firebase/messaging-types'; -import { FirebaseStorage } from '@firebase/storage-types'; -import { FirebaseFirestore } from '@firebase/firestore-types'; -export class FirebaseApp implements _FirebaseApp { - name: string; - automaticDataCollectionEnabled: boolean; - options: {}; - auth: () => FirebaseAuth; - database: (databaseURL?: string) => FirebaseDatabase; - messaging: () => FirebaseMessaging; - storage: (storageBucket?: string) => FirebaseStorage; - delete: () => Promise<void>; - firestore: () => FirebaseFirestore; -} +export class FirebaseApp extends _FirebaseApp { } export function _firebaseAppFactory(options: FirebaseOptions, name?: string, appConfig?: FirebaseAppConfig): FirebaseApp { const config = appConfig || {}; diff --git a/src/database-deprecated/database.ts b/src/database-deprecated/database.ts index 7abfd8c33..486033a47 100644 --- a/src/database-deprecated/database.ts +++ b/src/database-deprecated/database.ts @@ -26,7 +26,7 @@ export class AngularFireDatabase { ) { this.database = zone.runOutsideAngular(() => { const app = _firebaseAppFactory(config, name); - return app.database(databaseURL || undefined); + return app.database!(databaseURL || undefined); }); } diff --git a/src/database-deprecated/firebase_list_factory.spec.ts b/src/database-deprecated/firebase_list_factory.spec.ts index 2fab28383..80460391f 100644 --- a/src/database-deprecated/firebase_list_factory.spec.ts +++ b/src/database-deprecated/firebase_list_factory.spec.ts @@ -88,7 +88,7 @@ describe('FirebaseListFactory', () => { describe('<constructor>', () => { it('should accept a Firebase db ref in the constructor', () => { - const list = FirebaseListFactory(app.database().ref(`questions`)); + const list = FirebaseListFactory(app.database!().ref(`questions`)); expect(list instanceof FirebaseListObservable).toBe(true); }); @@ -108,7 +108,7 @@ describe('FirebaseListFactory', () => { it('equalTo - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(app.database().ref(questionsPath), { + const observable = FirebaseListFactory(app.database!().ref(questionsPath), { query: { orderByChild: 'height', equalTo: subject @@ -121,7 +121,7 @@ describe('FirebaseListFactory', () => { it('startAt - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(app.database().ref(questionsPath), { + const observable = FirebaseListFactory(app.database!().ref(questionsPath), { query: { orderByChild: 'height', startAt: subject @@ -134,7 +134,7 @@ describe('FirebaseListFactory', () => { it('endAt - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(app.database().ref(questionsPath), { + const observable = FirebaseListFactory(app.database!().ref(questionsPath), { query: { orderByChild: 'height', endAt: subject @@ -146,7 +146,7 @@ describe('FirebaseListFactory', () => { it('should throw an error if limitToLast and limitToFirst are chained', () => { - const observable = FirebaseListFactory(app.database().ref(questionsPath), { + const observable = FirebaseListFactory(app.database!().ref(questionsPath), { query: { orderByChild: 'height', limitToFirst: 10, @@ -158,7 +158,7 @@ describe('FirebaseListFactory', () => { it('should throw an error if startAt is used with equalTo', () => { - const observable = FirebaseListFactory(app.database().ref(questionsPath), { + const observable = FirebaseListFactory(app.database!().ref(questionsPath), { query: { orderByChild: 'height', equalTo: 10, @@ -170,7 +170,7 @@ describe('FirebaseListFactory', () => { it('should throw an error if endAt is used with equalTo', () => { - const observable = FirebaseListFactory(app.database().ref(questionsPath), { + const observable = FirebaseListFactory(app.database!().ref(questionsPath), { query: { orderByChild: 'height', equalTo: 10, @@ -182,7 +182,7 @@ describe('FirebaseListFactory', () => { it('should throw an error if startAt and endAt is used with equalTo', () => { - const observable = FirebaseListFactory(app.database().ref(questionsPath), { + const observable = FirebaseListFactory(app.database!().ref(questionsPath), { query: { orderByChild: 'height', equalTo: 10, @@ -207,7 +207,7 @@ describe('FirebaseListFactory', () => { it('equalTo - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(app.database().ref(questionsPath), { + const observable = FirebaseListFactory(app.database!().ref(questionsPath), { query: { orderByValue: true, equalTo: subject @@ -220,7 +220,7 @@ describe('FirebaseListFactory', () => { it('startAt - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(app.database().ref(questionsPath), { + const observable = FirebaseListFactory(app.database!().ref(questionsPath), { query: { orderByValue: true, startAt: subject @@ -233,7 +233,7 @@ describe('FirebaseListFactory', () => { it('endAt - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(app.database().ref(questionsPath), { + const observable = FirebaseListFactory(app.database!().ref(questionsPath), { query: { orderByValue: true, endAt: subject @@ -257,7 +257,7 @@ describe('FirebaseListFactory', () => { it('equalTo - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(app.database().ref(questionsPath), { + const observable = FirebaseListFactory(app.database!().ref(questionsPath), { query: { orderByKey: true, equalTo: subject @@ -270,7 +270,7 @@ describe('FirebaseListFactory', () => { it('startAt - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(app.database().ref(questionsPath), { + const observable = FirebaseListFactory(app.database!().ref(questionsPath), { query: { orderByKey: true, startAt: subject @@ -283,7 +283,7 @@ describe('FirebaseListFactory', () => { it('endAt - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(app.database().ref(questionsPath), { + const observable = FirebaseListFactory(app.database!().ref(questionsPath), { query: { orderByKey: true, endAt: subject @@ -306,7 +306,7 @@ describe('FirebaseListFactory', () => { it('equalTo - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(app.database().ref(questionsPath), { + const observable = FirebaseListFactory(app.database!().ref(questionsPath), { query: { orderByKey: true, equalTo: subject @@ -319,7 +319,7 @@ describe('FirebaseListFactory', () => { it('startAt - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(app.database().ref(questionsPath), { + const observable = FirebaseListFactory(app.database!().ref(questionsPath), { query: { orderByKey: true, startAt: subject @@ -332,7 +332,7 @@ describe('FirebaseListFactory', () => { it('endAt - should re-run a query when the observable value has emitted', (done: any) => { const subject = new Subject(); - const observable = FirebaseListFactory(app.database().ref(questionsPath), { + const observable = FirebaseListFactory(app.database!().ref(questionsPath), { query: { orderByKey: true, endAt: subject @@ -348,7 +348,7 @@ describe('FirebaseListFactory', () => { describe('shape', () => { it('should have a a FirebaseListObservable shape when queried', () => { - const observable = FirebaseListFactory(app.database().ref(questionsPath), { + const observable = FirebaseListFactory(app.database!().ref(questionsPath), { query: { orderByChild: 'height', equalTo: '1' @@ -378,9 +378,9 @@ describe('FirebaseListFactory', () => { val1 = { key: 'key1' }; val2 = { key: 'key2' }; val3 = { key: 'key3' }; - app.database().ref().remove(done); - questions = FirebaseListFactory(app.database().ref(`questions`)); - questionsSnapshotted = FirebaseListFactory(app.database().ref(`questionssnapshot`), { preserveSnapshot: true }); + app.database!().ref().remove(done); + questions = FirebaseListFactory(app.database!().ref(`questions`)); + questionsSnapshotted = FirebaseListFactory(app.database!().ref(`questionssnapshot`), { preserveSnapshot: true }); ref = questions.$ref; refSnapshotted = questionsSnapshotted.$ref; }); @@ -576,7 +576,7 @@ describe('FirebaseListFactory', () => { it('should call off on all events when disposed', (done: any) => { - const questionRef = app.database().ref().child('questions'); + const questionRef = app.database!().ref().child('questions'); subscription = FirebaseListFactory(questionRef).subscribe(_ => { let firebaseSpy = spyOn(questionRef, 'off').and.callThrough(); expect(firebaseSpy).not.toHaveBeenCalled(); @@ -682,7 +682,7 @@ describe('FirebaseListFactory', () => { }) .run(() => { // Creating a new observable so that the current zone is captured. - subscription = FirebaseListFactory(app.database().ref(`questions`)) + subscription = FirebaseListFactory(app.database!().ref(`questions`)) .filter(d => d .map((v: any) => v.$value) .indexOf('in-the-zone') > -1) @@ -745,7 +745,7 @@ describe('FirebaseListFactory', () => { }) .then(() => { - let query1 = FirebaseListFactory(app.database().ref(`questions`), { + let query1 = FirebaseListFactory(app.database!().ref(`questions`), { query: { orderByChild: 'data', startAt: { value: 0 } @@ -753,7 +753,7 @@ describe('FirebaseListFactory', () => { }); let promise1 = toPromise.call(take.call(query1, 1)); - let query2 = FirebaseListFactory(app.database().ref(`questions`), { + let query2 = FirebaseListFactory(app.database!().ref(`questions`), { query: { orderByChild: 'data', startAt: { value: 0, key: 'val2' } @@ -783,7 +783,7 @@ describe('FirebaseListFactory', () => { }) .then(() => { - let query1 = FirebaseListFactory(app.database().ref(`questions`), { + let query1 = FirebaseListFactory(app.database!().ref(`questions`), { query: { orderByChild: 'data', equalTo: { value: 0 } @@ -791,7 +791,7 @@ describe('FirebaseListFactory', () => { }); let promise1 = toPromise.call(take.call(query1, 1)); - let query2 = FirebaseListFactory(app.database().ref(`questions`), { + let query2 = FirebaseListFactory(app.database!().ref(`questions`), { query: { orderByChild: 'data', equalTo: { value: 0, key: 'val2' } @@ -821,7 +821,7 @@ describe('FirebaseListFactory', () => { }) .then(() => { - let query1 = FirebaseListFactory(app.database().ref(`questions`), { + let query1 = FirebaseListFactory(app.database!().ref(`questions`), { query: { orderByChild: 'data', endAt: { value: 0 } @@ -829,7 +829,7 @@ describe('FirebaseListFactory', () => { }); let promise1 = toPromise.call(take.call(query1, 1)); - let query2 = FirebaseListFactory(app.database().ref(`questions`), { + let query2 = FirebaseListFactory(app.database!().ref(`questions`), { query: { orderByChild: 'data', endAt: { value: 0, key: 'val2' } @@ -859,7 +859,7 @@ describe('FirebaseListFactory', () => { .then(() => { let subject = new Subject<boolean>(); - let query = FirebaseListFactory(app.database().ref(`questions`), { + let query = FirebaseListFactory(app.database!().ref(`questions`), { query: { orderByChild: 'even', equalTo: subject diff --git a/src/database-deprecated/firebase_list_observable.spec.ts b/src/database-deprecated/firebase_list_observable.spec.ts index 29b32fa48..4c5862089 100644 --- a/src/database-deprecated/firebase_list_observable.spec.ts +++ b/src/database-deprecated/firebase_list_observable.spec.ts @@ -25,7 +25,7 @@ describe('FirebaseListObservable', () => { inject([FirebaseApp, AngularFireDatabase], (_app: FBApp, _db: AngularFireDatabase) => { app = _app; db = _db; - ref = app.database().ref(); + ref = app.database!().ref(); O = new FirebaseListObservable(ref, (observer:Observer<any>) => { }); })(); diff --git a/src/database-deprecated/firebase_object_factory.spec.ts b/src/database-deprecated/firebase_object_factory.spec.ts index cf056d688..6f13a629c 100644 --- a/src/database-deprecated/firebase_object_factory.spec.ts +++ b/src/database-deprecated/firebase_object_factory.spec.ts @@ -35,7 +35,7 @@ describe('FirebaseObjectFactory', () => { describe('<constructor>', () => { it('should accept a Firebase db ref in the constructor', () => { - const object = FirebaseObjectFactory(app.database().ref().child(`questions`)); + const object = FirebaseObjectFactory(app.database!().ref().child(`questions`)); expect(object instanceof FirebaseObjectObservable).toBe(true); }); @@ -45,9 +45,9 @@ describe('FirebaseObjectFactory', () => { beforeEach((done: any) => { i = Date.now(); - ref = app.database().ref().child(`questions/${i}`); + ref = app.database!().ref().child(`questions/${i}`); nextSpy = nextSpy = jasmine.createSpy('next'); - observable = FirebaseObjectFactory(app.database().ref(`questions/${i}`)); + observable = FirebaseObjectFactory(app.database!().ref(`questions/${i}`)); ref.remove(done); }); @@ -105,7 +105,7 @@ describe('FirebaseObjectFactory', () => { }); it('should emit snapshots if preserveSnapshot option is true', (done: any) => { - observable = FirebaseObjectFactory(app.database().ref(`questions/${i}`), { preserveSnapshot: true }); + observable = FirebaseObjectFactory(app.database!().ref(`questions/${i}`), { preserveSnapshot: true }); ref.remove(() => { ref.set('preserved snapshot!', () => { subscription = observable.subscribe(data => { @@ -118,7 +118,7 @@ describe('FirebaseObjectFactory', () => { it('should call off on all events when disposed', () => { - const dbRef = app.database().ref(); + const dbRef = app.database!().ref(); let firebaseSpy = spyOn(dbRef, 'off'); subscription = FirebaseObjectFactory(dbRef).subscribe(); expect(firebaseSpy).not.toHaveBeenCalled(); @@ -132,7 +132,7 @@ describe('FirebaseObjectFactory', () => { }) .run(() => { // Creating a new observable so that the current zone is captured. - subscription = FirebaseObjectFactory(app.database().ref(`questions/${i}`)) + subscription = FirebaseObjectFactory(app.database!().ref(`questions/${i}`)) .filter(d => d.$value === 'in-the-zone') .subscribe(data => { expect(Zone.current.name).toBe('newZone'); diff --git a/src/database-deprecated/firebase_object_observable.spec.ts b/src/database-deprecated/firebase_object_observable.spec.ts index cd33163ce..1157067b9 100644 --- a/src/database-deprecated/firebase_object_observable.spec.ts +++ b/src/database-deprecated/firebase_object_observable.spec.ts @@ -24,7 +24,7 @@ describe('FirebaseObjectObservable', () => { inject([FirebaseApp, AngularFireDatabase], (_app: FBApp, _db: AngularFireDatabase) => { app = _app; db = _db; - ref = app.database().ref(); + ref = app.database!().ref(); O = new FirebaseObjectObservable((observer: Observer<any>) => { }, ref); })(); diff --git a/src/database/database.ts b/src/database/database.ts index 665023b7b..a77a0f706 100644 --- a/src/database/database.ts +++ b/src/database/database.ts @@ -24,7 +24,7 @@ export class AngularFireDatabase { this.scheduler = new FirebaseZoneScheduler(zone, platformId); this.database = zone.runOutsideAngular(() => { const app = _firebaseAppFactory(options, name, config); - return app.database(databaseURL || undefined); + return app.database!(databaseURL || undefined); }); } diff --git a/src/database/list/audit-trail.spec.ts b/src/database/list/audit-trail.spec.ts index 2c334cfe0..7448cf047 100644 --- a/src/database/list/audit-trail.spec.ts +++ b/src/database/list/audit-trail.spec.ts @@ -32,8 +32,8 @@ describe('auditTrail', () => { inject([FirebaseApp, AngularFireDatabase], (app_: FirebaseApp, _db: AngularFireDatabase) => { app = app_; db = _db; - app.database().goOffline(); - createRef = (path: string) => { app.database().goOffline(); return app.database().ref(path); }; + app.database!().goOffline(); + createRef = (path: string) => { app.database!().goOffline(); return app.database!().ref(path); }; })(); }); diff --git a/src/database/list/changes.spec.ts b/src/database/list/changes.spec.ts index 58116ebac..de2e07cc1 100644 --- a/src/database/list/changes.spec.ts +++ b/src/database/list/changes.spec.ts @@ -32,8 +32,8 @@ describe('listChanges', () => { inject([FirebaseApp, AngularFireDatabase], (app_: FirebaseApp, _db: AngularFireDatabase) => { app = app_; db = _db; - app.database().goOffline(); - ref = (path: string) => { app.database().goOffline(); return app.database().ref(path); }; + app.database!().goOffline(); + ref = (path: string) => { app.database!().goOffline(); return app.database!().ref(path); }; })(); }); @@ -109,7 +109,7 @@ describe('listChanges', () => { const data = changes.map(change => change.payload.val()); expect(data.length).toEqual(items.length - 1); }).add(done); - app.database().goOnline(); + app.database!().goOnline(); aref.set(batch).then(() => { aref.child(items[0].key).remove(); }); @@ -122,7 +122,7 @@ describe('listChanges', () => { const data = changes.map(change => change.payload.val()); expect(data[1].name).toEqual('lol'); }).add(done); - app.database().goOnline(); + app.database!().goOnline(); aref.set(batch).then(() => { aref.child(items[1].key).update({ name: 'lol'}); }); @@ -137,7 +137,7 @@ describe('listChanges', () => { // the new result is now the last result expect(data[data.length - 1]).toEqual(items[0]); }).add(done); - app.database().goOnline(); + app.database!().goOnline(); aref.set(batch).then(() => { aref.child(items[0].key).setPriority('a', () => {}); }); diff --git a/src/database/list/snapshot-changes.spec.ts b/src/database/list/snapshot-changes.spec.ts index 514c1e936..0f489799a 100644 --- a/src/database/list/snapshot-changes.spec.ts +++ b/src/database/list/snapshot-changes.spec.ts @@ -33,8 +33,8 @@ describe('snapshotChanges', () => { inject([FirebaseApp, AngularFireDatabase], (app_: FirebaseApp, _db: AngularFireDatabase) => { app = app_; db = _db; - app.database().goOffline(); - createRef = (path: string) => { app.database().goOffline(); return app.database().ref(path); }; + app.database!().goOffline(); + createRef = (path: string) => { app.database!().goOffline(); return app.database!().ref(path); }; })(); }); @@ -103,7 +103,7 @@ describe('snapshotChanges', () => { copy[0].name = name; expect(data).toEqual(copy); }).add(done); - app.database().goOnline(); + app.database!().goOnline(); ref.set(batch).then(() => { ref.child(items[0].key).update({ name }) }); diff --git a/src/database/list/state-changes.spec.ts b/src/database/list/state-changes.spec.ts index d42e0a4ca..458fb9af8 100644 --- a/src/database/list/state-changes.spec.ts +++ b/src/database/list/state-changes.spec.ts @@ -32,8 +32,8 @@ describe('stateChanges', () => { inject([FirebaseApp, AngularFireDatabase], (app_: FirebaseApp, _db: AngularFireDatabase) => { app = app_; db = _db; - app.database().goOffline(); - createRef = (path: string) => { app.database().goOffline(); return app.database().ref(path); }; + app.database!().goOffline(); + createRef = (path: string) => { app.database!().goOffline(); return app.database!().ref(path); }; })(); }); diff --git a/src/database/observable/fromRef.spec.ts b/src/database/observable/fromRef.spec.ts index 44efe5236..e3d0c0e9f 100644 --- a/src/database/observable/fromRef.spec.ts +++ b/src/database/observable/fromRef.spec.ts @@ -30,8 +30,8 @@ describe('fromRef', () => { }); inject([FirebaseApp], (app_: FirebaseApp) => { app = app_; - app.database().goOffline(); - ref = (path: string) => { app.database().goOffline(); return app.database().ref(path); }; + app.database!().goOffline(); + ref = (path: string) => { app.database!().goOffline(); return app.database!().ref(path); }; })(); }); diff --git a/src/firestore/firestore.ts b/src/firestore/firestore.ts index 83476f107..657c5e573 100644 --- a/src/firestore/firestore.ts +++ b/src/firestore/firestore.ts @@ -119,7 +119,7 @@ export class AngularFirestore { this.scheduler = new FirebaseZoneScheduler(zone, platformId); this.firestore = zone.runOutsideAngular(() => { const app = _firebaseAppFactory(config, name); - const firestore = app.firestore(); + const firestore = app.firestore!(); firestore.settings(settings || DefaultFirestoreSettings); return firestore; }); diff --git a/src/storage/storage.ts b/src/storage/storage.ts index de80842f9..09471c961 100644 --- a/src/storage/storage.ts +++ b/src/storage/storage.ts @@ -31,7 +31,7 @@ export class AngularFireStorage { this.scheduler = new FirebaseZoneScheduler(zone, platformId); this.storage = zone.runOutsideAngular(() => { const app = _firebaseAppFactory(options, name, config); - return app.storage(storageBucket || undefined); + return app.storage!(storageBucket || undefined); }); }