import { type NextFunction } from "express"; /** * Wraps an Express request handler with tracing instrumentation. * * This utility function is intended to be used as a higher-order function to add tracing capabilities * to any standard Express handler. It leverages the `traceFn` function to automatically trace the * execution of the wrapped handler, capturing relevant telemetry for observability and debugging. * * The wrapped handler maintains the original signature and supports both synchronous and asynchronous * handlers. Any errors thrown by the handler will propagate as usual, allowing Express error handling * middleware to function as expected. * * @template TReq - The type of the Express request object. Defaults to `Request`. * @template TRes - The type of the Express response object. Defaults to `Response`. * @param handler - The original Express handler function to be wrapped. It can be synchronous or return a Promise. * @returns A new Express-compatible handler function with tracing instrumentation applied. * * @example * ```typescript * app.get('/endpoint', wrapExpressHandler(async (req, res) => { * // handler logic * })); * ``` * * @remarks * - The `traceFn` function must be defined in the scope and should handle the tracing logic. * - This wrapper is transparent to the handler's logic and does not alter request or response objects. */ export declare function wrapExpressHandler(handler: (req: TReq, res: TRes, next?: NextFunction) => void | Promise): (req: TReq, res: TRes, next?: NextFunction) => Promise; /** * Wraps all function properties of a given module object with tracing logic. * * This utility iterates over each property of the provided module object. If a property is a function, * it replaces it with an async wrapper that invokes the original function within a tracing context * using `traceFn`. Non-function properties are copied as-is. The returned object preserves the original * module's shape and types. * * @typeParam T - The type of the module object whose functions will be wrapped. * @param module - The module object whose function properties should be wrapped with tracing. * @returns A new object with the same properties as the input module, where all function properties * are wrapped with tracing logic. * * @remarks * - The tracing logic assumes that all function properties are asynchronous and return Promises. * - The original module object is not mutated; a new object is returned. * - Non-function properties are shallow-copied. * * @example * ```typescript * const tracedModule = wrapFunctionsWithTracing(myModule); * await tracedModule.someAsyncFunction(); * ``` */ export declare function wrapFunctionsWithTracing(module: T): T; /** * Wraps a class method with tracing logic, supporting both synchronous and asynchronous functions. * * This decorator factory intercepts method calls, invoking the provided `traceFn` utility to record * tracing information for each invocation. It ensures that both synchronous and asynchronous methods * are traced uniformly by always passing a Promise to `traceFn`. The original method's `this` context * and arguments are preserved. * * @template This - The type of the class instance (`this`) the method belongs to. * @template Args - The tuple type representing the method's argument list. * @template Return - The return type of the original method. * * @param target - The original method to be wrapped and traced. * @param context - The decorator context, providing metadata such as the method name. * @returns A replacement method that wraps the original method with tracing logic. * * @remarks * - The tracing is performed by the `traceFn` utility, which is expected to handle both sync and async flows. * - The method name is extracted from the decorator context and passed as metadata to `traceFn`. * - This utility is intended for use as a method decorator in class-based modules. * * @example * ```typescript * class MyService { * @traced * async fetchData(id: string): Promise { * // ... * } * } * ``` */ export declare function traced(target: (this: This, ...args: Args) => Return, context: ClassMethodDecoratorContext Return>): (this: This, ...args: Args) => Return; type Constructor = new (...args: any[]) => T; /** * A class decorator factory that wraps all methods of a given class with tracing logic. * * This higher-order function returns a new class that extends the provided `BaseClass`. * In the constructor of the new class, it iterates over all own property names of the prototype, * and for each method (excluding the constructor), it replaces the method with a wrapped version * that invokes the `traceFn` function. This enables automatic tracing of both async and sync methods. * * - Async methods are detected by checking if the method's constructor name is `"AsyncFunction"`. * - Both async and sync methods are wrapped such that their execution is traced, and the method name * is passed as metadata to the tracing function. * - The original method's `this` context and arguments are preserved. * * @template TBase - The type of the base class to be extended and wrapped. * @param BaseClass - The class whose methods should be wrapped with tracing logic. * @returns A new class extending `BaseClass` with all methods wrapped for tracing. * * @example * ```typescript * @TracedClass * class MyService { * async fetchData() { ... } * calculate() { ... } * } * or * const TracedService = TracedClass(MyService); * const service = new TracedService(); * // All method calls on `service` will be traced. * ``` * * @remarks * - The `traceFn` function must be defined in the module scope and should accept a function to execute * and an options object containing at least the method name. * - This decorator is intended for use in environments where method-level tracing is required for * observability or debugging purposes. * - The decorator assumes that all methods are either synchronous or asynchronous functions. */ export declare function TracedClass(BaseClass: TBase): TBase; export {};