@kenniy/godeye-data-contracts
Version:
Enterprise-grade base repository architecture for GOD-EYE microservices with zero overhead and maximum code reuse
71 lines (70 loc) • 3.15 kB
TypeScript
import { IResponse, IResponseMetadata, IPaginatedData } from "../types/response.types";
/**
* ResponseFactory - Standardized response creation across all services
*
* This factory ensures consistent response format throughout the entire
* microservices ecosystem while providing performance monitoring capabilities.
*/
export declare class ResponseFactory {
/**
* Create a successful response with auto-detection
* Automatically detects if data is paginated and formats accordingly
*/
static success<T>(data: T, message?: string, metadata?: Partial<IResponseMetadata>, start_time?: number): IResponse<T>;
/**
* BLAZING FAST: Create paginated response with pre-computed values
* Optimized for maximum performance with minimal calculations
*/
static paginated<T>(items: T[], total: number, page: number, limit: number, message?: string, metadata?: Partial<IResponseMetadata>, start_time?: number): IResponse<IPaginatedData<T>>;
/**
* Create an error response
*/
static error(error: string, message: string, status_code?: number, metadata?: Partial<IResponseMetadata>, start_time?: number): IResponse<never>;
/**
* 400 Bad Request
*/
static badRequest(message: string, error?: string, metadata?: Partial<IResponseMetadata>, start_time?: number): IResponse<never>;
/**
* 401 Unauthorized
*/
static unauthorized(message?: string, metadata?: Partial<IResponseMetadata>, start_time?: number): IResponse<never>;
/**
* 403 Forbidden
*/
static forbidden(message?: string, metadata?: Partial<IResponseMetadata>, start_time?: number): IResponse<never>;
/**
* 404 Not Found
*/
static notFound(message?: string, metadata?: Partial<IResponseMetadata>, start_time?: number): IResponse<never>;
/**
* 422 Validation Error
*/
static validationError(message: string, validation_errors: string[], metadata?: Partial<IResponseMetadata>, start_time?: number): IResponse<never>;
/**
* 429 Rate Limited
*/
static rateLimited(message?: string, rate_limit_remaining?: number, metadata?: Partial<IResponseMetadata>, start_time?: number): IResponse<never>;
/**
* 500 Internal Server Error
*/
static serverError(message?: string, metadata?: Partial<IResponseMetadata>, start_time?: number): IResponse<never>;
/**
* Auto-detect if data is paginated by checking for various pagination formats
* Supports multiple common pagination patterns
*/
private static isPaginatedData;
/**
* Extract pagination data from various formats
* Normalizes different pagination structures to standard format
*/
private static extractPaginationData;
/**
* Get current system performance metrics
* Call this to automatically populate performance metadata
*/
static getPerformanceMetrics(): Partial<IResponseMetadata>;
/**
* Create response with automatic performance monitoring
*/
static successWithMetrics<T>(data: T, message?: string, custom_metadata?: Partial<IResponseMetadata>, start_time?: number): IResponse<T>;
}