From 4f6727810baf6cb4980d44a2638d0e14fc3a1fed Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Wed, 31 Jul 2024 16:29:15 +0200 Subject: [PATCH] feat(code): Improve the default code by adding usage comments --- .../apps/code/actions/run-javascript/index.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/apps/code/actions/run-javascript/index.js b/packages/backend/src/apps/code/actions/run-javascript/index.js index ca36e50a..64020cec 100644 --- a/packages/backend/src/apps/code/actions/run-javascript/index.js +++ b/packages/backend/src/apps/code/actions/run-javascript/index.js @@ -42,7 +42,8 @@ export default defineAction({ type: 'code', required: true, variables: false, - value: 'const code = async (inputs) => { \n return true;\n};', + value: + 'const code = async (inputs) => { \n // E.g. if you have an input called username,\n // you can access its value by calling inputs.username\n // Return value will be used as output of this step.\n\n return true;\n};', }, ], @@ -59,10 +60,18 @@ export default defineAction({ try { const context = await isolate.createContext(); - await context.global.set('inputs', new ivm.ExternalCopy(objectifiedInput).copyInto()) + await context.global.set( + 'inputs', + new ivm.ExternalCopy(objectifiedInput).copyInto() + ); - const compiledCodeSnippet = await isolate.compileScript(`${codeSnippet}; code(inputs);`); - const codeFunction = await compiledCodeSnippet.run(context, { reference: true, promise: true }); + const compiledCodeSnippet = await isolate.compileScript( + `${codeSnippet}; code(inputs);` + ); + const codeFunction = await compiledCodeSnippet.run(context, { + reference: true, + promise: true, + }); $.setActionItem({ raw: { output: await codeFunction.copy() } }); } finally {