Skip to content

Commit 744caca

Browse files
authored
fix: Decoupled FirebaseNamespace from new module entry points (#1432)
* fix: Decoupled FirebaseNamespace from new module entry points * fix: Updated comments * Trigger checks
1 parent bee6a2b commit 744caca

12 files changed

+288
-378
lines changed

etc/firebase-admin.app.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export interface FirebaseError {
5454
}
5555

5656
// @public (undocumented)
57-
export function getApp(name?: string): App;
57+
export function getApp(appName?: string): App;
5858

5959
// @public (undocumented)
6060
export function getApps(): App[];
@@ -68,7 +68,7 @@ export interface GoogleOAuthAccessToken {
6868
}
6969

7070
// @public (undocumented)
71-
export function initializeApp(options?: AppOptions, name?: string): App;
71+
export function initializeApp(options?: AppOptions, appName?: string): App;
7272

7373
// @public
7474
export function refreshToken(refreshTokenPathOrObject: string | object, httpAgent?: Agent): Credential;

src/app/firebase-app.ts

Lines changed: 10 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,16 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { AppOptions, app } from '../firebase-namespace-api';
18+
import { AppOptions, App } from './core';
19+
import { AppStore } from './lifecycle';
1920
import { Credential } from './credential';
2021
import { getApplicationDefault } from './credential-internal';
2122
import * as validator from '../utils/validator';
2223
import { deepCopy } from '../utils/deep-copy';
23-
import { FirebaseNamespaceInternals } from './firebase-namespace';
2424
import { AppErrorCodes, FirebaseAppError } from '../utils/error';
2525

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-
3926
const TOKEN_EXPIRY_THRESHOLD_MILLIS = 5 * 60 * 1000;
4027

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-
4628
/**
4729
* Type representing a Firebase OAuth access token (derived from a Google OAuth2 access token) which
4830
* can be used to authenticate to Firebase services such as the Realtime Database and Auth.
@@ -159,15 +141,16 @@ export class FirebaseAppInternals {
159141
*
160142
* @internal
161143
*/
162-
export class FirebaseApp implements app.App {
144+
export class FirebaseApp implements App {
145+
163146
public INTERNAL: FirebaseAppInternals;
164147

165148
private name_: string;
166149
private options_: AppOptions;
167150
private services_: {[name: string]: unknown} = {};
168151
private isDeleted_ = false;
169152

170-
constructor(options: AppOptions, name: string, private firebaseInternals_: FirebaseNamespaceInternals) {
153+
constructor(options: AppOptions, name: string, private readonly appStore?: AppStore) {
171154
this.name_ = name;
172155
this.options_ = deepCopy(options);
173156

@@ -197,121 +180,6 @@ export class FirebaseApp implements app.App {
197180
this.INTERNAL = new FirebaseAppInternals(credential);
198181
}
199182

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-
315183
/**
316184
* Returns the name of the FirebaseApp instance.
317185
*
@@ -346,7 +214,11 @@ export class FirebaseApp implements app.App {
346214
*/
347215
public delete(): Promise<void> {
348216
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);
350222

351223
return Promise.all(Object.keys(this.services_).map((serviceName) => {
352224
const service = this.services_[serviceName];

0 commit comments

Comments
 (0)