mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
refactor(core): Small improvements to external hooks (#12915)
This commit is contained in:
parent
be967ebec0
commit
647dc198c2
|
@ -1,6 +1,6 @@
|
|||
import { Config, Env } from '../decorators';
|
||||
|
||||
class ColonSeperatedStringArray<T extends string = string> extends Array<T> {
|
||||
class ColonSeparatedStringArray<T extends string = string> extends Array<T> {
|
||||
constructor(str: string) {
|
||||
super();
|
||||
const parsed = str.split(':') as this;
|
||||
|
@ -13,5 +13,5 @@ class ColonSeperatedStringArray<T extends string = string> extends Array<T> {
|
|||
export class ExternalHooksConfig {
|
||||
/** Files containing external hooks. Multiple files can be separated by colon (":") */
|
||||
@Env('EXTERNAL_HOOK_FILES')
|
||||
files: ColonSeperatedStringArray = [];
|
||||
files: ColonSeparatedStringArray = [];
|
||||
}
|
||||
|
|
|
@ -24,12 +24,12 @@ type Repositories = {
|
|||
Workflow: WorkflowRepository;
|
||||
};
|
||||
|
||||
type Hooks = {
|
||||
type ExternalHooksMap = {
|
||||
'n8n.ready': [server: AbstractServer, config: Config];
|
||||
'n8n.stop': [];
|
||||
'worker.ready': [];
|
||||
'n8n.stop': never;
|
||||
'worker.ready': never;
|
||||
|
||||
'activeWorkflows.initialized': [];
|
||||
'activeWorkflows.initialized': never;
|
||||
|
||||
'credentials.create': [encryptedData: ICredentialsDb];
|
||||
'credentials.update': [newCredentialData: ICredentialsDb];
|
||||
|
@ -78,7 +78,7 @@ type Hooks = {
|
|||
executionId: string,
|
||||
];
|
||||
};
|
||||
type HookNames = keyof Hooks;
|
||||
type HookNames = keyof ExternalHooksMap;
|
||||
|
||||
// TODO: Derive this type from Hooks
|
||||
interface IExternalHooksFileData {
|
||||
|
@ -90,7 +90,7 @@ interface IExternalHooksFileData {
|
|||
@Service()
|
||||
export class ExternalHooks {
|
||||
private readonly registered: {
|
||||
[hookName in HookNames]?: Array<(...args: Hooks[hookName]) => Promise<void>>;
|
||||
[hookName in HookNames]?: Array<(...args: ExternalHooksMap[hookName]) => Promise<void>>;
|
||||
} = {};
|
||||
|
||||
private readonly dbCollections: Repositories;
|
||||
|
@ -146,7 +146,7 @@ export class ExternalHooks {
|
|||
|
||||
async run<HookName extends HookNames>(
|
||||
hookName: HookName,
|
||||
hookParameters?: Hooks[HookName],
|
||||
hookParameters?: ExternalHooksMap[HookName],
|
||||
): Promise<void> {
|
||||
const { registered, dbCollections } = this;
|
||||
const hookFunctions = registered[hookName];
|
||||
|
|
Loading…
Reference in a new issue