Skip to content
Merged
11 changes: 1 addition & 10 deletions src/database/api/DataSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,8 @@ export class DataSnapshot {
return !this.node_.isEmpty();
}

/**
* @return {?string} The key of the location this snapshot's data came from.
*/
getKey(): string | null {
validateArgCount('DataSnapshot.key', 0, 0, arguments.length);

return this.ref_.getKey();
}

get key() {
return this.getKey();
return this.ref_.getKey();
}

/**
Expand Down
41 changes: 15 additions & 26 deletions src/database/api/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import { Reference } from "./Reference";
import { Repo } from "../core/Repo";
import { RepoManager } from "../core/RepoManager";
import { validateArgCount } from "../../utils/validation";
import { FirebaseApp } from "../../app/firebase_app";
import { validateUrl } from "../core/util/validation";

/**
* Class representing a firebase database.
* @implements {firebase.Service}
*/
export class Database {
/** @type {Repo} */
repo_;
/** @type {Firebase} */
root_;
repo_: Repo;
root_: Reference;
INTERNAL;
private __database: Database;

static ServerValue = {
'TIMESTAMP': {
Expand All @@ -43,18 +43,24 @@ export class Database {
this.INTERNAL = new DatabaseInternals(this);
}

app: null
get app(): FirebaseApp {
return this.repo_.app;
}

get database(): Database {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The database getter actually belongs in Repo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch! Thank you!

return this.__database || (this.__database = new Database(this));
}

/**
* Returns a reference to the root or the path specified in opt_pathString.
* @param {string=} opt_pathString
* @param {string=} pathString
* @return {!Firebase} Firebase reference.
*/
ref(opt_pathString): Reference {
ref(pathString?): Reference {
this.checkDeleted_('ref');
validateArgCount('database.ref', 0, 1, arguments.length);

return opt_pathString !== undefined ? this.root_.child(opt_pathString) : this.root_;
return pathString !== undefined ? this.root_.child(pathString) : this.root_;
}

/**
Expand Down Expand Up @@ -85,7 +91,7 @@ export class Database {
* @param {string} apiName
* @private
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use 'private checkDeleted_()" instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

K

*/
checkDeleted_(apiName) {
private checkDeleted_(apiName) {
if (this.repo_ === null) {
fatal("Cannot call " + apiName + " on a deleted database.");
}
Expand All @@ -105,23 +111,6 @@ export class Database {
}
};

// Note: This is an un-minfied property of the Database only.
Object.defineProperty(Database.prototype, 'app', {
/**
* @this {!Database}
* @return {!firebase.app.App}
*/
get() {
return this.repo_.app;
}
});

Object.defineProperty(Repo.prototype, 'database', {
get() {
return this.__database || (this.__database = new Database(this));
}
});

class DatabaseInternals {
database
/** @param {!Database} database */
Expand Down