This repository was archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 431
Expand file tree
/
Copy pathfirebase.d.ts
More file actions
1247 lines (1032 loc) · 33.8 KB
/
firebase.d.ts
File metadata and controls
1247 lines (1032 loc) · 33.8 KB
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
export namespace firebase {
/**
* The allowed values for LoginOptions.type.
*/
export enum LoginType {
/**
* No further data is required.
*/
ANONYMOUS,
/**
* This requires you to pass in the 'passwordOptions' as well.
*/
PASSWORD,
/**
* This requires you to add the 'phoneOptions' as well.
*/
PHONE,
/**
* This requires you to pass either an authentication token generated by your backend server
* or the tokenProviderFn function that returns a promise to provide the token (see 'customOptions').
* See: https://firebase.google.com/docs/auth/server
*/
CUSTOM,
/**
* This requires you to setup Facebook Auth in the Firebase console,
* as well as uncommenting the SDK includes in include.gradle (Android) and Podfile (iOS).
* You can pass in an optional 'facebookOptions' object to override the default scopes.
*/
FACEBOOK,
/**
* This requires you to setup Google Sign In in the Firebase console,
* as well as uncommenting the SDK includes in include.gradle (Android) and Podfile (iOS).
* You can pass in an optional 'googleOptions' object to set a 'hostedDomain'.
*/
GOOGLE,
/**
* This requires you to pass in the 'emailLinkOptions' as well.
* Note that 'Firebase Dynamic Links' must be enabled for this login type to work.
*/
EMAIL_LINK,
/**
* Apple
*/
APPLE,
}
export enum LogComplexEventTypeParameter {
STRING,
INT,
FLOAT,
DOUBLE,
LONG,
ARRAY,
BOOLEAN,
}
/**
* The allowed values for QueryOptions.orderBy.type.
*/
export enum QueryOrderByType {
KEY,
VALUE,
CHILD,
PRIORITY,
}
/**
* The allowed values for QueryOptions.range.type.
*/
export enum QueryRangeType {
START_AT,
END_AT,
EQUAL_TO,
}
/**
* The allowed values for QueryOptions.limit.type.
*/
export enum QueryLimitType {
FIRST,
LAST,
}
export enum ServerValue {
/**
* When for instance using setValue you can set a timestamp property to this placeholder value.
* Example:
* updateTs: firebase.ServerValue.TIMESTAMP
*/
TIMESTAMP,
}
export interface MessagingOptions {
/**
* For Messaging, either pass in this callback function here, or use addOnMessageReceivedCallback.
*/
onPushTokenReceivedCallback?: (token: string) => void;
/**
* For Messaging, either pass in this callback function here, or use addOnPushTokenReceivedCallback.
*/
onMessageReceivedCallback?: (message: Message) => void;
/**
* For Messaging (Push Notifications). Whether you want this plugin to automatically display the notifications or just notify the callback.
* Currently used on iOS only. Default true.
*/
showNotifications?: boolean;
/**
* For Messaging (Push Notifications). Whether you want this plugin to always handle the notifications when the app is in foreground.
* Currently used on iOS only. Default false.
*/
showNotificationsWhenInForeground?: boolean;
/**
* Automatically clear the badges on starting.
* Currently used on iOS only. Default true.
*/
autoClearBadge?: boolean;
}
/**
* The options object passed into the init function.
*/
export interface InitOptions extends MessagingOptions {
/**
* Allow the app to send analytics data to Firebase.
* Can also be set later with analytics.setAnalyticsCollectionEnabled.
* Default true.
*/
analyticsCollectionEnabled?: boolean;
/**
* Allow the app to collect Crashlytics data and send it to Firebase.
* Can also be set later with crashlytics.setCrashReportingEnabled.
* Only useful in case it was disabled in AndroidManfifest.xml and/or Info.plist,
* see https://firebase.google.com/docs/crashlytics/customize-crash-reports
*/
crashlyticsCollectionEnabled?: boolean;
/**
* Allow disk persistence. Default true for Firestore, false for regular Firebase DB.
*/
persist?: boolean;
/**
* Get notified when the user is logged in.
*/
onAuthStateChanged?: (data: AuthStateData) => void;
/**
* Attempt to sign out before initializing, useful in case previous
* project token is cached which leads to following type of error:
* "[FirebaseDatabase] Authentication failed: invalid_token ..."
* Default false.
*/
iOSEmulatorFlush?: boolean;
/**
* For Firebase Storage you can pass in something like 'gs://n-plugin-test.appspot.com'
* here so we can cache it. Otherwise pass in the 'bucket' param when using Storage features.
* Can be found in the firebase console.
*/
storageBucket?: string;
/**
* Get notified when a dynamic link was used to launch the app. Alternatively use addOnDynamicLinkReceivedCallback.
* TODO iOS seems to return an object; not a string
*/
onDynamicLinkCallback?: (data: DynamicLinkData) => void;
}
export interface QueryRangeOption {
type: QueryRangeType;
value: any;
}
/**
* The options object passed into the query function.
*/
export interface QueryOptions {
/**
* How you'd like to sort the query result.
*/
orderBy: {
type: QueryOrderByType;
/**
* mandatory when type is QueryOrderByType.CHILD
*/
value?: string;
};
/**
* You can further restrict the returned results by specifying restrictions.
* Need more than one range restriction? Use 'ranges' instead.
*/
range?: QueryRangeOption;
/**
* Same as 'range', but for a 'chain of ranges'.
* You can further restrict the returned results by specifying restrictions.
*/
ranges?: QueryRangeOption[];
/**
* You can limit the number of returned rows if you want to.
*/
limit?: {
type: QueryLimitType;
value: number;
};
/**
* Set this to true if you don't want to listen for any future updates,
* but just want to retrieve the current value.
* You can also use this to check if certain data is in the database.
* Default false.
*/
singleEvent?: boolean;
}
export interface GetAuthTokenOptions {
/**
* Default false.
*/
forceRefresh?: boolean;
}
export interface IdTokenResult {
token: string;
claims: { [key: string]: any };
signInProvider: string;
expirationTime: number;
issuedAtTime: number;
authTime: number;
}
export interface Provider {
id: string;
token?: string;
}
export interface FirebasePasswordLoginOptions {
email: string;
password: string;
}
export interface FirebaseEmailLinkActionCodeSettings {
url: string;
iOS?: {
bundleId: string;
};
android?: {
packageName: string;
installApp?: false;
minimumVersion?: string;
};
}
export interface FirebaseEmailLinkLoginOptions
extends FirebaseEmailLinkActionCodeSettings {
email: string;
}
export interface FirebasePhoneLoginOptions {
phoneNumber: string;
/**
* The message show to the user that prompts him to enter the received verification code.
* Default: "Verification code".
*/
verificationPrompt?: string;
android?: {
/**
* The maximum amount of time you are willing to wait for SMS auto-retrieval to be completed by the library. Maximum allowed value is 2 minutes. Use 0 to disable SMS-auto-retrieval. If you specified a positive value less than 30 seconds, library will default to 30 seconds.
* Default: 60 (seconds)
* See: https://firebase.google.com/docs/reference/android/com/google/firebase/auth/PhoneAuthProvider
*/
timeout: number;
};
}
export interface FirebaseGoogleLoginOptions {
hostedDomain?: string;
/**
* You can add scopes like "https://www.googleapis.com/auth/contacts.readonly" and "https://www.googleapis.com/auth/user.birthday.read"
*
* Default: ["profile", "email"]
*/
scopes?: Array<string>;
}
export interface FirebaseFacebookLoginOptions {
/**
* Default: ["public_profile", "email"]
*/
scopes?: Array<string>;
}
export type AppleLoginScope = "name" | "email";
export interface AppleLoginOptions {
/**
* Default: ["name", "email"]
*/
scopes?: Array<AppleLoginScope>;
/**
* Android only.
* Supported locales: https://developer.apple.com/documentation/signinwithapplejs/incorporating_sign_in_with_apple_into_other_platforms#3332112
* Default: "en".
*/
locale?: string;
}
export interface FirebaseCustomLoginOptions {
/**
* The JSON Web Token (JWT) to use for authentication.
* Either specify this, or 'tokenProviderFn'.
* See: https://firebase.google.com/docs/auth/server
*/
token?: string;
/**
* A function that returns a promise with the JSON Web Token (JWT) to use for authentication.
* Either specify this, or 'token'.
* See: https://firebase.google.com/docs/auth/server
*/
tokenProviderFn?: () => Promise<String>;
}
export interface LoginIOSOptions {
controller?: any;
}
/**
* The options object passed into the login function.
*/
export interface LoginOptions {
type: LoginType;
passwordOptions?: FirebasePasswordLoginOptions;
emailLinkOptions?: FirebaseEmailLinkLoginOptions;
phoneOptions?: FirebasePhoneLoginOptions;
googleOptions?: FirebaseGoogleLoginOptions;
facebookOptions?: FirebaseFacebookLoginOptions;
appleOptions?: AppleLoginOptions;
customOptions?: FirebaseCustomLoginOptions;
ios?: LoginIOSOptions;
/**
* @deprecated Please use the 'passwordOptions?: FirebasePasswordLoginOptions' object instead.
*/
email?: string;
/**
* @deprecated Please use the 'passwordOptions?: FirebasePasswordLoginOptions' object instead.
*/
password?: string;
/**
* @deprecated Please use the 'customOptions?: FirebaseCustomLoginOptions' object instead.
*/
token?: string;
/**
* @deprecated Please use the 'customOptions?: FirebaseCustomLoginOptions' object instead.
*/
tokenProviderFn?: () => Promise<String>;
/**
* @deprecated Please use the 'facebookOptions?: FirebaseFacebookLoginOptions' object instead.
*/
scope?: string[];
}
export interface ReauthenticateOptions {
type: LoginType;
passwordOptions?: FirebasePasswordLoginOptions;
/**
* @deprecated Please use the 'passwordOptions?: FirebasePasswordLoginOptions' object instead.
*/
email?: string;
/**
* @deprecated Please use the 'passwordOptions?: FirebasePasswordLoginOptions' object instead.
*/
password?: string;
}
type ActionCodeSettings = {
url: string;
handleCodeInApp?: boolean;
android?: {
installApp?: boolean;
minimumVersion?: string;
packageName: string;
};
iOS?: {
bundleId: string;
dynamicLinkDomain?: string;
};
};
/**
* The returned object from the login function.
*/
export interface User {
uid: string;
email?: string;
emailVerified: boolean;
displayName?: string;
phoneNumber?: string;
anonymous: boolean;
isAnonymous: boolean; // This is used by the web API
providers: Array<Provider>;
photoURL?: string;
metadata: UserMetadata;
additionalUserInfo?: AdditionalUserInfo;
/** iOS only */
refreshToken?: string;
getIdToken(forceRefresh?: boolean): Promise<string>;
getIdTokenResult(forceRefresh?: boolean): Promise<IdTokenResult>;
sendEmailVerification(
actionCodeSettings?: ActionCodeSettings
): Promise<void>;
}
/**
* The metadata of the user
*/
export interface UserMetadata {
creationTimestamp: Date;
lastSignInTimestamp: Date;
}
/**
* Contains additional user information
*/
export interface AdditionalUserInfo {
profile: Map<string, any>;
providerId: string;
username: string;
isNewUser: boolean;
}
/**
* The returned object from the push function.
*/
export interface PushResult {
key: string;
}
/**
* The returned object from the addEventListener functions.
*/
export interface AddEventListenerResult {
path: string;
listeners: Array<any>;
}
/**
* The options object passed into the createUser function.
*/
export interface CreateUserOptions {
email: string;
password: string;
}
/**
* The options object passed into the updateProfile function.
*/
export interface UpdateProfileOptions {
displayName?: string;
photoURL?: string;
}
/**
* The returned object in the callback handlers
* of the addChildEventListener and addValueEventListener functions.
*/
export interface FBData {
type: string;
key: string;
value: any;
}
export interface FBDataSingleEvent extends FBData {
children?: Array<any>;
}
export interface FBErrorData {
error: string;
}
export interface AuthStateData {
loggedIn?: boolean;
user?: User;
}
export interface AuthStateChangeListener {
onAuthStateChanged: (data: AuthStateData) => void;
thisArg?: any;
}
export interface RemoteConfigProperty {
key: string;
default: any;
}
export interface GetRemoteConfigOptions {
/**
* Fetch new results from the server more often.
* Default false.
*/
developerMode?: boolean;
/**
* The number of seconds before retrieving fresh state from the server.
* Default 12 hours.
*/
cacheExpirationSeconds?: number;
/**
* The configuration properties to retrieve for your app. Specify as:
* properties: [{
* key: "holiday_promo_enabled",
* default: false
* }, ..]
*/
properties: Array<RemoteConfigProperty>;
}
/**
* The returned object from the getRemoteConfig function.
*/
export interface GetRemoteConfigResult {
/**
* The date the data was last refreshed from the server.
* Should honor the 'cacheExpirationSeconds' you passed in previously.
*/
lastFetch: Date;
/**
* The result may be throttled when retrieved from the server.
* Even when the cache has expired. And it's just FYI really.
*/
throttled: boolean;
/**
* A JS Object with properties and values.
* If you previously requested keys ["foo", "is_enabled"] then this will be like:
* properties: {
* foo: "bar",
* is_enabled: true
* }
*/
properties: Object;
}
export interface DynamicLinkData {
url: string;
minimumAppVersion: string;
}
/**
* The returned object in the callback handler of the addOnMessageReceivedCallback function.
*
* Note that any custom data you send from your server will be available as
* key/value properties on the Message object as well.
*/
export interface Message {
/**
* Indicated whether or not the notification was received while the app was in the foreground.
*/
foreground: boolean;
/**
* The main text shown in the notificiation.
* Not available on Android when the notification was received in the background.
*/
body?: string;
/**
* Optional title, shown above the body in the notification.
* Not available on Android when the notification was received in the background.
*/
title?: string;
/**
* Any other data you may have added to the notification.
*/
data: any;
/**
* Indicates whether or not the notification was tapped.
* iOS only.
*/
notificationTapped?: boolean;
}
export function init(options?: InitOptions): Promise<any>;
// Database
export interface OnDisconnect {
cancel(): Promise<any>;
remove(): Promise<any>;
set(value: any): Promise<any>;
setWithPriority(value: any, priority: number | string): Promise<any>;
update(values: Object): Promise<any>;
}
export interface DataSnapshot {
key: string;
ref: any; // TODO: Type it so that it returns a databaseReference.
child(path: string): DataSnapshot;
exists(): boolean;
forEach(action: (snapshot: DataSnapshot) => any): boolean;
getPriority(): string | number | null;
hasChild(path: string): boolean;
hasChildren(): boolean;
numChildren(): number;
toJSON(): Object;
val(): any;
}
export interface FirebaseQueryResult {
type: string;
key: string;
value: any;
}
export type Unsubscribe = () => void;
export namespace dynamicLinks {
export enum MATCH_CONFIDENCE {
WEAK,
STRONG,
}
export interface DynamicLinkCallbackData {
url: string;
matchConfidence?: MATCH_CONFIDENCE;
minimumAppVersion?: string;
}
}
// Auth
export function login(options: LoginOptions): Promise<User>;
export function reauthenticate(options: ReauthenticateOptions): Promise<User>;
export function reloadUser(): Promise<void>;
export function getAuthToken(
option: GetAuthTokenOptions
): Promise<IdTokenResult>;
export function logout(): Promise<any>;
export function unlink(providerId: string): Promise<User>;
export function fetchSignInMethodsForEmail(
email: string
): Promise<Array<string>>;
export function sendEmailVerification(
actionCodeSettings?: ActionCodeSettings
): Promise<any>;
export function createUser(options: CreateUserOptions): Promise<User>;
export function deleteUser(): Promise<any>;
export function updateProfile(options: UpdateProfileOptions): Promise<any>;
export function sendPasswordResetEmail(email: string): Promise<void>;
export function updateEmail(newEmail: string): Promise<void>;
export function updatePassword(newPassword: string): Promise<void>;
export function addAuthStateListener(
listener: AuthStateChangeListener
): boolean;
export function removeAuthStateListener(
listener: AuthStateChangeListener
): boolean;
export function hasAuthStateListener(
listener: AuthStateChangeListener
): boolean;
export function getCurrentUser(): Promise<User>;
// Messaging
export function addOnMessageReceivedCallback(
onMessageReceived: (data: Message) => void
): Promise<any>;
export function addOnPushTokenReceivedCallback(
onPushTokenReceived: (data: string) => void
): Promise<any>;
export function registerForInteractivePush(model: any): void;
export function getCurrentPushToken(): Promise<string>;
export function registerForPushNotifications(
options?: MessagingOptions
): Promise<void>;
export function unregisterForPushNotifications(): Promise<void>;
export function subscribeToTopic(topicName): Promise<any>;
export function unsubscribeFromTopic(topicName): Promise<any>;
export function areNotificationsEnabled(): boolean;
// dynamic links
export function addOnDynamicLinkReceivedCallback(
onDynamicLinkReceived: (
callBackData: dynamicLinks.DynamicLinkCallbackData
) => void
): Promise<any>;
// remote config
export function getRemoteConfig(
options: GetRemoteConfigOptions
): Promise<GetRemoteConfigResult>;
export function transaction(
path: string,
transactionUpdate: (a: any) => any,
onComplete?: (
error: Error | null,
committed: boolean,
dataSnapshot: DataSnapshot
) => any
): Promise<any>;
export function push(path: string, value: any): Promise<PushResult>;
export function getValue(path: string): Promise<any>;
export function setValue(path: string, value: any): Promise<any>;
export function update(path: string, value: any): Promise<any>;
export function remove(path: string): Promise<any>;
export function query(
onValueEvent: (data: FBData | FBErrorData) => void,
path: string,
options: QueryOptions
): Promise<any>;
export function addChildEventListener(
onChildEvent: (data: FBData) => void,
path: string
): Promise<AddEventListenerResult>;
export function addValueEventListener(
onValueEvent: (data: FBData) => void,
path: string
): Promise<AddEventListenerResult>;
export function removeEventListeners(
listeners: Array<any>,
path: string
): Promise<any>;
export function onDisconnect(path: string): OnDisconnect;
export function enableLogging(
logger?: boolean | ((a: string) => any),
persistent?: boolean
);
/**
* Tells the client to keep its local cache in sync with the server automatically.
*/
export function keepInSync(path: string, switchOn: boolean): Promise<any>;
}
export namespace firestore {
export type DocumentData = { [field: string]: any };
export type WhereFilterOp =
| "<"
| "<="
| "=="
| ">="
| ">"
| "in"
| "array-contains"
| "array-contains-any";
export type OrderByDirection = "desc" | "asc";
export interface GeoPoint {
longitude: number;
latitude: number;
}
export function GeoPoint(latitude: number, longitude: number): GeoPoint;
export interface Settings {
/** The hostname to connect to. */
host?: string;
/** Whether to use SSL when connecting. */
ssl?: boolean;
/**
* Specifies whether to use `Timestamp` objects for timestamp fields in
* `DocumentSnapshot`s. This is enabled by default and should not be
* disabled.
*
* Previously, Firestore returned timestamp fields as `Date` but `Date`
* only supports millisecond precision, which leads to truncation and
* causes unexpected behavior when using a timestamp from a snapshot as a
* part of a subsequent query.
*
* So now Firestore returns `Timestamp` values instead of `Date`, avoiding
* this kind of problem.
*
* To opt into the old behavior of returning `Date` objects, you can
* temporarily set `timestampsInSnapshots` to false.
*
* @deprecated This setting will be removed in a future release. You should
* update your code to expect `Timestamp` objects and stop using the
* `timestampsInSnapshots` setting.
*/
timestampsInSnapshots?: boolean;
/**
* An approximate cache size threshold for the on-disk data. If the cache grows beyond this
* size, Firestore will start removing data that hasn't been recently used. The size is not a
* guarantee that the cache will stay below that size, only that if the cache exceeds the given
* size, cleanup will be attempted.
*
* The default value is 40 MB. The threshold must be set to at least 1 MB, and can be set to
* CACHE_SIZE_UNLIMITED to disable garbage collection.
*/
cacheSizeBytes?: number;
}
/**
* Specifies custom settings to be used to configure the `Firestore`
* instance. Must be set before invoking any other methods.
*
* @param settings The settings to use.
*/
export function settings(settings: Settings): void;
export interface SetOptions {
merge?: boolean;
}
export interface SnapshotMetadata {
/**
* True if the snapshot contains the result of local writes (e.g. set() or
* update() calls) that have not yet been committed to the backend.
* If your listener has opted into metadata updates (via
* `DocumentListenOptions` or `QueryListenOptions`) you will receive another
* snapshot with `hasPendingWrites` equal to false once the writes have been
* committed to the backend.
*/
readonly hasPendingWrites: boolean;
/**
* True if the snapshot was created from cached data rather than
* guaranteed up-to-date server data. If your listener has opted into
* metadata updates (via `DocumentListenOptions` or `QueryListenOptions`)
* you will receive another snapshot with `fromCache` equal to false once
* the client has received up-to-date data from the backend.
*/
readonly fromCache: boolean;
}
export interface DocumentSnapshot {
ios?: any;
/* FIRDocumentSnapshot */
android?: any;
/* com.google.firebase.firestore.DocumentSnapshot */
id: string;
exists: boolean;
ref: DocumentReference;
/**
* Included when includeMetadataChanges is true.
*/
readonly metadata?: SnapshotMetadata;
data(): DocumentData;
}
export interface SnapshotListenOptions {
/**
* Include a change even if only the metadata of the query or of a document changed.
* Default false.
*/
readonly includeMetadataChanges?: boolean;
}
export interface GetOptions {
/**
* Describes whether we should get from server or cache.
*
* Setting to 'default' (or not setting at all), causes Firestore to try to
* retrieve an up-to-date (server-retrieved) snapshot, but fall back to
* returning cached data if the server can't be reached.
*
* Setting to 'server' causes Firestore to avoid the cache, generating an
* error if the server cannot be reached. Note that the cache will still be
* updated if the server request succeeds. Also note that latency-compensation
* still takes effect, so any pending write operations will be visible in the
* returned data (merged into the server-provided data).
*
* Setting to 'cache' causes Firestore to immediately return a value from the
* cache, ignoring the server completely (implying that the returned value
* may be stale with respect to the value on the server.) If there is no data
* in the cache to satisfy the `get()` call, `DocumentReference.get()` will
* return an error and `QuerySnapshot.get()` will return an empty
* `QuerySnapshot` with no documents.
*/
source?: "default" | "server" | "cache";
}
export interface DocumentReference {
readonly discriminator: "docRef";
readonly id: string;
/**
* A reference to the Collection to which this DocumentReference belongs.
*/
readonly parent: CollectionReference;
readonly path: string;
readonly firestore: any;
collection: (collectionPath: string) => CollectionReference;
set: (document: any, options?: SetOptions) => Promise<void>;
get: (options?: GetOptions) => Promise<DocumentSnapshot>;
update: (document: any) => Promise<void>;
delete: () => Promise<void>;
onSnapshot(
optionsOrCallback:
| SnapshotListenOptions
| ((snapshot: DocumentSnapshot) => void),
callbackOrOnError?: (snapshot: DocumentSnapshot | Error) => void,
onError?: (error: Error) => void
): () => void;
android?: any;
ios?: any;
}
export interface Query {
readonly firestore: any;
get(options?: GetOptions): Promise<QuerySnapshot>;
where(fieldPath: string, opStr: WhereFilterOp, value: any): Query;
orderBy(
fieldPath: string,
directionStr: firestore.OrderByDirection
): Query;
limit(limit: number): Query;
onSnapshot(
optionsOrCallback:
| SnapshotListenOptions
| ((snapshot: QuerySnapshot) => void),
callbackOrOnError?: (snapshotOrError: QuerySnapshot | Error) => void,
onError?: (error: Error) => void
): () => void;
startAt(snapshot: DocumentSnapshot): Query;
startAt(...fieldValues: any[]): Query;
startAfter(snapshot: DocumentSnapshot): Query;
startAfter(...fieldValues: any[]): Query;
endAt(snapshot: DocumentSnapshot): Query;
endAt(...fieldValues: any[]): Query;
endBefore(snapshot: DocumentSnapshot): Query;