File tree 4 files changed +23
-15
lines changed
4 files changed +23
-15
lines changed Original file line number Diff line number Diff line change 16
16
*/
17
17
18
18
import { fatal } from '../core/util/util' ;
19
- import { parseRepoInfo } from '../core/util/libs/parser' ;
19
+ import { parseDatabaseURL , parseRepoInfo } from '../core/util/libs/parser' ;
20
20
import { Path } from '../core/util/Path' ;
21
21
import { Reference } from './Reference' ;
22
22
import { Repo } from '../core/Repo' ;
@@ -156,16 +156,21 @@ export class Database implements FirebaseService {
156
156
const parsedURL = parseRepoInfo ( url , this . repo_ . repoInfo_ . nodeAdmin ) ;
157
157
validateUrl ( apiName , 1 , parsedURL ) ;
158
158
159
- const repoInfo = parsedURL . repoInfo ;
160
- const expectedHost = this . repo_ . originalHost ;
161
- if ( repoInfo . host !== expectedHost ) {
159
+ const newHost = parsedURL . repoInfo . host ;
160
+ const originalHost = parseDatabaseURL ( this . repo_ . productionUrl ) . host ;
161
+ const currentHost = this . repo_ . repoInfo_ . host ;
162
+ if ( newHost !== originalHost && newHost !== currentHost ) {
163
+ const expected = originalHost === currentHost
164
+ ? originalHost
165
+ : `${ originalHost } or ${ currentHost } ` ;
166
+
162
167
fatal (
163
168
apiName +
164
169
': Host name does not match the current database: ' +
165
170
'(found ' +
166
- repoInfo . host +
171
+ newHost +
167
172
' but expected ' +
168
- expectedHost +
173
+ expected +
169
174
')'
170
175
) ;
171
176
}
Original file line number Diff line number Diff line change @@ -54,11 +54,8 @@ const INTERRUPT_REASON = 'repo_interrupt';
54
54
* A connection to a single data repository.
55
55
*/
56
56
export class Repo {
57
- /** Key for uniquely identifying this repo, used in RepoManager */
58
- readonly key : string ;
59
-
60
57
/** Record of the original host, which does not change even if useEmulator mutates the repo */
61
- readonly originalHost : string ;
58
+ readonly productionUrl : string ;
62
59
63
60
dataUpdateCount = 0 ;
64
61
private infoSyncTree_ : SyncTree ;
@@ -91,9 +88,7 @@ export class Repo {
91
88
public app : FirebaseApp ,
92
89
public authTokenProvider_ : AuthTokenProvider
93
90
) {
94
- // This key is intentionally not updated if RepoInfo is later changed or replaced
95
- this . key = this . repoInfo_ . toURLString ( ) ;
96
- this . originalHost = this . repoInfo_ . host ;
91
+ this . productionUrl = this . repoInfo_ . toURLString ( ) ;
97
92
}
98
93
99
94
start ( ) : void {
Original file line number Diff line number Diff line change @@ -176,13 +176,13 @@ export class RepoManager {
176
176
deleteRepo ( repo : Repo ) {
177
177
const appRepos = safeGet ( this . repos_ , repo . app . name ) ;
178
178
// This should never happen...
179
- if ( ! appRepos || safeGet ( appRepos , repo . key ) !== repo ) {
179
+ if ( ! appRepos || safeGet ( appRepos , repo . productionUrl ) !== repo ) {
180
180
fatal (
181
181
`Database ${ repo . app . name } (${ repo . repoInfo_ } ) has already been deleted.`
182
182
) ;
183
183
}
184
184
repo . interrupt ( ) ;
185
- delete appRepos [ repo . key ] ;
185
+ delete appRepos [ repo . productionUrl ] ;
186
186
}
187
187
188
188
/**
Original file line number Diff line number Diff line change @@ -286,4 +286,12 @@ describe('Database Tests', () => {
286
286
const ref = db . refFromURL ( DATABASE_ADDRESS + '/path/to/data' ) ;
287
287
expect ( ref . toString ( ) ) . to . equal ( `http://localhost:1234/path/to/data` ) ;
288
288
} ) ;
289
+
290
+ it ( 'refFromURL accepts an emulated ref with useEmulator' , ( ) => {
291
+ const db = ( firebase as any ) . database ( ) ;
292
+ db . useEmulator ( 'localhost' , 1234 ) ;
293
+
294
+ const ref = db . refFromURL ( 'http://localhost:1234/path/to/data' ) ;
295
+ expect ( ref . toString ( ) ) . to . equal ( `http://localhost:1234/path/to/data` ) ;
296
+ } ) ;
289
297
} ) ;
You can’t perform that action at this time.
0 commit comments