@@ -27,6 +27,7 @@ import { Provider } from '@firebase/component';
27
27
import {
28
28
getModularInstance ,
29
29
createMockUserToken ,
30
+ // deepEqual,
30
31
EmulatorMockTokenOptions ,
31
32
getDefaultEmulatorHostnameAndPort
32
33
} from '@firebase/util' ;
@@ -38,7 +39,7 @@ import {
38
39
FirebaseAuthTokenProvider
39
40
} from '../core/AuthTokenProvider' ;
40
41
import { Repo , repoInterrupt , repoResume , repoStart } from '../core/Repo' ;
41
- import { RepoInfo } from '../core/RepoInfo' ;
42
+ import { RepoInfo , RepoInfoEmulatorOptions } from '../core/RepoInfo' ;
42
43
import { parseRepoInfo } from '../core/util/libs/parser' ;
43
44
import { newEmptyPath , pathIsEmpty } from '../core/util/Path' ;
44
45
import {
@@ -84,19 +85,20 @@ let useRestClient = false;
84
85
*/
85
86
function repoManagerApplyEmulatorSettings (
86
87
repo : Repo ,
87
- host : string ,
88
- port : number ,
89
- tokenProvider ?: AuthTokenProvider
88
+ hostAndPort : string ,
89
+ emulatorOptions : RepoInfoEmulatorOptions ,
90
+ tokenProvider ?: AuthTokenProvider ,
90
91
) : void {
91
92
repo . repoInfo_ = new RepoInfo (
92
- ` ${ host } : ${ port } ` ,
93
+ hostAndPort ,
93
94
/* secure= */ false ,
94
95
repo . repoInfo_ . namespace ,
95
96
repo . repoInfo_ . webSocketOnly ,
96
97
repo . repoInfo_ . nodeAdmin ,
97
98
repo . repoInfo_ . persistenceKey ,
98
99
repo . repoInfo_ . includeNamespaceInQueryParams ,
99
- /*isUsingEmulator=*/ true
100
+ /*isUsingEmulator=*/ true ,
101
+ emulatorOptions
100
102
) ;
101
103
102
104
if ( tokenProvider ) {
@@ -350,13 +352,23 @@ export function connectDatabaseEmulator(
350
352
) : void {
351
353
db = getModularInstance ( db ) ;
352
354
db . _checkNotDeleted ( 'useEmulator' ) ;
355
+ const hostAndPort = `${ host } :${ port } ` ;
356
+ const repo = db . _repoInternal ;
353
357
if ( db . _instanceStarted ) {
358
+ // If the instance has already been started, then silenty fail if this function is called again
359
+ // with the same parameters. If the parameters differ then assert.
360
+ if (
361
+ true
362
+ // hostAndPort === db._repoInternal.repoInfo_.host //&&
363
+ //deepEqual(options, repo.repoInfo_.emulatorOptions)
364
+ ) {
365
+ return ;
366
+ }
354
367
fatal (
355
- 'Cannot call useEmulator () after instance has already been initialized .'
368
+ 'connectDatabaseEmulator () cannot alter the emulator configuration after the database instance has started .'
356
369
) ;
357
370
}
358
371
359
- const repo = db . _repoInternal ;
360
372
let tokenProvider : EmulatorTokenProvider | undefined = undefined ;
361
373
if ( repo . repoInfo_ . nodeAdmin ) {
362
374
if ( options . mockUserToken ) {
@@ -374,7 +386,7 @@ export function connectDatabaseEmulator(
374
386
}
375
387
376
388
// Modify the repo to apply emulator settings
377
- repoManagerApplyEmulatorSettings ( repo , host , port , tokenProvider ) ;
389
+ repoManagerApplyEmulatorSettings ( repo , hostAndPort , options , tokenProvider ) ;
378
390
}
379
391
380
392
/**
0 commit comments