|
15 | 15 | * limitations under the License.
|
16 | 16 | */
|
17 | 17 |
|
18 |
| -import { AppOptions, app } from '../firebase-namespace-api'; |
| 18 | +import { AppOptions, App } from './core'; |
| 19 | +import { AppStore } from './lifecycle'; |
19 | 20 | import { Credential } from './credential';
|
20 | 21 | import { getApplicationDefault } from './credential-internal';
|
21 | 22 | import * as validator from '../utils/validator';
|
22 | 23 | import { deepCopy } from '../utils/deep-copy';
|
23 |
| -import { FirebaseNamespaceInternals } from './firebase-namespace'; |
24 | 24 | import { AppErrorCodes, FirebaseAppError } from '../utils/error';
|
25 | 25 |
|
26 |
| -import { Auth } from '../auth/index'; |
27 |
| -import { AppCheck } from '../app-check/index'; |
28 |
| -import { MachineLearning } from '../machine-learning/index'; |
29 |
| -import { Messaging } from '../messaging/index'; |
30 |
| -import { Storage } from '../storage/index'; |
31 |
| -import { Database } from '../database/index'; |
32 |
| -import { Firestore } from '../firestore/index'; |
33 |
| -import { InstanceId } from '../instance-id/index'; |
34 |
| -import { Installations } from '../installations/index'; |
35 |
| -import { ProjectManagement } from '../project-management/index'; |
36 |
| -import { SecurityRules } from '../security-rules/index'; |
37 |
| -import { RemoteConfig } from '../remote-config/index'; |
38 |
| - |
39 | 26 | const TOKEN_EXPIRY_THRESHOLD_MILLIS = 5 * 60 * 1000;
|
40 | 27 |
|
41 |
| -/** |
42 |
| - * Type representing a callback which is called every time an app lifecycle event occurs. |
43 |
| - */ |
44 |
| -export type AppHook = (event: string, app: app.App) => void; |
45 |
| - |
46 | 28 | /**
|
47 | 29 | * Type representing a Firebase OAuth access token (derived from a Google OAuth2 access token) which
|
48 | 30 | * can be used to authenticate to Firebase services such as the Realtime Database and Auth.
|
@@ -159,15 +141,16 @@ export class FirebaseAppInternals {
|
159 | 141 | *
|
160 | 142 | * @internal
|
161 | 143 | */
|
162 |
| -export class FirebaseApp implements app.App { |
| 144 | +export class FirebaseApp implements App { |
| 145 | + |
163 | 146 | public INTERNAL: FirebaseAppInternals;
|
164 | 147 |
|
165 | 148 | private name_: string;
|
166 | 149 | private options_: AppOptions;
|
167 | 150 | private services_: {[name: string]: unknown} = {};
|
168 | 151 | private isDeleted_ = false;
|
169 | 152 |
|
170 |
| - constructor(options: AppOptions, name: string, private firebaseInternals_: FirebaseNamespaceInternals) { |
| 153 | + constructor(options: AppOptions, name: string, private readonly appStore?: AppStore) { |
171 | 154 | this.name_ = name;
|
172 | 155 | this.options_ = deepCopy(options);
|
173 | 156 |
|
@@ -197,121 +180,6 @@ export class FirebaseApp implements app.App {
|
197 | 180 | this.INTERNAL = new FirebaseAppInternals(credential);
|
198 | 181 | }
|
199 | 182 |
|
200 |
| - /** |
201 |
| - * Returns the AppCheck service instance associated with this app. |
202 |
| - * |
203 |
| - * @returns The AppCheck service instance of this app. |
204 |
| - */ |
205 |
| - public appCheck(): AppCheck { |
206 |
| - const fn = require('../app-check/index').getAppCheck; |
207 |
| - return fn(this); |
208 |
| - } |
209 |
| - |
210 |
| - /** |
211 |
| - * Returns the Auth service instance associated with this app. |
212 |
| - * |
213 |
| - * @returns The Auth service instance of this app. |
214 |
| - */ |
215 |
| - public auth(): Auth { |
216 |
| - const fn = require('../auth/index').getAuth; |
217 |
| - return fn(this); |
218 |
| - } |
219 |
| - |
220 |
| - /** |
221 |
| - * Returns the Database service for the specified URL, and the current app. |
222 |
| - * |
223 |
| - * @returns The Database service instance of this app. |
224 |
| - */ |
225 |
| - public database(url?: string): Database { |
226 |
| - const fn = require('../database/index').getDatabaseWithUrl; |
227 |
| - return fn(url, this); |
228 |
| - } |
229 |
| - |
230 |
| - /** |
231 |
| - * Returns the Messaging service instance associated with this app. |
232 |
| - * |
233 |
| - * @returns The Messaging service instance of this app. |
234 |
| - */ |
235 |
| - public messaging(): Messaging { |
236 |
| - const fn = require('../messaging/index').getMessaging; |
237 |
| - return fn(this); |
238 |
| - } |
239 |
| - |
240 |
| - /** |
241 |
| - * Returns the Storage service instance associated with this app. |
242 |
| - * |
243 |
| - * @returns The Storage service instance of this app. |
244 |
| - */ |
245 |
| - public storage(): Storage { |
246 |
| - const fn = require('../storage/index').getStorage; |
247 |
| - return fn(this); |
248 |
| - } |
249 |
| - |
250 |
| - public firestore(): Firestore { |
251 |
| - const fn = require('../firestore/index').getFirestore; |
252 |
| - return fn(this); |
253 |
| - } |
254 |
| - |
255 |
| - /** |
256 |
| - * Returns the InstanceId service instance associated with this app. |
257 |
| - * |
258 |
| - * @returns The InstanceId service instance of this app. |
259 |
| - */ |
260 |
| - public instanceId(): InstanceId { |
261 |
| - const fn = require('../instance-id/index').getInstanceId; |
262 |
| - return fn(this); |
263 |
| - } |
264 |
| - |
265 |
| - /** |
266 |
| - * Returns the InstanceId service instance associated with this app. |
267 |
| - * |
268 |
| - * @returns The InstanceId service instance of this app. |
269 |
| - */ |
270 |
| - public installations(): Installations { |
271 |
| - const fn = require('../installations/index').getInstallations; |
272 |
| - return fn(this); |
273 |
| - } |
274 |
| - |
275 |
| - /** |
276 |
| - * Returns the MachineLearning service instance associated with this app. |
277 |
| - * |
278 |
| - * @returns The Machine Learning service instance of this app |
279 |
| - */ |
280 |
| - public machineLearning(): MachineLearning { |
281 |
| - const fn = require('../machine-learning/index').getMachineLearning; |
282 |
| - return fn(this); |
283 |
| - } |
284 |
| - |
285 |
| - /** |
286 |
| - * Returns the ProjectManagement service instance associated with this app. |
287 |
| - * |
288 |
| - * @returns The ProjectManagement service instance of this app. |
289 |
| - */ |
290 |
| - public projectManagement(): ProjectManagement { |
291 |
| - const fn = require('../project-management/index').getProjectManagement; |
292 |
| - return fn(this); |
293 |
| - } |
294 |
| - |
295 |
| - /** |
296 |
| - * Returns the SecurityRules service instance associated with this app. |
297 |
| - * |
298 |
| - * @returns The SecurityRules service instance of this app. |
299 |
| - */ |
300 |
| - public securityRules(): SecurityRules { |
301 |
| - const fn = require('../security-rules/index').getSecurityRules; |
302 |
| - return fn(this); |
303 |
| - } |
304 |
| - |
305 |
| - /** |
306 |
| - * Returns the RemoteConfig service instance associated with this app. |
307 |
| - * |
308 |
| - * @returns The RemoteConfig service instance of this app. |
309 |
| - */ |
310 |
| - public remoteConfig(): RemoteConfig { |
311 |
| - const fn = require('../remote-config/index').getRemoteConfig; |
312 |
| - return fn(this); |
313 |
| - } |
314 |
| - |
315 | 183 | /**
|
316 | 184 | * Returns the name of the FirebaseApp instance.
|
317 | 185 | *
|
@@ -346,7 +214,11 @@ export class FirebaseApp implements app.App {
|
346 | 214 | */
|
347 | 215 | public delete(): Promise<void> {
|
348 | 216 | this.checkDestroyed_();
|
349 |
| - this.firebaseInternals_.removeApp(this.name_); |
| 217 | + |
| 218 | + // Also remove the instance from the AppStore. This is needed to support the existing |
| 219 | + // app.delete() use case. In the future we can remove this API, and deleteApp() will |
| 220 | + // become the only way to tear down an App. |
| 221 | + this.appStore?.removeApp(this.name); |
350 | 222 |
|
351 | 223 | return Promise.all(Object.keys(this.services_).map((serviceName) => {
|
352 | 224 | const service = this.services_[serviceName];
|
|
0 commit comments