@@ -203,7 +203,7 @@ export function initializeApp(
203
203
* @example
204
204
* ```javascript
205
205
*
206
- * // Initialize an instance of `FirebaseServerApp`.
206
+ * // Initialize an instance of `FirebaseServerApp` with explicit options .
207
207
* // Retrieve your own options values by adding a web app on
208
208
* // https://console.firebase.google.com
209
209
* initializeServerApp({
@@ -231,29 +231,52 @@ export function initializeServerApp(
231
231
config : FirebaseServerAppSettings
232
232
) : FirebaseServerApp ;
233
233
234
+ /**
235
+ * Creates and initializes a {@link @firebase/app#FirebaseServerApp } instance with default configuration.
236
+ *
237
+ * @example
238
+ * ```javascript
239
+ * // Initialize with default configuration
240
+ * initializeServerApp();
241
+ * ```
242
+ *
243
+ * @returns The initialized `FirebaseServerApp` with default configuration.
244
+ *
245
+ * @public
246
+ */
247
+ export function initializeServerApp ( ) : FirebaseServerApp ;
248
+
234
249
export function initializeServerApp (
235
- _options : FirebaseOptions | FirebaseApp ,
236
- _serverAppConfig : FirebaseServerAppSettings
250
+ _options ? : FirebaseOptions | FirebaseApp ,
251
+ _serverAppConfig : FirebaseServerAppSettings = { }
237
252
) : FirebaseServerApp {
238
253
if ( isBrowser ( ) && ! isWebWorker ( ) ) {
239
254
// FirebaseServerApp isn't designed to be run in browsers.
240
255
throw ERROR_FACTORY . create ( AppError . INVALID_SERVER_APP_ENVIRONMENT ) ;
241
256
}
242
257
243
- if ( _serverAppConfig . automaticDataCollectionEnabled === undefined ) {
244
- _serverAppConfig . automaticDataCollectionEnabled = false ;
258
+ let options = _options ;
259
+ const config : FirebaseServerAppSettings = {
260
+ automaticDataCollectionEnabled : false ,
261
+ ..._serverAppConfig
262
+ } ;
263
+
264
+ options ||= getDefaultAppConfig ( ) ;
265
+
266
+ if ( ! options ) {
267
+ throw ERROR_FACTORY . create ( AppError . NO_OPTIONS ) ;
245
268
}
246
269
247
270
let appOptions : FirebaseOptions ;
248
- if ( _isFirebaseApp ( _options ) ) {
249
- appOptions = _options . options ;
271
+ if ( _isFirebaseApp ( options ) ) {
272
+ appOptions = options . options ;
250
273
} else {
251
- appOptions = _options ;
274
+ appOptions = options ;
252
275
}
253
276
254
277
// Build an app name based on a hash of the configuration options.
255
278
const nameObj = {
256
- ..._serverAppConfig ,
279
+ ...config ,
257
280
...appOptions
258
281
} ;
259
282
@@ -270,7 +293,7 @@ export function initializeServerApp(
270
293
) ;
271
294
} ;
272
295
273
- if ( _serverAppConfig . releaseOnDeref !== undefined ) {
296
+ if ( config . releaseOnDeref !== undefined ) {
274
297
if ( typeof FinalizationRegistry === 'undefined' ) {
275
298
throw ERROR_FACTORY . create (
276
299
AppError . FINALIZATION_REGISTRY_NOT_SUPPORTED ,
@@ -283,7 +306,7 @@ export function initializeServerApp(
283
306
const existingApp = _serverApps . get ( nameString ) as FirebaseServerApp ;
284
307
if ( existingApp ) {
285
308
( existingApp as FirebaseServerAppImpl ) . incRefCount (
286
- _serverAppConfig . releaseOnDeref
309
+ config . releaseOnDeref
287
310
) ;
288
311
return existingApp ;
289
312
}
@@ -295,7 +318,7 @@ export function initializeServerApp(
295
318
296
319
const newApp = new FirebaseServerAppImpl (
297
320
appOptions ,
298
- _serverAppConfig ,
321
+ config ,
299
322
nameString ,
300
323
container
301
324
) ;
@@ -375,22 +398,22 @@ export async function deleteApp(app: FirebaseApp): Promise<void> {
375
398
let cleanupProviders = false ;
376
399
const name = app . name ;
377
400
if ( _apps . has ( name ) ) {
378
- cleanupProviders = true ;
379
- _apps . delete ( name ) ;
380
- } else if ( _serverApps . has ( name ) ) {
381
- const firebaseServerApp = app as FirebaseServerAppImpl ;
382
- if ( firebaseServerApp . decRefCount ( ) <= 0 ) {
383
- _serverApps . delete ( name ) ;
384
401
cleanupProviders = true ;
385
- }
402
+ _apps . delete ( name ) ;
403
+ } else if ( _serverApps . has ( name ) ) {
404
+ const firebaseServerApp = app as FirebaseServerAppImpl ;
405
+ if ( firebaseServerApp . decRefCount ( ) <= 0 ) {
406
+ _serverApps . delete ( name ) ;
407
+ cleanupProviders = true ;
408
+ }
386
409
}
387
410
388
411
if ( cleanupProviders ) {
389
- await Promise . all (
412
+ await Promise . all (
390
413
( app as FirebaseAppImpl ) . container
391
- . getProviders ( )
392
- . map ( provider => provider . delete ( ) )
393
- ) ;
414
+ . getProviders ( )
415
+ . map ( provider => provider . delete ( ) )
416
+ ) ;
394
417
( app as FirebaseAppImpl ) . isDeleted = true ;
395
418
}
396
419
}
0 commit comments