import { Model } from './Model'; import { SequelizeHooks } from './SequelizeHooks'; /** * Virtual class for deduplication */ export class Hooks< M extends Model = Model, TModelAttributes extends {} = any, TCreationAttributes extends {} = TModelAttributes, > { /** * A dummy variable that doesn't exist on the real object. This exists so * Typescript can infer the type of the attributes in static functions. Don't * try to access this! */ _model: M; /** * A similar dummy variable that doesn't exist on the real object. Do not * try to access this in real code. */ _attributes: TModelAttributes; /** * A similar dummy variable that doesn't exist on the real object. Do not * try to access this in real code. */ _creationAttributes: TCreationAttributes; /** * Add a hook to the model * * @param name Provide a name for the hook function. It can be used to remove the hook later or to order * hooks based on some sort of priority system in the future. */ public static addHook< H extends Hooks, K extends keyof SequelizeHooks, >( this: HooksStatic, hookType: K, name: string, fn: SequelizeHooks[K], ): HooksCtor; public static addHook< H extends Hooks, K extends keyof SequelizeHooks, >( this: HooksStatic, hookType: K, fn: SequelizeHooks[K], ): HooksCtor; /** * Remove hook from the model */ public static removeHook( this: HooksStatic, hookType: keyof SequelizeHooks, name: string, ): HooksCtor; /** * Check whether the mode has any hooks of this type */ public static hasHook( this: HooksStatic, hookType: keyof SequelizeHooks, ): boolean; public static hasHooks( this: HooksStatic, hookType: keyof SequelizeHooks, ): boolean; /** * Add a hook to the model * * @param name Provide a name for the hook function. It can be used to remove the hook later or to order * hooks based on some sort of priority system in the future. */ public addHook>( hookType: K, name: string, fn: SequelizeHooks[K], ): this; public addHook>( hookType: K, fn: SequelizeHooks[K], ): this; /** * Remove hook from the model */ public removeHook>( hookType: K, name: string, ): this; /** * Check whether the mode has any hooks of this type */ public hasHook>( hookType: K, ): boolean; public hasHooks>( hookType: K, ): boolean; } export type HooksCtor = typeof Hooks & { new (): H }; export type HooksStatic = { new (): H };