import type { DependencyList } from 'react'; import type Fetch from './Fetch'; import type { CachedData } from './utils/cache'; export type Service = (...args: TParams) => Promise; export type Subscribe = () => void; export interface FetchState { loading: boolean; params?: TParams; data?: TData; error?: Error; } export interface PluginReturn { onBefore?: (params: TParams) => ({ stopNow?: boolean; returnNow?: boolean; } & Partial>) | void; onRequest?: (service: Service, params: TParams) => { servicePromise?: Promise; }; onSuccess?: (data: TData, params: TParams) => void; onError?: (e: Error, params: TParams) => void; onFinally?: (params: TParams, data?: TData, e?: Error) => void; onCancel?: () => void; onMutate?: (data: TData) => void; } export interface Options { manual?: boolean; onBefore?: (params: TParams) => void; onSuccess?: (data: TData, params: TParams) => void; onError?: (e: Error, params: TParams) => void; onFinally?: (params: TParams, data?: TData, e?: Error) => void; defaultParams?: TParams; refreshDeps?: DependencyList; refreshDepsAction?: () => void; loadingDelay?: number; pollingInterval?: number; pollingWhenHidden?: boolean; pollingErrorRetryCount?: number; refreshOnWindowFocus?: boolean; focusTimespan?: number; debounceWait?: number; debounceLeading?: boolean; debounceTrailing?: boolean; debounceMaxWait?: number; throttleWait?: number; throttleLeading?: boolean; throttleTrailing?: boolean; cacheKey?: string; cacheTime?: number; staleTime?: number; setCache?: (data: CachedData) => void; getCache?: (params: TParams) => CachedData | undefined; retryCount?: number; retryInterval?: number; ready?: boolean; } export type Plugin = { (fetchInstance: Fetch, options: Options): PluginReturn; onInit?: (options: Options) => Partial>; }; export interface Result { loading: boolean; data?: TData; error?: Error; params: TParams | []; cancel: Fetch['cancel']; refresh: Fetch['refresh']; refreshAsync: Fetch['refreshAsync']; run: Fetch['run']; runAsync: Fetch['runAsync']; mutate: Fetch['mutate']; } export type Timeout = ReturnType;