/* eslint-disable @typescript-eslint/no-explicit-any */ import type { CacheAxiosResponse } from 'axios-cache-interceptor'; /** The internal axios state used by `axios-cache-hooks` */ export type State = LoadingState | ErrorState | SuccessState; export type LoadingState = { /** If the current request is loading */ loading: true; /** The returned data for this request, if present */ data?: undefined; /** The error thrown by this http request, if any */ error?: undefined; /** The complete `CacheAxiosResponse` */ response?: undefined; /** Last response data unique id. @internal */ rid?: number; }; export type ErrorState = { /** If the current request is loading */ loading: false; /** The returned data for this request, if present */ data?: undefined; /** The error thrown by this http request, if any */ error: unknown; /** The complete `CacheAxiosResponse` */ response?: CacheAxiosResponse; /** Last response data unique id. @internal */ rid: number; }; export type SuccessState = { /** If the request is loading */ loading: false; /** The returned data for this request, if present */ data: D; /** The error thrown by this http request, if any */ error?: undefined; /** The complete `CacheAxiosResponse` */ response: CacheAxiosResponse; /** Last response data unique id. @internal */ rid: number; }; /** * This is where you should define your custom axios request logic. * * **Note**: Remember to ALWAYS spread the {@link AxiosRequestConfig} object in the axios call. */ export type ApiCall = ( ...args: A ) => Promise>; /** * The current request state. * * The response data was provided as the in the first object of this tuple. */ export type DataLessState = Omit, 'data'>; export type AxiosCacheHooks = { /** * Uses the provided `apiCall` to execute a axios request. * * Make sure the `apiCall` function has an `CacheRequestConfig` argument in the same * index as your `configIndexFinder` defined. * * **Note**: This is different from `useMutation` because it calls the axios request * directly on the first render. * * @example * * ```tsx * const [user, { loading }] = useQuery(getUser, 'Arthur'); * * if (loading) { * return
Loading...
; * } * * return
{user.name}
; * ``` * * @param apiCall The function that will return a {@link CacheAxiosResponse} * @param args Arguments to pass to the `apiCall`. You can change this arguments without * any problems. * @see http://tinylibs.js.org/packages/axios-cache-hooks */ useQuery( this: void, apiCall: ApiCall, ...args: A ): [data: D | undefined, info: DataLessState]; /** * Uses the provided `apiCall` to execute a axios request when the returned `refetch` * function is called. * * Make sure the `apiCall` function has an `CacheRequestConfig` argument in the same * index as your `configIndexFinder` defined. * * **Note**: This is different from `useQuery` because it **DOES NOT** calls the axios * request on the first render. * * @example * * ```tsx * const [state, refetch] = useMutation(createUser); * * return ; * ``` * * @param apiCall The function that will return a {@link CacheAxiosResponse}. * @see http://tinylibs.js.org/packages/axios-cache-hooks */ useMutation( this: void, apiCall: ApiCall ): [state: State, refetch: (...args: A) => void]; };