import { Disposable } from './disposable'; import { ObservableValue } from './observable-value'; /** * Options object for tracing method calls */ export interface TraceMethodOptions any, TArgs extends any[]> { /** * The context object. Can be an instance or a constructor for static methods */ object: T; /** * The method reference that needs to be traced */ method: TMethod; /** * Unique identifier for the method */ methodName: string; /** * Callback that will be called right before executing the method */ onCalled?: (newValue: TraceMethodCall) => void; /** * Callback that will be called right after the method returns */ onFinished?: (newValue: TraceMethodFinished, TArgs>) => void; /** * Callback that will be called when a method throws an error */ onError?: (newValue: TraceMethodError) => void; /** * The method execution will be awaited if set */ isAsync?: boolean; } /** * Defines a trace method call object */ export interface TraceMethodCall { /** * The timestamp when the event occured */ startDateTime: Date; /** * The provided arguments for the call */ methodArguments: TArgs; } /** * Defines a trace event when a method call has been finished */ export interface TraceMethodFinished extends TraceMethodCall { returned: TReturns; finishedDateTime: Date; } /** * Defines a trace event when an error was thrown during a method call */ export interface TraceMethodError extends TraceMethodCall { error: any; errorDateTime: Date; } /** * Defines a method mapping object */ export interface MethodMapping { /** * The original method instance */ originalMethod: (...args: TArgs) => TReturns; /** * An observable for distributing the events */ callObservable: ObservableValue>; finishedObservable: ObservableValue>; errorObservable: ObservableValue>; } /** * Defines an Object Trace mapping */ export interface ObjectTrace { /** * Map about the already wrapped methods */ methodMappings: Map>; } /** * Helper class that can be used to trace method calls programmatically * * Usage example: * ```ts * const methodTracer: Disposable = Trace.method({ * object: myObjectInstance, // You can define an object constructor for static methods as well * method: myObjectInstance.method, // The method to be tracked * methodName: 'method', // Unique identifier for the method * isAsync: true, // if you set to async, method finished will be *await*-ed * onCalled: (traceData) => { * console.log("Method called:", traceData) * }, * onFinished: (traceData) => { * console.log("Method call finished:", traceData) * }, * onError: (traceData) => { * console.log("Method throwed an error:", traceData) * } * }); * ``` */ export declare class Trace { private static objectTraces; private static getMethodTrace; private static traceStart; private static traceFinished; private static traceError; private static callMethod; private static callMethodAsync; /** * Creates an observer that will be observe method calls, finishes and errors * @param options The options object for the trace */ static method any, TArgs extends any[]>(options: TraceMethodOptions): Disposable; } //# sourceMappingURL=trace.d.ts.map