-
Notifications
You must be signed in to change notification settings - Fork 982
refactor(database): Add typescript database implementation [Part 2/3] #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4a0df56
refactor(database): add typescript implementation
jshcrowthe dcf2f5c
refactor(database): update build process to include database.ts
jshcrowthe 7e609d6
refactor(*): refactor environment builds to be based on separate .ts …
jshcrowthe e72bfbe
WIP: patch database code in nodeJS
jshcrowthe 2f6a406
refactor(database): classes for typescript database implementation (#55)
jsayol cf357d0
fix(database): Add missing "typeof" (#74)
jsayol 61b8a48
WIP: fixes from @schmidt-sebastian's review
jshcrowthe 71e4440
WIP: fix: TS Build error
jshcrowthe 25aeeed
fix(database): fix issue with missing repo method
jshcrowthe 61c8d25
WIP: review adjustments #1
jshcrowthe a01ff31
WIP: review comments #2
jshcrowthe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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': { | ||
|
@@ -43,18 +43,24 @@ export class Database { | |
this.INTERNAL = new DatabaseInternals(this); | ||
} | ||
|
||
app: null | ||
get app(): FirebaseApp { | ||
return this.repo_.app; | ||
} | ||
|
||
get database(): Database { | ||
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_; | ||
} | ||
|
||
/** | ||
|
@@ -85,7 +91,7 @@ export class Database { | |
* @param {string} apiName | ||
* @private | ||
|
||
*/ | ||
checkDeleted_(apiName) { | ||
private checkDeleted_(apiName) { | ||
if (this.repo_ === null) { | ||
fatal("Cannot call " + apiName + " on a deleted database."); | ||
} | ||
|
@@ -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 */ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 RepoThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch! Thank you!