Без опису
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. import * as modularAPIs from '@firebase/app';
  2. import { _addComponent, deleteApp, _DEFAULT_ENTRY_NAME, registerVersion } from '@firebase/app';
  3. import { Component } from '@firebase/component';
  4. import { ErrorFactory, contains, deepExtend } from '@firebase/util';
  5. /**
  6. * @license
  7. * Copyright 2019 Google LLC
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License");
  10. * you may not use this file except in compliance with the License.
  11. * You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing, software
  16. * distributed under the License is distributed on an "AS IS" BASIS,
  17. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. */
  21. /**
  22. * Global context object for a collection of services using
  23. * a shared authentication state.
  24. */
  25. class FirebaseAppLiteImpl {
  26. constructor(_delegate, firebase) {
  27. this._delegate = _delegate;
  28. this.firebase = firebase;
  29. // add itself to container
  30. _addComponent(_delegate, new Component('app-compat', () => this, "PUBLIC" /* ComponentType.PUBLIC */));
  31. }
  32. get automaticDataCollectionEnabled() {
  33. return this._delegate.automaticDataCollectionEnabled;
  34. }
  35. set automaticDataCollectionEnabled(val) {
  36. this.automaticDataCollectionEnabled = val;
  37. }
  38. get name() {
  39. return this._delegate.name;
  40. }
  41. get options() {
  42. return this._delegate.options;
  43. }
  44. delete() {
  45. this.firebase.INTERNAL.removeApp(this.name);
  46. return deleteApp(this._delegate);
  47. }
  48. /**
  49. * Return a service instance associated with this app (creating it
  50. * on demand), identified by the passed instanceIdentifier.
  51. *
  52. * NOTE: Currently storage is the only one that is leveraging this
  53. * functionality. They invoke it by calling:
  54. *
  55. * ```javascript
  56. * firebase.app().storage('STORAGE BUCKET ID')
  57. * ```
  58. *
  59. * The service name is passed to this already
  60. * @internal
  61. */
  62. _getService(name, instanceIdentifier = _DEFAULT_ENTRY_NAME) {
  63. this._delegate.checkDestroyed();
  64. // getImmediate will always succeed because _getService is only called for registered components.
  65. return this._delegate.container.getProvider(name).getImmediate({
  66. identifier: instanceIdentifier
  67. });
  68. }
  69. }
  70. /**
  71. * @license
  72. * Copyright 2019 Google LLC
  73. *
  74. * Licensed under the Apache License, Version 2.0 (the "License");
  75. * you may not use this file except in compliance with the License.
  76. * You may obtain a copy of the License at
  77. *
  78. * http://www.apache.org/licenses/LICENSE-2.0
  79. *
  80. * Unless required by applicable law or agreed to in writing, software
  81. * distributed under the License is distributed on an "AS IS" BASIS,
  82. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  83. * See the License for the specific language governing permissions and
  84. * limitations under the License.
  85. */
  86. const ERRORS = {
  87. ["no-app" /* AppError.NO_APP */]: "No Firebase App '{$appName}' has been created - " +
  88. 'call Firebase App.initializeApp()',
  89. ["invalid-app-argument" /* AppError.INVALID_APP_ARGUMENT */]: 'firebase.{$appName}() takes either no argument or a ' +
  90. 'Firebase App instance.'
  91. };
  92. const ERROR_FACTORY = new ErrorFactory('app-compat', 'Firebase', ERRORS);
  93. /**
  94. * @license
  95. * Copyright 2019 Google LLC
  96. *
  97. * Licensed under the Apache License, Version 2.0 (the "License");
  98. * you may not use this file except in compliance with the License.
  99. * You may obtain a copy of the License at
  100. *
  101. * http://www.apache.org/licenses/LICENSE-2.0
  102. *
  103. * Unless required by applicable law or agreed to in writing, software
  104. * distributed under the License is distributed on an "AS IS" BASIS,
  105. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  106. * See the License for the specific language governing permissions and
  107. * limitations under the License.
  108. */
  109. /**
  110. * Because auth can't share code with other components, we attach the utility functions
  111. * in an internal namespace to share code.
  112. * This function return a firebase namespace object without
  113. * any utility functions, so it can be shared between the regular firebaseNamespace and
  114. * the lite version.
  115. */
  116. function createFirebaseNamespaceCore(firebaseAppImpl) {
  117. const apps = {};
  118. // // eslint-disable-next-line @typescript-eslint/no-explicit-any
  119. // const components = new Map<string, Component<any>>();
  120. // A namespace is a plain JavaScript Object.
  121. const namespace = {
  122. // Hack to prevent Babel from modifying the object returned
  123. // as the firebase namespace.
  124. // @ts-ignore
  125. __esModule: true,
  126. initializeApp: initializeAppCompat,
  127. // @ts-ignore
  128. app,
  129. registerVersion: modularAPIs.registerVersion,
  130. setLogLevel: modularAPIs.setLogLevel,
  131. onLog: modularAPIs.onLog,
  132. // @ts-ignore
  133. apps: null,
  134. SDK_VERSION: modularAPIs.SDK_VERSION,
  135. INTERNAL: {
  136. registerComponent: registerComponentCompat,
  137. removeApp,
  138. useAsService,
  139. modularAPIs
  140. }
  141. };
  142. // Inject a circular default export to allow Babel users who were previously
  143. // using:
  144. //
  145. // import firebase from 'firebase';
  146. // which becomes: var firebase = require('firebase').default;
  147. //
  148. // instead of
  149. //
  150. // import * as firebase from 'firebase';
  151. // which becomes: var firebase = require('firebase');
  152. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  153. namespace['default'] = namespace;
  154. // firebase.apps is a read-only getter.
  155. Object.defineProperty(namespace, 'apps', {
  156. get: getApps
  157. });
  158. /**
  159. * Called by App.delete() - but before any services associated with the App
  160. * are deleted.
  161. */
  162. function removeApp(name) {
  163. delete apps[name];
  164. }
  165. /**
  166. * Get the App object for a given name (or DEFAULT).
  167. */
  168. function app(name) {
  169. name = name || modularAPIs._DEFAULT_ENTRY_NAME;
  170. if (!contains(apps, name)) {
  171. throw ERROR_FACTORY.create("no-app" /* AppError.NO_APP */, { appName: name });
  172. }
  173. return apps[name];
  174. }
  175. // @ts-ignore
  176. app['App'] = firebaseAppImpl;
  177. /**
  178. * Create a new App instance (name must be unique).
  179. *
  180. * This function is idempotent. It can be called more than once and return the same instance using the same options and config.
  181. */
  182. function initializeAppCompat(options, rawConfig = {}) {
  183. const app = modularAPIs.initializeApp(options, rawConfig);
  184. if (contains(apps, app.name)) {
  185. return apps[app.name];
  186. }
  187. const appCompat = new firebaseAppImpl(app, namespace);
  188. apps[app.name] = appCompat;
  189. return appCompat;
  190. }
  191. /*
  192. * Return an array of all the non-deleted FirebaseApps.
  193. */
  194. function getApps() {
  195. // Make a copy so caller cannot mutate the apps list.
  196. return Object.keys(apps).map(name => apps[name]);
  197. }
  198. function registerComponentCompat(component) {
  199. const componentName = component.name;
  200. const componentNameWithoutCompat = componentName.replace('-compat', '');
  201. if (modularAPIs._registerComponent(component) &&
  202. component.type === "PUBLIC" /* ComponentType.PUBLIC */) {
  203. // create service namespace for public components
  204. // The Service namespace is an accessor function ...
  205. const serviceNamespace = (appArg = app()) => {
  206. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  207. if (typeof appArg[componentNameWithoutCompat] !== 'function') {
  208. // Invalid argument.
  209. // This happens in the following case: firebase.storage('gs:/')
  210. throw ERROR_FACTORY.create("invalid-app-argument" /* AppError.INVALID_APP_ARGUMENT */, {
  211. appName: componentName
  212. });
  213. }
  214. // Forward service instance lookup to the FirebaseApp.
  215. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  216. return appArg[componentNameWithoutCompat]();
  217. };
  218. // ... and a container for service-level properties.
  219. if (component.serviceProps !== undefined) {
  220. deepExtend(serviceNamespace, component.serviceProps);
  221. }
  222. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  223. namespace[componentNameWithoutCompat] = serviceNamespace;
  224. // Patch the FirebaseAppImpl prototype
  225. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  226. firebaseAppImpl.prototype[componentNameWithoutCompat] =
  227. // TODO: The eslint disable can be removed and the 'ignoreRestArgs'
  228. // option added to the no-explicit-any rule when ESlint releases it.
  229. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  230. function (...args) {
  231. const serviceFxn = this._getService.bind(this, componentName);
  232. return serviceFxn.apply(this, component.multipleInstances ? args : []);
  233. };
  234. }
  235. return component.type === "PUBLIC" /* ComponentType.PUBLIC */
  236. ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
  237. namespace[componentNameWithoutCompat]
  238. : null;
  239. }
  240. // Map the requested service to a registered service name
  241. // (used to map auth to serverAuth service when needed).
  242. function useAsService(app, name) {
  243. if (name === 'serverAuth') {
  244. return null;
  245. }
  246. const useService = name;
  247. return useService;
  248. }
  249. return namespace;
  250. }
  251. /**
  252. * @license
  253. * Copyright 2019 Google LLC
  254. *
  255. * Licensed under the Apache License, Version 2.0 (the "License");
  256. * you may not use this file except in compliance with the License.
  257. * You may obtain a copy of the License at
  258. *
  259. * http://www.apache.org/licenses/LICENSE-2.0
  260. *
  261. * Unless required by applicable law or agreed to in writing, software
  262. * distributed under the License is distributed on an "AS IS" BASIS,
  263. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  264. * See the License for the specific language governing permissions and
  265. * limitations under the License.
  266. */
  267. function createFirebaseNamespaceLite() {
  268. const namespace = createFirebaseNamespaceCore(FirebaseAppLiteImpl);
  269. namespace.SDK_VERSION = `${namespace.SDK_VERSION}_LITE`;
  270. const registerComponent = namespace.INTERNAL.registerComponent;
  271. namespace.INTERNAL.registerComponent = registerComponentForLite;
  272. /**
  273. * This is a special implementation, so it only works with performance.
  274. * only allow performance SDK to register.
  275. */
  276. function registerComponentForLite(
  277. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  278. component) {
  279. // only allow performance to register with firebase lite
  280. if (component.type === "PUBLIC" /* ComponentType.PUBLIC */ &&
  281. !component.name.includes('performance') &&
  282. !component.name.includes('installations')) {
  283. throw Error(`${name} cannot register with the standalone perf instance`);
  284. }
  285. return registerComponent(component);
  286. }
  287. return namespace;
  288. }
  289. const name$1 = "@firebase/app-compat";
  290. const version = "0.2.1";
  291. /**
  292. * @license
  293. * Copyright 2019 Google LLC
  294. *
  295. * Licensed under the Apache License, Version 2.0 (the "License");
  296. * you may not use this file except in compliance with the License.
  297. * You may obtain a copy of the License at
  298. *
  299. * http://www.apache.org/licenses/LICENSE-2.0
  300. *
  301. * Unless required by applicable law or agreed to in writing, software
  302. * distributed under the License is distributed on an "AS IS" BASIS,
  303. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  304. * See the License for the specific language governing permissions and
  305. * limitations under the License.
  306. */
  307. function registerCoreComponents(variant) {
  308. // Register `app` package.
  309. registerVersion(name$1, version, variant);
  310. }
  311. /**
  312. * @license
  313. * Copyright 2019 Google LLC
  314. *
  315. * Licensed under the Apache License, Version 2.0 (the "License");
  316. * you may not use this file except in compliance with the License.
  317. * You may obtain a copy of the License at
  318. *
  319. * http://www.apache.org/licenses/LICENSE-2.0
  320. *
  321. * Unless required by applicable law or agreed to in writing, software
  322. * distributed under the License is distributed on an "AS IS" BASIS,
  323. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  324. * See the License for the specific language governing permissions and
  325. * limitations under the License.
  326. */
  327. const firebase = createFirebaseNamespaceLite();
  328. registerCoreComponents('lite');
  329. export { firebase as default };
  330. //# sourceMappingURL=index.lite.js.map