Skip to content

Commit a1b291b

Browse files
author
Brian Chen
committed
Remove unused baseDoc arg and iterate fowards in local serializer
1 parent b574873 commit a1b291b

13 files changed

+74
-117
lines changed

common/api-review/app-exp.api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
```ts
66

77
import { Component } from '@firebase/component';
8-
import { FirebaseApp } from '@firebase/app-types';
9-
import { FirebaseAppConfig } from '@firebase/app-types';
10-
import { FirebaseOptions } from '@firebase/app-types';
8+
import { FirebaseApp } from '@firebase/app-types-exp';
9+
import { FirebaseAppConfig } from '@firebase/app-types-exp';
10+
import { FirebaseOptions } from '@firebase/app-types-exp';
1111
import { LogCallback } from '@firebase/logger';
1212
import { LogLevelString } from '@firebase/logger';
1313
import { LogOptions } from '@firebase/logger';

common/api-review/firestore-lite.api.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ export class FirebaseFirestore implements FirestoreService {
201201
protected _terminate(): Promise<void>;
202202
// (undocumented)
203203
get _terminated(): boolean;
204-
}
204+
// (undocumented)
205+
toJSON(): object;
206+
}
205207

206208
// @public
207209
export interface FirestoreDataConverter<T> {

common/api-review/installations-exp.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { FirebaseInstallations } from '@firebase/installations-types-exp';
1010
// @public
1111
export function deleteInstallations(installations: FirebaseInstallations): Promise<void>;
1212

13+
export { FirebaseInstallations }
14+
1315
// @public
1416
export function getId(installations: FirebaseInstallations): Promise<string>;
1517

common/api-review/messaging-exp.api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { Unsubscribe } from '@firebase/util';
1414
// @public
1515
export function deleteToken(messaging: FirebaseMessaging): Promise<boolean>;
1616

17+
export { FirebaseMessaging }
18+
1719
// @public
1820
export function getMessaging(app: FirebaseApp): FirebaseMessaging;
1921

@@ -23,6 +25,8 @@ export function getToken(messaging: FirebaseMessaging, options?: {
2325
swReg?: ServiceWorkerRegistration;
2426
}): Promise<string>;
2527

28+
export { MessagePayload }
29+
2630
// @public
2731
export function onMessage(messaging: FirebaseMessaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;
2832

common/api-review/performance-exp.api.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ import { FirebasePerformance } from '@firebase/performance-types-exp';
99
import { PerformanceSettings } from '@firebase/performance-types-exp';
1010
import { PerformanceTrace } from '@firebase/performance-types-exp';
1111

12+
export { FirebasePerformance }
13+
1214
// @public
1315
export function getPerformance(app: FirebaseApp, settings?: PerformanceSettings): FirebasePerformance;
1416

17+
export { PerformanceSettings }
18+
19+
export { PerformanceTrace }
20+
1521
// @public
1622
export function trace(performance: FirebasePerformance, name: string): PerformanceTrace;
1723

common/api-review/remote-config-exp.api.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
```ts
66

77
import { FirebaseApp } from '@firebase/app-types-exp';
8-
import { LogLevel } from '@firebase/remote-config-types-exp';
98
import { RemoteConfig } from '@firebase/remote-config-types-exp';
10-
import { Value } from '@firebase/remote-config-types-exp';
9+
import { LogLevel as RemoteConfigLogLevel } from '@firebase/remote-config-types-exp';
10+
import { Value as ValueType } from '@firebase/remote-config-types-exp';
1111

1212
// @public
1313
export function activate(remoteConfig: RemoteConfig): Promise<boolean>;
@@ -22,7 +22,7 @@ export function fetchAndActivate(remoteConfig: RemoteConfig): Promise<boolean>;
2222
export function fetchConfig(remoteConfig: RemoteConfig): Promise<void>;
2323

2424
// @public
25-
export function getAll(remoteConfig: RemoteConfig): Record<string, Value>;
25+
export function getAll(remoteConfig: RemoteConfig): Record<string, ValueType>;
2626

2727
// @public
2828
export function getBoolean(remoteConfig: RemoteConfig, key: string): boolean;
@@ -37,10 +37,16 @@ export function getRemoteConfig(app: FirebaseApp): RemoteConfig;
3737
export function getString(remoteConfig: RemoteConfig, key: string): string;
3838

3939
// @public
40-
export function getValue(remoteConfig: RemoteConfig, key: string): Value;
40+
export function getValue(remoteConfig: RemoteConfig, key: string): ValueType;
41+
42+
export { RemoteConfig }
43+
44+
export { RemoteConfigLogLevel }
4145

