@@ -1112,6 +1112,37 @@ declare namespace firebase.firestore {
1112
1112
readonly merge ?: boolean ;
1113
1113
}
1114
1114
1115
+ /**
1116
+ * An options object that configures the behavior of `get()` calls on
1117
+ * `DocumentReference` and `Query`. By providing a `GetOptions` object, these
1118
+ * methods can be configured to fetch results only from the server, only from
1119
+ * the local cache or attempt to fetch results from the server and fall back to
1120
+ * the cache (which is the default).
1121
+ */
1122
+ export interface GetOptions {
1123
+ /**
1124
+ * Describes whether we should get from server or cache.
1125
+ *
1126
+ * Setting to 'default' (or not setting at all), causes Firestore to try to
1127
+ * retrieve an up-to-date (server-retrieved) snapshot, but fall back to
1128
+ * returning cached data if the server can't be reached.
1129
+ *
1130
+ * Setting to 'server' causes Firestore to avoid the cache, generating an
1131
+ * error if the server cannot be reached. Note that the cache will still be
1132
+ * updated if the server request succeeds. Also note that latency-compensation
1133
+ * still takes effect, so any pending write operations will be visible in the
1134
+ * returned data (merged into the server-provided data).
1135
+ *
1136
+ * Setting to 'cache' causes Firestore to immediately return a value from the
1137
+ * cache, ignoring the server completely (implying that the returned value
1138
+ * may be stale with respect to the value on the server.) If there is no data
1139
+ * in the cache to satisfy the `get()` call, `DocumentReference.get()` will
1140
+ * return an error and `QuerySnapshot.get()` will return an empty
1141
+ * `QuerySnapshot` with no documents.
1142
+ */
1143
+ readonly source ?: 'default' | 'server' | 'cache' ;
1144
+ }
1145
+
1115
1146
/**
1116
1147
* A `DocumentReference` refers to a document location in a Firestore database
1117
1148
* and can be used to write, read, or listen to the location. The document at
@@ -1213,14 +1244,16 @@ declare namespace firebase.firestore {
1213
1244
/**
1214
1245
* Reads the document referred to by this `DocumentReference`.
1215
1246
*
1216
- * Note: get() attempts to provide up-to-date data when possible by waiting
1217
- * for data from the server, but it may return cached data or fail if you
1218
- * are offline and the server cannot be reached.
1247
+ * Note: By default, get() attempts to provide up-to-date data when possible
1248
+ * by waiting for data from the server, but it may return cached data or fail
1249
+ * if you are offline and the server cannot be reached. This behavior can be
1250
+ * altered via the `GetOptions` parameter.
1219
1251
*
1252
+ * @param options An object to configure the get behavior.
1220
1253
* @return A Promise resolved with a DocumentSnapshot containing the
1221
1254
* current document contents.
1222
1255
*/
1223
- get ( ) : Promise < DocumentSnapshot > ;
1256
+ get ( options ?: GetOptions ) : Promise < DocumentSnapshot > ;
1224
1257
1225
1258
/**
1226
1259
* Attaches a listener for DocumentSnapshot events. You may either pass
@@ -1598,9 +1631,15 @@ declare namespace firebase.firestore {
1598
1631
/**
1599
1632
* Executes the query and returns the results as a QuerySnapshot.
1600
1633
*
1634
+ * Note: By default, get() attempts to provide up-to-date data when possible
1635
+ * by waiting for data from the server, but it may return cached data or fail
1636
+ * if you are offline and the server cannot be reached. This behavior can be
1637
+ * altered via the `GetOptions` parameter.
1638
+ *
1639
+ * @param options An object to configure the get behavior.
1601
1640
* @return A Promise that will be resolved with the results of the Query.
1602
1641
*/
1603
- get ( ) : Promise < QuerySnapshot > ;
1642
+ get ( options ?: GetOptions ) : Promise < QuerySnapshot > ;
1604
1643
1605
1644
/**
1606
1645
* Attaches a listener for QuerySnapshot events. You may either pass
0 commit comments