declare type Interceptor = { /** An optional name for the interceptor */ name?: string; /** Callback for each loop when used by the hook */ loop?: (...args: Args) => void; /** Callback when an error occurs during the hook's call */ error?: (err: Error) => void; /** Callback when a result is found for a hook's invocation */ result?: (r: ReturnType extends Promise ? AwaitedValue : ReturnType) => void; /** Callback when a hook's call is complete */ done?: () => void; /** Callback when a hook is tapped */ tap?: (tap: Tap) => void; } & ({ /** If context should be omitted from the 'call'. This is the default */ context?: false; /** Callback when the hook is tapped without context */ call?: (...args: Args) => void; } | { /** If context should be included in the 'call' */ context: true; /** Callback when the hook is tapped with context */ call?: (context: ContextType, ...args: Args) => void; }); declare type Tap = { key: symbol; name: string; before?: string | Array; } & ({ context: false; callback: (...args: Args) => ReturnType; } | { context: true; callback: (context: ContextType, ...args: Args) => ReturnType; }); declare type BasicTap = (name: string, callback: (...args: Args) => ReturnType, before?: string | Array) => Tap; declare type TapWithContext = ((options: { name: string; context?: false; before?: string | Array; }, callback: (...args: Args) => ReturnType) => Tap) | ((options: { name: string; context: true; before?: string | Array; }, callback: (context: ContextType, ...args: Args) => ReturnType) => Tap); interface SyncBaseHookType { tap: BasicTap | TapWithContext; call(...args: Args): void; untap(key: Tap): void; isUsed(): boolean; intercept(int: Interceptor): void; } /** A manager for all intercepts inside of a tap */ declare class InterceptionManager> { protected interceptions: Array>; private interceptionKeySet; constructor(); isUsed(): boolean; intercept(int: Interceptor): void; tap(tap: Tap): void; call(ctx: ContextType, ...args: Args): void; loop(...args: Args): void; error(err: unknown): void; result(r: ReturnType extends Promise ? AwaitedValue : ReturnType): void; done(): void; } declare abstract class Hook> implements SyncBaseHookType { protected taps: Array>; protected interceptions: InterceptionManager; constructor(); tap(options: { name: string; context?: false; before?: string | Array; }, callback: (...args: Args) => ReturnType): Tap; tap(options: { name: string; context: true; before?: string | Array; }, callback: (ctx: ContextType, ...args: Args) => ReturnType): Tap; tap(name: string, callback: (...args: Args) => ReturnType): Tap; abstract call(...args: Args): ReturnType; untap(tap: Tap): void; isUsed(): boolean; intercept(int: Interceptor): void; } declare class SyncHook> extends Hook { call(...args: Args): void; } declare class SyncBailHook> extends Hook { call(...args: Args): ReturnType | undefined | null; } declare class SyncWaterfallHook> extends Hook { call(...args: Args): Args[0]; } declare class SyncLoopHook> extends Hook { call(...args: Args): void; } declare class AsyncParallelHook> extends Hook, ContextType> { call(...args: Args): Promise; } declare class AsyncParallelBailHook> extends Hook, ContextType> { call(...args: Args): Promise; } declare class AsyncSeriesHook> extends Hook, ContextType> { call(...args: Args): Promise; } declare class AsyncSeriesBailHook> extends Hook, ContextType> { call(...args: Args): Promise; } declare class AsyncSeriesWaterfallHook> extends Hook, ContextType> { call(...args: Args): Promise; } declare class AsyncSeriesLoopHook> extends Hook, ContextType> { call(...args: Args): Promise; } export { AsyncParallelBailHook, AsyncParallelHook, AsyncSeriesBailHook, AsyncSeriesHook, AsyncSeriesLoopHook, AsyncSeriesWaterfallHook, Interceptor, SyncBailHook, SyncHook, SyncLoopHook, SyncWaterfallHook, Tap };