@tsed/common
Version:
A TypeScript Framework on top of Express
94 lines (93 loc) • 2.97 kB
TypeScript
import { Type } from "@tsed/core";
import { JsonEntityStore, JsonEntityStoreOptions, JsonOperation } from "@tsed/schema";
import { ParamMetadata } from "./ParamMetadata";
export interface EndpointConstructorOptions extends JsonEntityStoreOptions {
beforeMiddlewares?: Function[];
middlewares?: Function[];
afterMiddlewares?: Function[];
}
export interface EndpointViewOptions {
path: string;
options: any;
}
export interface EndpointRedirectOptions {
status: number | undefined;
url: string;
}
/**
* EndpointMetadata contains metadata about a controller and his method.
* Each annotation (@Get, @Body...) attached to a method are stored in a endpoint.
* EndpointMetadata convert this metadata to an array which contain arguments to call an Express method.
*
* Example :
*
* @Controller("/my-path")
* provide MyClass {
*
* @Get("/")
* @Authenticated()
* public myMethod(){}
* }
*
*/
export declare class EndpointMetadata extends JsonEntityStore implements EndpointConstructorOptions {
beforeMiddlewares: any[];
middlewares: any[];
afterMiddlewares: any[];
statusCode: number;
constructor(options: EndpointConstructorOptions);
get targetName(): string;
get params(): ParamMetadata[];
/**
* Return the JsonOperation
*/
get operation(): JsonOperation;
get operationPaths(): Map<string, import("@tsed/schema").JsonMethodPath>;
get view(): EndpointViewOptions;
set view(view: EndpointViewOptions);
get location(): string;
set location(url: string);
get acceptMimes(): string[];
set acceptMimes(mimes: string[]);
get redirect(): EndpointRedirectOptions;
set redirect(options: EndpointRedirectOptions);
/**
* Get all endpoints from a given class and his parents.
* @param {Type<any>} target
* @returns {EndpointMetadata[]}
*/
static getEndpoints(target: Type<any>): EndpointMetadata[];
/**
* Get an endpoint.
* @param target
* @param propertyKey
* @param descriptor
*/
static get(target: Type<any>, propertyKey: string | symbol, descriptor?: PropertyDescriptor): EndpointMetadata;
addOperationPath(method: string, path: string | RegExp, options?: any): JsonOperation;
/**
* Find the a value at the controller level. Let this value be extended or overridden by the endpoint itself.
*
* @param key
* @returns {any}
*/
get<T = any>(key: any): T;
/**
* Append middlewares to the beforeMiddlewares list.
* @param args
* @returns {EndpointMetadata}
*/
before(args: Function[]): this;
/**
* Append middlewares to the afterMiddlewares list.
* @param args
* @returns {EndpointMetadata}
*/
after(args: Function[]): this;
/**
* Store all arguments collected via Annotation.
* @param args
*/
use(args: Function[]): this;
clone(): EndpointMetadata;
}