Skip to content

Commit 618e60a

Browse files
committed
Leave private methods out.
1 parent cd85d1a commit 618e60a

File tree

1 file changed

+61
-94
lines changed

1 file changed

+61
-94
lines changed

packages/firestore/src/core/sync_engine.ts

+61-94
Original file line numberDiff line numberDiff line change
@@ -211,55 +211,10 @@ export interface SyncEngine extends RemoteSyncer {
211211
*/
212212
registerPendingWritesCallback(callback: Deferred<void>): Promise<void>;
213213

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-
252214
activeLimboDocumentResolutions(): SortedMap<DocumentKey, TargetId>;
253215

254216
enqueuedLimboDocumentResolutions(): DocumentKey[];
255217

256-
emitNewSnapsAndNotifyLocalStore(
257-
changes: MaybeDocumentMap,
258-
remoteEvent?: RemoteEvent
259-
): Promise<void>;
260-
261-
assertSubscribed(fnName: string): void;
262-
263218
handleCredentialChange(user: User): Promise<void>;
264219

265220
enableNetwork(): Promise<void>;
@@ -691,15 +646,20 @@ class SyncEngineImpl implements SyncEngine {
691646
}
692647
}
693648

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 {
695654
(this.pendingWritesCallbacks.get(batchId) || []).forEach(callback => {
696655
callback.resolve();
697656
});
698657

699658
this.pendingWritesCallbacks.delete(batchId);
700659
}
701660

702-
rejectOutstandingPendingWritesCallbacks(errorMessage: string): void {
661+
/** Reject all outstanding callbacks waiting for pending writes to complete. */
662+
private rejectOutstandingPendingWritesCallbacks(errorMessage: string): void {
703663
this.pendingWritesCallbacks.forEach(callbacks => {
704664
callbacks.forEach(callback => {
705665
callback.reject(new FirestoreError(Code.CANCELLED, errorMessage));
@@ -709,7 +669,10 @@ class SyncEngineImpl implements SyncEngine {
709669
this.pendingWritesCallbacks.clear();
710670
}
711671

712-
addMutationCallback(batchId: BatchId, callback: Deferred<void>): void {
672+
private addMutationCallback(
673+
batchId: BatchId,
674+
callback: Deferred<void>
675+
): void {
713676
let newCallbacks = this.mutationUserCallbacks[this.currentUser.toKey()];
714677
if (!newCallbacks) {
715678
newCallbacks = new SortedMap<BatchId, Deferred<void>>(
@@ -720,7 +683,11 @@ class SyncEngineImpl implements SyncEngine {
720683
this.mutationUserCallbacks[this.currentUser.toKey()] = newCallbacks;
721684
}
722685

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 {
724691
let newCallbacks = this.mutationUserCallbacks[this.currentUser.toKey()];
725692

726693
// NOTE: Mutations restored from persistence won't have callbacks, so it's
@@ -743,7 +710,10 @@ class SyncEngineImpl implements SyncEngine {
743710
}
744711
}
745712

746-
removeAndCleanupTarget(targetId: number, error: Error | null = null): void {
713+
protected removeAndCleanupTarget(
714+
targetId: number,
715+
error: Error | null = null
716+
): void {
747717
this.sharedClientState.removeLocalQueryTarget(targetId);
748718

749719
debugAssert(
@@ -773,7 +743,7 @@ class SyncEngineImpl implements SyncEngine {
773743
}
774744
}
775745

776-
removeLimboTarget(key: DocumentKey): void {
746+
private removeLimboTarget(key: DocumentKey): void {
777747
// It's possible that the target already got removed because the query failed. In that case,
778748
// the key won't exist in `limboTargetsByKey`. Only do the cleanup if we still have the target.
779749
const limboTargetId = this.activeLimboTargetsByKey.get(key);
@@ -788,7 +758,7 @@ class SyncEngineImpl implements SyncEngine {
788758
this.pumpEnqueuedLimboResolutions();
789759
}
790760

791-
updateTrackedLimbos(
761+
protected updateTrackedLimbos(
792762
targetId: TargetId,
793763
limboChanges: LimboDocumentChange[]
794764
): void {
@@ -812,7 +782,7 @@ class SyncEngineImpl implements SyncEngine {
812782
}
813783
}
814784

815-
trackLimboChange(limboChange: AddedLimboDocument): void {
785+
private trackLimboChange(limboChange: AddedLimboDocument): void {
816786
const key = limboChange.key;
817787
if (!this.activeLimboTargetsByKey.get(key)) {
818788
logDebug(LOG_TAG, 'New document in limbo: ' + key);
@@ -821,7 +791,15 @@ class SyncEngineImpl implements SyncEngine {
821791
}
822792
}
823793

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 {
825803
while (
826804
this.enqueuedLimboResolutions.length > 0 &&
827805
this.activeLimboTargetsByKey.size < this.maxConcurrentLimboResolutions
@@ -857,7 +835,7 @@ class SyncEngineImpl implements SyncEngine {
857835
return this.enqueuedLimboResolutions;
858836
}
859837

860-
async emitNewSnapsAndNotifyLocalStore(
838+
protected async emitNewSnapsAndNotifyLocalStore(
861839
changes: MaybeDocumentMap,
862840
remoteEvent?: RemoteEvent
863841
): Promise<void> {
@@ -921,7 +899,7 @@ class SyncEngineImpl implements SyncEngine {
921899
await this.localStore.notifyLocalViewChanges(docChangesInAllViews);
922900
}
923901

924-
assertSubscribed(fnName: string): void {
902+
protected assertSubscribed(fnName: string): void {
925903
debugAssert(
926904
this.syncEngineListener !== null,
927905
'Trying to call ' + fnName + ' before calling subscribe().'
@@ -1006,41 +984,7 @@ export function newSyncEngine(
1006984
export interface MultiTabSyncEngine
1007985
extends SharedClientStateSyncer,
1008986
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-
1015987
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;
1044988
}
1045989

1046990
/**
@@ -1090,7 +1034,11 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
10901034
return super.disableNetwork();
10911035
}
10921036

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(
10941042
queryView: QueryView
10951043
): Promise<ViewChange> {
10961044
const queryResult = await this.localStore.executeQuery(
@@ -1214,7 +1162,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
12141162
}
12151163
}
12161164

1217-
resetLimboDocuments(): void {
1165+
private resetLimboDocuments(): void {
12181166
this.activeLimboResolutionsByTarget.forEach((_, targetId) => {
12191167
this.remoteStore.unlisten(targetId);
12201168
});
@@ -1225,7 +1173,16 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
12251173
);
12261174
}
12271175

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(
12291186
targets: TargetId[],
12301187
transitionToPrimary: boolean
12311188
): Promise<TargetData[]> {
@@ -1279,7 +1236,17 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
12791236
return activeQueries;
12801237
}
12811238

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 {
12831250
return new Query(
12841251
target.path,
12851252
target.collectionGroup,

0 commit comments

Comments
 (0)