firestore-large-batch
Version:
A library for limitless batching operations in Firestore
65 lines (64 loc) • 2.99 kB
TypeScript
import * as firestore from "@google-cloud/firestore";
/**
* LargeBatch allows for batching operations in Firestore.
*/
export declare class LargeBatch {
private firestoreInstance;
private batches;
private operationCount;
/**
* Creates a new instance of the `LargeBatch` class.
* @param firestoreInstance An instance of Firestore.
*/
constructor(firestoreInstance: firestore.Firestore);
/**
* Returns the current batch and if the number of operations in that batch reaches 500, a new batch is added to the array
*/
private currentBatch;
/**
* Adds a create operation to the current batch.
* @param documentRef A Firestore DocumentReference.
* @param data The data to be added to the document.
*/
create<T>(documentRef: firestore.DocumentReference<T>, data: T): void;
/**
* Adds a set operation to the current batch.
* @param documentRef A Firestore DocumentReference.
* @param data The data to be set on the document.
* @param options Optional settings to use when setting the document.
*/
set<T>(documentRef: firestore.DocumentReference<T>, data: Partial<T> | firestore.WithFieldValue<T>, options?: firestore.SetOptions | undefined): void;
/**
* Adds an update operation to the current batch.
* @param documentRef A Firestore DocumentReference.
* @param data The data to be updated on the document.
* @param precondition An optional precondition to use when updating the document.
*/
update<T>(documentRef: firestore.DocumentReference<T>, data: firestore.UpdateData<T>, precondition?: firestore.Precondition): void;
/**
* Adds an update field operation to the current batch.
* @param documentRef A Firestore DocumentReference.
* @param field The field to update on the document.
* @param value The new value of the field.
* @param fieldsOrPrecondition Additional fields to update on the document, or an optional precondition to use when updating the document.
*/
updateField(documentRef: firestore.DocumentReference<unknown>, field: string | firestore.FieldPath, value: unknown, ...fieldsOrPrecondition: unknown[]): void;
/**
* Adds a delete operation to the current batch.
* @param documentRef A Firestore DocumentReference.
* @param precondition An optional precondition to use when deleting the document.
*/
delete(documentRef: firestore.DocumentReference<unknown>, precondition?: firestore.Precondition): void;
/**
* Commits all batches. Optionally, you can pass a commit unit which controls the number of batches that are committed at a time.
* @param commitUnit Number of batches to commit at a time.
*/
commit(options?: {
commitUnit?: number;
}): Promise<void>;
/**
* Commits all batches and reset the batch array and operation count
* @param batches Array of batches to be committed
*/
private commitBatches;
}