Skip to content

Commit ae6b3c4

Browse files
committed
refactor(database): Several classes and utility methods
1 parent 6515f83 commit ae6b3c4

File tree

12 files changed

+32
-32
lines changed

12 files changed

+32
-32
lines changed

src/database/api/Database.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,8 @@ import { RepoInfo } from '../core/RepoInfo';
1515
* @implements {FirebaseService}
1616
*/
1717
export class Database implements FirebaseService {
18-
/** @type {Reference} */
19-
private root_: Reference;
20-
21-
/** @type {DatabaseInternals} */
2218
INTERNAL: DatabaseInternals;
23-
24-
app: FirebaseApp | null;
19+
private root_: Reference;
2520

2621
static readonly ServerValue = {
2722
'TIMESTAMP': {
@@ -108,8 +103,7 @@ export class Database implements FirebaseService {
108103
}
109104
}
110105

111-
class DatabaseInternals {
112-
database
106+
export class DatabaseInternals {
113107
/** @param {!Database} database */
114108
constructor(public database: Database) {
115109
}

src/database/core/RepoInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { LONG_POLLING, WEBSOCKET } from '../realtime/Constants';
66

77
/**
88
* A class that holds metadata about a Repo object
9-
*
9+
*
1010
* @constructor
1111
*/
1212
export class RepoInfo {

src/database/core/SparseSnapshotTree.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class SparseSnapshotTree {
3434
const childKey = path.getFront();
3535
path = path.popFront();
3636
if (this.children_.contains(childKey)) {
37-
const childTree = this.children_.get(childKey) as SparseSnapshotTree;
37+
const childTree = <SparseSnapshotTree>this.children_.get(childKey) as SparseSnapshotTree;
3838
return childTree.find(path);
3939
} else {
4040
return null;
@@ -67,7 +67,7 @@ export class SparseSnapshotTree {
6767
this.children_.add(childKey, new SparseSnapshotTree());
6868
}
6969

70-
const child = this.children_.get(childKey) as SparseSnapshotTree;
70+
const child = <SparseSnapshotTree>this.children_.get(childKey) as SparseSnapshotTree;
7171
path = path.popFront();
7272
child.remember(path, data);
7373
}

src/database/core/SyncTree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ export class SyncTree {
521521
let queries: Query[] = [];
522522
if (maybeChildSyncPoint) {
523523
queries = queries.concat(
524-
maybeChildSyncPoint.getQueryViews().map(view => view.getQuery())
524+
maybeChildSyncPoint.getQueryViews().map(view=> view.getQuery())
525525
);
526526
}
527527
forEach(childMap, function (key: string, childQueries: Query[]) {

src/database/core/WriteTree.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export class WriteTree {
239239
* @return {!ChildrenNode}
240240
*/
241241
calcCompleteEventChildren(treePath: Path, completeServerChildren: ChildrenNode | null) {
242-
let completeChildren = ChildrenNode.EMPTY_NODE as Node;
242+
let completeChildren = <Node>ChildrenNode.EMPTY_NODE as Node;
243243
const topLevelSet = this.visibleWrites_.getCompleteNode(treePath);
244244
if (topLevelSet) {
245245
if (!topLevelSet.isLeafNode()) {
@@ -385,8 +385,8 @@ export class WriteTree {
385385
if (!toIterate.isEmpty() && !toIterate.isLeafNode()) {
386386
const nodes = [];
387387
const cmp = index.getCompare();
388-
const iter = reverse ? (toIterate as ChildrenNode).getReverseIteratorFrom(startPost, index) :
389-
(toIterate as ChildrenNode).getIteratorFrom(startPost, index);
388+
const iter = reverse ? (toIterateas ChildrenNode).getReverseIteratorFrom(startPost, index) :
389+
(toIterateas ChildrenNode).getIteratorFrom(startPost, index);
390390
let next = iter.getNext();
391391
while (next && nodes.length < count) {
392392
if (cmp(next, startPost) !== 0) {
@@ -563,7 +563,7 @@ export class WriteTreeRef {
563563
* @return {!ChildrenNode}
564564
*/
565565
calcCompleteEventChildren(completeServerChildren: ChildrenNode | null): ChildrenNode {
566-
return this.writeTree_.calcCompleteEventChildren(this.treePath_, completeServerChildren) as ChildrenNode;
566+
return <ChildrenNode>this.writeTree_.calcCompleteEventChildren(this.treePath_, completeServerChildren) as ChildrenNode;
567567
}
568568

569569
/**

src/database/core/util/CountedSet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ export class CountedSet<K, V> {
2929
* @return {V}
3030
*/
3131
get(item: K): V | void {
32-
return this.contains(item) ? this.set[item as any] : undefined;
32+
return this.contains(item) ? this.set[<any>item as any] : undefined;
3333
}
3434

3535
/**
3636
* @param {!K} item
3737
*/
3838
remove(item: K) {
39-
delete this.set[item as any];
39+
delete this.set[<any>item as any];
4040
}
4141

4242
/**

src/database/core/util/Path.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class Path {
4040

4141
this.pieceNum_ = 0;
4242
} else {
43-
this.pieces_ = pathOrString as string[];
43+
this.pieces_ = <string[]>pathOrString as string[];
4444
this.pieceNum_ = pieceNum;
4545
}
4646
}

src/database/core/util/SortedMap.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class SortedMapIterator<K, V, T> {
8383
if (this.resultGenerator_)
8484
result = this.resultGenerator_(node.key, node.value);
8585
else
86-
result = {key: node.key, value: node.value} as any;
86+
result = <any>{key: node.key, value: node.value} as any;
8787

8888
if (this.isReverse_) {
8989
node = node.left;
@@ -114,7 +114,7 @@ export class SortedMapIterator<K, V, T> {
114114
if (this.resultGenerator_) {
115115
return this.resultGenerator_(node.key, node.value);
116116
} else {
117-
return {key: node.key, value: node.value} as any;
117+
return <any>{key: node.key, value: node.value} as any;
118118
}
119119
}
120120
}
@@ -303,7 +303,7 @@ export class LLRBNode<K, V> {
303303
} else {
304304
smallest = (n.right as LLRBNode<K,V>).min_();
305305
n = n.copy(smallest.key, smallest.value, null, null,
306-
(n.right as LLRBNode<K,V>).removeMin_());
306+
(n.rightas LLRBNode<K,V>).removeMin_());
307307
}
308308
}
309309
n = n.copy(null, null, null, null, n.right.remove(key, comparator));
@@ -364,7 +364,7 @@ export class LLRBNode<K, V> {
364364
*/
365365
private rotateLeft_(): LLRBNode<K,V> {
366366
const nl = this.copy(null, null, LLRBNode.RED, null, this.right.left);
367-
return this.right.copy(null, null, this.color, nl, null) as LLRBNode<K,V>;
367+
return <LLRBNode<K,V>>this.right.copy(null, null, this.color, nl, null) as LLRBNode<K,V>;
368368
}
369369

370370
/**
@@ -373,7 +373,7 @@ export class LLRBNode<K, V> {
373373
*/
374374
private rotateRight_(): LLRBNode<K,V> {
375375
const nr = this.copy(null, null, LLRBNode.RED, this.left.right, null);
376-
return this.left.copy(null, null, this.color, null, nr) as LLRBNode<K,V>;
376+
return <LLRBNode<K,V>>this.left.copy(null, null, this.color, null, nr) as LLRBNode<K,V>;
377377
}
378378

379379
/**

src/database/core/util/util.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ export const warnAboutUnsupportedMethod = function (methodName: string) {
240240
*/
241241
export const isInvalidJSONNumber = function (data: any): boolean {
242242
return typeof data === 'number' &&
243-
(data != data || // NaN
244-
data == Number.POSITIVE_INFINITY ||
245-
data == Number.NEGATIVE_INFINITY);
243+
(data != data || // NaN
244+
data == Number.POSITIVE_INFINITY ||
245+
data == Number.NEGATIVE_INFINITY);
246246
};
247247

248248

src/database/realtime/Connection.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class Connection {
121121

122122
const healthyTimeout_ms = conn['healthyTimeout'] || 0;
123123
if (healthyTimeout_ms > 0) {
124-
this.healthyTimeout_ = setTimeoutNonBlocking(() => {
124+
this.healthyTimeout_ = <number><any>setTimeoutNonBlocking(() => {
125125
this.healthyTimeout_ = null;
126126
if (!this.isHealthy_) {
127127
if (this.conn_ && this.conn_.bytesReceived > BYTES_RECEIVED_HEALTHY_OVERRIDE) {
@@ -199,7 +199,7 @@ export class Connection {
199199

200200
private onSecondaryControl_(controlData: { [k: string]: any }) {
201201
if (MESSAGE_TYPE in controlData) {
202-
const cmd = controlData[MESSAGE_TYPE] as string;
202+
const cmd: string = controlData[MESSAGE_TYPE] as string;
203203
if (cmd === SWITCH_ACK) {
204204
this.upgradeIfSecondaryHealthy_();
205205
} else if (cmd === CONTROL_RESET) {
@@ -292,7 +292,7 @@ export class Connection {
292292
private onControl_(controlData: { [k: string]: any }) {
293293
const cmd: string = requireKey(MESSAGE_TYPE, controlData);
294294
if (MESSAGE_DATA in controlData) {
295-
const payload = controlData[MESSAGE_DATA];
295+
const payload: any = controlData[MESSAGE_DATA];
296296
if (cmd === SERVER_HELLO) {
297297
this.onHandshake_(payload);
298298
} else if (cmd === END_TRANSMISSION) {

src/database/realtime/Transport.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,10 @@ export abstract class Transport {
5252
abstract send(data: Object): void;
5353

5454
abstract markConnectionHealthy(): void;
55+
56+
abstract markConnectionHealthy();
57+
}
58+
59+
export interface TransportConstructor {
60+
new(connId: string, RepoInfo, transportSessionId?: string, lastSessionId?: string);
5561
}

src/database/realtime/WebSocketConnection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ export class WebSocketConnection implements Transport {
273273
handleIncomingFrame(mess: { [k: string]: any }) {
274274
if (this.mySock === null)
275275
return; // Chrome apparently delivers incoming packets even after we .close() the connection sometimes.
276-
const data = mess['data'] as string;
276+
const data: string = mess['data'] as string;
277277
this.bytesReceived += data.length;
278278
this.stats_.incrementCounter('bytes_received', data.length);
279279

@@ -362,7 +362,7 @@ export class WebSocketConnection implements Transport {
362362
*/
363363
resetKeepAlive() {
364364
clearInterval(this.keepaliveTimer);
365-
this.keepaliveTimer = setInterval(() => {
365+
this.keepaliveTimer = <number><any>setInterval(() => {
366366
//If there has been no websocket activity for a while, send a no-op
367367
if (this.mySock) {
368368
this.sendString_('0');

0 commit comments

Comments
 (0)