File tree Expand file tree Collapse file tree 4 files changed +15
-23
lines changed Expand file tree Collapse file tree 4 files changed +15
-23
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 { parseDatabaseURL , parseRepoInfo } from '../core/util/libs/parser' ;
19
+ import { 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,21 +156,16 @@ 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 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
-
159
+ const repoInfo = parsedURL . repoInfo ;
160
+ const expectedHost = this . repo_ . originalHost ;
161
+ if ( repoInfo . host !== expectedHost ) {
167
162
fatal (
168
163
apiName +
169
164
': Host name does not match the current database: ' +
170
165
'(found ' +
171
- newHost +
166
+ repoInfo . host +
172
167
' but expected ' +
173
- expected +
168
+ expectedHost +
174
169
')'
175
170
) ;
176
171
}
Original file line number Diff line number Diff line change @@ -54,8 +54,11 @@ 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
+
57
60
/** Record of the original host, which does not change even if useEmulator mutates the repo */
58
- readonly productionUrl : string ;
61
+ readonly originalHost : string ;
59
62
60
63
dataUpdateCount = 0 ;
61
64
private infoSyncTree_ : SyncTree ;
@@ -88,7 +91,9 @@ export class Repo {
88
91
public app : FirebaseApp ,
89
92
public authTokenProvider_ : AuthTokenProvider
90
93
) {
91
- this . productionUrl = this . repoInfo_ . toURLString ( ) ;
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 ;
92
97
}
93
98
94
99
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 . productionUrl ) !== repo ) {
179
+ if ( ! appRepos || safeGet ( appRepos , repo . key ) !== 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 . productionUrl ] ;
185
+ delete appRepos [ repo . key ] ;
186
186
}
187
187
188
188
/**
Original file line number Diff line number Diff line change @@ -286,12 +286,4 @@ 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
- } ) ;
297
289
} ) ;
You can’t perform that action at this time.
0 commit comments