/
index.esm.js
572 lines (563 loc) · 23.2 KB
/
index.esm.js
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
import { __assign } from 'tslib';
import { ErrorFactory, deepExtend, deepCopy, contains, createSubscribe, isBrowser, isNode } from '@firebase/util';
import { Logger } from '@firebase/logger';
/**
* @license
* Copyright 2019 Google Inc.
*
* 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.
*/
var _a;
var ERRORS = (_a = {},
_a["no-app" /* NO_APP */] = "No Firebase App '{$appName}' has been created - " +
'call Firebase App.initializeApp()',
_a["bad-app-name" /* BAD_APP_NAME */] = "Illegal App name: '{$appName}",
_a["duplicate-app" /* DUPLICATE_APP */] = "Firebase App named '{$appName}' already exists",
_a["app-deleted" /* APP_DELETED */] = "Firebase App named '{$appName}' already deleted",
_a["invalid-app-argument" /* INVALID_APP_ARGUMENT */] = 'firebase.{$appName}() takes either no argument or a ' +
'Firebase App instance.',
_a);
var ERROR_FACTORY = new ErrorFactory('app', 'Firebase', ERRORS);
/**
* @license
* Copyright 2019 Google Inc.
*
* 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.
*/
var DEFAULT_ENTRY_NAME = '[DEFAULT]';
/**
* @license
* Copyright 2017 Google Inc.
*
* 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.
*/
var FirebaseAppImpl = /** @class */ (function () {
function FirebaseAppImpl(options, config, firebase_) {
var _this = this;
this.firebase_ = firebase_;
this.isDeleted_ = false;
this.services_ = {};
// An array to capture listeners before the true auth functions
// exist
this.tokenListeners_ = [];
// An array to capture requests to send events before analytics component loads.
// eslint-disable-next-line @typescript-eslint/no-explicit-any, use any here to make using function.apply easier
this.analyticsEventRequests_ = [];
this.name_ = config.name;
this.automaticDataCollectionEnabled_ =
config.automaticDataCollectionEnabled || false;
this.options_ = deepCopy(options);
var self = this;
this.INTERNAL = {
getUid: function () { return null; },
getToken: function () { return Promise.resolve(null); },
addAuthTokenListener: function (callback) {
_this.tokenListeners_.push(callback);
// Make sure callback is called, asynchronously, in the absence of the auth module
setTimeout(function () { return callback(null); }, 0);
},
removeAuthTokenListener: function (callback) {
_this.tokenListeners_ = _this.tokenListeners_.filter(function (listener) { return listener !== callback; });
},
analytics: {
logEvent: function () {
self.analyticsEventRequests_.push(arguments);
}
}
};
}
Object.defineProperty(FirebaseAppImpl.prototype, "automaticDataCollectionEnabled", {
get: function () {
this.checkDestroyed_();
return this.automaticDataCollectionEnabled_;
},
set: function (val) {
this.checkDestroyed_();
this.automaticDataCollectionEnabled_ = val;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FirebaseAppImpl.prototype, "name", {
get: function () {
this.checkDestroyed_();
return this.name_;
},
enumerable: true,
configurable: true
});
Object.defineProperty(FirebaseAppImpl.prototype, "options", {
get: function () {
this.checkDestroyed_();
return this.options_;
},
enumerable: true,
configurable: true
});
FirebaseAppImpl.prototype.delete = function () {
var _this = this;
return new Promise(function (resolve) {
_this.checkDestroyed_();
resolve();
})
.then(function () {
_this.firebase_.INTERNAL.removeApp(_this.name_);
var services = [];
for (var _i = 0, _a = Object.keys(_this.services_); _i < _a.length; _i++) {
var serviceKey = _a[_i];
for (var _b = 0, _c = Object.keys(_this.services_[serviceKey]); _b < _c.length; _b++) {
var instanceKey = _c[_b];
services.push(_this.services_[serviceKey][instanceKey]);
}
}
return Promise.all(services
.filter(function (service) { return 'INTERNAL' in service; })
.map(function (service) { return service.INTERNAL.delete(); }));
})
.then(function () {
_this.isDeleted_ = true;
_this.services_ = {};
});
};
/**
* 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
*/
FirebaseAppImpl.prototype._getService = function (name, instanceIdentifier) {
if (instanceIdentifier === void 0) { instanceIdentifier = DEFAULT_ENTRY_NAME; }
this.checkDestroyed_();
if (!this.services_[name]) {
this.services_[name] = {};
}
if (!this.services_[name][instanceIdentifier]) {
/**
* If a custom instance has been defined (i.e. not '[DEFAULT]')
* then we will pass that instance on, otherwise we pass `null`
*/
var instanceSpecifier = instanceIdentifier !== DEFAULT_ENTRY_NAME
? instanceIdentifier
: undefined;
var service = this.firebase_.INTERNAL.factories[name](this, this.extendApp.bind(this), instanceSpecifier);
this.services_[name][instanceIdentifier] = service;
}
return this.services_[name][instanceIdentifier];
};
/**
* Remove a service instance from the cache, so we will create a new instance for this service
* when people try to get this service again.
*
* NOTE: currently only firestore is using this functionality to support firestore shutdown.
*
* @param name The service name
* @param instanceIdentifier instance identifier in case multiple instances are allowed
* @internal
*/
FirebaseAppImpl.prototype._removeServiceInstance = function (name, instanceIdentifier) {
if (instanceIdentifier === void 0) { instanceIdentifier = DEFAULT_ENTRY_NAME; }
if (this.services_[name] && this.services_[name][instanceIdentifier]) {
delete this.services_[name][instanceIdentifier];
}
};
/**
* Callback function used to extend an App instance at the time
* of service instance creation.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
FirebaseAppImpl.prototype.extendApp = function (props) {
// Copy the object onto the FirebaseAppImpl prototype
deepExtend(this, props);
if (props.INTERNAL) {
/**
* If the app has overwritten the addAuthTokenListener stub, forward
* the active token listeners on to the true fxn.
*
* TODO: This function is required due to our current module
* structure. Once we are able to rely strictly upon a single module
* implementation, this code should be refactored and Auth should
* provide these stubs and the upgrade logic
*/
if (props.INTERNAL.addAuthTokenListener) {
for (var _i = 0, _a = this.tokenListeners_; _i < _a.length; _i++) {
var listener = _a[_i];
this.INTERNAL.addAuthTokenListener(listener);
}
this.tokenListeners_ = [];
}
if (props.INTERNAL.analytics) {
for (var _b = 0, _c = this.analyticsEventRequests_; _b < _c.length; _b++) {
var request = _c[_b];
// logEvent is the actual implementation at this point.
// We forward the queued events to it.
this.INTERNAL.analytics.logEvent.apply(undefined, request);
}
this.analyticsEventRequests_ = [];
}
}
};
/**
* This function will throw an Error if the App has already been deleted -
* use before performing API actions on the App.
*/
FirebaseAppImpl.prototype.checkDestroyed_ = function () {
if (this.isDeleted_) {
throw ERROR_FACTORY.create("app-deleted" /* APP_DELETED */, { appName: this.name_ });
}
};
return FirebaseAppImpl;
}());
// Prevent dead-code elimination of these methods w/o invalid property
// copying.
(FirebaseAppImpl.prototype.name && FirebaseAppImpl.prototype.options) ||
FirebaseAppImpl.prototype.delete ||
console.log('dc');
var version = "7.0.0";
/**
* @license
* Copyright 2019 Google Inc.
*
* 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.
*/
var logger = new Logger('@firebase/app');
/**
* @license
* Copyright 2019 Google Inc.
*
* 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) {
var apps = {};
var factories = {};
var appHooks = {};
// A namespace is a plain JavaScript Object.
var namespace = {
// Hack to prevent Babel from modifying the object returned
// as the firebase namespace.
// @ts-ignore
__esModule: true,
initializeApp: initializeApp,
// @ts-ignore
app: app,
// @ts-ignore
apps: null,
SDK_VERSION: version,
INTERNAL: {
registerService: registerService,
removeApp: removeApp,
factories: factories,
useAsService: useAsService
}
};
// 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) {
var app = apps[name];
callAppHooks(app, 'delete');
delete apps[name];
}
/**
* Get the App object for a given name (or DEFAULT).
*/
function app(name) {
name = name || DEFAULT_ENTRY_NAME;
if (!contains(apps, name)) {
throw ERROR_FACTORY.create("no-app" /* NO_APP */, { appName: name });
}
return apps[name];
}
// @ts-ignore
app['App'] = firebaseAppImpl;
function initializeApp(options, rawConfig) {
if (rawConfig === void 0) { rawConfig = {}; }
if (typeof rawConfig !== 'object' || rawConfig === null) {
var name_1 = rawConfig;
rawConfig = { name: name_1 };
}
var config = rawConfig;
if (config.name === undefined) {
config.name = DEFAULT_ENTRY_NAME;
}
var name = config.name;
if (typeof name !== 'string' || !name) {
throw ERROR_FACTORY.create("bad-app-name" /* BAD_APP_NAME */, {
appName: String(name)
});
}
if (contains(apps, name)) {
throw ERROR_FACTORY.create("duplicate-app" /* DUPLICATE_APP */, { appName: name });
}
var app = new firebaseAppImpl(options, config, namespace);
apps[name] = app;
callAppHooks(app, 'create');
return app;
}
/*
* 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(function (name) { return apps[name]; });
}
/*
* Register a Firebase Service.
*
* firebase.INTERNAL.registerService()
*
* TODO: Implement serviceProperties.
*/
function registerService(name, createService, serviceProperties, appHook, allowMultipleInstances) {
if (allowMultipleInstances === void 0) { allowMultipleInstances = false; }
// If re-registering a service that already exists, return existing service
if (factories[name]) {
logger.debug("There were multiple attempts to register service " + name + ".");
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return namespace[name];
}
// Capture the service factory for later service instantiation
factories[name] = createService;
// Capture the appHook, if passed
if (appHook) {
appHooks[name] = appHook;
// Run the **new** app hook on all existing apps
getApps().forEach(function (app) {
appHook('create', app);
});
}
// The Service namespace is an accessor function ...
function serviceNamespace(appArg) {
if (appArg === void 0) { appArg = app(); }
// @ts-ignore
if (typeof appArg[name] !== 'function') {
// Invalid argument.
// This happens in the following case: firebase.storage('gs:/')
throw ERROR_FACTORY.create("invalid-app-argument" /* INVALID_APP_ARGUMENT */, {
appName: name
});
}
// Forward service instance lookup to the FirebaseApp.
// @ts-ignore
return appArg[name]();
}
// ... and a container for service-level properties.
if (serviceProperties !== undefined) {
deepExtend(serviceNamespace, serviceProperties);
}
// Monkey-patch the serviceNamespace onto the firebase namespace
// @ts-ignore
namespace[name] = serviceNamespace;
// Patch the FirebaseAppImpl prototype
// @ts-ignore
firebaseAppImpl.prototype[name] =
// 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 () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var serviceFxn = this._getService.bind(this, name);
return serviceFxn.apply(this, allowMultipleInstances ? args : []);
};
return serviceNamespace;
}
function callAppHooks(app, eventName) {
for (var _i = 0, _a = Object.keys(factories); _i < _a.length; _i++) {
var serviceName = _a[_i];
// Ignore virtual services
var factoryName = useAsService(app, serviceName);
if (factoryName === null) {
return;
}
if (appHooks[factoryName]) {
appHooks[factoryName](eventName, app);
}
}
}
// 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;
}
var useService = name;
return useService;
}
return namespace;
}
/**
* @license
* Copyright 2019 Google Inc.
*
* 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() {
var namespace = createFirebaseNamespaceCore(FirebaseAppImpl);
namespace.INTERNAL = __assign({}, namespace.INTERNAL, { createFirebaseNamespace: createFirebaseNamespace,
extendNamespace: extendNamespace,
createSubscribe: createSubscribe,
ErrorFactory: ErrorFactory,
deepExtend: deepExtend });
/**
* Patch the top-level firebase namespace with additional properties.
*
* firebase.INTERNAL.extendNamespace()
*/
function extendNamespace(props) {
deepExtend(namespace, props);
}
return namespace;
}
/**
* @license
* Copyright 2017 Google Inc.
*
* 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.
*/
// Firebase Lite detection
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (isBrowser() && self.firebase !== undefined) {
logger.warn("\n Warning: Firebase is already defined in the global scope. Please make sure\n Firebase library is only loaded once.\n ");
// eslint-disable-next-line
var sdkVersion = self.firebase.SDK_VERSION;
if (sdkVersion && sdkVersion.indexOf('LITE') >= 0) {
logger.warn("\n Warning: You are trying to load Firebase while using Firebase Performance standalone script.\n You should load Firebase Performance with this instance of Firebase to avoid loading duplicate code.\n ");
}
}
var firebaseNamespace = createFirebaseNamespace();
var initializeApp = firebaseNamespace.initializeApp;
// TODO: This 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
firebaseNamespace.initializeApp = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
// Environment check before initializing app
// Do the check in initializeApp, so people have a chance to disable it by setting logLevel
// in @firebase/logger
if (isNode()) {
logger.warn("\n Warning: This is a browser-targeted Firebase bundle but it appears it is being\n run in a Node environment. If running in a Node environment, make sure you\n are using the bundle specified by the \"main\" field in package.json.\n \n If you are using Webpack, you can specify \"main\" as the first item in\n \"resolve.mainFields\":\n https://webpack.js.org/configuration/resolve/#resolvemainfields\n \n If using Rollup, use the rollup-plugin-node-resolve plugin and specify \"main\"\n as the first item in \"mainFields\", e.g. ['main', 'module'].\n https://github.com/rollup/rollup-plugin-node-resolve\n ");
}
return initializeApp.apply(undefined, args);
};
var firebase = firebaseNamespace;
export default firebase;
export { firebase };
//# sourceMappingURL=index.esm.js.map