UNPKG

@noony-serverless/core

Version:

A Middy base framework compatible with Firebase and GCP Cloud Functions with TypeScript

91 lines 2.66 kB
import Container from 'typedi'; /** * Framework-agnostic HTTP method enum */ export declare enum HttpMethod { GET = "GET", POST = "POST", PUT = "PUT", DELETE = "DELETE", PATCH = "PATCH", OPTIONS = "OPTIONS", HEAD = "HEAD" } /** * Framework-agnostic request interface that can work with any HTTP framework */ export interface NoonyRequest<T = unknown> { method: HttpMethod | string; url: string; path?: string; headers: Record<string, string | string[] | undefined>; query: Record<string, string | string[] | undefined>; params: Record<string, string>; body?: unknown; rawBody?: Buffer | string; parsedBody?: T; validatedBody?: T; ip?: string; userAgent?: string; } /** * Framework-agnostic response interface that can work with any HTTP framework */ export interface NoonyResponse { status(code: number): NoonyResponse; json(data: unknown): NoonyResponse | void; send(data: unknown): NoonyResponse | void; header(name: string, value: string): NoonyResponse; headers(headers: Record<string, string>): NoonyResponse; end(): void; statusCode?: number; headersSent?: boolean; } /** @deprecated Use NoonyRequest instead */ export type GenericRequest<T = unknown> = NoonyRequest<T>; /** @deprecated Use NoonyResponse instead */ export type GenericResponse = NoonyResponse; /** * Security configuration for request processing */ export interface SecurityConfig { maxBodySize?: number; maxDepth?: number; allowedContentTypes?: string[]; enableSanitization?: boolean; } /** * Handler configuration options */ export interface HandlerOptions { timeout?: number; middlewareTimeout?: number; security?: SecurityConfig; enableAsyncContext?: boolean; } /** * Represents the execution context for handling a request and response in an application. * * @template T Specifies the type of the custom request payload. */ export interface Context<T = unknown> { readonly req: NoonyRequest<T>; readonly res: NoonyResponse; container?: Container; error?: Error | null; readonly businessData: Map<string, unknown>; user?: unknown; readonly startTime: number; readonly requestId: string; timeoutSignal?: AbortSignal; responseData?: unknown; } /** * Utility function to generate unique request IDs */ export declare function generateRequestId(): string; /** * Creates a context object for framework-agnostic handlers */ export declare function createContext<T = unknown>(req: NoonyRequest<T>, res: NoonyResponse, options?: Partial<Context<T>>): Context<T>; //# sourceMappingURL=core.d.ts.map