Skip to content

Commit cd3095d

Browse files
Merge
2 parents fe82b46 + c08851c commit cd3095d

File tree

68 files changed

+385
-319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+385
-319
lines changed

integration/browserify/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"test": "karma start --single-run"
88
},
99
"dependencies": {
10-
"firebase": "5.4.0"
10+
"firebase": "5.4.1"
1111
},
1212
"devDependencies": {
1313
"@babel/core": "7.0.0-beta.47",

integration/firebase-typings/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"test": "tsc index.ts --outDir dist"
77
},
88
"dependencies": {
9-
"firebase": "5.4.0"
9+
"firebase": "5.4.1"
1010
},
1111
"devDependencies": {
1212
"typescript": "2.8.1"

integration/messaging/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"test:manual": "mocha --exit"
99
},
1010
"dependencies": {
11-
"firebase": "5.4.0"
11+
"firebase": "5.4.1"
1212
},
1313
"devDependencies": {
1414
"chai": "4.1.2",

integration/typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"test": "karma start --single-run"
77
},
88
"dependencies": {
9-
"firebase": "5.4.0"
9+
"firebase": "5.4.1"
1010
},
1111
"devDependencies": {
1212
"@babel/core": "7.0.0-beta.47",

integration/webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"test": "karma start --single-run"
88
},
99
"dependencies": {
10-
"firebase": "5.4.0"
10+
"firebase": "5.4.1"
1111
},
1212
"devDependencies": {
1313
"@babel/core": "7.0.0-beta.47",

packages/auth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@firebase/auth",
3-
"version": "0.7.2",
3+
"version": "0.7.3",
44
"main": "dist/auth.js",
55
"module": "dist/auth.esm.js",
66
"description": "Javascript library for Firebase Auth SDK",

packages/auth/src/storage/indexeddb.js

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ fireauth.storage.IndexedDB = function(
9999
opt_indexedDB || goog.global.indexedDB);
100100
/** @public {string} The storage type identifier. */
101101
this.type = fireauth.storage.Storage.Type.INDEXEDDB;
102+
/**
103+
* @private {?goog.Promise<void>} The pending polling promise for syncing
104+
* unprocessed indexedDB external changes.
105+
*/
106+
this.poll_ = null;
107+
/**
108+
* @private {?number} The poll timer ID for syncing external indexedDB
109+
* changes.
110+
*/
111+
this.pollTimerId_ = null;
102112
/**
103113
* @private {?fireauth.messagechannel.Receiver} The messageChannel receiver if
104114
* running from a serviceworker.
@@ -634,29 +644,30 @@ fireauth.storage.IndexedDB.prototype.startListeners_ = function() {
634644
var self = this;
635645
// Stop any previous listeners.
636646
this.stopListeners_();
637-
// Repeat sync every fireauth.storage.IndexedDB.POLLING_DELAY_ ms.
638647
var repeat = function() {
639-
self.poll_ =
640-
goog.Timer.promise(fireauth.storage.IndexedDB.POLLING_DELAY_)
641-
.then(goog.bind(self.sync_, self))
642-
.then(function(keys) {
643-
// If keys modified, call listeners.
644-
if (keys.length > 0) {
645-
goog.array.forEach(
646-
self.storageListeners_,
647-
function(listener) {
648-
listener(keys);
649-
});
650-
}
651-
})
652-
.then(repeat)
653-
.thenCatch(function(error) {
654-
// Do not repeat if cancelled externally.
655-
if (error.message != fireauth.storage.IndexedDB.STOP_ERROR_) {
656-
repeat();
657-
}
658-
});
659-
return self.poll_;
648+
self.pollTimerId_ = setTimeout(
649+
function() {
650+
self.poll_ = self.sync_()
651+
.then(function(keys) {
652+
// If keys modified, call listeners.
653+
if (keys.length > 0) {
654+
goog.array.forEach(
655+
self.storageListeners_,
656+
function(listener) {
657+
listener(keys);
658+
});
659+
}
660+
})
661+
.then(function() {
662+
repeat();
663+
})
664+
.thenCatch(function(error) {
665+
if (error.message != fireauth.storage.IndexedDB.STOP_ERROR_) {
666+
repeat();
667+
}
668+
});
669+
},
670+
fireauth.storage.IndexedDB.POLLING_DELAY_);
660671
};
661672
repeat();
662673
};
@@ -671,4 +682,9 @@ fireauth.storage.IndexedDB.prototype.stopListeners_ = function() {
671682
// Cancel polling function.
672683
this.poll_.cancel(fireauth.storage.IndexedDB.STOP_ERROR_);
673684
}
685+
// Clear any pending polling timer.
686+
if (this.pollTimerId_) {
687+
clearTimeout(this.pollTimerId_);
688+
this.pollTimerId_ = null;
689+
}
674690
};

packages/auth/test/storage/indexeddb_test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,43 @@ function testStopListeners() {
408408
assertEquals(1, listener3.getCallCount());
409409
assertArrayEquals(
410410
['key1', 'key2'], listener3.getLastCall().getArgument(0));
411+
db.store['firebaseLocalStorage'] = {
412+
'key1': {'fbase_key': 'key1', 'value': 1},
413+
'key3': {'fbase_key': 'key3', 'value': 3}
414+
};
415+
clock.tick(800);
416+
// Only listener3 should be called.
417+
assertEquals(0, listener1.getCallCount());
418+
assertEquals(0, listener2.getCallCount());
419+
assertEquals(2, listener3.getCallCount());
420+
assertArrayEquals(
421+
['key2', 'key3'], listener3.getLastCall().getArgument(0));
422+
// Remove listener3.
423+
manager.removeStorageListener(listener3);
424+
// Add listener1 again.
425+
manager.addStorageListener(listener1);
426+
db.store['firebaseLocalStorage'] = {
427+
'key1': {'fbase_key': 'key1', 'value': 0},
428+
'key3': {'fbase_key': 'key3', 'value': 3},
429+
'key4': {'fbase_key': 'key4', 'value': 4}
430+
};
431+
clock.tick(800);
432+
// Only listener1 should be called.
433+
assertEquals(1, listener1.getCallCount());
434+
assertEquals(0, listener2.getCallCount());
435+
assertEquals(2, listener3.getCallCount());
436+
assertArrayEquals(
437+
['key1', 'key4'], listener1.getLastCall().getArgument(0));
438+
// Remove all listeners.
439+
manager.removeAllStorageListeners();
440+
db.store['firebaseLocalStorage'] = {
441+
'key1': {'fbase_key': 'key1', 'value': 0}
442+
};
443+
clock.tick(800);
444+
// No additional listener should be called.
445+
assertEquals(1, listener1.getCallCount());
446+
assertEquals(0, listener2.getCallCount());
447+
assertEquals(2, listener3.getCallCount());
411448
}
412449

413450

packages/firebase/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "firebase",
3-
"version": "5.4.0",
3+
"version": "5.4.1",
44
"description": "Firebase JavaScript library for web and Node.js",
55
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
66
"license": "Apache-2.0",
@@ -36,9 +36,9 @@
3636
"react-native": "dist/index.rn.cjs.js",
3737
"dependencies": {
3838
"@firebase/app": "0.3.3",
39-
"@firebase/auth": "0.7.2",
39+
"@firebase/auth": "0.7.3",
4040
"@firebase/database": "0.3.4",
41-
"@firebase/firestore": "0.7.0",
41+
"@firebase/firestore": "0.7.1",
4242
"@firebase/functions": "0.3.0",
4343
"@firebase/messaging": "0.3.5",
4444
"@firebase/polyfill": "0.3.3",

packages/firestore/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@firebase/firestore",
3-
"version": "0.7.0",
3+
"version": "0.7.1",
44
"description": "",
55
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
66
"scripts": {

packages/firestore/src/api/database.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,12 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
319319

320320
enableNetwork(): Promise<void> {
321321
this.ensureClientConfigured();
322-
return this._firestoreClient.enableNetwork();
322+
return this._firestoreClient!.enableNetwork();
323323
}
324324

325325
disableNetwork(): Promise<void> {
326326
this.ensureClientConfigured();
327-
return this._firestoreClient.disableNetwork();
327+
return this._firestoreClient!.disableNetwork();
328328
}
329329

330330
enablePersistence(settings?: _PersistenceSettings): Promise<void> {
@@ -597,7 +597,7 @@ export class Transaction implements firestore.Transaction {
597597
} else if (doc instanceof Document) {
598598
return new DocumentSnapshot(this._firestore, ref._key, doc, false);
599599
} else {
600-
fail('MaybeDocument is neither Document nor NoDocument');
600+
throw fail('MaybeDocument is neither Document nor NoDocument');
601601
}
602602
});
603603
}
@@ -1060,8 +1060,8 @@ export class DocumentReference implements firestore.DocumentReference {
10601060
}
10611061

10621062
get(options?: firestore.GetOptions): Promise<firestore.DocumentSnapshot> {
1063-
validateOptionNames('DocumentReference.get', options, ['source']);
10641063
if (options) {
1064+
validateOptionNames('DocumentReference.get', options, ['source']);
10651065
validateNamedOptionalPropertyEquals(
10661066
'DocumentReference.get',
10671067
'options',
@@ -1888,11 +1888,10 @@ export class QuerySnapshot implements firestore.QuerySnapshot {
18881888
docChanges(
18891889
options?: firestore.SnapshotListenOptions
18901890
): firestore.DocumentChange[] {
1891-
validateOptionNames('QuerySnapshot.docChanges', options, [
1892-
'includeMetadataChanges'
1893-
]);
1894-
18951891
if (options) {
1892+
validateOptionNames('QuerySnapshot.docChanges', options, [
1893+
'includeMetadataChanges'
1894+
]);
18961895
validateNamedOptionalType(
18971896
'QuerySnapshot.docChanges',
18981897
'boolean',
@@ -1901,7 +1900,9 @@ export class QuerySnapshot implements firestore.QuerySnapshot {
19011900
);
19021901
}
19031902

1904-
const includeMetadataChanges = options && options.includeMetadataChanges;
1903+
const includeMetadataChanges = !!(
1904+
options && options.includeMetadataChanges
1905+
);
19051906

19061907
if (includeMetadataChanges && this._snapshot.excludesMetadataChanges) {
19071908
throw new FirestoreError(
@@ -2030,7 +2031,7 @@ export class CollectionReference extends Query
20302031
'Document path must be a non-empty string'
20312032
);
20322033
}
2033-
const path = ResourcePath.fromString(pathString);
2034+
const path = ResourcePath.fromString(pathString!);
20342035
return DocumentReference.forPath(
20352036
this._query.path.child(path),
20362037
this.firestore

packages/firestore/src/api/user_data_converter.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,20 +339,22 @@ export class UserDataConverter {
339339
fieldMask = new FieldMask(context.fieldMask);
340340
fieldTransforms = context.fieldTransforms;
341341
} else {
342-
const validatedFieldPaths = [];
342+
const validatedFieldPaths: FieldPath[] = [];
343343

344344
for (const stringOrFieldPath of fieldPaths) {
345-
let fieldPath;
345+
let fieldPath: FieldPath;
346346

347347
if (stringOrFieldPath instanceof ExternalFieldPath) {
348-
fieldPath = stringOrFieldPath as ExternalFieldPath;
348+
fieldPath = stringOrFieldPath._internalPath;
349349
} else if (typeof stringOrFieldPath === 'string') {
350350
fieldPath = fieldPathFromDotSeparatedString(
351351
methodName,
352352
stringOrFieldPath
353353
);
354354
} else {
355-
fail('Expected stringOrFieldPath to be a string or a FieldPath');
355+
throw fail(
356+
'Expected stringOrFieldPath to be a string or a FieldPath'
357+
);
356358
}
357359

358360
if (!context.contains(fieldPath)) {
@@ -693,7 +695,7 @@ export class UserDataConverter {
693695
methodName,
694696
FieldPath.EMPTY_PATH
695697
);
696-
return this.parseData(element, context.childContextForArray(i));
698+
return this.parseData(element, context.childContextForArray(i))!;
697699
});
698700
}
699701
}

packages/firestore/src/core/firestore_client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ export class FirestoreClient {
508508
return view.applyChanges(
509509
viewDocChanges,
510510
/* updateLimboDocuments= */ false
511-
).snapshot;
511+
).snapshot!;
512512
});
513513
}
514514

