跳到主要内容

代码节点(type = "code")

执行自定义 JavaScript 逻辑,对上下文进行任意变换。

Schema

  • 参考: CodeNode.json
  • 核心字段:
    • data.inputs:输入 Schema
    • data.inputsValues:输入字段来源
    • data.script:脚本(language / content
    • data.outputs:输出 Schema

示例

脚本入口函数形如:

async function main(params) {
return {
ok: true,
echo: params
};
}

把 HTTP 返回加工为 End 输出(示意):

{
"nodes": [
{ "id": "http_0", "type": "http" },
{
"id": "code_0",
"type": "code",
"data": {
"inputsValues": {
"input": { "type": "ref", "content": ["http_0", "body"] }
},
"script": { "language": "javascript", "content": "async function main(params){ return { result: params.input }; }" }
}
}
],
"edges": [{ "sourceNodeID": "http_0", "targetNodeID": "code_0" }]
}