mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(Set Node): Overhaul (#6348)
Github issue / Community forum post (link here to close automatically): https://github.com/n8n-io/n8n/pull/6348 --------- Co-authored-by: Giulio Andreini <g.andreini@gmail.com> Co-authored-by: Marcus <marcus@n8n.io>
This commit is contained in:
69
packages/nodes-base/nodes/Set/v2/raw.mode.ts
Normal file
69
packages/nodes-base/nodes/Set/v2/raw.mode.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import type {
|
||||
INodeExecutionData,
|
||||
IExecuteFunctions,
|
||||
INodeProperties,
|
||||
IDataObject,
|
||||
INode,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { parseJsonParameter, composeReturnItem, resolveRawData } from './helpers/utils';
|
||||
import type { SetNodeOptions } from './helpers/interfaces';
|
||||
import { updateDisplayOptions } from '../../../utils/utilities';
|
||||
|
||||
const properties: INodeProperties[] = [
|
||||
{
|
||||
displayName: 'JSON Output',
|
||||
name: 'jsonOutput',
|
||||
type: 'string',
|
||||
typeOptions: {
|
||||
editor: 'json',
|
||||
editorLanguage: 'json',
|
||||
rows: 5,
|
||||
},
|
||||
default: '{\n "my_field_1": "value",\n "my_field_2": 1\n}',
|
||||
validateType: 'object',
|
||||
ignoreValidationDuringExecution: true,
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
mode: ['raw'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(
|
||||
this: IExecuteFunctions,
|
||||
item: INodeExecutionData,
|
||||
i: number,
|
||||
options: SetNodeOptions,
|
||||
rawData: IDataObject,
|
||||
node: INode,
|
||||
) {
|
||||
try {
|
||||
let newData: IDataObject;
|
||||
if (rawData.jsonOutput === undefined) {
|
||||
const json = this.getNodeParameter('jsonOutput', i) as string;
|
||||
newData = parseJsonParameter(json, node, i);
|
||||
} else {
|
||||
newData = parseJsonParameter(
|
||||
resolveRawData.call(this, rawData.jsonOutput as string, i),
|
||||
node,
|
||||
i,
|
||||
);
|
||||
}
|
||||
|
||||
return composeReturnItem.call(this, i, item, newData, options);
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
return { json: { error: (error as Error).message } };
|
||||
}
|
||||
throw new NodeOperationError(node, error as Error, {
|
||||
itemIndex: i,
|
||||
description: error.description,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user