import { FunctionCallData , FunctionCallsData , FunctionCallParametersData } from 'js-yaml-loader!@/*' ; import { IFunctionCall } from './IFunctionCall' ; import { FunctionCallArgumentCollection } from './Argument/FunctionCallArgumentCollection' ; import { FunctionCallArgument } from './Argument/FunctionCallArgument' ; import { FunctionCall } from './FunctionCall' ; export function parseFunctionCalls ( calls ) { if ( calls === undefined ) { throw new Error ( 'undefined call data' ) ; } const sequence = getCallSequence ( calls ) ; return sequence . map ( ( call ) => parseFunctionCall ( call ) ) ; } function getCallSequence ( calls ) { if ( typeof calls !== 'object' ) { throw new Error ( 'called function(s) must be an object' ) ; } if ( calls instanceof Array ) { return calls as FunctionCallData [ ] ; } return [ calls as FunctionCallData ] ; } function parseFunctionCall ( call ) { if ( ! call ) { throw new Error ( 'undefined function call' ) ; } const callArgs = parseArgs ( call . parameters ) ; return new FunctionCall ( call . function , callArgs ) ; } function parseArgs ( parameters ) { return Object . keys ( parameters || { } ) . map ( ( parameterName ) => new FunctionCallArgument ( parameterName , parameters [ parameterName ] ) ) . reduce ( ( args , arg ) => { args . addArgument ( arg ) ; return args ; } , new FunctionCallArgumentCollection ( ) ) ; }