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