Skip to content

Commit 9f38d85

Browse files
committed
Roll back database changes
1 parent 21e14c0 commit 9f38d85

17 files changed

+63
-70
lines changed

packages/database/index.node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export function registerDatabase(instance: FirebaseNamespace) {
8181
ServerValue,
8282
TEST_ACCESS
8383
},
84-
undefined,
84+
null,
8585
true
8686
);
8787

packages/database/src/api/Database.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { RepoInfo } from '../core/RepoInfo';
3232
* @implements {FirebaseService}
3333
*/
3434
export class Database implements FirebaseService {
35-
INTERNAL?: DatabaseInternals;
35+
INTERNAL: DatabaseInternals;
3636
private root_: Reference;
3737

3838
static readonly ServerValue = {
@@ -141,7 +141,7 @@ export class Database implements FirebaseService {
141141

142142
export class DatabaseInternals {
143143
/** @param {!Database} database */
144-
constructor(public database?: Database) {}
144+
constructor(public database: Database) {}
145145

146146
/** @return {Promise<void>} */
147147
async delete(): Promise<void> {
@@ -150,9 +150,7 @@ export class DatabaseInternals {
150150

151151
(this.database as any).repo_ = null;
152152
(this.database as any).root_ = null;
153-
if (this.database) {
154-
this.database.INTERNAL = undefined;
155-
}
156-
this.database = undefined;
153+
this.database.INTERNAL = null;
154+
this.database = null;
157155
}
158156
}

packages/database/src/api/Query.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export class Query {
254254
const container = new ChildEventRegistration(
255255
callbacks,
256256
cancelCallback,
257-
context || undefined
257+
context
258258
);
259259
this.repo.addEventCallbackForQuery(this, container);
260260
}
@@ -270,7 +270,7 @@ export class Query {
270270
context?: Object | null
271271
): void {
272272
validateArgCount('Query.off', 0, 3, arguments.length);
273-
validateEventType('Query.off', 1, eventType || '', true);
273+
validateEventType('Query.off', 1, eventType, true);
274274
validateCallback('Query.off', 2, callback, true);
275275
validateContextObject('Query.off', 3, context, true);
276276

@@ -288,7 +288,7 @@ export class Query {
288288
callbacks = {};
289289
callbacks[eventType] = callback;
290290
}
291-
container = new ChildEventRegistration(callbacks, null, context || undefined);
291+
container = new ChildEventRegistration(callbacks, null, context || null);
292292
}
293293
this.repo.removeEventCallbackForQuery(this, container);
294294
}
@@ -498,7 +498,7 @@ export class Query {
498498
): Query {
499499
validateArgCount('Query.startAt', 0, 2, arguments.length);
500500
validateFirebaseDataArg('Query.startAt', 1, value, this.path, true);
501-
validateKey('Query.startAt', 2, name || undefined, true);
501+
validateKey('Query.startAt', 2, name, true);
502502

503503
const newParams = this.queryParams_.startAt(value, name);
504504
Query.validateLimit_(newParams);
@@ -529,7 +529,7 @@ export class Query {
529529
): Query {
530530
validateArgCount('Query.endAt', 0, 2, arguments.length);
531531
validateFirebaseDataArg('Query.endAt', 1, value, this.path, true);
532-
validateKey('Query.endAt', 2, name || undefined, true);
532+
validateKey('Query.endAt', 2, name, true);
533533

534534
const newParams = this.queryParams_.endAt(value, name);
535535
Query.validateLimit_(newParams);

packages/database/src/core/Repo.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class Repo {
132132
}
133133

134134
authTokenProvider.addTokenChangeListener(token => {
135-
token && this.server_.refreshAuthToken(token);
135+
this.server_.refreshAuthToken(token);
136136
});
137137

138138
// In the case of multiple Repos for the same repoInfo (i.e. there are multiple Firebase.Contexts being used),
@@ -240,7 +240,7 @@ export class Repo {
240240
data = this.interceptServerDataCallback_
241241
? this.interceptServerDataCallback_(pathString, data)
242242
: data;
243-
let events: Array<Event> = [];
243+
let events = [];
244244
if (tag) {
245245
if (isMerge) {
246246
const taggedChildren = map(data as { [k: string]: any }, (raw: any) =>
@@ -602,7 +602,7 @@ export class Repo {
602602
*/
603603
removeEventCallbackForQuery(
604604
query: Query,
605-
eventRegistration: EventRegistration | null
605+
eventRegistration: EventRegistration
606606
) {
607607
// These are guaranteed not to raise events, since we're not passing in a cancelError. However, we can future-proof
608608
// a little bit by handling the return values anyways.

packages/database/src/core/RepoManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class RepoManager {
8080
* @return {!Database}
8181
*/
8282
databaseFromApp(app: FirebaseApp, url?: string): Database {
83-
const dbUrl: string | undefined = url || app.options[DATABASE_URL_OPTION];
83+
const dbUrl: string = url || app.options[DATABASE_URL_OPTION];
8484
if (dbUrl === undefined) {
8585
fatal(
8686
"Can't determine Firebase Database URL. Be sure to include " +
@@ -89,7 +89,7 @@ export class RepoManager {
8989
);
9090
}
9191

92-
const parsedUrl = parseRepoInfo(dbUrl || '');
92+
const parsedUrl = parseRepoInfo(dbUrl);
9393
const repoInfo = parsedUrl.repoInfo;
9494

9595
validateUrl('Invalid Firebase Database URL', 1, parsedUrl);

packages/database/src/core/SparseSnapshotTree.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class SparseSnapshotTree {
4848
if (this.value_ != null) {
4949
return this.value_.getChild(path);
5050
} else if (!path.isEmpty() && this.children_ != null) {
51-
const childKey = path.getFront() || '';
51+
const childKey = path.getFront();
5252
path = path.popFront();
5353
if (this.children_.contains(childKey)) {
5454
const childTree = this.children_.get(childKey) as SparseSnapshotTree;
@@ -79,7 +79,7 @@ export class SparseSnapshotTree {
7979
this.children_ = new CountedSet<string, SparseSnapshotTree>();
8080
}
8181

82-
const childKey = path.getFront() || '';
82+
const childKey = path.getFront();
8383
if (!this.children_.contains(childKey)) {
8484
this.children_.add(childKey, new SparseSnapshotTree());
8585
}
@@ -118,7 +118,7 @@ export class SparseSnapshotTree {
118118
return this.forget(path);
119119
}
120120
} else if (this.children_ !== null) {
121-
const childKey = path.getFront() || '';
121+
const childKey = path.getFront();
122122
path = path.popFront();
123123
if (this.children_.contains(childKey)) {
124124
const safeToRemove = (this.children_.get(

packages/database/src/core/SyncPoint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export class SyncPoint {
149149
false
150150
),
151151
new CacheNode(
152-
/** @type {!Node} */ (serverCache as Node),
152+
/** @type {!Node} */ (serverCache),
153153
serverCacheComplete,
154154
false
155155
)

packages/database/src/core/SyncTree.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export class SyncTree {
163163
ackUserWrite(writeId: number, revert: boolean = false) {
164164
const write = this.pendingWriteTree_.getWrite(writeId);
165165
const needToReevaluate = this.pendingWriteTree_.removeWrite(writeId);
166-
if (!needToReevaluate || !write) {
166+
if (!needToReevaluate) {
167167
return [];
168168
} else {
169169
let affectedTree = ImmutableTree.Empty;
@@ -350,7 +350,7 @@ export class SyncTree {
350350
const subtree = this.syncPointTree_.subtree(path);
351351
subtree.foreachChild(function(childName, childSyncPoint) {
352352
const completeCache = childSyncPoint.getCompleteServerCache(Path.Empty);
353-
if (completeCache && serverCache) {
353+
if (completeCache) {
354354
serverCache = serverCache.updateImmediateChild(
355355
childName,
356356
completeCache
@@ -381,7 +381,7 @@ export class SyncTree {
381381
serverCacheComplete
382382
);
383383
if (!viewAlreadyExists && !foundAncestorDefaultView) {
384-
const view /** @type !View */ = syncPoint.viewForQuery(query) as View;
384+
const view /** @type !View */ = syncPoint.viewForQuery(query);
385385
events = events.concat(this.setupListener_(query, view));
386386
}
387387
return events;
@@ -530,7 +530,7 @@ export class SyncTree {
530530
});
531531
return writeTree.calcCompleteEventCache(
532532
path,
533-
serverCache || null,
533+
serverCache,
534534
writeIdsToExclude,
535535
includeHiddenSets
536536
);
@@ -551,7 +551,7 @@ export class SyncTree {
551551
(relativePath, maybeChildSyncPoint, childMap) => {
552552
if (maybeChildSyncPoint && maybeChildSyncPoint.hasCompleteView()) {
553553
const completeView = maybeChildSyncPoint.getCompleteView();
554-
return [completeView as View];
554+
return [completeView];
555555
} else {
556556
// No complete view here, flatten any deeper listens into an array
557557
let views: View[] = [];
@@ -628,12 +628,10 @@ export class SyncTree {
628628
// The root of this subtree has our query. We're here because we definitely need to send a listen for that, but we
629629
// may need to shadow other listens as well.
630630
if (tag) {
631-
if (subtree.value) {
632-
assert(
633-
!subtree.value.hasCompleteView(),
634-
"If we're adding a query, it shouldn't be shadowed"
635-
);
636-
}
631+
assert(
632+
!subtree.value.hasCompleteView(),
633+
"If we're adding a query, it shouldn't be shadowed"
634+
);
637635
} else {
638636
// Shadow everything at or below this location, this is a default listener.
639637
const queriesToStop = subtree.fold<Query[]>(function(
@@ -646,7 +644,7 @@ export class SyncTree {
646644
maybeChildSyncPoint &&
647645
maybeChildSyncPoint.hasCompleteView()
648646
) {
649-
return [(maybeChildSyncPoint.getCompleteView() as View).getQuery()];
647+
return [maybeChildSyncPoint.getCompleteView().getQuery()];
650648
} else {
651649
// No default listener here, flatten any deeper queries into an array
652650
let queries: Query[] = [];
@@ -789,7 +787,7 @@ export class SyncTree {
789787
queryPath: Path,
790788
operation: Operation
791789
): Event[] {
792-
const syncPoint = this.syncPointTree_.get(queryPath) as SyncPoint;
790+
const syncPoint = this.syncPointTree_.get(queryPath);
793791
assert(syncPoint, "Missing sync point for query tag that we're tracking");
794792
const writesCache = this.pendingWriteTree_.childWrites(queryPath);
795793
return syncPoint.applyOperation(
@@ -857,7 +855,7 @@ export class SyncTree {
857855
}
858856

859857
let events: Event[] = [];
860-
const childName = operation.path.getFront() || '';
858+
const childName = operation.path.getFront();
861859
const childOperation = operation.operationForChild(childName);
862860
const childTree = syncPointTree.children.get(childName);
863861
if (childTree && childOperation) {

packages/database/src/core/WriteTree.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ export class WriteTree {
278278
(!writeIdsToExclude ||
279279
!~writeIdsToExclude.indexOf(write.writeId)) &&
280280
(write.path.contains(treePath) || treePath.contains(write.path))
281-
) || false;
281+
);
282282
};
283283
const mergeAtPath = WriteTree.layerTree_(
284284
this.allWrites_,
@@ -398,15 +398,15 @@ export class WriteTree {
398398
const childMerge = this.visibleWrites_.childCompoundWrite(path);
399399
if (childMerge.isEmpty()) {
400400
// We're not shadowing at all. Case 1
401-
return (existingServerSnap as Node).getChild(childPath);
401+
return existingServerSnap.getChild(childPath);
402402
} else {
403403
// This could be more efficient if the serverNode + updates doesn't change the eventSnap
404404
// However this is tricky to find out, since user updates don't necessary change the server
405405
// snap, e.g. priority updates on empty nodes, or deep deletes. Another special case is if the server
406406
// adds nodes, but doesn't change any existing writes. It is therefore not enough to
407407
// only check if the updates change the serverNode.
408408
// Maybe check if the merge tree contains these special cases and only do a full overwrite in that case?
409-
return childMerge.apply((existingServerSnap as Node).getChild(childPath));
409+
return childMerge.apply(existingServerSnap.getChild(childPath));
410410
}
411411
}
412412
}
@@ -486,7 +486,7 @@ export class WriteTree {
486486
}
487487
toIterate = toIterate.withIndex(index);
488488
if (!toIterate.isEmpty() && !toIterate.isLeafNode()) {
489-
const nodes: Array<NamedNode> = [];
489+
const nodes = [];
490490
const cmp = index.getCompare();
491491
const iter = reverse
492492
? (toIterate as ChildrenNode).getReverseIteratorFrom(startPost, index)

packages/database/src/core/util/Path.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class Path {
131131
parent(): Path | null {
132132
if (this.pieceNum_ >= this.pieces_.length) return null;
133133

134-
const pieces: Array<string> = [];
134+
const pieces = [];
135135
for (let i = this.pieceNum_; i < this.pieces_.length - 1; i++)
136136
pieces.push(this.pieces_[i]);
137137

@@ -143,7 +143,7 @@ export class Path {
143143
* @return {!Path}
144144
*/
145145
child(childPathObj: string | Path): Path {
146-
const pieces: Array<string> = [];
146+
const pieces = [];
147147
for (let i = this.pieceNum_; i < this.pieces_.length; i++)
148148
pieces.push(this.pieces_[i]);
149149

packages/database/src/core/util/ServerValues.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export const resolveDeferredValueSnapshot = function(
9494
const rawPri = node.getPriority().val() as
9595
| object
9696
| boolean
97+
| null
9798
| number
9899
| string;
99100
const priority = resolveDeferredValue(rawPri, serverValues);

packages/database/src/core/util/SortedMap.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,10 @@ export class SortedMapIterator<K, V, T> {
9191
}
9292
}
9393

94-
getNext(): T | null {
94+
getNext(): T {
9595
if (this.nodeStack_.length === 0) return null;
9696

9797
let node = this.nodeStack_.pop();
98-
99-
if (!node) return null;
100-
10198
let result: T;
10299
if (this.resultGenerator_)
103100
result = this.resultGenerator_(node.key, node.value);
@@ -124,7 +121,7 @@ export class SortedMapIterator<K, V, T> {
124121
return this.nodeStack_.length > 0;
125122
}
126123

127-
peek(): T | null {
124+
peek(): T {
128125
if (this.nodeStack_.length === 0) return null;
129126

130127
const node = this.nodeStack_[this.nodeStack_.length - 1];
@@ -262,9 +259,9 @@ export class LLRBNode<K, V> {
262259
}
263260

264261
/**
265-
* @return {K} The maximum key in the tree.
262+
* @return {!K} The maximum key in the tree.
266263
*/
267-
maxKey(): K | null {
264+
maxKey(): K {
268265
if (this.right.isEmpty()) {
269266
return this.key;
270267
} else {
@@ -673,7 +670,7 @@ export class SortedMap<K, V> {
673670
getPredecessorKey(key: K): K | null {
674671
let cmp,
675672
node = this.root_,
676-
rightParent: LLRBNode<K, V> | LLRBEmptyNode<K, V> | null = null;
673+
rightParent = null;
677674
while (!node.isEmpty()) {
678675
cmp = this.comparator_(key, node.key);
679676
if (cmp === 0) {
@@ -760,7 +757,7 @@ export class SortedMap<K, V> {
760757
*/
761758
getIterator<T>(
762759
resultGenerator?: (k: K, v: V) => T
763-
): SortedMapIterator<K | null, V, T> {
760+
): SortedMapIterator<K, V, T> {
764761
return new SortedMapIterator(
765762
this.root_,
766763
null,
@@ -773,7 +770,7 @@ export class SortedMap<K, V> {
773770
getIteratorFrom<T>(
774771
key: K,
775772
resultGenerator?: (k: K, v: V) => T
776-
): SortedMapIterator<K | null, V, T> {
773+
): SortedMapIterator<K, V, T> {
777774
return new SortedMapIterator(
778775
this.root_,
779776
key,
@@ -786,7 +783,7 @@ export class SortedMap<K, V> {
786783
getReverseIteratorFrom<T>(
787784
key: K,
788785
resultGenerator?: (k: K, v: V) => T
789-
): SortedMapIterator<K | null, V, T> {
786+
): SortedMapIterator<K, V, T> {
790787
return new SortedMapIterator(
791788
this.root_,
792789
key,
@@ -798,7 +795,7 @@ export class SortedMap<K, V> {
798795

799796
getReverseIterator<T>(
800797
resultGenerator?: (k: K, v: V) => T
801-
): SortedMapIterator<K | null, V, T> {
798+
): SortedMapIterator<K, V, T> {
802799
return new SortedMapIterator(
803800
this.root_,
804801
null,

0 commit comments

Comments
 (0)