Skip to content

Commit 5bf5767

Browse files
committed
remove fromJSONUsingConverter, user override.
1 parent 78626ef commit 5bf5767

File tree

4 files changed

+36
-42
lines changed

4 files changed

+36
-42
lines changed

common/api-review/firestore.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class DocumentSnapshot<AppModelType = DocumentData, DbModelType extends D
179179
data(options?: SnapshotOptions): AppModelType | undefined;
180180
exists(): this is QueryDocumentSnapshot<AppModelType, DbModelType>;
181181
static fromJSON(db: Firestore, json: object): DocumentSnapshot;
182-
static fromJSONUsingConverter<AppModelType, DbModelType extends DocumentData = DocumentData>(db: Firestore, json: object, converter: FirestoreDataConverter<AppModelType, DbModelType>): DocumentSnapshot<AppModelType, DbModelType>;
182+
static fromJSON<AppModelType, DbModelType extends DocumentData = DocumentData>(db: Firestore, json: object, converter: FirestoreDataConverter<AppModelType, DbModelType>): DocumentSnapshot<AppModelType, DbModelType>;
183183
get(fieldPath: string | FieldPath, options?: SnapshotOptions): any;
184184
get id(): string;
185185
readonly metadata: SnapshotMetadata;
@@ -657,7 +657,7 @@ export class QuerySnapshot<AppModelType = DocumentData, DbModelType extends Docu
657657
get empty(): boolean;
658658
forEach(callback: (result: QueryDocumentSnapshot<AppModelType, DbModelType>) => void, thisArg?: unknown): void;
659659
static fromJSON(db: Firestore, json: object): QuerySnapshot;
660-
static fromJSONUsingConverter<AppModelType, DbModelType extends DocumentData = DocumentData>(db: Firestore, json: object, converter: FirestoreDataConverter<AppModelType, DbModelType>): QuerySnapshot<AppModelType, DbModelType>;
660+
static fromJSON<AppModelType, DbModelType extends DocumentData = DocumentData>(db: Firestore, json: object, converter: FirestoreDataConverter<AppModelType, DbModelType>): QuerySnapshot<AppModelType, DbModelType>;
661661
readonly metadata: SnapshotMetadata;
662662
readonly query: Query<AppModelType, DbModelType>;
663663
get size(): number;

