@magnetarjs/plugin-firestore
Version:
Magnetar plugin firestore
19 lines (18 loc) • 1.14 kB
JavaScript
import { batchSyncFactory, getFirestoreDocPath, } from '@magnetarjs/utils-firestore';
import { mapGetOrSet } from 'getorset-anything';
import { isFullString, isNumber } from 'is-what';
import { applySyncBatch, createWriteBatch } from '../helpers/batchHelpers.js';
export function deleteActionFactory(batchSyncMap, firestorePluginOptions) {
return async function ({ payload, collectionPath, docId, actionConfig, pluginModuleConfig, }) {
const _docId = docId || payload;
if (!isFullString(_docId))
throw new Error('No ID passed to delete action.');
const documentPath = getFirestoreDocPath(collectionPath, _docId, pluginModuleConfig, firestorePluginOptions); // prettier-ignore
const syncDebounceMs = isNumber(actionConfig.syncDebounceMs)
? actionConfig.syncDebounceMs
: pluginModuleConfig.syncDebounceMs;
const batchSync = mapGetOrSet(batchSyncMap, collectionPath, () => batchSyncFactory(firestorePluginOptions, createWriteBatch, applySyncBatch));
const result = await batchSync.delete(documentPath, syncDebounceMs);
return result;
};
}