import { UseMutationOptions, UseMutationResult } from '@tanstack/react-query'; import { AxiosError } from 'axios'; import { ApiQueryMeta } from './createApiQuery'; /** * Configuration options for creating an API mutation hook * @template TVariables - Type of the mutation variables/parameters (use never for parameterless mutations) * @template TResponse - Type of the mutation response */ /** @public */ export interface CreateApiMutationOptions { /** * Mutation key for cache management * - For parameterless mutations: provide a static string array * - For parameterized mutations: provide a function that generates the key from variables */ mutationKey: string[]; /** * API function to call * - For parameterless mutations: provide a function with no parameters * - For parameterized mutations: provide a function that takes the variables */ mutationFn: TVariables extends never ? () => Promise : (variables: TVariables) => Promise; /** * Default mutation options to be merged with user-provided options * @optional */ defaultOptions?: Omit, 'mutationKey' | 'mutationFn' | 'meta'> & { meta?: ApiQueryMeta; }; } /** * Creates a strongly-typed mutation hook with enhanced error handling and options management * * @example Parameterless mutation: * ```ts * const useLogoutMutation = createApiMutation({ * mutationKey: ['logout'], * mutationFn: () => api.logout(), * defaultOptions: { retry: false } * }); * * // Usage * const { mutate, isLoading } = useLogoutMutation(); * ``` * * @example Parameterized mutation: * ```ts * const useCreateUserMutation = createApiMutation({ * mutationKey: ['user', 'create'], * mutationFn: (variables) => api.createUser(variables) * }); * * // Usage * const { mutate, isLoading } = useCreateUserMutation({ * onSuccess: (user) => { * // Do something with the result * }, * onError: (error) => { * // Do something with the error * } * }); * ``` */ /** @public */ export declare function createApiMutation({ mutationKey, mutationFn, defaultOptions, }: CreateApiMutationOptions): (options?: Omit, "mutationKey" | "mutationFn" | "meta"> & { meta?: ApiQueryMeta; }) => UseMutationResult;