Options
All
  • Public
  • Public/Protected
  • All
Menu

@tosee/misc

Index

Variables

Body

Body: Function = ...

Http Params Decorator

example
    
@POST("/transform")
@Validate({
schema: Trans,
error: (err) => {
throw "validateerror";
}
}, ValidateType.Body)
async transform(@Body body: Trans) {
return new Response(200, null, success);
}

Ctx

Ctx: Function = ...

Http Params Decorator

example
    
@POST("/transform")
async transform(@Ctx ctx: Koa.Context) {
return new Response(200, null, success);
}

Headers

Headers: Function = ...

Http Params Decorator

example
    
@POST("/transform")
@Validate({
schema: Trans,
error: (err) => {
throw "validateerror";
}
}, ValidateType.Headers)
async transform(@Headers headers: Trans) {
return new Response(200, null, success);
}

Params

Params: Function = ...

Http Params Decorator

example
    
@POST("/transform")
@Validate({
schema: Trans,
error: (err) => {
throw "validateerror";
}
}, ValidateType.QueryParams)
async transform(@Params params: Trans) {
return new Response(200, null, success);
}

Query

Query: Function = ...

Http Params Decorator

example
    
@POST("/transform")
@Validate({
schema: Trans,
error: (err) => {
throw "validateerror";
}
}, ValidateType.QueryParams)
async transform(@Query query: Trans) {
return new Response(200, null, success);
}

logger

logger: Logger = ...

Functions

Const Controller

  • Controller(path?: string): ClassDecorator
  • Controller Decorator

    example
        
    @Controller('/prefix')
    export default class Router {
    }

    Parameters

    • Optional path: string

      router prefix

    Returns ClassDecorator

DELETE

  • DELETE(path: string | RegExp): (target: Object, key: string, descriptor: TypedPropertyDescriptor<Function>) => void
  • Http Method Decorator

    example
        
    @Controller('/prefix')
    export default class Router {
    @DELETE("/test")
    test(@Ctx ctx){
    return new Response(200,null,"hello world");
    }
    }

    Parameters

    • path: string | RegExp

      path

    Returns (target: Object, key: string, descriptor: TypedPropertyDescriptor<Function>) => void

      • (target: Object, key: string, descriptor: TypedPropertyDescriptor<Function>): void
      • Parameters

        • target: Object
        • key: string
        • descriptor: TypedPropertyDescriptor<Function>

        Returns void

GET

  • GET(path: string | RegExp): (target: Object, key: string, descriptor: TypedPropertyDescriptor<Function>) => void
  • Http Method Decorator

    example
        
    @Controller('/prefix')
    export default class Router {
    @Get("/test")
    test(@Ctx ctx){
    return new Response(200,null,"hello world");
    }
    }

    Parameters

    • path: string | RegExp

      router prefix

    Returns (target: Object, key: string, descriptor: TypedPropertyDescriptor<Function>) => void

      • (target: Object, key: string, descriptor: TypedPropertyDescriptor<Function>): void
      • Parameters

        • target: Object
        • key: string
        • descriptor: TypedPropertyDescriptor<Function>

        Returns void

POST

  • POST(path: string | RegExp): (target: Object, key: string, descriptor: TypedPropertyDescriptor<Function>) => void
  • Http Method Decorator

    example
        
    @Controller('/prefix')
    export default class Router {
    @POST("/test")
    test(@Ctx ctx){
    return new Response(200,null,"hello world");
    }
    }

    Parameters

    • path: string | RegExp

      path

    Returns (target: Object, key: string, descriptor: TypedPropertyDescriptor<Function>) => void

      • (target: Object, key: string, descriptor: TypedPropertyDescriptor<Function>): void
      • Parameters

        • target: Object
        • key: string
        • descriptor: TypedPropertyDescriptor<Function>

        Returns void

PUT

  • PUT(path: string | RegExp): (target: Object, key: string, descriptor: TypedPropertyDescriptor<Function>) => void
  • Http Method Decorator

    example
        
    @Controller('/prefix')
    export default class Router {
    @PUT("/test")
    test(@Ctx ctx){
    return new Response(200,null,"hello world");
    }
    }

    Parameters

    • path: string | RegExp

      path

    Returns (target: Object, key: string, descriptor: TypedPropertyDescriptor<Function>) => void

      • (target: Object, key: string, descriptor: TypedPropertyDescriptor<Function>): void
      • Parameters

        • target: Object
        • key: string
        • descriptor: TypedPropertyDescriptor<Function>

        Returns void

Validate

  • Validate(ValidateOptions: { options?: ValidatorOptions; schema: any; error?: any }, type?: ValidateType): MethodDecorator
  • use class-validator to validate request object

    example

    class Test{
    @IsBoolean()
    test:Boolean;
    }

    export class Router{
    @GET('/test')
    @Validate({schema:Test,error:(errors)=> {
    throw new Error(`${errors.map(error=>Object.values(error.constraints))}`)
    })
    async test(){
    ctx.body = 'origin';
    }
    }

    Parameters

    • ValidateOptions: { options?: ValidatorOptions; schema: any; error?: any }
      • Optional options?: ValidatorOptions
      • schema: any
      • error?:function
        • error(errors: ValidationError[]): any
    • Optional type: ValidateType

    Returns MethodDecorator

Generated using TypeDoc