hikma-engine
Version:
Code Knowledge Graph Indexer - A sophisticated TypeScript-based indexer that transforms Git repositories into multi-dimensional knowledge stores for AI agents
106 lines • 3.58 kB
TypeScript
/**
* @file Response formatting utilities for consistent API responses.
* Provides standardized response formatting with metadata injection.
*/
import { Request } from 'express';
import { SuccessAPIResponse, ErrorAPIResponse, CacheInfo } from '../types/responses';
/**
* Response formatter configuration options.
*/
interface ResponseFormatterOptions {
includeDebugInfo?: boolean;
includeCacheInfo?: boolean;
includePerformance?: boolean;
includeTimestamp?: boolean;
}
/**
* Response formatter class for creating standardized API responses.
*/
export declare class ResponseFormatter {
private options;
constructor(options?: ResponseFormatterOptions);
/**
* Creates a successful API response.
*/
success<T>(req: Request, data: T, startTime?: number, pagination?: {
page: number;
limit: number;
total?: number;
offset?: number;
}): SuccessAPIResponse<T>;
/**
* Creates an error API response.
*/
error(req: Request, code: string, message: string, statusCode?: number, details?: any, startTime?: number): ErrorAPIResponse;
/**
* Creates a paginated response with search results.
*/
paginatedResults<T>(req: Request, results: T[], pagination: {
page: number;
limit: number;
total?: number;
offset?: number;
}, startTime?: number, additionalData?: Record<string, any>): SuccessAPIResponse<{
results: T[];
} & Record<string, any>>;
/**
* Creates a health check response.
*/
healthCheck(req: Request, status: 'healthy' | 'unhealthy' | 'degraded', checks: Record<string, any>, startTime?: number): SuccessAPIResponse<any>;
/**
* Creates an extended response with additional metadata.
*/
extended<T>(req: Request, data: T, startTime?: number, extensions?: {
cache?: CacheInfo;
performance?: Record<string, number>;
debug?: Record<string, any>;
}): SuccessAPIResponse<T>;
}
/**
* Default response formatter instance.
*/
export declare const responseFormatter: ResponseFormatter;
/**
* Utility functions for quick response formatting.
*/
export declare const formatResponse: {
/**
* Quick success response.
*/
success: <T>(req: Request, data: T, startTime?: number) => SuccessAPIResponse<T>;
/**
* Quick error response.
*/
error: (req: Request, code: string, message: string, details?: any, startTime?: number) => ErrorAPIResponse;
/**
* Quick paginated response.
*/
paginated: <T>(req: Request, results: T[], page: number, limit: number, total?: number, startTime?: number) => SuccessAPIResponse<{
results: T[];
} & Record<string, any>>;
/**
* Quick health check response.
*/
health: (req: Request, status: "healthy" | "unhealthy" | "degraded", checks: Record<string, any>, startTime?: number) => SuccessAPIResponse<any>;
};
/**
* Middleware to inject timing information into responses.
*/
export declare function timingMiddleware(req: Request, res: any, next: Function): void;
/**
* Response compression utility for large responses.
*/
export declare function compressResponse(data: any): any;
/**
* Response validation utility to ensure responses meet API standards.
*/
export declare function validateResponse(response: any): {
valid: boolean;
errors: string[];
};
/**
* Response size calculator for monitoring.
*/
export declare function calculateResponseSize(response: any): number;
export {};
//# sourceMappingURL=response-formatter.d.ts.map