-
Notifications
You must be signed in to change notification settings - Fork 928
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
Changes from 17 commits
f5a00fc
e87b617
fdd432a
01e1529
1d48049
de10404
d2df5e8
21cc4bf
c5bb26f
c2e0e38
479b6bb
1ffaad2
eb7d26c
b0568bb
826fff2
d94b0f4
0b620ca
da10a15
cf41539
a2df21b
c11e067
706c060
a8123d8
f9d4b3e
416850e
5a175a4
635c9e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ import { _FirebaseNamespace } from '@firebase/app-types/private'; | |
import { Component, ComponentType } from '@firebase/component'; | ||
|
||
import { | ||
FirebaseFirestore, | ||
Firestore as FirebaseFirestore, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Not sure how this worked in the past, since |
||
CACHE_SIZE_UNLIMITED, | ||
GeoPoint, | ||
Timestamp | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,12 @@ export { | |
SetOptions, | ||
DocumentData, | ||
UpdateData, | ||
Primitive, | ||
WithFieldValue, | ||
NestedUpdateFields, | ||
AddPrefixToKeys, | ||
NestedPartial, | ||
UnionToIntersection, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you saying to move the helper types into a separate There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Moved into |
||
refEqual, | ||
queryEqual | ||
} from '../src/exp/reference'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,6 +106,7 @@ import { | |
AbstractUserDataWriter | ||
} from '../../exp/index'; // import from the exp public API | ||
import { DatabaseId } from '../core/database_info'; | ||
import { NestedPartial, WithFieldValue } from '../lite/reference'; | ||
import { UntypedFirestoreDataConverter } from '../lite/user_data_reader'; | ||
import { DocumentKey } from '../model/document_key'; | ||
import { FieldPath, ResourcePath } from '../model/path'; | ||
|
@@ -452,9 +453,9 @@ export class Transaction implements PublicTransaction, Compat<ExpTransaction> { | |
const ref = castReference(documentRef); | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Yes, since the method parameter types are |
||
} else { | ||
this._delegate.set(ref, data); | ||
this._delegate.set(ref, data as WithFieldValue<T>); | ||
} | ||
return this; | ||
} | ||
|
@@ -513,9 +514,9 @@ export class WriteBatch implements PublicWriteBatch, Compat<ExpWriteBatch> { | |
const ref = castReference(documentRef); | ||
if (options) { | ||
validateSetOptions('WriteBatch.set', options); | ||
this._delegate.set(ref, data, options); | ||
this._delegate.set(ref, data as NestedPartial<T>, options); | ||
} else { | ||
this._delegate.set(ref, data); | ||
this._delegate.set(ref, data as WithFieldValue<T>); | ||
} | ||
return this; | ||
} | ||
|
@@ -597,19 +598,19 @@ class FirestoreDataConverter<U> | |
); | ||
} | ||
|
||
toFirestore(modelObject: U): PublicDocumentData; | ||
toFirestore(modelObject: WithFieldValue<U>): PublicDocumentData; | ||
toFirestore( | ||
modelObject: Partial<U>, | ||
modelObject: NestedPartial<U>, | ||
options: PublicSetOptions | ||
): PublicDocumentData; | ||
toFirestore( | ||
modelObject: U | Partial<U>, | ||
modelObject: WithFieldValue<U> | NestedPartial<U>, | ||
options?: PublicSetOptions | ||
): PublicDocumentData { | ||
if (!options) { | ||
return this._delegate.toFirestore(modelObject as U); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WithFieldValue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} else { | ||
return this._delegate.toFirestore(modelObject, options); | ||
return this._delegate.toFirestore(modelObject as Partial<U>, options); | ||
} | ||
} | ||
|
||
|
@@ -733,7 +734,11 @@ export class DocumentReference<T = PublicDocumentData> | |
set(value: T | Partial<T>, options?: PublicSetOptions): Promise<void> { | ||
options = validateSetOptions('DocumentReference.set', options); | ||
try { | ||
return setDoc(this._delegate, value, options); | ||
if (options) { | ||
return setDoc(this._delegate, value as NestedPartial<T>, options); | ||
} else { | ||
return setDoc(this._delegate, value as WithFieldValue<T>); | ||
} | ||
} catch (e) { | ||
throw replaceFunctionName(e, 'setDoc()', 'DocumentReference.set()'); | ||
} | ||
|
@@ -1287,7 +1292,7 @@ export class CollectionReference<T = PublicDocumentData> | |
} | ||
|
||
add(data: T): Promise<DocumentReference<T>> { | ||
return addDoc(this._delegate, data).then( | ||
return addDoc(this._delegate, data as WithFieldValue<T>).then( | ||
docRef => new DocumentReference(this.firestore, docRef) | ||
); | ||
} | ||
|
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
.