UNPKG

@daiso-tech/core

Version:

The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.

35 lines (34 loc) 1.23 kB
/** * @module Resilience */ import { type AsyncMiddleware, type AsyncMiddlewareFn, type HookContext } from "../../../hooks/_module.js"; import { type Invokable } from "../../../utilities/_module.js"; /** * The `dynamic` is wrapper middleware that allows configuration of other middlewares dynamically based on the function arguments and context. * * IMPORT_PATH: `"@daiso-tech/core/resilience"` * @group Middlewares * * @example * ```ts * import { dynamic, fallback } from "@daiso-tech/core/resilience"; * import { AsyncHooks } from "@daiso-tech/core/hooks"; * * await new AsyncHooks( * (a: number, b: number) => a / b, * [ * // You pass callback function where you get access to the function arguments and context. * // The callback function must return a middleware. * dynamic((_args, _context) => * fallback({ * fallbackValue: 1, * }), * ), * ], * ).invoke(1, 0); * ``` */ export declare function dynamic<TParameters extends unknown[], TReturn, TContext extends HookContext>(dynamic: NoInfer<Invokable<[ arguments_: TParameters, context: TContext ], AsyncMiddleware<TParameters, TReturn, TContext>>>): AsyncMiddlewareFn<TParameters, TReturn, TContext>;