typenexus
Version:
TypeNexus is a good tool for API encapsulation and management. It provides a clean and lightweight way to package TypeORM functionality, helping you build applications faster while reducing template code redundancy and type conversion work.
56 lines (46 loc) • 1.67 kB
text/typescript
import { MiddlewareMetadataArgs } from './args/MiddlewareMetadataArgs.js';
import { ExpressMiddlewareInterface } from '../DriverOptions.js';
import { ExpressErrorMiddlewareInterface } from '../DriverOptions.js';
import { getFromContainer } from './ControllerMetadata.js';
/**
* Middleware metadata.
*/
export class MiddlewareMetadata {
// -------------------------------------------------------------------------
// Properties
// -------------------------------------------------------------------------
/**
* Indicates if this middleware is global, thous applied to all routes.
*/
global: boolean;
/**
* Object class of the middleware class.
*/
target: Function;
/**
* Execution priority of the middleware.
*/
priority: number;
/**
* Indicates if middleware must be executed after routing action is executed.
*/
type: 'before' | 'after';
// -------------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------------
constructor(args: MiddlewareMetadataArgs) {
this.global = args.global;
this.target = args.target;
this.priority = args.priority;
this.type = args.type;
}
// -------------------------------------------------------------------------
// Accessors
// -------------------------------------------------------------------------
/**
* Gets middleware instance from the container.
*/
get instance(): ExpressMiddlewareInterface | ExpressErrorMiddlewareInterface {
return getFromContainer<ExpressMiddlewareInterface | ExpressErrorMiddlewareInterface>(this.target);
}
}