refactor(core): Extract duplicate utility functions and add unit tests (no-changelog) (#9814)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-06-20 12:09:23 +02:00
committed by GitHub
parent 283d1ca583
commit e4463c62b4
14 changed files with 207 additions and 199 deletions

View File

@@ -1,44 +1,5 @@
import get from 'lodash/get';
import isEqual from 'lodash/isEqual';
import isObject from 'lodash/isObject';
import merge from 'lodash/merge';
import reduce from 'lodash/reduce';
import {
NodeOperationError,
type IDataObject,
type INode,
type INodeExecutionData,
} from 'n8n-workflow';
export const compareItems = (
obj: INodeExecutionData,
obj2: INodeExecutionData,
keys: string[],
disableDotNotation: boolean,
_node: INode,
) => {
let result = true;
for (const key of keys) {
if (!disableDotNotation) {
if (!isEqual(get(obj.json, key), get(obj2.json, key))) {
result = false;
break;
}
} else {
if (!isEqual(obj.json[key], obj2.json[key])) {
result = false;
break;
}
}
}
return result;
};
export const flattenKeys = (obj: IDataObject, path: string[] = []): IDataObject => {
return !isObject(obj)
? { [path.join('.')]: obj }
: reduce(obj, (cum, next, key) => merge(cum, flattenKeys(next as IDataObject, [...path, key])), {}); //prettier-ignore
};
import { NodeOperationError, type INode, type INodeExecutionData } from 'n8n-workflow';
export const validateInputData = (
node: INode,