import type { WatchSource } from "vue"; import Fetch from "./fetch"; export type Subscribe = () => void; export interface Options { manual?: boolean; onBefore?: (params: TParams) => void; onSuccess?: (data: TData, params: TParams) => void; onError?: (e: Error, params: TParams) => void; // formatResult?: (res: any) => TData; onFinally?: (params: TParams, data?: TData, e?: Error) => void; defaultParams?: TParams; // refreshDeps refreshDeps?: WatchSource; refreshDepsAction?: () => void; // loading delay loadingDelay?: number; // polling pollingInterval?: number; pollingWhenHidden?: boolean; // refresh on window focus refreshOnWindowFocus?: boolean; focusTimespan?: number; // debounce debounceWait?: number; debounceLeading?: boolean; debounceTrailing?: boolean; debounceMaxWait?: number; // throttle throttleWait?: number; throttleLeading?: boolean; throttleTrailing?: boolean; // cache cacheKey?: string; cacheTime?: number; staleTime?: number; // setCache?: (data: CachedData) => void; // getCache?: (params: TParams) => CachedData | undefined; // retry retryCount?: number; retryInterval?: number; // ready ready?: boolean; // [key: string]: any; } export type Service = ( ...args: TParams ) => Promise; 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 type Plugin = { ( fetchInstance: Fetch, options: Options ): PluginReturn; onInit?: ( options: Options ) => Partial>; };