1 | import { queueScheduler, asyncScheduler } from 'rxjs';
|
2 | import { tap, subscribeOn, observeOn } from 'rxjs/operators';
|
3 | import { InjectionToken, Version, isDevMode, NgZone, Optional, VERSION as VERSION$1, NgModule, Inject, PLATFORM_ID } from '@angular/core';
|
4 | import firebase from 'firebase/app';
|
5 |
|
6 | function noop() {
|
7 | }
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | class ɵZoneScheduler {
|
13 | constructor(zone, delegate = queueScheduler) {
|
14 | this.zone = zone;
|
15 | this.delegate = delegate;
|
16 | }
|
17 | now() {
|
18 | return this.delegate.now();
|
19 | }
|
20 | schedule(work, delay, state) {
|
21 | const targetZone = this.zone;
|
22 |
|
23 |
|
24 | const workInZone = function (state) {
|
25 | targetZone.runGuarded(() => {
|
26 | work.apply(this, [state]);
|
27 | });
|
28 | };
|
29 |
|
30 |
|
31 |
|
32 | return this.delegate.schedule(workInZone, delay, state);
|
33 | }
|
34 | }
|
35 |
|
36 | class ɵBlockUntilFirstOperator {
|
37 | constructor(zone) {
|
38 | this.zone = zone;
|
39 | this.task = null;
|
40 | }
|
41 | call(subscriber, source) {
|
42 | const unscheduleTask = this.unscheduleTask.bind(this);
|
43 | this.task = this.zone.run(() => Zone.current.scheduleMacroTask('firebaseZoneBlock', noop, {}, noop, noop));
|
44 | return source.pipe(tap({ next: unscheduleTask, complete: unscheduleTask, error: unscheduleTask })).subscribe(subscriber).add(unscheduleTask);
|
45 | }
|
46 | unscheduleTask() {
|
47 |
|
48 |
|
49 | setTimeout(() => {
|
50 | if (this.task != null && this.task.state === 'scheduled') {
|
51 | this.task.invoke();
|
52 | this.task = null;
|
53 | }
|
54 | }, 10);
|
55 | }
|
56 | }
|
57 |
|
58 | class ɵAngularFireSchedulers {
|
59 | constructor(ngZone) {
|
60 | this.ngZone = ngZone;
|
61 | this.outsideAngular = ngZone.runOutsideAngular(() => new ɵZoneScheduler(Zone.current));
|
62 | this.insideAngular = ngZone.run(() => new ɵZoneScheduler(Zone.current, asyncScheduler));
|
63 | }
|
64 | }
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | function ɵkeepUnstableUntilFirstFactory(schedulers) {
|
72 | return function keepUnstableUntilFirst(obs$) {
|
73 | obs$ = obs$.lift(new ɵBlockUntilFirstOperator(schedulers.ngZone));
|
74 | return obs$.pipe(
|
75 |
|
76 | subscribeOn(schedulers.outsideAngular),
|
77 |
|
78 | observeOn(schedulers.insideAngular)
|
79 |
|
80 |
|
81 | );
|
82 | };
|
83 | }
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 | const noopFunctions = ['ngOnDestroy'];
|
92 |
|
93 |
|
94 | const ɵlazySDKProxy = (klass, observable, zone, options = {}) => {
|
95 | return new Proxy(klass, {
|
96 | get: (_, name) => zone.runOutsideAngular(() => {
|
97 | var _a;
|
98 | if (klass[name]) {
|
99 | if ((_a = options === null || options === void 0 ? void 0 : options.spy) === null || _a === void 0 ? void 0 : _a.get) {
|
100 | options.spy.get(name, klass[name]);
|
101 | }
|
102 | return klass[name];
|
103 | }
|
104 | if (noopFunctions.indexOf(name) > -1) {
|
105 | return () => {
|
106 | };
|
107 | }
|
108 | const promise = observable.toPromise().then(mod => {
|
109 | const ret = mod && mod[name];
|
110 |
|
111 | if (typeof ret === 'function') {
|
112 | return ret.bind(mod);
|
113 | }
|
114 | else if (ret && ret.then) {
|
115 | return ret.then((res) => zone.run(() => res));
|
116 | }
|
117 | else {
|
118 | return zone.run(() => ret);
|
119 | }
|
120 | });
|
121 |
|
122 | return new Proxy(() => { }, {
|
123 | get: (_, name) => promise[name],
|
124 | // TODO handle callbacks as transparently as I can
|
125 | apply: (self, _, args) => promise.then(it => {
|
126 | var _a;
|
127 | const res = it && it(...args);
|
128 | if ((_a = options === null || options === void 0 ? void 0 : options.spy) === null || _a === void 0 ? void 0 : _a.apply) {
|
129 | options.spy.apply(name, args, res);
|
130 | }
|
131 | return res;
|
132 | })
|
133 | });
|
134 | })
|
135 | });
|
136 | };
|
137 | const ɵapplyMixins = (derivedCtor, constructors) => {
|
138 | constructors.forEach((baseCtor) => {
|
139 | Object.getOwnPropertyNames(baseCtor.prototype || baseCtor).forEach((name) => {
|
140 | Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype || baseCtor, name));
|
141 | });
|
142 | });
|
143 | };
|
144 |
|
145 | const FIREBASE_OPTIONS = new InjectionToken('angularfire2.app.options');
|
146 | const FIREBASE_APP_NAME = new InjectionToken('angularfire2.app.nameOrConfig');
|
147 |
|
148 |
|
149 | class FirebaseApp {
|
150 | }
|
151 | const VERSION = new Version('6.1.5');
|
152 | function ɵfirebaseAppFactory(options, zone, nameOrConfig) {
|
153 | const name = typeof nameOrConfig === 'string' && nameOrConfig || '[DEFAULT]';
|
154 | const config = typeof nameOrConfig === 'object' && nameOrConfig || {};
|
155 | config.name = config.name || name;
|
156 |
|
157 | const existingApp = firebase.apps.filter(app => app && app.name === config.name)[0];
|
158 |
|
159 |
|
160 | const app = (existingApp || zone.runOutsideAngular(() => firebase.initializeApp(options, config)));
|
161 | try {
|
162 | if (JSON.stringify(options) !== JSON.stringify(app.options)) {
|
163 | const hmr = !!module.hot;
|
164 | log('error', `${app.name} Firebase App already initialized with different options${hmr ? ', you may need to reload as Firebase is not HMR aware.' : '.'}`);
|
165 | }
|
166 | }
|
167 | catch (e) { }
|
168 | return app;
|
169 | }
|
170 | const ɵlogAuthEmulatorError = () => {
|
171 |
|
172 | log('warn', 'You may need to import \'firebase/auth\' manually in your component rather than rely on AngularFireAuth\'s dynamic import, when using the emulator suite https://github.com/angular/angularfire/issues/2656');
|
173 | };
|
174 | const log = (level, ...args) => {
|
175 | if (isDevMode() && typeof console !== 'undefined') {
|
176 | console[level](...args);
|
177 | }
|
178 | };
|
179 | const ɵ0 = log;
|
180 | globalThis.ɵAngularfireInstanceCache || (globalThis.ɵAngularfireInstanceCache = new Map());
|
181 | function ɵfetchInstance(cacheKey, moduleName, app, fn, args) {
|
182 | const [instance, ...cachedArgs] = globalThis.ɵAngularfireInstanceCache.get(cacheKey) || [];
|
183 | if (instance) {
|
184 | try {
|
185 | if (args.some((arg, i) => {
|
186 | const cachedArg = cachedArgs[i];
|
187 | if (arg && typeof arg === 'object') {
|
188 | return JSON.stringify(arg) !== JSON.stringify(cachedArg);
|
189 | }
|
190 | else {
|
191 | return arg !== cachedArg;
|
192 | }
|
193 | })) {
|
194 | const hmr = !!module.hot;
|
195 | log('error', `${moduleName} was already initialized on the ${app.name} Firebase App instance with different settings.${hmr ? ' You may need to reload as Firebase is not HMR aware.' : ''}`);
|
196 | }
|
197 | }
|
198 | catch (e) { }
|
199 | return instance;
|
200 | }
|
201 | else {
|
202 | const newInstance = fn();
|
203 | globalThis.ɵAngularfireInstanceCache.set(cacheKey, [newInstance, ...args]);
|
204 | return newInstance;
|
205 | }
|
206 | }
|
207 | const FIREBASE_APP_PROVIDER = {
|
208 | provide: FirebaseApp,
|
209 | useFactory: ɵfirebaseAppFactory,
|
210 | deps: [
|
211 | FIREBASE_OPTIONS,
|
212 | NgZone,
|
213 | [new Optional(), FIREBASE_APP_NAME]
|
214 | ]
|
215 | };
|
216 | class AngularFireModule {
|
217 |
|
218 | constructor(platformId) {
|
219 | firebase.registerVersion('angularfire', VERSION.full, platformId.toString());
|
220 | firebase.registerVersion('angular', VERSION$1.full);
|
221 | }
|
222 | static initializeApp(options, nameOrConfig) {
|
223 | return {
|
224 | ngModule: AngularFireModule,
|
225 | providers: [
|
226 | { provide: FIREBASE_OPTIONS, useValue: options },
|
227 | { provide: FIREBASE_APP_NAME, useValue: nameOrConfig }
|
228 | ]
|
229 | };
|
230 | }
|
231 | }
|
232 | AngularFireModule.decorators = [
|
233 | { type: NgModule, args: [{
|
234 | providers: [FIREBASE_APP_PROVIDER]
|
235 | },] }
|
236 | ];
|
237 |
|
238 | AngularFireModule.ctorParameters = () => [
|
239 | { type: Object, decorators: [{ type: Inject, args: [PLATFORM_ID,] }] }
|
240 | ];
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 | export { AngularFireModule, FIREBASE_APP_NAME, FIREBASE_OPTIONS, FirebaseApp, VERSION, ɵ0, ɵAngularFireSchedulers, ɵBlockUntilFirstOperator, ɵZoneScheduler, ɵapplyMixins, ɵfetchInstance, ɵfirebaseAppFactory, ɵkeepUnstableUntilFirstFactory, ɵlazySDKProxy, ɵlogAuthEmulatorError };
|
247 |
|