import chalk from 'chalk'; import * as stepTemplates from './stepTemplatesHelper'; export const STEP_TYPES = [ 'API', 'SQL', 'PUSHER', 'DIRECT_INDEX', 'FORWARD', 'CACHE', 'VERIFY_CACHED', 'GET_KEY_VALUE', 'SET_KEY_VALUE', 'UPDATE_ITEM_STATUS', 'SLEEP', 'EXCEPTION', 'BASE64_TO_MIME_TYPE', 'CHECK_FORMAT', 'DOWNLOAD_CSV', 'INVALIDATE_CACHE', 'ENQUEUER', ]; export const STEP_STATES = ['Before', 'Current', 'After']; export async function createStep( stepName: string, stepType: string, options?: { sample?: string }, ) { // create a stepTypeName by converting a stepType from UNDERSCORE_UPPER_CASE to UnderscoreUpperCase var stepTypeName = stepType .split('_') .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) .join(''); // dynamically call the corresponding function createStep(stepName) const stepFunctionName = `create${stepTypeName}Step`; if (typeof stepTemplates[stepFunctionName] !== 'function') { stepTypeName = 'Forward'; console.error( `${chalk.red('✘')} Step creation function ${chalk.red(stepFunctionName)} does not exist. Fallback to ${chalk.red('createForwardStep')}`, ); } var step = await stepTemplates[stepFunctionName](stepName, options); return step; }