@@ -22,10 +22,10 @@ import { DocumentKey } from '../../../src/model/document_key';
22
22
import { Firestore } from './database' ;
23
23
import {
24
24
DocumentKeyReference ,
25
+ ParsedUpdateData ,
25
26
UserDataReader
26
27
} from '../../../src/api/user_data_reader' ;
27
28
import { Query as InternalQuery } from '../../../src/core/query' ;
28
- import { FirebaseFirestore , FirestoreDataConverter } from '../../index' ;
29
29
import { ResourcePath } from '../../../src/model/path' ;
30
30
import { AutoId } from '../../../src/util/misc' ;
31
31
import { DocumentSnapshot } from './snapshot' ;
@@ -38,6 +38,7 @@ import { DeleteMutation, Precondition } from '../../../src/model/mutation';
38
38
import { PlatformSupport } from '../../../src/platform/platform' ;
39
39
import { applyFirestoreDataConverter } from '../../../src/api/database' ;
40
40
import { DatabaseId } from '../../../src/core/database_info' ;
41
+ import { FieldPath } from './field_path' ;
41
42
import { cast } from './util' ;
42
43
import {
43
44
validateArgType ,
@@ -78,7 +79,7 @@ export class Query<T = firestore.DocumentData> implements firestore.Query<T> {
78
79
constructor (
79
80
readonly firestore : Firestore ,
80
81
readonly _query : InternalQuery ,
81
- readonly _converter ?: FirestoreDataConverter < T >
82
+ readonly _converter ?: firestore . FirestoreDataConverter < T >
82
83
) { }
83
84
84
85
where (
@@ -173,11 +174,11 @@ export class CollectionReference<T = firestore.DocumentData> extends Query<T>
173
174
}
174
175
175
176
export function collection (
176
- firestore : FirebaseFirestore ,
177
+ firestore : firestore . FirebaseFirestore ,
177
178
collectionPath : string
178
179
) : CollectionReference < firestore . DocumentData > ;
179
180
export function collection (
180
- reference : DocumentReference ,
181
+ reference : firestore . DocumentReference ,
181
182
collectionPath : string
182
183
) : CollectionReference < firestore . DocumentData > ;
183
184
export function collection (
@@ -198,11 +199,11 @@ export function collection(
198
199
}
199
200
200
201
export function doc (
201
- firestore : FirebaseFirestore ,
202
+ firestore : firestore . FirebaseFirestore ,
202
203
documentPath : string
203
204
) : DocumentReference < firestore . DocumentData > ;
204
205
export function doc < T > (
205
- reference : CollectionReference < T > ,
206
+ reference : firestore . CollectionReference < T > ,
206
207
documentPath ?: string
207
208
) : DocumentReference < T > ;
208
209
export function doc < T > (
@@ -277,6 +278,15 @@ export function getDoc<T>(
277
278
} ) ;
278
279
}
279
280
281
+ export function setDoc < T > (
282
+ reference : firestore . DocumentReference < T > ,
283
+ data : T
284
+ ) : Promise < void > ;
285
+ export function setDoc < T > (
286
+ reference : firestore . DocumentReference < T > ,
287
+ data : Partial < T > ,
288
+ options : firestore . SetOptions
289
+ ) : Promise < void > ;
280
290
export function setDoc < T > (
281
291
reference : firestore . DocumentReference < T > ,
282
292
data : T ,
@@ -307,6 +317,63 @@ export function setDoc<T>(
307
317
) ;
308
318
}
309
319
320
+ export function updateDoc (
321
+ reference : firestore . DocumentReference ,
322
+ data : firestore . UpdateData
323
+ ) : Promise < void > ;
324
+ export function updateDoc (
325
+ reference : firestore . DocumentReference ,
326
+ field : string | firestore . FieldPath ,
327
+ value : unknown ,
328
+ ...moreFieldsAndValues : unknown [ ]
329
+ ) : Promise < void > ;
330
+ export function updateDoc (
331
+ reference : firestore . DocumentReference ,
332
+ fieldOrUpdateData : string | firestore . FieldPath | firestore . UpdateData ,
333
+ value ?: unknown ,
334
+ ...moreFieldsAndValues : unknown [ ]
335
+ ) : Promise < void > {
336
+ const ref = cast ( reference , DocumentReference ) ;
337
+
338
+ // Kick off configuring the client, which freezes the settings.
339
+ const configureClient = ref . firestore . _ensureClientConfigured ( ) ;
340
+ const dataReader = newUserDataReader (
341
+ ref . firestore . _databaseId ,
342
+ ref . firestore . _settings !
343
+ ) ;
344
+
345
+ let parsed : ParsedUpdateData ;
346
+ if (
347
+ typeof fieldOrUpdateData === 'string' ||
348
+ fieldOrUpdateData instanceof FieldPath
349
+ ) {
350
+ parsed = dataReader . parseUpdateVarargs (
351
+ 'updateDoc' ,
352
+ fieldOrUpdateData ,
353
+ value ,
354
+ moreFieldsAndValues
355
+ ) ;
356
+ } else {
357
+ parsed = dataReader . parseUpdateData ( 'updateDoc' , fieldOrUpdateData ) ;
358
+ }
359
+
360
+ return configureClient . then ( datastore =>
361
+ invokeCommitRpc (
362
+ datastore ,
363
+ parsed . toMutations ( ref . _key , Precondition . none ( ) )
364
+ )
365
+ ) ;
366
+
367
+ return ref . firestore
368
+ . _ensureClientConfigured ( )
369
+ . then ( datastore =>
370
+ invokeCommitRpc (
371
+ datastore ,
372
+ parsed . toMutations ( ref . _key , Precondition . exists ( true ) )
373
+ )
374
+ ) ;
375
+ }
376
+
310
377
export function deleteDoc (
311
378
reference : firestore . DocumentReference
312
379
) : Promise < void > {
0 commit comments