@magnetarjs/plugin-firestore
Version:
Magnetar plugin firestore
24 lines (23 loc) • 882 B
JavaScript
export function revertActionFactory(actions, firestorePluginOptions) {
return async function ({ payload, collectionPath, docId, actionConfig, pluginModuleConfig, actionName, error, }) {
// reverting on read actions is not neccesary
const isReadAction = ['fetch', 'stream'].includes(actionName);
if (isReadAction)
return;
// revert all write actions when called on a doc
if (docId) {
if (actionName === 'insert') {
if (actions.delete)
await actions.delete({
payload: undefined,
collectionPath,
docId,
actionConfig,
pluginModuleConfig,
});
return;
}
}
// other actions don't need revert
};
}