/** * Interceptor decorators (@Guard, @Transform, @Intercept) * * All three decorators have unified semantics: * - @Guard is sugar for @Intercept({ request: guardFn }) * - @Transform is sugar for @Intercept({ response: transformFn }) * - @Intercept provides full control over both request and response */ import type { IInterceptOptions, IGuardOptions, TGuardFunction, TResponseInterceptor } from '../core/smartserve.interfaces.js'; /** * @Guard decorator - validates requests before handler execution * * Guards return boolean: true to allow, false to reject with 403 Forbidden * * @example * ```typescript * // Single guard * @Guard(isAuthenticated) * * // Multiple guards (all must pass) * @Guard([isAuthenticated, hasRole('admin')]) * * // With custom rejection response * @Guard(isAuthenticated, { * onReject: () => new Response('Unauthorized', { status: 401 }) * }) * ``` */ export declare function Guard(guardOrGuards: TGuardFunction | TGuardFunction[], options?: IGuardOptions): (target: any, context: ClassDecoratorContext | ClassMethodDecoratorContext) => any; /** * @Transform decorator - modifies response after handler execution * * @example * ```typescript * // Single transform * @Transform(data => ({ success: true, data })) * * // Multiple transforms (applied in order) * @Transform([addTimestamp, wrapResponse]) * ``` */ export declare function Transform(transformOrTransforms: TResponseInterceptor | TResponseInterceptor[]): (target: any, context: ClassDecoratorContext | ClassMethodDecoratorContext) => any; /** * @Intercept decorator - full control over request and response interception * * @example * ```typescript * @Intercept({ * request: async (ctx) => { * ctx.state.startTime = Date.now(); * return ctx; * }, * response: (res, ctx) => ({ * ...res, * duration: Date.now() - ctx.state.startTime * }) * }) * ``` */ export declare function Intercept(options: IInterceptOptions): (target: any, context: ClassDecoratorContext | ClassMethodDecoratorContext) => any; /** * Create a guard that checks for a specific header */ export declare function hasHeader(headerName: string, expectedValue?: string): TGuardFunction; /** * Create a guard that checks for Bearer token */ export declare function hasBearerToken(): TGuardFunction; /** * Create a rate limiting guard */ export declare function rateLimit(maxRequests: number, windowMs: number): TGuardFunction; /** * Wrap response in a success envelope */ export declare function wrapSuccess(data: T): { success: true; data: T; }; /** * Add timestamp to response */ export declare function addTimestamp(data: T): T & { timestamp: number; };