mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(core): Remove circular refs from Code and push msg (#5741)
* remove circular refs from code items (and lint fixes) * cleanup --------- * add some tests Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
committed by
GitHub
parent
199a91b398
commit
b6d8a0f985
@@ -12,15 +12,28 @@ function isTraversable(maybe: unknown): maybe is IDataObject {
|
||||
* 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;
|
||||
const knownObjects = new WeakSet();
|
||||
|
||||
output[key] =
|
||||
value.constructor.name !== 'Object'
|
||||
? JSON.stringify(value) // Date, RegExp, etc.
|
||||
: standardizeOutput(value);
|
||||
function standardizeOutputRecursive(obj: IDataObject): IDataObject {
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
if (!isTraversable(value)) continue;
|
||||
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
if (knownObjects.has(value)) {
|
||||
// Found circular reference
|
||||
continue;
|
||||
}
|
||||
knownObjects.add(value);
|
||||
}
|
||||
|
||||
obj[key] =
|
||||
value.constructor.name !== 'Object'
|
||||
? JSON.stringify(value) // Date, RegExp, etc.
|
||||
: standardizeOutputRecursive(value);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
standardizeOutputRecursive(output);
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user