Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public getDatabase(url?: string): Database {
const dbUrl: string = this.ensureUrl(url);
if (!validator.isNonEmptyString(dbUrl)) {
throw new FirebaseDatabaseError({
code: 'invalid-argument',
message: 'Database URL must be a valid, non-empty URL string.',
});
}
let db: Database = this.INTERNAL.databases[dbUrl];
if (typeof db === 'undefined') {
const rtdb = require('@firebase/database');
const { version } = require('../../package.json');
db = rtdb.initStandalone(this.appInternal, dbUrl, version).instance;
const rulesClient = new DatabaseRulesClient(this.app, dbUrl);
db.getRules = () => {
return rulesClient.getRules();
};
db.getRulesJSON = () => {
return rulesClient.getRulesJSON();
};
db.setRules = (source) => {
return rulesClient.setRules(source);
};
this.INTERNAL.databases[dbUrl] = db;
}
return db;
}
DatabaseService.prototype.getDatabase = function (url) {
var dbUrl = this.ensureUrl(url);
if (!validator.isNonEmptyString(dbUrl)) {
throw new error_1.FirebaseDatabaseError({
code: 'invalid-argument',
message: 'Database URL must be a valid, non-empty URL string.',
});
}
var db = this.INTERNAL.databases[dbUrl];
if (typeof db === 'undefined') {
var rtdb = require('@firebase/database');
db = rtdb.initStandalone(this.appInternal, dbUrl).instance;
this.INTERNAL.databases[dbUrl] = db;
}
return db;
};
DatabaseService.prototype.ensureUrl = function (url) {