-
Notifications
You must be signed in to change notification settings - Fork 989
Firestore: QoL improvements for converters #5268
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
Conversation
🦋 Changeset detectedLatest commit: 635c9e3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Changeset File Check ✅
|
schmidt-sebastian
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Roughly LGTM :)
|
|
||
| type Primitive = string | number | boolean | bigint | undefined | null; | ||
| // eslint-disable-next-line @typescript-eslint/ban-types | ||
| type Builtin = Primitive | Function; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we use Function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used it when I had special FieldValue return types. Removed it.
Binary Size ReportAffected SDKs
Test Logs |
Size Analysis ReportAffected ProductsNo changes between base commit (cca8cdf) and head commit (5301fc7f). |
schmidt-sebastian
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is great. Some cleanup suggestions, most of which you will probably push back on :)
| toFirestore(modelObject: T): DocumentData; | ||
| toFirestore(modelObject: Partial<T>, options: SetOptions): DocumentData; | ||
| toFirestore(modelObject: WithFieldValue<T>): DocumentData; | ||
| toFirestore(modelObject: NestedPartial<T>, options: SetOptions): DocumentData; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we were going to align those two names. Have you thought of a naming pattern that would achieve that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to PartialWithFieldValue.
|
|
||
| import { | ||
| FirebaseFirestore, | ||
| Firestore as FirebaseFirestore, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Not sure how this worked in the past, since FirebaseFirestore isn't exported by ../exp/index.
packages/firestore/exp/api.ts
Outdated
| NestedUpdateFields, | ||
| AddPrefixToKeys, | ||
| NestedPartial, | ||
| UnionToIntersection, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: I think it would be cleaner if these were exports from a dedicated module, which would make it easier to understand that SetOptions and Primitive are completely unrelated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying to move the helper types into a separate exp/helper.ts file, or for lite as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like lite/types.ts that you can refer to from exp/ and lite/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved into lite/types
| if (options) { | ||
| validateSetOptions('Transaction.set', options); | ||
| this._delegate.set(ref, data, options); | ||
| this._delegate.set(ref, data as NestedPartial<T>, options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, since the method parameter types are T | Partial<T>, we have to cast.
| * An untyped Firestore Data Converter interface that is shared between the | ||
| * lite, firestore-exp and classic SDK. | ||
| */ | ||
| export interface UntypedFirestoreDataConverter<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also update the docs for FirestoreDataConverter to explain what this new input type is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added for UntypedFirestoreDataConverter and FirestoreDataConverter.
| const ref = doc(collection(db, 'testobj')).withConverter( | ||
| testConverter | ||
| ); | ||
| await setBaseDoc(ref); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also withTestDocAndInitialData that should give you an existing doc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
schmidt-sebastian
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
|
|
@svailla4 Thanks for catching this! Will look into this some more. |
|
This allows for dot notation in the middle of the object, but this probably won't work. link type Schema = {
foo: {
bar: {
baz: number
}
}
}
const updateData: UpdateData<Schema> = {
foo: {
"bar.baz": 3
}
} |
|
I get an error when using this with Record in Typescript 4.4. link type Schema = {
foo: {
bar: Record<string, string>
}
}
const updateData: UpdateData<Schema> = {
foo:{
bar: {
baz: 'hello'
}
}
} |


Fixes #4277.
Changes implemented:
Partialfields when using a converter.