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.

36 lines 1.1 kB
/** * @module Async */ import { callInvokable, } 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 function dynamic(dynamic) { return (args, next, settings) => { const middleware = callInvokable(dynamic, args, settings.context); return callInvokable(middleware, args, next, settings); }; } //# sourceMappingURL=dynamic.middleware.js.map