1 | import * as i0 from '@angular/core';
|
2 | import { InjectionToken, isDevMode, NgZone, Optional, VERSION as VERSION$1, PLATFORM_ID, NgModule, Inject } from '@angular/core';
|
3 | import firebase from 'firebase/compat/app';
|
4 | import { VERSION } from '@angular/fire';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | const noopFunctions = ['ngOnDestroy'];
|
14 |
|
15 |
|
16 | const ɵlazySDKProxy = (klass, observable, zone, options = {}) => {
|
17 | return new Proxy(klass, {
|
18 | get: (_, name) => zone.runOutsideAngular(() => {
|
19 | var _a;
|
20 | if (klass[name]) {
|
21 | if ((_a = options === null || options === void 0 ? void 0 : options.spy) === null || _a === void 0 ? void 0 : _a.get) {
|
22 | options.spy.get(name, klass[name]);
|
23 | }
|
24 | return klass[name];
|
25 | }
|
26 | if (noopFunctions.indexOf(name) > -1) {
|
27 | return () => {
|
28 | };
|
29 | }
|
30 | const promise = observable.toPromise().then(mod => {
|
31 | const ret = mod && mod[name];
|
32 |
|
33 | if (typeof ret === 'function') {
|
34 | return ret.bind(mod);
|
35 | }
|
36 | else if (ret && ret.then) {
|
37 | return ret.then((res) => zone.run(() => res));
|
38 | }
|
39 | else {
|
40 | return zone.run(() => ret);
|
41 | }
|
42 | });
|
43 |
|
44 | return new Proxy(() => { }, {
|
45 | get: (_, name) => promise[name],
|
46 | // TODO handle callbacks as transparently as I can
|
47 | apply: (self, _, args) => promise.then(it => {
|
48 | var _a;
|
49 | const res = it && it(...args);
|
50 | if ((_a = options === null || options === void 0 ? void 0 : options.spy) === null || _a === void 0 ? void 0 : _a.apply) {
|
51 | options.spy.apply(name, args, res);
|
52 | }
|
53 | return res;
|
54 | })
|
55 | });
|
56 | })
|
57 | });
|
58 | };
|
59 | const ɵapplyMixins = (derivedCtor, constructors) => {
|
60 | constructors.forEach((baseCtor) => {
|
61 | Object.getOwnPropertyNames(baseCtor.prototype || baseCtor).forEach((name) => {
|
62 | Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype || baseCtor, name));
|
63 | });
|
64 | });
|
65 | };
|
66 |
|
67 | class FirebaseApp {
|
68 | constructor(app) {
|
69 | return app;
|
70 | }
|
71 | }
|
72 |
|
73 | const FIREBASE_OPTIONS = new InjectionToken('angularfire2.app.options');
|
74 | const FIREBASE_APP_NAME = new InjectionToken('angularfire2.app.name');
|
75 | function ɵfirebaseAppFactory(options, zone, nameOrConfig) {
|
76 | const name = typeof nameOrConfig === 'string' && nameOrConfig || '[DEFAULT]';
|
77 | const config = typeof nameOrConfig === 'object' && nameOrConfig || {};
|
78 | config.name = config.name || name;
|
79 |
|
80 | const existingApp = firebase.apps.filter(app => app && app.name === config.name)[0];
|
81 |
|
82 |
|
83 | const app = (existingApp || zone.runOutsideAngular(() => firebase.initializeApp(options, config)));
|
84 | try {
|
85 | if (JSON.stringify(options) !== JSON.stringify(app.options)) {
|
86 | const hmr = !!module.hot;
|
87 | log$1('error', `${app.name} Firebase App already initialized with different options${hmr ? ', you may need to reload as Firebase is not HMR aware.' : '.'}`);
|
88 | }
|
89 | }
|
90 | catch (e) { }
|
91 | return new FirebaseApp(app);
|
92 | }
|
93 | const log$1 = (level, ...args) => {
|
94 | if (isDevMode() && typeof console !== 'undefined') {
|
95 | console[level](...args);
|
96 | }
|
97 | };
|
98 | const FIREBASE_APP_PROVIDER = {
|
99 | provide: FirebaseApp,
|
100 | useFactory: ɵfirebaseAppFactory,
|
101 | deps: [
|
102 | FIREBASE_OPTIONS,
|
103 | NgZone,
|
104 | [new Optional(), FIREBASE_APP_NAME]
|
105 | ]
|
106 | };
|
107 | class AngularFireModule {
|
108 |
|
109 | constructor(platformId) {
|
110 | firebase.registerVersion('angularfire', VERSION.full, 'core');
|
111 | firebase.registerVersion('angularfire', VERSION.full, 'app-compat');
|
112 | firebase.registerVersion('angular', VERSION$1.full, platformId.toString());
|
113 | }
|
114 | static initializeApp(options, nameOrConfig) {
|
115 | return {
|
116 | ngModule: AngularFireModule,
|
117 | providers: [
|
118 | { provide: FIREBASE_OPTIONS, useValue: options },
|
119 | { provide: FIREBASE_APP_NAME, useValue: nameOrConfig }
|
120 | ]
|
121 | };
|
122 | }
|
123 | }
|
124 | AngularFireModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFireModule, deps: [{ token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.NgModule });
|
125 | AngularFireModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFireModule });
|
126 | AngularFireModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFireModule, providers: [FIREBASE_APP_PROVIDER] });
|
127 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFireModule, decorators: [{
|
128 | type: NgModule,
|
129 | args: [{
|
130 | providers: [FIREBASE_APP_PROVIDER]
|
131 | }]
|
132 | }], ctorParameters: function () { return [{ type: Object, decorators: [{
|
133 | type: Inject,
|
134 | args: [PLATFORM_ID]
|
135 | }] }]; } });
|
136 |
|
137 | function ɵcacheInstance(cacheKey, moduleName, appName, fn, deps) {
|
138 | const [, instance, cachedDeps] = globalThis.ɵAngularfireInstanceCache.find((it) => it[0] === cacheKey) || [];
|
139 | if (instance) {
|
140 | if (!matchDep(deps, cachedDeps)) {
|
141 | log('error', `${moduleName} was already initialized on the ${appName} Firebase App with different settings.${IS_HMR ? ' You may need to reload as Firebase is not HMR aware.' : ''}`);
|
142 | log('warn', { is: deps, was: cachedDeps });
|
143 | }
|
144 | return instance;
|
145 | }
|
146 | else {
|
147 | const newInstance = fn();
|
148 | globalThis.ɵAngularfireInstanceCache.push([cacheKey, newInstance, deps]);
|
149 | return newInstance;
|
150 | }
|
151 | }
|
152 | function matchDep(a, b) {
|
153 | try {
|
154 | return a.toString() === b.toString();
|
155 | }
|
156 | catch (_) {
|
157 | return a === b;
|
158 | }
|
159 | }
|
160 | const IS_HMR = !!module.hot;
|
161 | const log = (level, ...args) => {
|
162 | if (isDevMode() && typeof console !== 'undefined') {
|
163 | console[level](...args);
|
164 | }
|
165 | };
|
166 | globalThis.ɵAngularfireInstanceCache || (globalThis.ɵAngularfireInstanceCache = []);
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 | export { AngularFireModule, FIREBASE_APP_NAME, FIREBASE_OPTIONS, FirebaseApp, ɵapplyMixins, ɵcacheInstance, ɵfirebaseAppFactory, ɵlazySDKProxy };
|
173 |
|