refactor(Code Node): Constently handle various kinds of data returned by user code (#6002)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-04-19 13:09:46 +02:00
committed by GitHub
parent fe058aa8ee
commit f9b3aeac44
6 changed files with 309 additions and 220 deletions

View File

@@ -1,7 +1,9 @@
import type { IDataObject } from 'n8n-workflow';
export function isObject(maybe: unknown): maybe is { [key: string]: unknown } {
return typeof maybe === 'object' && maybe !== null && !Array.isArray(maybe);
return (
typeof maybe === 'object' && maybe !== null && !Array.isArray(maybe) && !(maybe instanceof Date)
);
}
function isTraversable(maybe: unknown): maybe is IDataObject {
@@ -13,7 +15,6 @@ function isTraversable(maybe: unknown): maybe is IDataObject {
*/
export function standardizeOutput(output: IDataObject) {
function standardizeOutputRecursive(obj: IDataObject, knownObjects = new WeakSet()): IDataObject {
if (obj === undefined || obj === null) return obj;
for (const [key, value] of Object.entries(obj)) {
if (!isTraversable(value)) continue;