暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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