40 lines
1.8 KiB
JavaScript
40 lines
1.8 KiB
JavaScript
/* eslint-disable @typescript-eslint/no-for-in-array */
|
|
export function mapConnectionsByDestination(connections) {
|
|
const returnConnection = {};
|
|
let connectionInfo;
|
|
let maxIndex;
|
|
for (const sourceNode in connections) {
|
|
if (!connections.hasOwnProperty(sourceNode)) {
|
|
continue;
|
|
}
|
|
for (const type of Object.keys(connections[sourceNode])) {
|
|
if (!connections[sourceNode].hasOwnProperty(type)) {
|
|
continue;
|
|
}
|
|
for (const inputIndex in connections[sourceNode][type]) {
|
|
if (!connections[sourceNode][type].hasOwnProperty(inputIndex)) {
|
|
continue;
|
|
}
|
|
for (connectionInfo of connections[sourceNode][type][inputIndex] ?? []) {
|
|
if (!returnConnection.hasOwnProperty(connectionInfo.node)) {
|
|
returnConnection[connectionInfo.node] = {};
|
|
}
|
|
if (!returnConnection[connectionInfo.node].hasOwnProperty(connectionInfo.type)) {
|
|
returnConnection[connectionInfo.node][connectionInfo.type] = [];
|
|
}
|
|
maxIndex = returnConnection[connectionInfo.node][connectionInfo.type].length - 1;
|
|
for (let j = maxIndex; j < connectionInfo.index; j++) {
|
|
returnConnection[connectionInfo.node][connectionInfo.type].push([]);
|
|
}
|
|
returnConnection[connectionInfo.node][connectionInfo.type][connectionInfo.index]?.push({
|
|
node: sourceNode,
|
|
type,
|
|
index: parseInt(inputIndex, 10),
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return returnConnection;
|
|
}
|
|
//# sourceMappingURL=map-connections-by-destination.js.map
|