feat(core): extract params from workflow

This commit is contained in:
karishmas6
2024-07-31 05:36:34 +05:30
parent f6cf2591e3
commit 29b365b714

View File

@@ -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);
}
}