diff options
Diffstat (limited to 'server/lib/plugins/hooks.ts')
-rw-r--r-- | server/lib/plugins/hooks.ts | 35 |
1 files changed, 0 insertions, 35 deletions
diff --git a/server/lib/plugins/hooks.ts b/server/lib/plugins/hooks.ts deleted file mode 100644 index 694527c12..000000000 --- a/server/lib/plugins/hooks.ts +++ /dev/null | |||
@@ -1,35 +0,0 @@ | |||
1 | import Bluebird from 'bluebird' | ||
2 | import { ServerActionHookName, ServerFilterHookName } from '../../../shared/models' | ||
3 | import { logger } from '../../helpers/logger' | ||
4 | import { PluginManager } from './plugin-manager' | ||
5 | |||
6 | type PromiseFunction <U, T> = (params: U) => Promise<T> | Bluebird<T> | ||
7 | type RawFunction <U, T> = (params: U) => T | ||
8 | |||
9 | // Helpers to run hooks | ||
10 | const Hooks = { | ||
11 | wrapObject: <T, U extends ServerFilterHookName>(result: T, hookName: U, context?: any) => { | ||
12 | return PluginManager.Instance.runHook(hookName, result, context) | ||
13 | }, | ||
14 | |||
15 | wrapPromiseFun: async <U, T, V extends ServerFilterHookName>(fun: PromiseFunction<U, T>, params: U, hookName: V) => { | ||
16 | const result = await fun(params) | ||
17 | |||
18 | return PluginManager.Instance.runHook(hookName, result, params) | ||
19 | }, | ||
20 | |||
21 | wrapFun: async <U, T, V extends ServerFilterHookName>(fun: RawFunction<U, T>, params: U, hookName: V) => { | ||
22 | const result = fun(params) | ||
23 | |||
24 | return PluginManager.Instance.runHook(hookName, result, params) | ||
25 | }, | ||
26 | |||
27 | runAction: <T, U extends ServerActionHookName>(hookName: U, params?: T) => { | ||
28 | PluginManager.Instance.runHook(hookName, undefined, params) | ||
29 | .catch(err => logger.error('Fatal hook error.', { err })) | ||
30 | } | ||
31 | } | ||
32 | |||
33 | export { | ||
34 | Hooks | ||
35 | } | ||