cloudv-graph2expression
v0.0.4
Published
从图生成表达式,用于完成`logicFlow` -> `liteFlow` 数据交换格式的转化
Downloads
2
Readme
cloudv-graph2expression
从图生成表达式,用于完成logicFlow
-> liteFlow
数据交换格式的转化
e.g.
假设从logicFlow
中获得了图结构,如下:
nodes = [
{
id: "a",
properties: {
isHead: true,
},
},
{
id: "b",
properties: {},
},
{
id: "c",
properties: {},
},
{
id: "d",
properties: {},
},
{
id: "e",
properties: {
isEnd: true
},
},
];
const edges = [
{
id: "a2b",
sourceNodeId: "a",
targetNodeId: "b",
properties: {},
},
{
id: "a2c",
sourceNodeId: "a",
targetNodeId: "c",
properties: {},
},
{
id: "a2d",
sourceNodeId: "a",
targetNodeId: "d",
properties: {},
},
{
id: "b2e",
sourceNodeId: "b",
targetNodeId: "e",
properties: {},
},
{
id: "c2e",
sourceNodeId: "c",
targetNodeId: "e",
properties: {},
},
{
id: "d2e",
sourceNodeId: "d",
targetNodeId: "e",
properties: {},
},
];
引入 graphToExpression
import graphToExpression from "cloudv-graph2expression";
const expression = graphToExpression(nodes, edges);
console.info(expression);
得到 expression
:
THEN(a,THEN(WHEN(b,c,d),e))
值得注意的是:要求图结构的开始和结束节点均只能有一个,且需要用properties中的isEnd或isHead标识,这是目前的权宜之计,后期会根据传入数据进行校验,不满足生成规则后,则会提醒反馈;