UNPKG

@decorators/server

Version:

node decorators - decorators for express library

51 lines (50 loc) 1.43 kB
import { MethodMetadata, ParamMetadata } from '../types'; import { Context } from './context'; export declare function paramDecoratorFactory(metadata: Partial<ParamMetadata> & { [key: string]: any; }): (target: InstanceType<any>, methodName: string, index: number) => void; export declare function methodDecoratorFactory(metadata: Partial<MethodMetadata> & { [key: string]: any; }): (target: object, methodName: string, descriptor: TypedPropertyDescriptor<any>) => TypedPropertyDescriptor<any>; /** * Creates a custom parameter decorator * * Example: * * ... * export function AccessParam() { * return createParamDecorator((context: HttpContext) => { * const req = context.getRequest<Request>(); * * return req.query.access; * }); * } * * ... * authorize(@AccessParam() access: string) * ... */ export declare function createParamDecorator(factory: (context: Context) => Promise<any> | any): (target: any, methodName: string, index: number) => void; /** * Creates a custom method or class decorator * * Example: * * ... * export function Access(access: string) { * return Decorate('access', access); * } * ... * * @Access('granted') * create() * ... * * Also can be used without a wrapper: * * ... * @Decorate('access', granted) * create() * ... */ export declare function Decorate(key: string, value: unknown): (target: object, propertyKey?: any, descriptor?: any) => any;