mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-23 11:44:06 -08:00
refactor(core): Stop importing LoggerProxy and createDeferredPromise in nodes-base (no-changelog) (#5742)
* refactor(core): Stop importing LoggerProxy in nodes-base * refactor(core): Stop importing createDeferredPromise in nodes-base
This commit is contained in:
parent
40aacf9279
commit
38e91ab730
|
@ -62,6 +62,7 @@ import type {
|
|||
FileSystemHelperFunctions,
|
||||
} from 'n8n-workflow';
|
||||
import {
|
||||
createDeferredPromise,
|
||||
NodeApiError,
|
||||
NodeHelpers,
|
||||
NodeOperationError,
|
||||
|
@ -1956,6 +1957,7 @@ const getCommonWorkflowFunctions = (
|
|||
node: INode,
|
||||
additionalData: IWorkflowExecuteAdditionalData,
|
||||
): Omit<FunctionsBase, 'getCredentials'> => ({
|
||||
logger: Logger,
|
||||
getNode: () => deepCopy(node),
|
||||
getWorkflow: () => ({
|
||||
id: workflow.id,
|
||||
|
@ -2118,6 +2120,7 @@ export function getExecutePollFunctions(
|
|||
);
|
||||
},
|
||||
helpers: {
|
||||
createDeferredPromise,
|
||||
...getRequestHelperFunctions(workflow, node, additionalData),
|
||||
...getBinaryHelperFunctions(additionalData),
|
||||
returnJsonArray,
|
||||
|
@ -2176,6 +2179,7 @@ export function getExecuteTriggerFunctions(
|
|||
);
|
||||
},
|
||||
helpers: {
|
||||
createDeferredPromise,
|
||||
...getRequestHelperFunctions(workflow, node, additionalData),
|
||||
...getBinaryHelperFunctions(additionalData),
|
||||
returnJsonArray,
|
||||
|
@ -2351,6 +2355,7 @@ export function getExecuteFunctions(
|
|||
await additionalData.hooks?.executeHookFunctions('sendResponse', [response]);
|
||||
},
|
||||
helpers: {
|
||||
createDeferredPromise,
|
||||
...getRequestHelperFunctions(workflow, node, additionalData),
|
||||
...getFileSystemHelperFunctions(node),
|
||||
...getBinaryHelperFunctions(additionalData),
|
||||
|
@ -2492,6 +2497,7 @@ export function getExecuteSingleFunctions(
|
|||
return dataProxy.getDataProxy();
|
||||
},
|
||||
helpers: {
|
||||
createDeferredPromise,
|
||||
...getRequestHelperFunctions(workflow, node, additionalData),
|
||||
...getBinaryHelperFunctions(additionalData),
|
||||
|
||||
|
@ -2747,6 +2753,7 @@ export function getExecuteWebhookFunctions(
|
|||
getWebhookName: () => webhookData.webhookDescription.name,
|
||||
prepareOutputData: NodeHelpers.prepareOutputData,
|
||||
helpers: {
|
||||
createDeferredPromise,
|
||||
...getRequestHelperFunctions(workflow, node, additionalData),
|
||||
...getBinaryHelperFunctions(additionalData),
|
||||
returnJsonArray,
|
||||
|
|
|
@ -7,7 +7,6 @@ import type {
|
|||
ICredentialsDecrypted,
|
||||
ICredentialTestFunctions,
|
||||
IDataObject,
|
||||
IDeferredPromise,
|
||||
INodeCredentialTestResult,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
|
@ -15,7 +14,7 @@ import type {
|
|||
INodeTypeDescription,
|
||||
ITriggerResponse,
|
||||
} from 'n8n-workflow';
|
||||
import { createDeferredPromise, LoggerProxy as Logger, NodeOperationError } from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import type { ImapSimple, ImapSimpleOptions, Message } from 'imap-simple';
|
||||
import { connect as imapConnect, getParts } from 'imap-simple';
|
||||
|
@ -272,7 +271,7 @@ export class EmailReadImapV1 implements INodeType {
|
|||
const options = this.getNodeParameter('options', {}) as IDataObject;
|
||||
|
||||
const staticData = this.getWorkflowStaticData('node');
|
||||
Logger.debug('Loaded static data for node "EmailReadImap"', { staticData });
|
||||
this.logger.debug('Loaded static data for node "EmailReadImap"', { staticData });
|
||||
|
||||
let connection: ImapSimple;
|
||||
|
||||
|
@ -501,7 +500,7 @@ export class EmailReadImapV1 implements INodeType {
|
|||
return newEmails;
|
||||
};
|
||||
|
||||
const returnedPromise: IDeferredPromise<void> | undefined = await createDeferredPromise();
|
||||
const returnedPromise = await this.helpers.createDeferredPromise();
|
||||
|
||||
const establishConnection = async (): Promise<ImapSimple> => {
|
||||
let searchCriteria = ['UNSEEN'] as Array<string | string[]>;
|
||||
|
@ -538,7 +537,9 @@ export class EmailReadImapV1 implements INodeType {
|
|||
* - You can check if UIDs changed in the above example
|
||||
* by checking UIDValidity.
|
||||
*/
|
||||
Logger.debug('Querying for new messages on node "EmailReadImap"', { searchCriteria });
|
||||
this.logger.debug('Querying for new messages on node "EmailReadImap"', {
|
||||
searchCriteria,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -547,7 +548,7 @@ export class EmailReadImapV1 implements INodeType {
|
|||
this.emit([returnData]);
|
||||
}
|
||||
} catch (error) {
|
||||
Logger.error('Email Read Imap node encountered an error fetching new emails', {
|
||||
this.logger.error('Email Read Imap node encountered an error fetching new emails', {
|
||||
error,
|
||||
});
|
||||
// Wait with resolving till the returnedPromise got resolved, else n8n will be unhappy
|
||||
|
@ -580,17 +581,19 @@ export class EmailReadImapV1 implements INodeType {
|
|||
conn.on('error', async (error) => {
|
||||
const errorCode = error.code.toUpperCase();
|
||||
if (['ECONNRESET', 'EPIPE'].includes(errorCode as string)) {
|
||||
Logger.verbose(`IMAP connection was reset (${errorCode}) - reconnecting.`, { error });
|
||||
this.logger.verbose(`IMAP connection was reset (${errorCode}) - reconnecting.`, {
|
||||
error,
|
||||
});
|
||||
try {
|
||||
connection = await establishConnection();
|
||||
await connection.openBox(mailbox);
|
||||
return;
|
||||
} catch (e) {
|
||||
Logger.error('IMAP reconnect did fail', { error: e });
|
||||
this.logger.error('IMAP reconnect did fail', { error: e });
|
||||
// If something goes wrong we want to run emitError
|
||||
}
|
||||
} else {
|
||||
Logger.error('Email Read Imap node encountered a connection error', { error });
|
||||
this.logger.error('Email Read Imap node encountered a connection error', { error });
|
||||
this.emitError(error as Error);
|
||||
}
|
||||
});
|
||||
|
@ -606,7 +609,7 @@ export class EmailReadImapV1 implements INodeType {
|
|||
|
||||
if (options.forceReconnect !== undefined) {
|
||||
reconnectionInterval = setInterval(async () => {
|
||||
Logger.verbose('Forcing reconnection of IMAP node.');
|
||||
this.logger.verbose('Forcing reconnection of IMAP node.');
|
||||
connection.end();
|
||||
connection = await establishConnection();
|
||||
await connection.openBox(mailbox);
|
||||
|
|
|
@ -6,7 +6,6 @@ import type {
|
|||
ICredentialsDecrypted,
|
||||
ICredentialTestFunctions,
|
||||
IDataObject,
|
||||
IDeferredPromise,
|
||||
INodeCredentialTestResult,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
|
@ -14,7 +13,7 @@ import type {
|
|||
INodeTypeDescription,
|
||||
ITriggerResponse,
|
||||
} from 'n8n-workflow';
|
||||
import { createDeferredPromise, LoggerProxy as Logger, NodeOperationError } from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import type { ImapSimple, ImapSimpleOptions, Message } from 'imap-simple';
|
||||
import { connect as imapConnect, getParts } from 'imap-simple';
|
||||
|
@ -278,7 +277,7 @@ export class EmailReadImapV2 implements INodeType {
|
|||
const options = this.getNodeParameter('options', {}) as IDataObject;
|
||||
|
||||
const staticData = this.getWorkflowStaticData('node');
|
||||
Logger.debug('Loaded static data for node "EmailReadImap"', { staticData });
|
||||
this.logger.debug('Loaded static data for node "EmailReadImap"', { staticData });
|
||||
|
||||
let connection: ImapSimple;
|
||||
let closeFunctionWasCalled = false;
|
||||
|
@ -509,7 +508,7 @@ export class EmailReadImapV2 implements INodeType {
|
|||
return newEmails;
|
||||
};
|
||||
|
||||
const returnedPromise: IDeferredPromise<void> | undefined = await createDeferredPromise();
|
||||
const returnedPromise = await this.helpers.createDeferredPromise();
|
||||
|
||||
const establishConnection = async (): Promise<ImapSimple> => {
|
||||
let searchCriteria = ['UNSEEN'] as Array<string | string[]>;
|
||||
|
@ -546,7 +545,9 @@ export class EmailReadImapV2 implements INodeType {
|
|||
* - You can check if UIDs changed in the above example
|
||||
* by checking UIDValidity.
|
||||
*/
|
||||
Logger.debug('Querying for new messages on node "EmailReadImap"', { searchCriteria });
|
||||
this.logger.debug('Querying for new messages on node "EmailReadImap"', {
|
||||
searchCriteria,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -555,7 +556,7 @@ export class EmailReadImapV2 implements INodeType {
|
|||
this.emit([returnData]);
|
||||
}
|
||||
} catch (error) {
|
||||
Logger.error('Email Read Imap node encountered an error fetching new emails', {
|
||||
this.logger.error('Email Read Imap node encountered an error fetching new emails', {
|
||||
error,
|
||||
});
|
||||
// Wait with resolving till the returnedPromise got resolved, else n8n will be unhappy
|
||||
|
@ -567,7 +568,7 @@ export class EmailReadImapV2 implements INodeType {
|
|||
}
|
||||
},
|
||||
onupdate: async (seqno: number, info) => {
|
||||
Logger.verbose(`Email Read Imap:update ${seqno}`, info as IDataObject);
|
||||
this.logger.verbose(`Email Read Imap:update ${seqno}`, info as IDataObject);
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -590,17 +591,17 @@ export class EmailReadImapV2 implements INodeType {
|
|||
return imapConnect(config).then(async (conn) => {
|
||||
conn.on('close', async (_hadError: boolean) => {
|
||||
if (isCurrentlyReconnecting) {
|
||||
Logger.debug('Email Read Imap: Connected closed for forced reconnecting');
|
||||
this.logger.debug('Email Read Imap: Connected closed for forced reconnecting');
|
||||
} else if (closeFunctionWasCalled) {
|
||||
Logger.debug('Email Read Imap: Shutting down workflow - connected closed');
|
||||
this.logger.debug('Email Read Imap: Shutting down workflow - connected closed');
|
||||
} else {
|
||||
Logger.error('Email Read Imap: Connected closed unexpectedly');
|
||||
this.logger.error('Email Read Imap: Connected closed unexpectedly');
|
||||
this.emitError(new Error('Imap connection closed unexpectedly'));
|
||||
}
|
||||
});
|
||||
conn.on('error', async (error) => {
|
||||
const errorCode = error.code.toUpperCase();
|
||||
Logger.verbose(`IMAP connection experienced an error: (${errorCode})`, { error });
|
||||
this.logger.verbose(`IMAP connection experienced an error: (${errorCode})`, { error });
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
await closeFunction();
|
||||
this.emitError(error as Error);
|
||||
|
@ -617,7 +618,7 @@ export class EmailReadImapV2 implements INodeType {
|
|||
|
||||
if (options.forceReconnect !== undefined) {
|
||||
reconnectionInterval = setInterval(async () => {
|
||||
Logger.verbose('Forcing reconnect to IMAP server');
|
||||
this.logger.verbose('Forcing reconnect to IMAP server');
|
||||
try {
|
||||
isCurrentlyReconnecting = true;
|
||||
if (connection.closeBox) await connection.closeBox(false);
|
||||
|
@ -625,7 +626,7 @@ export class EmailReadImapV2 implements INodeType {
|
|||
connection = await establishConnection();
|
||||
await connection.openBox(mailbox);
|
||||
} catch (error) {
|
||||
Logger.error(error as string);
|
||||
this.logger.error(error as string);
|
||||
} finally {
|
||||
isCurrentlyReconnecting = false;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import type {
|
|||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
import { LoggerProxy as Logger } from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
googleApiRequest,
|
||||
|
@ -303,7 +302,7 @@ export class GmailTrigger implements INodeType {
|
|||
}
|
||||
const workflow = this.getWorkflow();
|
||||
const node = this.getNode();
|
||||
Logger.error(
|
||||
this.logger.error(
|
||||
`There was a problem in '${node.name}' node in workflow '${workflow.id}': '${error.description}'`,
|
||||
{
|
||||
node: node.name,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
|
||||
import type {
|
||||
IDataObject,
|
||||
IDeferredPromise,
|
||||
INodeExecutionData,
|
||||
INodeProperties,
|
||||
INodeType,
|
||||
|
@ -9,7 +10,7 @@ import type {
|
|||
ITriggerFunctions,
|
||||
ITriggerResponse,
|
||||
} from 'n8n-workflow';
|
||||
import { createDeferredPromise, LoggerProxy as Logger, NodeOperationError } from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { rabbitDefaultOptions } from './DefaultOptions';
|
||||
|
||||
|
@ -220,9 +221,9 @@ export class RabbitMQTrigger implements INodeType {
|
|||
}
|
||||
}
|
||||
|
||||
let responsePromise = undefined;
|
||||
let responsePromise: IDeferredPromise<IRun> | undefined = undefined;
|
||||
if (acknowledgeMode !== 'immediately') {
|
||||
responsePromise = await createDeferredPromise<IRun>();
|
||||
responsePromise = await this.helpers.createDeferredPromise();
|
||||
}
|
||||
|
||||
this.emit([[item]], undefined, responsePromise);
|
||||
|
@ -253,7 +254,7 @@ export class RabbitMQTrigger implements INodeType {
|
|||
messageTracker.answered(message);
|
||||
}
|
||||
|
||||
Logger.error(
|
||||
this.logger.error(
|
||||
`There was a problem with the RabbitMQ Trigger node "${node.name}" in workflow "${workflow.id}": "${error.message}"`,
|
||||
{
|
||||
node: node.name,
|
||||
|
@ -277,7 +278,7 @@ export class RabbitMQTrigger implements INodeType {
|
|||
} catch (error) {
|
||||
const workflow = this.getWorkflow();
|
||||
const node = this.getNode();
|
||||
Logger.error(
|
||||
this.logger.error(
|
||||
`There was a problem closing the RabbitMQ Trigger node connection "${node.name}" in workflow "${workflow.id}": "${error.message}"`,
|
||||
{
|
||||
node: node.name,
|
||||
|
|
|
@ -8,7 +8,7 @@ import type {
|
|||
INodePropertyOptions,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
import { LoggerProxy as Logger, NodeApiError } from 'n8n-workflow';
|
||||
import { NodeApiError } from 'n8n-workflow';
|
||||
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
|
@ -109,7 +109,7 @@ export async function salesforceApiRequest(
|
|||
qs,
|
||||
instance_url as string,
|
||||
);
|
||||
Logger.debug(
|
||||
this.logger.debug(
|
||||
`Authentication for "Salesforce" node is using "jwt". Invoking URI ${options.uri}`,
|
||||
);
|
||||
options.headers!.Authorization = `Bearer ${access_token}`;
|
||||
|
@ -130,7 +130,7 @@ export async function salesforceApiRequest(
|
|||
qs,
|
||||
credentials.oauthTokenData.instance_url,
|
||||
);
|
||||
Logger.debug(
|
||||
this.logger.debug(
|
||||
`Authentication for "Salesforce" node is using "OAuth2". Invoking URI ${options.uri}`,
|
||||
);
|
||||
Object.assign(options, option);
|
||||
|
|
|
@ -8,7 +8,7 @@ import type {
|
|||
INodeTypeDescription,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
import { LoggerProxy as Logger, NodeApiError, NodeOperationError } from 'n8n-workflow';
|
||||
import { NodeApiError, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { accountFields, accountOperations } from './AccountDescription';
|
||||
|
||||
|
@ -1065,7 +1065,7 @@ export class Salesforce implements INodeType {
|
|||
const resource = this.getNodeParameter('resource', 0);
|
||||
const operation = this.getNodeParameter('operation', 0);
|
||||
|
||||
Logger.debug(
|
||||
this.logger.debug(
|
||||
`Running "Salesforce" node named "${this.getNode.name}" resource "${resource}" operation "${operation}"`,
|
||||
);
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ export interface IDeferredPromise<T> {
|
|||
resolve: (result: T) => void;
|
||||
}
|
||||
|
||||
export async function createDeferredPromise<T>(): Promise<IDeferredPromise<T>> {
|
||||
export async function createDeferredPromise<T = void>(): Promise<IDeferredPromise<T>> {
|
||||
return new Promise<IDeferredPromise<T>>((resolveCreate) => {
|
||||
const promise = new Promise<T>((resolve, reject) => {
|
||||
resolveCreate({ promise: async () => promise, resolve, reject });
|
||||
|
|
|
@ -657,7 +657,11 @@ export interface ICredentialTestFunctions {
|
|||
};
|
||||
}
|
||||
|
||||
export interface JsonHelperFunctions {
|
||||
interface BaseHelperFunctions {
|
||||
createDeferredPromise: <T = void>() => Promise<IDeferredPromise<T>>;
|
||||
}
|
||||
|
||||
interface JsonHelperFunctions {
|
||||
returnJsonArray(jsonData: IDataObject | IDataObject[]): INodeExecutionData[];
|
||||
}
|
||||
|
||||
|
@ -709,6 +713,7 @@ export interface RequestHelperFunctions {
|
|||
}
|
||||
|
||||
export interface FunctionsBase {
|
||||
logger: ILogger;
|
||||
getCredentials(type: string, itemIndex?: number): Promise<ICredentialDataDecryptedObject>;
|
||||
getNode(): INode;
|
||||
getWorkflow(): IWorkflowMetadata;
|
||||
|
@ -749,6 +754,7 @@ export type IExecuteFunctions = ExecuteFunctions.GetNodeParameterFn &
|
|||
sendResponse(response: IExecuteResponsePromiseData): void;
|
||||
|
||||
helpers: RequestHelperFunctions &
|
||||
BaseHelperFunctions &
|
||||
BinaryHelperFunctions &
|
||||
FileSystemHelperFunctions &
|
||||
JsonHelperFunctions & {
|
||||
|
@ -772,6 +778,7 @@ export interface IExecuteSingleFunctions extends BaseExecutionFunctions {
|
|||
): NodeParameterValueType | object;
|
||||
|
||||
helpers: RequestHelperFunctions &
|
||||
BaseHelperFunctions &
|
||||
BinaryHelperFunctions & {
|
||||
assertBinaryData(propertyName: string, inputIndex?: number): IBinaryData;
|
||||
getBinaryDataBuffer(propertyName: string, inputIndex?: number): Promise<Buffer>;
|
||||
|
@ -812,7 +819,10 @@ export interface IPollFunctions
|
|||
fallbackValue?: any,
|
||||
options?: IGetNodeParameterOptions,
|
||||
): NodeParameterValueType | object;
|
||||
helpers: RequestHelperFunctions & BinaryHelperFunctions & JsonHelperFunctions;
|
||||
helpers: RequestHelperFunctions &
|
||||
BaseHelperFunctions &
|
||||
BinaryHelperFunctions &
|
||||
JsonHelperFunctions;
|
||||
}
|
||||
|
||||
export interface ITriggerFunctions
|
||||
|
@ -828,7 +838,10 @@ export interface ITriggerFunctions
|
|||
fallbackValue?: any,
|
||||
options?: IGetNodeParameterOptions,
|
||||
): NodeParameterValueType | object;
|
||||
helpers: RequestHelperFunctions & BinaryHelperFunctions & JsonHelperFunctions;
|
||||
helpers: RequestHelperFunctions &
|
||||
BaseHelperFunctions &
|
||||
BinaryHelperFunctions &
|
||||
JsonHelperFunctions;
|
||||
}
|
||||
|
||||
export interface IHookFunctions
|
||||
|
@ -862,7 +875,10 @@ export interface IWebhookFunctions extends FunctionsBaseWithRequiredKeys<'getMod
|
|||
outputData: INodeExecutionData[],
|
||||
outputIndex?: number,
|
||||
): Promise<INodeExecutionData[][]>;
|
||||
helpers: RequestHelperFunctions & BinaryHelperFunctions & JsonHelperFunctions;
|
||||
helpers: RequestHelperFunctions &
|
||||
BaseHelperFunctions &
|
||||
BinaryHelperFunctions &
|
||||
JsonHelperFunctions;
|
||||
}
|
||||
|
||||
export interface INodeCredentialsDetails {
|
||||
|
|
Loading…
Reference in a new issue