4246
// @public
43-
export function setLogLevel(remoteConfig: RemoteConfig, logLevel: LogLevel): void;
47+
export function setLogLevel(remoteConfig: RemoteConfig, logLevel: RemoteConfigLogLevel): void;
48+
49+
export { ValueType }
4450

4551

4652
// (No @packageDocumentation comment for this package)

packages/firestore/src/local/local_documents_view.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ export class LocalDocumentsView {
268268
const mutatedDoc = applyMutationToLocalView(
269269
mutation,
270270
baseDoc,
271-
baseDoc,
272271
batch.localWriteTime
273272
);
274273
if (mutatedDoc instanceof Document) {

packages/firestore/src/local/local_serializer.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,19 +201,21 @@ export function fromDbMutationBatch(
201201
// on the SDK means that old `transform` mutations stored in IndexedDB need
202202
// to be updated to `update_transforms`.
203203
// TODO(b/174608374): Remove this code once we perform a schema migration.
204-
for (let i = dbBatch.mutations.length - 1; i >= 0; --i) {
205-
const mutationProto = dbBatch.mutations[i];
206-
if (mutationProto?.transform !== undefined) {
204+
for (let i = 0; i < dbBatch.mutations.length - 1; ++i) {
205+
const currentMutation = dbBatch.mutations[i];
206+
const hasTransform =
207+
i + 1 < dbBatch.mutations.length &&
208+
dbBatch.mutations[i + 1].transform !== undefined;
209+
if (hasTransform) {
207210
debugAssert(
208-
i >= 1 &&
209-
dbBatch.mutations[i - 1].transform === undefined &&
210-
dbBatch.mutations[i - 1].update !== undefined,
211+
dbBatch.mutations[i].transform === undefined &&
212+
dbBatch.mutations[i].update !== undefined,
211213
'TransformMutation should be preceded by a patch or set mutation'
212214
);
213-
const mutationToJoin = dbBatch.mutations[i - 1];
214-
mutationToJoin.updateTransforms = mutationProto.transform.fieldTransforms;
215-
dbBatch.mutations.splice(i, 1);
216-
--i;
215+
const transformMutation = dbBatch.mutations[i + 1];
216+
currentMutation.updateTransforms = transformMutation.transform!.fieldTransforms;
217+
dbBatch.mutations.splice(i + 1, 1);
218+
++i;
217219
}
218220
}
219221

packages/firestore/src/model/mutation.ts

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,6 @@ export function applyMutationToRemoteDocument(
270270
* @param mutation - The mutation to apply.
271271
* @param maybeDoc - The document to mutate. The input document can be null if
272272
* the client has no knowledge of the pre-mutation state of the document.
273-
* @param baseDoc - The state of the document prior to this mutation batch. The
274-
* input document can be null if the client has no knowledge of the
275-
* pre-mutation state of the document.
276273
* @param localWriteTime - A timestamp indicating the local write time of the
277274
* batch this mutation is a part of.
278275
* @returns The mutated document. The returned document may be null, but only
@@ -281,25 +278,14 @@ export function applyMutationToRemoteDocument(
281278
export function applyMutationToLocalView(
282279
mutation: Mutation,
283280
maybeDoc: MaybeDocument | null,
284-
baseDoc: MaybeDocument | null,
285281
localWriteTime: Timestamp
286282
): MaybeDocument | null {
287283
verifyMutationKeyMatches(mutation, maybeDoc);
288284

289285
if (mutation instanceof SetMutation) {
290-
return applySetMutationToLocalView(
291-
mutation,
292-
maybeDoc,
293-
localWriteTime,
294-
baseDoc
295-
);
286+
return applySetMutationToLocalView(mutation, maybeDoc, localWriteTime);
296287
} else if (mutation instanceof PatchMutation) {
297-
return applyPatchMutationToLocalView(
298-
mutation,
299-
maybeDoc,
300-
localWriteTime,
301-
baseDoc
302-
);
288+
return applyPatchMutationToLocalView(mutation, maybeDoc, localWriteTime);
303289
} else {
304290
debugAssert(
305291
mutation instanceof DeleteMutation,
@@ -469,8 +455,7 @@ function applySetMutationToRemoteDocument(
469455
function applySetMutationToLocalView(
470456
mutation: SetMutation,
471457
maybeDoc: MaybeDocument | null,
472-
localWriteTime: Timestamp,
473-
baseDoc: MaybeDocument | null
458+
localWriteTime: Timestamp
474459
): MaybeDocument | null {
475460
if (!preconditionIsValidForDocument(mutation.precondition, maybeDoc)) {
476461
return maybeDoc;
@@ -480,8 +465,7 @@ function applySetMutationToLocalView(
480465
const transformResults = localTransformResults(
481466
mutation.fieldTransforms,
482467
localWriteTime,
483-
maybeDoc,
484-
baseDoc
468+
maybeDoc
485469
);
486470
newData = transformObject(
487471
mutation.fieldTransforms,
@@ -551,8 +535,7 @@ function applyPatchMutationToRemoteDocument(
551535
function applyPatchMutationToLocalView(
552536
mutation: PatchMutation,
553537
maybeDoc: MaybeDocument | null,
554-
localWriteTime: Timestamp,
555-
baseDoc: MaybeDocument | null
538+
localWriteTime: Timestamp
556539
): MaybeDocument | null {
557540
if (!preconditionIsValidForDocument(mutation.precondition, maybeDoc)) {
558541
return maybeDoc;
@@ -562,8 +545,7 @@ function applyPatchMutationToLocalView(
562545
const transformResults = localTransformResults(
563546
mutation.fieldTransforms,
564547
localWriteTime,
565-
maybeDoc,
566-
baseDoc
548+
maybeDoc
567549
);
568550
const newData = patchDocument(mutation, maybeDoc, transformResults);
569551
return new Document(mutation.key, version, newData, {
@@ -613,13 +595,14 @@ function patchObject(mutation: PatchMutation, data: ObjectValue): ObjectValue {
613595
* containing transforms has been acknowledged by the server.
614596
*
615597
* @param fieldTransforms - The field transforms to apply the result to.
616-
* @param baseDoc - The document prior to applying this mutation batch.
598+
* @param maybeDoc - The current state of the document after applying all
599+
* previous mutations.
617600
* @param serverTransformResults - The transform results received by the server.
618601
* @returns The transform results list.
619602
*/
620603
function serverTransformResults(
621604
fieldTransforms: FieldTransform[],
622-
baseDoc: MaybeDocument | null,
605+
maybeDoc: MaybeDocument | null,
623606
serverTransformResults: Array<ProtoValue | null>
624607
): ProtoValue[] {
625608
const transformResults: ProtoValue[] = [];
@@ -633,8 +616,8 @@ function serverTransformResults(
633616
const fieldTransform = fieldTransforms[i];
634617
const transform = fieldTransform.transform;
635618
let previousValue: ProtoValue | null = null;
636-
if (baseDoc instanceof Document) {
637-
previousValue = baseDoc.field(fieldTransform.field);
619+
if (maybeDoc instanceof Document) {
620+
previousValue = maybeDoc.field(fieldTransform.field);
638621
}
639622
transformResults.push(
640623
applyTransformOperationToRemoteDocument(
@@ -657,14 +640,12 @@ function serverTransformResults(
657640
* generate ServerTimestampValues).
658641
* @param maybeDoc - The current state of the document after applying all
659642
* previous mutations.
660-
* @param baseDoc - The document prior to applying this mutation batch.
661643
* @returns The transform results list.
662644
*/
663645
function localTransformResults(
664646
fieldTransforms: FieldTransform[],
665647
localWriteTime: Timestamp,
666-
maybeDoc: MaybeDocument | null,
667-
baseDoc: MaybeDocument | null
648+
maybeDoc: MaybeDocument | null
668649
): ProtoValue[] {
669650
const transformResults: ProtoValue[] = [];
670651
for (const fieldTransform of fieldTransforms) {

packages/firestore/src/model/mutation_batch.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,17 @@ export class MutationBatch {
132132
maybeDoc = applyMutationToLocalView(
133133
mutation,
134134
maybeDoc,
135-
maybeDoc,
136135
this.localWriteTime
137136
);
138137
}
139138
}
140139

141-
const baseDoc = maybeDoc;
142-
143140
// Second, apply all user-provided mutations.
144141
for (const mutation of this.mutations) {
145142
if (mutation.key.isEqual(docKey)) {
146143
maybeDoc = applyMutationToLocalView(
147144
mutation,
148145
maybeDoc,
149-
baseDoc,
150146
this.localWriteTime
151147
);
152148
}

packages/firestore/test/unit/local/local_serializer.test.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,6 @@ describe('Local Serializer', () => {
129129
);
130130
});
131131

132-
it('TransformMutation (legacy) on its own throws assertion', () => {
133-
const dbMutationBatch = new DbMutationBatch(
134-
userId,
135-
batchId,
136-
1000,
137-
[],
138-
[transformMutationWrite]
139-
);
140-
expect(() =>
141-
fromDbMutationBatch(localSerializer, dbMutationBatch)
142-
).to.throw(
143-
'TransformMutation should be preceded by a patch or set mutation'
144-
);
145-
});
146-
147132
it('DeleteMutation + TransformMutation (legacy) on its own throws assertion', () => {
148133
const dbMutationBatch = new DbMutationBatch(
149134
userId,

0 commit comments

Comments
 (0)