firelordjs
Version:
🔥 High Precision Typescript Wrapper for Firestore Web, Providing Unparalleled Type Safe and Dev Experience
32 lines (31 loc) • 1.2 kB
JavaScript
import { setCreator } from './set';
import { updateCreator } from './update';
import { updateNoFlattenCreator } from './updateNoFlatten';
import { deleteCreator } from './delete';
import { writeBatch as writeBatch_, getFirestore } from 'firebase/firestore';
/**
* Creates a write batch, used for performing multiple writes as a single
* atomic operation. The maximum number of writes allowed in a single {@link WriteBatch}
* is 500.
*
* Unlike transactions, write batches are persisted offline and therefore are
* preferable when you don't need to condition your writes on read data.
*
* @param firestore Optional, a reference to the Firestore database.
* If no value is provided, default Firestore instance is used.
*
* @returns A {@link WriteBatch} that can be used to atomically execute multiple
* writes.
*/
export var writeBatch = function (firestore) {
var batch = writeBatch_(
// @ts-expect-error
firestore || getFirestore());
return {
commit: function () { return batch.commit(); },
set: setCreator(batch),
update: updateCreator(batch),
delete: deleteCreator(batch),
updateNoFlatten: updateNoFlattenCreator(batch),
};
};