@@ -211,55 +211,12 @@ export interface SyncEngine extends RemoteSyncer {
211
211
*/
212
212
registerPendingWritesCallback ( callback : Deferred < void > ) : Promise < void > ;
213
213
214
- /**
215
- * Triggers the callbacks that are waiting for this batch id to get acknowledged by server,
216
- * if there are any.
217
- */
218
- triggerPendingWritesCallbacks ( batchId : BatchId ) : void ;
219
-
220
- /** Reject all outstanding callbacks waiting for pending writes to complete. */
221
- rejectOutstandingPendingWritesCallbacks ( errorMessage : string ) : void ;
222
-
223
- addMutationCallback ( batchId : BatchId , callback : Deferred < void > ) : void ;
224
-
225
- /**
226
- * Resolves or rejects the user callback for the given batch and then discards
227
- * it.
228
- */
229
- processUserCallback ( batchId : BatchId , error : Error | null ) : void ;
230
-
231
- removeAndCleanupTarget ( targetId : number , error : Error | null ) : void ;
232
-
233
- removeLimboTarget ( key : DocumentKey ) : void ;
234
-
235
- updateTrackedLimbos (
236
- targetId : TargetId ,
237
- limboChanges : LimboDocumentChange [ ]
238
- ) : void ;
239
-
240
214
trackLimboChange ( limboChange : AddedLimboDocument ) : void ;
241
215
242
- /**
243
- * Starts listens for documents in limbo that are enqueued for resolution,
244
- * subject to a maximum number of concurrent resolutions.
245
- *
246
- * Without bounding the number of concurrent resolutions, the server can fail
247
- * with "resource exhausted" errors which can lead to pathological client
248
- * behavior as seen in https://github.com/firebase/firebase-js-sdk/issues/2683.
249
- */
250
- pumpEnqueuedLimboResolutions ( ) : void ;
251
-
252
216
activeLimboDocumentResolutions ( ) : SortedMap < DocumentKey , TargetId > ;
253
217
254
218
enqueuedLimboDocumentResolutions ( ) : DocumentKey [ ] ;
255
219
256
- emitNewSnapsAndNotifyLocalStore (
257
- changes : MaybeDocumentMap ,
258
- remoteEvent ?: RemoteEvent
259
- ) : Promise < void > ;
260
-
261
- assertSubscribed ( fnName : string ) : void ;
262
-
263
220
handleCredentialChange ( user : User ) : Promise < void > ;
264
221
265
222
enableNetwork ( ) : Promise < void > ;
@@ -691,15 +648,20 @@ class SyncEngineImpl implements SyncEngine {
691
648
}
692
649
}
693
650
694
- triggerPendingWritesCallbacks ( batchId : BatchId ) : void {
651
+ /**
652
+ * Triggers the callbacks that are waiting for this batch id to get acknowledged by server,
653
+ * if there are any.
654
+ */
655
+ private triggerPendingWritesCallbacks ( batchId : BatchId ) : void {
695
656
( this . pendingWritesCallbacks . get ( batchId ) || [ ] ) . forEach ( callback => {
696
657
callback . resolve ( ) ;
697
658
} ) ;
698
659
699
660
this . pendingWritesCallbacks . delete ( batchId ) ;
700
661
}
701
662
702
- rejectOutstandingPendingWritesCallbacks ( errorMessage : string ) : void {
663
+ /** Reject all outstanding callbacks waiting for pending writes to complete. */
664
+ private rejectOutstandingPendingWritesCallbacks ( errorMessage : string ) : void {
703
665
this . pendingWritesCallbacks . forEach ( callbacks => {
704
666
callbacks . forEach ( callback => {
705
667
callback . reject ( new FirestoreError ( Code . CANCELLED , errorMessage ) ) ;
@@ -709,7 +671,10 @@ class SyncEngineImpl implements SyncEngine {
709
671
this . pendingWritesCallbacks . clear ( ) ;
710
672
}
711
673
712
- addMutationCallback ( batchId : BatchId , callback : Deferred < void > ) : void {
674
+ private addMutationCallback (
675
+ batchId : BatchId ,
676
+ callback : Deferred < void >
677
+ ) : void {
713
678
let newCallbacks = this . mutationUserCallbacks [ this . currentUser . toKey ( ) ] ;
714
679
if ( ! newCallbacks ) {
715
680
newCallbacks = new SortedMap < BatchId , Deferred < void > > (
@@ -720,7 +685,11 @@ class SyncEngineImpl implements SyncEngine {
720
685
this . mutationUserCallbacks [ this . currentUser . toKey ( ) ] = newCallbacks ;
721
686
}
722
687
723
- processUserCallback ( batchId : BatchId , error : Error | null ) : void {
688
+ /**
689
+ * Resolves or rejects the user callback for the given batch and then discards
690
+ * it.
691
+ */
692
+ protected processUserCallback ( batchId : BatchId , error : Error | null ) : void {
724
693
let newCallbacks = this . mutationUserCallbacks [ this . currentUser . toKey ( ) ] ;
725
694
726
695
// NOTE: Mutations restored from persistence won't have callbacks, so it's
@@ -743,7 +712,10 @@ class SyncEngineImpl implements SyncEngine {
743
712
}
744
713
}
745
714
746
- removeAndCleanupTarget ( targetId : number , error : Error | null = null ) : void {
715
+ protected removeAndCleanupTarget (
716
+ targetId : number ,
717
+ error : Error | null = null
718
+ ) : void {
747
719
this . sharedClientState . removeLocalQueryTarget ( targetId ) ;
748
720
749
721
debugAssert (
@@ -773,7 +745,7 @@ class SyncEngineImpl implements SyncEngine {
773
745
}
774
746
}
775
747
776
- removeLimboTarget ( key : DocumentKey ) : void {
748
+ private removeLimboTarget ( key : DocumentKey ) : void {
777
749
// It's possible that the target already got removed because the query failed. In that case,
778
750
// the key won't exist in `limboTargetsByKey`. Only do the cleanup if we still have the target.
779
751
const limboTargetId = this . activeLimboTargetsByKey . get ( key ) ;
@@ -788,7 +760,7 @@ class SyncEngineImpl implements SyncEngine {
788
760
this . pumpEnqueuedLimboResolutions ( ) ;
789
761
}
790
762
791
- updateTrackedLimbos (
763
+ protected updateTrackedLimbos (
792
764
targetId : TargetId ,
793
765
limboChanges : LimboDocumentChange [ ]
794
766
) : void {
@@ -812,7 +784,7 @@ class SyncEngineImpl implements SyncEngine {
812
784
}
813
785
}
814
786
815
- trackLimboChange ( limboChange : AddedLimboDocument ) : void {
787
+ private trackLimboChange ( limboChange : AddedLimboDocument ) : void {
816
788
const key = limboChange . key ;
817
789
if ( ! this . activeLimboTargetsByKey . get ( key ) ) {
818
790
logDebug ( LOG_TAG , 'New document in limbo: ' + key ) ;
@@ -821,7 +793,15 @@ class SyncEngineImpl implements SyncEngine {
821
793
}
822
794
}
823
795
824
- pumpEnqueuedLimboResolutions ( ) : void {
796
+ /**
797
+ * Starts listens for documents in limbo that are enqueued for resolution,
798
+ * subject to a maximum number of concurrent resolutions.
799
+ *
800
+ * Without bounding the number of concurrent resolutions, the server can fail
801
+ * with "resource exhausted" errors which can lead to pathological client
802
+ * behavior as seen in https://github.com/firebase/firebase-js-sdk/issues/2683.
803
+ */
804
+ private pumpEnqueuedLimboResolutions ( ) : void {
825
805
while (
826
806
this . enqueuedLimboResolutions . length > 0 &&
827
807
this . activeLimboTargetsByKey . size < this . maxConcurrentLimboResolutions
@@ -857,7 +837,7 @@ class SyncEngineImpl implements SyncEngine {
857
837
return this . enqueuedLimboResolutions ;
858
838
}
859
839
860
- async emitNewSnapsAndNotifyLocalStore (
840
+ protected async emitNewSnapsAndNotifyLocalStore (
861
841
changes : MaybeDocumentMap ,
862
842
remoteEvent ?: RemoteEvent
863
843
) : Promise < void > {
@@ -921,7 +901,7 @@ class SyncEngineImpl implements SyncEngine {
921
901
await this . localStore . notifyLocalViewChanges ( docChangesInAllViews ) ;
922
902
}
923
903
924
- assertSubscribed ( fnName : string ) : void {
904
+ protected assertSubscribed ( fnName : string ) : void {
925
905
debugAssert (
926
906
this . syncEngineListener !== null ,
927
907
'Trying to call ' + fnName + ' before calling subscribe().'
@@ -1006,41 +986,7 @@ export function newSyncEngine(
1006
986
export interface MultiTabSyncEngine
1007
987
extends SharedClientStateSyncer ,
1008
988
SyncEngine {
1009
- /**
1010
- * Reconcile the list of synced documents in an existing view with those
1011
- * from persistence.
1012
- */
1013
- synchronizeViewAndComputeSnapshot ( queryView : QueryView ) : Promise < ViewChange > ;
1014
-
1015
989
applyPrimaryState ( isPrimary : boolean ) : Promise < void > ;
1016
-
1017
- resetLimboDocuments ( ) : void ;
1018
-
1019
- /**
1020
- * Reconcile the query views of the provided query targets with the state from
1021
- * persistence. Raises snapshots for any changes that affect the local
1022
- * client and returns the updated state of all target's query data.
1023
- *
1024
- * @param targets the list of targets with views that need to be recomputed
1025
- * @param transitionToPrimary `true` iff the tab transitions from a secondary
1026
- * tab to a primary tab
1027
- */
1028
- synchronizeQueryViewsAndRaiseSnapshots (
1029
- targets : TargetId [ ] ,
1030
- transitionToPrimary : boolean
1031
- ) : Promise < TargetData [ ] > ;
1032
-
1033
- /**
1034
- * Creates a `Query` object from the specified `Target`. There is no way to
1035
- * obtain the original `Query`, so we synthesize a `Query` from the `Target`
1036
- * object.
1037
- *
1038
- * The synthesized result might be different from the original `Query`, but
1039
- * since the synthesized `Query` should return the same results as the
1040
- * original one (only the presentation of results might differ), the potential
1041
- * difference will not cause issues.
1042
- */
1043
- synthesizeTargetToQuery ( target : Target ) : Query ;
1044
990
}
1045
991
1046
992
/**
@@ -1090,7 +1036,11 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
1090
1036
return super . disableNetwork ( ) ;
1091
1037
}
1092
1038
1093
- async synchronizeViewAndComputeSnapshot (
1039
+ /**
1040
+ * Reconcile the list of synced documents in an existing view with those
1041
+ * from persistence.
1042
+ */
1043
+ private async synchronizeViewAndComputeSnapshot (
1094
1044
queryView : QueryView
1095
1045
) : Promise < ViewChange > {
1096
1046
const queryResult = await this . localStore . executeQuery (
@@ -1214,7 +1164,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
1214
1164
}
1215
1165
}
1216
1166
1217
- resetLimboDocuments ( ) : void {
1167
+ private resetLimboDocuments ( ) : void {
1218
1168
this . activeLimboResolutionsByTarget . forEach ( ( _ , targetId ) => {
1219
1169
this . remoteStore . unlisten ( targetId ) ;
1220
1170
} ) ;
@@ -1225,7 +1175,16 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
1225
1175
) ;
1226
1176
}
1227
1177
1228
- async synchronizeQueryViewsAndRaiseSnapshots (
1178
+ /**
1179
+ * Reconcile the query views of the provided query targets with the state from
1180
+ * persistence. Raises snapshots for any changes that affect the local
1181
+ * client and returns the updated state of all target's query data.
1182
+ *
1183
+ * @param targets the list of targets with views that need to be recomputed
1184
+ * @param transitionToPrimary `true` iff the tab transitions from a secondary
1185
+ * tab to a primary tab
1186
+ */
1187
+ private async synchronizeQueryViewsAndRaiseSnapshots (
1229
1188
targets : TargetId [ ] ,
1230
1189
transitionToPrimary : boolean
1231
1190
) : Promise < TargetData [ ] > {
@@ -1279,7 +1238,17 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
1279
1238
return activeQueries ;
1280
1239
}
1281
1240
1282
- synthesizeTargetToQuery ( target : Target ) : Query {
1241
+ /**
1242
+ * Creates a `Query` object from the specified `Target`. There is no way to
1243
+ * obtain the original `Query`, so we synthesize a `Query` from the `Target`
1244
+ * object.
1245
+ *
1246
+ * The synthesized result might be different from the original `Query`, but
1247
+ * since the synthesized `Query` should return the same results as the
1248
+ * original one (only the presentation of results might differ), the potential
1249
+ * difference will not cause issues.
1250
+ */
1251
+ private synthesizeTargetToQuery ( target : Target ) : Query {
1283
1252
return new Query (
1284
1253
target . path ,
1285
1254
target . collectionGroup ,
0 commit comments