/
firestore.d.ts
1357 lines (1213 loc) · 48.4 KB
/
firestore.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @fileoverview Firestore Server API.
*
* Copyright 2017 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// tslint:disable
// Declare a global (ambient) namespace
// (used when not using import statement, but just script include).
declare namespace FirebaseFirestore {
/**
* Document data (for use with `DocumentReference.set()`) consists of fields
* mapped to values.
*/
export type DocumentData = {[field: string]: any};
/**
* Update data (for use with `DocumentReference.update()`) consists of field
* paths (e.g. 'foo' or 'foo.baz') mapped to values. Fields that contain dots
* reference nested fields within the document.
*/
export type UpdateData = {[fieldPath: string]: any};
/**
* Sets the log function for all active Firestore instances.
*/
function setLogFunction(logger: (msg:string) => void): void;
/**
* Settings used to directly configure a `Firestore` instance.
*/
export interface Settings {
/**
* The project ID from the Google Developer's Console, e.g.
* 'grape-spaceship-123'. We will also check the environment variable
* GCLOUD_PROJECT for your project ID. Can be omitted in environments that
* support {@link https://cloud.google.com/docs/authentication Application
* Default Credentials}
*/
projectId?: string;
/** The hostname to connect to. */
host?: string;
/** The port to connect to. */
port?: number;
/**
* Local file containing the Service Account credentials as downloaded from
* the Google Developers Console. Can be omitted in environments that
* support {@link https://cloud.google.com/docs/authentication Application
* Default Credentials}. To configure Firestore with custom credentials, use
* the `credentials` property to provide the `client_email` and
* `private_key` of your service account.
*/
keyFilename?: string;
/**
* The 'client_email' and 'private_key' properties of the service account
* to use with your Firestore project. Can be omitted in environments that
* support {@link https://cloud.google.com/docs/authentication Application
* Default Credentials}. If your credentials are stored in a JSON file, you
* can specify a `keyFilename` instead.
*/
credentials?: {client_email?:string, private_key?:string};
/** Whether to use SSL when connecting. */
ssl?: boolean;
[key: string]: any; // Accept other properties, such as GRPC settings.
}
/**
* `Firestore` represents a Firestore Database and is the entry point for all
* Firestore operations.
*/
export class Firestore {
/**
* @param settings Configuration object. See [Firestore Documentation]
* {@link https://firebase.google.com/docs/firestore/}
*/
public constructor(settings?: Settings);
/**
* Specifies custom settings to be used to configure the `Firestore`
* instance. Can only be invoked once and before any other Firestore
* method.
*
* If settings are provided via both `settings()` and the `Firestore`
* constructor, both settings objects are merged and any settings provided
* via `settings()` take precedence.
*
* @param {object} settings The settings to use for all Firestore
* operations.
*/
settings(settings: Settings): void;
/**
* Gets a `CollectionReference` instance that refers to the collection at
* the specified path.
*
* @param collectionPath A slash-separated path to a collection.
* @return The `CollectionReference` instance.
*/
collection(collectionPath: string): CollectionReference;
/**
* Gets a `DocumentReference` instance that refers to the document at the
* specified path.
*
* @param documentPath A slash-separated path to a document.
* @return The `DocumentReference` instance.
*/
doc(documentPath: string): DocumentReference;
/**
* Creates and returns a new Query that includes all documents in the
* database that are contained in a collection or subcollection with the
* given collectionId.
*
* @param collectionId Identifies the collections to query over. Every
* collection or subcollection with this ID as the last segment of its path
* will be included. Cannot contain a slash.
* @return The created Query.
*/
collectionGroup(collectionId: string): Query;
/**
* Retrieves multiple documents from Firestore.
*
* The first argument is required and must be of type `DocumentReference`
* followed by any additional `DocumentReference` documents. If used, the
* optional `ReadOptions` must be the last argument.
*
* @param {Array.<DocumentReference|ReadOptions>} documentRefsOrReadOptions
* The `DocumentReferences` to receive, followed by an optional field
* mask.
* @return A Promise that resolves with an array of resulting document
* snapshots.
*/
getAll(...documentRefsOrReadOptions: Array<DocumentReference|ReadOptions>):
Promise<DocumentSnapshot[]>;
/**
* Terminates the Firestore client and closes all open streams.
*
* @return A Promise that resolves when the client is terminated.
*/
terminate(): Promise<void>;
/**
* Fetches the root collections that are associated with this Firestore
* database.
*
* @returns A Promise that resolves with an array of CollectionReferences.
*/
listCollections() : Promise<CollectionReference[]>;
/**
* Executes the given updateFunction and commits the changes applied within
* the transaction.
*
* You can use the transaction object passed to 'updateFunction' to read and
* modify Firestore documents under lock. Transactions are committed once
* 'updateFunction' resolves and attempted up to five times on failure.
*
* @param updateFunction The function to execute within the transaction
* context.
* @param {object=} transactionOptions Transaction options.
* @param {number=} transactionOptions.maxAttempts The maximum number of
* attempts for this transaction.
* @return If the transaction completed successfully or was explicitly
* aborted (by the updateFunction returning a failed Promise), the Promise
* returned by the updateFunction will be returned here. Else if the
* transaction failed, a rejected Promise with the corresponding failure
* error will be returned.
*/
runTransaction<T>(
updateFunction: (transaction: Transaction) => Promise<T>,
transactionOptions?:{maxAttempts?: number}
): Promise<T>;
/**
* Creates a write batch, used for performing multiple writes as a single
* atomic operation.
*/
batch(): WriteBatch;
}
/**
* An immutable object representing a geo point in Firestore. The geo point
* is represented as latitude/longitude pair.
*
* Latitude values are in the range of [-90, 90].
* Longitude values are in the range of [-180, 180].
*/
export class GeoPoint {
/**
* Creates a new immutable GeoPoint object with the provided latitude and
* longitude values.
* @param latitude The latitude as number between -90 and 90.
* @param longitude The longitude as number between -180 and 180.
*/
constructor(latitude: number, longitude: number);
readonly latitude: number;
readonly longitude: number;
/**
* Returns true if this `GeoPoint` is equal to the provided one.
*
* @param other The `GeoPoint` to compare against.
* @return true if this `GeoPoint` is equal to the provided one.
*/
isEqual(other: GeoPoint): boolean;
}
/**
* A reference to a transaction.
* The `Transaction` object passed to a transaction's updateFunction provides
* the methods to read and write data within the transaction context. See
* `Firestore.runTransaction()`.
*/
export class Transaction {
private constructor();
/**
* Retrieves a query result. Holds a pessimistic lock on all returned
* documents.
*
* @param query A query to execute.
* @return A QuerySnapshot for the retrieved data.
*/
get(query: Query): Promise<QuerySnapshot>;
/**
* Reads the document referenced by the provided `DocumentReference.`
* Holds a pessimistic lock on the returned document.
*
* @param documentRef A reference to the document to be read.
* @return A DocumentSnapshot for the read data.
*/
get(documentRef: DocumentReference): Promise<DocumentSnapshot>;
/**
* Retrieves multiple documents from Firestore. Holds a pessimistic lock on
* all returned documents.
*
* The first argument is required and must be of type `DocumentReference`
* followed by any additional `DocumentReference` documents. If used, the
* optional `ReadOptions` must be the last argument.
*
* @param {Array.<DocumentReference|ReadOptions>} documentRefsOrReadOptions
* The `DocumentReferences` to receive, followed by an optional field
* mask.
* @return A Promise that resolves with an array of resulting document
* snapshots.
*/
getAll(...documentRefsOrReadOptions: Array<DocumentReference|ReadOptions>):
Promise<DocumentSnapshot[]>;
/**
* Create the document referred to by the provided `DocumentReference`.
* The operation will fail the transaction if a document exists at the
* specified location.
*
* @param documentRef A reference to the document to be create.
* @param data The object data to serialize as the document.
* @return This `Transaction` instance. Used for chaining method calls.
*/
create(documentRef: DocumentReference, data: DocumentData): Transaction;
/**
* Writes to the document referred to by the provided `DocumentReference`.
* If the document does not exist yet, it will be created. If you pass
* `SetOptions`, the provided data can be merged into the existing document.
*
* @param documentRef A reference to the document to be set.
* @param data An object of the fields and values for the document.
* @param options An object to configure the set behavior.
* @return This `Transaction` instance. Used for chaining method calls.
*/
set(documentRef: DocumentReference, data: DocumentData,
options?: SetOptions): Transaction;
/**
* Updates fields in the document referred to by the provided
* `DocumentReference`. The update will fail if applied to a document that
* does not exist.
*
* Nested fields can be updated by providing dot-separated field path
* strings.
*
* @param documentRef A reference to the document to be updated.
* @param data An object containing the fields and values with which to
* update the document.
* @param precondition A Precondition to enforce on this update.
* @return This `Transaction` instance. Used for chaining method calls.
*/
update(documentRef: DocumentReference, data: UpdateData,
precondition?: Precondition): Transaction;
/**
* Updates fields in the document referred to by the provided
* `DocumentReference`. The update will fail if applied to a document that
* does not exist.
*
* Nested fields can be updated by providing dot-separated field path
* strings or by providing FieldPath objects.
*
* A `Precondition` restricting this update can be specified as the last
* argument.
*
* @param documentRef A reference to the document to be updated.
* @param field The first field to update.
* @param value The first value
* @param fieldsOrPrecondition An alternating list of field paths and values
* to update, optionally followed by a `Precondition` to enforce on this
* update.
* @return This `Transaction` instance. Used for chaining method calls.
*/
update(documentRef: DocumentReference, field: string|FieldPath, value:any,
...fieldsOrPrecondition: any[]): Transaction;
/**
* Deletes the document referred to by the provided `DocumentReference`.
*
* @param documentRef A reference to the document to be deleted.
* @param precondition A Precondition to enforce for this delete.
* @return This `Transaction` instance. Used for chaining method calls.
*/
delete(documentRef: DocumentReference,
precondition?: Precondition): Transaction;
}
/**
* A write batch, used to perform multiple writes as a single atomic unit.
*
* A `WriteBatch` object can be acquired by calling `Firestore.batch()`. It
* provides methods for adding writes to the write batch. None of the
* writes will be committed (or visible locally) until `WriteBatch.commit()`
* is called.
*
* Unlike transactions, write batches are persisted offline and therefore are
* preferable when you don't need to condition your writes on read data.
*/
export class WriteBatch {
private constructor();
/**
* Create the document referred to by the provided `DocumentReference`. The
* operation will fail the batch if a document exists at the specified
* location.
*
* @param documentRef A reference to the document to be created.
* @param data The object data to serialize as the document.
* @return This `WriteBatch` instance. Used for chaining method calls.
*/
create(documentRef: DocumentReference, data: DocumentData): WriteBatch;
/**
* Write to the document referred to by the provided `DocumentReference`.
* If the document does not exist yet, it will be created. If you pass
* `SetOptions`, the provided data can be merged into the existing document.
*
* @param documentRef A reference to the document to be set.
* @param data An object of the fields and values for the document.
* @param options An object to configure the set behavior.
* @return This `WriteBatch` instance. Used for chaining method calls.
*/
set(documentRef: DocumentReference, data: DocumentData,
options?: SetOptions): WriteBatch;
/**
* Update fields of the document referred to by the provided
* `DocumentReference`. If the document doesn't yet exist, the update fails
* and the entire batch will be rejected.
*
* Nested fields can be updated by providing dot-separated field path
* strings.
*
* @param documentRef A reference to the document to be updated.
* @param data An object containing the fields and values with which to
* update the document.
* @param precondition A Precondition to enforce on this update.
* @return This `WriteBatch` instance. Used for chaining method calls.
*/
update(documentRef: DocumentReference, data: UpdateData,
precondition?: Precondition): WriteBatch;
/**
* Updates fields in the document referred to by the provided
* `DocumentReference`. The update will fail if applied to a document that
* does not exist.
*
* Nested fields can be updated by providing dot-separated field path
* strings or by providing FieldPath objects.
*
* A `Precondition` restricting this update can be specified as the last
* argument.
*
* @param documentRef A reference to the document to be updated.
* @param field The first field to update.
* @param value The first value
* @param fieldsOrPrecondition An alternating list of field paths and values
* to update, optionally followed a `Precondition` to enforce on this update.
* @return This `WriteBatch` instance. Used for chaining method calls.
*/
update(documentRef: DocumentReference, field: string|FieldPath, value:any,
...fieldsOrPrecondition: any[]): WriteBatch;
/**
* Deletes the document referred to by the provided `DocumentReference`.
*
* @param documentRef A reference to the document to be deleted.
* @param precondition A Precondition to enforce for this delete.
* @return This `WriteBatch` instance. Used for chaining method calls.
*/
delete(documentRef: DocumentReference,
precondition?: Precondition): WriteBatch;
/**
* Commits all of the writes in this write batch as a single atomic unit.
*
* @return A Promise resolved once all of the writes in the batch have been
* successfully written to the backend as an atomic unit.
*/
commit(): Promise<WriteResult[]>;
}
/**
* An options object that configures conditional behavior of `update()` and
* `delete()` calls in `DocumentReference`, `WriteBatch`, and `Transaction`.
* Using Preconditions, these calls can be restricted to only apply to
* documents that match the specified restrictions.
*/
export interface Precondition {
/**
* If set, the last update time to enforce.
*/
readonly lastUpdateTime?: Timestamp;
}
/**
* An options object that configures the behavior of `set()` calls in
* `DocumentReference`, `WriteBatch` and `Transaction`. These calls can be
* configured to perform granular merges instead of overwriting the target
* documents in their entirety.
*/
export interface SetOptions {
/**
* Changes the behavior of a set() call to only replace the values specified
* in its data argument. Fields omitted from the set() call remain
* untouched.
*/
readonly merge?: boolean;
/**
* Changes the behavior of set() calls to only replace the specified field
* paths. Any field path that is not specified is ignored and remains
* untouched.
*
* It is an error to pass a SetOptions object to a set() call that is
* missing a value for any of the fields specified here.
*/
readonly mergeFields?: (string|FieldPath)[];
}
/**
* An options object that can be used to configure the behavior of `getAll()`
* calls. By providing a `fieldMask`, these calls can be configured to only
* return a subset of fields.
*/
export interface ReadOptions {
/**
* Specifies the set of fields to return and reduces the amount of data
* transmitted by the backend.
*
* Adding a field mask does not filter results. Documents do not need to
* contain values for all the fields in the mask to be part of the result
* set.
*/
readonly fieldMask?: (string|FieldPath)[];
}
/**
* A WriteResult wraps the write time set by the Firestore servers on `sets()`,
* `updates()`, and `creates()`.
*/
export class WriteResult {
private constructor();
/**
* The write time as set by the Firestore servers.
*/
readonly writeTime: Timestamp;
/**
* Returns true if this `WriteResult` is equal to the provided one.
*
* @param other The `WriteResult` to compare against.
* @return true if this `WriteResult` is equal to the provided one.
*/
isEqual(other: WriteResult): boolean;
}
/**
* A `DocumentReference` refers to a document location in a Firestore database
* and can be used to write, read, or listen to the location. The document at
* the referenced location may or may not exist. A `DocumentReference` can
* also be used to create a `CollectionReference` to a subcollection.
*/
export class DocumentReference {
private constructor();
/** The identifier of the document within its collection. */
readonly id: string;
/**
* The `Firestore` for the Firestore database (useful for performing
* transactions, etc.).
*/
readonly firestore: Firestore;
/**
* A reference to the Collection to which this DocumentReference belongs.
*/
readonly parent: CollectionReference;
/**
* A string representing the path of the referenced document (relative
* to the root of the database).
*/
readonly path: string;
/**
* Gets a `CollectionReference` instance that refers to the collection at
* the specified path.
*
* @param collectionPath A slash-separated path to a collection.
* @return The `CollectionReference` instance.
*/
collection(collectionPath: string): CollectionReference;
/**
* Fetches the subcollections that are direct children of this document.
*
* @returns A Promise that resolves with an array of CollectionReferences.
*/
listCollections() : Promise<CollectionReference[]>;
/**
* Creates a document referred to by this `DocumentReference` with the
* provided object values. The write fails if the document already exists
*
* @param data The object data to serialize as the document.
* @return A Promise resolved with the write time of this create.
*/
create(data: DocumentData): Promise<WriteResult>;
/**
* Writes to the document referred to by this `DocumentReference`. If the
* document does not yet exist, it will be created. If you pass
* `SetOptions`, the provided data can be merged into an existing document.
*
* @param data A map of the fields and values for the document.
* @param options An object to configure the set behavior.
* @return A Promise resolved with the write time of this set.
*/
set(data: DocumentData, options?: SetOptions): Promise<WriteResult>;
/**
* Updates fields in the document referred to by this `DocumentReference`.
* The update will fail if applied to a document that does not exist.
*
* Nested fields can be updated by providing dot-separated field path
* strings.
*
* @param data An object containing the fields and values with which to
* update the document.
* @param precondition A Precondition to enforce on this update.
* @return A Promise resolved with the write time of this update.
*/
update(data: UpdateData, precondition?: Precondition): Promise<WriteResult>;
/**
* Updates fields in the document referred to by this `DocumentReference`.
* The update will fail if applied to a document that does not exist.
*
* Nested fields can be updated by providing dot-separated field path
* strings or by providing FieldPath objects.
*
* A `Precondition` restricting this update can be specified as the last
* argument.
*
* @param field The first field to update.
* @param value The first value.
* @param moreFieldsOrPrecondition An alternating list of field paths and
* values to update, optionally followed by a `Precondition` to enforce on
* this update.
* @return A Promise resolved with the write time of this update.
*/
update(field: string|FieldPath, value:any,
...moreFieldsOrPrecondition: any[]): Promise<WriteResult>;
/**
* Deletes the document referred to by this `DocumentReference`.
*
* @param precondition A Precondition to enforce for this delete.
* @return A Promise resolved with the write time of this delete.
*/
delete(precondition?:Precondition): Promise<WriteResult>;
/**
* Reads the document referred to by this `DocumentReference`.
*
* @return A Promise resolved with a DocumentSnapshot containing the
* current document contents.
*/
get(): Promise<DocumentSnapshot>;
/**
* Attaches a listener for DocumentSnapshot events.
*
* @param onNext A callback to be called every time a new `DocumentSnapshot`
* is available.
* @param onError A callback to be called if the listen fails or is
* cancelled. No further callbacks will occur.
* @return An unsubscribe function that can be called to cancel
* the snapshot listener.
*/
onSnapshot(onNext: (snapshot: DocumentSnapshot) => void,
onError?: (error: Error) => void): () => void;
/**
* Returns true if this `DocumentReference` is equal to the provided one.
*
* @param other The `DocumentReference` to compare against.
* @return true if this `DocumentReference` is equal to the provided one.
*/
isEqual(other: DocumentReference): boolean;
}
/**
* A `DocumentSnapshot` contains data read from a document in your Firestore
* database. The data can be extracted with `.data()` or `.get(<field>)` to
* get a specific field.
*
* For a `DocumentSnapshot` that points to a non-existing document, any data
* access will return 'undefined'. You can use the `exists` property to
* explicitly verify a document's existence.
*/
export class DocumentSnapshot {
protected constructor();
/** True if the document exists. */
readonly exists: boolean;
/** A `DocumentReference` to the document location. */
readonly ref: DocumentReference;
/**
* The ID of the document for which this `DocumentSnapshot` contains data.
*/
readonly id: string;
/**
* The time the document was created. Not set for documents that don't
* exist.
*/
readonly createTime?: Timestamp;
/**
* The time the document was last updated (at the time the snapshot was
* generated). Not set for documents that don't exist.
*/
readonly updateTime?: Timestamp;
/**
* The time this snapshot was read.
*/
readonly readTime: Timestamp;
/**
* Retrieves all fields in the document as an Object. Returns 'undefined' if
* the document doesn't exist.
*
* @return An Object containing all fields in the document.
*/
data(): DocumentData | undefined;
/**
* Retrieves the field specified by `fieldPath`.
*
* @param fieldPath The path (e.g. 'foo' or 'foo.bar') to a specific field.
* @return The data at the specified field location or undefined if no such
* field exists in the document.
*/
get(fieldPath: string|FieldPath): any;
/**
* Returns true if the document's data and path in this `DocumentSnapshot`
* is equal to the provided one.
*
* @param other The `DocumentSnapshot` to compare against.
* @return true if this `DocumentSnapshot` is equal to the provided one.
*/
isEqual(other: DocumentSnapshot): boolean;
}
/**
* A `QueryDocumentSnapshot` contains data read from a document in your
* Firestore database as part of a query. The document is guaranteed to exist
* and its data can be extracted with `.data()` or `.get(<field>)` to get a
* specific field.
*
* A `QueryDocumentSnapshot` offers the same API surface as a
* `DocumentSnapshot`. Since query results contain only existing documents, the
* `exists` property will always be true and `data()` will never return
* 'undefined'.
*/
export class QueryDocumentSnapshot extends DocumentSnapshot {
private constructor();
/**
* The time the document was created.
*/
readonly createTime: Timestamp;
/**
* The time the document was last updated (at the time the snapshot was
* generated).
*/
readonly updateTime: Timestamp;
/**
* Retrieves all fields in the document as an Object.
*
* @override
* @return An Object containing all fields in the document.
*/
data(): DocumentData;
}
/**
* The direction of a `Query.orderBy()` clause is specified as 'desc' or 'asc'
* (descending or ascending).
*/
export type OrderByDirection = 'desc' | 'asc';
/**
* Filter conditions in a `Query.where()` clause are specified using the
* strings '<', '<=', '==', '>=', '>', 'array-contains', 'in', and
* 'array-contains-any'.
*/
export type WhereFilterOp = '<' | '<=' | '==' | '>=' | '>' | 'array-contains' |
'in' | 'array-contains-any';
/**
* A `Query` refers to a Query which you can read or listen to. You can also
* construct refined `Query` objects by adding filters and ordering.
*/
export class Query {
protected constructor();
/**
* The `Firestore` for the Firestore database (useful for performing
* transactions, etc.).
*/
readonly firestore: Firestore;
/**
* Creates and returns a new Query with the additional filter that documents
* must contain the specified field and that its value should satisfy the
* relation constraint provided.
*
* This function returns a new (immutable) instance of the Query (rather
* than modify the existing instance) to impose the filter.
*
* @param fieldPath The path to compare
* @param opStr The operation string (e.g "<", "<=", "==", ">", ">=").
* @param value The value for comparison
* @return The created Query.
*/
where(fieldPath: string|FieldPath, opStr: WhereFilterOp, value: any): Query;
/**
* Creates and returns a new Query that's additionally sorted by the
* specified field, optionally in descending order instead of ascending.
*
* This function returns a new (immutable) instance of the Query (rather
* than modify the existing instance) to impose the order.
*
* @param fieldPath The field to sort by.
* @param directionStr Optional direction to sort by ('asc' or 'desc'). If
* not specified, order will be ascending.
* @return The created Query.
*/
orderBy(
fieldPath: string|FieldPath, directionStr?: OrderByDirection
): Query;
/**
* Creates and returns a new Query that's additionally limited to only
* return up to the specified number of documents.
*
* This function returns a new (immutable) instance of the Query (rather
* than modify the existing instance) to impose the limit.
*
* @param limit The maximum number of items to return.
* @return The created Query.
*/
limit(limit: number): Query;
/**
* Specifies the offset of the returned results.
*
* This function returns a new (immutable) instance of the Query (rather
* than modify the existing instance) to impose the offset.
*
* @param offset The offset to apply to the Query results.
* @return The created Query.
*/
offset(offset: number): Query;
/**
* Creates and returns a new Query instance that applies a field mask to
* the result and returns only the specified subset of fields. You can
* specify a list of field paths to return, or use an empty list to only
* return the references of matching documents.
*
* This function returns a new (immutable) instance of the Query (rather
* than modify the existing instance) to impose the field mask.
*
* @param field The field paths to return.
* @return The created Query.
*/
select(...field: (string | FieldPath)[]): Query;
/**
* Creates and returns a new Query that starts at the provided document
* (inclusive). The starting position is relative to the order of the query.
* The document must contain all of the fields provided in the orderBy of
* this query.
*
* @param snapshot The snapshot of the document to start after.
* @return The created Query.
*/
startAt(snapshot: DocumentSnapshot): Query;
/**
* Creates and returns a new Query that starts at the provided fields
* relative to the order of the query. The order of the field values
* must match the order of the order by clauses of the query.
*
* @param fieldValues The field values to start this query at, in order
* of the query's order by.
* @return The created Query.
*/
startAt(...fieldValues: any[]): Query;
/**
* Creates and returns a new Query that starts after the provided document
* (exclusive). The starting position is relative to the order of the query.
* The document must contain all of the fields provided in the orderBy of
* this query.
*
* @param snapshot The snapshot of the document to start after.
* @return The created Query.
*/
startAfter(snapshot: DocumentSnapshot): Query;
/**
* Creates and returns a new Query that starts after the provided fields
* relative to the order of the query. The order of the field values
* must match the order of the order by clauses of the query.
*
* @param fieldValues The field values to start this query after, in order
* of the query's order by.
* @return The created Query.
*/
startAfter(...fieldValues: any[]): Query;
/**
* Creates and returns a new Query that ends before the provided document
* (exclusive). The end position is relative to the order of the query. The
* document must contain all of the fields provided in the orderBy of this
* query.
*
* @param snapshot The snapshot of the document to end before.
* @return The created Query.
*/
endBefore(snapshot: DocumentSnapshot): Query;
/**
* Creates and returns a new Query that ends before the provided fields
* relative to the order of the query. The order of the field values
* must match the order of the order by clauses of the query.
*
* @param fieldValues The field values to end this query before, in order
* of the query's order by.
* @return The created Query.
*/
endBefore(...fieldValues: any[]): Query;
/**
* Creates and returns a new Query that ends at the provided document
* (inclusive). The end position is relative to the order of the query. The
* document must contain all of the fields provided in the orderBy of this
* query.
*
* @param snapshot The snapshot of the document to end at.
* @return The created Query.
*/
endAt(snapshot: DocumentSnapshot): Query;
/**
* Creates and returns a new Query that ends at the provided fields
* relative to the order of the query. The order of the field values
* must match the order of the order by clauses of the query.
*
* @param fieldValues The field values to end this query at, in order
* of the query's order by.
* @return The created Query.
*/
endAt(...fieldValues: any[]): Query;
/**
* Executes the query and returns the results as a `QuerySnapshot`.
*
* @return A Promise that will be resolved with the results of the Query.
*/
get(): Promise<QuerySnapshot>;
/*
* Executes the query and returns the results as Node Stream.
*
* @return A stream of QueryDocumentSnapshot.
*/
stream(): NodeJS.ReadableStream;
/**
* Attaches a listener for `QuerySnapshot `events.
*
* @param onNext A callback to be called every time a new `QuerySnapshot`
* is available.
* @param onError A callback to be called if the listen fails or is
* cancelled. No further callbacks will occur.
* @return An unsubscribe function that can be called to cancel
* the snapshot listener.
*/
onSnapshot(onNext: (snapshot: QuerySnapshot) => void,
onError?: (error: Error) => void) : () => void;
/**
* Returns true if this `Query` is equal to the provided one.
*
* @param other The `Query` to compare against.
* @return true if this `Query` is equal to the provided one.
*/
isEqual(other: Query): boolean;
}
/**
* A `QuerySnapshot` contains zero or more `QueryDocumentSnapshot` objects
* representing the results of a query. The documents can be accessed as an
* array via the `docs` property or enumerated using the `forEach` method. The
* number of documents can be determined via the `empty` and `size`
* properties.
*/
export class QuerySnapshot {
private constructor();
/**
* The query on which you called `get` or `onSnapshot` in order to get this
* `QuerySnapshot`.
*/
readonly query: Query;
/** An array of all the documents in the QuerySnapshot. */
readonly docs: QueryDocumentSnapshot[];
/** The number of documents in the QuerySnapshot. */
readonly size: number;
/** True if there are no documents in the QuerySnapshot. */