1 |
|
2 | import * as i0 from '@angular/core';
|
3 | import { InjectionToken, Injectable, Inject, Optional, NgZone, NgModule } from '@angular/core';
|
4 | import { of, from } from 'rxjs';
|
5 | import { observeOn, switchMap, map, shareReplay } from 'rxjs/operators';
|
6 | import * as i1 from '@angular/fire';
|
7 | import { ɵAngularFireSchedulers, ɵfirebaseAppFactory, ɵfetchInstance, ɵlazySDKProxy, FIREBASE_OPTIONS, FIREBASE_APP_NAME, ɵapplyMixins } from '@angular/fire';
|
8 |
|
9 | const proxyPolyfillCompat = {
|
10 | useEmulator: null,
|
11 | useFunctionsEmulator: null,
|
12 | httpsCallable: null,
|
13 | };
|
14 |
|
15 | const ORIGIN = new InjectionToken('angularfire2.functions.origin');
|
16 | const REGION = new InjectionToken('angularfire2.functions.region');
|
17 | const NEW_ORIGIN_BEHAVIOR = new InjectionToken('angularfire2.functions.new-origin-behavior');
|
18 | const USE_EMULATOR = new InjectionToken('angularfire2.functions.use-emulator');
|
19 | class AngularFireFunctions {
|
20 | constructor(options, nameOrConfig, zone, region, origin, newOriginBehavior, _useEmulator) {
|
21 | const schedulers = new ɵAngularFireSchedulers(zone);
|
22 | const useEmulator = _useEmulator;
|
23 | const functions = of(undefined).pipe(observeOn(schedulers.outsideAngular), switchMap(() => import('firebase/functions')), map(() => ɵfirebaseAppFactory(options, zone, nameOrConfig)), map(app => ɵfetchInstance(`${app.name}.functions.${region || origin}`, 'AngularFireFunctions', app, () => {
|
24 | let functions;
|
25 | if (newOriginBehavior) {
|
26 | if (region && origin) {
|
27 | throw new Error('REGION and ORIGIN can\'t be used at the same time.');
|
28 | }
|
29 | functions = app.functions(region || origin || undefined);
|
30 | }
|
31 | else {
|
32 | functions = app.functions(region || undefined);
|
33 | }
|
34 | if (!newOriginBehavior && !useEmulator && origin) {
|
35 | functions.useFunctionsEmulator(origin);
|
36 | }
|
37 | if (useEmulator) {
|
38 | functions.useEmulator(...useEmulator);
|
39 | }
|
40 | return functions;
|
41 | }, [region, origin, useEmulator])), shareReplay({ bufferSize: 1, refCount: false }));
|
42 | this.httpsCallable = (name, options) => (data) => from(functions).pipe(observeOn(schedulers.insideAngular), switchMap(functions => functions.httpsCallable(name, options)(data)), map(r => r.data));
|
43 | return ɵlazySDKProxy(this, functions, zone);
|
44 | }
|
45 | }
|
46 | AngularFireFunctions.ɵprov = i0.ɵɵdefineInjectable({ factory: function AngularFireFunctions_Factory() { return new AngularFireFunctions(i0.ɵɵinject(i1.FIREBASE_OPTIONS), i0.ɵɵinject(i1.FIREBASE_APP_NAME, 8), i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(REGION, 8), i0.ɵɵinject(ORIGIN, 8), i0.ɵɵinject(NEW_ORIGIN_BEHAVIOR, 8), i0.ɵɵinject(USE_EMULATOR, 8)); }, token: AngularFireFunctions, providedIn: "any" });
|
47 | AngularFireFunctions.decorators = [
|
48 | { type: Injectable, args: [{
|
49 | providedIn: 'any'
|
50 | },] }
|
51 | ];
|
52 |
|
53 | AngularFireFunctions.ctorParameters = () => [
|
54 | { type: undefined, decorators: [{ type: Inject, args: [FIREBASE_OPTIONS,] }] },
|
55 | { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [FIREBASE_APP_NAME,] }] },
|
56 | { type: NgZone },
|
57 | { type: String, decorators: [{ type: Optional }, { type: Inject, args: [REGION,] }] },
|
58 | { type: String, decorators: [{ type: Optional }, { type: Inject, args: [ORIGIN,] }] },
|
59 | { type: Boolean, decorators: [{ type: Optional }, { type: Inject, args: [NEW_ORIGIN_BEHAVIOR,] }] },
|
60 | { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [USE_EMULATOR,] }] }
|
61 | ];
|
62 | ɵapplyMixins(AngularFireFunctions, [proxyPolyfillCompat]);
|
63 |
|
64 | class AngularFireFunctionsModule {
|
65 | }
|
66 | AngularFireFunctionsModule.decorators = [
|
67 | { type: NgModule, args: [{
|
68 | providers: [AngularFireFunctions]
|
69 | },] }
|
70 | ];
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | export { AngularFireFunctions, AngularFireFunctionsModule, NEW_ORIGIN_BEHAVIOR, ORIGIN, REGION, USE_EMULATOR };
|
77 |
|