UNPKG

4.1 kBJavaScriptView Raw
1
2import * as i0 from '@angular/core';
3import { InjectionToken, Injectable, Inject, Optional, NgZone, NgModule } from '@angular/core';
4import { of, from } from 'rxjs';
5import { observeOn, switchMap, map, shareReplay } from 'rxjs/operators';
6import * as i1 from '@angular/fire';
7import { ɵAngularFireSchedulers, ɵfirebaseAppFactory, ɵfetchInstance, ɵlazySDKProxy, FIREBASE_OPTIONS, FIREBASE_APP_NAME, ɵapplyMixins } from '@angular/fire';
8
9const proxyPolyfillCompat = {
10 useEmulator: null,
11 useFunctionsEmulator: null,
12 httpsCallable: null,
13};
14
15const ORIGIN = new InjectionToken('angularfire2.functions.origin');
16const REGION = new InjectionToken('angularfire2.functions.region');
17const NEW_ORIGIN_BEHAVIOR = new InjectionToken('angularfire2.functions.new-origin-behavior');
18const USE_EMULATOR = new InjectionToken('angularfire2.functions.use-emulator');
19class 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/** @nocollapse */ 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" });
47AngularFireFunctions.decorators = [
48 { type: Injectable, args: [{
49 providedIn: 'any'
50 },] }
51];
52/** @nocollapse */
53AngularFireFunctions.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
64class AngularFireFunctionsModule {
65}
66AngularFireFunctionsModule.decorators = [
67 { type: NgModule, args: [{
68 providers: [AngularFireFunctions]
69 },] }
70];
71
72/**
73 * Generated bundle index. Do not edit.
74 */
75
76export { AngularFireFunctions, AngularFireFunctionsModule, NEW_ORIGIN_BEHAVIOR, ORIGIN, REGION, USE_EMULATOR };
77//# sourceMappingURL=angular-fire-functions.js.map