Skip to content

Commit 9139e36

Browse files
committed
Documentation cleanup
1 parent dca658e commit 9139e36

File tree

3 files changed

+50
-14
lines changed

3 files changed

+50
-14
lines changed

etc/firebase-admin.app.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ export interface FirebaseError {
8383
toJSON(): object;
8484
}
8585

86-
// @public (undocumented)
86+
// @public
8787
export function getApp(appName?: string): App;
8888

89-
// @public (undocumented)
89+
// @public
9090
export function getApps(): App[];
9191

9292
// @public

src/app/firebase-app.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,22 @@ export class FirebaseApp implements App {
220220
}
221221

222222
/**
223+
* Returns `true` if this app was initialized with auto-initialization.
224+
* FirebaseApp instance.
225+
*
223226
* @internal
224227
*/
225228
public autoInit(): boolean {
226229
return this.autoInit_;
227230
}
228231

229232
/**
233+
* Returns `true` if the FirebaseApp instance was initialized with a custom
234+
* Credential.
235+
*
230236
* @internal
231237
*/
232-
public initializedWithCustomCredential() : boolean {
238+
public customCredential() : boolean {
233239
return this.customCredential_;
234240
}
235241

src/app/lifecycle.ts

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,26 @@ export class AppStore {
4040
options.credential = getApplicationDefault();
4141
}
4242

43-
// Check to see if an App already exists. And validate that we can return it
44-
// given the AppOptions parameter provided to initializeApp.
43+
// Check if an App already exists and, if so, ensure its AppOptions match
44+
// those of this initializeApp request.
4545
if (this.appStore.has(appName)) {
4646
const currentApp = this.appStore.get(appName)!;
47+
// Ensure the autoInit state matches the existing app's. If not, throw.
4748
if (currentApp.autoInit() !== autoInit) {
4849
throw new FirebaseAppError(
4950
AppErrorCodes.INVALID_APP_OPTIONS,
5051
`Firebase app named "${appName}" attempted mismatch between custom AppOptions` +
5152
' and an App created via Auto Init.'
5253
)
5354
} else if (autoInit) {
55+
// Auto-initialization is triggered when no options were passed to
56+
// initializeApp. With no options to compare, simply return the App.
5457
return currentApp;
5558
} else {
56-
// httpAgent breaks idempotency. Throw if the AppOptions parameter or the
57-
// existing app contains a httpAgent.
59+
// Auto-initialization was not used.
60+
61+
// httpAgent breaks idempotency since the objects cannot be compared.
62+
// Throw if a httpAgent exists in AppOptions or the existing App.
5863
if (typeof options.httpAgent !== 'undefined') {
5964
throw new FirebaseAppError(
6065
AppErrorCodes.INVALID_APP_OPTIONS,
@@ -70,10 +75,8 @@ export class AppStore {
7075
' options configuration: httpAgent'
7176
);
7277
}
73-
74-
// Credential breaks idempotency. Throw if the AppOptions parameter contains a
75-
// Credential, or if the existing app's credential was provided during its
76-
// construction.
78+
// Credential breaks idempotency since the objects cannot be compared.
79+
// Throw if a Credential exists in AppOptions or the existing App.
7780
if (typeof options.credential !== 'undefined') {
7881
throw new FirebaseAppError(
7982
AppErrorCodes.INVALID_APP_OPTIONS,
@@ -82,16 +85,17 @@ export class AppStore {
8285
' of Credential objects with the existing app. Please use getApp or getApps' +
8386
' to reuse the existing app instead.'
8487
);
85-
} else if (currentApp.initializedWithCustomCredential()) {
88+
} else if (currentApp.customCredential()) {
8689
throw new FirebaseAppError(
8790
AppErrorCodes.INVALID_APP_OPTIONS,
8891
`An existing app named "${appName}" already exists with a different` +
8992
' options configuration: Credential'
9093
);
9194
}
9295

93-
// FirebaseApp appends credentials to the options upon construction. Remove
94-
// those generated credentials for the sake of AppOptions parameter comparison.
96+
// FirebaseApp() appends an instance of Credential to the `options`
97+
// field upon construction (below). Run a comparison of the app's
98+
// options without this auto generated Credential.
9599
const currentAppOptions = { ...currentApp.options };
96100
delete currentAppOptions.credential;
97101
if (deepEqual(options, currentAppOptions)) {
@@ -161,6 +165,16 @@ export class AppStore {
161165
}
162166
}
163167

168+
/**
169+
* Checks to see if the provided appName is a non-empty string and throws if it
170+
* is not.
171+
*
172+
* @param appName A string representation of an App name.
173+
*
174+
* @throws FirebaseAppError if appName is not of type string or is empty.
175+
*
176+
* @internal
177+
*/
164178
function validateAppNameFormat(appName: string): void {
165179
if (typeof appName !== 'string' || appName === '') {
166180
throw new FirebaseAppError(
@@ -205,10 +219,26 @@ export function initializeApp(options?: AppOptions, appName: string = DEFAULT_AP
205219
return defaultAppStore.initializeApp(options, appName);
206220
}
207221

222+
/**
223+
* Returns an existing App instance for the provided name. If no name is provided
224+
* the the default app name is queried.
225+
*
226+
* @param appName - Optional name of the FirebaseApp instance.
227+
*
228+
* @returns An existing App instance that matches the name provided.
229+
*
230+
* @throws FirebaseAppError if no {@link App} exists for the given name.
231+
* @throws FirebaseAppError if the `appName` is malformed.
232+
*/
208233
export function getApp(appName: string = DEFAULT_APP_NAME): App {
209234
return defaultAppStore.getApp(appName);
210235
}
211236

237+
/**
238+
* A (read-only) array of all initialized apps.
239+
*
240+
* @returns An array containing all initialized apps.
241+
*/
212242
export function getApps(): App[] {
213243
return defaultAppStore.getApps();
214244
}

0 commit comments

Comments
 (0)