react-native-firebase / firestore/lib/modular
firestore/lib/modular
AggregateField
Defined in: firestore/lib/modular/index.d.ts:1285
Represents an aggregation that can be performed by Firestore.
Constructor
new AggregateField<
T>(aggregateType?,_internalFieldPath?):AggregateField<T>
Defined in: firestore/lib/modular/index.d.ts:1298
Internal
Create a new AggregateField<T>
_internalFieldPath?
readonlyoptional_internalFieldPath:any
Defined in: firestore/lib/modular/index.d.ts:1300
Optionally specifies the field that is aggregated.
aggregateType
readonlyaggregateType:AggregateType
Defined in: firestore/lib/modular/index.d.ts:1290
Indicates the aggregation operation of this AggregateField.
type
readonlytype:"AggregateField"='AggregateField'
Defined in: firestore/lib/modular/index.d.ts:1287
A type string to uniquely identify instances of this class.
Transaction
Defined in: firestore/lib/modular/index.d.ts:663
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
runTransaction.
Constructor
new Transaction():
Transaction
delete()
delete<
AppModelType,DbModelType>(documentRef):this
Defined in: firestore/lib/modular/index.d.ts:754
Deletes the document referred to by the provided DocumentReference.
DbModelType
DbModelType extends DocumentData
documentRef
DocumentReference<AppModelType, DbModelType>
A reference to the document to be deleted.
get()
get<
AppModelType,DbModelType>(documentRef):Promise<DocumentSnapshot<AppModelType,DbModelType>>
Defined in: firestore/lib/modular/index.d.ts:670
Reads the document referenced by the provided DocumentReference.
DbModelType
DbModelType extends DocumentData
documentRef
DocumentReference<AppModelType, DbModelType>
A reference to the document to be read.
Call Signature
set<
AppModelType,DbModelType>(documentRef,data):this
Defined in: firestore/lib/modular/index.d.ts:683
Writes to the document referred to by the provided DocumentReference. If the document does not exist yet, it will be created.
DbModelType
DbModelType extends DocumentData
documentRef
DocumentReference<AppModelType, DbModelType>
A reference to the document to be set.
data
WithFieldValue<AppModelType>
An object of the fields and values for the document.
Call Signature
set<
AppModelType,DbModelType>(documentRef,data,options):this
Defined in: firestore/lib/modular/index.d.ts:699
Writes to the document referred to by the provided DocumentReference. If the document does not exist yet, it will be created.
If you provide merge or mergeFields, the provided data can be merged
into an existing document.
DbModelType
DbModelType extends DocumentData
documentRef
DocumentReference<AppModelType, DbModelType>
A reference to the document to be set.
data
PartialWithFieldValue<AppModelType>
An object of the fields and values for the document.
Call Signature
update<
AppModelType,DbModelType>(documentRef,data):this
Defined in: firestore/lib/modular/index.d.ts:717
Updates fields in the document referred to by the provided DocumentReference. The update will fail if applied to a document that does not exist.
DbModelType
DbModelType extends DocumentData
documentRef
DocumentReference<AppModelType, DbModelType>
A reference to the document to be updated.
data
UpdateData<DbModelType>
An object containing the fields and values with which to update the document. Fields can contain dots to reference nested fields within the document.
Call Signature
update<
AppModelType,DbModelType>(documentRef,field,value, ...moreFieldsAndValues):this
Defined in: firestore/lib/modular/index.d.ts:736
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.
DbModelType
DbModelType extends DocumentData
documentRef
DocumentReference<AppModelType, DbModelType>
A reference to the document to be updated.
field
The first field to update.
string | FieldPath
Call Signature
update<
AppModelType,DbModelType>(documentRef,fieldOrUpdateData,value?, ...moreFieldsAndValues):this
Defined in: firestore/lib/modular/index.d.ts:742
Updates fields in the document referred to by the provided DocumentReference. The update will fail if applied to a document that does not exist.
DbModelType
DbModelType extends DocumentData
documentRef
DocumentReference<AppModelType, DbModelType>
A reference to the document to be updated.
fieldOrUpdateData
string | FieldPath | UpdateData<DbModelType>
WriteBatch
Defined in: firestore/lib/modular/index.d.ts:558
A write batch, used to perform multiple writes as a single atomic unit.
A WriteBatch object can be acquired by calling writeBatch. 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.
Constructor
new WriteBatch():
WriteBatch
commit()
commit():
Promise<void>
Defined in: firestore/lib/modular/index.d.ts:653
Commits all of the writes in this write batch as a single atomic unit.
The result of these writes will only be reflected in document reads that occur after the returned promise resolves. If the client is offline, the write fails. If you would like to see local modifications or buffer writes until the client is online, use the full Firestore SDK.
Returns
Promise<void>
A Promise resolved once all of the writes in the batch have been
successfully written to the backend as an atomic unit (note that it won't
resolve while you're offline).
delete()
delete<
AppModelType,DbModelType>(documentRef):WriteBatch
Defined in: firestore/lib/modular/index.d.ts:638
Deletes the document referred to by the provided DocumentReference.
DbModelType
DbModelType extends DocumentData
documentRef
DocumentReference<AppModelType, DbModelType>
A reference to the document to be deleted.
Call Signature
set<
AppModelType,DbModelType>(documentRef,data):WriteBatch
Defined in: firestore/lib/modular/index.d.ts:567
Writes to the document referred to by the provided DocumentReference. If the document does not exist yet, it will be created.
DbModelType
DbModelType extends DocumentData
documentRef
DocumentReference<AppModelType, DbModelType>
A reference to the document to be set.
data
WithFieldValue<AppModelType>
An object of the fields and values for the document.
Call Signature
set<
AppModelType,DbModelType>(documentRef,data,options):WriteBatch
Defined in: firestore/lib/modular/index.d.ts:583
Writes to the document referred to by the provided DocumentReference. If the document does not exist yet, it will be created.
If you provide merge or mergeFields, the provided data can be merged
into an existing document.
DbModelType
DbModelType extends DocumentData
documentRef
DocumentReference<AppModelType, DbModelType>
A reference to the document to be set.
data
PartialWithFieldValue<AppModelType>
An object of the fields and values for the document.
Call Signature
update<
AppModelType,DbModelType>(documentRef,data):WriteBatch
Defined in: firestore/lib/modular/index.d.ts:600
Updates fields in the document referred to by the provided DocumentReference. The update will fail if applied to a document that does not exist.
DbModelType
DbModelType extends DocumentData
documentRef
DocumentReference<AppModelType, DbModelType>
A reference to the document to be updated.
data
UpdateData<DbModelType>
An object containing the fields and values with which to update the document. Fields can contain dots to reference nested fields within the document.
Call Signature
update<
AppModelType,DbModelType>(documentRef,field,value, ...moreFieldsAndValues):WriteBatch
Defined in: firestore/lib/modular/index.d.ts:619
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 update by providing dot-separated field path strings
or by providing FieldPath objects.
DbModelType
DbModelType extends DocumentData
documentRef
DocumentReference<AppModelType, DbModelType>
A reference to the document to be updated.
field
The first field to update.
string | FieldPath
Call Signature
update<
AppModelType,DbModelType>(documentRef,fieldOrUpdateData,value?, ...moreFieldsAndValues):WriteBatch
Defined in: firestore/lib/modular/index.d.ts:625
Updates fields in the document referred to by the provided DocumentReference. The update will fail if applied to a document that does not exist.
DbModelType
DbModelType extends DocumentData
documentRef
DocumentReference<AppModelType, DbModelType>
A reference to the document to be updated.
fieldOrUpdateData
string | FieldPath | UpdateData<DbModelType>
CollectionReference
Defined in: firestore/lib/modular/index.d.ts:450
A CollectionReference object can be used for adding documents, getting document references, and querying for
documents (using the methods inherited from Query).
Extends
Query<AppModelType,DbModelType>
AppModelType
AppModelType = DocumentData
DbModelType
DbModelType extends DocumentData = DocumentData
converter
converter:
FirestoreDataConverter<AppModelType,DbModelType> |null
Defined in: firestore/lib/modular/index.d.ts:422
If provided, the FirestoreDataConverter associated with this instance.
firestore
firestore:
Module
Defined in: firestore/lib/modular/index.d.ts:417
The Firestore instance the document is in. This is useful for performing transactions, for example.
id
id:
string
Defined in: firestore/lib/modular/index.d.ts:457
The collection's identifier.
parent
parent:
DocumentReference<DocumentData,DocumentData> |null
Defined in: firestore/lib/modular/index.d.ts:463
A reference to the containing DocumentReference if this is a subcollection. If this isn't a
subcollection, the reference is null.
path
path:
string
Defined in: firestore/lib/modular/index.d.ts:468
A string representing the path of the referenced collection (relative to the root of the database).
Call Signature
withConverter(
converter):CollectionReference<DocumentData,DocumentData>
Defined in: firestore/lib/modular/index.d.ts:477
Removes the current converter.
Returns
CollectionReference<DocumentData, DocumentData>
A CollectionReference<DocumentData, DocumentData> that does not
use a converter.
Call Signature
withConverter<
NewAppModelType,NewDbModelType>(converter):CollectionReference<NewAppModelType,NewDbModelType>
Defined in: firestore/lib/modular/index.d.ts:488
Applies a custom data converter to this CollectionReference, allowing you
to use your own custom model objects with Firestore. When you call addDoc with the returned CollectionReference instance, the provided
converter will convert between Firestore data of type NewDbModelType and
your custom type NewAppModelType.
NewDbModelType
NewDbModelType extends DocumentData = DocumentData
converter
FirestoreDataConverter<NewAppModelType, NewDbModelType>
Converts objects to and from Firestore.
Returns
CollectionReference<NewAppModelType, NewDbModelType>
A CollectionReference that uses the provided converter.
DocumentData
Defined in: firestore/lib/modular/index.d.ts:23
A DocumentData object represents the data in a document.
- Same as FirebaseFirestoreTypes.DocumentData
DocumentReference
Defined in: firestore/lib/modular/index.d.ts:498
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.
AppModelType
AppModelType = DocumentData
DbModelType
DbModelType extends DocumentData = DocumentData
converter
converter:
FirestoreDataConverter<AppModelType,DbModelType> |null
Defined in: firestore/lib/modular/index.d.ts:510
If provided, the FirestoreDataConverter associated with this instance.
firestore
firestore:
Module
Defined in: firestore/lib/modular/index.d.ts:505
The Firestore instance the document is in. This is useful for performing transactions, for example.
id
id:
string
Defined in: firestore/lib/modular/index.d.ts:515
The document's identifier within its collection.
parent
parent:
CollectionReference<AppModelType,DbModelType>
Defined in: firestore/lib/modular/index.d.ts:520
The Collection this DocumentReference belongs to.
path
path:
string
Defined in: firestore/lib/modular/index.d.ts:525
A string representing the path of the referenced document (relative to the root of the database).
Call Signature
withConverter(
converter):DocumentReference<DocumentData,DocumentData>
Defined in: firestore/lib/modular/index.d.ts:534
Removes the current converter.
Returns
DocumentReference<DocumentData, DocumentData>
A DocumentReference<DocumentData, DocumentData> that does not
use a converter.
Call Signature
withConverter<
NewAppModelType,NewDbModelType>(converter):DocumentReference<NewAppModelType,NewDbModelType>
Defined in: firestore/lib/modular/index.d.ts:545
Applies a custom data converter to this DocumentReference, allowing you
to use your own custom model objects with Firestore. When you call
:1, getDoc:1, etc. with the returned DocumentReference
instance, the provided converter will convert between Firestore data of
type NewDbModelType and your custom type NewAppModelType.
NewDbModelType
NewDbModelType extends DocumentData = DocumentData
converter
FirestoreDataConverter<NewAppModelType, NewDbModelType>
Converts objects to and from Firestore.
Returns
DocumentReference<NewAppModelType, NewDbModelType>
A DocumentReference that uses the provided converter.
FirestoreDataConverter
Defined in: firestore/lib/modular/index.d.ts:349
Converter used by withConverter() to transform user objects of type
AppModelType into Firestore data of type DbModelType.
Using the converter allows you to specify generic type arguments when storing and retrieving objects from Firestore.
In this context, an "AppModel" is a class that is used in an application to
package together related information and functionality. Such a class could,
for example, have properties with complex, nested data types, properties used
for memoization, properties of types not supported by Firestore (such as
symbol and bigint), and helper functions that perform compound
operations. Such classes are not suitable and/or possible to store into a
Firestore database. Instead, instances of such classes need to be converted
to "plain old JavaScript objects" (POJOs) with exclusively primitive
properties, potentially nested inside other POJOs or arrays of POJOs. In this
context, this type is referred to as the "DbModel" and would be an object
suitable for persisting into Firestore. For convenience, applications can
implement FirestoreDataConverter and register the converter with Firestore
objects, such as DocumentReference or Query, to automatically convert
AppModel to DbModel when storing into Firestore, and convert DbModel
to AppModel when retrieving from Firestore.
Example
Simple Example
const numberConverter = {
toFirestore(value: WithFieldValue<number>) {
return { value };
},
fromFirestore(snapshot: QueryDocumentSnapshot, options: SnapshotOptions) {
return snapshot.data(options).value as number;
}
};
async function simpleDemo(db: Firestore): Promise<void> {
const documentRef = doc(db, 'values/value123').withConverter(numberConverter);
// converters are used with `setDoc`, `addDoc`, and `getDoc`
await setDoc(documentRef, 42);
const snapshot1 = await getDoc(documentRef);
assertEqual(snapshot1.data(), 42);
// converters are not used when writing data with `updateDoc`
await updateDoc(documentRef, { value: 999 });
const snapshot2 = await getDoc(documentRef);
assertEqual(snapshot2.data(), 999);
}
Advanced Example
// The Post class is a model that is used by our application.
// This class may have properties and methods that are specific
// to our application execution, which do not need to be persisted
// to Firestore.
class Post {
constructor(
readonly title: string,
readonly author: string,
readonly lastUpdatedMillis: number
) {}
toString(): string {
return `${this.title} by ${this.author}`;
}
}
// The PostDbModel represents how we want our posts to be stored
// in Firestore. This DbModel has different properties (`ttl`,
// `aut`, and `lut`) from the Post class we use in our application.
interface PostDbModel {
ttl: string;
aut: { firstName: string; lastName: string };
lut: Timestamp;
}
// The `PostConverter` implements `FirestoreDataConverter` and specifies
// how the Firestore SDK can convert `Post` objects to `PostDbModel`
// objects and vice versa.
class PostConverter implements FirestoreDataConverter<Post, PostDbModel> {
toFirestore(post: WithFieldValue<Post>): WithFieldValue<PostDbModel> {
return {
ttl: post.title,
aut: this._autFromAuthor(post.author),
lut: this._lutFromLastUpdatedMillis(post.lastUpdatedMillis)
};
}
fromFirestore(snapshot: QueryDocumentSnapshot, options: SnapshotOptions): Post {
const data = snapshot.data(options) as PostDbModel;
const author = `${data.aut.firstName} ${data.aut.lastName}`;
return new Post(data.ttl, author, data.lut.toMillis());
}
_autFromAuthor(
author: string | FieldValue
): { firstName: string; lastName: string } | FieldValue {
if (typeof author !== 'string') {
// `author` is a FieldValue, so just return it.
return author;
}
const [firstName, lastName] = author.split(' ');
return {firstName, lastName};
}
_lutFromLastUpdatedMillis(
lastUpdatedMillis: number | FieldValue
): Timestamp | FieldValue {
if (typeof lastUpdatedMillis !== 'number') {
// `lastUpdatedMillis` must be a FieldValue, so just return it.
return lastUpdatedMillis;
}
return Timestamp.fromMillis(lastUpdatedMillis);
}
}
async function advancedDemo(db: Firestore): Promise<void> {
// Create a `DocumentReference` with a `FirestoreDataConverter`.
const documentRef = doc(db, 'posts/post123').withConverter(new PostConverter());
// The `data` argument specified to `setDoc()` is type checked by the
// TypeScript compiler to be compatible with `Post`. Since the `data`
// argument is typed as `WithFieldValue<Post>` rather than just `Post`,
// this allows properties of the `data` argument to also be special
// Firestore values that perform server-side mutations, such as
// `arrayRemove()`, `deleteField()`, and `serverTimestamp()`.
await setDoc(documentRef, {
title: 'My Life',
author: 'Foo Bar',
lastUpdatedMillis: serverTimestamp()
});
// The TypeScript compiler will fail to compile if the `data` argument to
// `setDoc()` is _not_ compatible with `WithFieldValue<Post>`. This
// type checking prevents the caller from specifying objects with incorrect
// properties or property values.
// @ts-expect-error "Argument of type { ttl: string; } is not assignable
// to parameter of type WithFieldValue<Post>"
await setDoc(documentRef, { ttl: 'The Title' });
// When retrieving a document with `getDoc()` the `DocumentSnapshot`
// object's `data()` method returns a `Post`, rather than a generic object,
// which would have been returned if the `DocumentReference` did _not_ have a
// `FirestoreDataConverter` attached to it.
const snapshot1: DocumentSnapshot<Post> = await getDoc(documentRef);
const post1: Post = snapshot1.data()!;
if (post1) {
assertEqual(post1.title, 'My Life');
assertEqual(post1.author, 'Foo Bar');
}
// The `data` argument specified to `updateDoc()` is type checked by the
// TypeScript compiler to be compatible with `PostDbModel`. Note that
// unlike `setDoc()`, whose `data` argument must be compatible with `Post`,
// the `data` argument to `updateDoc()` must be compatible with
// `PostDbModel`. Similar to `setDoc()`, since the `data` argument is typed
// as `WithFieldValue<PostDbModel>` rather than just `PostDbModel`, this
// allows properties of the `data` argument to also be those special
// Firestore values, like `arrayRemove()`, `deleteField()`, and
// `serverTimestamp()`.
await updateDoc(documentRef, {
'aut.firstName': 'NewFirstName',
lut: serverTimestamp()
});
// The TypeScript compiler will fail to compile if the `data` argument to
// `updateDoc()` is _not_ compatible with `WithFieldValue<PostDbModel>`.
// This type checking prevents the caller from specifying objects with
// incorrect properties or property values.
// @ts-expect-error "Argument of type { title: string; } is not assignable
// to parameter of type WithFieldValue<PostDbModel>"
await updateDoc(documentRef, { title: 'New Title' });
const snapshot2: DocumentSnapshot<Post> = await getDoc(documentRef);
const post2: Post = snapshot2.data()!;
if (post2) {
assertEqual(post2.title, 'My Life');
assertEqual(post2.author, 'NewFirstName Bar');
}
}
DbModelType
DbModelType extends DocumentData = DocumentData
fromFirestore()
fromFirestore(
snapshot,options?):AppModelType
Defined in: firestore/lib/modular/index.d.ts:400
Called by the Firestore SDK to convert Firestore data into an object of
type AppModelType. You can access your data by calling:
snapshot.data(options).
Generally, the data returned from snapshot.data() can be cast to
DbModelType; however, this is not guaranteed because Firestore does not
enforce a schema on the database. For example, writes from a previous
version of the application or writes from another client that did not use a
type converter could have written data with different properties and/or
property types. The implementation will need to choose whether to
gracefully recover from non-conforming data or throw an error.
To override this method, see (FirestoreDataConverter.fromFirestore:1).
snapshot
QueryDocumentSnapshot<DocumentData, DocumentData>
A QueryDocumentSnapshot containing your data and metadata.
Call Signature
toFirestore(
modelObject):WithFieldValue<DbModelType>
Defined in: firestore/lib/modular/index.d.ts:363
Called by the Firestore SDK to convert a custom model object of type
AppModelType into a plain JavaScript object (suitable for writing
directly to the Firestore database) of type DbModelType. To use set()
with merge and mergeFields, toFirestore() must be defined with
PartialWithFieldValue<AppModelType>.
The WithFieldValue<T> type extends T to also allow FieldValues such as
deleteField to be used as property values.
modelObject
WithFieldValue<AppModelType>
Returns
WithFieldValue<DbModelType>
Call Signature
toFirestore(
modelObject,options):PartialWithFieldValue<DbModelType>
Defined in: firestore/lib/modular/index.d.ts:377
Called by the Firestore SDK to convert a custom model object of type
AppModelType into a plain JavaScript object (suitable for writing
directly to the Firestore database) of type DbModelType. Used with
(setDoc:1), (WriteBatch.set:1) and
(Transaction.set:1) with merge:true or mergeFields.
The PartialWithFieldValue<T> type extends Partial<T> to allow
FieldValues such as (arrayUnion:1) to be used as property values.
It also supports nested Partial by allowing nested fields to be
omitted.
modelObject
PartialWithFieldValue<AppModelType>
Returns
PartialWithFieldValue<DbModelType>
Query
Defined in: firestore/lib/modular/index.d.ts:410
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.
AppModelType
AppModelType = DocumentData
DbModelType
DbModelType extends DocumentData = DocumentData
converter
converter:
FirestoreDataConverter<AppModelType,DbModelType> |null
Defined in: firestore/lib/modular/index.d.ts:422
If provided, the FirestoreDataConverter associated with this instance.
firestore
firestore:
Module
Defined in: firestore/lib/modular/index.d.ts:417
The Firestore instance the document is in. This is useful for performing transactions, for example.
Call Signature
withConverter(
converter):Query<DocumentData,DocumentData>
Defined in: firestore/lib/modular/index.d.ts:431
Removes the current converter.
Returns
Query<DocumentData, DocumentData>
A Query<DocumentData, DocumentData> that does not use a
converter.
Call Signature
withConverter<
NewAppModelType,NewDbModelType>(converter):Query<NewAppModelType,NewDbModelType>
Defined in: firestore/lib/modular/index.d.ts:441
Applies a custom data converter to this query, allowing you to use your own
custom model objects with Firestore. When you call getDocs with
the returned query, the provided converter will convert between Firestore
data of type NewDbModelType and your custom type NewAppModelType.
z
NewDbModelType
NewDbModelType extends DocumentData = DocumentData
converter
FirestoreDataConverter<NewAppModelType, NewDbModelType>
Converts objects to and from Firestore.
Returns
Query<NewAppModelType, NewDbModelType>
A Query that uses the provided converter.
AddPrefixToKeys
AddPrefixToKeys<
Prefix,T> ={ [K in keyof T & string as `${Prefix}.${K}`]?: T[K] }
Defined in: firestore/lib/modular/index.d.ts:57
Returns a new map where every key is prefixed with the outer key appended to a dot.
AggregateFieldType
AggregateFieldType =
ReturnType<typeofsum> |ReturnType<typeofaverage> |ReturnType<typeofcount>
Defined in: firestore/lib/modular/index.d.ts:1247
The union of all AggregateField types that are supported by Firestore.
AggregateQuerySnapshot
AggregateQuerySnapshot =
FirebaseFirestoreTypes.AggregateQuerySnapshot
Defined in: firestore/lib/modular/index.d.ts:10
ChildUpdateFields
ChildUpdateFields<
K,V> =VextendsRecord<string,unknown> ?AddPrefixToKeys<K,UpdateData<V>> :never
Defined in: firestore/lib/modular/index.d.ts:70
Helper for calculating the nested fields for a given type T1. This is needed to distribute
union types such as undefined | {...} (happens for optional props) or {a: A} | {b: B}.
In this use case, V is used to distribute the union types of T[K] on Record, since T[K]
is evaluated as an expression and not distributed.
See https://www.typescriptlang.org/docs/handbook/advanced-types.html#distributive-conditional-types
EmulatorMockTokenOptions
EmulatorMockTokenOptions = {
user_id:string; } | {sub:string; } &Partial<FirebaseIdToken>
Defined in: firestore/lib/modular/index.d.ts:108
NestedUpdateFields
NestedUpdateFields<
T> =UnionToIntersection<{ [K in keyof T & string]: ChildUpdateFields<K, T[K]> }[keyofT&string]>
Defined in: firestore/lib/modular/index.d.ts:77
For each field (e.g. 'bar'), find all nested keys (e.g. {'bar.baz': T1, 'bar.qux': T2}).
Intersect them together to make a single map containing all possible keys that are all marked as optional
PartialWithFieldValue
PartialWithFieldValue<
T> =Partial<T> |TextendsPrimitive?T:Textendsobject? { [K in keyof T]?: PartialWithFieldValue<T[K]> | FieldValue } :never
Defined in: firestore/lib/modular/index.d.ts:31
Similar to Typescript's Partial<T>, but allows nested fields to be
omitted and FieldValues to be passed in as property values.
PersistentCacheIndexManager
PersistentCacheIndexManager =
FirebaseFirestoreTypes.PersistentCacheIndexManager
Defined in: firestore/lib/modular/index.d.ts:9
Primitive
Primitive =
string|number|boolean|undefined|null
Defined in: firestore/lib/modular/index.d.ts:17
Primitive types.
QueryCompositeFilterConstraint
QueryCompositeFilterConstraint =
FirebaseFirestoreTypes.QueryCompositeFilterConstraint
Defined in: firestore/lib/modular/index.d.ts:14
SetOptions
SetOptions =
FirebaseFirestoreTypes.SetOptions
Defined in: firestore/lib/modular/index.d.ts:11
SnapshotListenOptions
SnapshotListenOptions =
FirebaseFirestoreTypes.SnapshotListenOptions
Defined in: firestore/lib/modular/index.d.ts:12
UnionToIntersection
UnionToIntersection<
U> =Uextendsunknown? (k) =>void:neverextends (k) =>void?I:never
Defined in: firestore/lib/modular/index.d.ts:48
Given a union type U = T1 | T2 | ..., returns an intersected type (T1 & T2 & ...).
Uses distributive conditional types and inference from conditional types. This works because multiple candidates for the same type variable in contra-variant positions causes an intersection type to be inferred. https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-inference-in-conditional-types https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type
UpdateData
UpdateData<
T> =TextendsPrimitive?T:Textendsobject? { [K in keyof T]?: UpdateData<T[K]> | FieldValue } &NestedUpdateFields<T> :Partial<T>
Defined in: firestore/lib/modular/index.d.ts:88
Update data (for use with updateDoc) that consists of field paths (e.g. 'foo' or 'foo.baz') mapped to values. Fields that contain dots reference nested fields within the document. FieldValues can be passed in as property values.
WhereFilterOp
WhereFilterOp =
FirebaseFirestoreTypes.WhereFilterOp
Defined in: firestore/lib/modular/index.d.ts:13
WithFieldValue
WithFieldValue<
T> =T|TextendsPrimitive?T:Textendsobject? { [K in keyof T]: WithFieldValue<T[K]> | FieldValue } :never
Defined in: firestore/lib/modular/index.d.ts:100
Allows FieldValues to be passed in as a property value while maintaining type safety.
addDoc()
addDoc<
AppModelType,DbModelType>(reference,data):Promise<DocumentReference<AppModelType,DbModelType>>
Defined in: firestore/lib/modular/index.d.ts:1022
Add a new document to specified CollectionReference with the given data,
assigning it a document ID automatically.
DbModelType
DbModelType extends DocumentData
reference
CollectionReference<AppModelType, DbModelType>
A reference to the collection to add this document to.
data
WithFieldValue<AppModelType>
An Object containing the data for the new document.
Returns
Promise<DocumentReference<AppModelType, DbModelType>>
A Promise resolved with a DocumentReference pointing to the
newly created document after it has been written to the backend (Note that it
won't resolve while you're offline).
average()
average(
field):AggregateField<number|null>
Defined in: firestore/lib/modular/index.d.ts:1273
Create an AggregateField object that can be used to compute the average of a specified field over a range of documents in the result set of a query.
field
Specifies the field to average across the result set.
string | FieldPath
Returns
AggregateField<number | null>
clearIndexedDbPersistence()
clearIndexedDbPersistence(
firestore):Promise<void>
Defined in: firestore/lib/modular/index.d.ts:1060
Aimed primarily at clearing up any data cached from running tests. Needs to be executed before any database calls are made.
clearPersistence()
clearPersistence(
firestore):Promise<void>
Defined in: firestore/lib/modular/index.d.ts:1052
Aimed primarily at clearing up any data cached from running tests. Needs to be executed before any database calls are made.
Deprecated, please use clearIndexedDbPersistence instead.
Call Signature
collection(
firestore,path, ...pathSegments):CollectionReference<DocumentData,DocumentData>
Defined in: firestore/lib/modular/index.d.ts:853
Gets a CollectionReference instance that refers to the collection at
the specified absolute path.
Returns
CollectionReference<DocumentData, DocumentData>
The CollectionReference instance.
Call Signature
collection<
AppModelType,DbModelType>(reference,path, ...pathSegments):CollectionReference<DocumentData,DocumentData>
Defined in: firestore/lib/modular/index.d.ts:871
Gets a CollectionReference instance that refers to a subcollection of
reference at the specified relative path.
DbModelType
DbModelType extends DocumentData
reference
CollectionReference<AppModelType, DbModelType>
A reference to a collection.
Returns
CollectionReference<DocumentData, DocumentData>
The CollectionReference instance.
Call Signature
collection<
AppModelType,DbModelType>(reference,path, ...pathSegments):CollectionReference<DocumentData,DocumentData>
Defined in: firestore/lib/modular/index.d.ts:889
Gets a CollectionReference instance that refers to a subcollection of
reference at the specified relative path.
DbModelType
DbModelType extends DocumentData
reference
DocumentReference<AppModelType, DbModelType>
A reference to a document.
Returns
CollectionReference<DocumentData, DocumentData>
The CollectionReference instance.
Call Signature
collection(
reference,path, ...pathSegments):CollectionReference<DocumentData>
Defined in: firestore/lib/modular/index.d.ts:907
Gets a CollectionReference instance that refers to a subcollection of
reference at the specified relative path.
pathSegments
...string[]
Additional path segments that will be applied relative to the first argument.
Returns
CollectionReference<DocumentData>
The CollectionReference instance.
collectionGroup()
collectionGroup(
firestore,collectionId):Query<DocumentData,DocumentData>
Defined in: firestore/lib/modular/index.d.ts:940
Creates and returns a new Query instance that includes all documents in the
database that are contained in a collection or subcollection with the
given collectionId.
collectionId
string
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.
Returns
Query<DocumentData, DocumentData>
The created Query.
connectFirestoreEmulator()
connectFirestoreEmulator(
firestore,host,port,options?):void
Defined in: firestore/lib/modular/index.d.ts:156
Modify this instance to communicate with the Cloud Firestore emulator.
mockUserToken?
string | EmulatorMockTokenOptions
the mock auth token to use for unit testing
count()
count():
AggregateField<number>
Defined in: firestore/lib/modular/index.d.ts:1279
Create an AggregateField object that can be used to compute the count of documents in the result set of a query.
Returns
AggregateField<number>
deleteAllPersistentCacheIndexes()
deleteAllPersistentCacheIndexes(
indexManager):Promise<void>
Defined in: firestore/lib/modular/index.d.ts:1392
Removes all persistent cache indexes. Note this function also deletes indexes
generated by setIndexConfiguration(), which is deprecated.
disableNetwork()
disableNetwork(
firestore):Promise<void>
Defined in: firestore/lib/modular/index.d.ts:1043
Disables network usage for this instance. It can be re-enabled via enableNetwork. While the network is disabled, any snapshot listeners,
getDoc() or getDocs() calls will return results from cache, and any write
operations will be queued until the network is restored.
disablePersistentCacheIndexAutoCreation()
disablePersistentCacheIndexAutoCreation(
indexManager):Promise<void>
Defined in: firestore/lib/modular/index.d.ts:1383
Stops creating persistent cache indexes automatically for local query execution.
The indexes which have been created by calling enableIndexAutoCreation() still take effect.
Call Signature
doc(
firestore,path, ...pathSegments):DocumentReference<DocumentData,DocumentData>
Defined in: firestore/lib/modular/index.d.ts:796
Gets a DocumentReference instance that refers to the document at the
specified absolute path.
pathSegments
...string[]
Additional path segments that will be applied relative to the first argument.
Returns
DocumentReference<DocumentData, DocumentData>
The DocumentReference instance.
Call Signature
doc<
AppModelType,DbModelType>(reference,path?, ...pathSegments):DocumentReference<AppModelType,DbModelType>
Defined in: firestore/lib/modular/index.d.ts:817
Gets a DocumentReference instance that refers to a document within
reference at the specified relative path. If no path is specified, an
automatically-generated unique ID will be used for the returned
DocumentReference.
DbModelType
DbModelType extends DocumentData
reference
CollectionReference<AppModelType, DbModelType>
A reference to a collection.
pathSegments
...string[]
Additional path segments that will be applied relative to the first argument.
Returns
DocumentReference<AppModelType, DbModelType>
The DocumentReference instance.
Call Signature
doc<
AppModelType,DbModelType>(reference,path, ...pathSegments):DocumentReference<DocumentData,DocumentData>
Defined in: firestore/lib/modular/index.d.ts:835
Gets a DocumentReference instance that refers to a document within
reference at the specified relative path.
DbModelType
DbModelType extends DocumentData
reference
DocumentReference<AppModelType, DbModelType>
A reference to a Firestore document.
pathSegments
...string[]
Additional path segments that will be applied relative to the first argument.
Returns
DocumentReference<DocumentData, DocumentData>
The DocumentReference instance.
enableNetwork()
enableNetwork(
firestore):Promise<void>
Defined in: firestore/lib/modular/index.d.ts:1033
Re-enables use of the network for this Firestore instance after a prior call to disableNetwork.
enablePersistentCacheIndexAutoCreation()
enablePersistentCacheIndexAutoCreation(
indexManager):Promise<void>
Defined in: firestore/lib/modular/index.d.ts:1374
Enables the SDK to create persistent cache indexes automatically for local query execution when the SDK believes cache indexes can help improves performance. This feature is disabled by default.
getAggregateFromServer()
getAggregateFromServer<
AggregateSpecType,AppModelType,DbModelType>(query,aggregateSpec):Promise<any>
Defined in: firestore/lib/modular/index.d.ts:1252
DbModelType
DbModelType extends DocumentData
query
Query<AppModelType, DbModelType>
getCountFromServer()
getCountFromServer<
AppModelType,DbModelType>(query):Promise<AggregateQuerySnapshot<{count:AggregateField<number>; },AppModelType,DbModelType>>
Defined in: firestore/lib/modular/index.d.ts:1171
Calculates the number of documents in the result set of the given query, without actually downloading the documents.
Using this function to count the documents is efficient because only the final count, not the documents' data, is downloaded. This function can even count the documents if the result set would be prohibitively large to download entirely (e.g. thousands of documents).
The result received from the server is presented, unaltered, without considering any local state. That is, documents in the local cache are not taken into consideration, neither are local modifications not yet synchronized with the server. Previously-downloaded results, if any, are not used: every request using this source necessarily involves a round trip to the server.
DbModelType
DbModelType extends DocumentData
query
Query<AppModelType, DbModelType>
The query whose result set size to calculate.
Returns
Promise<AggregateQuerySnapshot<{ count: AggregateField<number>; }, AppModelType, DbModelType>>
A Promise that will be resolved with the count; the count can be
retrieved from snapshot.data().count, where snapshot is the
AggregateQuerySnapshot to which the returned Promise resolves.
Call Signature
getFirestore():
Module
Defined in: firestore/lib/modular/index.d.ts:118
Returns the existing default Firestore instance that is associated with the default @firebase/app#FirebaseApp. If no instance exists, initializes a new instance with default settings.
Call Signature
getFirestore(
app):Module
Defined in: firestore/lib/modular/index.d.ts:130
Internal
Returns the existing default Firestore instance that is associated with the provided @firebase/app#FirebaseApp. If no instance exists, initializes a new instance with default settings.
Call Signature
getFirestore(
app?):Module
Defined in: firestore/lib/modular/index.d.ts:132
Returns the existing default Firestore instance that is associated with the default @firebase/app#FirebaseApp. If no instance exists, initializes a new instance with default settings.
Call Signature
getFirestore(
app?,databaseId?):Module
Defined in: firestore/lib/modular/index.d.ts:144
Returns the existing default Firestore instance that is associated with the provided @firebase/app#FirebaseApp and database ID. If no instance exists, initializes a new instance with default settings.
databaseId?
string
The ID of the Firestore database to use. If not provided, the default database is used.
getPersistentCacheIndexManager()
getPersistentCacheIndexManager(
firestore):PersistentCacheIndexManager|null
Defined in: firestore/lib/modular/index.d.ts:1364
Gets the PersistentCacheIndexManager instance used by this Cloud Firestore instance.
This is not the same as Cloud Firestore Indexes.
Persistent cache indexes are optional indexes that only exist within the SDK to assist in local query execution.
Returns
PersistentCacheIndexManager | null
PersistentCacheIndexManager | null - The PersistentCacheIndexManager instance or null if local persistent storage is not in use.
initializeFirestore()
initializeFirestore(
app,settings,databaseId?):Promise<Module>
Defined in: firestore/lib/modular/index.d.ts:1108
loadBundle()
loadBundle(
firestore,bundleData):LoadBundleTask
Defined in: firestore/lib/modular/index.d.ts:1323
Loads a Firestore bundle into the local cache.
bundleData
An object representing the bundle to be loaded. Valid
objects are ArrayBuffer, ReadableStream<Uint8Array> or string.
string | ArrayBuffer | ReadableStream<Uint8Array<ArrayBufferLike>>
Returns
LoadBundleTask
A LoadBundleTask object, which notifies callers with progress
updates, and completion or error events. It can be used as a
Promise<LoadBundleTaskProgress>.
namedQuery()
namedQuery(
firestore,name):Promise<Query<DocumentData,DocumentData> |null>
Defined in: firestore/lib/modular/index.d.ts:1340
Reads a Firestore Query from local cache, identified by the given name.
The named queries are packaged into bundles on the server side (along
with resulting documents), and loaded to local cache using loadBundle. Once
in local cache, use this method to extract a Query by name.
Returns
Promise<Query<DocumentData, DocumentData> | null>
A named Query.
refEqual()
refEqual<
AppModelType,DbModelType>(left,right):boolean
Defined in: firestore/lib/modular/index.d.ts:920
Returns true if the provided references are equal.
DbModelType
DbModelType extends DocumentData
left
DocumentReference<AppModelType, DbModelType> | CollectionReference<AppModelType, DbModelType> A reference to compare.
DocumentReference<AppModelType, DbModelType> | CollectionReference<AppModelType, DbModelType>
right
DocumentReference<AppModelType, DbModelType> | CollectionReference<AppModelType, DbModelType> A reference to compare.
DocumentReference<AppModelType, DbModelType> | CollectionReference<AppModelType, DbModelType>
Returns
boolean
boolean true if the references point to the same location in the same Firestore database.
Call Signature
runTransaction<
T>(firestore,updateFunction,options?):Promise<T>
Defined in: firestore/lib/modular/index.d.ts:778
Executes the given updateFunction and then attempts to commit the changes
applied within the transaction. If any document read within the transaction
has changed, Cloud Firestore retries the updateFunction. If it fails to
commit after 5 attempts, the transaction fails.
The maximum number of writes allowed in a single transaction is 500.
Returns
Promise<T>
If the transaction completed successfully or was explicitly aborted
(the updateFunction returned a failed promise), the promise returned by the
updateFunction is returned here. Otherwise, if the transaction failed, a
rejected promise with the corresponding failure error is returned.
Call Signature
runTransaction<
T>(firestore,updateFunction):Promise<T>
Defined in: firestore/lib/modular/index.d.ts:1145
Executes the given updateFunction and then attempts to commit the changes
applied within the transaction. If any document read within the transaction
has changed, Cloud Firestore retries the updateFunction. If it fails to
commit after 5 attempts, the transaction fails.
The maximum number of writes allowed in a single transaction is 500.
Returns
Promise<T>
If the transaction completed successfully or was explicitly aborted
(the updateFunction returned a failed promise), the promise returned by the
updateFunction is returned here. Otherwise, if the transaction failed, a
rejected promise with the corresponding failure error is returned.
Call Signature
setDoc<
AppModelType,DbModelType>(reference,data):Promise<void>
Defined in: firestore/lib/modular/index.d.ts:954
Writes to the document referred to by this DocumentReference. If the
document does not yet exist, it will be created.
DbModelType
DbModelType extends DocumentData
reference
DocumentReference<AppModelType, DbModelType>
A reference to the document to write.
data
WithFieldValue<AppModelType>
A map of the fields and values for the document.
Returns
Promise<void>
A Promise resolved once the data has been successfully written
to the backend (note that it won't resolve while you're offline).
Call Signature
setDoc<
AppModelType,DbModelType>(reference,data,options):Promise<void>
Defined in: firestore/lib/modular/index.d.ts:970
Writes to the document referred to by the specified DocumentReference. If
the document does not yet exist, it will be created. If you provide merge
or mergeFields, the provided data can be merged into an existing document.
DbModelType
DbModelType extends DocumentData
reference
DocumentReference<AppModelType, DbModelType>
A reference to the document to write.
data
PartialWithFieldValue<AppModelType>
A map of the fields and values for the document.
Returns
Promise<void>
A Promise resolved once the data has been successfully written to the backend (note that it won't resolve while you're offline).
setLogLevel()
setLogLevel(
logLevel):void
Defined in: firestore/lib/modular/index.d.ts:1126
Sets the verbosity of Cloud Firestore logs (debug, error, or silent).
sum()
sum(
field):AggregateField<number>
Defined in: firestore/lib/modular/index.d.ts:1266
Create an AggregateField object that can be used to compute the sum of a specified field over a range of documents in the result set of a query.
field
Specifies the field to sum across the result set.
string | FieldPath
Returns
AggregateField<number>
terminate()
terminate(
firestore):Promise<void>
Defined in: firestore/lib/modular/index.d.ts:1081
Terminates the provided Firestore instance.
To restart after termination, create a new instance of FirebaseFirestore with (getFirestore:1).
Termination does not cancel any pending writes, and any promises that are awaiting a response from the server will not be resolved. If you have persistence enabled, the next time you start this instance, it will resume sending these writes to the server.
Note: Under normal circumstances, calling terminate() is not required. This
function is useful only when you want to force this instance to release all
of its resources or in combination with clearIndexedDbPersistence() to
ensure that all local state is destroyed between test runs.
Returns
Promise<void>
A Promise that is resolved when the instance has been successfully
terminated.
Call Signature
updateDoc<
AppModelType,DbModelType>(reference,data):Promise<void>
Defined in: firestore/lib/modular/index.d.ts:987
Updates fields in the document referred to by the specified
DocumentReference. The update will fail if applied to a document that does
not exist.
DbModelType
DbModelType extends DocumentData
reference
DocumentReference<AppModelType, DbModelType>
A reference to the document to update.
data
UpdateData<DbModelType>
An object containing the fields and values with which to update the document. Fields can contain dots to reference nested fields within the document.
Returns
Promise<void>
A Promise resolved once the data has been successfully written
to the backend (note that it won't resolve while you're offline).
Call Signature
updateDoc<
AppModelType,DbModelType>(reference,field,value, ...moreFieldsAndValues):Promise<void>
Defined in: firestore/lib/modular/index.d.ts:1006
Updates fields in the document referred to by the specified
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.
DbModelType
DbModelType extends DocumentData
reference
DocumentReference<AppModelType, DbModelType>
A reference to the document to update.
field
The first field to update.
string | FieldPath
Returns
Promise<void>
A Promise resolved once the data has been successfully written
to the backend (note that it won't resolve while you're offline).
waitForPendingWrites()
waitForPendingWrites(
firestore):Promise<void>
Defined in: firestore/lib/modular/index.d.ts:1099
Waits until all currently pending writes for the active user have been acknowledged by the backend.
The returned promise resolves immediately if there are no outstanding writes.
Otherwise, the promise waits for all previously issued writes (including
those written in a previous app session), but it does not wait for writes
that were added after the function is called. If you want to wait for
additional writes, call waitForPendingWrites() again.
Any outstanding waitForPendingWrites() promises are rejected during user
changes.
Returns
Promise<void>
A Promise which resolves when all currently pending writes have been
acknowledged by the backend.
writeBatch()
writeBatch(
firestore):WriteBatch
Defined in: firestore/lib/modular/index.d.ts:1355
Creates a write batch, used for performing multiple writes as a single atomic operation. The maximum number of writes allowed in a single WriteBatch is 500.
The result of these writes will only be reflected in document reads that occur after the returned promise resolves. If the client is offline, the write fails. If you would like to see local modifications or buffer writes until the client is online, use the full Firestore SDK.
and
Re-exports and
AppliableConstraint
Re-exports AppliableConstraint
arrayRemove
Re-exports arrayRemove
arrayUnion
Re-exports arrayUnion
Bytes
Re-exports Bytes
deleteDoc
Re-exports deleteDoc
deleteField
Re-exports deleteField
documentId
Re-exports documentId
DocumentSnapshot
Re-exports DocumentSnapshot
endAt
Re-exports endAt
endBefore
Re-exports endBefore
FieldPath
Re-exports FieldPath
FieldValue
Re-exports FieldValue
FirestoreError
Re-exports FirestoreError
GeoPoint
Re-exports GeoPoint
getDoc
Re-exports getDoc
getDocFromCache
Re-exports getDocFromCache
getDocFromServer
Re-exports getDocFromServer
getDocs
Re-exports getDocs
getDocsFromCache
Re-exports getDocsFromCache
getDocsFromServer
Re-exports getDocsFromServer
increment
Re-exports increment
limit
Re-exports limit
limitToLast
Re-exports limitToLast
onSnapshot
Re-exports onSnapshot
onSnapshotsInSync
Re-exports onSnapshotsInSync
or
Re-exports or
orderBy
Re-exports orderBy
OrderByDirection
Re-exports OrderByDirection
query
Re-exports query
QueryConstraint
Re-exports QueryConstraint
QueryConstraintType
Re-exports QueryConstraintType
QueryDocumentSnapshot
Re-exports QueryDocumentSnapshot
QueryEndAtConstraint
Re-exports QueryEndAtConstraint
queryEqual
Re-exports queryEqual
QueryFieldFilterConstraint
Re-exports QueryFieldFilterConstraint
QueryLimitConstraint
Re-exports QueryLimitConstraint
QueryNonFilterConstraint
Re-exports QueryNonFilterConstraint
QueryOrderByConstraint
Re-exports QueryOrderByConstraint
QuerySnapshot
Re-exports QuerySnapshot
QueryStartAtConstraint
Re-exports QueryStartAtConstraint
serverTimestamp
Re-exports serverTimestamp
snapshotEqual
Re-exports snapshotEqual
startAfter
Re-exports startAfter
startAt
Re-exports startAt
Timestamp
Re-exports Timestamp
Unsubscribe
Re-exports Unsubscribe
vector
Re-exports vector
VectorValue
Re-exports VectorValue
where
Re-exports where
