import { useOptimisticUpdate } from "pinia-colada-plugin-normalizer" export const useDeleteCharacter = defineMutation(() => { const { transaction } = useOptimisticUpdate() const { mutate, ...mutation } = useMutation({ onMutate({ id }) { const optionsCache = useOptionsCache() const tx = transaction() tx.remove("character", _toString(id)) optionsCache.update() return { ...tx, rollbackOptions: optionsCache.rollback } }, mutation: ({ id }) => useEmit("character:delete", id), onError: (error, _vars, { rollback, rollbackOptions }) => { rollback?.() rollbackOptions() console.error("[useDeleteCharacter] [onError]", error) }, onSuccess: (_data, _vars, { commit }) => commit?.() }) return { ...mutation, deleteCharacter: (id) => mutate({ id }) } })