File tree 3 files changed +16
-9
lines changed
3 files changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,9 @@ const ignoredRe = [
43
43
] ;
44
44
45
45
/** If non-empty, list the test cases to run exclusively. */
46
- const exclusiveRe = [ ] ;
46
+ const exclusiveRe = [
47
+ / s e t : M e r g e A l l c a n n o t b e s p e c i f i e d w i t h e m p t y d a t a ./ , // b/73495873
48
+ ] ;
47
49
48
50
const docRef = function ( path ) {
49
51
const relativePath = ResourcePath . fromSlashSeparatedString ( path ) . relativeName ;
Original file line number Diff line number Diff line change @@ -280,7 +280,7 @@ class WriteBatch {
280
280
281
281
validate . isDocumentReference ( 'documentRef' , documentRef ) ;
282
282
validate . isDocument ( 'data' , data , {
283
- allowEmpty : ! merge ,
283
+ allowEmpty : true ,
284
284
allowDeletes : merge ? 'all' : 'none' ,
285
285
allowServerTimestamps : true ,
286
286
} ) ;
@@ -292,11 +292,13 @@ class WriteBatch {
292
292
const transform = DocumentTransform . fromObject ( documentRef , data ) ;
293
293
const documentMask = DocumentMask . fromObject ( data ) ;
294
294
295
+ const hasDocumentData = ! document . isEmpty || ! documentMask . isEmpty ;
296
+
295
297
let write ;
296
298
297
299
if ( ! merge ) {
298
300
write = document . toProto ( ) ;
299
- } else if ( ! document . isEmpty || ! documentMask . isEmpty ) {
301
+ } else if ( hasDocumentData || transform . isEmpty ) {
300
302
write = document . toProto ( ) ;
301
303
write . updateMask = documentMask . toProto ( ) ;
302
304
}
Original file line number Diff line number Diff line change @@ -979,6 +979,15 @@ describe('set document', function() {
979
979
) ;
980
980
} ) ;
981
981
982
+ it ( 'supports empty merge' , function ( ) {
983
+ firestore . api . Firestore . _commit = function ( request , options , callback ) {
984
+ requestEquals ( request , set ( document ( ) , updateMask ( ) ) ) ;
985
+ callback ( null , writeResult ( 1 ) ) ;
986
+ } ;
987
+
988
+ return firestore . doc ( 'collectionId/documentId' ) . set ( { } , { merge : true } ) ;
989
+ } ) ;
990
+
982
991
it ( 'supports nested empty merge' , function ( ) {
983
992
firestore . api . Firestore . _commit = function ( request , options , callback ) {
984
993
requestEquals (
@@ -1030,12 +1039,6 @@ describe('set document', function() {
1030
1039
} , / F i e l d V a l u e .d e l e t e \( \) m u s t a p p e a r a t t h e t o p - l e v e l a n d c a n o n l y b e u s e d i n u p d a t e \( \) o r s e t \( \) w i t h { merge:t r u e } ./ ) ;
1031
1040
} ) ;
1032
1041
1033
- it ( 'rejects empty merges' , function ( ) {
1034
- assert . throws ( ( ) => {
1035
- firestore . doc ( 'collectionId/documentId' ) . set ( { } , { merge : true } ) ;
1036
- } , / A t l e a s t o n e f i e l d m u s t b e u p d a t e d ./ ) ;
1037
- } ) ;
1038
-
1039
1042
it ( "doesn't accept arrays" , function ( ) {
1040
1043
assert . throws ( ( ) => {
1041
1044
firestore . doc ( 'collectionId/documentId' ) . set ( [ 42 ] ) ;
You can’t perform that action at this time.
0 commit comments