import { oRequest } from '../connection/o-request.js'; import { oResponse } from '../connection/o-response.js'; import { oError } from '../error/o-error.js'; /** * Response context for building responses with proper metadata */ export interface ResponseContext { /** Whether this is a streaming response */ isStream?: boolean; /** Whether this is the last chunk in a stream */ isLast?: boolean; /** Whether the operation was successful */ success?: boolean; /** Request ID for correlation */ requestId?: string | number; /** Connection ID from the request */ connectionId?: string | number; /** Request method for tracking */ requestMethod?: string | number; } /** * Middleware function that can intercept and transform responses */ export type ResponseMiddleware = (response: oResponse, context: ResponseContext) => oResponse | Promise; /** * Metrics tracker interface for extensible metrics tracking */ export interface MetricsTracker { trackSuccess(context: ResponseContext): void; trackError(context: ResponseContext, error: oError): void; } /** * Default metrics tracker that increments counters */ export declare class DefaultMetricsTracker implements MetricsTracker { private metrics; constructor(metrics: { successCount: number; errorCount: number; }); trackSuccess(context: ResponseContext): void; trackError(context: ResponseContext, error: oError): void; } /** * ResponseBuilder - Unified response generation for all Olane routing paths * * This class provides a single source of truth for creating responses across: * - Local execution (useSelf) * - Remote execution (use, useChild) * - Router forwarding (forward, executeSelfRouting) * - Streaming responses * * Features: * - Consistent error normalization * - Automatic metrics tracking * - Context-aware response building (streaming, success/error states) * - Extensible middleware system * * @example * ```typescript * const builder = new ResponseBuilder() * .withMetrics(node.metrics) * .use(loggingMiddleware); * * const response = await builder.build(request, result, error); * ``` */ export declare class ResponseBuilder { private middlewares; private metricsTracker?; /** * Add a middleware function to intercept responses */ use(middleware: ResponseMiddleware): this; /** * Configure metrics tracking * @param metrics The metrics object to track success/error counts */ withMetrics(metrics: { successCount: number; errorCount: number; }): this; /** * Configure custom metrics tracker * @param tracker Custom metrics tracker implementation */ withCustomMetrics(tracker: MetricsTracker): this; /** * Normalize any error into an oError instance * @param error The error to normalize * @returns An oError instance */ normalizeError(error: any): oError; /** * Build a complete response from a request and result * @param request The original request * @param result The result data (or error object) * @param error Optional error object * @param context Additional response context * @returns An oResponse instance */ build(request: oRequest, result: any, error?: any, context?: Partial): Promise; /** * Build a streaming chunk response * @param request The original request * @param chunkData The chunk data * @param context Additional response context * @returns An oResponse instance with _last: false */ buildChunk(request: oRequest, chunkData: any, context?: Partial): Promise; /** * Build the final chunk in a stream * @param request The original request * @param context Additional response context * @returns An oResponse instance with _last: true */ buildFinalChunk(request: oRequest, context?: Partial): Promise; /** * Build an error response * @param request The original request * @param error The error that occurred * @param context Additional response context * @returns An oResponse instance with error details */ buildError(request: oRequest, error: any, context?: Partial): Promise; /** * Execute a function and automatically build a response based on the outcome * @param request The request being executed * @param executor The function to execute * @param context Additional response context * @returns An oResponse instance */ execute(request: oRequest, executor: () => Promise, context?: Partial): Promise; /** * Create a new ResponseBuilder instance (for chaining) * @returns A new ResponseBuilder instance */ static create(): ResponseBuilder; } //# sourceMappingURL=response-builder.d.ts.map