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): ClassDecoratorControllerOptions
| Property | Type | Description |
|---|---|---|
prefix | string | Base URL path for all routes in this controller class. |
host | string | string[] | Subdomain or host restriction for this controller. |
cors | boolean | CorsConfig | Controller-scoped CORS configuration. |
tags | string[] | 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.
| Decorator | HTTP Method | Signature |
|---|---|---|
@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:
| Decorator | Signature | Description | Example |
|---|---|---|---|
@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
| Pipe | Options Interface | Description |
|---|---|---|
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
| Decorator | Target | Options / Arguments | Description |
|---|---|---|---|
@Use(...items) | Class / Method | (Handler | Guard | Interceptor | Filter)[] | Attaches middlewares, guards, interceptors, or filters. |
@UseGuards(...guards) | Class / Method | Guard[] | Attaches authorization guards (canActivate). |
@UseInterceptors(...interceptors) | Class / Method | Interceptor[] | Attaches response/request interceptors (intercept). |
@UseFilters(...filters) | Class / Method | Filter[] | Attaches exception filters (catch). |
@Catch(...exceptions) | Class | ErrorConstructor[] | Declares exception types handled by an ExceptionFilter. |
@Timeout(ms) | Class / Method | number | TimeoutOptions | Overrides request timeout threshold in ms (0 to disable). |
@RateLimit(options) | Class / Method | RateLimitOptions | Enforces rate limits on endpoints. |
@Cors(options) | Class / Method | CorsConfig | boolean | Enforces CORS configuration. |
@IpFilter(options) | Class / Method | IpFilterOptions | Enforces CIDR IP allow/deny lists. |
@Idempotent(options?) | Class / Method | IdempotencyOptions | Enables response caching via Idempotency-Key. |
@Dedupe(options?) | Class / Method | DedupeOptions | Deduplicates concurrent in-flight requests with identical keys. |
@BlockProbes(options?) | Class / Method | BlockProbesOptions | Blackholes malicious scanner probes (.env, wp-admin). |
@Upload(field, options?) | Method | string, FileUploadOptions | Configures multipart file upload streaming on the endpoint. |
5. Security & Access Control
| Decorator | Target | Arguments | Description |
|---|---|---|---|
@Permissions(...permissions) | Class / Method | string[] | Enforces required permission strings on the route. |
@Roles(...roles) | Class / Method | string[] | Enforces required user role strings on the route. |
@Public() / @IsPublic() | Class / Method | None | Bypasses global authentication guards. |
6. Response Modifiers & Metadata
| Decorator | Target | Signature | Description |
|---|---|---|---|
@HttpCode(code) | Method | (code: number) => MethodDecorator | Sets the default HTTP status code for successful responses. |
@Header(name, value) | Method | (name: string, value: string) => MethodDecorator | Injects a static HTTP response header. |
@Redirect(url, status?) | Method | (url: string, status?: number) => MethodDecorator | Redirects response to target URL. |
@Returns(schema) | Method | (schema: any) => MethodDecorator | Defines response schema for OpenAPI documentation. |
@Hosts(...hosts) | Class / Method | (...hosts: string[]) => any | Restricts route to specific host/subdomain headers. |
@SetMetadata(key, value) | Class / Method | (key: string, value: any) => any | Attaches custom metadata inspectable via Reflector. |
7. IoC, Dependency Injection & Modules
| Decorator | Target | Options | Description |
|---|---|---|---|
@Injectable(options?) | Class | { scope?: 'singleton' | 'request' | 'transient' } | Marks a class as an IoC provider managed by the container. |
@Inject(token) | Constructor / Property | ProviderToken<T> | Injects dependency by class, token string, or symbol. |
@Optional() | Constructor / Property | None | Allows unresolved dependencies to return undefined instead of throwing. |
@Module(metadata) | Class | ModuleMetadata | Declares an application module (imports, controllers, providers, exports). |
@Global() | Class | None | Makes module exports globally available without explicit importing. |
@Boundary(config) | Class | BoundaryConfig | Declares a folder-scoped boundary class. |
8. Caching, Transactions & Profiling
| Decorator | Target | Options | Description |
|---|---|---|---|
@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?) | Method | TransactionOptions | Wraps database queries within an atomic transaction. |
@Profile(options?) | Method | { thresholdMs?: number, warnSlow?: boolean } | Measures and logs method execution latency. |
9. Cron & Scheduling Decorators
| Decorator | Target | Signature | Description |
|---|---|---|---|
@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. |