Use: <TParameters extends unknown[], TReturn>(
    invokable: Invokable<TParameters, TReturn>,
    middlewares: OneOrMore<Middleware<TParameters, TReturn>>,
) => InvokableFn<TParameters, TReturn>

Function that applies a middleware chain to an invokable function or object.

Wraps the provided invokable with the specified middlewares, creating a new function that executes all middlewares in priority order before delegating to the original invokable. The execution happens within the provided execution context.

Type declaration

const use = useFactory();

// Apply a single middleware
const logged = use(fetchData, loggingMiddleware);

// Apply multiple middlewares (executed in priority order)
const enhanced = use(fetchData, [
{ priority: 0, invoke: authMiddleware },
{ priority: 10, invoke: cacheMiddleware },
{ priority: 20, invoke: loggingMiddleware }
]);

// Call the wrapped function
const result = logged(arg1, arg2);

IMPORT_PATH: @daiso-tech/core/middleware