UNPKG

@pinia/colada-plugin-retry

Version:
46 lines (42 loc) 1.64 kB
import { PiniaColadaPluginContext } from '@pinia/colada'; /** * Pinia Colada Retry plugin. * * Adds the ability to retry failed queries. * * @module @pinia/colada-plugin-retry */ /** * Options for the Pinia Colada Retry plugin. */ interface RetryOptions { /** * The delay between retries. Can be a duration in ms or a function that receives the attempt number (starts at 0) and returns a duration in ms. By default, it will wait 2^attempt * 1000 ms, but never more than 30 seconds. * @param attempt - * @returns */ delay?: number | ((attempt: number) => number); /** * The maximum number of times to retry the operation. Set to 0 to disable or to Infinity to retry forever. It can also be a function that receives the failure count and the error and returns if it should retry. Defaults to 3. **Must be a positive number**. */ retry?: number | ((failureCount: number, error: unknown) => boolean); } interface RetryEntry { retryCount: number; timeoutId?: ReturnType<typeof setTimeout>; } /** * Plugin that adds the ability to retry failed queries. * * @param globalOptions - global options for the retries */ declare function PiniaColadaRetry(globalOptions?: RetryOptions): (context: PiniaColadaPluginContext) => void; declare module '@pinia/colada' { interface UseQueryOptions<TResult, TError, TDataInitial> { /** * Options for the retries of this query added by `@pinia/colada-plugin-retry`. */ retry?: RetryOptions | Exclude<RetryOptions['retry'], undefined>; } } export { PiniaColadaRetry, type RetryEntry, type RetryOptions };