Skip to content

Commit 2939025

Browse files
committed
Merge branch 'ts-database/final' into ts-database/migrate-test-harness
2 parents d78d6c4 + bb80d31 commit 2939025

File tree

6 files changed

+28
-53
lines changed

6 files changed

+28
-53
lines changed

src/database/api/DataSnapshot.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,8 @@ export class DataSnapshot {
139139
return !this.node_.isEmpty();
140140
}
141141

142-
/**
143-
* @return {?string} The key of the location this snapshot's data came from.
144-
*/
145-
getKey(): string | null {
146-
validateArgCount('DataSnapshot.key', 0, 0, arguments.length);
147-
148-
return this.ref_.getKey();
149-
}
150-
151142
get key() {
152-
return this.getKey();
143+
return this.ref_.getKey();
153144
}
154145

155146
/**

src/database/api/Database.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@ import { Reference } from "./Reference";
66
import { Repo } from "../core/Repo";
77
import { RepoManager } from "../core/RepoManager";
88
import { validateArgCount } from "../../utils/validation";
9+
import { FirebaseApp } from "../../app/firebase_app";
910
import { validateUrl } from "../core/util/validation";
1011

1112
/**
1213
* Class representing a firebase database.
1314
* @implements {firebase.Service}
1415
*/
1516
export class Database {
16-
/** @type {Repo} */
17-
repo_;
18-
/** @type {Firebase} */
19-
root_;
17+
repo_: Repo;
18+
root_: Reference;
2019
INTERNAL;
21-
20+
2221
static ServerValue = {
2322
'TIMESTAMP': {
2423
'.sv' : 'timestamp'
@@ -43,7 +42,9 @@ export class Database {
4342
this.INTERNAL = new DatabaseInternals(this);
4443
}
4544

46-
app: null
45+
get app(): FirebaseApp {
46+
return this.repo_.app;
47+
}
4748

4849
/**
4950
* Returns a reference to the root or the path specified in opt_pathString.
@@ -83,9 +84,8 @@ export class Database {
8384

8485
/**
8586
* @param {string} apiName
86-
* @private
8787
*/
88-
checkDeleted_(apiName) {
88+
private checkDeleted_(apiName) {
8989
if (this.repo_ === null) {
9090
fatal("Cannot call " + apiName + " on a deleted database.");
9191
}
@@ -105,21 +105,10 @@ export class Database {
105105
}
106106
};
107107

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-
}
108+
Object.defineProperty(Repo.prototype, 'database', {
109+
get() {
110+
return this.__database || (this.__database = new Database(this));
111+
}
123112
});
124113

125114
class DatabaseInternals {

src/database/api/Query.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ import { DataSnapshot } from './DataSnapshot';
2222

2323
let __referenceConstructor: new(repo: Repo, path: Path) => Query;
2424

25+
export interface SnapshotCallback {
26+
(a: DataSnapshot, b?: string): any
27+
}
28+
2529
/**
2630
* A Query represents a filter to be applied to a firebase location. This object purely represents the
2731
* query expression (and exposes our public API to build the query). The actual query logic is in ViewBase.js.
@@ -143,8 +147,8 @@ export class Query {
143147
* @param {Object=} context
144148
* @return {!function(DataSnapshot, string=)}
145149
*/
146-
on(eventType: string, callback: (a: DataSnapshot, b?: string) => any,
147-
cancelCallbackOrContext?: ((a: Error) => any) | Object, context?: Object): (a: DataSnapshot, b?: string) => any {
150+
on(eventType: string, callback: SnapshotCallback,
151+
cancelCallbackOrContext?: ((a: Error) => any) | Object, context?: Object): SnapshotCallback {
148152
validateArgCount('Query.on', 2, 4, arguments.length);
149153
validateEventType('Query.on', 1, eventType, false);
150154
validateCallback('Query.on', 2, callback, false);
@@ -177,7 +181,7 @@ export class Query {
177181
* @param {?function(Error)} cancelCallback
178182
* @param {?Object} context
179183
*/
180-
onChildEvent(callbacks: { [k: string]: (a: DataSnapshot, b: string | null) => any },
184+
onChildEvent(callbacks: { [k: string]: SnapshotCallback },
181185
cancelCallback: ((a: Error) => any) | null, context: Object | null) {
182186
const container = new ChildEventRegistration(callbacks, cancelCallback, context);
183187
this.repo.addEventCallbackForQuery(this, container);
@@ -188,7 +192,7 @@ export class Query {
188192
* @param {(function(!DataSnapshot, ?string=))=} callback
189193
* @param {Object=} context
190194
*/
191-
off(eventType?: string, callback?: (a: DataSnapshot, b?: string | null) => any, context?: Object) {
195+
off(eventType?: string, callback?: SnapshotCallback, context?: Object) {
192196
validateArgCount('Query.off', 0, 3, arguments.length);
193197
validateEventType('Query.off', 1, eventType, true);
194198
validateCallback('Query.off', 2, callback, true);
@@ -218,9 +222,8 @@ export class Query {
218222
* @return {!firebase.Promise}
219223
*/
220224
once(eventType: string,
221-
userCallback?: (a: DataSnapshot, b?: string) => any,
222-
cancelOrContext?,
223-
context?: Object): Promise<DataSnapshot> {
225+
userCallback?: SnapshotCallback,
226+
cancelOrContext?, context?: Object): Promise<DataSnapshot> {
224227
validateArgCount('Query.once', 1, 4, arguments.length);
225228
validateEventType('Query.once', 1, eventType, false);
226229
validateCallback('Query.once', 2, userCallback, true);
@@ -378,7 +381,7 @@ export class Query {
378381
}
379382

380383
// Calling with no params tells us to start at the beginning.
381-
if (value == null) {
384+
if (value === undefined) {
382385
value = null;
383386
name = null;
384387
}

src/database/api/TransactionResult.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,5 @@ export class TransactionResult {
66
* @param {boolean} committed
77
* @param {fb.api.DataSnapshot} snapshot
88
*/
9-
constructor(committed, snapshot) {
10-
/**
11-
* @type {boolean}
12-
*/
13-
this['committed'] = committed;
14-
/**
15-
* @type {fb.api.DataSnapshot}
16-
*/
17-
this['snapshot'] = snapshot;
18-
}
9+
constructor(public committed, public snapshot) {}
1910
}

src/database/core/Repo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class Repo {
3737
dataUpdateCount;
3838
serverSyncTree_: SyncTree;
3939

40-
private repoInfo_;
40+
public repoInfo_;
4141
private stats_;
4242
private statsListener_;
4343
private eventQueue_;
@@ -84,7 +84,7 @@ export class Repo {
8484
const authOverride = app.options['databaseAuthVariableOverride'];
8585
// Validate authOverride
8686
if (typeof authOverride !== 'undefined' && authOverride !== null) {
87-
if (authOverride !== 'object') {
87+
if (typeof authOverride !== 'object') {
8888
throw new Error('Only objects are supported for option databaseAuthVariableOverride');
8989
}
9090
try {

tests/config/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"apiKey":"AIzaSyBNHCyZ-bpv-WA-HpXTmigJm2aq3z1kaH8","authDomain":"jscore-sandbox-141b5.firebaseapp.com","databaseURL":"https://jscore-sandbox-141b5.firebaseio.com","projectId":"jscore-sandbox-141b5","storageBucket":"jscore-sandbox-141b5.appspot.com","messagingSenderId":"280127633210"}

0 commit comments

Comments
 (0)