Skip to content

Commit 49ab776

Browse files
committed
Revert "Combine two fields, add a test, accept localhost in refFromURL"
This reverts commit d3e5503.
1 parent d3e5503 commit 49ab776

File tree

4 files changed

+15
-23
lines changed

4 files changed

+15
-23
lines changed

packages/database/src/api/Database.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { fatal } from '../core/util/util';
19-
import { parseDatabaseURL, parseRepoInfo } from '../core/util/libs/parser';
19+
import { parseRepoInfo } from '../core/util/libs/parser';
2020
import { Path } from '../core/util/Path';
2121
import { Reference } from './Reference';
2222
import { Repo } from '../core/Repo';
@@ -156,21 +156,16 @@ export class Database implements FirebaseService {
156156
const parsedURL = parseRepoInfo(url, this.repo_.repoInfo_.nodeAdmin);
157157
validateUrl(apiName, 1, parsedURL);
158158

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) {
167162
fatal(
168163
apiName +
169164
': Host name does not match the current database: ' +
170165
'(found ' +
171-
newHost +
166+
repoInfo.host +
172167
' but expected ' +
173-
expected +
168+
expectedHost +
174169
')'
175170
);
176171
}

packages/database/src/core/Repo.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ const INTERRUPT_REASON = 'repo_interrupt';
5454
* A connection to a single data repository.
5555
*/
5656
export class Repo {
57+
/** Key for uniquely identifying this repo, used in RepoManager */
58+
readonly key: string;
59+
5760
/** Record of the original host, which does not change even if useEmulator mutates the repo */
58-
readonly productionUrl: string;
61+
readonly originalHost: string;
5962

6063
dataUpdateCount = 0;
6164
private infoSyncTree_: SyncTree;
@@ -88,7 +91,9 @@ export class Repo {
8891
public app: FirebaseApp,
8992
public authTokenProvider_: AuthTokenProvider
9093
) {
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;
9297
}
9398

9499
start(): void {

packages/database/src/core/RepoManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,13 @@ export class RepoManager {
176176
deleteRepo(repo: Repo) {
177177
const appRepos = safeGet(this.repos_, repo.app.name);
178178
// This should never happen...
179-
if (!appRepos || safeGet(appRepos, repo.productionUrl) !== repo) {
179+
if (!appRepos || safeGet(appRepos, repo.key) !== repo) {
180180
fatal(
181181
`Database ${repo.app.name}(${repo.repoInfo_}) has already been deleted.`
182182
);
183183
}
184184
repo.interrupt();
185-
delete appRepos[repo.productionUrl];
185+
delete appRepos[repo.key];
186186
}
187187

188188
/**

packages/database/test/database.test.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,4 @@ describe('Database Tests', () => {
286286
const ref = db.refFromURL(DATABASE_ADDRESS + '/path/to/data');
287287
expect(ref.toString()).to.equal(`http://localhost:1234/path/to/data`);
288288
});
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-
});
297289
});

0 commit comments

Comments
 (0)