@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.
37 lines • 1.15 kB
JavaScript
/**
* @module Resilience
*/
import {} from "../../../hooks/_module.js";
import { callInvokable } 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 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