@@ -6,18 +6,18 @@ import { Reference } from "./Reference";
6
6
import { Repo } from "../core/Repo" ;
7
7
import { RepoManager } from "../core/RepoManager" ;
8
8
import { validateArgCount } from "../../utils/validation" ;
9
+ import { FirebaseApp } from "../../app/firebase_app" ;
9
10
import { validateUrl } from "../core/util/validation" ;
10
11
11
12
/**
12
13
* Class representing a firebase database.
13
14
* @implements {firebase.Service}
14
15
*/
15
16
export class Database {
16
- /** @type {Repo } */
17
- repo_ ;
18
- /** @type {Firebase } */
19
- root_ ;
17
+ repo_ : Repo ;
18
+ root_ : Reference ;
20
19
INTERNAL ;
20
+ private __database : Database ;
21
21
22
22
static ServerValue = {
23
23
'TIMESTAMP' : {
@@ -43,18 +43,24 @@ export class Database {
43
43
this . INTERNAL = new DatabaseInternals ( this ) ;
44
44
}
45
45
46
- app : null
46
+ get app ( ) : FirebaseApp {
47
+ return this . repo_ . app ;
48
+ }
49
+
50
+ get database ( ) : Database {
51
+ return this . __database || ( this . __database = new Database ( this ) ) ;
52
+ }
47
53
48
54
/**
49
55
* Returns a reference to the root or the path specified in opt_pathString.
50
- * @param {string= } opt_pathString
56
+ * @param {string= } pathString
51
57
* @return {!Firebase } Firebase reference.
52
58
*/
53
- ref ( opt_pathString ) : Reference {
59
+ ref ( pathString ? ) : Reference {
54
60
this . checkDeleted_ ( 'ref' ) ;
55
61
validateArgCount ( 'database.ref' , 0 , 1 , arguments . length ) ;
56
62
57
- return opt_pathString !== undefined ? this . root_ . child ( opt_pathString ) : this . root_ ;
63
+ return pathString !== undefined ? this . root_ . child ( pathString ) : this . root_ ;
58
64
}
59
65
60
66
/**
@@ -85,7 +91,7 @@ export class Database {
85
91
* @param {string } apiName
86
92
* @private
87
93
*/
88
- checkDeleted_ ( apiName ) {
94
+ private checkDeleted_ ( apiName ) {
89
95
if ( this . repo_ === null ) {
90
96
fatal ( "Cannot call " + apiName + " on a deleted database." ) ;
91
97
}
@@ -105,23 +111,6 @@ export class Database {
105
111
}
106
112
} ;
107
113
108
- // Note: This is an un-minfied property of the Database only.
109
- Object . defineProperty ( Database . prototype , 'app' , {
110
- /**
111
- * @this {!Database}
112
- * @return {!firebase.app.App }
113
- */
114
- get ( ) {
115
- return this . repo_ . app ;
116
- }
117
- } ) ;
118
-
119
- Object . defineProperty ( Repo . prototype , 'database' , {
120
- get ( ) {
121
- return this . __database || ( this . __database = new Database ( this ) ) ;
122
- }
123
- } ) ;
124
-
125
114
class DatabaseInternals {
126
115
database
127
116
/** @param {!Database } database */
0 commit comments