import {type MaybeRef} from '@vueuse/core'; import {useMutation, type UseMutationOptions, type UseMutationReturnType} from '@tanstack/vue-query'; import {type MutationFunction} from '@tanstack/query-core'; import {type BackendEndpoint} from '@myparcel-pdk/common'; import {type ApiException} from '@myparcel/sdk'; import {type ActionInput, type BackendEndpointResponse} from '../../../types'; type MaybeRefDeep = MaybeRef< // eslint-disable-next-line @typescript-eslint/ban-types T extends Function ? T : T extends object ? { [Property in keyof T]: MaybeRefDeep; } : T >; type VueMutationObserverOptions = { [Property in keyof UseMutationOptions]: MaybeRefDeep< UseMutationOptions[Property] >; }; type UsePdkMutation = < E extends BackendEndpoint, TData extends BackendEndpointResponse = BackendEndpointResponse, TError extends ApiException = ApiException, TVariables extends ActionInput = ActionInput, TContext = unknown, >( endpoint: E, mutationFn: MaybeRef>, options?: MaybeRef< Omit, 'mutationKey' | 'mutationFn'> >, ) => UseMutationReturnType; export const usePdkMutation: UsePdkMutation = (endpoint, mutationFn, options) => { return useMutation([endpoint], mutationFn, options); };