From 09985c4811c24991a511eaaee9bec018d2992a73 Mon Sep 17 00:00:00 2001 From: vxksf Date: Wed, 18 Aug 2021 17:43:09 -0300 Subject: [PATCH] fix the absence of circular structure treatment --- src/step.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/step.js b/src/step.js index b0f11d4..88d9caf 100644 --- a/src/step.js +++ b/src/step.js @@ -71,19 +71,32 @@ class Step { return Ok(ret) } + let circularStructureCache = [] + const _circularStructureHandling = (key, value) => { + if (typeof value === 'object' && value !== null) { + if (circularStructureCache.includes(value)) return + circularStructureCache.push(value) + } + return value + } + let ret = undefined this._auditTrail.description = this.description this._auditTrail.return = "" ret = await _runFunction() - if (ret !== undefined) this._auditTrail.return = JSON.parse(JSON.stringify(ret)) + if (ret !== undefined) { + this._auditTrail.return = JSON.parse(JSON.stringify(ret, _circularStructureHandling)) + circularStructureCache = [] + } + if (ret) { this._auditTrail.elapsedTime = process.hrtime.bigint() - startTime return ret } ret = await _runNestedSteps() - this._auditTrail.return = JSON.parse(JSON.stringify(ret)) + this._auditTrail.return = JSON.parse(JSON.stringify(ret, _circularStructureHandling)) this._auditTrail.elapsedTime = process.hrtime.bigint() - startTime return ret }