import {AxiosError, AxiosResponse, AxiosInstance, Method} from 'axios'; import { InfiniteData, UseQueryResult, UseQueryOptions, UseInfiniteQueryResult, UseInfiniteQueryOptions, UseMutationOptions, UseMutationResult, MutationKey } from 'react-query'; import {ListIterateeCustom, PropertyPath} from 'lodash'; import {QueryClient} from "react-query/core"; export interface DynamicFetchParamsProps { query?: object; params?: object; } export interface DynamicFetchPaginateParamsProps { query?: object; params?: object; search?: object; } export interface DynamicFetchInfiniteParamsProps { query?: object; params?: object; search?: object; pageParams?: boolean | number; } export interface MutationRequestProps { body?: any; queryParams?: object; params?: object; } export type QueryOptionProps = Omit< UseQueryOptions, AxiosError, AxiosResponse, any>, 'queryKey' | 'queryFn' | 'enabled' | 'staleTime' | 'cacheTime' | 'onSuccess' | 'onError' >; export type QueryFetchOptionProps = Omit< UseQueryOptions< AxiosResponse, AxiosError, AxiosResponse, string | (string | number)[] >, 'queryKey' | 'queryFn' | 'enabled' | 'staleTime' | 'cacheTime' | 'onSuccess' | 'onError' >; export type QueryPaginateOptionProps = Omit< UseQueryOptions< AxiosResponse, AxiosError, AxiosResponse, (string | number | null | undefined)[] >, 'queryKey' | 'queryFn' | 'enabled' | 'staleTime' | 'cacheTime' | 'onSuccess' | 'onError' >; export type QueryInfiniteOptionProps = Omit< UseInfiniteQueryOptions< InfiniteData>, AxiosError, AxiosResponse, InfiniteData>, string | (string | number | null | undefined)[] >, 'queryKey' | 'queryFn' | 'enabled' | 'staleTime' | 'cacheTime' | 'onSuccess' | 'onError' >; export type MutationOptionProps = Omit< UseMutationOptions, AxiosError, MutationRequestProps>, 'mutationKey' | 'mutationFn' | 'onSuccess' | 'onError' >; export interface updatePathList { objectPath?: PropertyPath; listPath?: PropertyPath; } export interface ConfigureProps { axios?: AxiosInstance; queryOptions?: QueryOptionProps; fetchQueryOptions?: QueryFetchOptionProps; paginateQueryOptions?: QueryPaginateOptionProps; infiniteQueryOptions?: QueryInfiniteOptionProps; mutationOptions?: MutationOptionProps; } export interface UseFetchProps { axiosInstance: AxiosInstance; url: string; name?: Array | string; query?: object; params?: object; staleTime?: number; cacheTime?: number; showError?: boolean; enabled?: boolean; onSuccess?(data: AxiosResponse): void; onError?(error: AxiosError): void; options?: QueryFetchOptionProps; } export type UseFetchResultProps = UseQueryResult, AxiosError> & { refresh(): void; fetch(fetchParams: DynamicFetchParamsProps): void; data: any; query?: object; params?: object; }; export interface UsePaginateProps { axiosInstance: AxiosInstance; name?: Array | string; url: string; page: number; perPage?: number; staleTime?: number; cacheTime?: number; query?: object; search?: object; params?: object; enabled?: boolean; onSuccess?(data: AxiosResponse): void; onError?(error: AxiosError): void; options?: QueryPaginateOptionProps; } export type UsePaginateResultProps = UseQueryResult, AxiosError> & { refresh(): void; fetch(fetchParams: DynamicFetchPaginateParamsProps): void; data: any; query?: object; params?: object; }; export interface UseInfiniteProps { axiosInstance: AxiosInstance; url: string; name?: Array | string; infiniteKey?: string; staticKey?: string[]; query?: object; search?: object; params?: object; staleTime?: number; cacheTime?: number; initialData?: any; enabled?: boolean; onSuccess?(data: InfiniteData): void; onError?(error: AxiosError): void; options?: QueryInfiniteOptionProps; } export type UseInfiniteResultProps = UseInfiniteQueryResult, AxiosError> & { refresh(): void; fetch(fetchParams: DynamicFetchPaginateParamsProps): void; fetchPage(fetchParams: DynamicFetchInfiniteParamsProps): void; data: any; }; export interface UsePostProps { axiosInstance: AxiosInstance; name: MutationKey; url: string; query?: object; method?: Method; removeQueries?: Array | string>; refetchQueries?: Array | string>; isMultipart?: boolean; showError?: boolean; isUrlencoded?: boolean; onSuccess?(response: any, request?: any, params?: any): void; onError?(error: any, request?: any, params?: any): void; options?: MutationOptionProps; } export type UsePostResultProps = UseMutationResult< AxiosResponse, AxiosError, MutationRequestProps > & { post(mutationParams: MutationRequestProps): void; params?: MutationRequestProps; }; export interface UseModifyQueryProps { queryName: Array | string; } export type UseModifyQueryResultProps = { updateQuery(path: updatePathList, updateValue: any, predicate?: ListIterateeCustom | number): void; removeQuery(): void; pushQuery(insertValue: any, path?: updatePathList, predicate?: ListIterateeCustom): void; unshiftQuery(insertValue: any, path?: updatePathList, predicate?: ListIterateeCustom): void; deleteQuery(path: updatePathList, predicate?: ListIterateeCustom | number): void; setQuery(insertValue: any): void; }; export type UsePersistResultProps = { saveQuery(queryClient: QueryClient): void; saveData(name: string, data: any): void; getData(name: string): any; deleteData(name: string): void; }; export interface SubscribeDataProps { key: string; path: string | string[]; } export interface UseSubscribeQueryProps { name: Array | string; subscribesDataSet: SubscribeDataProps[]; } export declare function configure(options: ConfigureProps): void; export declare function useFetch(props: Omit): UseFetchResultProps; export declare function usePaginate(props: Omit): UsePaginateResultProps; export declare function useInfinite(props: Omit): UseInfiniteResultProps; export declare function usePost(props: Omit): UseInfiniteResultProps; export declare function useModifyQuery(props: UseModifyQueryProps): UseModifyQueryResultProps; export declare function usePersist(): UsePersistResultProps; export declare function useSubscribeQuery(props: UseSubscribeQueryProps): any; export default useFetch;