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
@@ -62,6 +62,31 @@ export const jsonParse = <T>(jsonString: string, options?: JSONParseOptions<T>):
|
||||
}
|
||||
};
|
||||
|
||||
type JSONStringifyOptions = {
|
||||
replaceCircularRefs?: boolean;
|
||||
circularRefReplacement?: string;
|
||||
};
|
||||
|
||||
const getReplaceCircularReferencesFn = (options: JSONStringifyOptions) => {
|
||||
const knownObjects = new WeakSet();
|
||||
return (key: any, value: any) => {
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
if (knownObjects.has(value)) {
|
||||
return options?.circularRefReplacement ?? '[Circular Reference]';
|
||||
}
|
||||
knownObjects.add(value);
|
||||
}
|
||||
return value;
|
||||
};
|
||||
};
|
||||
|
||||
export const jsonStringify = (obj: unknown, options: JSONStringifyOptions = {}): string => {
|
||||
const replacer = options?.replaceCircularRefs
|
||||
? getReplaceCircularReferencesFn(options)
|
||||
: undefined;
|
||||
return JSON.stringify(obj, replacer);
|
||||
};
|
||||
|
||||
export const sleep = async (ms: number): Promise<void> =>
|
||||
new Promise((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
|
||||
Reference in New Issue
Block a user