Skip to content

Commit

Permalink
feat(core): Add batching and other options to declarative nodes (#8885)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kret <michael.k@radency.com>
  • Loading branch information
janober and michael-radency authored Jun 7, 2024
1 parent e520f8a commit 4e56863
Show file tree
Hide file tree
Showing 4 changed files with 511 additions and 75 deletions.
1 change: 1 addition & 0 deletions packages/editor-ui/src/components/NodeSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
:parameters="parametersSetting"
:node-values="nodeValues"
:is-read-only="isReadOnly"
:hide-delete="true"
:hidden-issues-inputs="hiddenIssuesInputs"
path="parameters"
@value-changed="valueChanged"
Expand Down
130 changes: 130 additions & 0 deletions packages/workflow/src/NodeHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,134 @@ const commonCORSParameters: INodeProperties[] = [
},
];

const declarativeNodeOptionParameters: INodeProperties = {
displayName: 'Request Options',
name: 'requestOptions',
type: 'collection',
isNodeSetting: true,
placeholder: 'Add Option',
default: {},
options: [
{
displayName: 'Batching',
name: 'batching',
placeholder: 'Add Batching',
type: 'fixedCollection',
typeOptions: {
multipleValues: false,
},
default: {
batch: {},
},
options: [
{
displayName: 'Batching',
name: 'batch',
values: [
{
displayName: 'Items per Batch',
name: 'batchSize',
type: 'number',
typeOptions: {
minValue: -1,
},
default: 50,
description:
'Input will be split in batches to throttle requests. -1 for disabled. 0 will be treated as 1.',
},
{
displayName: 'Batch Interval (ms)',
name: 'batchInterval',
type: 'number',
typeOptions: {
minValue: 0,
},
default: 1000,
description: 'Time (in milliseconds) between each batch of requests. 0 for disabled.',
},
],
},
],
},
{
displayName: 'Ignore SSL Issues',
name: 'allowUnauthorizedCerts',
type: 'boolean',
noDataExpression: true,
default: false,
description:
'Whether to accept the response even if SSL certificate validation is not possible',
},
{
displayName: 'Proxy',
name: 'proxy',
type: 'string',
default: '',
placeholder: 'e.g. http://myproxy:3128',
description:
'HTTP proxy to use. If authentication is required it can be defined as follow: http://username:password@myproxy:3128',
},
{
displayName: 'Timeout',
name: 'timeout',
type: 'number',
typeOptions: {
minValue: 1,
},
default: 10000,
description:
'Time in ms to wait for the server to send response headers (and start the response body) before aborting the request',
},
],
};

export function applyDeclarativeNodeOptionParameters(nodeType: INodeType): void {
if (nodeType.execute || nodeType.trigger || nodeType.webhook || nodeType.description.polling) {
return;
}

const parameters = nodeType.description.properties;

if (!parameters) {
return;
}

// Was originally under "options" instead of "requestOptions" so the chance
// that that existed was quite high. With this name the chance is actually
// very low that it already exists but lets leave it in anyway to be sure.
const existingRequestOptionsIndex = parameters.findIndex(
(parameter) => parameter.name === 'requestOptions',
);
if (existingRequestOptionsIndex !== -1) {
parameters[existingRequestOptionsIndex] = {
...declarativeNodeOptionParameters,
options: [
...(declarativeNodeOptionParameters.options || []),
...(parameters[existingRequestOptionsIndex]?.options || []),
],
};

if (parameters[existingRequestOptionsIndex]?.options) {
parameters[existingRequestOptionsIndex].options!.sort((a, b) => {
if ('displayName' in a && 'displayName' in b) {
if (a.displayName < b.displayName) {
return -1;
}
if (a.displayName > b.displayName) {
return 1;
}
}

return 0;
});
}
} else {
parameters.push(declarativeNodeOptionParameters);
}

return;
}

/**
* Apply special parameters which should be added to nodeTypes depending on their type or configuration
*/
Expand All @@ -289,6 +417,8 @@ export function applySpecialNodeParameters(nodeType: INodeType): void {
];
else properties.push(...commonCORSParameters);
}

applyDeclarativeNodeOptionParameters(nodeType);
}

const getPropertyValues = (
Expand Down
Loading

0 comments on commit 4e56863

Please sign in to comment.