n8n/packages/nodes-base/nodes/Set/v2/raw.mode.ts
कारतोफ्फेलस्क्रिप्ट™ 216ec079c9
feat(editor): Create separate components for JS and JSON editors (no-changelog) (#8156)
## Summary
This is part-1 of refactoring our code editors to extract different type
of editors into their own components.
In part-2 we'll
1. delete a of unused or duplicate code
2. switch to a `useEditor` composable to bring more UX consistency
across all the code editors.

## Review / Merge checklist
- [x] PR title and summary are descriptive
- [x] Tests included
2023-12-29 10:49:27 +01:00

68 lines
1.6 KiB
TypeScript

import type {
INodeExecutionData,
IExecuteFunctions,
INodeProperties,
IDataObject,
INode,
} from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { updateDisplayOptions } from '../../../utils/utilities';
import { parseJsonParameter, composeReturnItem, resolveRawData } from './helpers/utils';
import type { SetNodeOptions } from './helpers/interfaces';
const properties: INodeProperties[] = [
{
displayName: 'JSON Output',
name: 'jsonOutput',
type: 'json',
typeOptions: {
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 }, pairedItem: { item: i } };
}
throw new NodeOperationError(node, error as Error, {
itemIndex: i,
description: error.description,
});
}
}