UNPKG

@magnetarjs/plugin-firestore-admin

Version:

Magnetar plugin firestore-admin

19 lines (18 loc) 1.19 kB
import { batchSyncFactory, getFirestoreDocPath, } from '@magnetarjs/utils-firestore'; import { mapGetOrSet } from 'getorset-anything'; import { isArray, isNumber } from 'is-what'; import { applySyncBatch, createWriteBatch } from '../helpers/batchHelpers.js'; export function deletePropActionFactory(batchSyncMap, firestorePluginOptions) { return async function ({ payload, collectionPath, docId, actionConfig, pluginModuleConfig, }) { if (!docId) throw new Error('An non-existent action was triggered on a collection'); const documentPath = getFirestoreDocPath(collectionPath, docId, pluginModuleConfig, firestorePluginOptions); // prettier-ignore const payloadArray = isArray(payload) ? payload : [payload]; const syncDebounceMs = isNumber(actionConfig.syncDebounceMs) ? actionConfig.syncDebounceMs : pluginModuleConfig.syncDebounceMs; const batchSync = mapGetOrSet(batchSyncMap, collectionPath, () => batchSyncFactory(firestorePluginOptions, createWriteBatch, applySyncBatch)); const result = await batchSync.deleteProp(documentPath, payloadArray, syncDebounceMs); return result; }; }