1 import { HookType } from '../../models/plugins/hook-type.enum'
2 import { isCatchable, isPromise } from '../miscs/miscs'
4 function getHookType (hookName: string) {
5 if (hookName.startsWith('filter:')) return HookType.FILTER
6 if (hookName.startsWith('action:')) return HookType.ACTION
11 async function internalRunHook <T> (handler: Function, hookType: HookType, result: T, params: any, onError: (err: Error) => void) {
13 if (hookType === HookType.FILTER) {
14 const p = handler(result, params)
16 if (isPromise(p)) result = await p
22 // Action/static hooks do not have result value
23 const p = handler(params)
25 if (hookType === HookType.STATIC) {
26 if (isPromise(p)) await p
31 if (hookType === HookType.ACTION) {
32 if (isCatchable(p)) p.catch((err: any) => onError(err))