1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
'use strict';
var util = require('@firebase/util');
var component = require('@firebase/component');
var modularAPIs = require('@firebase/app');
var logger$1 = require('@firebase/logger');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var modularAPIs__namespace = /*#__PURE__*/_interopNamespace(modularAPIs);
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Global context object for a collection of services using
* a shared authentication state.
*
* marked as internal because it references internal types exported from @firebase/app
* @internal
*/
class FirebaseAppImpl {
constructor(_delegate, firebase) {
this._delegate = _delegate;
this.firebase = firebase;
// add itself to container
modularAPIs._addComponent(_delegate, new component.Component('app-compat', () => this, "PUBLIC" /* ComponentType.PUBLIC */));
this.container = _delegate.container;
}
get automaticDataCollectionEnabled() {
return this._delegate.automaticDataCollectionEnabled;
}
set automaticDataCollectionEnabled(val) {
this._delegate.automaticDataCollectionEnabled = val;
}
get name() {
return this._delegate.name;
}
get options() {
return this._delegate.options;
}
delete() {
return new Promise(resolve => {
this._delegate.checkDestroyed();
resolve();
}).then(() => {
this.firebase.INTERNAL.removeApp(this.name);
return modularAPIs.deleteApp(this._delegate);
});
}
/**
* Return a service instance associated with this app (creating it
* on demand), identified by the passed instanceIdentifier.
*
* NOTE: Currently storage and functions are the only ones that are leveraging this
* functionality. They invoke it by calling:
*
* ```javascript
* firebase.app().storage('STORAGE BUCKET ID')
* ```
*
* The service name is passed to this already
* @internal
*/
_getService(name, instanceIdentifier = modularAPIs._DEFAULT_ENTRY_NAME) {
this._delegate.checkDestroyed();
// Initialize instance if InstantiationMode is `EXPLICIT`.
const provider = this._delegate.container.getProvider(name);
if (!provider.isInitialized() &&
provider.getComponent()?.instantiationMode === "EXPLICIT" /* InstantiationMode.EXPLICIT */) {
provider.initialize();
}
// getImmediate will always succeed because _getService is only called for registered components.
return provider.getImmediate({
identifier: instanceIdentifier
});
}
/**
* Remove a service instance from the cache, so we will create a new instance for this service
* when people try to get it again.
*
* NOTE: currently only firestore uses this functionality to support firestore shutdown.
*
* @param name The service name
* @param instanceIdentifier instance identifier in case multiple instances are allowed
* @internal
*/
_removeServiceInstance(name, instanceIdentifier = modularAPIs._DEFAULT_ENTRY_NAME) {
this._delegate.container
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.getProvider(name)
.clearInstance(instanceIdentifier);
}
/**
* @param component the component being added to this app's container
* @internal
*/
_addComponent(component) {
modularAPIs._addComponent(this._delegate, component);
}
_addOrOverwriteComponent(component) {
modularAPIs._addOrOverwriteComponent(this._delegate, component);
}
toJSON() {
return {
name: this.name,
automaticDataCollectionEnabled: this.automaticDataCollectionEnabled,
options: this.options
};
}
}
// TODO: investigate why the following needs to be commented out
// Prevent dead-code elimination of these methods w/o invalid property
// copying.
// (FirebaseAppImpl.prototype.name && FirebaseAppImpl.prototype.options) ||
// FirebaseAppImpl.prototype.delete ||
// console.log('dc');
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const ERRORS = {
["no-app" /* AppError.NO_APP */]: "No Firebase App '{$appName}' has been created - " +
'call Firebase App.initializeApp()',
["invalid-app-argument" /* AppError.INVALID_APP_ARGUMENT */]: 'firebase.{$appName}() takes either no argument or a ' +
'Firebase App instance.'
};
const ERROR_FACTORY = new util.ErrorFactory('app-compat', 'Firebase', ERRORS);
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Because auth can't share code with other components, we attach the utility functions
* in an internal namespace to share code.
* This function return a firebase namespace object without
* any utility functions, so it can be shared between the regular firebaseNamespace and
* the lite version.
*/
function createFirebaseNamespaceCore(firebaseAppImpl) {
const apps = {};
// // eslint-disable-next-line @typescript-eslint/no-explicit-any
// const components = new Map<string, Component<any>>();
// A namespace is a plain JavaScript Object.
const namespace = {
// Hack to prevent Babel from modifying the object returned
// as the firebase namespace.
// @ts-ignore
__esModule: true,
initializeApp: initializeAppCompat,
// @ts-ignore
app,
registerVersion: modularAPIs__namespace.registerVersion,
setLogLevel: modularAPIs__namespace.setLogLevel,
onLog: modularAPIs__namespace.onLog,
// @ts-ignore
apps: null,
SDK_VERSION: modularAPIs__namespace.SDK_VERSION,
INTERNAL: {
registerComponent: registerComponentCompat,
removeApp,
useAsService,
modularAPIs: modularAPIs__namespace
}
};
// Inject a circular default export to allow Babel users who were previously
// using:
//
// import firebase from 'firebase';
// which becomes: var firebase = require('firebase').default;
//
// instead of
//
// import * as firebase from 'firebase';
// which becomes: var firebase = require('firebase');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
namespace['default'] = namespace;
// firebase.apps is a read-only getter.
Object.defineProperty(namespace, 'apps', {
get: getApps
});
/**
* Called by App.delete() - but before any services associated with the App
* are deleted.
*/
function removeApp(name) {
delete apps[name];
}
/**
* Get the App object for a given name (or DEFAULT).
*/
function app(name) {
name = name || modularAPIs__namespace._DEFAULT_ENTRY_NAME;
if (!util.contains(apps, name)) {
throw ERROR_FACTORY.create("no-app" /* AppError.NO_APP */, { appName: name });
}
return apps[name];
}
// @ts-ignore
app['App'] = firebaseAppImpl;
/**
* Create a new App instance (name must be unique).
*
* This function is idempotent. It can be called more than once and return the same instance using the same options and config.
*/
function initializeAppCompat(options, rawConfig = {}) {
const app = modularAPIs__namespace.initializeApp(options, rawConfig);
if (util.contains(apps, app.name)) {
return apps[app.name];
}
const appCompat = new firebaseAppImpl(app, namespace);
apps[app.name] = appCompat;
return appCompat;
}
/*
* Return an array of all the non-deleted FirebaseApps.
*/
function getApps() {
// Make a copy so caller cannot mutate the apps list.
return Object.keys(apps).map(name => apps[name]);
}
function registerComponentCompat(component) {
const componentName = component.name;
const componentNameWithoutCompat = componentName.replace('-compat', '');
if (modularAPIs__namespace._registerComponent(component) &&
component.type === "PUBLIC" /* ComponentType.PUBLIC */) {
// create service namespace for public components
// The Service namespace is an accessor function ...
const serviceNamespace = (appArg = app()) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (typeof appArg[componentNameWithoutCompat] !== 'function') {
// Invalid argument.
// This happens in the following case: firebase.storage('gs:/')
throw ERROR_FACTORY.create("invalid-app-argument" /* AppError.INVALID_APP_ARGUMENT */, {
appName: componentName
});
}
// Forward service instance lookup to the FirebaseApp.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return appArg[componentNameWithoutCompat]();
};
// ... and a container for service-level properties.
if (component.serviceProps !== undefined) {
util.deepExtend(serviceNamespace, component.serviceProps);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
namespace[componentNameWithoutCompat] = serviceNamespace;
// Patch the FirebaseAppImpl prototype
// eslint-disable-next-line @typescript-eslint/no-explicit-any
firebaseAppImpl.prototype[componentNameWithoutCompat] =
// TODO: The eslint disable can be removed and the 'ignoreRestArgs'
// option added to the no-explicit-any rule when ESlint releases it.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function (...args) {
const serviceFxn = this._getService.bind(this, componentName);
return serviceFxn.apply(this, component.multipleInstances ? args : []);
};
}
return component.type === "PUBLIC" /* ComponentType.PUBLIC */
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
namespace[componentNameWithoutCompat]
: null;
}
// Map the requested service to a registered service name
// (used to map auth to serverAuth service when needed).
function useAsService(app, name) {
if (name === 'serverAuth') {
return null;
}
const useService = name;
return useService;
}
return namespace;
}
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Return a firebase namespace object.
*
* In production, this will be called exactly once and the result
* assigned to the 'firebase' global. It may be called multiple times
* in unit tests.
*/
function createFirebaseNamespace() {
const namespace = createFirebaseNamespaceCore(FirebaseAppImpl);
namespace.INTERNAL = {
...namespace.INTERNAL,
createFirebaseNamespace,
extendNamespace,
createSubscribe: util.createSubscribe,
ErrorFactory: util.ErrorFactory,
deepExtend: util.deepExtend
};
/**
* Patch the top-level firebase namespace with additional properties.
*
* firebase.INTERNAL.extendNamespace()
*/
function extendNamespace(props) {
util.deepExtend(namespace, props);
}
return namespace;
}
const firebase$1 = createFirebaseNamespace();
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const logger = new logger$1.Logger('@firebase/app-compat');
const name = "@firebase/app-compat";
const version = "0.5.5";
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function registerCoreComponents(variant) {
// Register `app` package.
modularAPIs.registerVersion(name, version, variant);
}
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
try {
const globals = util.getGlobal();
// Firebase Lite detection
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (globals.firebase !== undefined) {
logger.warn(`
Warning: Firebase is already defined in the global scope. Please make sure
Firebase library is only loaded once.
`);
// eslint-disable-next-line
const sdkVersion = globals.firebase
.SDK_VERSION;
if (sdkVersion && sdkVersion.indexOf('LITE') >= 0) {
logger.warn(`
Warning: You are trying to load Firebase while using Firebase Performance standalone script.
You should load Firebase Performance with this instance of Firebase to avoid loading duplicate code.
`);
}
}
}
catch {
// ignore errors thrown by getGlobal
}
const firebase = firebase$1;
registerCoreComponents();
module.exports = firebase;
//# sourceMappingURL=index.cjs.js.map
|