Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schmidt-sebastian/08c74a0160809165fed81e31088cf8ce to your computer and use it in GitHub Desktop.
Save schmidt-sebastian/08c74a0160809165fed81e31088cf8ce to your computer and use it in GitHub Desktop.
diff --git a/packages/database/src/api/Database.ts b/packages/database/src/api/Database.ts
index 0a974f6be..59cc873d3 100644
--- a/packages/database/src/api/Database.ts
+++ b/packages/database/src/api/Database.ts
@@ -105,11 +105,11 @@ export class Database implements FirebaseService {
const apiName = 'database.refFromURL';
this.checkDeleted_(apiName);
validateArgCount(apiName, 1, 1, arguments.length);
- const parsedURL = parseRepoInfo(url);
+ const parsedURL = parseRepoInfo(url, this.repo_.repoInfo_.nodeAdmin);
validateUrl(apiName, 1, parsedURL);
const repoInfo = parsedURL.repoInfo;
- if (repoInfo.host !== (this.repo_.repoInfo_ as RepoInfo).host) {
+ if (repoInfo.host !== this.repo_.repoInfo_.host) {
fatal(
apiName +
': Host name does not match the current database: ' +
diff --git a/packages/database/src/core/RepoInfo.ts b/packages/database/src/core/RepoInfo.ts
index d2adf5c33..e3ceb2c09 100644
--- a/packages/database/src/core/RepoInfo.ts
+++ b/packages/database/src/core/RepoInfo.ts
@@ -31,20 +31,21 @@ export class RepoInfo {
internalHost: string;
/**
- * @param {string} host Hostname portion of the url for the repo
- * @param {boolean} secure Whether or not this repo is accessed over ssl
- * @param {string} namespace The namespace represented by the repo
- * @param {boolean} webSocketOnly Whether to prefer websockets over all other transports (used by Nest).
- * @param {string=} persistenceKey Override the default session persistence storage key
+ * @param host Hostname portion of the url for the repo
+ * @param secure Whether or not this repo is accessed over ssl
+ * @param namespace The namespace represented by the repo
+ * @param webSocketOnly Whether to prefer websockets over all other transports (used by Nest).
+ * @param nodeAdmin Whether this instance uses Admin SDK credentials
+ * @param persistenceKey Override the default session persistence storage key
*/
constructor(
host: string,
- public secure: boolean,
- public namespace: string,
- public webSocketOnly: boolean,
- public persistenceKey: string = '',
- public includeNamespaceInQueryParams: boolean = false,
- public nodeAdmin: boolean = false
+ public readonly secure: boolean,
+ public readonly namespace: string,
+ public readonly webSocketOnly: boolean,
+ public readonly nodeAdmin: boolean,
+ public readonly persistenceKey: string = '',
+ public readonly includeNamespaceInQueryParams: boolean = false,
) {
this.host = host.toLowerCase();
this.domain = this.host.substr(this.host.indexOf('.') + 1);
@@ -74,10 +75,6 @@ export class RepoInfo {
);
}
- setNodeAdmin(nodeAdmin: boolean) {
- this.nodeAdmin = nodeAdmin;
- }
-
updateHost(newHost: string) {
if (newHost !== this.internalHost) {
this.internalHost = newHost;
diff --git a/packages/database/src/core/RepoManager.ts b/packages/database/src/core/RepoManager.ts
index 625b68851..76d025938 100644
--- a/packages/database/src/core/RepoManager.ts
+++ b/packages/database/src/core/RepoManager.ts
@@ -111,7 +111,7 @@ export class RepoManager {
);
}
- let parsedUrl = parseRepoInfo(dbUrl);
+ let parsedUrl = parseRepoInfo(dbUrl, nodeAdmin);
let repoInfo = parsedUrl.repoInfo;
let isEmulator: boolean;
@@ -124,16 +124,12 @@ export class RepoManager {
if (dbEmulatorHost) {
isEmulator = true;
dbUrl = `http://${dbEmulatorHost}?ns=${repoInfo.namespace}`;
- parsedUrl = parseRepoInfo(dbUrl);
+ parsedUrl = parseRepoInfo(dbUrl, nodeAdmin);
repoInfo = parsedUrl.repoInfo;
} else {
isEmulator = !parsedUrl.repoInfo.secure;
}
- if (nodeAdmin) {
- repoInfo.setNodeAdmin(nodeAdmin);
- }
-
const authTokenProvider =
nodeAdmin && isEmulator
? new EmulatorAdminTokenProvider()
diff --git a/packages/database/src/core/util/libs/parser.ts b/packages/database/src/core/util/libs/parser.ts
index 5ae1979ea..bda26166c 100644
--- a/packages/database/src/core/util/libs/parser.ts
+++ b/packages/database/src/core/util/libs/parser.ts
@@ -61,13 +61,9 @@ function decodeQuery(queryString: string): { [key: string]: string } {
return results;
}
-/**
- *
- * @param {!string} dataURL
- * @return {{repoInfo: !RepoInfo, path: !Path}}
- */
export const parseRepoInfo = function (
- dataURL: string
+ dataURL: string,
+ nodeAdmin: boolean
): { repoInfo: RepoInfo; path: Path } {
const parsedUrl = parseDatabaseURL(dataURL),
namespace = parsedUrl.namespace;
@@ -101,6 +97,7 @@ export const parseRepoInfo = function (
parsedUrl.host,
parsedUrl.secure,
namespace,
+ nodeAdmin,
webSocketOnly,
/*persistenceKey=*/ '',
/*includeNamespaceInQueryParams=*/ namespace !== parsedUrl.subdomain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment