/** * @module Resilience */ import { type BackoffPolicy } from "../../../backoff-policies/contracts/_module.js"; import { type MiddlewareFn } from "../../../middleware/contracts/_module.js"; import { type ITimeSpan } from "../../../time-span/contracts/_module.js"; import { TimeSpan } from "../../../time-span/implementations/_module.js"; import { type Invocable, type ErrorPolicySettings } from "../../../utilities/_module.js"; /** * IMPORT_PATH: `"@daiso-tech/core/resilience"` * @group Middlewares */ export type OnRetryAttemptData = Array> = { attempt: number; args: TParameters; }; /** * IMPORT_PATH: `"@daiso-tech/core/resilience"` * @group Middlewares */ export type OnExecutionAttempt = Array> = Invocable<[data: OnRetryAttemptData]>; /** * IMPORT_PATH: `"@daiso-tech/core/resilience"` * @group Middlewares */ export type OnRetryDelayData = Array> = { error: unknown; attempt: number; waitTime: TimeSpan; args: TParameters; }; /** * IMPORT_PATH: `"@daiso-tech/core/resilience"` * @group Middlewares */ export type OnRetryDelay = Array> = Invocable<[data: OnRetryDelayData]>; /** * Lifecycle callbacks for the `retry` middleware. * Invoked at key points during retry attempts: before execution and before the delay. * * IMPORT_PATH: `"@daiso-tech/core/resilience"` * @group Middlewares */ export type RetryCallbacks = Array> = { /** * Callback {@link Invocable | `Invocable`} that will be called before execution attempt. */ onExecutionAttempt?: OnExecutionAttempt; /** * Callback {@link Invocable | `Invocable`} that will be called before the retry delay starts. */ onRetryDelay?: OnRetryDelay; }; /** * Configuration for the `retry` resilience middleware. * Retries the wrapped function up to a maximum number of attempts. * Supports configurable backoff policies and lifecycle callbacks. * * IMPORT_PATH: `"@daiso-tech/core/resilience"` * @group Middlewares */ export type RetrySettings = Array> = RetryCallbacks & ErrorPolicySettings & { /** * You can decide maximal times you can retry. * @default 4 */ maxAttempts?: number; /** * @default * ```ts * import { exponentialBackoff } from "@daiso-tech/core/backoff-policies"; * * exponentialBackoff(); * ``` */ backoffPolicy?: BackoffPolicy; /** * If true last error will be thrown otherwise an {@link RetryResilienceError | `RetryResilienceError`} will be thrown. * * @default false */ throwLastError?: boolean; }; /** * @internal */ export type HandleOnExecutionAttemptSettings> = { onExecutionAttempt: OnExecutionAttempt; attempt: number; args: TParameters; }; /** * @internal */ export declare function handleOnExecutionAttempt>(settings: HandleOnExecutionAttemptSettings): void; /** * @internal */ export type HandleOnRetryDelaySettings> = { onRetryDelay: OnRetryDelay; error: unknown; waitTime: ITimeSpan; attempt: number; args: TParameters; }; /** * @internal */ export declare function handleOnRetryDelay>(settings: HandleOnRetryDelaySettings): void; /** * IMPORT_PATH: `@daiso-tech/core/resilience` * @group Middlewares * @throws {RetryResilienceError} */ export declare function retry, TReturn>(settings?: NoInfer>): MiddlewareFn>;