diff --git a/dbux-code/src/dataFlowView/DataFlowNodeProvider.js b/dbux-code/src/dataFlowView/DataFlowNodeProvider.js index b787c9ee5..a6c801317 100644 --- a/dbux-code/src/dataFlowView/DataFlowNodeProvider.js +++ b/dbux-code/src/dataFlowView/DataFlowNodeProvider.js @@ -75,13 +75,21 @@ export default class DataFlowNodeProvider extends BaseTreeViewNodeProvider { } // apply filters - const { accessId, valueId } = dataNode; + const { accessId, valueId, refId } = dataNode; + /** + * @type {DataNode[]} + */ let dataNodes; + let firstNode = null; if (DataFlowSearchModeType.is.ByAccessId(this.controller.searchMode)) { dataNodes = dp.indexes.dataNodes.byAccessId.get(accessId); } else if (DataFlowSearchModeType.is.ByValueId(this.controller.searchMode)) { dataNodes = dp.indexes.dataNodes.byValueId.get(valueId); + + if (refId) { + firstNode = dp.util.getAnyFirstNodeByRefId(dataNode.refId); + } } if (DataFlowFilterModeType.is.ReadOnly(this.controller.filterMode)) { @@ -92,6 +100,13 @@ export default class DataFlowNodeProvider extends BaseTreeViewNodeProvider { } const dataTraceIds = new Set(); + + if (firstNode && dataNodes?.[0]?.nodeId !== firstNode.nodeId) { + // manually add first trace + // see https://github.com/Domiii/dbux/issues/702 + dataNodes.unshift(firstNode); + } + return dataNodes?.map((node) => { const dataTrace = dp.collections.traces.getById(node.traceId); if (dataTraceIds.has(dataTrace.traceId)) { diff --git a/dbux-data/src/collections/DataNodeCollection.js b/dbux-data/src/collections/DataNodeCollection.js index bcfeb5242..69bde4934 100644 --- a/dbux-data/src/collections/DataNodeCollection.js +++ b/dbux-data/src/collections/DataNodeCollection.js @@ -30,6 +30,8 @@ export default class DataNodeCollection extends Collection { if (dataNode.refId) { const firstRef = this.dp.indexes.dataNodes.byRefId.getFirst(dataNode.refId); + // const firstNodeId = this.dp.util.getAnyFirstNodeIdByRefId(dataNode.refId); + // return Math.min(firstNodeId, firstRef.nodeId); return firstRef.nodeId; } else { diff --git a/dbux-data/src/dataProviderUtil.js b/dbux-data/src/dataProviderUtil.js index f76107c73..28a0067ed 100644 --- a/dbux-data/src/dataProviderUtil.js +++ b/dbux-data/src/dataProviderUtil.js @@ -941,14 +941,48 @@ export default { return null; }, + /** @param {DataProvider} dp */ getDataNodesByRefId(dp, refId) { return dp.indexes.dataNodes.byRefId.get(refId); }, + /** @param {DataProvider} dp */ getFirstDataNodeByRefId(dp, refId) { return dp.indexes.dataNodes.byRefId.getFirst(refId); }, + /** + * Get first DataNode by refId, even if it does NOT OWN it. + * + * @param {DataProvider} dp + */ + getAnyFirstNodeIdByRefId(dp, refId) { + const ref = dp.collections.values.getById(refId); + const { nodeId } = ref; + // const { traceId } = dp.collections.dataNodes.getById(nodeId); + // return traceId; + return nodeId; + }, + + /** + * Get first DataNode by refId, even if it does NOT OWN it. + * + * @param {DataProvider} dp + */ + getAnyFirstNodeByRefId(dp, refId) { + const nodeId = dp.util.getAnyFirstNodeIdByRefId(refId); + return nodeId && dp.collections.dataNodes.getById(nodeId); + }, + + /** + * @param {DataProvider} dp + */ + getFirstTraceIdByNodeId(dp, nodeId) { + const { traceId } = dp.collections.dataNodes.getById(nodeId); + return traceId; + }, + + /** @param {DataProvider} dp */ getFirstTraceIdByRefId(dp, refId) { const dataNode = dp.indexes.dataNodes.byRefId.getFirst(refId); return dataNode?.traceId; diff --git a/dbux-runtime/src/data/dataNodeCollection.js b/dbux-runtime/src/data/dataNodeCollection.js index 99871ad3c..17c1e89ad 100644 --- a/dbux-runtime/src/data/dataNodeCollection.js +++ b/dbux-runtime/src/data/dataNodeCollection.js @@ -88,7 +88,18 @@ export class DataNodeCollection extends Collection { return writeNode; } - createDataNode(value, traceId, type, varAccess, inputs, meta = null) { + createRefDataNode(value, parentNodeId, propValue, refId) { + const { traceId } = this.getById(parentNodeId); + const type = DataNodeType.Write; + const varAccess = { + objectNodeId: parentNodeId, + prop: propValue + }; + const inputs = null, meta = null; + return this.createDataNode(value, traceId, type, varAccess, inputs, meta, refId); + } + + createDataNode(value, traceId, type, varAccess, inputs, meta = null, refId = null) { const dataNode = pools.dataNodes.allocate(); dataNode.nodeId = this._all.length; @@ -98,10 +109,13 @@ export class DataNodeCollection extends Collection { this.push(dataNode); - // valueRef - const valueRef = valueCollection.registerValueMaybe(value, dataNode, meta); + if (!refId) { + // valueRef + const valueRef = valueCollection.registerValueMaybe(value, dataNode, meta); + refId = valueRef?.refId || 0; + } - dataNode.refId = valueRef?.refId || 0; + dataNode.refId = refId; dataNode.varAccess = varAccess; if (Verbose) { diff --git a/dbux-runtime/src/data/valueCollection.js b/dbux-runtime/src/data/valueCollection.js index 75f417e31..13f21f282 100644 --- a/dbux-runtime/src/data/valueCollection.js +++ b/dbux-runtime/src/data/valueCollection.js @@ -541,7 +541,6 @@ class ValueCollection extends Collection { * @return {ValueRef} */ _serialize(value, nodeId, depth = 1, category = null, meta = null) { - // let serialized = serialize(category, value, serializationLimits); let serialized; let pruneState = ValuePruneState.Normal; let typeName = ''; @@ -669,10 +668,10 @@ class ValueCollection extends Collection { // start serializing serialized = {}; - const builtInSerializer = this.getBuiltInSerializer(value); - if (builtInSerializer) { + const serialize = this.getBuiltInSerializer(value); + if (serialize) { // serialize built-in types - especially: RegExp, Map, Set - builtInSerializer(value, nodeId, depth, serialized, valueRef, meta); + serialize(value, nodeId, depth, serialized, valueRef, meta); } else { // serialize object (default) diff --git a/samples/__samplesInput__/json-parse1.js b/samples/__samplesInput__/json-parse1.js new file mode 100644 index 000000000..d0daf46de --- /dev/null +++ b/samples/__samplesInput__/json-parse1.js @@ -0,0 +1,7 @@ +var a = JSON.parse('[{ "x": 1 }, { "x": 2 }]'); + +var b = a[0]; +var c = a[1]; + +console.log(a[0], b, a); +console.log(c); \ No newline at end of file