@gabliam/web-core
Version:
Gabliam plugin for add web-core
438 lines (437 loc) • 10.9 kB
TypeScript
import { Type } from '@gabliam/core';
import { ExecutionContext } from '../execution-context';
import { GabContext } from '../gab-context';
/**
* Represent the handler for extract the parameter
*
* args : Arguments passed to decorator
* ctx: GabContext
* type: type of parameters (ex @Query('nb) nb: number, type = Number)
* execCtx: ExecutionContext
* next: next function
*/
export type HandlerFn = <V>(args: any, ctx: GabContext, type: Type<any> | undefined, execCtx: ExecutionContext | null | undefined, next: V) => any;
export interface WebParamDecorator<T = any> {
/**
* Hander for extract the param
*/
handler: HandlerFn;
/**
* Arguments passed to decorator
*/
args: T[];
/**
* Type of decorator for introspection of parameters (swagger by ex)
*/
type: string;
}
/**
* Function for create you own param decorator
* @usageNotes
*
* You must passed a type and the handler
* Type is mandatory, this param is used for introspection of parameters (swagger by ex)
*
* Sample to extract the user in query
*
* ```typescript
* const User = makeWebParamDecorator('user', (args, ctx) => ctx.request.user)
*
* @Controller('/')
* class SampleController {
* @Get('/')
* hello(@User() user: UserModel) {
* return 'Hello';
* }
* }
* ```
*/
export declare const makeWebParamDecorator: (type: string, handler: HandlerFn) => any;
/**
* Type of the `ExecContext` decorator / constructor function.
*/
export interface ExecContextDecorator {
/**
* Decorator that marks a parameter to inject ExecContext
*
* @usageNotes
*
* ```typescript
* @Controller('/')
* class SampleController {
* @Get('/')
* hello(@ExecContext() execCtx: ExecContext) {
* return 'Hello';
* }
* }
* ```
*/
(): ParameterDecorator;
/**
* see the `@ExecContext` decorator.
*/
new (): any;
}
export declare const ExecContext: ExecContextDecorator;
/**
* Type of the `Context` decorator / constructor function.
*/
export interface ContextDecorator {
/**
* Decorator that marks a parameter to inject Context
*
* @usageNotes
* You can supply an optional path to extract a part of Context.
* Under the hood, use lodash.get
*
* Example with full Context
*
* ```typescript
* @Controller('/')
* class SampleController {
* @Get('/')
* hello(@Context() ctx: GabContext) {
* return 'Hello';
* }
* }
* ```
*
* Example with part of Context
*
* ```typescript
* @Controller('/')
* class SampleController {
* @Get('/')
* hello(@Context('protocol') protocol: string) {
* return 'Hello';
* }
* }
* ```
*/
(path?: string): ParameterDecorator;
/**
* see the `@Context` decorator.
*/
new (path?: string): any;
}
export declare const Context: ContextDecorator;
/**
* Type of the `Request` decorator / constructor function.
*/
export interface RequestDecorator {
/**
* Decorator that marks a parameter to inject Request
*
* @usageNotes
* You can supply an optional path to extract a part of Request.
* Under the hood, use lodash.get
*
* Example with full Request
*
* ```typescript
* @Controller('/')
* class SampleController {
* @Get('/')
* hello(@Request() request: GabRequest) {
* return 'Hello';
* }
* }
* ```
*
* Example with part of Request
*
* ```typescript
* @Controller('/')
* class SampleController {
* @Get('/')
* hello(@Request('fresh') fresh: boolean) {
* return 'Hello';
* }
* }
* ```
*/
(path?: string): ParameterDecorator;
/**
* see the `@Request` decorator.
*/
new (path?: string): any;
}
export declare const Request: RequestDecorator;
/**
* Type of the `Response` decorator / constructor function.
*/
export interface ResponseDecorator {
/**
* Decorator that marks a parameter to inject Response
*
* @usageNotes
* You can supply an optional path to extract a part of Response.
* Under the hood, use lodash.get
*
* Example with full Response
*
* ```typescript
* @Controller('/')
* class SampleController {
* @Get('/')
* hello(@Response() response: GabResponse) {
* return 'Hello';
* }
* }
* ```
*
* Example with part of Response
*
* ```typescript
* @Controller('/')
* class SampleController {
* @Get('/')
* hello(@Response('headersSent') headersSent: boolean) {
* return 'Hello';
* }
* }
* ```
*/
(path?: string): ParameterDecorator;
/**
* see the `@Response` decorator.
*/
new (path?: string): any;
}
export declare const Response: ResponseDecorator;
/**
* Type of the `RequestParam` decorator / constructor function.
*/
export interface RequestParamDecorator {
/**
* Decorator that marks a parameter to inject RequestParam (context.request.params object)
*
* @usageNotes
* You can supply an optional path to extract a part of RequestParam.
* Under the hood, use lodash.get
*
* Example with full RequestParam
*
* ```typescript
* @Controller('/')
* class SampleController {
* @Get('/:id')
* get(@RequestParam() params: any) {
* return 'Hello';
* }
* }
* ```
*
* Example with part of RequestParam
*
* ```typescript
* @Controller('/')
* class SampleController {
* @Get('/:id')
* get(@RequestParam('id') id: string) {
* return 'Hello';
* }
* }
* ```
*/
(path?: string): ParameterDecorator;
/**
* see the `@RequestParam` decorator.
*/
new (path?: string): any;
}
export declare const RequestParam: RequestParamDecorator;
/**
* Type of the `QueryParam` decorator / constructor function.
*/
export interface QueryParamDecorator {
/**
* Decorator that marks a parameter to inject QueryParam (context.request.query object)
*
* @usageNotes
* You can supply an optional path to extract a part of QueryParam.
* Under the hood, use lodash.get
*
* Example with full QueryParam
*
* ```typescript
* @Controller('/')
* class SampleController {
* @Get('/:id')
* get(@QueryParam() query: any) {
* return 'Hello';
* }
* }
* ```
*
* Example with part of QueryParam
*
* ```typescript
* @Controller('/')
* class SampleController {
* @Get('/:id')
* get(@QueryParam('test') test: string) {
* return 'Hello';
* }
* }
* ```
*/
(path?: string): ParameterDecorator;
/**
* see the `@QueryParam` decorator.
*/
new (path?: string): any;
}
export declare const QueryParam: QueryParamDecorator;
/**
* Type of the `RequestBody` decorator / constructor function.
*/
export interface RequestBodyDecorator {
/**
* Decorator that marks a parameter to inject RequestBody (context.request.body object)
*
* @usageNotes
* You can supply an optional path to extract a part of RequestBody.
* Under the hood, use lodash.get
*
* Example with full RequestBody
*
* ```typescript
* @Controller('/')
* class SampleController {
* @Get('/:id')
* get(@RequestBody() body: any) {
* return 'Hello';
* }
* }
* ```
*
* Example with part of RequestBody
*
* ```typescript
* @Controller('/')
* class SampleController {
* @Get('/:id')
* get(@RequestBody('test') test: string) {
* return 'Hello';
* }
* }
* ```
*/
(path?: string): ParameterDecorator;
/**
* see the `@RequestBody` decorator.
*/
new (path?: string): any;
}
export declare const RequestBody: RequestBodyDecorator;
/**
* Type of the `RequestHeaders` decorator / constructor function.
*/
export interface RequestHeadersDecorator {
/**
* Decorator that marks a parameter to inject RequestHeaders (context.request.headers object)
*
* @usageNotes
* You can supply an optional path to extract a part of RequestHeaders.
* Under the hood, use lodash.get
*
* Example with full RequestHeaders
*
* ```typescript
* @Controller('/')
* class SampleController {
* @Get('/:id')
* get(@RequestHeaders() headers: any) {
* return 'Hello';
* }
* }
* ```
*
* Example with part of RequestHeaders
*
* ```typescript
* @Controller('/')
* class SampleController {
* @Get('/:id')
* get(@RequestHeaders('test') test: string) {
* return 'Hello';
* }
* }
* ```
*/
(path?: string): ParameterDecorator;
/**
* see the `@RequestHeaders` decorator.
*/
new (path?: string): any;
}
export declare const RequestHeaders: RequestHeadersDecorator;
/**
* Type of the `Cookies` decorator / constructor function.
*/
export interface CookiesDecorator {
/**
* Decorator that marks a parameter to inject Cookies (context.request.headers object)
*
* @usageNotes
* You can supply an optional path to extract a part of Cookies.
* Under the hood, use lodash.get
*
* Example with full Cookies
*
* ```typescript
* @Controller('/')
* class SampleController {
* @Get('/:id')
* get(@Cookies() headers: any) {
* return 'Hello';
* }
* }
* ```
*
* Example with part of Cookies
*
* ```typescript
* @Controller('/')
* class SampleController {
* @Get('/:id')
* get(@Cookies('test') test: string) {
* return 'Hello';
* }
* }
* ```
*/
(path?: string): ParameterDecorator;
/**
* see the `@Cookies` decorator.
*/
new (path?: string): any;
}
export declare const Cookies: CookiesDecorator;
/**
* Type of the `Next` decorator / constructor function.
*/
export interface NextDecorator {
/**
* Decorator that marks a parameter to inject Next function
*
* @usageNotes
*
* ```typescript
* @Controller('/')
* class SampleController {
* @Get('/')
* hello(@Next() next: any) {
* next();
* }
* }
* ```
*/
(): ParameterDecorator;
/**
* see the `@Next` decorator.
*/
new (): any;
}
export declare const Next: NextDecorator;