diff --git a/mx-interpreter/preprocessor.ts b/mx-interpreter/preprocessor.ts index 95fae90c..7905c41a 100644 --- a/mx-interpreter/preprocessor.ts +++ b/mx-interpreter/preprocessor.ts @@ -46,5 +46,28 @@ export default class Preprocessor { return error; } + /** +* Extracts parameter names from the workflow. +* @param {WorkflowFile} workflow The given workflow +* @returns {String[]} List of parameters' names. +*/ + static getParams(workflow: WorkflowFile) : string[] { + const getParamsRecurse = (object : any) : string[] => { + if (typeof object === 'object') { + // Recursion base case + if (object.$param) { + return [object.$param]; + } + + // Recursion general case + return Object.values(object) + .reduce((p: string[], v : any) : string[] => [...p, ...getParamsRecurse(v)], []); + } + return []; + }; + + return getParamsRecurse(workflow.workflow); + } + } \ No newline at end of file