Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-andersen committed Aug 24, 2023
1 parent 3603e2e commit f792c79
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 30 deletions.
3 changes: 2 additions & 1 deletion dev/src/collection-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ export class CollectionGroup<
* Applies a custom data converter to this `CollectionGroup`, allowing you
* to use your own custom model objects with Firestore. When you call get()
* on the returned `CollectionGroup`, the provided converter will convert
* between Firestore data and your custom type U.
* between Firestore data of type `NewDbModelType` and your custom type
* `NewAppModelType`.
*
* Using the converter allows you to specify generic type arguments when
* storing and retrieving objects from Firestore.
Expand Down
27 changes: 16 additions & 11 deletions dev/src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,14 @@ export class DocumentSnapshot<
* @param obj The object to store in the DocumentSnapshot.
* @return The created DocumentSnapshot.
*/
static fromObject<U>(
ref: firestore.DocumentReference<U>,
obj: firestore.DocumentData
): DocumentSnapshot<U> {
const serializer = (ref as DocumentReference<U>).firestore._serializer!;
static fromObject<AppModelType, DbModelType>(
ref: firestore.DocumentReference<AppModelType, DbModelType>,
obj: DbModelType
): DocumentSnapshot<AppModelType, DbModelType> {
const serializer = (ref as DocumentReference<AppModelType, DbModelType>)
.firestore._serializer!;
return new DocumentSnapshot(
ref as DocumentReference<U>,
ref as DocumentReference<AppModelType, DbModelType>,
serializer.encodeFields(obj)
);
}
Expand All @@ -173,11 +174,12 @@ export class DocumentSnapshot<
* @param data The field/value map to expand.
* @return The created DocumentSnapshot.
*/
static fromUpdateMap<U>(
ref: firestore.DocumentReference<U>,
static fromUpdateMap<AppModelType, DbModelType>(
ref: firestore.DocumentReference<AppModelType, DbModelType>,
data: UpdateMap
): DocumentSnapshot<U> {
const serializer = (ref as DocumentReference<U>).firestore._serializer!;
): DocumentSnapshot<AppModelType, DbModelType> {
const serializer = (ref as DocumentReference<AppModelType, DbModelType>)
.firestore._serializer!;

/**
* Merges 'value' at the field path specified by the path array into
Expand Down Expand Up @@ -247,7 +249,10 @@ export class DocumentSnapshot<
merge(res, value, path, 0);
}

return new DocumentSnapshot(ref as DocumentReference<U>, res);
return new DocumentSnapshot(
ref as DocumentReference<AppModelType, DbModelType>,
res
);
}

/**
Expand Down
9 changes: 5 additions & 4 deletions dev/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ const MAX_CONCURRENT_REQUESTS_PER_CLIENT = 100;

/**
* Converter used by [withConverter()]{@link Query#withConverter} to transform
* user objects of type T into Firestore data.
* user objects of type `AppModelType` into Firestore data of type
* `DbModelType`.
*
* Using the converter allows you to specify generic type arguments when storing
* and retrieving objects from Firestore.
Expand Down Expand Up @@ -212,10 +213,10 @@ const MAX_CONCURRENT_REQUESTS_PER_CLIENT = 100;
*
* ```
* @property {Function} toFirestore Called by the Firestore SDK to convert a
* custom model object of type T into a plain Javascript object (suitable for
* writing directly to the Firestore database).
* custom model object of type `AppModelType` into a plain Javascript object
* (suitable for writing directly to the Firestore database).
* @property {Function} fromFirestore Called by the Firestore SDK to convert
* Firestore data into an object of type T.
* Firestore data into an object of type `AppModelType`.
* @typedef {Object} FirestoreDataConverter
*/

Expand Down
16 changes: 8 additions & 8 deletions dev/src/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ export class DocumentReference<
* [SetOptions]{@link SetOptions}, the provided data can be merged into an
* existing document.
*
* @param {T|Partial<T>} data A map of the fields and values for the document.
* @param {T|Partial<AppModelType>} data A map of the fields and values for
* the document.
* @param {SetOptions=} options An object to configure the set behavior.
* @param {boolean=} options.merge If true, set() merges the values specified
* in its data argument. Fields omitted from this set() call remain untouched.
Expand Down Expand Up @@ -630,7 +631,8 @@ export class DocumentReference<
* Applies a custom data converter to this DocumentReference, allowing you to
* use your own custom model objects with Firestore. When you call set(),
* get(), etc. on the returned DocumentReference instance, the provided
* converter will convert between Firestore data and your custom type U.
* converter will convert between Firestore data of type `NewDbModelType` and
* your custom type `NewAppModelType`.
*
* Using the converter allows you to specify generic type arguments when
* storing and retrieving objects from Firestore.
Expand Down Expand Up @@ -1678,9 +1680,7 @@ export class Query<
* });
* ```
*/
select(
...fieldPaths: Array<string | FieldPath>
): Query<firestore.DocumentData> {
select(...fieldPaths: Array<string | FieldPath>): Query {
const fields: api.StructuredQuery.IFieldReference[] = [];

if (fieldPaths.length === 0) {
Expand Down Expand Up @@ -2766,8 +2766,7 @@ export class Query<
* Applies a custom data converter to this Query, allowing you to use your
* own custom model objects with Firestore. When you call get() on the
* returned Query, the provided converter will convert between Firestore
* data and your custom type of type `NewDbModelType` and your custom type
* `NewAppModelType`.
* data of type `NewDbModelType` and your custom type `NewAppModelType`.
*
* Using the converter allows you to specify generic type arguments when
* storing and retrieving objects from Firestore.
Expand Down Expand Up @@ -3096,7 +3095,8 @@ export class CollectionReference<
* Applies a custom data converter to this CollectionReference, allowing you
* to use your own custom model objects with Firestore. When you call add() on
* the returned CollectionReference instance, the provided converter will
* convert between Firestore data and your custom type U.
* convert between Firestore data of type `NewDbModelType` and your custom
* type `NewAppModelType`.
*
* Using the converter allows you to specify generic type arguments when
* storing and retrieving objects from Firestore.
Expand Down
15 changes: 9 additions & 6 deletions types/firestore.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1377,8 +1377,8 @@ declare namespace FirebaseFirestore {
* Applies a custom data converter to this DocumentReference, allowing you
* to use your own custom model objects with Firestore. When you call
* set(), get(), etc. on the returned DocumentReference instance, the
* provided converter will convert between Firestore data and your custom
* type U.
* provided converter will convert between Firestore data of type
* `NewDbModelType` and your custom type `NewAppModelType`.
*
* @param converter Converts objects to and from Firestore. Passing in
* `null` removes the current converter.
Expand Down Expand Up @@ -2042,7 +2042,8 @@ declare namespace FirebaseFirestore {
* Applies a custom data converter to this `CollectionGroup`, allowing you
* to use your own custom model objects with Firestore. When you call get()
* on the returned `CollectionGroup`, the provided converter will convert
* between Firestore data and your custom type U.
* between Firestore data of type `NewDbModelType` and your custom type
* `NewAppModelType`.
*
* Using the converter allows you to specify generic type arguments when
* storing and retrieving objects from Firestore.
Expand Down Expand Up @@ -2081,10 +2082,12 @@ declare namespace FirebaseFirestore {
*
* @param converter Converts objects to and from Firestore. Passing in
* `null` removes the current converter.
* @return A `CollectionGroup<U>` that uses the provided converter.
* @return A `CollectionGroup` that uses the provided converter.
*/
withConverter<U>(converter: FirestoreDataConverter<U>): CollectionGroup<U>;
withConverter(converter: null): CollectionGroup<DocumentData>;
withConverter<AppModelType, DbModelType>(
converter: FirestoreDataConverter<AppModelType, DbModelType>
): CollectionGroup<AppModelType, DbModelType>;
withConverter(converter: null): CollectionGroup;
}

/**
Expand Down

0 comments on commit f792c79

Please sign in to comment.