Skip to content

Commit 6376d97

Browse files
authored
feat(functions): Add Functions
1 parent 58fced7 commit 6376d97

File tree

4 files changed

+13
-25
lines changed

4 files changed

+13
-25
lines changed

src/core/firebase.app.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const FIREBASE_APP_NAME = new InjectionToken<string | FirebaseAppConfig |
2626

2727
// Have to implement as we need to return a class from the provider, we should consider exporting
2828
// this in the firebase/app types as this is our highest risk of breaks
29-
export class FirebaseApp implements Partial<FirebaseAppType> {
29+
export class FirebaseApp implements FirebaseAppType {
3030
name: string;
3131
options: {};
3232
analytics: () => Analytics;
@@ -39,6 +39,7 @@ export class FirebaseApp implements Partial<FirebaseAppType> {
3939
firestore: () => FirebaseFirestore;
4040
functions: (region?: string) => Functions;
4141
remoteConfig: () => RemoteConfig;
42+
automaticDataCollectionEnabled: boolean;
4243
}
4344

4445
export const VERSION = new Version('ANGULARFIRE2_VERSION');

src/functions/functions.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { TestBed } from '@angular/core/testing';
22
import { AngularFireModule, FIREBASE_APP_NAME, FIREBASE_OPTIONS, FirebaseApp } from '@angular/fire';
33
import { AngularFireFunctions, AngularFireFunctionsModule, ORIGIN, REGION } from '@angular/fire/functions';
44
import { COMMON_CONFIG } from '../test-config';
5-
import 'firebase/functions';
65
import { rando } from '../firestore/utils.spec';
76

87
describe('AngularFireFunctions', () => {

src/functions/functions.ts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@ import {
1212
ɵPromiseProxy,
1313
ɵapplyMixins
1414
} from '@angular/fire';
15-
import firebase from 'firebase/app';
1615
import { proxyPolyfillCompat } from './base';
17-
import { HttpsCallableOptions } from '@firebase/functions-types';
16+
import { HttpsCallableOptions, Functions, useFunctionsEmulator, httpsCallable, getFunctions } from 'firebase/functions';
1817
import { ɵfetchInstance } from '@angular/fire';
1918

2019
export const ORIGIN = new InjectionToken<string>('angularfire2.functions.origin');
2120
export const REGION = new InjectionToken<string>('angularfire2.functions.region');
2221
export const NEW_ORIGIN_BEHAVIOR = new InjectionToken<boolean>('angularfire2.functions.new-origin-behavior');
2322

2423
// SEMVER(7): use Parameters to detirmine the useEmulator arguments
25-
// type UseEmulatorArguments = Parameters<typeof firebase.functions.Functions.prototype.useEmulator>;
24+
// type UseEmulatorArguments = Parameters<typeof Functions.prototype.useEmulator>;
2625
type UseEmulatorArguments = [string, number];
2726
export const USE_EMULATOR = new InjectionToken<UseEmulatorArguments>('angularfire2.functions.use-emulator');
2827

2928
// override httpsCallable for compatibility with 5.x
30-
export interface AngularFireFunctions extends Omit<ɵPromiseProxy<firebase.functions.Functions>, 'httpsCallable'> {
29+
export interface AngularFireFunctions extends Omit<ɵPromiseProxy<Functions>, 'httpsCallable'> {
3130
}
3231

3332
@Injectable({
@@ -42,8 +41,10 @@ export class AngularFireFunctions {
4241
@Optional() @Inject(FIREBASE_APP_NAME) nameOrConfig: string | FirebaseAppConfig | null | undefined,
4342
zone: NgZone,
4443
@Optional() @Inject(REGION) region: string | null,
45-
@Optional() @Inject(ORIGIN) origin: string | null,
46-
@Optional() @Inject(NEW_ORIGIN_BEHAVIOR) newOriginBehavior: boolean | null,
44+
// MARK: Breaking change
45+
// Removed: Origin has been removed?
46+
// @Optional() @Inject(ORIGIN) origin: string | null,
47+
// @Optional() @Inject(NEW_ORIGIN_BEHAVIOR) newOriginBehavior: boolean | null,
4748
@Optional() @Inject(USE_EMULATOR) _useEmulator: any, // can't use the tuple here
4849
) {
4950
const schedulers = new ɵAngularFireSchedulers(zone);
@@ -54,20 +55,10 @@ export class AngularFireFunctions {
5455
switchMap(() => import('firebase/functions')),
5556
map(() => ɵfirebaseAppFactory(options, zone, nameOrConfig)),
5657
map(app => ɵfetchInstance(`${app.name}.functions.${region || origin}`, 'AngularFireFunctions', app, () => {
57-
let functions: firebase.functions.Functions;
58-
if (newOriginBehavior) {
59-
if (region && origin) {
60-
throw new Error('REGION and ORIGIN can\'t be used at the same time.');
61-
}
62-
functions = app.functions(region || origin || undefined);
63-
} else {
64-
functions = app.functions(region || undefined);
65-
}
66-
if (!newOriginBehavior && !useEmulator && origin) {
67-
functions.useFunctionsEmulator(origin);
68-
}
58+
const functions = getFunctions(app, region || undefined);
6959
if (useEmulator) {
70-
functions.useEmulator(...useEmulator);
60+
const [host, port] = useEmulator;
61+
useFunctionsEmulator(functions, host, port);
7162
}
7263
return functions;
7364
}, [region, origin, useEmulator])),
@@ -77,7 +68,7 @@ export class AngularFireFunctions {
7768
this.httpsCallable = <T = any, R = any>(name: string, options?: HttpsCallableOptions) =>
7869
(data: T) => from(functions).pipe(
7970
observeOn(schedulers.insideAngular),
80-
switchMap(functions => functions.httpsCallable(name, options)(data)),
71+
switchMap(functions => httpsCallable(functions, name, options)(data)),
8172
map(r => r.data as R)
8273
);
8374

src/functions/public_api.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
2-
import 'firebase/functions'; // removed in build process when not UMD
3-
41
export * from './functions';
52
export * from './functions.module';

0 commit comments

Comments
 (0)