@@ -12,22 +12,21 @@ import {
12
12
ɵPromiseProxy ,
13
13
ɵapplyMixins
14
14
} from '@angular/fire' ;
15
- import firebase from 'firebase/app' ;
16
15
import { proxyPolyfillCompat } from './base' ;
17
- import { HttpsCallableOptions } from '@ firebase/functions-types ' ;
16
+ import { HttpsCallableOptions , Functions , useFunctionsEmulator , httpsCallable , getFunctions } from 'firebase/functions' ;
18
17
import { ɵfetchInstance } from '@angular/fire' ;
19
18
20
19
export const ORIGIN = new InjectionToken < string > ( 'angularfire2.functions.origin' ) ;
21
20
export const REGION = new InjectionToken < string > ( 'angularfire2.functions.region' ) ;
22
21
export const NEW_ORIGIN_BEHAVIOR = new InjectionToken < boolean > ( 'angularfire2.functions.new-origin-behavior' ) ;
23
22
24
23
// 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>;
26
25
type UseEmulatorArguments = [ string , number ] ;
27
26
export const USE_EMULATOR = new InjectionToken < UseEmulatorArguments > ( 'angularfire2.functions.use-emulator' ) ;
28
27
29
28
// 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' > {
31
30
}
32
31
33
32
@Injectable ( {
@@ -42,8 +41,10 @@ export class AngularFireFunctions {
42
41
@Optional ( ) @Inject ( FIREBASE_APP_NAME ) nameOrConfig : string | FirebaseAppConfig | null | undefined ,
43
42
zone : NgZone ,
44
43
@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,
47
48
@Optional ( ) @Inject ( USE_EMULATOR ) _useEmulator : any , // can't use the tuple here
48
49
) {
49
50
const schedulers = new ɵAngularFireSchedulers ( zone ) ;
@@ -54,20 +55,10 @@ export class AngularFireFunctions {
54
55
switchMap ( ( ) => import ( 'firebase/functions' ) ) ,
55
56
map ( ( ) => ɵfirebaseAppFactory ( options , zone , nameOrConfig ) ) ,
56
57
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 ) ;
69
59
if ( useEmulator ) {
70
- functions . useEmulator ( ...useEmulator ) ;
60
+ const [ host , port ] = useEmulator ;
61
+ useFunctionsEmulator ( functions , host , port ) ;
71
62
}
72
63
return functions ;
73
64
} , [ region , origin , useEmulator ] ) ) ,
@@ -77,7 +68,7 @@ export class AngularFireFunctions {
77
68
this . httpsCallable = < T = any , R = any > ( name : string , options ?: HttpsCallableOptions ) =>
78
69
( data : T ) => from ( functions ) . pipe (
79
70
observeOn ( schedulers . insideAngular ) ,
80
- switchMap ( functions => functions . httpsCallable ( name , options ) ( data ) ) ,
71
+ switchMap ( functions => httpsCallable ( functions , name , options ) ( data ) ) ,
81
72
map ( r => r . data as R )
82
73
) ;
83
74
0 commit comments