Skip to content

Commit 9669ccf

Browse files
committed
fix(): Shore up optional types and allow functions emulator configuration
1 parent 75f3dae commit 9669ccf

File tree

11 files changed

+100
-89
lines changed

11 files changed

+100
-89
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angularfire2",
3-
"version": "5.1.0",
3+
"version": "5.1.1",
44
"description": "The official library of Firebase and Angular.",
55
"private": true,
66
"scripts": {
@@ -12,7 +12,7 @@
1212
"delayed_karma": "sleep 10 && karma start",
1313
"build": "rm -rf dist && node tools/build.js",
1414
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1",
15-
"build:wrapper": "npm i --prefix wrapper && VERSION=5.1.0 npm run --prefix wrapper build"
15+
"build:wrapper": "npm i --prefix wrapper && VERSION=5.1.1 npm run --prefix wrapper build"
1616
},
1717
"keywords": [
1818
"angular",
@@ -35,7 +35,7 @@
3535
"@angular/core": ">=6.0.0 <8",
3636
"@angular/platform-browser": ">=6.0.0 <8",
3737
"@angular/platform-browser-dynamic": ">=6.0.0 <8",
38-
"firebase": "^5.5.0",
38+
"firebase": "^5.5.7",
3939
"rxjs": "^6.0.0",
4040
"ws": "^3.3.2",
4141
"xhr2": "^0.1.4",
@@ -46,9 +46,9 @@
4646
"utf-8-validate": "~4.0.0"
4747
},
4848
"devDependencies": {
49+
"@angular/animations": ">=6.0.0 <8",
4950
"@angular/compiler-cli": ">=6.0.0 <8",
5051
"@angular/platform-server": ">=6.0.0 <8",
51-
"@angular/animations": ">=6.0.0 <8",
5252
"@types/jasmine": "^2.5.36",
5353
"@types/request": "0.0.30",
5454
"concurrently": "^2.2.0",

src/auth/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class AngularFireAuth {
3838

3939
constructor(
4040
@Inject(FirebaseOptionsToken) options:FirebaseOptions,
41-
@Optional() @Inject(FirebaseNameOrConfigToken) nameOrConfig:string|FirebaseAppConfig|undefined,
41+
@Optional() @Inject(FirebaseNameOrConfigToken) nameOrConfig:string|FirebaseAppConfig|null,
4242
@Inject(PLATFORM_ID) platformId: Object,
4343
private zone: NgZone
4444
) {

src/core/firebase.app.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class FirebaseApp implements app.App {
3434
functions: (region?: string) => FirebaseFunctions;
3535
}
3636

37-
export function _firebaseAppFactory(options: FirebaseOptions, nameOrConfig?: string | FirebaseAppConfig) {
37+
export function _firebaseAppFactory(options: FirebaseOptions, nameOrConfig?: string|FirebaseAppConfig|null) {
3838
const name = typeof nameOrConfig === 'string' && nameOrConfig || '[DEFAULT]';
3939
const config = typeof nameOrConfig === 'object' && nameOrConfig || {};
4040
config.name = config.name || name;
@@ -53,7 +53,7 @@ const FirebaseAppProvider = {
5353
[new Optional(), FirebaseNameOrConfigToken]
5454
]
5555
};
56-
56+
5757
@NgModule({
5858
providers: [ FirebaseAppProvider ],
5959
})

src/core/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
"angularfire",
1313
"angularfire2"
1414
],
15-
"repository": {
16-
"type": "git",
17-
"url": "git+https://github.com/angular/angularfire2.git"
18-
},
15+
"repository": "github:angular/angularfire2",
1916
"author": "angular,firebase",
2017
"license": "MIT",
18+
"homepage": "https://firebaseopensource.com/projects/angular/angularfire2",
2119
"peerDependencies": {
2220
"@angular/common": "ANGULAR_VERSION",
2321
"@angular/core": "ANGULAR_VERSION",

src/database/database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class AngularFireDatabase {
1313

1414
constructor(
1515
@Inject(FirebaseOptionsToken) options:FirebaseOptions,
16-
@Optional() @Inject(FirebaseNameOrConfigToken) nameOrConfig:string|FirebaseAppConfig|undefined,
16+
@Optional() @Inject(FirebaseNameOrConfigToken) nameOrConfig:string|FirebaseAppConfig|null,
1717
@Optional() @Inject(RealtimeDatabaseURL) databaseURL:string,
1818
@Inject(PLATFORM_ID) platformId: Object,
1919
zone: NgZone

src/firestore/firestore.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { AngularFirestoreDocument } from './document/document';
77
import { AngularFirestoreCollection } from './collection/collection';
88

99
import { FirebaseFirestore, FirebaseOptions, FirebaseAppConfig, FirebaseOptionsToken, FirebaseNameOrConfigToken, _firebaseAppFactory, FirebaseZoneScheduler } from '@angular/fire';
10-
import { isPlatformBrowser } from '@angular/common';
10+
import { isPlatformServer } from '@angular/common';
1111

1212
import { firestore } from 'firebase/app';
1313

@@ -107,12 +107,12 @@ export class AngularFirestore {
107107
*/
108108
constructor(
109109
@Inject(FirebaseOptionsToken) options:FirebaseOptions,
110-
@Optional() @Inject(FirebaseNameOrConfigToken) nameOrConfig:string|FirebaseAppConfig|undefined,
110+
@Optional() @Inject(FirebaseNameOrConfigToken) nameOrConfig:string|FirebaseAppConfig|null,
111111
@Optional() @Inject(EnablePersistenceToken) shouldEnablePersistence: boolean,
112112
@Optional() @Inject(FirestoreSettingsToken) settings: Settings,
113113
@Inject(PLATFORM_ID) platformId: Object,
114114
zone: NgZone,
115-
@Optional() @Inject(PersistenceSettingsToken) persistenceSettings: PersistenceSettings|undefined,
115+
@Optional() @Inject(PersistenceSettingsToken) persistenceSettings: PersistenceSettings|null
116116
) {
117117
this.scheduler = new FirebaseZoneScheduler(zone, platformId);
118118
this.firestore = zone.runOutsideAngular(() => {
@@ -122,12 +122,12 @@ export class AngularFirestore {
122122
return firestore;
123123
});
124124

125-
if (shouldEnablePersistence && isPlatformBrowser(platformId)) {
125+
if (shouldEnablePersistence && !isPlatformServer(platformId)) {
126126
// We need to try/catch here because not all enablePersistence() failures are caught
127127
// https://github.com/firebase/firebase-js-sdk/issues/608
128128
const enablePersistence = () => {
129129
try {
130-
return from(this.firestore.enablePersistence(persistenceSettings).then(() => true, () => false));
130+
return from(this.firestore.enablePersistence(persistenceSettings || undefined).then(() => true, () => false));
131131
} catch(e) {
132132
return of(false);
133133
}

src/functions/functions.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ReflectiveInjector, Provider } from '@angular/core';
22
import { TestBed, inject } from '@angular/core/testing';
33
import { FirebaseApp, FirebaseOptionsToken, AngularFireModule, FirebaseNameOrConfigToken } from '@angular/fire';
4-
import { AngularFireFunctions, AngularFireFunctionsModule, FunctionsRegionToken } from '@angular/fire/functions';
4+
import { AngularFireFunctions, AngularFireFunctionsModule, FunctionsRegionToken, FunctionsEmulatorOrigin } from '@angular/fire/functions';
55
import { COMMON_CONFIG } from './test-config';
66

77
describe('AngularFireFunctions', () => {
@@ -32,6 +32,9 @@ describe('AngularFireFunctions', () => {
3232

3333
it('should have the Firebase Functions instance', () => {
3434
expect(afFns.functions).toBeDefined();
35+
expect((afFns.functions as any).app_).toEqual(app);
36+
expect((afFns.functions as any).region_).toEqual('us-central1');
37+
expect((afFns.functions as any).emulatorOrigin).toEqual(null);
3538
});
3639

3740
});
@@ -52,6 +55,7 @@ describe('AngularFireFunctions with different app', () => {
5255
{ provide: FirebaseNameOrConfigToken, useValue: FIREBASE_APP_NAME_TOO },
5356
{ provide: FirebaseOptionsToken, useValue: COMMON_CONFIG },
5457
{ provide: FunctionsRegionToken, useValue: 'asia-northeast1' },
58+
{ provide: FunctionsEmulatorOrigin, useValue: 'http://localhost:9999' },
5559
]
5660
});
5761
inject([FirebaseApp, AngularFireFunctions], (app_: FirebaseApp, _fns: AngularFireFunctions) => {
@@ -73,6 +77,9 @@ describe('AngularFireFunctions with different app', () => {
7377

7478
it('should have the Firebase Functions instance', () => {
7579
expect(afFns.functions).toBeDefined();
80+
expect((afFns.functions as any).app_).toEqual(app);
81+
expect((afFns.functions as any).region_).toEqual('asia-northeast1');
82+
expect((afFns.functions as any).emulatorOrigin).toEqual('http://localhost:9999');
7683
});
7784

7885
});

src/functions/functions.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Injectable, Inject, Optional, NgZone, PLATFORM_ID, InjectionToken } from '@angular/core';
22
import { Observable, from } from 'rxjs';
3-
import { map } from 'rxjs/operators';
3+
import { map, catchError } from 'rxjs/operators';
44
import { FirebaseOptions, FirebaseAppConfig } from '@angular/fire';
55
import { FirebaseFunctions, FirebaseOptionsToken, FirebaseNameOrConfigToken, _firebaseAppFactory, FirebaseZoneScheduler } from '@angular/fire';
66

77
export const FunctionsRegionToken = new InjectionToken<string>('angularfire2.functions.region');
8+
export const FunctionsEmulatorOrigin = new InjectionToken<string>('angularfire2.functions.emulatorOrigin');
89

910
@Injectable()
1011
export class AngularFireFunctions {
@@ -18,10 +19,11 @@ export class AngularFireFunctions {
1819

1920
constructor(
2021
@Inject(FirebaseOptionsToken) options:FirebaseOptions,
21-
@Optional() @Inject(FirebaseNameOrConfigToken) nameOrConfig:string|FirebaseAppConfig|undefined,
22+
@Optional() @Inject(FirebaseNameOrConfigToken) nameOrConfig:string|FirebaseAppConfig|null,
2223
@Inject(PLATFORM_ID) platformId: Object,
2324
zone: NgZone,
24-
@Optional() @Inject(FunctionsRegionToken) region:string|undefined
25+
@Optional() @Inject(FunctionsRegionToken) region:string|null,
26+
@Optional() @Inject(FunctionsEmulatorOrigin) emulatorOrigin:string|null
2527
) {
2628
this.scheduler = new FirebaseZoneScheduler(zone, platformId);
2729

@@ -30,6 +32,10 @@ export class AngularFireFunctions {
3032
return app.functions(region || undefined);
3133
});
3234

35+
if (emulatorOrigin) {
36+
this.functions.useFunctionsEmulator(emulatorOrigin);
37+
}
38+
3339
}
3440

3541
public httpsCallable<T=any, R=any>(name: string) {

src/messaging/messaging.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Injectable, Inject, Optional, NgZone, PLATFORM_ID } from '@angular/core';
2-
import { isPlatformBrowser } from '@angular/common';
2+
import { isPlatformServer } from '@angular/common';
33
import { messaging } from 'firebase/app';
44
import { Observable, empty, from, of, throwError } from 'rxjs';
55
import { mergeMap, catchError, map, switchMap, concat, defaultIfEmpty } from 'rxjs/operators';
@@ -18,12 +18,12 @@ export class AngularFireMessaging {
1818

1919
constructor(
2020
@Inject(FirebaseOptionsToken) options:FirebaseOptions,
21-
@Optional() @Inject(FirebaseNameOrConfigToken) nameOrConfig:string|FirebaseAppConfig|undefined,
21+
@Optional() @Inject(FirebaseNameOrConfigToken) nameOrConfig:string|FirebaseAppConfig|null,
2222
@Inject(PLATFORM_ID) platformId: Object,
2323
zone: NgZone
2424
) {
2525

26-
if (isPlatformBrowser(platformId)) {
26+
if (!isPlatformServer(platformId)) {
2727

2828
// @ts-ignore
2929
const requireMessaging = from(import('firebase/messaging'));

src/storage/storage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export class AngularFireStorage {
2222

2323
constructor(
2424
@Inject(FirebaseOptionsToken) options:FirebaseOptions,
25-
@Optional() @Inject(FirebaseNameOrConfigToken) nameOrConfig:string|FirebaseAppConfig|undefined,
26-
@Optional() @Inject(StorageBucket) storageBucket:string,
25+
@Optional() @Inject(FirebaseNameOrConfigToken) nameOrConfig:string|FirebaseAppConfig|null,
26+
@Optional() @Inject(StorageBucket) storageBucket:string|null,
2727
@Inject(PLATFORM_ID) platformId: Object,
2828
zone: NgZone
2929
) {

0 commit comments

Comments
 (0)