1- import type { EvaluateOptions , Expression , FunctionObject , ReferenceObject } from "../types" ;
1+ import type { EvaluateOptions , Expression , FunctionObject , FunctionReturn , ReferenceObject } from "../types" ;
22import { EndpointError } from "../types" ;
3- import { callFunction } from "./callFunction" ;
3+ import { customEndpointFunctions } from "./customEndpointFunctions" ;
4+ import { endpointFunctions } from "./endpointFunctions" ;
45import { evaluateTemplate } from "./evaluateTemplate" ;
56import { getReferenceValue } from "./getReferenceValue" ;
67
@@ -14,3 +15,16 @@ export const evaluateExpression = (obj: Expression, keyName: string, options: Ev
1415 }
1516 throw new EndpointError ( `'${ keyName } ': ${ String ( obj ) } is not a string, function or reference.` ) ;
1617} ;
18+
19+ export const callFunction = ( { fn, argv } : FunctionObject , options : EvaluateOptions ) : FunctionReturn => {
20+ const evaluatedArgs = argv . map ( ( arg ) =>
21+ [ "boolean" , "number" ] . includes ( typeof arg ) ? arg : evaluateExpression ( arg as Expression , "arg" , options )
22+ ) ;
23+ const fnSegments = fn . split ( "." ) ;
24+ if ( fnSegments [ 0 ] in customEndpointFunctions && fnSegments [ 1 ] != null ) {
25+ // @ts -ignore Element implicitly has an 'any' type
26+ return customEndpointFunctions [ fnSegments [ 0 ] ] [ fnSegments [ 1 ] ] ( ...evaluatedArgs ) ;
27+ }
28+ // @ts -ignore Element implicitly has an 'any' type
29+ return endpointFunctions [ fn ] ( ...evaluatedArgs ) ;
30+ } ;
0 commit comments