refactor: Improve typings for webhook methods (no-changelog) (#5713)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-03-17 12:25:31 +01:00
committed by GitHub
parent a28396ee91
commit 6a8c9b7ccc
43 changed files with 10 additions and 68 deletions

View File

@@ -1163,6 +1163,8 @@ export interface ITriggerResponse {
manualTriggerResponse?: Promise<INodeExecutionData[][]>;
}
export type WebhookSetupMethodNames = 'checkExists' | 'create' | 'delete';
export interface INodeType {
description: INodeTypeDescription;
execute?(
@@ -1172,9 +1174,6 @@ export interface INodeType {
poll?(this: IPollFunctions): Promise<INodeExecutionData[][] | null>;
trigger?(this: ITriggerFunctions): Promise<ITriggerResponse | undefined>;
webhook?(this: IWebhookFunctions): Promise<IWebhookResponseData>;
hooks?: {
[key: string]: (this: IHookFunctions) => Promise<boolean>;
};
methods?: {
loadOptions?: {
[key: string]: (this: ILoadOptionsFunctions) => Promise<INodePropertyOptions[]>;
@@ -1192,7 +1191,9 @@ export interface INodeType {
};
};
webhookMethods?: {
[key: string]: IWebhookSetupMethods;
[name in IWebhookDescription['name']]?: {
[method in WebhookSetupMethodNames]: (this: IHookFunctions) => Promise<boolean>;
};
};
}
@@ -1213,15 +1214,6 @@ export interface INodeCredentialTestRequest {
credentials: ICredentialsDecrypted;
}
export type WebhookSetupMethodNames = 'checkExists' | 'create' | 'delete';
export interface IWebhookSetupMethods {
[key: string]: ((this: IHookFunctions) => Promise<boolean>) | undefined;
checkExists?: (this: IHookFunctions) => Promise<boolean>;
create?: (this: IHookFunctions) => Promise<boolean>;
delete?: (this: IHookFunctions) => Promise<boolean>;
}
export interface INodeCredentialDescription {
name: string;
required?: boolean;
@@ -1436,7 +1428,7 @@ export interface IWebhookDescription {
[key: string]: WebhookHttpMethod | WebhookResponseMode | boolean | string | undefined;
httpMethod: WebhookHttpMethod | string;
isFullPath?: boolean;
name: string;
name: 'default' | 'setup';
path: string;
responseBinaryPropertyName?: string;
responseContentType?: string;

View File

@@ -982,17 +982,8 @@ export class Workflow {
const node = this.getNode(webhookData.node) as INode;
const nodeType = this.nodeTypes.getByNameAndVersion(node.type, node.typeVersion);
if (nodeType.webhookMethods === undefined) {
return;
}
if (nodeType.webhookMethods[webhookData.webhookDescription.name] === undefined) {
return;
}
if (nodeType.webhookMethods[webhookData.webhookDescription.name][method] === undefined) {
return;
}
const webhookFn = nodeType.webhookMethods?.[webhookData.webhookDescription.name]?.[method];
if (webhookFn === undefined) return;
const thisArgs = nodeExecuteFunctions.getExecuteHookFunctions(
this,
@@ -1003,8 +994,8 @@ export class Workflow {
isTest,
webhookData,
);
// eslint-disable-next-line consistent-return
return nodeType.webhookMethods[webhookData.webhookDescription.name][method]!.call(thisArgs);
return webhookFn.call(thisArgs);
}
/**