From d8af5effe9004aae292f8c06a8cbcfd62f5191de Mon Sep 17 00:00:00 2001 From: YISH Date: Fri, 23 Feb 2024 15:52:26 +0800 Subject: [PATCH] =?UTF-8?q?Allow=20default=20variable=20values=20=E2=80=8B?= =?UTF-8?q?=E2=80=8Bwhen=20testing=20CustomFunction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ```js const question = $question ?? 'my default question' ``` --- packages/server/src/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index 20102a42..e2ccae81 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -307,7 +307,10 @@ export class App { // execute custom function node this.app.post('/api/v1/node-custom-function', async (req: Request, res: Response) => { const body = req.body - const nodeData = { inputs: body } + const functionInputVariables = Object.fromEntries( + [...(body?.javascriptFunction ?? '').matchAll(/\$([a-zA-Z0-9_]+)/g)].map((g) => [g[1], undefined]) + ) + const nodeData = { inputs: { functionInputVariables, ...body } } if (Object.prototype.hasOwnProperty.call(this.nodesPool.componentNodes, 'customFunction')) { try { const nodeInstanceFilePath = this.nodesPool.componentNodes['customFunction'].filePath as string