Skip to content

Commit 2ae1b8d

Browse files
committed
Apply Sebastian's fixes
1 parent 91166f9 commit 2ae1b8d

File tree

4 files changed

+19
-29
lines changed

4 files changed

+19
-29
lines changed

packages/database/src/api/Database.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ export class Database implements FirebaseService {
105105
const apiName = 'database.refFromURL';
106106
this.checkDeleted_(apiName);
107107
validateArgCount(apiName, 1, 1, arguments.length);
108-
const parsedURL = parseRepoInfo(url);
108+
const parsedURL = parseRepoInfo(url, this.repo_.repoInfo_.nodeAdmin);
109109
validateUrl(apiName, 1, parsedURL);
110110

111111
const repoInfo = parsedURL.repoInfo;
112-
if (repoInfo.host !== (this.repo_.repoInfo_ as RepoInfo).host) {
112+
if (repoInfo.host !== this.repo_.repoInfo_.host) {
113113
fatal(
114114
apiName +
115115
': Host name does not match the current database: ' +

packages/database/src/core/RepoInfo.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,21 @@ export class RepoInfo {
3131
internalHost: string;
3232

3333
/**
34-
* @param {string} host Hostname portion of the url for the repo
35-
* @param {boolean} secure Whether or not this repo is accessed over ssl
36-
* @param {string} namespace The namespace represented by the repo
37-
* @param {boolean} webSocketOnly Whether to prefer websockets over all other transports (used by Nest).
38-
* @param {string=} persistenceKey Override the default session persistence storage key
34+
* @param host Hostname portion of the url for the repo
35+
* @param secure Whether or not this repo is accessed over ssl
36+
* @param namespace The namespace represented by the repo
37+
* @param webSocketOnly Whether to prefer websockets over all other transports (used by Nest).
38+
* @param nodeAdmin Whether this instance uses Admin SDK credentials
39+
* @param persistenceKey Override the default session persistence storage key
3940
*/
4041
constructor(
4142
host: string,
42-
public secure: boolean,
43-
public namespace: string,
44-
public webSocketOnly: boolean,
45-
public persistenceKey: string = '',
46-
public includeNamespaceInQueryParams: boolean = false,
47-
public nodeAdmin: boolean = false
43+
public readonly secure: boolean,
44+
public readonly namespace: string,
45+
public readonly webSocketOnly: boolean,
46+
public readonly nodeAdmin: boolean,
47+
public readonly persistenceKey: string = '',
48+
public readonly includeNamespaceInQueryParams: boolean = false
4849
) {
4950
this.host = host.toLowerCase();
5051
this.domain = this.host.substr(this.host.indexOf('.') + 1);
@@ -74,10 +75,6 @@ export class RepoInfo {
7475
);
7576
}
7677

77-
setNodeAdmin(nodeAdmin: boolean) {
78-
this.nodeAdmin = nodeAdmin;
79-
}
80-
8178
updateHost(newHost: string) {
8279
if (newHost !== this.internalHost) {
8380
this.internalHost = newHost;

packages/database/src/core/RepoManager.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export class RepoManager {
111111
);
112112
}
113113

114-
let parsedUrl = parseRepoInfo(dbUrl);
114+
let parsedUrl = parseRepoInfo(dbUrl, nodeAdmin);
115115
let repoInfo = parsedUrl.repoInfo;
116116

117117
let isEmulator: boolean;
@@ -124,16 +124,12 @@ export class RepoManager {
124124
if (dbEmulatorHost) {
125125
isEmulator = true;
126126
dbUrl = `http://${dbEmulatorHost}?ns=${repoInfo.namespace}`;
127-
parsedUrl = parseRepoInfo(dbUrl);
127+
parsedUrl = parseRepoInfo(dbUrl, nodeAdmin);
128128
repoInfo = parsedUrl.repoInfo;
129129
} else {
130130
isEmulator = !parsedUrl.repoInfo.secure;
131131
}
132132

133-
if (nodeAdmin) {
134-
repoInfo.setNodeAdmin(nodeAdmin);
135-
}
136-
137133
const authTokenProvider =
138134
nodeAdmin && isEmulator
139135
? new EmulatorAdminTokenProvider()

packages/database/src/core/util/libs/parser.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,9 @@ function decodeQuery(queryString: string): { [key: string]: string } {
6161
return results;
6262
}
6363

64-
/**
65-
*
66-
* @param {!string} dataURL
67-
* @return {{repoInfo: !RepoInfo, path: !Path}}
68-
*/
6964
export const parseRepoInfo = function (
70-
dataURL: string
65+
dataURL: string,
66+
nodeAdmin: boolean
7167
): { repoInfo: RepoInfo; path: Path } {
7268
const parsedUrl = parseDatabaseURL(dataURL),
7369
namespace = parsedUrl.namespace;
@@ -101,6 +97,7 @@ export const parseRepoInfo = function (
10197
parsedUrl.host,
10298
parsedUrl.secure,
10399
namespace,
100+
nodeAdmin,
104101
webSocketOnly,
105102
/*persistenceKey=*/ '',
106103
/*includeNamespaceInQueryParams=*/ namespace !== parsedUrl.subdomain

0 commit comments

Comments
 (0)