arvox-backend
Version:
Un framework backend moderne et modulaire basé sur Hono, TypeScript et l'architecture hexagonale avec authentification Better Auth + Drizzle intégrée
138 lines • 3.56 kB
TypeScript
/**
* Utility class for standardizing API responses
*/
export declare class ResponseUtil {
/**
* Create a successful response
* @param data - Data to return
* @param status - HTTP status code
* @returns Response object with JSON and status
*/
success<T>(data: T, status?: number): {
json: {
success: boolean;
data: T;
};
status: number;
};
/**
* Create an error response
* @param error - Error message or Error object
* @param status - HTTP status code
* @returns Response object with JSON and status
*/
error(error: string | Error, status?: number): {
json: {
success: boolean;
error: string;
};
status: number;
};
/**
* Create a paginated response
* @param items - Array of items
* @param total - Total count
* @param page - Current page
* @param limit - Items per page
* @param status - HTTP status code
* @returns Paginated response object
*/
paginated<T>(items: T[], total: number, page: number, limit: number, status?: number): {
json: {
success: boolean;
data: {
items: T[];
pagination: {
total: number;
page: number;
limit: number;
totalPages: number;
hasNext: boolean;
hasPrev: boolean;
};
};
};
status: number;
};
/**
* Create a validation error response
* @param errors - Validation errors
* @param status - HTTP status code
* @returns Validation error response
*/
validationError(errors: Array<{
field: string;
message: string;
}>, status?: number): {
json: {
success: boolean;
error: string;
details: {
field: string;
message: string;
}[];
};
status: number;
};
/**
* Create a not found response
* @param resource - Resource that was not found
* @returns Not found response
*/
notFound(resource?: string): {
json: {
success: boolean;
error: string;
};
status: number;
};
/**
* Create an unauthorized response
* @param message - Optional custom message
* @returns Unauthorized response
*/
unauthorized(message?: string): {
json: {
success: boolean;
error: string;
};
status: number;
};
/**
* Create a forbidden response
* @param message - Optional custom message
* @returns Forbidden response
*/
forbidden(message?: string): {
json: {
success: boolean;
error: string;
};
status: number;
};
/**
* Create a conflict response
* @param message - Conflict message
* @returns Conflict response
*/
conflict(message: string): {
json: {
success: boolean;
error: string;
};
status: number;
};
/**
* Create a server error response
* @param message - Error message
* @returns Server error response
*/
serverError(message?: string): {
json: {
success: boolean;
error: string;
};
status: number;
};
}
//# sourceMappingURL=response.util.d.ts.map