mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 20:54:07 -08:00
fix(core): delete some of the redundant code in core (#4359)
This commit is contained in:
parent
2e69e2c953
commit
5eb1eb88e4
|
@ -4,7 +4,6 @@ import {
|
||||||
IAllExecuteFunctions,
|
IAllExecuteFunctions,
|
||||||
IBinaryData,
|
IBinaryData,
|
||||||
ICredentialTestFunctions as ICredentialTestFunctionsBase,
|
ICredentialTestFunctions as ICredentialTestFunctionsBase,
|
||||||
ICredentialType,
|
|
||||||
IDataObject,
|
IDataObject,
|
||||||
IExecuteFunctions as IExecuteFunctionsBase,
|
IExecuteFunctions as IExecuteFunctionsBase,
|
||||||
IExecuteSingleFunctions as IExecuteSingleFunctionsBase,
|
IExecuteSingleFunctions as IExecuteSingleFunctionsBase,
|
||||||
|
@ -12,7 +11,6 @@ import {
|
||||||
IHttpRequestOptions,
|
IHttpRequestOptions,
|
||||||
ILoadOptionsFunctions as ILoadOptionsFunctionsBase,
|
ILoadOptionsFunctions as ILoadOptionsFunctionsBase,
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodeType,
|
|
||||||
IOAuth2Options,
|
IOAuth2Options,
|
||||||
IPairedItemData,
|
IPairedItemData,
|
||||||
IPollFunctions as IPollFunctionsBase,
|
IPollFunctions as IPollFunctionsBase,
|
||||||
|
@ -24,12 +22,8 @@ import {
|
||||||
NodeExecutionWithMetadata,
|
NodeExecutionWithMetadata,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
import { OptionsWithUri, OptionsWithUrl } from 'request';
|
import type { OptionsWithUri, OptionsWithUrl } from 'request';
|
||||||
import requestPromise from 'request-promise-native';
|
import type { RequestPromiseAPI, RequestPromiseOptions } from 'request-promise-native';
|
||||||
|
|
||||||
interface Constructable<T> {
|
|
||||||
new (): T;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IProcessMessage {
|
export interface IProcessMessage {
|
||||||
data?: any;
|
data?: any;
|
||||||
|
@ -50,19 +44,19 @@ export interface IExecuteFunctions extends IExecuteFunctionsBase {
|
||||||
requestWithAuthentication(
|
requestWithAuthentication(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUri | RequestPromiseOptions,
|
||||||
additionalCredentialOptions?: IAdditionalCredentialOptions,
|
additionalCredentialOptions?: IAdditionalCredentialOptions,
|
||||||
): Promise<any>;
|
): Promise<any>;
|
||||||
requestOAuth2(
|
requestOAuth2(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUri | RequestPromiseOptions,
|
||||||
oAuth2Options?: IOAuth2Options,
|
oAuth2Options?: IOAuth2Options,
|
||||||
): Promise<any>; // tslint:disable-line:no-any
|
): Promise<any>; // tslint:disable-line:no-any
|
||||||
requestOAuth1(
|
requestOAuth1(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUrl | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUrl | RequestPromiseOptions,
|
||||||
): Promise<any>; // tslint:disable-line:no-any
|
): Promise<any>; // tslint:disable-line:no-any
|
||||||
returnJsonArray(jsonData: IDataObject | IDataObject[]): INodeExecutionData[];
|
returnJsonArray(jsonData: IDataObject | IDataObject[]): INodeExecutionData[];
|
||||||
normalizeItems(items: INodeExecutionData | INodeExecutionData[]): INodeExecutionData[];
|
normalizeItems(items: INodeExecutionData | INodeExecutionData[]): INodeExecutionData[];
|
||||||
|
@ -92,19 +86,19 @@ export interface IExecuteSingleFunctions extends IExecuteSingleFunctionsBase {
|
||||||
requestWithAuthentication(
|
requestWithAuthentication(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUri | RequestPromiseOptions,
|
||||||
additionalCredentialOptions?: IAdditionalCredentialOptions,
|
additionalCredentialOptions?: IAdditionalCredentialOptions,
|
||||||
): Promise<any>;
|
): Promise<any>;
|
||||||
requestOAuth2(
|
requestOAuth2(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUri | RequestPromiseOptions,
|
||||||
oAuth2Options?: IOAuth2Options,
|
oAuth2Options?: IOAuth2Options,
|
||||||
): Promise<any>; // tslint:disable-line:no-any
|
): Promise<any>; // tslint:disable-line:no-any
|
||||||
requestOAuth1(
|
requestOAuth1(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUrl | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUrl | RequestPromiseOptions,
|
||||||
): Promise<any>; // tslint:disable-line:no-any
|
): Promise<any>; // tslint:disable-line:no-any
|
||||||
httpRequestWithAuthentication(
|
httpRequestWithAuthentication(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
|
@ -126,19 +120,19 @@ export interface IPollFunctions extends IPollFunctionsBase {
|
||||||
requestWithAuthentication(
|
requestWithAuthentication(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUri | RequestPromiseOptions,
|
||||||
additionalCredentialOptions?: IAdditionalCredentialOptions,
|
additionalCredentialOptions?: IAdditionalCredentialOptions,
|
||||||
): Promise<any>;
|
): Promise<any>;
|
||||||
requestOAuth2(
|
requestOAuth2(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUri | RequestPromiseOptions,
|
||||||
oAuth2Options?: IOAuth2Options,
|
oAuth2Options?: IOAuth2Options,
|
||||||
): Promise<any>; // tslint:disable-line:no-any
|
): Promise<any>; // tslint:disable-line:no-any
|
||||||
requestOAuth1(
|
requestOAuth1(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUrl | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUrl | RequestPromiseOptions,
|
||||||
): Promise<any>; // tslint:disable-line:no-any
|
): Promise<any>; // tslint:disable-line:no-any
|
||||||
returnJsonArray(jsonData: IDataObject | IDataObject[]): INodeExecutionData[];
|
returnJsonArray(jsonData: IDataObject | IDataObject[]): INodeExecutionData[];
|
||||||
httpRequestWithAuthentication(
|
httpRequestWithAuthentication(
|
||||||
|
@ -165,19 +159,19 @@ export interface ITriggerFunctions extends ITriggerFunctionsBase {
|
||||||
requestWithAuthentication(
|
requestWithAuthentication(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUri | RequestPromiseOptions,
|
||||||
additionalCredentialOptions?: IAdditionalCredentialOptions,
|
additionalCredentialOptions?: IAdditionalCredentialOptions,
|
||||||
): Promise<any>;
|
): Promise<any>;
|
||||||
requestOAuth2(
|
requestOAuth2(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUri | RequestPromiseOptions,
|
||||||
oAuth2Options?: IOAuth2Options,
|
oAuth2Options?: IOAuth2Options,
|
||||||
): Promise<any>; // tslint:disable-line:no-any
|
): Promise<any>; // tslint:disable-line:no-any
|
||||||
requestOAuth1(
|
requestOAuth1(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUrl | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUrl | RequestPromiseOptions,
|
||||||
): Promise<any>; // tslint:disable-line:no-any
|
): Promise<any>; // tslint:disable-line:no-any
|
||||||
returnJsonArray(jsonData: IDataObject | IDataObject[]): INodeExecutionData[];
|
returnJsonArray(jsonData: IDataObject | IDataObject[]): INodeExecutionData[];
|
||||||
httpRequestWithAuthentication(
|
httpRequestWithAuthentication(
|
||||||
|
@ -201,19 +195,19 @@ export interface ILoadOptionsFunctions extends ILoadOptionsFunctionsBase {
|
||||||
requestWithAuthentication(
|
requestWithAuthentication(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUri | RequestPromiseOptions,
|
||||||
additionalCredentialOptions?: IAdditionalCredentialOptions,
|
additionalCredentialOptions?: IAdditionalCredentialOptions,
|
||||||
): Promise<any>;
|
): Promise<any>;
|
||||||
requestOAuth2?: (
|
requestOAuth2?: (
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUri | RequestPromiseOptions,
|
||||||
oAuth2Options?: IOAuth2Options,
|
oAuth2Options?: IOAuth2Options,
|
||||||
) => Promise<any>; // tslint:disable-line:no-any
|
) => Promise<any>; // tslint:disable-line:no-any
|
||||||
requestOAuth1?(
|
requestOAuth1?(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUrl | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUrl | RequestPromiseOptions,
|
||||||
): Promise<any>; // tslint:disable-line:no-any
|
): Promise<any>; // tslint:disable-line:no-any
|
||||||
httpRequestWithAuthentication(
|
httpRequestWithAuthentication(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
|
@ -225,7 +219,7 @@ export interface ILoadOptionsFunctions extends ILoadOptionsFunctionsBase {
|
||||||
|
|
||||||
export interface ICredentialTestFunctions extends ICredentialTestFunctionsBase {
|
export interface ICredentialTestFunctions extends ICredentialTestFunctionsBase {
|
||||||
helpers: {
|
helpers: {
|
||||||
request: requestPromise.RequestPromiseAPI;
|
request: RequestPromiseAPI;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,19 +230,19 @@ export interface IHookFunctions extends IHookFunctionsBase {
|
||||||
requestWithAuthentication(
|
requestWithAuthentication(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUri | RequestPromiseOptions,
|
||||||
additionalCredentialOptions?: IAdditionalCredentialOptions,
|
additionalCredentialOptions?: IAdditionalCredentialOptions,
|
||||||
): Promise<any>;
|
): Promise<any>;
|
||||||
requestOAuth2(
|
requestOAuth2(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUri | RequestPromiseOptions,
|
||||||
oAuth2Options?: IOAuth2Options,
|
oAuth2Options?: IOAuth2Options,
|
||||||
): Promise<any>; // tslint:disable-line:no-any
|
): Promise<any>; // tslint:disable-line:no-any
|
||||||
requestOAuth1(
|
requestOAuth1(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUrl | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUrl | RequestPromiseOptions,
|
||||||
): Promise<any>; // tslint:disable-line:no-any
|
): Promise<any>; // tslint:disable-line:no-any
|
||||||
httpRequestWithAuthentication(
|
httpRequestWithAuthentication(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
|
@ -270,19 +264,19 @@ export interface IWebhookFunctions extends IWebhookFunctionsBase {
|
||||||
requestWithAuthentication(
|
requestWithAuthentication(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUri | RequestPromiseOptions,
|
||||||
additionalCredentialOptions?: IAdditionalCredentialOptions,
|
additionalCredentialOptions?: IAdditionalCredentialOptions,
|
||||||
): Promise<any>;
|
): Promise<any>;
|
||||||
requestOAuth2(
|
requestOAuth2(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUri | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUri | RequestPromiseOptions,
|
||||||
oAuth2Options?: IOAuth2Options,
|
oAuth2Options?: IOAuth2Options,
|
||||||
): Promise<any>; // tslint:disable-line:no-any
|
): Promise<any>; // tslint:disable-line:no-any
|
||||||
requestOAuth1(
|
requestOAuth1(
|
||||||
this: IAllExecuteFunctions,
|
this: IAllExecuteFunctions,
|
||||||
credentialsType: string,
|
credentialsType: string,
|
||||||
requestOptions: OptionsWithUrl | requestPromise.RequestPromiseOptions,
|
requestOptions: OptionsWithUrl | RequestPromiseOptions,
|
||||||
): Promise<any>; // tslint:disable-line:no-any
|
): Promise<any>; // tslint:disable-line:no-any
|
||||||
returnJsonArray(jsonData: IDataObject | IDataObject[]): INodeExecutionData[];
|
returnJsonArray(jsonData: IDataObject | IDataObject[]): INodeExecutionData[];
|
||||||
httpRequestWithAuthentication(
|
httpRequestWithAuthentication(
|
||||||
|
@ -299,16 +293,6 @@ export interface IWorkflowSettings extends IWorkflowSettingsWorkflow {
|
||||||
saveManualRuns?: boolean;
|
saveManualRuns?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// New node definition in file
|
|
||||||
export interface INodeDefinitionFile {
|
|
||||||
[key: string]: Constructable<INodeType | ICredentialType>;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Is identical to TaskDataConnections but does not allow null value to be used as input for nodes
|
|
||||||
export interface INodeInputDataConnections {
|
|
||||||
[key: string]: INodeExecutionData[][];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IWorkflowData {
|
export interface IWorkflowData {
|
||||||
pollResponses?: IPollResponse[];
|
pollResponses?: IPollResponse[];
|
||||||
triggerResponses?: ITriggerResponse[];
|
triggerResponses?: ITriggerResponse[];
|
||||||
|
|
82
packages/core/src/LoadNodeDetails.ts
Normal file
82
packages/core/src/LoadNodeDetails.ts
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
import type {
|
||||||
|
INode,
|
||||||
|
INodeCredentials,
|
||||||
|
INodeParameters,
|
||||||
|
INodeTypeNameVersion,
|
||||||
|
INodeTypes,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
import { Workflow } from 'n8n-workflow';
|
||||||
|
|
||||||
|
const TEMP_NODE_NAME = 'Temp-Node';
|
||||||
|
const TEMP_WORKFLOW_NAME = 'Temp-Workflow';
|
||||||
|
|
||||||
|
export abstract class LoadNodeDetails {
|
||||||
|
path: string;
|
||||||
|
|
||||||
|
workflow: Workflow;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
nodeTypeNameAndVersion: INodeTypeNameVersion,
|
||||||
|
nodeTypes: INodeTypes,
|
||||||
|
path: string,
|
||||||
|
currentNodeParameters: INodeParameters,
|
||||||
|
credentials?: INodeCredentials,
|
||||||
|
) {
|
||||||
|
const nodeType = nodeTypes.getByNameAndVersion(
|
||||||
|
nodeTypeNameAndVersion.name,
|
||||||
|
nodeTypeNameAndVersion.version,
|
||||||
|
);
|
||||||
|
|
||||||
|
this.path = path;
|
||||||
|
|
||||||
|
if (nodeType === undefined) {
|
||||||
|
throw new Error(
|
||||||
|
`The node-type "${nodeTypeNameAndVersion.name} v${nodeTypeNameAndVersion.version}" is not known!`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const nodeData: INode = {
|
||||||
|
parameters: currentNodeParameters,
|
||||||
|
id: 'uuid-1234',
|
||||||
|
name: TEMP_NODE_NAME,
|
||||||
|
type: nodeTypeNameAndVersion.name,
|
||||||
|
typeVersion: nodeTypeNameAndVersion.version,
|
||||||
|
position: [0, 0],
|
||||||
|
};
|
||||||
|
|
||||||
|
if (credentials) {
|
||||||
|
nodeData.credentials = credentials;
|
||||||
|
}
|
||||||
|
|
||||||
|
const workflowData = {
|
||||||
|
nodes: [nodeData],
|
||||||
|
connections: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
this.workflow = new Workflow({
|
||||||
|
nodes: workflowData.nodes,
|
||||||
|
connections: workflowData.connections,
|
||||||
|
active: false,
|
||||||
|
nodeTypes,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns data of a fake workflow
|
||||||
|
*/
|
||||||
|
getWorkflowData() {
|
||||||
|
return {
|
||||||
|
name: TEMP_WORKFLOW_NAME,
|
||||||
|
active: false,
|
||||||
|
connections: {},
|
||||||
|
nodes: Object.values(this.workflow.nodes),
|
||||||
|
createdAt: new Date(),
|
||||||
|
updatedAt: new Date(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getTempNode() {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
return this.workflow.getNode(TEMP_NODE_NAME)!;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,104 +1,11 @@
|
||||||
/* eslint-disable no-restricted-syntax */
|
import type { INodeListSearchResult, IWorkflowExecuteAdditionalData } from 'n8n-workflow';
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
||||||
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
||||||
|
|
||||||
import {
|
|
||||||
INode,
|
|
||||||
INodeCredentials,
|
|
||||||
INodeListSearchResult,
|
|
||||||
INodeParameters,
|
|
||||||
INodeTypeNameVersion,
|
|
||||||
INodeTypes,
|
|
||||||
IWorkflowExecuteAdditionalData,
|
|
||||||
Workflow,
|
|
||||||
} from 'n8n-workflow';
|
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-cycle
|
|
||||||
import { NodeExecuteFunctions } from '.';
|
import { NodeExecuteFunctions } from '.';
|
||||||
|
import { LoadNodeDetails } from './LoadNodeDetails';
|
||||||
|
|
||||||
const TEMP_NODE_NAME = 'Temp-Node';
|
export class LoadNodeListSearch extends LoadNodeDetails {
|
||||||
const TEMP_WORKFLOW_NAME = 'Temp-Workflow';
|
|
||||||
|
|
||||||
export class LoadNodeListSearch {
|
|
||||||
currentNodeParameters: INodeParameters;
|
|
||||||
|
|
||||||
path: string;
|
|
||||||
|
|
||||||
workflow: Workflow;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
nodeTypeNameAndVersion: INodeTypeNameVersion,
|
|
||||||
nodeTypes: INodeTypes,
|
|
||||||
path: string,
|
|
||||||
currentNodeParameters: INodeParameters,
|
|
||||||
credentials?: INodeCredentials,
|
|
||||||
) {
|
|
||||||
const nodeType = nodeTypes.getByNameAndVersion(
|
|
||||||
nodeTypeNameAndVersion.name,
|
|
||||||
nodeTypeNameAndVersion.version,
|
|
||||||
);
|
|
||||||
this.currentNodeParameters = currentNodeParameters;
|
|
||||||
this.path = path;
|
|
||||||
if (nodeType === undefined) {
|
|
||||||
throw new Error(
|
|
||||||
`The node-type "${nodeTypeNameAndVersion.name} v${nodeTypeNameAndVersion.version}" is not known!`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const nodeData: INode = {
|
|
||||||
parameters: currentNodeParameters,
|
|
||||||
id: 'uuid-1234',
|
|
||||||
name: TEMP_NODE_NAME,
|
|
||||||
type: nodeTypeNameAndVersion.name,
|
|
||||||
typeVersion: nodeTypeNameAndVersion.version,
|
|
||||||
position: [0, 0],
|
|
||||||
};
|
|
||||||
if (credentials) {
|
|
||||||
nodeData.credentials = credentials;
|
|
||||||
}
|
|
||||||
|
|
||||||
const workflowData = {
|
|
||||||
nodes: [nodeData],
|
|
||||||
connections: {},
|
|
||||||
};
|
|
||||||
|
|
||||||
this.workflow = new Workflow({
|
|
||||||
nodes: workflowData.nodes,
|
|
||||||
connections: workflowData.connections,
|
|
||||||
active: false,
|
|
||||||
nodeTypes,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns data of a fake workflow
|
|
||||||
*
|
|
||||||
* @returns
|
|
||||||
* @memberof LoadNodeParameterOptions
|
|
||||||
*/
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
||||||
getWorkflowData() {
|
|
||||||
return {
|
|
||||||
name: TEMP_WORKFLOW_NAME,
|
|
||||||
active: false,
|
|
||||||
connections: {},
|
|
||||||
nodes: Object.values(this.workflow.nodes),
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the available options via a predefined method
|
* Returns the available options via a predefined method
|
||||||
*
|
|
||||||
* @param {string} methodName The name of the method of which to get the data from
|
|
||||||
* @param {IWorkflowExecuteAdditionalData} additionalData
|
|
||||||
* @returns {Promise<INodePropertyOptions[]>}
|
|
||||||
* @memberof LoadNodeParameterOptions
|
|
||||||
*/
|
*/
|
||||||
async getOptionsViaMethodName(
|
async getOptionsViaMethodName(
|
||||||
methodName: string,
|
methodName: string,
|
||||||
|
@ -106,28 +13,24 @@ export class LoadNodeListSearch {
|
||||||
filter?: string,
|
filter?: string,
|
||||||
paginationToken?: string,
|
paginationToken?: string,
|
||||||
): Promise<INodeListSearchResult> {
|
): Promise<INodeListSearchResult> {
|
||||||
const node = this.workflow.getNode(TEMP_NODE_NAME);
|
const node = this.getTempNode();
|
||||||
|
|
||||||
const nodeType = this.workflow.nodeTypes.getByNameAndVersion(node!.type, node?.typeVersion);
|
const nodeType = this.workflow.nodeTypes.getByNameAndVersion(node.type, node.typeVersion);
|
||||||
|
const method = nodeType?.methods?.listSearch?.[methodName];
|
||||||
|
|
||||||
if (
|
if (typeof method !== 'function') {
|
||||||
!nodeType ||
|
|
||||||
nodeType.methods === undefined ||
|
|
||||||
nodeType.methods.listSearch === undefined ||
|
|
||||||
nodeType.methods.listSearch[methodName] === undefined
|
|
||||||
) {
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`The node-type "${node!.type}" does not have the method "${methodName}" defined!`,
|
`The node-type "${node.type}" does not have the method "${methodName}" defined!`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const thisArgs = NodeExecuteFunctions.getLoadOptionsFunctions(
|
const thisArgs = NodeExecuteFunctions.getLoadOptionsFunctions(
|
||||||
this.workflow,
|
this.workflow,
|
||||||
node!,
|
node,
|
||||||
this.path,
|
this.path,
|
||||||
additionalData,
|
additionalData,
|
||||||
);
|
);
|
||||||
|
|
||||||
return nodeType.methods.listSearch[methodName].call(thisArgs, filter, paginationToken);
|
return method.call(thisArgs, filter, paginationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,154 +1,59 @@
|
||||||
/* eslint-disable no-restricted-syntax */
|
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
||||||
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ILoadOptions,
|
ILoadOptions,
|
||||||
INode,
|
|
||||||
INodeCredentials,
|
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodeParameters,
|
|
||||||
INodeProperties,
|
INodeProperties,
|
||||||
INodePropertyOptions,
|
INodePropertyOptions,
|
||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeNameVersion,
|
|
||||||
INodeTypes,
|
|
||||||
IRunExecutionData,
|
IRunExecutionData,
|
||||||
ITaskDataConnections,
|
ITaskDataConnections,
|
||||||
IWorkflowExecuteAdditionalData,
|
IWorkflowExecuteAdditionalData,
|
||||||
RoutingNode,
|
RoutingNode,
|
||||||
Workflow,
|
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-cycle
|
|
||||||
import { NodeExecuteFunctions } from '.';
|
import { NodeExecuteFunctions } from '.';
|
||||||
|
import { LoadNodeDetails } from './LoadNodeDetails';
|
||||||
|
|
||||||
const TEMP_NODE_NAME = 'Temp-Node';
|
export class LoadNodeParameterOptions extends LoadNodeDetails {
|
||||||
const TEMP_WORKFLOW_NAME = 'Temp-Workflow';
|
|
||||||
|
|
||||||
export class LoadNodeParameterOptions {
|
|
||||||
currentNodeParameters: INodeParameters;
|
|
||||||
|
|
||||||
path: string;
|
|
||||||
|
|
||||||
workflow: Workflow;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
nodeTypeNameAndVersion: INodeTypeNameVersion,
|
|
||||||
nodeTypes: INodeTypes,
|
|
||||||
path: string,
|
|
||||||
currentNodeParameters: INodeParameters,
|
|
||||||
credentials?: INodeCredentials,
|
|
||||||
) {
|
|
||||||
const nodeType = nodeTypes.getByNameAndVersion(
|
|
||||||
nodeTypeNameAndVersion.name,
|
|
||||||
nodeTypeNameAndVersion.version,
|
|
||||||
);
|
|
||||||
this.currentNodeParameters = currentNodeParameters;
|
|
||||||
this.path = path;
|
|
||||||
if (nodeType === undefined) {
|
|
||||||
throw new Error(
|
|
||||||
`The node-type "${nodeTypeNameAndVersion.name} v${nodeTypeNameAndVersion.version}" is not known!`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const nodeData: INode = {
|
|
||||||
parameters: currentNodeParameters,
|
|
||||||
id: 'uuid-1234',
|
|
||||||
name: TEMP_NODE_NAME,
|
|
||||||
type: nodeTypeNameAndVersion.name,
|
|
||||||
typeVersion: nodeTypeNameAndVersion.version,
|
|
||||||
position: [0, 0],
|
|
||||||
};
|
|
||||||
if (credentials) {
|
|
||||||
nodeData.credentials = credentials;
|
|
||||||
}
|
|
||||||
|
|
||||||
const workflowData = {
|
|
||||||
nodes: [nodeData],
|
|
||||||
connections: {},
|
|
||||||
};
|
|
||||||
|
|
||||||
this.workflow = new Workflow({
|
|
||||||
nodes: workflowData.nodes,
|
|
||||||
connections: workflowData.connections,
|
|
||||||
active: false,
|
|
||||||
nodeTypes,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns data of a fake workflow
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
||||||
getWorkflowData() {
|
|
||||||
return {
|
|
||||||
name: TEMP_WORKFLOW_NAME,
|
|
||||||
active: false,
|
|
||||||
connections: {},
|
|
||||||
nodes: Object.values(this.workflow.nodes),
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the available options via a predefined method
|
* Returns the available options via a predefined method
|
||||||
*
|
|
||||||
* @param {string} methodName The name of the method of which to get the data from
|
|
||||||
*/
|
*/
|
||||||
async getOptionsViaMethodName(
|
async getOptionsViaMethodName(
|
||||||
methodName: string,
|
methodName: string,
|
||||||
additionalData: IWorkflowExecuteAdditionalData,
|
additionalData: IWorkflowExecuteAdditionalData,
|
||||||
): Promise<INodePropertyOptions[]> {
|
): Promise<INodePropertyOptions[]> {
|
||||||
const node = this.workflow.getNode(TEMP_NODE_NAME);
|
const node = this.getTempNode();
|
||||||
|
|
||||||
const nodeType = this.workflow.nodeTypes.getByNameAndVersion(node!.type, node?.typeVersion);
|
const nodeType = this.workflow.nodeTypes.getByNameAndVersion(node.type, node.typeVersion);
|
||||||
|
const method = nodeType?.methods?.loadOptions?.[methodName];
|
||||||
|
|
||||||
if (
|
if (typeof method !== 'function') {
|
||||||
!nodeType ||
|
|
||||||
nodeType.methods === undefined ||
|
|
||||||
nodeType.methods.loadOptions === undefined ||
|
|
||||||
nodeType.methods.loadOptions[methodName] === undefined
|
|
||||||
) {
|
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`The node-type "${node!.type}" does not have the method "${methodName}" defined!`,
|
`The node-type "${node.type}" does not have the method "${methodName}" defined!`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const thisArgs = NodeExecuteFunctions.getLoadOptionsFunctions(
|
const thisArgs = NodeExecuteFunctions.getLoadOptionsFunctions(
|
||||||
this.workflow,
|
this.workflow,
|
||||||
node!,
|
node,
|
||||||
this.path,
|
this.path,
|
||||||
additionalData,
|
additionalData,
|
||||||
);
|
);
|
||||||
|
|
||||||
return nodeType.methods.loadOptions[methodName].call(thisArgs);
|
return method.call(thisArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the available options via a load request information
|
* Returns the available options via a load request information
|
||||||
*
|
|
||||||
* @param {ILoadOptions} loadOptions The load options which also contain the request information
|
|
||||||
*/
|
*/
|
||||||
async getOptionsViaRequestProperty(
|
async getOptionsViaRequestProperty(
|
||||||
loadOptions: ILoadOptions,
|
loadOptions: ILoadOptions,
|
||||||
additionalData: IWorkflowExecuteAdditionalData,
|
additionalData: IWorkflowExecuteAdditionalData,
|
||||||
): Promise<INodePropertyOptions[]> {
|
): Promise<INodePropertyOptions[]> {
|
||||||
const node = this.workflow.getNode(TEMP_NODE_NAME);
|
const node = this.getTempNode();
|
||||||
|
|
||||||
const nodeType = this.workflow.nodeTypes.getByNameAndVersion(node!.type, node?.typeVersion);
|
const nodeType = this.workflow.nodeTypes.getByNameAndVersion(node.type, node?.typeVersion);
|
||||||
|
|
||||||
if (
|
if (!nodeType?.description?.requestDefaults?.baseURL) {
|
||||||
nodeType === undefined ||
|
|
||||||
!nodeType.description.requestDefaults ||
|
|
||||||
!nodeType.description.requestDefaults.baseURL
|
|
||||||
) {
|
|
||||||
// This in in here for now for security reasons.
|
// This in in here for now for security reasons.
|
||||||
// Background: As the full data for the request to make does get send, and the auth data
|
// Background: As the full data for the request to make does get send, and the auth data
|
||||||
// will then be applied, would it be possible to retrieve that data like that. By at least
|
// will then be applied, would it be possible to retrieve that data like that. By at least
|
||||||
|
@ -156,9 +61,7 @@ export class LoadNodeParameterOptions {
|
||||||
// In the future this code has to get improved that it does not use the request information from
|
// In the future this code has to get improved that it does not use the request information from
|
||||||
// the request rather resolves it via the parameter-path and nodeType data.
|
// the request rather resolves it via the parameter-path and nodeType data.
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`The node-type "${
|
`The node-type "${node.type}" does not exist or does not have "requestDefaults.baseURL" defined!`,
|
||||||
node!.type
|
|
||||||
}" does not exist or does not have "requestDefaults.baseURL" defined!`,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +72,7 @@ export class LoadNodeParameterOptions {
|
||||||
|
|
||||||
const routingNode = new RoutingNode(
|
const routingNode = new RoutingNode(
|
||||||
this.workflow,
|
this.workflow,
|
||||||
node!,
|
node,
|
||||||
connectionInputData,
|
connectionInputData,
|
||||||
runExecutionData ?? null,
|
runExecutionData ?? null,
|
||||||
additionalData,
|
additionalData,
|
||||||
|
@ -203,7 +106,7 @@ export class LoadNodeParameterOptions {
|
||||||
inputData,
|
inputData,
|
||||||
runIndex,
|
runIndex,
|
||||||
tempNode,
|
tempNode,
|
||||||
{ node: node!, source: null, data: {} },
|
{ node, source: null, data: {} },
|
||||||
NodeExecuteFunctions,
|
NodeExecuteFunctions,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue