import { NgModule , Optional , NgZone , InjectionToken , ModuleWithProviders , Injector } from '@angular/core' ; import { Functions as FirebaseFunctions } from 'firebase/functions' ; import { ɵgetDefaultInstanceOf , ɵAngularFireSchedulers , VERSION } from '@angular/fire' ; import { Functions , FunctionsInstances , FUNCTIONS_PROVIDER_NAME } from './functions' ; import { FirebaseApps , FirebaseApp } from '@angular/fire/app' ; import { AuthInstances } from '@angular/fire/auth' ; import { registerVersion } from 'firebase/app' ; import { AppCheckInstances } from '@angular/fire/app-check' ; export const PROVIDED_FUNCTIONS_INSTANCES = new InjectionToken < Functions [ ] > ( 'angularfire2.functions-instances' ) ; export function defaultFunctionsInstanceFactory ( provided , defaultApp ) { const defaultAuth = ɵgetDefaultInstanceOf < FirebaseFunctions > ( FUNCTIONS_PROVIDER_NAME , provided , defaultApp ) ; return defaultAuth && new Functions ( defaultAuth ) ; } export function functionsInstanceFactory ( fn ) { return ( zone , injector ) => { const functions = zone . runOutsideAngular ( ( ) => fn ( injector ) ) ; return new Functions ( functions ) ; } ; } const FUNCTIONS_INSTANCES_PROVIDER = { provide : FunctionsInstances , deps : [ [ new Optional ( ) , PROVIDED_FUNCTIONS_INSTANCES ] , ] } ; const DEFAULT_FUNCTIONS_INSTANCE_PROVIDER = { provide : Functions , useFactory : defaultFunctionsInstanceFactory , deps : [ [ new Optional ( ) , PROVIDED_FUNCTIONS_INSTANCES ] , FirebaseApp , ] } ; @ NgModule ( { providers : [ DEFAULT_FUNCTIONS_INSTANCE_PROVIDER , FUNCTIONS_INSTANCES_PROVIDER , ] } ) export class FunctionsModule { constructor ( ) { registerVersion ( 'angularfire' , VERSION . full , 'fn' ) ; } } export function provideFunctions ( fn , ... deps ) { return { ngModule : FunctionsModule , providers : [ { provide : PROVIDED_FUNCTIONS_INSTANCES , useFactory : functionsInstanceFactory ( fn ) , multi : true , deps : [ NgZone , Injector , ɵAngularFireSchedulers , FirebaseApps , [ new Optional ( ) , AuthInstances ] , [ new Optional ( ) , AppCheckInstances ] , ... deps , ] } ] } ; }