/** * 核心装饰器 * @author ranyunlong<549510622@qq.com> * license MIT */ import { TKServer } from "./Server"; import 'reflect-metadata'; declare type CreateDecoratorCallback = (options: TKServer.ControllerOptions, propertyKey?: string | symbol, descriptorOrIndex?: TypedPropertyDescriptor | number) => void; /** * 自定义指令方法 * @param callback 回调函数 返回核心的options选项 * @param Controller 可选自定义装饰器获取到的 构造函数 */ export declare function createDecorator(callback: CreateDecoratorCallback, Controller?: TKServer.Controller): TKServer.Decorator; /** * PropertyDecorator * Files * * Examples * ``` * import { Controller, Files } from '@tkrjs/Core' * @Controller('/') * export class IndexController { * } * ``` */ export declare function Controller(path: string): TKServer.ClassDecorator; /** * PropertyDecorator * Query * * Examples * ``` * import { Controller, Get, Query, TKServer } from '@tkrjs/Core' * interface Datas { * aa: string; * bb: string; * } * @Controller('/') * export class IndexController { * @Query query!: object; * @Get * private async index( * @Query param1:string, * @Query(['aa','bb']) param2:string, * @Query({aa: String, bb: Number }) param3:TKServer.Validator * ){ * console.log(param1) * console.log(param2) * console.log(this.query) * if(param3.getError()){ * return param3.getError() * } else { * return param3.data * } * } * } * ``` */ export declare const Query: { (target: Object, propertyKey: string | symbol): void; (target: Object, propertyKey: string | symbol, parameterIndex: number): void; (field: string | object | string[]): ParameterDecorator; }; /** * PropertyDecorator * Param * * Examples * ``` * import { Controller, Get, Param, TKServer } from '@tkrjs/Core' * interface Datas { * id: number; * news: string; * } * @Controller('/') * export class IndexController { * @Get(':id') * @Post(':id/:news') * private async index( * @Param param:string, * @Param('id') param1: string; * @Param(['id','news']) param2: string; * @Param({id:Number, news:string}) param3: param3:TKServer.Validator; * ){ * console.log(param, param1, param2, param3) * } * } * ``` */ export declare const Param: { (target: Object, propertyKey: string | symbol): void; (target: Object, propertyKey: string | symbol, parameterIndex: number): void; (field: string | object | string[]): ParameterDecorator; }; /** * PropertyDecorator * Body * * Examples * ``` * import { Controller, Post, Body, TKServer } from '@tkrjs/Core' * interface Datas { * aa: string; * bb: string; * } * @Controller('/') * export class IndexController { * @Body body!: string; * @Post * private async index( * @Body param1:string, * @Body(['aa','bb']) param2:string, * @Body({aa: String, bb: Number }) param3:TKServer.Validator * ){ * console.log(param1) * console.log(param2) * console.log(this.body) * if(param3.getError()){ * return param3.getError() * } else { * return param3.data * } * } * } * ``` */ export declare const Body: { (target: Object, propertyKey: string | symbol): void; (target: Object, propertyKey: string | symbol, parameterIndex: number): void; (field: string | object | string[]): ParameterDecorator; }; /** * PropertyDecorator * Body * * Examples * ``` * import { Controller, Post, Session } from '@tkrjs/Core' * @Controller('/') * export class IndexController { * * @Session public session!: object; * * @Body * private async index( * @Session param:string, * @Session('user') user:string, * ){ * console.log(param) * console.log(user) * console.log(this.session) * } * } * ``` */ export declare const Session: { (target: Object, propertyKey: string | symbol): void; (target: Object, propertyKey: string | symbol, parameterIndex: number): void; (field: string | object | string[]): ParameterDecorator; }; /** * PropertyDecorator * Files * * Examples * ``` * import { Controller, Files } from '@tkrjs/Core' * @Controller('/') * export class IndexController { * * @Files public files!: object; * * @Post * private async index( * @Files param:string, * ){ * console.log(param) * console.log(this.files) * } * } * ``` */ export declare const Files: { (target: Object, propertyKey: string | symbol): void; (target: Object, propertyKey: string | symbol, parameterIndex: number): void; (field: string | object | string[]): ParameterDecorator; }; export declare const Header: { (target: Object, propertyKey: string | symbol): void; (target: Object, propertyKey: string | symbol, parameterIndex: number): void; (field: string | object | string[]): ParameterDecorator; }; export declare const Headers: { (target: Object, propertyKey: string | symbol): void; (target: Object, propertyKey: string | symbol, parameterIndex: number): void; (field: string | object | string[]): ParameterDecorator; }; /** * RequestMethodDecorators * Get * * Examples * ``` * import { Controller, Get } from '@tkrjs/Core' * @Controller('/') * export class IndexController{ * @Get * private async index() { * // Request method Get * return 'http://localhost:3000/index' * } * * @Get * private async test() { * // Request method Get * return 'http://localhost:3000/test' * } * * @Get('api') * private async test1() { * // Request method Get * return 'http://localhost:3000/api' * } * * @Get('api/:id') * private async test1() { * // Request method Get * // {id} Is any data * return 'http://localhost:3000/api/{id}' * } * } * ``` */ export declare const Get: { (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor): void; (route: string): MethodDecorator; }; /** * RequestMethodDecorators * All * * Examples * ``` * import { Controller, All } from '@tkrjs/Core' * @Controller('/') * export class IndexController{ * @All * private async index() { * // Request method all * return 'http://localhost:3000/index' * } * * @All * private async test() { * // Request method all * return 'http://localhost:3000/test' * } * * @All('api') * private async test1() { * // Request method all * return 'http://localhost:3000/api' * } * * @All('api/:id') * private async test1() { * // Request method all * // {id} Is any data * return 'http://localhost:3000/api/{id}' * } * } * ``` */ export declare const All: { (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor): void; (route: string): MethodDecorator; }; /** * RequestMethodDecorators * Delete * * Examples * ``` * import { Controller, Delete } from '@tkrjs/Core' * @Controller('/') * export class IndexController{ * @Delete * private async index() { * // Request method Delete * return 'http://localhost:3000/index' * } * * @Delete * private async test() { * // Request method Delete * return 'http://localhost:3000/test' * } * * @Delete('api') * private async test1() { * // Request method Delete * return 'http://localhost:3000/api' * } * * @Delete('api/:id') * private async test1() { * // Request method Delete * // {id} Is any data * return 'http://localhost:3000/api/{id}' * } * } * ``` */ export declare const Delete: { (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor): void; (route: string): MethodDecorator; }; /** * RequestMethodDecorators * Head * * Examples * ``` * import { Controller, Head } from '@tkrjs/Core' * @Controller('/') * export class IndexController{ * @Head * private async index() { * // Request method Head * return 'http://localhost:3000/index' * } * * @Head * private async test() { * // Request method Head * return 'http://localhost:3000/test' * } * * @Head('api') * private async test1() { * // Request method Head * return 'http://localhost:3000/api' * } * * @Head('api/:id') * private async test1() { * // Request method Head * // {id} Is any data * return 'http://localhost:3000/api/{id}' * } * } * ``` */ export declare const Head: { (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor): void; (route: string): MethodDecorator; }; /** * RequestMethodDecorators * Options * * Examples * ``` * import { Controller, Options } from '@tkrjs/Core' * @Controller('/') * export class IndexController{ * @Options * private async index() { * // Request method Options * return 'http://localhost:3000/index' * } * * @Options * private async test() { * // Request method Options * return 'http://localhost:3000/test' * } * * @Options('api') * private async test1() { * // Request method Options * return 'http://localhost:3000/api' * } * * @Options('api/:id') * private async test1() { * // Request method Options * // {id} Is any data * return 'http://localhost:3000/api/{id}' * } * } * ``` */ export declare const Options: { (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor): void; (route: string): MethodDecorator; }; /** * RequestMethodDecorators * Patch * * Examples * ``` * import { Controller, Patch } from '@tkrjs/Core' * @Controller('/') * export class IndexController{ * @Patch * private async index() { * // Request method Patch * return 'http://localhost:3000/index' * } * * @Patch * private async test() { * // Request method Patch * return 'http://localhost:3000/test' * } * * @Patch('api') * private async test1() { * // Request method Patch * return 'http://localhost:3000/api' * } * * @Patch('api/:id') * private async test1() { * // Request method Patch * // {id} Is any data * return 'http://localhost:3000/api/{id}' * } * } * ``` */ export declare const Patch: { (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor): void; (route: string): MethodDecorator; }; /** * RequestMethodDecorators * Post * * Examples * ``` * import { Controller, Post } from '@tkrjs/Core' * @Controller('/') * export class IndexController{ * @Post * private async index() { * // Request method Post * return 'http://localhost:3000/index' * } * * @Post * private async test() { * // Request method Post * return 'http://localhost:3000/test' * } * * @Post('api') * private async test1() { * // Request method Post * return 'http://localhost:3000/api' * } * * @Post('api/:id') * private async test1() { * // Request method Post * // {id} Is any data * return 'http://localhost:3000/api/{id}' * } * } * ``` */ export declare const Post: { (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor): void; (route: string): MethodDecorator; }; /** * RequestMethodDecorators * Put * * Examples * ``` * import { Controller, Put } from '@tkrjs/Core' * @Controller('/') * export class IndexController{ * @Put * private async index() { * // Request method Put * return 'http://localhost:3000/index' * } * * @Put * private async test() { * // Request method Put * return 'http://localhost:3000/test' * } * * @Put('api') * private async test1() { * // Request method Put * return 'http://localhost:3000/api' * } * * @Put('api/:id') * private async test1() { * // Request method Put * // {id} Is any data * return 'http://localhost:3000/api/{id}' * } * } * ``` */ export declare const Put: { (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor): void; (route: string): MethodDecorator; }; export declare const Request: { (target: Object, propertyKey: string | symbol): void; (target: Object, propertyKey: string | symbol, parameterIndex: number): void; (field: string | object | string[]): ParameterDecorator; }; export declare const Response: { (target: Object, propertyKey: string | symbol): void; (target: Object, propertyKey: string | symbol, parameterIndex: number): void; (field: string | object | string[]): ParameterDecorator; }; /** * PropertyDecorator * * Examples * ``` * @Controller('/') * export class IndexController { * constructor() {} * @Database('users') db: TKServer.Database; * @Get('/') * private async index() { * return await this.db.select() * } * } * ``` */ export declare function Database(target: Object, propertyKey: string): void; export declare function Database(table: string): PropertyDecorator; export {};