import { isFullString , isNumber } from 'is-what' ; import { PluginDeleteAction , PluginDeleteActionPayload , SyncBatch } from '@magnetarjs/core' ; import { FirestoreModuleConfig , FirestorePluginOptions } from '../CreatePlugin' ; import { BatchSync } from '../helpers/batchSync' ; import { getFirestoreDocPath } from '../helpers/pathHelpers' ; export function deleteActionFactory ( batchSync , firestorePluginOptions ) { return async function ( { payload , collectionPath , docId , actionConfig , pluginModuleConfig , } ) : Promise < SyncBatch > { const _docId = docId || payload ; if ( ! isFullString ( _docId ) ) throw new Error ( 'No ID passed to delete action.' ) ; const documentPath = getFirestoreDocPath ( collectionPath , _docId , pluginModuleConfig , firestorePluginOptions ) ; const syncDebounceMs = isNumber ( actionConfig . syncDebounceMs ) ? actionConfig . syncDebounceMs : pluginModuleConfig . syncDebounceMs ; const result = await batchSync . delete ( documentPath , syncDebounceMs ) ; return result ; } ; }