import { resolveMiddleware } from "../class/middleware" ; import Controller , { Controller$ , ControllerMiddleware$ } from "../class/controller" ; import { MIDDLEWARE } from "../const" ; param middlewareName param options export function Use ( middlewareName , options = { } ) { const MiddlewareFactory = resolveMiddleware ( middlewareName ) ; return function ( target , propertyKey , descriptor ) { if ( target instanceof Controller === false || typeof target [ propertyKey ] !== "function" ) { throw new Error ( "@USE() decorator only for controller method" ) ; } const controllerMiddleware = target [ MIDDLEWARE ] || [ ] ; controllerMiddleware . push ( { handler : propertyKey , factory : MiddlewareFactory , options } ) ; target [ MIDDLEWARE ] = controllerMiddleware ; } ; }