import type { InferRouteBody, InferRouteError, InferRouteOptions, InferRouteOutput, ParsedPathAndMethod } from '@aydee-app/eden'; import { type DefaultError, type MutateOptions, type QueryClient, type UseBaseMutationResult, type UseMutationOptions, type UseMutationResult } from '@tanstack/react-query'; import type { RouteSchema } from 'elysia'; import type { EdenContextState } from '../../context'; import type { Override } from '../../utils/types'; import type { EdenQueryBaseOptions } from '../internal/query-base-options'; import type { WithEdenQueryExtension } from '../internal/query-hook-extension'; export type EdenUseMutationOptions = UseMutationOptions & EdenQueryBaseOptions; export type EdenUseMutationResult = WithEdenQueryExtension, { mutateAsync: EdenAsyncMutationFunction; mutate: EdenMutationFunction; }>>; export type EdenUseMutation, TInput = Partial, 'params'>> & Omit, 'params'>, TData = InferRouteOutput, TError = InferRouteError> = (options?: EdenUseMutationOptions) => EdenUseMutationResult; export type EdenAsyncMutationFunction = (variables: {} extends TVariables ? void : unknown extends TVariables ? void : TVariables, options: {} extends TInput ? void | (TInput & MutateOptions, TContext>) : TInput & MutateOptions, TContext>) => Promise; export type EdenMutationFunction = (variables: {} extends TVariables ? void : unknown extends TVariables ? void : TVariables, options: {} extends TInput ? void | (TInput & MutateOptions, TContext>) : TInput & MutateOptions, TContext>) => void; /** * @internal * * Need to be able to provide multiple arguments to `useMutation`, since * Eden's mutations accept a body as the first argument, and additional options * as the second argument -- which are sometimes required. * * To accomplish this, eden-query intercepts the hook call to grab the args as a single object, * then destructures it in custom `mutate` and `asyncMutate` implementations. * * This "hack" is needed since the vanilla `useMutation` hook doesn't allow multiple args :( */ export type EdenUseMutationVariables = { /** * The first argument provided to the `useMutation` hook, i.e. the request body. */ body: TBody; } & ({} extends TOptions ? { /** * The second argument provided to the `useMutation` hook, i.e. request options. */ options?: TOptions; } : { /** * The second argument provided to the `useMutation` hook, i.e. request options. */ options: TOptions; }); /** * In order to extend the {@link createMutation} API to allow query/headers to be * passed in and forwarded properly, create custom wrapper around {@link createMutation} that * can accept multiple arguments. */ export declare function useEdenMutation(options: UseMutationOptions, queryClient?: QueryClient): UseMutationResult; export declare function getEdenUseMutationOptions(parsedPathsAndMethod: ParsedPathAndMethod, context: EdenContextState, input?: InferRouteOptions, options?: EdenUseMutationOptions, config?: any): UseMutationOptions;