packages/firestore/src/core/query.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,8 @@ export class NanFilter extends Filter {
591591
}
592592

593593
matches(doc: Document): boolean {
594-
const val = doc.field(this.field).value();
594+
const field = doc.field(this.field);
595+
const val = field && field.value();
595596
return typeof val === 'number' && isNaN(val);
596597
}
597598

@@ -680,7 +681,7 @@ export class Bound {
680681
docValue !== undefined,
681682
'Field should exist since document matched the orderBy already.'
682683
);
683-
comparison = component.compareTo(docValue);
684+
comparison = component.compareTo(docValue!);
684685
}
685686
if (orderByComponent.dir === Direction.DESCENDING) {
686687
comparison = comparison * -1;

packages/firestore/src/core/sync_engine.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
252252
);
253253
const viewChange = view.applyChanges(
254254
viewDocChanges,
255-
/* updateLimboDocuments= */ this.isPrimary,
255+
/* updateLimboDocuments= */ this.isPrimary === true,
256256
synthesizedTargetChange
257257
);
258258
assert(
@@ -781,7 +781,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
781781
remoteEvent && remoteEvent.targetChanges[queryView.targetId];
782782
const viewChange = queryView.view.applyChanges(
783783
viewDocChanges,
784-
/* updateLimboDocuments= */ this.isPrimary,
784+
/* updateLimboDocuments= */ this.isPrimary === true,
785785
targetChange
786786
);
787787
return this.updateTrackedLimbos(
@@ -809,7 +809,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
809809
});
810810

