@foal/core
Version:
Full-featured Node.js framework, with no complexity
58 lines (57 loc) • 1.97 kB
TypeScript
import 'reflect-metadata';
import { Context, HttpResponse } from './http';
import { OpenApiDecorator } from './openapi';
import { ServiceManager } from './service-manager';
/**
* Interface of a function that can be returned in a hook function. This function is then
* executed after the controller method execution.
*
* @export
*/
export type HookPostFunction = (response: HttpResponse) => void | Promise<void>;
/**
* Interface of a function from which a hook can be created.
*
* @export
*/
export type HookFunction<C = Context> = (ctx: C, services: ServiceManager) => void | HttpResponse | HookPostFunction | Promise<void | HttpResponse | HookPostFunction>;
/**
* Interface of a hook. It is actually the interface of a decorator.
*
* @export
*/
export type HookDecorator = (target: any, propertyKey?: string) => any;
/**
* Create a hook from one or several functions.
*
* @export
* @param {HookFunction[]} hookFunction - The function from which the hook should be created.
* @returns {HookDecorator} - The hook decorator.
*/
export declare function Hook<C = Context>(hookFunction: HookFunction<C>, openApiDecorators?: OpenApiDecorator[], options?: {
openapi?: boolean;
}): HookDecorator;
/**
* Get the function from which the hook was made.
*
* @export
* @param {HookDecorator} hook - The hook decorator.
* @returns {HookFunction} The hook function.
*/
export declare function getHookFunction(hook: HookDecorator): HookFunction;
/**
* Get the functions from which the hook was made.
*
* @export
* @param {HookDecorator} hook - The hook decorator.
* @returns {HookFunction[]} The hook functions.
*/
export declare function getHookFunctions(hook: HookDecorator): HookFunction[];
/**
* Group multiple hooks into a new one.
*
* @export
* @param {...HookDecorator[]} hookDecorators - The hooks to merge.
* @returns {HookDecorator} The new hook.
*/
export declare function MergeHooks(...hookDecorators: HookDecorator[]): HookDecorator;