declare module '@ioc:Adonis/Core/Profiler' { /** * Shape of data packet for a single action */ export type ProfilerAction = { type: 'action'; label: string; timestamp: number; duration: [number, number]; data: any; parent_id?: string; }; /** * Shape of data packet for a single row */ export type ProfilerRow = { id: string; type: 'row'; label: string; timestamp: number; duration: [number, number]; data: any; parent_id?: string; }; /** * The processor action or worker node that listens for the logs */ export type ProfilerProcessor = string | ((log: ProfilerAction | ProfilerRow) => void | Promise); /** * Profiler action just has one method to mark * the action as `done`. */ export interface ProfilerActionContract { /** * End profiling an action */ end(data?: any): void; } /** * Exposes the API to time functions */ export interface AbstractProfilerContract { /** * Time a function by wrapping it inside the callback */ profile(action: string, data: any, cb: () => T): T; /** * Create a profiler action to time a block of code. Make sure to * call `end` on the output of this function */ profile(action: string, data?: any): ProfilerActionContract; profile(action: string, data?: any, cb?: () => T): ProfilerActionContract | T; /** * Time an async function by wrapping it inside the callback */ profileAsync(action: string, data: any, cb: () => Promise): Promise; /** * Create a profiler action to time a block of code. Make sure to * call `end` on the output of this function */ profileAsync(action: string, data?: any): Promise; profileAsync(action: string, data?: any, cb?: () => Promise): Promise; } /** * Profiler row can spawn new actions or new rows */ export interface ProfilerRowContract extends AbstractProfilerContract { hasParent: boolean; /** * Create a children row */ create(label: string, data?: any): ProfilerRowContract; /** * End profiling a row */ end(data?: any): void; } /** * Main profiler */ export interface ProfilerContract extends AbstractProfilerContract { processor?: Exclude; isEnabled(labelOrAction: string): boolean; /** * Create a new profiler row */ create(label: string, data?: any): ProfilerRowContract; /** * Define a custom processor function or path to * the processor function module. */ process(fn: ProfilerProcessor): void; /** * Flush final bits (if any) and close the worker * process */ cleanup(): void; } /** * Profiler config */ export type ProfilerConfig = { enabled: boolean; whitelist: string[]; blacklist: string[]; }; const Profiler: ProfilerContract; export default Profiler; }