import {ConnectionBodyChunk} from "../chunks/types/ConnectionBodyChunk"; import {childPortChunkToChildPortRef} from "./childPortChunkToChildPortRef"; import {Connection} from "./types/Connection"; import {PortDirection} from "./types/PortDirection"; export function connectionBodyChunkToConnection( connectionBodyChunk: ConnectionBodyChunk ): Connection | null { const { captures: { 1: portChunk1, 2: portChunk2 } } = connectionBodyChunk; const childPortRef1 = childPortChunkToChildPortRef(portChunk1); const childPortRef2 = childPortChunkToChildPortRef(portChunk2); const {direction: portDirection1} = childPortRef1; const {direction: portDirection2} = childPortRef2; if ( portDirection1 === PortDirection.output && portDirection2 === PortDirection.input ) { return {from: childPortRef1, to: childPortRef2}; } else if ( portDirection1 === PortDirection.input && portDirection2 === PortDirection.output ) { return {from: childPortRef2, to: childPortRef1}; } else { return null; } }