docs-devsite/firestore_.documentsnapshot.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export declare class DocumentSnapshot<AppModelType = DocumentData, DbModelType e
4141
| [data(options)](./firestore_.documentsnapshot.md#documentsnapshotdata) | | Retrieves all fields in the document as an <code>Object</code>. Returns <code>undefined</code> if the document doesn't exist.<!-- -->By default, <code>serverTimestamp()</code> values that have not yet been set to their final value will be returned as <code>null</code>. You can override this by passing an options object. |
4242
| [exists()](./firestore_.documentsnapshot.md#documentsnapshotexists) | | Returns whether or not the data exists. True if the document exists. |
4343
| [fromJSON(db, json)](./firestore_.documentsnapshot.md#documentsnapshotfromjson) | <code>static</code> | Builds a <code>DocumentSnapshot</code> instance from a JSON object created by [DocumentSnapshot.toJSON()](./firestore_.documentsnapshot.md#documentsnapshottojson)<!-- -->. |
44-
| [fromJSONUsingConverter(db, json, converter)](./firestore_.documentsnapshot.md#documentsnapshotfromjsonusingconverter) | <code>static</code> | Builds a <code>DocumentSnapshot</code> instance from a JSON object created by [DocumentSnapshot.toJSON()](./firestore_.documentsnapshot.md#documentsnapshottojson)<!-- -->. |
44+
| [fromJSON(db, json, converter)](./firestore_.documentsnapshot.md#documentsnapshotfromjson) | <code>static</code> | Builds a <code>DocumentSnapshot</code> instance from a JSON object created by [DocumentSnapshot.toJSON()](./firestore_.documentsnapshot.md#documentsnapshottojson)<!-- -->. |
4545
| [get(fieldPath, options)](./firestore_.documentsnapshot.md#documentsnapshotget) | | Retrieves the field specified by <code>fieldPath</code>. Returns <code>undefined</code> if the document or field doesn't exist.<!-- -->By default, a <code>serverTimestamp()</code> that has not yet been set to its final value will be returned as <code>null</code>. You can override this by passing an options object. |
4646
| [toJSON()](./firestore_.documentsnapshot.md#documentsnapshottojson) | | Returns a JSON-serializable representation of this <code>DocumentSnapshot</code> instance. |
4747

@@ -145,14 +145,14 @@ static fromJSON(db: Firestore, json: object): DocumentSnapshot;
145145

146146
an instance of [DocumentSnapshot](./firestore_.documentsnapshot.md#documentsnapshot_class) if the JSON object could be parsed. Throws a [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class) if an error occurs.
147147

148-
## DocumentSnapshot.fromJSONUsingConverter()
148+
## DocumentSnapshot.fromJSON()
149149

150150
Builds a `DocumentSnapshot` instance from a JSON object created by [DocumentSnapshot.toJSON()](./firestore_.documentsnapshot.md#documentsnapshottojson)<!-- -->.
151151

152152
<b>Signature:</b>
153153

154154
```typescript
155-
static fromJSONUsingConverter<AppModelType, DbModelType extends DocumentData = DocumentData>(db: Firestore, json: object, converter: FirestoreDataConverter<AppModelType, DbModelType>): DocumentSnapshot<AppModelType, DbModelType>;
155+
static fromJSON<AppModelType, DbModelType extends DocumentData = DocumentData>(db: Firestore, json: object, converter: FirestoreDataConverter<AppModelType, DbModelType>): DocumentSnapshot<AppModelType, DbModelType>;
156156
```
157157

158158
#### Parameters

docs-devsite/firestore_.querysnapshot.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export declare class QuerySnapshot<AppModelType = DocumentData, DbModelType exte
3535
| [docChanges(options)](./firestore_.querysnapshot.md#querysnapshotdocchanges) | | Returns an array of the documents changes since the last snapshot. If this is the first snapshot, all documents will be in the list as 'added' changes. |
3636
| [forEach(callback, thisArg)](./firestore_.querysnapshot.md#querysnapshotforeach) | | Enumerates all of the documents in the <code>QuerySnapshot</code>. |
3737
| [fromJSON(db, json)](./firestore_.querysnapshot.md#querysnapshotfromjson) | <code>static</code> | Builds a <code>QuerySnapshot</code> instance from a JSON object created by [QuerySnapshot.toJSON()](./firestore_.querysnapshot.md#querysnapshottojson)<!-- -->. |
38-
| [fromJSONUsingConverter(db, json, converter)](./firestore_.querysnapshot.md#querysnapshotfromjsonusingconverter) | <code>static</code> | Builds a <code>QuerySnapshot</code> instance from a JSON object created by [QuerySnapshot.toJSON()](./firestore_.querysnapshot.md#querysnapshottojson)<!-- -->. |
38+
| [fromJSON(db, json, converter)](./firestore_.querysnapshot.md#querysnapshotfromjson) | <code>static</code> | Builds a <code>QuerySnapshot</code> instance from a JSON object created by [QuerySnapshot.toJSON()](./firestore_.querysnapshot.md#querysnapshottojson)<!-- -->. |
3939
| [toJSON()](./firestore_.querysnapshot.md#querysnapshottojson) | | Returns a JSON-serializable representation of this <code>QuerySnapshot</code> instance. |
4040

4141
## QuerySnapshot.docs
@@ -152,14 +152,14 @@ static fromJSON(db: Firestore, json: object): QuerySnapshot;
152152

153153
an instance of [QuerySnapshot](./firestore_.querysnapshot.md#querysnapshot_class) if the JSON object could be parsed. Throws a [FirestoreError](./firestore_.firestoreerror.md#firestoreerror_class) if an error occurs.
154154

155-
## QuerySnapshot.fromJSONUsingConverter()
155+
## QuerySnapshot.fromJSON()
156156

157157
Builds a `QuerySnapshot` instance from a JSON object created by [QuerySnapshot.toJSON()](./firestore_.querysnapshot.md#querysnapshottojson)<!-- -->.
158158

159159
<b>Signature:</b>
160160

161161
```typescript
162-
static fromJSONUsingConverter<AppModelType, DbModelType extends DocumentData = DocumentData>(db: Firestore, json: object, converter: FirestoreDataConverter<AppModelType, DbModelType>): QuerySnapshot<AppModelType, DbModelType>;
162+
static fromJSON<AppModelType, DbModelType extends DocumentData = DocumentData>(db: Firestore, json: object, converter: FirestoreDataConverter<AppModelType, DbModelType>): QuerySnapshot<AppModelType, DbModelType>;
163163
```
164164

165165
#### Parameters

packages/firestore/src/api/snapshot.ts

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -579,10 +579,7 @@ export class DocumentSnapshot<
579579
* @returns an instance of {@link DocumentSnapshot} if the JSON object could be
580580
* parsed. Throws a {@link FirestoreError} if an error occurs.
581581
*/
582-
static fromJSON(db: Firestore, json: object): DocumentSnapshot {
583-
return DocumentSnapshot.fromJSONInternal(db, json, /* converter = */ null);
584-
}
585-
582+
static fromJSON(db: Firestore, json: object): DocumentSnapshot;
586583
/**
587584
* Builds a `DocumentSnapshot` instance from a JSON object created by
588585
* {@link DocumentSnapshot.toJSON}.
@@ -593,29 +590,21 @@ export class DocumentSnapshot<
593590
* @returns an instance of {@link DocumentSnapshot} if the JSON object could be
594591
* parsed. Throws a {@link FirestoreError} if an error occurs.
595592
*/
596-
static fromJSONUsingConverter<
593+
static fromJSON<
597594
AppModelType,
598595
DbModelType extends DocumentData = DocumentData
599596
>(
600597
db: Firestore,
601598
json: object,
602599
converter: FirestoreDataConverter<AppModelType, DbModelType>
603-
): DocumentSnapshot<AppModelType, DbModelType> {
604-
return DocumentSnapshot.fromJSONInternal(db, json, converter);
605-
}
606-
607-
/**
608-
* Internal implementation for 'fromJSON' and 'fromJSONUsingCoverter'.
609-
* @internal
610-
* @private
611-
*/
612-
private static fromJSONInternal<
600+
): DocumentSnapshot<AppModelType, DbModelType>;
601+
static fromJSON<
613602
AppModelType,
614603
DbModelType extends DocumentData = DocumentData
615604
>(
616605
db: Firestore,
617606
json: object,
618-
converter: FirestoreDataConverter<AppModelType, DbModelType> | null = null
607+
...args: unknown[]
619608
): DocumentSnapshot<AppModelType, DbModelType> {
620609
if (validateJSON(json, DocumentSnapshot._jsonSchema)) {
621610
// Parse the bundle data.
@@ -645,6 +634,15 @@ export class DocumentSnapshot<
645634
ResourcePath.fromString(json.bundleName)
646635
);
647636

637+
let converter: FirestoreDataConverter<AppModelType, DbModelType> | null =
638+
null;
639+
if (args[0]) {
640+
converter = args[0] as FirestoreDataConverter<
641+
AppModelType,
642+
DbModelType
643+
>;
644+
}
645+
648646
// Return the external facing DocumentSnapshot.
649647
return new DocumentSnapshot(
650648
db,
@@ -891,9 +889,7 @@ export class QuerySnapshot<
891889
* @returns an instance of {@link QuerySnapshot} if the JSON object could be
892890
* parsed. Throws a {@link FirestoreError} if an error occurs.
893891
*/
894-
static fromJSON(db: Firestore, json: object): QuerySnapshot {
895-
return QuerySnapshot.fromJSONInternal(db, json, /* converter = */ null);
896-
}
892+
static fromJSON(db: Firestore, json: object): QuerySnapshot;
897893

898894
/**
899895
* Builds a `QuerySnapshot` instance from a JSON object created by
@@ -905,29 +901,18 @@ export class QuerySnapshot<
905901
* @returns an instance of {@link QuerySnapshot} if the JSON object could be
906902
* parsed. Throws a {@link FirestoreError} if an error occurs.
907903
*/
908-
static fromJSONUsingConverter<
904+
static fromJSON<
909905
AppModelType,
910906
DbModelType extends DocumentData = DocumentData
911907
>(
912908
db: Firestore,
913909
json: object,
914910
converter: FirestoreDataConverter<AppModelType, DbModelType>
915-
): QuerySnapshot<AppModelType, DbModelType> {
916-
return QuerySnapshot.fromJSONInternal(db, json, converter);
917-
}
918-
919-
/**
920-
* Internal implementation for 'fromJSON' and 'fromJSONUsingCoverter'.
921-
* @internal
922-
* @private
923-
*/
924-
private static fromJSONInternal<
925-
AppModelType,
926-
DbModelType extends DocumentData = DocumentData
927-
>(
911+
): QuerySnapshot<AppModelType, DbModelType>;
912+
static fromJSON<AppModelType, DbModelType extends DocumentData>(
928913
db: Firestore,
929914
json: object,
930-
converter: FirestoreDataConverter<AppModelType, DbModelType> | null
915+
...args: unknown[]
931916
): QuerySnapshot<AppModelType, DbModelType> {
932917
if (validateJSON(json, QuerySnapshot._jsonSchema)) {
933918
// Parse the bundle data.
@@ -968,6 +953,15 @@ export class QuerySnapshot<
968953
/* hasCachedResults= */ false
969954
);
970955

956+
let converter: FirestoreDataConverter<AppModelType, DbModelType> | null =
957+
null;
958+
if (args[0]) {
959+
converter = args[0] as FirestoreDataConverter<
960+
AppModelType,
961+
DbModelType
962+
>;
963+
}
964+
971965
// Create an external Query object, required to construct the QuerySnapshot.
972966
const externalQuery = new Query<AppModelType, DbModelType>(
973967
db,

0 commit comments

Comments
 (0)