Skip to content

Commit 7ec51b2

Browse files
myspiveydavideast
authored andcommitted
fix(): Migrate imports to new Typings from 4.8.1 to resolve #1385
1 parent 488f197 commit 7ec51b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+319
-331
lines changed

src/auth/auth.module.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { NgModule, NgZone } from '@angular/core';
2-
import * as firebase from 'firebase/app';
3-
import 'firebase/auth';
42
import { FirebaseApp, AngularFireModule } from 'angularfire2';
53
import { AngularFireAuth } from './auth';
64

src/auth/auth.spec.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import * as firebase from 'firebase/app';
1+
import { FirebaseApp as FBApp } from '@firebase/app-types';
2+
import { User } from '@firebase/auth-types';
23
import { ReflectiveInjector, Provider } from '@angular/core';
34
import { Observable } from 'rxjs/Observable'
45
import { Subject } from 'rxjs/Subject'
@@ -19,16 +20,16 @@ function authSkip(auth: Observable<any>, count: number): Observable<any> {
1920
return skip.call(auth, 1);
2021
}
2122

22-
const firebaseUser = <firebase.User> {
23+
const firebaseUser = <User> {
2324
uid: '12345',
2425
providerData: [{ displayName: 'jeffbcrossyface' }]
2526
};
2627

2728
describe('AngularFireAuth', () => {
28-
let app: firebase.app.App;
29+
let app: FBApp;
2930
let afAuth: AngularFireAuth;
3031
let authSpy: jasmine.Spy;
31-
let mockAuthState: Subject<firebase.User>;
32+
let mockAuthState: Subject<User>;
3233

3334
beforeEach(() => {
3435
TestBed.configureTestingModule({
@@ -42,11 +43,11 @@ describe('AngularFireAuth', () => {
4243
afAuth = _auth;
4344
})();
4445

45-
mockAuthState = new Subject<firebase.User>();
46+
mockAuthState = new Subject<User>();
4647
spyOn(afAuth, 'authState').and.returnValue(mockAuthState);
4748
spyOn(afAuth, 'idToken').and.returnValue(mockAuthState);
48-
afAuth.authState = mockAuthState as Observable<firebase.User>;
49-
afAuth.idToken = mockAuthState as Observable<firebase.User>;
49+
afAuth.authState = mockAuthState as Observable<User>;
50+
afAuth.idToken = mockAuthState as Observable<User>;
5051
});
5152

5253
afterEach(done => {
@@ -104,7 +105,7 @@ describe('AngularFireAuth', () => {
104105

105106
it('should emit auth updates through idToken', (done: any) => {
106107
let count = 0;
107-
108+
108109
// Check that the first value is null and second is the auth user
109110
const subs = afAuth.idToken.subscribe(user => {
110111
if (count === 0) {

src/auth/auth.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as firebase from 'firebase/app';
2-
import 'firebase/auth';
1+
import { FirebaseAuth, User } from '@firebase/auth-types';
32
import { Injectable, NgZone } from '@angular/core';
43
import { Observable } from 'rxjs/Observable';
54
import { observeOn } from 'rxjs/operator/observeOn';
@@ -15,12 +14,12 @@ export class AngularFireAuth {
1514
/**
1615
* Firebase Auth instance
1716
*/
18-
public readonly auth: firebase.auth.Auth;
17+
public readonly auth: FirebaseAuth;
1918

2019
/**
2120
* Observable of authentication state; as of 4.0 this is only triggered via sign-in/out
2221
*/
23-
public readonly authState: Observable<firebase.User|null>;
22+
public readonly authState: Observable<User|null>;
2423

2524
/**
2625
* Observable of the signed-in user's ID token; which includes sign-in, sign-out, and token refresh events
@@ -36,7 +35,7 @@ export class AngularFireAuth {
3635
});
3736
this.authState = observeOn.call(authState$, new ZoneScheduler(Zone.current));
3837

39-
const idToken$ = new Observable<firebase.User|null>(subscriber => {
38+
const idToken$ = new Observable<User|null>(subscriber => {
4039
const unsubscribe = this.auth.onIdTokenChanged(subscriber);
4140
return { unsubscribe };
4241
}).switchMap(user => {
@@ -45,4 +44,4 @@ export class AngularFireAuth {
4544
this.idToken = observeOn.call(idToken$, new ZoneScheduler(Zone.current));
4645
}
4746

48-
}
47+
}

src/core/angularfire2.spec.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import * as firebase from 'firebase/app';
1+
2+
import { Reference } from '@firebase/database-types';
23
import { TestBed, inject, withModule, async } from '@angular/core/testing';
34
import { ReflectiveInjector, Provider, PlatformRef, NgModule, Compiler, ApplicationRef, CompilerFactory } from '@angular/core';
45
import { FirebaseApp, FirebaseAppConfig, AngularFireModule } from 'angularfire2';
@@ -9,9 +10,9 @@ import { BrowserModule } from '@angular/platform-browser';
910
describe('angularfire', () => {
1011
let subscription:Subscription;
1112
let app: FirebaseApp;
12-
let rootRef: firebase.database.Reference;
13-
let questionsRef: firebase.database.Reference;
14-
let listOfQuestionsRef: firebase.database.Reference;
13+
let rootRef: Reference;
14+
let questionsRef: Reference;
15+
let listOfQuestionsRef: Reference;
1516
let defaultPlatform: PlatformRef;
1617

1718
const APP_NAME = 'super-awesome-test-firebase-app-name';

src/core/angularfire2.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as firebase from 'firebase/app';
21
import { FirebaseAppConfigToken, FirebaseApp, _firebaseAppFactory } from './firebase.app.module';
32
import { Injectable, InjectionToken, NgModule } from '@angular/core';
43
import { Subscription } from 'rxjs/Subscription';

src/core/firebase.app.module.ts

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
import { InjectionToken, } from '@angular/core';
22
import { FirebaseAppConfig } from './';
3-
import * as firebase from 'firebase/app';
3+
import { firebase } from '@firebase/app';
4+
5+
import { FirebaseApp as FBApp } from '@firebase/app-types';
6+
import { FirebaseAuth } from '@firebase/auth-types';
7+
import { FirebaseDatabase } from '@firebase/database-types';
8+
import { FirebaseMessaging } from '@firebase/messaging-types';
9+
import { FirebaseStorage } from '@firebase/storage-types';
10+
import { FirebaseFirestore } from '@firebase/firestore-types';
411

512
export const FirebaseAppConfigToken = new InjectionToken<FirebaseAppConfig>('FirebaseAppConfigToken');
613

7-
export class FirebaseApp implements firebase.app.App {
14+
export class FirebaseApp implements FBApp {
815
name: string;
916
options: {};
10-
auth: () => firebase.auth.Auth;
11-
database: () => firebase.database.Database;
12-
messaging: () => firebase.messaging.Messaging;
13-
storage: () => firebase.storage.Storage;
17+
auth: () => FirebaseAuth;
18+
database: () => FirebaseDatabase;
19+
messaging: () => FirebaseMessaging;
20+
storage: () => FirebaseStorage;
1421
delete: () => Promise<any>;
15-
firestore: () => firebase.firestore.Firestore;
22+
firestore: () => FirebaseFirestore;
1623
}
1724

1825
export function _firebaseAppFactory(config: FirebaseAppConfig, appName?: string): FirebaseApp {

src/database-deprecated/database.module.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { NgModule } from '@angular/core';
2-
import * as firebase from 'firebase/app';
3-
import 'firebase/database';
42
import { AngularFireModule, FirebaseApp } from 'angularfire2';
53
import { AngularFireDatabase } from './database';
64

src/database-deprecated/database.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import * as firebase from 'firebase/app';
2-
import 'firebase/database';
1+
import { FirebaseDatabase } from '@firebase/database-types';
32
import { Inject, Injectable } from '@angular/core';
43
import { FirebaseAppConfigToken, FirebaseAppConfig, FirebaseApp } from 'angularfire2';
54
import { FirebaseListFactory } from './firebase_list_factory';
@@ -15,8 +14,8 @@ export class AngularFireDatabase {
1514
/**
1615
* Firebase Database instance
1716
*/
18-
database: firebase.database.Database;
19-
17+
database: FirebaseDatabase;
18+
2019
constructor(public app: FirebaseApp) {
2120
this.database = app.database();
2221
}

src/database-deprecated/firebase_list_factory.spec.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as firebase from 'firebase/app';
1+
import { DataSnapshot } from '@firebase/database-types';
22
import { FirebaseApp, FirebaseAppConfig, AngularFireModule} from 'angularfire2';
3-
import { AngularFireDatabase, AngularFireDatabaseModule, FirebaseListObservable,
4-
FirebaseListFactory, onChildAdded, onChildChanged, onChildRemoved, onChildUpdated,
5-
FirebaseObjectFactory
3+
import { AngularFireDatabase, AngularFireDatabaseModule, FirebaseListObservable,
4+
FirebaseListFactory, onChildAdded, onChildChanged, onChildRemoved, onChildUpdated,
5+
FirebaseObjectFactory
66
} from 'angularfire2/database-deprecated';
77
import { TestBed, inject } from '@angular/core/testing';
88
import * as utils from './utils';
@@ -652,15 +652,15 @@ describe('FirebaseListFactory', () => {
652652
};
653653

654654
it('should return an object value with a $key property', () => {
655-
const unwrapped = utils.unwrapMapFn(snapshot as firebase.database.DataSnapshot);
655+
const unwrapped = utils.unwrapMapFn(snapshot as DataSnapshot);
656656
expect(unwrapped.$key).toEqual(snapshot.ref.key);
657657
});
658658

659659
it('should return an object value with a $value property if value is scalar', () => {
660660
const existsFn = () => { return true; }
661-
const unwrappedValue5 = utils.unwrapMapFn(Object.assign(snapshot, { val: () => 5, exists: existsFn }) as firebase.database.DataSnapshot);
662-
const unwrappedValueFalse = utils.unwrapMapFn(Object.assign(snapshot, { val: () => false, exists: existsFn }) as firebase.database.DataSnapshot);
663-
const unwrappedValueLol = utils.unwrapMapFn(Object.assign(snapshot, { val: () => 'lol', exists: existsFn }) as firebase.database.DataSnapshot);
661+
const unwrappedValue5 = utils.unwrapMapFn(Object.assign(snapshot, { val: () => 5, exists: existsFn }) as DataSnapshot);
662+
const unwrappedValueFalse = utils.unwrapMapFn(Object.assign(snapshot, { val: () => false, exists: existsFn }) as DataSnapshot);
663+
const unwrappedValueLol = utils.unwrapMapFn(Object.assign(snapshot, { val: () => 'lol', exists: existsFn }) as DataSnapshot);
664664

665665
expect(unwrappedValue5.$key).toEqual('key');
666666
expect(unwrappedValue5.$value).toEqual(5);

src/database-deprecated/firebase_list_factory.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as firebase from 'firebase/app';
1+
import * as database from '@firebase/database-types';
22
import { ZoneScheduler } from 'angularfire2';
33
import * as utils from './utils';
44
import 'firebase/database';
@@ -92,7 +92,7 @@ export function FirebaseListFactory (
9292
}
9393

9494
return queried;
95-
}), (queryRef: firebase.database.Reference, ix: number) => {
95+
}), (queryRef: database.Reference, ix: number) => {
9696
return firebaseListObservable(queryRef, { preserveSnapshot });
9797
})
9898
.subscribe(subscriber);
@@ -108,7 +108,7 @@ export function FirebaseListFactory (
108108
* asynchonous. It creates a initial array from a promise of ref.once('value'), and then starts
109109
* listening to child events. When the initial array is loaded, the observable starts emitting values.
110110
*/
111-
function firebaseListObservable(ref: firebase.database.Reference | DatabaseQuery, {preserveSnapshot}: FirebaseListFactoryOpts = {}): FirebaseListObservable<any> {
111+
function firebaseListObservable(ref: database.Reference | DatabaseQuery, {preserveSnapshot}: FirebaseListFactoryOpts = {}): FirebaseListObservable<any> {
112112

113113
const toValue = preserveSnapshot ? (snapshot => snapshot) : utils.unwrapMapFn;
114114
const toKey = preserveSnapshot ? (value => value.key) : (value => value.$key);

0 commit comments

Comments
 (0)