@pulzar/core
Version:
Next-generation Node.js framework for ultra-fast web applications with zero-reflection DI, GraphQL, WebSockets, events, and edge runtime support
46 lines • 1.76 kB
TypeScript
import type { FastifyReply, FastifyRequest } from "fastify";
export interface ApiResponse<T = any> {
success: boolean;
data?: T;
error?: string;
message?: string;
meta?: {
timestamp: string;
path: string;
duration?: number;
[key: string]: any;
};
}
export interface PaginatedResponse<T = any> extends ApiResponse<T[]> {
pagination: {
page: number;
limit: number;
total: number;
pages: number;
hasNext: boolean;
hasPrev: boolean;
};
}
export declare class ResponseWrapper {
private reply;
private request;
private startTime;
constructor(reply: FastifyReply, request: FastifyRequest);
success<T>(data: T, message?: string, meta?: Record<string, any>): void;
error(error: string | Error, statusCode?: number, meta?: Record<string, any>): void;
paginated<T>(data: T[], page: number, limit: number, total: number, message?: string, meta?: Record<string, any>): void;
created<T>(data: T, message?: string): void;
noContent(): void;
notFound(message?: string): void;
badRequest(message?: string): void;
unauthorized(message?: string): void;
forbidden(message?: string): void;
conflict(message?: string): void;
unprocessableEntity(message?: string): void;
tooManyRequests(message?: string): void;
internalServerError(message?: string): void;
}
export declare function wrapResponse(reply: FastifyReply, request: FastifyRequest): ResponseWrapper;
export declare function responseWrapperHook(request: FastifyRequest, reply: FastifyReply): void;
export declare function registerResponseWrapperPlugin(fastify: import("fastify").FastifyInstance): void;
//# sourceMappingURL=responseWrapper.d.ts.map