811811
await Promise.all(queriesProcessed);
812-
this.syncEngineListener.onWatchChange(newSnaps);
812+
this.syncEngineListener!.onWatchChange(newSnaps);
813813
this.localStore.notifyLocalViewChanges(docChangesInAllViews);
814814
// TODO(multitab): Multitab garbage collection
815815
if (this.isPrimary) {
@@ -940,13 +940,14 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
940940
}
941941
} else {
942942
assert(
943-
this.isPrimary,
943+
this.isPrimary === true,
944944
'A secondary tab should never have an active query without an active view.'
945945
);
946946
// For queries that never executed on this client, we need to
947947
// allocate the query in LocalStore and initialize a new View.
948948
const query = await this.localStore.getQueryForTarget(targetId);
949-
queryData = await this.localStore.allocateQuery(query);
949+
assert(!!query, `Query data for target ${targetId} not found`);
950+
queryData = await this.localStore.allocateQuery(query!);
950951
await this.initializeViewAndComputeSnapshot(
951952
queryData,
952953
/*current=*/ false
@@ -1000,7 +1001,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
10001001
queryView.query,
10011002
/*keepPersistedQueryData=*/ true
10021003
);
1003-
this.syncEngineListener!.onWatchError(queryView.query, error);
1004+
this.syncEngineListener!.onWatchError(queryView.query, error!);
10041005
break;
10051006
}
10061007
default:
@@ -1025,7 +1026,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
10251026
);
10261027
const query = await this.localStore.getQueryForTarget(targetId);
10271028
assert(!!query, `Query data for active target ${targetId} not found`);
1028-
const queryData = await this.localStore.allocateQuery(query);
1029+
const queryData = await this.localStore.allocateQuery(query!);
10291030
await this.initializeViewAndComputeSnapshot(
10301031
queryData,
10311032
/*current=*/ false

0 commit comments

Comments
 (0)