Skip to content

Commit 8359b95

Browse files
committed
converter feedback
1 parent 96a49f7 commit 8359b95

File tree

4 files changed

+10
-32
lines changed

4 files changed

+10
-32
lines changed

packages/firestore/src/api/reference_impl.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,10 +1005,7 @@ export function onSnapshotResume<
10051005
let curArg = 0;
10061006
let options: SnapshotListenOptions | undefined = undefined;
10071007
if (typeof args[curArg] === 'object' && !isPartialObserver(args[curArg])) {
1008-
console.error('DEDB arg 0 is SnapsotLsitenOptions');
10091008
options = args[curArg++] as SnapshotListenOptions;
1010-
} else {
1011-
console.error('DEDB arg 0 is NOT SnapsotLsitenOptions');
10121009
}
10131010

10141011
if (json.bundleSource === 'QuerySnapshot') {

packages/firestore/src/api/snapshot.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ export function documentSnapshotFromJSON<
608608
>(
609609
db: Firestore,
610610
json: object,
611-
...args: unknown[]
611+
converter?: FirestoreDataConverter<AppModelType, DbModelType>
612612
): DocumentSnapshot<AppModelType, DbModelType> {
613613
if (validateJSON(json, DocumentSnapshot._jsonSchema)) {
614614
// Parse the bundle data.
@@ -638,12 +638,6 @@ export function documentSnapshotFromJSON<
638638
ResourcePath.fromString(json.bundleName)
639639
);
640640

641-
let converter: FirestoreDataConverter<AppModelType, DbModelType> | null =
642-
null;
643-
if (args[0]) {
644-
converter = args[0] as FirestoreDataConverter<AppModelType, DbModelType>;
645-
}
646-
647641
// Return the external facing DocumentSnapshot.
648642
return new DocumentSnapshot(
649643
db,
@@ -654,7 +648,7 @@ export function documentSnapshotFromJSON<
654648
/* hasPendingWrites= */ false,
655649
/* fromCache= */ false
656650
),
657-
converter
651+
converter ? converter : null
658652
);
659653
}
660654
throw new FirestoreError(
@@ -918,7 +912,7 @@ export function querySnapshotFromJSON<
918912
>(
919913
db: Firestore,
920914
json: object,
921-
...args: unknown[]
915+
converter?: FirestoreDataConverter<AppModelType, DbModelType>
922916
): QuerySnapshot<AppModelType, DbModelType> {
923917
if (validateJSON(json, QuerySnapshot._jsonSchema)) {
924918
// Parse the bundle data.
@@ -959,16 +953,10 @@ export function querySnapshotFromJSON<
959953
/* hasCachedResults= */ false
960954
);
961955

962-
let converter: FirestoreDataConverter<AppModelType, DbModelType> | null =
963-
null;
964-
if (args[0]) {
965-
converter = args[0] as FirestoreDataConverter<AppModelType, DbModelType>;
966-
}
967-
968956
// Create an external Query object, required to construct the QuerySnapshot.
969957
const externalQuery = new Query<AppModelType, DbModelType>(
970958
db,
971-
converter,
959+
converter ? converter : null,
972960
query
973961
);
974962

packages/firestore/src/lite-api/reference.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -334,22 +334,12 @@ export class DocumentReference<
334334
>(
335335
firestore: Firestore,
336336
json: object,
337-
...args: unknown[]
337+
converter?: FirestoreDataConverter<NewAppModelType, NewDbModelType>
338338
): DocumentReference<NewAppModelType, NewDbModelType> {
339339
if (validateJSON(json, DocumentReference._jsonSchema)) {
340-
let converter: FirestoreDataConverter<
341-
NewAppModelType,
342-
NewDbModelType
343-
> | null = null;
344-
if (args[0]) {
345-
converter = args[0] as FirestoreDataConverter<
346-
NewAppModelType,
347-
NewDbModelType
348-
>;
349-
}
350340
return new DocumentReference<NewAppModelType, NewDbModelType>(
351341
firestore,
352-
converter,
342+
converter ? converter : null,
353343
new DocumentKey(ResourcePath.fromString(json.referencePath))
354344
);
355345
}

packages/firestore/src/util/bundle_reader_sync_impl.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import { BundleMetadata } from '../protos/firestore_bundle_proto';
1919
import { JsonProtoSerializer } from '../remote/serializer';
20+
import { Code, FirestoreError } from '../util/error'
2021

2122
import { BundleReaderSync, SizedBundleElement } from './bundle_reader';
2223

@@ -84,7 +85,9 @@ export class BundleReaderSyncImpl implements BundleReaderSync {
8485
*/
8586
private readJsonString(length: number): string {
8687
if (this.cursor + length > this.bundleData.length) {
87-
throw new Error('Reached the end of bundle when more is expected.');
88+
throw new FirestoreError(
89+
Code.INTERNAL,
90+
'Reached the end of bundle when more is expected.');
8891
}
8992
const result = this.bundleData.slice(this.cursor, (this.cursor += length));
9093
return result;

0 commit comments

Comments
 (0)