mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
* fix(core): make `deepCopy` backward compatible `JSON.parse(JSON.stringify())` uses `.toJSON` when available. so should `deepCopy` * fix(core): prevent double quotes on luxon datetimes (#4508) * 🐛 Prevent double quotes on luxon datetimes * ⚡ Generalize solution * update the types in packages/workflow/src/utils.ts * add `toJSON` check to NodeErrors.isTraversableObject as well * move the toJSON check before the cyclic dependency check * fix(core): keep backward compatibility in deepCopy by calling `toJSON` on objects that have it * fix(core): updating deepCopy typings * Revert "fix(core): updating deepCopy typings" This reverts commit 100a0f1f3d7ddac5425ccc8498381324f418d7a2. * fix(core): temporarily removing Date cloning from deepCopy * fix(core): updating deepCopy types * fix(core): updating deepCopy * fix(core): updating deepCopy get prototype of object Co-authored-by: Iván Ovejero <ivov.src@gmail.com> Co-authored-by: Csaba Tuncsik <csaba@n8n.io>
30 lines
960 B
TypeScript
30 lines
960 B
TypeScript
import type { IDataObject } from 'n8n-workflow';
|
|
|
|
/**
|
|
* Stringify any non-standard JS objects (e.g. `Date`, `RegExp`) inside output items at any depth.
|
|
*/
|
|
export function standardizeOutput(output: IDataObject) {
|
|
for (const [key, value] of Object.entries(output)) {
|
|
if (!isTraversable(value)) continue;
|
|
|
|
output[key] =
|
|
value.constructor.name !== 'Object'
|
|
? JSON.stringify(value) // Date, RegExp, etc.
|
|
: standardizeOutput(value);
|
|
}
|
|
|
|
return output;
|
|
}
|
|
|
|
export function isObject(maybe: unknown): maybe is { [key: string]: unknown } {
|
|
return typeof maybe === 'object' && maybe !== null && !Array.isArray(maybe);
|
|
}
|
|
|
|
function isTraversable(maybe: unknown): maybe is IDataObject {
|
|
return isObject(maybe) && typeof maybe.toJSON !== 'function' && Object.keys(maybe).length > 0;
|
|
}
|
|
|
|
export type CodeNodeMode = 'runOnceForAllItems' | 'runOnceForEachItem';
|
|
|
|
export const SUPPORTED_ITEM_KEYS = new Set(['json', 'binary', 'error', 'pairedItem', 'index']);
|