import { EntryPoint , Interceptor } from './application' ; import { ObjectContext } from './object-context' ; import { RequestContext } from './request-context' ; import { Request } from './request' ; import { Response } from './response' ; import * as utils from './utils' ; import * as path from 'path' ; export interface FunctionDefinition { moduleName ? : string ; functionName ? : string ; function ? : string ; } export interface EntryPointDefinition extends FunctionDefinition { _type : "EntryPoint" ; description ? : string ; executionStack ? : string [ ] ; displayRank ? : number ; exampleRequests ? : Request [ ] ; exampleResponses ? : Response [ ] ; } ; export interface InterceptorDefinition extends FunctionDefinition { _type : "Interceptor" ; description ? : string ; } ; export function createFunction ( definition , context ) { if ( definition . function != null ) { return eval ( '(' + definition . function + ')' ) ; } if ( definition . moduleName != null && definition . functionName != null ) { let moduleName = definition . moduleName ; if ( moduleName . startsWith ( '.' ) ) { moduleName = path . resolve ( context . baseDir , moduleName ) ; } return utils . appendMessageOnException ( "Unable to create function '" + definition . function + "' in module '" + definition . moduleName + "'." , ( ) => { return utils . loadFunction ( moduleName , definition . functionName ) ; } ) ; } throw new Error ( "Either property group 'moduleName' and 'functionName' or property 'function' should be present for Function object." ) ; } export function createEntryPoint ( definition , context ) { return < EntryPoint > createFunction ( definition , context ) ; } export function createInterceptor ( definition , context ) { return < Interceptor > createFunction ( definition , context ) ; }