Skip to content

Commit 2e9c758

Browse files
Cleanup
1 parent fad9e64 commit 2e9c758

File tree

11 files changed

+51
-46
lines changed

11 files changed

+51
-46
lines changed

packages/firestore/src/api/user_data_reader.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,9 @@ function parseScalarValue(
660660
return { stringValue: value };
661661
} else if (value instanceof Date) {
662662
const timestamp = Timestamp.fromDate(value);
663-
return { timestampValue: toTimestamp(context.serializer, timestamp) };
663+
return {
664+
timestampValue: toTimestamp(context.serializer, timestamp)
665+
};
664666
} else if (value instanceof Timestamp) {
665667
// Firestore backend truncates precision down to microseconds. To ensure
666668
// offline mode works the same with regards to truncation, perform the
@@ -669,7 +671,9 @@ function parseScalarValue(
669671
value.seconds,
670672
Math.floor(value.nanoseconds / 1000) * 1000
671673
);
672-
return { timestampValue: toTimestamp(context.serializer, timestamp) };
674+
return {
675+
timestampValue: toTimestamp(context.serializer, timestamp)
676+
};
673677
} else if (value instanceof GeoPoint) {
674678
return {
675679
geoPointValue: {
@@ -691,8 +695,8 @@ function parseScalarValue(
691695
}
692696
return {
693697
referenceValue: toResourceName(
694-
value._key.path,
695-
value._databaseId || context.serializer.databaseId
698+
value._databaseId || context.databaseId,
699+
value._key.path
696700
)
697701
};
698702
} else if (value === undefined && context.ignoreUndefinedProperties) {

packages/firestore/src/local/indexeddb_schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ export class DbMutationBatch {
483483
/**
484484
* A list of mutations to apply. All mutations will be applied atomically.
485485
*
486-
* Mutations are serialized via JsonProtoSerializer.toMutation().
486+
* Mutations are serialized via toMutation().
487487
*/
488488
public mutations: api.Write[]
489489
) {}

packages/firestore/src/platform_browser/browser_platform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class BrowserPlatform implements Platform {
5757
}
5858

5959
newSerializer(databaseId: DatabaseId): JsonProtoSerializer {
60-
return new JsonProtoSerializer(databaseId, { useProto3Json: true });
60+
return new JsonProtoSerializer(databaseId, /* useProto3Json= */ true);
6161
}
6262

6363
formatJSON(value: unknown): string {

packages/firestore/src/platform_node/node_platform.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ export class NodePlatform implements Platform {
5353
return new NoopConnectivityMonitor();
5454
}
5555

56-
newSerializer(partitionId: DatabaseId): JsonProtoSerializer {
57-
return new JsonProtoSerializer(partitionId, { useProto3Json: false });
56+
newSerializer(databaseId: DatabaseId): JsonProtoSerializer {
57+
return new JsonProtoSerializer(databaseId, /* useProto3Json= */ false);
5858
}
5959

6060
formatJSON(value: unknown): string {

packages/firestore/src/remote/serializer.ts

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -103,27 +103,24 @@ function assertPresent(value: unknown, description: string): asserts value {
103103
debugAssert(!isNullOrUndefined(value), description + ' is missing');
104104
}
105105

106-
export interface SerializerOptions {
107-
/**
108-
* The serializer supports both Protobuf.js and Proto3 JSON formats. By
109-
* setting serializer.flag to true, the serializer will use the Proto3 JSON format.
110-
*
111-
* For a description of the Proto3 JSON format check
112-
* https://developers.google.com/protocol-buffers/docs/proto3#json
113-
*/
114-
useProto3Json: boolean;
115-
}
116-
117106
/**
118-
* Generates JsonObject values for the Datastore API suitable for sending to
119-
* either GRPC stub methods or via the JSON/HTTP REST API.
107+
* This class generates JsonObject values for the Datastore API suitable for
108+
* sending to either GRPC stub methods or via the JSON/HTTP REST API.
109+
*
110+
* The serializer supports both Protobuf.js and Proto3 JSON formats. By
111+
* setting `useProto3Json` to true, the serializer will use the Proto3 JSON
112+
* format.
113+
*
114+
* For a description of the Proto3 JSON format check
115+
* https://developers.google.com/protocol-buffers/docs/proto3#json
116+
*
120117
* TODO(klimt): We can remove the databaseId argument if we keep the full
121118
* resource name in documents.
122119
*/
123120
export class JsonProtoSerializer {
124121
constructor(
125122
readonly databaseId: DatabaseId,
126-
readonly options: SerializerOptions
123+
readonly useProto3Json: boolean
127124
) {}
128125
}
129126

@@ -145,7 +142,7 @@ function toInt32Proto(
145142
serializer: JsonProtoSerializer,
146143
val: number | null
147144
): number | { value: number } | null {
148-
if (serializer.options.useProto3Json || isNullOrUndefined(val)) {
145+
if (serializer.useProto3Json || isNullOrUndefined(val)) {
149146
return val;
150147
} else {
151148
return { value: val };
@@ -183,7 +180,7 @@ export function toDouble(
183180
serializer: JsonProtoSerializer,
184181
value: number
185182
): api.Value {
186-
if (serializer.options.useProto3Json) {
183+
if (serializer.useProto3Json) {
187184
if (isNaN(value)) {
188185
return { doubleValue: 'NaN' };
189186
} else if (value === Infinity) {
@@ -214,7 +211,7 @@ export function toTimestamp(
214211
serializer: JsonProtoSerializer,
215212
timestamp: Timestamp
216213
): api.Timestamp {
217-
if (serializer.options.useProto3Json) {
214+
if (serializer.useProto3Json) {
218215
// Serialize to ISO-8601 date format, but with full nano resolution.
219216
// Since JS Date has only millis, let's only use it for the seconds and
220217
// then manually add the fractions to the end.
@@ -248,7 +245,7 @@ export function toBytes(
248245
serializer: JsonProtoSerializer,
249246
bytes: Blob | ByteString
250247
): string | Uint8Array {
251-
if (serializer.options.useProto3Json) {
248+
if (serializer.useProto3Json) {
252249
return bytes.toBase64();
253250
} else {
254251
return bytes.toUint8Array();
@@ -262,7 +259,7 @@ export function fromBytes(
262259
serializer: JsonProtoSerializer,
263260
value: string | Uint8Array | undefined
264261
): ByteString {
265-
if (serializer.options.useProto3Json) {
262+
if (serializer.useProto3Json) {
266263
hardAssert(
267264
value === undefined || typeof value === 'string',
268265
'value must be undefined or a string when using proto3 Json'
@@ -290,8 +287,8 @@ export function fromVersion(version: api.Timestamp): SnapshotVersion {
290287
}
291288

292289
export function toResourceName(
293-
path: ResourcePath,
294-
databaseId: DatabaseId
290+
databaseId: DatabaseId,
291+
path: ResourcePath
295292
): string {
296293
return fullyQualifiedPrefixPath(databaseId)
297294
.child('documents')
@@ -312,7 +309,7 @@ export function toName(
312309
serializer: JsonProtoSerializer,
313310
key: DocumentKey
314311
): string {
315-
return toResourceName(key.path, serializer.databaseId);
312+
return toResourceName(serializer.databaseId, key.path);
316313
}
317314

318315
export function fromName(
@@ -342,7 +339,7 @@ function toQueryPath(
342339
serializer: JsonProtoSerializer,
343340
path: ResourcePath
344341
): string {
345-
return toResourceName(path, serializer.databaseId);
342+
return toResourceName(serializer.databaseId, path);
346343
}
347344

348345
function fromQueryPath(name: string): ResourcePath {
@@ -711,7 +708,7 @@ function fromWriteResult(
711708
// deletes of non-existing documents (rather than null). This breaks the
712709
// test "get deleted doc while offline with source=cache" as NoDocuments
713710
// with version 0 are filtered by IndexedDb's RemoteDocumentCache.
714-
// TODO(#2149): Remove serializer.when Emulator is fixed
711+
// TODO(#2149): Remove this when Emulator is fixed
715712
version = fromVersion(commitTime);
716713
}
717714

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ async function withUnstartedCustomPersistence(
122122
queue: AsyncQueue
123123
) => Promise<void>
124124
): Promise<void> {
125-
const serializer = new JsonProtoSerializer(TEST_DATABASE_ID, {
126-
useProto3Json: true
127-
});
125+
const serializer = new JsonProtoSerializer(
126+
TEST_DATABASE_ID,
127+
/* useProto3Json= */ true
128+
);
128129

129130
const queue = new AsyncQueue();
130131
const platform = new TestPlatform(

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ export const INDEXEDDB_TEST_DATABASE_NAME =
8686
IndexedDbPersistence.buildStoragePrefix(TEST_DATABASE_INFO) +
8787
IndexedDbPersistence.MAIN_DATABASE;
8888

89-
const JSON_SERIALIZER = new JsonProtoSerializer(TEST_DATABASE_ID, {
90-
useProto3Json: true
91-
});
89+
const JSON_SERIALIZER = new JsonProtoSerializer(
90+
TEST_DATABASE_ID,
91+
/* useProto3Json= */ true
92+
);
9293

9394
/**
9495
* IndexedDb serializer that uses `TEST_DATABASE_ID` as its database

packages/firestore/test/unit/remote/serializer.helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export function serializerTest(
124124
): void {
125125
describe('Serializer', () => {
126126
const partition = new DatabaseId('p', 'd');
127-
const s = new JsonProtoSerializer(partition, { useProto3Json: false });
127+
const s = new JsonProtoSerializer(partition, /* useProto3Json= */ false);
128128

129129
/**
130130
* Wraps the given target in TargetData. This is useful because the APIs we're

packages/firestore/test/unit/specs/spec_test_runner.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,10 @@ abstract class TestRunner {
210210
this.queue = new AsyncQueue();
211211
this.queue.skipDelaysForTimerId(TimerId.ListenStreamConnectionBackoff);
212212

213-
this.serializer = new JsonProtoSerializer(this.databaseInfo.databaseId, {
214-
useProto3Json: true
215-
});
213+
this.serializer = new JsonProtoSerializer(
214+
this.databaseInfo.databaseId,
215+
/* useProto3Json= */ true
216+
);
216217

217218
this.useGarbageCollection = config.useGarbageCollection;
218219
this.numClients = config.numClients;

packages/firestore/test/util/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export function testUserDataReader(useProto3Json?: boolean): UserDataReader {
112112
databaseId,
113113
/* ignoreUndefinedProperties= */ false,
114114
useProto3Json !== undefined
115-
? new JsonProtoSerializer(databaseId, { useProto3Json })
115+
? new JsonProtoSerializer(databaseId, useProto3Json)
116116
: undefined
117117
);
118118
}

packages/firestore/test/util/spec_test_helpers.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ import {
3434
} from '../../src/remote/serializer';
3535
import { TEST_DATABASE_ID } from '../unit/local/persistence_test_helpers';
3636

37-
const serializer = new JsonProtoSerializer(TEST_DATABASE_ID, {
38-
useProto3Json: true
39-
});
37+
const serializer = new JsonProtoSerializer(
38+
TEST_DATABASE_ID,
39+
/* useProto3Json= */ true
40+
);
4041

4142
export function encodeWatchChange(
4243
watchChange: WatchChange

0 commit comments

Comments
 (0)