Add basic support for messages to the state graph
@@ -34,6 +34,8 @@ function getGraphFromState(applicationState: OakApplicationState) {
`channel${channelId.toString()}`;
const getHandleDotId = (nodeId: NodeId, handle: AbiHandle) =>
`node${nodeId.toString()}_${handle.toString()}`;
+ const getMessageDotId = (channelId: ChannelID, messageIndex: number) =>
+ `msg${channelId.toString()}_${messageIndex}`;
const oakNodes = [...applicationState.nodeInfos.entries()].map(
([nodeId, nodeInfo]) => `${getNodeDotId(nodeId)} [label="${nodeInfo.name}"]`
@@ -49,7 +51,14 @@ function getGraphFromState(applicationState: OakApplicationState) {
const oakChannels = [
...applicationState.channels.entries(),
].map(([channelId]) => getChannelDotId(channelId));
- const connections = [...applicationState.nodeInfos.entries()]
+ const oakMessages = [
+ ...applicationState.channels.entries(),
+ ].map(([channelId, channel]) =>
+ channel.messages.map((message, index) => getMessageDotId(channelId, index))
+ );
+ const connections = [
+ // Connections between nodes, handles, & channels
+ ...[...applicationState.nodeInfos.entries()]
.map(([nodeId, nodeInfo]) =>
[...nodeInfo.abiHandles.entries()].map(([handle, channelHalf]) => {
switch (channelHalf.direction) {
@@ -62,7 +71,9 @@ function getGraphFromState(applicationState: OakApplicationState) {
case ChannelHalfDirection.Read:
return `${getChannelDotId(
channelHalf.channelId
- )} -> ${getHandleDotId(nodeId, handle)} -> ${getNodeDotId(nodeId)}`;
+ )} -> ${getHandleDotId(nodeId, handle)} -> ${getNodeDotId(
+ nodeId
+ )}`;
default:
// This should never happen
@@ -72,7 +83,24 @@ function getGraphFromState(applicationState: OakApplicationState) {
}
})
)
- .flat();
+ .flat(),
+ // Connections between channels & messages
+ 'edge [arrowhead=none]',
+ ...[...applicationState.channels.entries()].map(([channelId, channel]) =>
+ channel.messages.map((message, index) =>
+ index === 0
+ ? // Connect the first message to the channel
+ `${getMessageDotId(channelId, index)} -> ${getChannelDotId(
+ channelId
+ )}`
+ : // Connect subsequent messages to the previous message
+ `${getMessageDotId(channelId, index)} -> ${getMessageDotId(
+ channelId,
+ index - 1
+ )}`
+ )
+ ),
+ ];
return `digraph Runtime {
graph [bgcolor=transparent]
@@ -88,6 +116,10 @@ function getGraphFromState(applicationState: OakApplicationState) {
node [shape=ellipse style=filled fillcolor=green]
${oakChannels.join('\n ')}
}
+ {
+ node [shape=rect fontsize=10 label="msg"]
+ ${oakMessages.join('\n ')}
+ }
${connections.join('\n ')}
}
`;
