Skip to content

Commit 23464c2

Browse files
jamesdanielsdavideast
authored andcommitted
5.1 release: support Firebase 5.5, multi-tab sync, function region selection, and Angular 7 (#1920)
* feat(afs): Support Firebase 5.5 and Firestore PersistenceSettings * chore(): Now that app types are mostly fixed, pull from those * chore(): Changelog entry for 5.1 * chore(): Use PersistenceSettings from interfaces, also fix types in firestore.ts * fix(afs): Fix constructor ordering so this isn't a break * feat(functions): Support region configuration via FunctionsRegionToken * chore(): Changelog entry for region selection * chore(): Support Angular 7 without peer dependency warnings * chore(): Changelog for Angular 7
1 parent d6f59c7 commit 23464c2

26 files changed

+1318
-162
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
<a name="5.1.0"></a>
2+
# [5.1.0](https://github.com/angular/angularfire2/compare/5.0.0-rc.12...5.1.0) (2018-10-17)
3+
4+
### Features
5+
6+
* **core:** Support Angular 7 without peer dependency warnings ([ed92c45](https://github.com/angular/angularfire2/commit/ed92c45))
7+
* **afs:** Support Firebase 5.5 and Firestore PersistenceSettings ([a9cf1ca](https://github.com/angular/angularfire2/commit/a9cf1ca))
8+
* **functions:** Support region configuration via `FunctionsRegionToken` ([8901617](https://github.com/angular/angularfire2/commit/8901617))
9+
10+
111
<a name="5.0.2"></a>
212
## [5.0.2](https://github.com/angular/angularfire2/compare/5.0.1...5.0.2) (2018-09-21)
313

package.json

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angularfire2",
3-
"version": "5.0.2",
3+
"version": "5.1.0",
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.0.2 npm run --prefix wrapper build"
15+
"build:wrapper": "npm i --prefix wrapper && VERSION=5.1.0 npm run --prefix wrapper build"
1616
},
1717
"keywords": [
1818
"angular",
@@ -30,12 +30,12 @@
3030
},
3131
"homepage": "https://github.com/angular/angularfire2#readme",
3232
"dependencies": {
33-
"@angular/common": "^6.0.0",
34-
"@angular/compiler": "^6.0.0",
35-
"@angular/core": "^6.0.0",
36-
"@angular/platform-browser": "^6.0.0",
37-
"@angular/platform-browser-dynamic": "^6.0.0",
38-
"firebase": "^5.0.3",
33+
"@angular/common": ">=6.0.0 <8",
34+
"@angular/compiler": ">=6.0.0 <8",
35+
"@angular/core": ">=6.0.0 <8",
36+
"@angular/platform-browser": ">=6.0.0 <8",
37+
"@angular/platform-browser-dynamic": ">=6.0.0 <8",
38+
"firebase": "^5.5.0",
3939
"rxjs": "^6.0.0",
4040
"ws": "^3.3.2",
4141
"xhr2": "^0.1.4",
@@ -46,8 +46,9 @@
4646
"utf-8-validate": "~4.0.0"
4747
},
4848
"devDependencies": {
49-
"@angular/compiler-cli": "^6.0.0",
50-
"@angular/platform-server": "^6.0.0",
49+
"@angular/compiler-cli": ">=6.0.0 <8",
50+
"@angular/platform-server": ">=6.0.0 <8",
51+
"@angular/animations": ">=6.0.0 <8",
5152
"@types/jasmine": "^2.5.36",
5253
"@types/request": "0.0.30",
5354
"concurrently": "^2.2.0",
@@ -82,7 +83,7 @@
8283
"systemjs": "^0.19.16",
8384
"systemjs-builder": "^0.15.7",
8485
"traceur": "0.0.96",
85-
"typescript": ">=2.7.2 <2.8.0"
86+
"typescript": ">=2.7.2 <2.8.0, >=3.1.1 <3.2"
8687
},
8788
"typings": "index.d.ts"
8889
}

src/auth/auth.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { User } from 'firebase';
1+
import { User } from 'firebase/app';
22
import { Observable, Subject } from 'rxjs'
33
import { TestBed, inject } from '@angular/core/testing';
44
import { FirebaseApp, FirebaseOptionsToken, AngularFireModule, FirebaseNameOrConfigToken } from '@angular/fire';

src/auth/auth.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Injectable, Inject, Optional, NgZone, PLATFORM_ID } from '@angular/core
22
import { Observable, of, from } from 'rxjs';
33
import { switchMap } from 'rxjs/operators';
44
import { FirebaseAppConfig, FirebaseOptions } from '@angular/fire';
5-
import { User, auth } from 'firebase';
5+
import { User, auth } from 'firebase/app';
66

77
import { FirebaseAuth, FirebaseOptionsToken, FirebaseNameOrConfigToken, _firebaseAppFactory, FirebaseZoneScheduler } from '@angular/fire';
88

src/core/angularfire2.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { FirebaseApp, AngularFireModule } from '@angular/fire';
44
import { Subscription } from 'rxjs';
55
import { COMMON_CONFIG } from './test-config';
66
import { BrowserModule } from '@angular/platform-browser';
7-
import { database } from 'firebase';
7+
import { database } from 'firebase/app';
88

99
describe('angularfire', () => {
1010
let subscription:Subscription;

src/core/firebase.app.module.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { InjectionToken, NgModule, Optional } from '@angular/core';
2-
import {app, auth, database, firestore, functions, messaging, storage } from 'firebase';
2+
import { app, auth, database, firestore, functions, messaging, storage } from 'firebase/app';
33
// @ts-ignore (https://github.com/firebase/firebase-js-sdk/pull/1206)
4-
import firebase from 'firebase/app';
4+
import firebase from 'firebase/app'; // once fixed can pull in as "default as firebase" above
55

66
// Public types don't expose FirebaseOptions or FirebaseAppConfig
77
export type FirebaseOptions = {[key:string]: any};
@@ -17,6 +17,8 @@ export type FirebaseStorage = storage.Storage;
1717
export type FirebaseFirestore = firestore.Firestore;
1818
export type FirebaseFunctions = functions.Functions;
1919

20+
// Have to implement as we need to return a class from the provider, we should consider exporting
21+
// this in the firebase/app types as this is our highest risk of breaks
2022
export class FirebaseApp implements app.App {
2123
name: string;
2224
options: {};
@@ -29,7 +31,7 @@ export class FirebaseApp implements app.App {
2931
storage: (storageBucket?: string) => FirebaseStorage;
3032
delete: () => Promise<void>;
3133
firestore: () => FirebaseFirestore;
32-
functions: () => FirebaseFunctions;
34+
functions: (region?: string) => FirebaseFunctions;
3335
}
3436

3537
export function _firebaseAppFactory(options: FirebaseOptions, nameOrConfig?: string | FirebaseAppConfig) {

src/database-deprecated/firebase_object_observable.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Observable, Operator, Subscriber, Subscription } from 'rxjs';
22
import { Reference } from './interfaces';
3-
import { database } from 'firebase';
3+
import { database } from 'firebase/app';
44

55
export class FirebaseObjectObservable<T> extends Observable<T> {
66
constructor(subscribe?: <R>(subscriber: Subscriber<R>) => Subscription | Function | void, public $ref?:Reference) {

src/database-deprecated/interfaces.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Observable } from 'rxjs';
2-
import { database } from 'firebase';
2+
import { database } from 'firebase/app';
33

44
export type Reference = database.Reference;
55
export type DataSnapshot = database.DataSnapshot;

src/database/interfaces.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Observable } from 'rxjs';
2-
import { database } from 'firebase';
2+
import { database } from 'firebase/app';
33

44
export type FirebaseOperation = string | database.Reference | database.DataSnapshot;
55

src/database/list/changes.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { database } from 'firebase';
1+
import { database } from 'firebase/app';
22
import { FirebaseApp, AngularFireModule } from '@angular/fire';
33
import { AngularFireDatabase, AngularFireDatabaseModule, listChanges } from '@angular/fire/database';
44
import { TestBed, inject } from '@angular/core/testing';

src/database/list/remove.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DatabaseReference, DataSnapshot, FirebaseOperation, DatabaseSnapshot } from '../interfaces';
22
import { checkOperationCases } from '../utils';
3-
import { database } from 'firebase';
3+
import { database } from 'firebase/app';
44

55
// TODO(davideast): Find out why TS thinks this returns firebase.Primise
66
// instead of Promise.

src/database/list/snapshot-changes.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { database } from 'firebase';
1+
import { database } from 'firebase/app';
22
import { FirebaseApp, AngularFireModule } from '@angular/fire';
33
import { AngularFireDatabase, AngularFireDatabaseModule, snapshotChanges, ChildEvent } from '@angular/fire/database';
44
import { TestBed, inject } from '@angular/core/testing';

src/database/list/state-changes.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { database } from 'firebase';
1+
import { database } from 'firebase/app';
22
import { FirebaseApp, AngularFireModule } from '@angular/fire';
33
import { AngularFireDatabase, AngularFireDatabaseModule, stateChanges, ChildEvent } from '@angular/fire/database';
44
import { TestBed, inject } from '@angular/core/testing';

src/firestore/collection/collection.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Observable, from } from 'rxjs';
22
import { fromCollectionRef } from '../observable/fromRef';
33
import { map, filter, scan } from 'rxjs/operators';
4-
import { firestore } from 'firebase';
4+
import { firestore } from 'firebase/app';
55

66
import { DocumentChangeType, CollectionReference, Query, DocumentReference, DocumentData, DocumentChangeAction } from '../interfaces';
77
import { docChanges, sortedChanges } from './changes';

src/firestore/document/document.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { map } from 'rxjs/operators';
55

66
import { AngularFirestore, associateQuery } from '../firestore';
77
import { AngularFirestoreCollection } from '../collection/collection';
8-
import { firestore } from 'firebase';
8+
import { firestore } from 'firebase/app';
99
import { runInZone } from '@angular/fire';
1010

1111
/**

src/firestore/firestore.module.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { InjectionToken, ModuleWithProviders, NgModule } from '@angular/core';
2-
import { AngularFirestore, EnablePersistenceToken } from './firestore';
1+
import { ModuleWithProviders, NgModule } from '@angular/core';
2+
import { PersistenceSettings } from './interfaces';
3+
import { AngularFirestore, EnablePersistenceToken, PersistenceSettingsToken } from './firestore';
34

45
import 'firebase/firestore';
56

@@ -10,11 +11,12 @@ export class AngularFirestoreModule {
1011
/**
1112
* Attempt to enable persistent storage, if possible
1213
*/
13-
static enablePersistence(): ModuleWithProviders {
14+
static enablePersistence(persistenceSettings?: PersistenceSettings): ModuleWithProviders {
1415
return {
1516
ngModule: AngularFirestoreModule,
1617
providers: [
1718
{ provide: EnablePersistenceToken, useValue: true },
19+
{ provide: PersistenceSettingsToken, useValue: persistenceSettings },
1820
]
1921
}
2022
}

src/firestore/firestore.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('AngularFirestore', () => {
2323
TestBed.configureTestingModule({
2424
imports: [
2525
AngularFireModule.initializeApp(COMMON_CONFIG),
26-
AngularFirestoreModule.enablePersistence()
26+
AngularFirestoreModule.enablePersistence({experimentalTabSynchronization: true})
2727
]
2828
});
2929
inject([FirebaseApp, AngularFirestore], (_app: FirebaseApp, _afs: AngularFirestore) => {

src/firestore/firestore.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import { InjectionToken, NgZone, PLATFORM_ID, Injectable, Inject, Optional } from '@angular/core';
22

33
import { Observable, of, from } from 'rxjs';
4-
import { catchError } from 'rxjs/operators';
5-
import { firestore } from 'firebase';
64

7-
import { Settings, CollectionReference, DocumentReference, QueryFn, AssociatedReference } from './interfaces';
5+
import { Settings, PersistenceSettings, CollectionReference, DocumentReference, QueryFn, AssociatedReference } from './interfaces';
86
import { AngularFirestoreDocument } from './document/document';
97
import { AngularFirestoreCollection } from './collection/collection';
108

119
import { FirebaseFirestore, FirebaseOptions, FirebaseAppConfig, FirebaseOptionsToken, FirebaseNameOrConfigToken, _firebaseAppFactory, FirebaseZoneScheduler } from '@angular/fire';
1210
import { isPlatformBrowser } from '@angular/common';
1311

12+
import { firestore } from 'firebase/app';
13+
1414
/**
1515
* The value of this token determines whether or not the firestore will have persistance enabled
1616
*/
1717
export const EnablePersistenceToken = new InjectionToken<boolean>('angularfire2.enableFirestorePersistence');
18+
export const PersistenceSettingsToken = new InjectionToken<PersistenceSettings|undefined>('angularfire2.firestore.persistenceSettings');
1819
export const FirestoreSettingsToken = new InjectionToken<Settings>('angularfire2.firestore.settings');
1920

2021
export const DefaultFirestoreSettings = {timestampsInSnapshots: true} as Settings;
@@ -110,7 +111,8 @@ export class AngularFirestore {
110111
@Optional() @Inject(EnablePersistenceToken) shouldEnablePersistence: boolean,
111112
@Optional() @Inject(FirestoreSettingsToken) settings: Settings,
112113
@Inject(PLATFORM_ID) platformId: Object,
113-
zone: NgZone
114+
zone: NgZone,
115+
@Optional() @Inject(PersistenceSettingsToken) persistenceSettings: PersistenceSettings|undefined,
114116
) {
115117
this.scheduler = new FirebaseZoneScheduler(zone, platformId);
116118
this.firestore = zone.runOutsideAngular(() => {
@@ -125,7 +127,7 @@ export class AngularFirestore {
125127
// https://github.com/firebase/firebase-js-sdk/issues/608
126128
const enablePersistence = () => {
127129
try {
128-
return from(this.firestore.enablePersistence().then(() => true, () => false));
130+
return from(this.firestore.enablePersistence(persistenceSettings).then(() => true, () => false));
129131
} catch(e) {
130132
return of(false);
131133
}

src/firestore/interfaces.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Subscriber } from 'rxjs';
2-
import { firestore } from 'firebase';
2+
import { firestore } from 'firebase/app';
33

44
export type Settings = firestore.Settings;
55
export type CollectionReference = firestore.CollectionReference;
66
export type DocumentReference = firestore.DocumentReference;
7-
7+
export type PersistenceSettings = firestore.PersistenceSettings;
88
export type DocumentChangeType = firestore.DocumentChangeType;
99
export type SnapshotOptions = firestore.SnapshotOptions;
1010
export type FieldPath = firestore.FieldPath;

src/firestore/utils.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { firestore } from 'firebase';
1+
import { firestore } from 'firebase/app';
22
import { AngularFirestoreCollection } from './collection/collection';
33

44
export interface Stock {

src/functions/functions.spec.ts

+7-2
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 } from '@angular/fire/functions';
4+
import { AngularFireFunctions, AngularFireFunctionsModule, FunctionsRegionToken } from '@angular/fire/functions';
55
import { COMMON_CONFIG } from './test-config';
66

77
describe('AngularFireFunctions', () => {
@@ -50,7 +50,8 @@ describe('AngularFireFunctions with different app', () => {
5050
],
5151
providers: [
5252
{ provide: FirebaseNameOrConfigToken, useValue: FIREBASE_APP_NAME_TOO },
53-
{ provide: FirebaseOptionsToken, useValue: COMMON_CONFIG }
53+
{ provide: FirebaseOptionsToken, useValue: COMMON_CONFIG },
54+
{ provide: FunctionsRegionToken, useValue: 'asia-northeast1' },
5455
]
5556
});
5657
inject([FirebaseApp, AngularFireFunctions], (app_: FirebaseApp, _fns: AngularFireFunctions) => {
@@ -70,6 +71,10 @@ describe('AngularFireFunctions with different app', () => {
7071
expect(afFns instanceof AngularFireFunctions).toEqual(true);
7172
});
7273

74+
it('should have the Firebase Functions instance', () => {
75+
expect(afFns.functions).toBeDefined();
76+
});
77+
7378
});
7479

7580
});

src/functions/functions.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { Injectable, Inject, Optional, NgZone, PLATFORM_ID } from '@angular/core';
1+
import { Injectable, Inject, Optional, NgZone, PLATFORM_ID, InjectionToken } from '@angular/core';
22
import { Observable, from } from 'rxjs';
33
import { map } from 'rxjs/operators';
4-
54
import { FirebaseOptions, FirebaseAppConfig } from '@angular/fire';
6-
75
import { FirebaseFunctions, FirebaseOptionsToken, FirebaseNameOrConfigToken, _firebaseAppFactory, FirebaseZoneScheduler } from '@angular/fire';
86

7+
export const FunctionsRegionToken = new InjectionToken<string>('angularfire2.functions.region');
8+
99
@Injectable()
1010
export class AngularFireFunctions {
1111

@@ -20,13 +20,14 @@ export class AngularFireFunctions {
2020
@Inject(FirebaseOptionsToken) options:FirebaseOptions,
2121
@Optional() @Inject(FirebaseNameOrConfigToken) nameOrConfig:string|FirebaseAppConfig|undefined,
2222
@Inject(PLATFORM_ID) platformId: Object,
23-
zone: NgZone
23+
zone: NgZone,
24+
@Optional() @Inject(FunctionsRegionToken) region:string|undefined
2425
) {
2526
this.scheduler = new FirebaseZoneScheduler(zone, platformId);
2627

2728
this.functions = zone.runOutsideAngular(() => {
2829
const app = _firebaseAppFactory(options, nameOrConfig);
29-
return app.functions();
30+
return app.functions(region);
3031
});
3132

3233
}

src/messaging/messaging.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable, Inject, Optional, NgZone, PLATFORM_ID } from '@angular/core';
22
import { isPlatformBrowser } from '@angular/common';
3-
import { messaging } from 'firebase';
3+
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';
66
import { FirebaseOptions, FirebaseAppConfig, runOutsideAngular } from '@angular/fire';

src/storage/interfaces.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { storage } from 'firebase';
1+
import { storage } from 'firebase/app';
22

33
export type UploadTask = storage.UploadTask;
44
export type UploadTaskSnapshot = storage.UploadTaskSnapshot;

src/storage/observable/fromTask.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Observable } from 'rxjs';
22
import { UploadTask, UploadTaskSnapshot } from '../interfaces';
3-
import { storage } from 'firebase';
3+
import { storage } from 'firebase/app';
44

55
export function fromTask(task: UploadTask) {
66
return new Observable<UploadTaskSnapshot>(subscriber => {

0 commit comments

Comments
 (0)