ExisJS

exisjs/decorators

The exisjs/decorators module provides TypeScript decorators for Class-Based OOP architecture. It covers routing controllers, HTTP method endpoints, parameter injection, validation pipes, traffic control, security guards, caching, and application lifecycle hooks.


Module Exports Overview

import {  // Routing & Controllers  Controller,  Get,  Post,  Put,  Patch,  Delete,  Options,  Head,  All,
  // Parameter Injection  Body,  RawBody,  Param,  Query,  QueryParam,  Headers,  Req,  Res,  Next,  Ip,  Cookies,  Cookie,  State,  AppCtx,  Fields,  UploadedFile,  UploadedFiles,  createParamDecorator,
  // Pipeline, Middleware & Security  Use,  UseGuards,  UseInterceptors,  UseFilters,  UsePipes,  Catch,  RateLimit,  Cors,  IpFilter,  Timeout,  Idempotent,  Dedupe,  BlockProbes,  Upload,  Roles,  Permissions,  Public,  IsPublic,  AllowAnonymous,
  // Responses & Metadata  HttpCode,  Header,  Redirect,  Returns,  Hosts,  SetMetadata,  Reflector,
  // IoC, Modules & Boundaries  Injectable,  Inject,  Optional,  Module,  Global,  Boundary,  Server,
  // Caching, Transactions & Profiling  Cacheable,  CacheEvict,  Transactional,  Profile,
  // Cron & Scheduling  Cron,  Interval,  TimeoutTask,} from 'exisjs/decorators'

1. Controller & Routing

@Controller(prefixOrOptions?, options?)

Marks a class as an HTTP controller slice mounted at the specified route prefix.

function Controller(  prefixOrOptions?: string | ControllerOptions,  options?: ControllerOptions): ClassDecorator

ControllerOptions

PropertyTypeDescription
prefixstringBase URL path for all routes in this controller class.
hoststring | string[]Subdomain or host restriction for this controller.
corsboolean | CorsConfigController-scoped CORS configuration.
tagsstring[]OpenAPI / Swagger tags for documentation grouping.
import { Controller, Get } from 'exisjs/decorators'
@Controller('/users')export default class UserController {  @Get('/')  async list() {    return { users: [] }  }}

HTTP Method Decorators

Method decorators register class methods as HTTP route handlers and attach validation schemas.

DecoratorHTTP MethodSignature
@Get(path?, schema?)GET(path?: string, schema?: MethodSchemaInput) => MethodDecorator
@Post(path?, schema?)POST(path?: string, schema?: MethodSchemaInput) => MethodDecorator
@Put(path?, schema?)PUT(path?: string, schema?: MethodSchemaInput) => MethodDecorator
@Patch(path?, schema?)PATCH(path?: string, schema?: MethodSchemaInput) => MethodDecorator
@Delete(path?, schema?)DELETE(path?: string, schema?: MethodSchemaInput) => MethodDecorator
@Options(path?, schema?)OPTIONS(path?: string, schema?: MethodSchemaInput) => MethodDecorator
@Head(path?, schema?)HEAD(path?: string, schema?: MethodSchemaInput) => MethodDecorator
@All(path?, schema?)Any Method(path?: string, schema?: MethodSchemaInput) => MethodDecorator
DEFAULT

Server-Sent Events use a normal @Get route that calls res.sse(); see Responses. WebSocket routes are not part of the class decorators.


2. Parameter Injectors

Parameter decorators extract and inject typed data directly into handler method arguments:

DecoratorSignatureDescriptionExample
@Body(property?, ...pipes)(prop?: string, ...pipes: Pipe[])Injects parsed request body or subfield.@Body() dto: CreateUserDto
@RawBody(encoding?)(encoding?: 'string' | 'utf8' | { encoding: string })Injects unparsed raw Buffer or string.@RawBody() payload: Buffer
@Param(key?, ...pipes)(key?: string, ...pipes: Pipe[])Injects URL path parameter.@Param('id', ParseIntPipe) id: number
@Query(key?, ...pipes)(key?: string, ...pipes: Pipe[])Injects query string parameter or dictionary.@Query('page') page: number
@Headers(name?, ...pipes)(name?: string, ...pipes: Pipe[])Injects HTTP request header.@Headers('authorization') auth: string
@Cookies(name?, ...pipes)(name?: string, ...pipes: Pipe[])Injects parsed cookie value or record.@Cookies('session') sid: string
@State(key?, ...pipes)(key?: string, ...pipes: Pipe[])Injects request state dictionary or property.@State('user') user: User
@UploadedFile(field?)(field?: string)Injects single uploaded file object.@UploadedFile('avatar') file: ExisFile
@UploadedFiles(field?)(field?: string)Injects multiple uploaded files.@UploadedFiles('docs') files: ExisFile[]
@Req()()Injects underlying ExisRequest.@Req() req: Request
@Res(options?)(opts?: { passthrough?: boolean })Injects underlying ExisResponse.@Res() res: Response
@Next()()Injects pipeline NextFunction.@Next() next: NextFunction
@Ip()()Injects client IP address string.@Ip() ip: string
@AppCtx()()Injects root Exis application instance.@AppCtx() app: App

createParamDecorator(factory)

Factory to create reusable custom parameter decorators:

import { createParamDecorator } from 'exisjs/decorators'
export const CurrentUser = createParamDecorator((data: string | undefined, ctx) => {  const req = ctx.req  return data ? req.user?.[data] : req.user})

3. Transformation & Validation Pipes

PipeOptions InterfaceDescription
ParseIntPipe{ errorHttpStatusCode?: number }Parses string to integer, throwing 400 if invalid.
ParseFloatPipe{ errorHttpStatusCode?: number }Parses string to floating point number.
ParseBoolPipe{ errorHttpStatusCode?: number }Parses "true", "false", 1, 0 to boolean.
ParseUUIDPipe{ version?: '1' | '4' | 'all' }Validates UUID strings.
ParseArrayPipe{ items?: Pipe, separator?: string }Splits comma-separated strings and applies item pipes.
ValidationPipe{ transform?: boolean }Validates DTO classes using schema assertions.

4. Pipeline & Middleware Decorators

DecoratorTargetOptions / ArgumentsDescription
@Use(...items)Class / Method(Handler | Guard | Interceptor | Filter)[]Attaches middlewares, guards, interceptors, or filters.
@UseGuards(...guards)Class / MethodGuard[]Attaches authorization guards (canActivate).
@UseInterceptors(...interceptors)Class / MethodInterceptor[]Attaches response/request interceptors (intercept).
@UseFilters(...filters)Class / MethodFilter[]Attaches exception filters (catch).
@Catch(...exceptions)ClassErrorConstructor[]Declares exception types handled by an ExceptionFilter.
@Timeout(ms)Class / Methodnumber | TimeoutOptionsOverrides request timeout threshold in ms (0 to disable).
@RateLimit(options)Class / MethodRateLimitOptionsEnforces rate limits on endpoints.
@Cors(options)Class / MethodCorsConfig | booleanEnforces CORS configuration.
@IpFilter(options)Class / MethodIpFilterOptionsEnforces CIDR IP allow/deny lists.
@Idempotent(options?)Class / MethodIdempotencyOptionsEnables response caching via Idempotency-Key.
@Dedupe(options?)Class / MethodDedupeOptionsDeduplicates concurrent in-flight requests with identical keys.
@BlockProbes(options?)Class / MethodBlockProbesOptionsBlackholes malicious scanner probes (.env, wp-admin).
@Upload(field, options?)Methodstring, FileUploadOptionsConfigures multipart file upload streaming on the endpoint.

5. Security & Access Control

DecoratorTargetArgumentsDescription
@Permissions(...permissions)Class / Methodstring[]Enforces required permission strings on the route.
@Roles(...roles)Class / Methodstring[]Enforces required user role strings on the route.
@Public() / @IsPublic()Class / MethodNoneBypasses global authentication guards.

6. Response Modifiers & Metadata

DecoratorTargetSignatureDescription
@HttpCode(code)Method(code: number) => MethodDecoratorSets the default HTTP status code for successful responses.
@Header(name, value)Method(name: string, value: string) => MethodDecoratorInjects a static HTTP response header.
@Redirect(url, status?)Method(url: string, status?: number) => MethodDecoratorRedirects response to target URL.
@Returns(schema)Method(schema: any) => MethodDecoratorDefines response schema for OpenAPI documentation.
@Hosts(...hosts)Class / Method(...hosts: string[]) => anyRestricts route to specific host/subdomain headers.
@SetMetadata(key, value)Class / Method(key: string, value: any) => anyAttaches custom metadata inspectable via Reflector.

7. IoC, Dependency Injection & Modules

DecoratorTargetOptionsDescription
@Injectable(options?)Class{ scope?: 'singleton' | 'request' | 'transient' }Marks a class as an IoC provider managed by the container.
@Inject(token)Constructor / PropertyProviderToken<T>Injects dependency by class, token string, or symbol.
@Optional()Constructor / PropertyNoneAllows unresolved dependencies to return undefined instead of throwing.
@Module(metadata)ClassModuleMetadataDeclares an application module (imports, controllers, providers, exports).
@Global()ClassNoneMakes module exports globally available without explicit importing.
@Boundary(config)ClassBoundaryConfigDeclares a folder-scoped boundary class.

8. Caching, Transactions & Profiling

DecoratorTargetOptionsDescription
@Cacheable(options)Method{ ttl?: number, key?: string | ((...args) => string) }Caches method return value in a bounded in-memory cache.
@CacheEvict(options)Method{ key: string | ((...args) => string) }Evicts cached keys upon successful method execution.
@Transactional(options?)MethodTransactionOptionsWraps database queries within an atomic transaction.
@Profile(options?)Method{ thresholdMs?: number, warnSlow?: boolean }Measures and logs method execution latency.

9. Cron & Scheduling Decorators

DecoratorTargetSignatureDescription
@Cron(schedule, options?)Method(schedule: string, options?: CronOptions)Schedules method to run according to a standard 5-part cron expression.
@Interval(ms, options?)Method(ms: number, options?: IntervalOptions)Schedules method to execute repeatedly every ms milliseconds.
@TimeoutTask(ms, options?)Method(ms: number, options?: TimeoutOptions)Schedules method to execute once after ms milliseconds following boot.