@@ -726,9 +726,15 @@ export class Transaction implements firestore.Transaction {
726
726
} ) ;
727
727
}
728
728
729
+ set < T > (
730
+ documentRef : DocumentReference < T > ,
731
+ data : Partial < T > ,
732
+ options : firestore . SetOptions
733
+ ) : Transaction ;
734
+ set < T > ( documentRef : DocumentReference < T > , data : T ) : Transaction ;
729
735
set < T > (
730
736
documentRef : firestore . DocumentReference < T > ,
731
- value : T ,
737
+ value : T | Partial < T > ,
732
738
options ?: firestore . SetOptions
733
739
) : Transaction {
734
740
validateBetweenNumberOfArgs ( 'Transaction.set' , arguments , 2 , 3 ) ;
@@ -738,15 +744,16 @@ export class Transaction implements firestore.Transaction {
738
744
this . _firestore
739
745
) ;
740
746
options = validateSetOptions ( 'Transaction.set' , options ) ;
741
- const [ convertedValue , functionName ] = applyFirestoreDataConverter (
747
+ const convertedValue = applyFirestoreDataConverter (
742
748
ref . _converter ,
743
749
value ,
744
- 'Transaction.set'
750
+ options
745
751
) ;
746
752
const parsed = this . _firestore . _dataReader . parseSetData (
747
- functionName ,
753
+ 'Transaction.set' ,
748
754
ref . _key ,
749
755
convertedValue ,
756
+ ref . _converter !== null ,
750
757
options
751
758
) ;
752
759
this . _transaction . set ( ref . _key , parsed ) ;
@@ -825,9 +832,15 @@ export class WriteBatch implements firestore.WriteBatch {
825
832
826
833
constructor ( private _firestore : Firestore ) { }
827
834
835
+ set < T > (
836
+ documentRef : DocumentReference < T > ,
837
+ data : Partial < T > ,
838
+ options : firestore . SetOptions
839
+ ) : WriteBatch ;
840
+ set < T > ( documentRef : DocumentReference < T > , data : T ) : WriteBatch ;
828
841
set < T > (
829
842
documentRef : firestore . DocumentReference < T > ,
830
- value : T ,
843
+ value : T | Partial < T > ,
831
844
options ?: firestore . SetOptions
832
845
) : WriteBatch {
833
846
validateBetweenNumberOfArgs ( 'WriteBatch.set' , arguments , 2 , 3 ) ;
@@ -838,15 +851,16 @@ export class WriteBatch implements firestore.WriteBatch {
838
851
this . _firestore
839
852
) ;
840
853
options = validateSetOptions ( 'WriteBatch.set' , options ) ;
841
- const [ convertedValue , functionName ] = applyFirestoreDataConverter (
854
+ const convertedValue = applyFirestoreDataConverter (
842
855
ref . _converter ,
843
856
value ,
844
- 'WriteBatch.set'
857
+ options
845
858
) ;
846
859
const parsed = this . _firestore . _dataReader . parseSetData (
847
- functionName ,
860
+ 'WriteBatch.set' ,
848
861
ref . _key ,
849
862
convertedValue ,
863
+ ref . _converter !== null ,
850
864
options
851
865
) ;
852
866
this . _mutations = this . _mutations . concat (
@@ -1032,22 +1046,21 @@ export class DocumentReference<T = firestore.DocumentData>
1032
1046
) ;
1033
1047
}
1034
1048
1035
- set (
1036
- value : firestore . DocumentData ,
1037
- options ?: firestore . SetOptions
1038
- ) : Promise < void > ;
1039
- set ( value : T , options ?: firestore . SetOptions ) : Promise < void > {
1049
+ set ( value : Partial < T > , options : firestore . SetOptions ) : Promise < void > ;
1050
+ set ( value : T ) : Promise < void > ;
1051
+ set ( value : T | Partial < T > , options ?: firestore . SetOptions ) : Promise < void > {
1040
1052
validateBetweenNumberOfArgs ( 'DocumentReference.set' , arguments , 1 , 2 ) ;
1041
1053
options = validateSetOptions ( 'DocumentReference.set' , options ) ;
1042
- const [ convertedValue , functionName ] = applyFirestoreDataConverter (
1054
+ const convertedValue = applyFirestoreDataConverter (
1043
1055
this . _converter ,
1044
1056
value ,
1045
- 'DocumentReference.set'
1057
+ options
1046
1058
) ;
1047
1059
const parsed = this . firestore . _dataReader . parseSetData (
1048
- functionName ,
1060
+ 'DocumentReference.set' ,
1049
1061
this . _key ,
1050
1062
convertedValue ,
1063
+ this . _converter !== null ,
1051
1064
options
1052
1065
) ;
1053
1066
return this . _firestoreClient . write (
@@ -2584,16 +2597,22 @@ function resultChangeType(type: ChangeType): firestore.DocumentChangeType {
2584
2597
export function applyFirestoreDataConverter < T > (
2585
2598
converter : UntypedFirestoreDataConverter < T > | null ,
2586
2599
value : T ,
2587
- functionName : string
2588
- ) : [ firestore . DocumentData , string ] {
2600
+ options ?: firestore . SetOptions
2601
+ ) : firestore . DocumentData {
2589
2602
let convertedValue ;
2590
2603
if ( converter ) {
2591
- convertedValue = converter . toFirestore ( value ) ;
2592
- functionName = 'toFirestore() in ' + functionName ;
2604
+ if ( options && ( options . merge || options . mergeFields ) ) {
2605
+ // Cast to `any` in order to satisfy the union type constraint on
2606
+ // toFirestore().
2607
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2608
+ convertedValue = ( converter as any ) . toFirestore ( value , options ) ;
2609
+ } else {
2610
+ convertedValue = converter . toFirestore ( value ) ;
2611
+ }
2593
2612
} else {
2594
2613
convertedValue = value as firestore . DocumentData ;
2595
2614
}
2596
- return [ convertedValue , functionName ] ;
2615
+ return convertedValue ;
2597
2616
}
2598
2617
2599
2618
function contains ( obj : object , key : string ) : obj is { key : unknown } {
0 commit comments