Skip to content

Commit

Permalink
fix(): Switching over to firebase from @firebase/*
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdaniels committed May 22, 2018
1 parent bb1938f commit 664c2d6
Show file tree
Hide file tree
Showing 57 changed files with 224 additions and 319 deletions.
7 changes: 6 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ module.exports = function(config) {
...getAngularFiles(['core','common','compiler','platform-browser','platform-browser-dynamic']),

'karma-test-shim.js',
'node_modules/firebase/firebase.js',
'node_modules/firebase/firebase-app.js',
'node_modules/firebase/firebase-auth.js',
'node_modules/firebase/firebase-database.js',
'node_modules/firebase/firebase-firestore.js',
'node_modules/firebase/firebase-functions.js',
'node_modules/firebase/firebase-storage.js',
'dist/packages-dist/bundles/core.umd.{js,map}',
'dist/packages-dist/bundles/auth.umd.{js,map}',
'dist/packages-dist/bundles/database.umd.{js,map}',
Expand Down
15 changes: 1 addition & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,7 @@
"@angular/core": "^6.0.0",
"@angular/platform-browser": "^6.0.0",
"@angular/platform-browser-dynamic": "^6.0.0",
"@firebase/app": "^0.3.1",
"@firebase/app-types": "^0.3.1",
"@firebase/auth": "^0.5.2",
"@firebase/auth-types": "^0.3.2",
"@firebase/database": "^0.3.1",
"@firebase/database-types": "^0.3.1",
"@firebase/firestore": "^0.5.2",
"@firebase/firestore-types": "^0.4.1",
"@firebase/functions": "^0.2.2",
"@firebase/functions-types": "^0.1.2",
"@firebase/messaging-types": "^0.2.2",
"@firebase/storage": "^0.2.2",
"@firebase/storage-types": "^0.2.2",
"firebase": "^5.0.3",
"bufferutil": "^3.0.3",
"rxjs": "^6.0.0",
"utf-8-validate": "^4.0.0",
Expand All @@ -63,7 +51,6 @@
"conventional-changelog-cli": "^1.2.0",
"es6-module-loader": "^0.17.10",
"es6-shim": "^0.35.0",
"firebase": "^5.0.2",
"fs-extra": "^4.0.0",
"gulp": "^3.9.0",
"gulp-jasmine": "^2.2.1",
Expand Down
3 changes: 2 additions & 1 deletion src/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NgModule } from '@angular/core';
import { AngularFireAuth } from './auth';
import '@firebase/auth';

import 'firebase/auth';

@NgModule({
providers: [ AngularFireAuth ]
Expand Down
2 changes: 1 addition & 1 deletion src/auth/auth.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { User } from '@firebase/auth-types';
import { User } from 'firebase/app';
import { ReflectiveInjector, Provider } from '@angular/core';
import { Observable, Subject } from 'rxjs'
import { TestBed, inject } from '@angular/core/testing';
Expand Down
8 changes: 4 additions & 4 deletions src/auth/auth.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { FirebaseAuth, User, IdTokenResult } from '@firebase/auth-types';
import { FirebaseOptions, FirebaseAppConfig } from '@firebase/app-types';
import { Injectable, Inject, Optional, NgZone, PLATFORM_ID } from '@angular/core';
import { Observable, of, from } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { FirebaseAppConfig, FirebaseOptions } from 'angularfire2';

import { FirebaseOptionsToken, FirebaseNameOrConfigToken, _firebaseAppFactory, FirebaseZoneScheduler } from 'angularfire2';
import { User, auth } from 'firebase/app';

import { FirebaseAuth, FirebaseOptionsToken, FirebaseNameOrConfigToken, _firebaseAppFactory, FirebaseZoneScheduler } from 'angularfire2';

@Injectable()
export class AngularFireAuth {
Expand Down Expand Up @@ -35,7 +35,7 @@ export class AngularFireAuth {
* helper properties for getting different data associated with the token as well as all the decoded payload claims
* (or null).
*/
public readonly idTokenResult: Observable<IdTokenResult|null>;
public readonly idTokenResult: Observable<auth.IdTokenResult|null>;

