@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.24 kB
TypeScript
/**
* @module Async
*/
import type { HookContext, AsyncMiddleware } from "../../../utilities/_module-exports.js";
import { type AsyncMiddlewareFn, type Invokable } from "../../../utilities/_module-exports.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/async"`
* @group Middlewares
*
* @example
* ```ts
* import { dynamic, fallback } from "@daiso-tech/core/async";
* import { AsyncHooks } from "@daiso-tech/core/utilities";
*
* 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>;