Skip to content

Add support for Typescript Custom Mapping #2240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
eff1d9b
working with generics fully implemented, no tests
Oct 4, 2019
f46af07
[AUTOMATED]: Prettier Code Styling
Oct 4, 2019
fb566cf
round 1 schmidt comments
Oct 4, 2019
c5d8a5f
[AUTOMATED]: Prettier Code Styling
Oct 4, 2019
aed17d1
resolve gil comments, no parent behavior
Oct 7, 2019
ea737f9
updated tests and fixed converterFromArgs
Oct 9, 2019
d6c6355
Merge branch 'master' into bc/generics
Oct 22, 2019
e2b67b3
add more default generic for compiling
Oct 23, 2019
7c150db
[AUTOMATED]: Prettier Code Styling
Oct 23, 2019
3f9bc7c
working with test + don't always pass converter
Nov 6, 2019
6fc432f
Merge branch 'master' into bc/generics
Nov 7, 2019
3096f4b
updated to withConverter, needs test cleanup
Nov 12, 2019
42297c6
[AUTOMATED]: Prettier Code Styling
Nov 12, 2019
338c876
change documentSnapshot methods to <unknown>
Nov 12, 2019
7c3c509
Merge branch 'master' into bc/generics
Nov 14, 2019
d02d5b4
remove unneeded code, added tests
Nov 18, 2019
90138b1
[AUTOMATED]: Prettier Code Styling
Nov 18, 2019
f571f6f
add comments to withConverter
Nov 19, 2019
e351bc8
Merge branch 'master' into bc/generics
Nov 20, 2019
12b602b
[AUTOMATED]: Prettier Code Styling
Nov 20, 2019
2dd8945
resolved comments, need to update jsdoc
Nov 26, 2019
95340bd
Merge branch 'master' into bc/generics
Nov 26, 2019
ba1d7ff
Merge branch 'bc/generics' of github.com:firebase/firebase-js-sdk int…
Nov 26, 2019
a03e009
add comment
Nov 26, 2019
877b3d0
[AUTOMATED]: Prettier Code Styling
Nov 26, 2019
84ebd0b
Merge branch 'master' into bc/generics
Dec 2, 2019
fef36eb
resolve comments from michael pt. 2
Dec 3, 2019
3abad69
Merge branch 'master' into bc/generics
Dec 3, 2019
2ecf3f8
add comment for toString() comparison
Dec 3, 2019
f79041c
remove defaultDocumentdataConverter, add readonly access, update comm…
Dec 5, 2019
6034dae
[AUTOMATED]: Prettier Code Styling
Dec 5, 2019
3c3dbca
add periods to param comments in index.d.ts
Dec 5, 2019
0fce460
remove toString() check in isEqual()
Dec 5, 2019
ab90ea7
change <unknown> to any, resolve sebastian's comments
Dec 9, 2019
b652bf9
[AUTOMATED]: Prettier Code Styling
Dec 9, 2019
a0b0975
add changelog
Dec 9, 2019
2627c4d
change database.ts back to unknown, update changelog
Dec 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions packages/firebase/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7088,8 +7088,8 @@ declare namespace firebase.firestore {
export function setLogLevel(logLevel: LogLevel): void;

/**
* Converter used by `withConverter()` to transform user objects into
* Firestore data.
* Converter used by `withConverter()` to transform user objects of type T
* into Firestore data.
*
* Using the converter allows you to specify generic type arguments when
* storing and retrieving objects from Firestore.
Expand Down Expand Up @@ -7142,7 +7142,7 @@ declare namespace firebase.firestore {
* type T. You can access your data by calling: `snapshot.data(options)`.
*
* @param snapshot A QueryDocumentSnapshot containing your data and metadata.
* @param options The SnapshotOptions from the initial call to data().
* @param options The SnapshotOptions from the initial call to `data()`.
*/
fromFirestore(snapshot: QueryDocumentSnapshot, options: SnapshotOptions): T;
}
Expand Down Expand Up @@ -7594,7 +7594,7 @@ declare namespace firebase.firestore {
* @return This `Transaction` instance. Used for chaining method calls.
*/
update(
documentRef: DocumentReference<unknown>,
documentRef: DocumentReference<any>,
data: UpdateData
): Transaction;

Expand All @@ -7614,7 +7614,7 @@ declare namespace firebase.firestore {
* to the backend (Note that it won't resolve while you're offline).
*/
update(
documentRef: DocumentReference<unknown>,
documentRef: DocumentReference<any>,
field: string | FieldPath,
value: any,
...moreFieldsAndValues: any[]
Expand All @@ -7626,7 +7626,7 @@ declare namespace firebase.firestore {
* @param documentRef A reference to the document to be deleted.
* @return This `Transaction` instance. Used for chaining method calls.
*/
delete(documentRef: DocumentReference<unknown>): Transaction;
delete(documentRef: DocumentReference<any>): Transaction;
}

/**
Expand Down Expand Up @@ -7671,7 +7671,7 @@ declare namespace firebase.firestore {
* @return This `WriteBatch` instance. Used for chaining method calls.
*/
update(
documentRef: DocumentReference<unknown>,
documentRef: DocumentReference<any>,
data: UpdateData
): WriteBatch;

Expand All @@ -7690,7 +7690,7 @@ declare namespace firebase.firestore {
* to the backend (Note that it won't resolve while you're offline).
*/
update(
documentRef: DocumentReference<unknown>,
documentRef: DocumentReference<any>,
field: string | FieldPath,
value: any,
...moreFieldsAndValues: any[]
Expand All @@ -7702,7 +7702,7 @@ declare namespace firebase.firestore {
* @param documentRef A reference to the document to be deleted.
* @return This `WriteBatch` instance. Used for chaining method calls.
*/
delete(documentRef: DocumentReference<unknown>): WriteBatch;
delete(documentRef: DocumentReference<any>): WriteBatch;

/**
* Commits all of the writes in this write batch as a single atomic unit.
Expand Down Expand Up @@ -7980,9 +7980,9 @@ declare namespace firebase.firestore {
/**
* 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, it will
* use the provided converter to convert data to/from type U (your custom
* model object type).
* set(), get(), etc. on the returned DocumentReference instance, the
* provided converter will convert between Firestore data and your custom
* type U.
*
* @param converter Converts objects to and from Firestore.
* @return A DocumentReference<U> that uses the provided converter.
Expand Down Expand Up @@ -8246,7 +8246,7 @@ declare namespace firebase.firestore {
* @param snapshot The snapshot of the document to start at.
* @return The created Query.
*/
startAt(snapshot: DocumentSnapshot<unknown>): Query<T>;
startAt(snapshot: DocumentSnapshot<any>): Query<T>;

/**
* Creates and returns a new Query that starts at the provided fields
Expand All @@ -8268,7 +8268,7 @@ declare namespace firebase.firestore {
* @param snapshot The snapshot of the document to start after.
* @return The created Query.
*/
startAfter(snapshot: DocumentSnapshot<unknown>): Query<T>;
startAfter(snapshot: DocumentSnapshot<any>): Query<T>;

/**
* Creates and returns a new Query that starts after the provided fields
Expand All @@ -8290,7 +8290,7 @@ declare namespace firebase.firestore {
* @param snapshot The snapshot of the document to end before.
* @return The created Query.
*/
endBefore(snapshot: DocumentSnapshot<unknown>): Query<T>;
endBefore(snapshot: DocumentSnapshot<any>): Query<T>;

/**
* Creates and returns a new Query that ends before the provided fields
Expand All @@ -8312,7 +8312,7 @@ declare namespace firebase.firestore {
* @param snapshot The snapshot of the document to end at.
* @return The created Query.
*/
endAt(snapshot: DocumentSnapshot<unknown>): Query<T>;
endAt(snapshot: DocumentSnapshot<any>): Query<T>;

/**
* Creates and returns a new Query that ends at the provided fields
Expand Down Expand Up @@ -8434,8 +8434,8 @@ declare namespace firebase.firestore {
/**
* 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, it will use the provided converter to convert data
* to/from type U (your custom model object type).
* returned Query, the provided converter will convert between Firestore
* data and your custom type U.
*
* @param converter Converts objects to and from Firestore.
* @return A Query<U> that uses the provided converter.
Expand Down Expand Up @@ -8590,8 +8590,8 @@ declare namespace firebase.firestore {
/**
* 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, it will use the provided
* converter to convert data to/from type U (your custom model object type).
* on the returned CollectionReference instance, the provided converter will
* convert between Firestore data and your custom type U.
*
* @param converter Converts objects to and from Firestore.
* @return A CollectionReference<U> that uses the provided converter.
Expand Down
20 changes: 10 additions & 10 deletions packages/firestore-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,17 @@ export class Transaction {
): Transaction;

update(
documentRef: DocumentReference<unknown>,
documentRef: DocumentReference<any>,
data: UpdateData
): Transaction;
update(
documentRef: DocumentReference<unknown>,
documentRef: DocumentReference<any>,
field: string | FieldPath,
value: any,
...moreFieldsAndValues: any[]
): Transaction;

delete(documentRef: DocumentReference<unknown>): Transaction;
delete(documentRef: DocumentReference<any>): Transaction;
}

export class WriteBatch {
Expand All @@ -163,15 +163,15 @@ export class WriteBatch {
options?: SetOptions
): WriteBatch;

update(documentRef: DocumentReference<unknown>, data: UpdateData): WriteBatch;
update(documentRef: DocumentReference<any>, data: UpdateData): WriteBatch;
update(
documentRef: DocumentReference<unknown>,
documentRef: DocumentReference<any>,
field: string | FieldPath,
value: any,
...moreFieldsAndValues: any[]
): WriteBatch;

delete(documentRef: DocumentReference<unknown>): WriteBatch;
delete(documentRef: DocumentReference<any>): WriteBatch;

commit(): Promise<void>;
}
Expand Down Expand Up @@ -308,16 +308,16 @@ export class Query<T = DocumentData> {

limitToLast(limit: number): Query<T>;

startAt(snapshot: DocumentSnapshot<unknown>): Query<T>;
startAt(snapshot: DocumentSnapshot<any>): Query<T>;
startAt(...fieldValues: any[]): Query<T>;

startAfter(snapshot: DocumentSnapshot<unknown>): Query<T>;
startAfter(snapshot: DocumentSnapshot<any>): Query<T>;
startAfter(...fieldValues: any[]): Query<T>;

endBefore(snapshot: DocumentSnapshot<unknown>): Query<T>;
endBefore(snapshot: DocumentSnapshot<any>): Query<T>;
endBefore(...fieldValues: any[]): Query<T>;

endAt(snapshot: DocumentSnapshot<unknown>): Query<T>;
endAt(snapshot: DocumentSnapshot<any>): Query<T>;
endAt(...fieldValues: any[]): Query<T>;

isEqual(other: Query<T>): boolean;
Expand Down
38 changes: 25 additions & 13 deletions packages/firestore/src/api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -772,17 +772,20 @@ export class Transaction implements firestore.Transaction {
}

update(
documentRef: firestore.DocumentReference<unknown>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
documentRef: firestore.DocumentReference<any>,
value: firestore.UpdateData
): Transaction;
update(
documentRef: firestore.DocumentReference<unknown>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
documentRef: firestore.DocumentReference<any>,
field: string | ExternalFieldPath,
value: unknown,
...moreFieldsAndValues: unknown[]
): Transaction;
update(
documentRef: firestore.DocumentReference<unknown>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
documentRef: firestore.DocumentReference<any>,
fieldOrUpdateData: string | ExternalFieldPath | firestore.UpdateData,
value?: unknown,
...moreFieldsAndValues: unknown[]
Expand Down Expand Up @@ -823,7 +826,8 @@ export class Transaction implements firestore.Transaction {
return this;
}

delete(documentRef: firestore.DocumentReference<unknown>): Transaction {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
delete(documentRef: firestore.DocumentReference<any>): Transaction {
validateExactNumberOfArgs('Transaction.delete', arguments, 1);
const ref = validateReference(
'Transaction.delete',
Expand Down Expand Up @@ -877,17 +881,20 @@ export class WriteBatch implements firestore.WriteBatch {
}

update(
documentRef: firestore.DocumentReference<unknown>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
documentRef: firestore.DocumentReference<any>,
value: firestore.UpdateData
): WriteBatch;
update(
documentRef: firestore.DocumentReference<unknown>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
documentRef: firestore.DocumentReference<any>,
field: string | ExternalFieldPath,
value: unknown,
...moreFieldsAndValues: unknown[]
): WriteBatch;
update(
documentRef: firestore.DocumentReference<unknown>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
documentRef: firestore.DocumentReference<any>,
fieldOrUpdateData: string | ExternalFieldPath | firestore.UpdateData,
value?: unknown,
...moreFieldsAndValues: unknown[]
Expand Down Expand Up @@ -932,7 +939,8 @@ export class WriteBatch implements firestore.WriteBatch {
return this;
}

delete(documentRef: firestore.DocumentReference<unknown>): WriteBatch {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
delete(documentRef: firestore.DocumentReference<any>): WriteBatch {
validateExactNumberOfArgs('WriteBatch.delete', arguments, 1);
this.verifyNotCommitted();
const ref = validateReference(
Expand Down Expand Up @@ -1652,7 +1660,8 @@ export class Query<T = firestore.DocumentData> implements firestore.Query<T> {
}

startAt(
docOrField: unknown | firestore.DocumentSnapshot<unknown>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
docOrField: unknown | firestore.DocumentSnapshot<any>,
...fields: unknown[]
): firestore.Query<T> {
validateAtLeastNumberOfArgs('Query.startAt', arguments, 1);
Expand All @@ -1670,7 +1679,8 @@ export class Query<T = firestore.DocumentData> implements firestore.Query<T> {
}

startAfter(
docOrField: unknown | firestore.DocumentSnapshot<unknown>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
docOrField: unknown | firestore.DocumentSnapshot<any>,
...fields: unknown[]
): firestore.Query<T> {
validateAtLeastNumberOfArgs('Query.startAfter', arguments, 1);
Expand All @@ -1688,7 +1698,8 @@ export class Query<T = firestore.DocumentData> implements firestore.Query<T> {
}

endBefore(
docOrField: unknown | firestore.DocumentSnapshot<unknown>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
docOrField: unknown | firestore.DocumentSnapshot<any>,
...fields: unknown[]
): firestore.Query<T> {
validateAtLeastNumberOfArgs('Query.endBefore', arguments, 1);
Expand All @@ -1706,7 +1717,8 @@ export class Query<T = firestore.DocumentData> implements firestore.Query<T> {
}

endAt(
docOrField: unknown | firestore.DocumentSnapshot<unknown>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
docOrField: unknown | firestore.DocumentSnapshot<any>,
...fields: unknown[]
): firestore.Query<T> {
validateAtLeastNumberOfArgs('Query.endAt', arguments, 1);
Expand Down Expand Up @@ -2663,7 +2675,7 @@ function applyFirestoreDataConverter<T>(
let convertedValue;
if (converter) {
convertedValue = converter.toFirestore(value);
functionName = 'toFirestore() in Transaction.set';
functionName = 'toFirestore() in ' + functionName;
} else {
convertedValue = value as firestore.DocumentData;
}
Expand Down