feat(code): Improve the default code by adding usage comments
This commit is contained in:
@@ -42,7 +42,8 @@ export default defineAction({
|
|||||||
type: 'code',
|
type: 'code',
|
||||||
required: true,
|
required: true,
|
||||||
variables: false,
|
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 {
|
try {
|
||||||
const context = await isolate.createContext();
|
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 compiledCodeSnippet = await isolate.compileScript(
|
||||||
const codeFunction = await compiledCodeSnippet.run(context, { reference: true, promise: true });
|
`${codeSnippet}; code(inputs);`
|
||||||
|
);
|
||||||
|
const codeFunction = await compiledCodeSnippet.run(context, {
|
||||||
|
reference: true,
|
||||||
|
promise: true,
|
||||||
|
});
|
||||||
|
|
||||||
$.setActionItem({ raw: { output: await codeFunction.copy() } });
|
$.setActionItem({ raw: { output: await codeFunction.copy() } });
|
||||||
} finally {
|
} finally {
|
||||||
|
Reference in New Issue
Block a user