constructor(
@Inject(FirebaseOptionsToken) options:FirebaseOptions,
Expand Down
3 changes: 1 addition & 2 deletions src/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
"@angular/core": "ANGULAR_VERSION",
"@angular/platform-browser": "ANGULAR_VERSION",
"@angular/platform-browser-dynamic": "ANGULAR_VERSION",
"@firebase/app": "FIREBASE_APP_VERSION",
"@firebase/auth": "FIREBASE_AUTH_VERSION",
"firebase": "FIREBASE_VERSION",
"rxjs": "RXJS_VERSION",
"zone.js": "ZONEJS_VERSION"
},
Expand Down
8 changes: 4 additions & 4 deletions src/core/angularfire2.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@

import { Reference } from '@firebase/database-types';
import { TestBed, inject, withModule, async } from '@angular/core/testing';
import { ReflectiveInjector, Provider, PlatformRef, NgModule, Compiler, ApplicationRef, CompilerFactory } from '@angular/core';
import { FirebaseApp, AngularFireModule } from 'angularfire2';
import { Subscription } from 'rxjs';
import { COMMON_CONFIG } from './test-config';
import { BrowserModule } from '@angular/platform-browser';
import { database } from 'firebase/app';

describe('angularfire', () => {
let subscription:Subscription;
let app: FirebaseApp;
let rootRef: Reference;
let questionsRef: Reference;
let listOfQuestionsRef: Reference;
let rootRef: database.Reference;
let questionsRef: database.Reference;
let listOfQuestionsRef: database.Reference;
let defaultPlatform: PlatformRef;

const APP_NAME = 'super-awesome-test-firebase-app-name';
Expand Down
6 changes: 0 additions & 6 deletions src/core/angularfire2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ import { isPlatformServer } from '@angular/common';
import { Observable, Subscription, queueScheduler as queue } from 'rxjs';
import { first } from 'rxjs/operators';

import { firebase } from '@firebase/app';
import { FirebaseApp, FirebaseOptions, FirebaseAppConfig } from '@firebase/app-types';

export const FirebaseOptionsToken = new InjectionToken<FirebaseOptions>('angularfire2.app.options');
export const FirebaseNameOrConfigToken = new InjectionToken<string|FirebaseAppConfig|undefined>('angularfire2.app.nameOrConfig')

// Put in database.ts when we drop database-depreciated
export const RealtimeDatabaseURL = new InjectionToken<string>('angularfire2.realtimeDatabaseURL');

Expand Down
33 changes: 20 additions & 13 deletions src/core/firebase.app.module.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import { InjectionToken, NgZone, NgModule, Optional } from '@angular/core';
import { app, auth, apps, database, firestore, functions, initializeApp, messaging, storage } from 'firebase/app';

import { FirebaseOptionsToken, FirebaseNameOrConfigToken } from './angularfire2';
// Public types don't expose FirebaseOptions or FirebaseAppConfig
export type FirebaseOptions = {[key:string]: any};
export type FirebaseAppConfig = {[key:string]: any};

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';
import { FirebaseFunctions } from '@firebase/functions-types';
export const FirebaseOptionsToken = new InjectionToken<FirebaseOptions>('angularfire2.app.options');
export const FirebaseNameOrConfigToken = new InjectionToken<string|FirebaseAppConfig|undefined>('angularfire2.app.nameOrConfig')

export class FirebaseApp implements _FirebaseApp {
export type FirebaseDatabase = database.Database;
export type FirebaseAuth = auth.Auth;
export type FirebaseMessaging = messaging.Messaging;
export type FirebaseStorage = storage.Storage;
export type FirebaseFirestore = firestore.Firestore;
export type FirebaseFunctions = functions.Functions;

export class FirebaseApp implements app.App {
name: string;
automaticDataCollectionEnabled: boolean;
options: {};
auth: () => FirebaseAuth;
// app.App database() doesn't take a databaseURL arg in the public types?
database: (databaseURL?: string) => FirebaseDatabase;
// automaticDataCollectionEnabled is now private? _automaticDataCollectionEnabled?
// automaticDataCollectionEnabled: true,
messaging: () => FirebaseMessaging;
storage: (storageBucket?: string) => FirebaseStorage;
delete: () => Promise<void>;
Expand All @@ -28,8 +34,9 @@ export function _firebaseAppFactory(options: FirebaseOptions, nameOrConfig?: str
const name = typeof nameOrConfig === 'string' && nameOrConfig || '[DEFAULT]';
const config = typeof nameOrConfig === 'object' && nameOrConfig || {};
config.name = config.name || name;
const existingApp = firebase.apps.filter(app => app.name === config.name)[0];
return (existingApp || firebase.initializeApp(options, config)) as FirebaseApp;
const existingApp = apps.filter(app => app && app.name === config.name)[0];
// We support FirebaseConfig, initializeApp's public type only accepts string; need to cast as any
return (existingApp || (initializeApp as any)(options, config)) as FirebaseApp;
}

const FirebaseAppProvider = {
Expand Down
2 changes: 1 addition & 1 deletion src/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@angular/core": "ANGULAR_VERSION",
"@angular/platform-browser": "ANGULAR_VERSION",
"@angular/platform-browser-dynamic": "ANGULAR_VERSION",
"@firebase/app": "FIREBASE_APP_VERSION",
"firebase": "FIREBASE_VERSION",
"rxjs": "RXJS_VERSION",
"zone.js": "ZONEJS_VERSION"
},
Expand Down
2 changes: 1 addition & 1 deletion src/database-deprecated/database.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NgModule } from '@angular/core';
import { AngularFireDatabase } from './database';
import '@firebase/database';
import 'firebase/database';

@NgModule({
providers: [ AngularFireDatabase ]
Expand Down
4 changes: 1 addition & 3 deletions src/database-deprecated/database.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { FirebaseDatabase } from '@firebase/database-types';
import { Inject, Injectable, Optional, NgZone } from '@angular/core';
import { FirebaseListFactory } from './firebase_list_factory';
import { FirebaseListObservable } from './firebase_list_observable';
import { FirebaseListFactoryOpts, FirebaseObjectFactoryOpts, PathReference } from './interfaces';
import { FirebaseObjectFactory } from './firebase_object_factory';
import { FirebaseObjectObservable } from './firebase_object_observable';
import * as utils from './utils';
import { FirebaseOptions, FirebaseAppConfig } from '@firebase/app-types';
import { FirebaseOptionsToken, FirebaseNameOrConfigToken, RealtimeDatabaseURL, _firebaseAppFactory } from 'angularfire2';
import { FirebaseDatabase, FirebaseOptions, FirebaseAppConfig, FirebaseOptionsToken, FirebaseNameOrConfigToken, RealtimeDatabaseURL, _firebaseAppFactory } from 'angularfire2';

@Injectable()
export class AngularFireDatabase {
Expand Down
7 changes: 3 additions & 4 deletions src/database-deprecated/firebase_list_factory.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { NgZone } from '@angular/core';
import * as database from '@firebase/database-types';
import { FirebaseZoneScheduler } from 'angularfire2';
import * as utils from './utils';
import { AFUnwrappedDataSnapshot } from './interfaces';
import { FirebaseListObservable } from './firebase_list_observable';
import { Observer } from 'rxjs';
import { observeOn, switchMap, map } from 'rxjs/operators';
import { observeQuery } from './query_observable';
import { Query, FirebaseListFactoryOpts, DatabaseReference, DatabaseQuery, DatabaseSnapshot } from './interfaces';
import { Reference, Query, FirebaseListFactoryOpts, DatabaseReference, DatabaseQuery, DatabaseSnapshot } from './interfaces';

export function FirebaseListFactory (
ref: DatabaseReference,
Expand Down Expand Up @@ -90,7 +89,7 @@ export function FirebaseListFactory (
}

return queried;
}), (queryRef: database.Reference, ix: number) => {
}), (queryRef: Reference, ix: number) => {
return firebaseListObservable(queryRef, { preserveSnapshot });
})
.subscribe(subscriber);
Expand All @@ -106,7 +105,7 @@ export function FirebaseListFactory (
* asynchonous. It creates a initial array from a promise of ref.once('value'), and then starts
* listening to child events. When the initial array is loaded, the observable starts emitting values.
*/
function firebaseListObservable(ref: database.Reference | DatabaseQuery, {preserveSnapshot}: FirebaseListFactoryOpts = {}): FirebaseListObservable<any> {
function firebaseListObservable(ref: Reference | DatabaseQuery, {preserveSnapshot}: FirebaseListFactoryOpts = {}): FirebaseListObservable<any> {

const toValue = preserveSnapshot ? (snapshot => snapshot) : utils.unwrapMapFn;
const toKey = preserveSnapshot ? (value => value.key) : (value => value.$key);
Expand Down
11 changes: 5 additions & 6 deletions src/database-deprecated/firebase_list_observable.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { FirebaseApp, FirebaseAppConfig, AngularFireModule} from 'angularfire2';
import { AngularFireDatabase, AngularFireDatabaseModule, FirebaseListObservable, FirebaseObjectFactory } from 'angularfire2/database-deprecated';
import { Observer } from 'rxjs/Observer';
import { map } from 'rxjs/operator/map';
import { FirebaseApp as FBApp } from '@firebase/app-types';
import { DataSnapshot, Reference } from '@firebase/database-types';
import { Observer } from 'rxjs';
import { map } from 'rxjs/operators';
import { unwrapMapFn } from './utils';
import { DataSnapshot, Reference } from './interfaces';

import { TestBed, inject } from '@angular/core/testing';
import { COMMON_CONFIG } from './test-config';

describe('FirebaseListObservable', () => {
let O: FirebaseListObservable<any>;
let ref: Reference;
let app: FBApp;
let app: FirebaseApp;
let db: AngularFireDatabase;

beforeEach(() => {
Expand All @@ -22,7 +21,7 @@ describe('FirebaseListObservable', () => {
AngularFireDatabaseModule
]
});
inject([FirebaseApp, AngularFireDatabase], (_app: FBApp, _db: AngularFireDatabase) => {
inject([FirebaseApp, AngularFireDatabase], (_app: FirebaseApp, _db: AngularFireDatabase) => {
app = _app;
db = _db;
ref = app.database().ref();
Expand Down
3 changes: 1 addition & 2 deletions src/database-deprecated/firebase_list_observable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Observable, Operator, Subscriber, Subscription } from 'rxjs';
import { Reference, DataSnapshot, ThenableReference } from '@firebase/database-types';
import * as utils from './utils';
import { AFUnwrappedDataSnapshot, FirebaseOperationCases, QueryReference, DatabaseSnapshot, DatabaseReference } from './interfaces';
import { Reference, DataSnapshot, ThenableReference, AFUnwrappedDataSnapshot, FirebaseOperationCases, QueryReference, DatabaseSnapshot, DatabaseReference } from './interfaces';

export type FirebaseOperation = string | Reference | DataSnapshot | AFUnwrappedDataSnapshot;

Expand Down
5 changes: 2 additions & 3 deletions src/database-deprecated/firebase_object_factory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { FirebaseApp as FBApp } from '@firebase/app-types';
import { Reference } from '@firebase/database-types';
import { Subscription } from 'rxjs';
import { FirebaseApp, FirebaseAppConfig, AngularFireModule } from 'angularfire2';
import { AngularFireDatabase, AngularFireDatabaseModule, FirebaseObjectObservable, FirebaseObjectFactory } from 'angularfire2/database-deprecated';
import { TestBed, inject } from '@angular/core/testing';
import { COMMON_CONFIG } from './test-config';
import { Reference } from './interfaces'

describe('FirebaseObjectFactory', () => {
let i = 0;
let ref: Reference;
let observable: FirebaseObjectObservable<any>;
let subscription: Subscription;
let nextSpy: jasmine.Spy;
let app: FBApp;
let app: FirebaseApp;
let db: AngularFireDatabase;

beforeEach(() => {
Expand Down
3 changes: 1 addition & 2 deletions src/database-deprecated/firebase_object_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { FirebaseObjectObservable } from './firebase_object_observable';
import { FirebaseZoneScheduler } from 'angularfire2';
import { Observer } from 'rxjs';
import { observeOn } from 'rxjs/operators';
import { DataSnapshot } from '@firebase/database-types';
import * as utils from './utils';
import { FirebaseObjectFactoryOpts, DatabaseReference } from './interfaces';
import { DataSnapshot, FirebaseObjectFactoryOpts, DatabaseReference } from './interfaces';

export function FirebaseObjectFactory (
ref: DatabaseReference,
Expand Down
11 changes: 5 additions & 6 deletions src/database-deprecated/firebase_object_observable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ import { TestBed, inject } from '@angular/core/testing';
import { FirebaseApp, FirebaseAppConfig, AngularFireModule } from 'angularfire2';
import { COMMON_CONFIG } from './test-config';
import { AngularFireDatabase, AngularFireDatabaseModule, FirebaseObjectObservable } from 'angularfire2/database-deprecated';
import { Observer } from 'rxjs/Observer';
import { map } from 'rxjs/operator/map';
import { FirebaseApp as FBApp } from '@firebase/app-types';
import { Reference } from '@firebase/database-types';
import { Observer } from 'rxjs';
import { map } from 'rxjs/operators';
import { Reference } from './interfaces';

describe('FirebaseObjectObservable', () => {

let O: FirebaseObjectObservable<any>;
let ref: Reference;
let app: FBApp;
let app: FirebaseApp;
let db: AngularFireDatabase;

beforeEach(() => {
Expand All @@ -21,7 +20,7 @@ describe('FirebaseObjectObservable', () => {
AngularFireDatabaseModule
]
});
inject([FirebaseApp, AngularFireDatabase], (_app: FBApp, _db: AngularFireDatabase) => {
inject([FirebaseApp, AngularFireDatabase], (_app: FirebaseApp, _db: AngularFireDatabase) => {
app = _app;
db = _db;
ref = app.database().ref();
Expand Down
3 changes: 2 additions & 1 deletion src/database-deprecated/firebase_object_observable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Observable, Operator, Subscriber, Subscription } from 'rxjs';
import { Reference } from '@firebase/database-types';
import { Reference } from './interfaces';
import { database } from 'firebase/app';

export class FirebaseObjectObservable<T> extends Observable<T> {
constructor(subscribe?: <R>(subscriber: Subscriber<R>) => Subscription | Function | void, public $ref?:Reference) {
Expand Down
8 changes: 6 additions & 2 deletions src/database-deprecated/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { Observable } from 'rxjs';
import { Reference, DataSnapshot, Query } from '@firebase/database-types';
import { database } from 'firebase/app';

export type Reference = database.Reference;
export type DataSnapshot = database.DataSnapshot;
export type ThenableReference = database.ThenableReference;

export interface FirebaseOperationCases {
stringCase: () => Promise<void>;
Expand Down Expand Up @@ -83,6 +87,6 @@ export type Primitive = number | string | boolean;

export type DatabaseSnapshot = DataSnapshot;
export type DatabaseReference = Reference;
export type DatabaseQuery = Query;
export type DatabaseQuery = database.Query;
export type QueryReference = DatabaseReference | DatabaseQuery;
export type PathReference = QueryReference | string;
3 changes: 1 addition & 2 deletions src/database-deprecated/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
"@angular/core": "ANGULAR_VERSION",
"@angular/platform-browser": "ANGULAR_VERSION",
"@angular/platform-browser-dynamic": "ANGULAR_VERSION",
"@firebase/app": "FIREBASE_APP_VERSION",
"@firebase/database": "FIREBASE_DATABASE_VERSION",
"firebase": "FIREBASE_VERSION",
"rxjs": "RXJS_VERSION",
"zone.js": "ZONEJS_VERSION"
},
Expand Down
4 changes: 2 additions & 2 deletions src/database-deprecated/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DataSnapshot, FirebaseDatabase } from '@firebase/database-types';
import { Subscription, Scheduler, queueScheduler as queue } from 'rxjs';
import { AFUnwrappedDataSnapshot, PathReference, DatabaseReference } from './interfaces';
import { DataSnapshot, AFUnwrappedDataSnapshot, PathReference, DatabaseReference } from './interfaces';
import { FirebaseDatabase } from 'angularfire2';

const REGEX_ABSOLUTE_URL = /^[a-z]+:\/\/.*/;

Expand Down
Loading

0 comments on commit 664c2d6

Please sign in to comment.