import { flat } from '@sap-cloud-sdk/util' ; import { FunctionDeclarationStructure , InterfaceDeclarationStructure , SourceFileStructure , StructureKind } from 'ts-morph' ; import { VdmFunctionImport , VdmServiceMetadata } from '../vdm-types' ; import { parametersInterface } from './parameters-interface' ; import { exportStatement } from './export-statement' ; import { actionImportFunction } from './action' ; import { importDeclarationsAction , importDeclarationsFunction } from './import' ; import { functionImportFunction } from './function' ; internal export function actionImportSourceFile ( service ) { if ( ! service . actionImports ) { throw new Error ( 'Tried to create action import source files without actions in service metadata.' ) ; } return { kind : StructureKind . SourceFile , statements : [ ... importDeclarationsFunction ( service ) , ... flat ( service . actionImports . map ( action => actionImportStatements ( action , service ) ) ) , exportStatement ( service . actionImports , 'actionImports' ) ] } ; } function actionImportStatements ( actionImport , service ) { return [ parametersInterface ( actionImport ) , actionImportFunction ( actionImport , service ) ] ; } internal export function functionImportSourceFile ( service ) { return { kind : StructureKind . SourceFile , statements : [ ... importDeclarationsAction ( service ) , ... flat ( service . functionImports . map ( fi => functionImportStatements ( fi , service ) ) ) , exportStatement ( service . functionImports , 'functionImports' ) ] } ; } function functionImportStatements ( functionImport , service ) { return [ parametersInterface ( functionImport ) , functionImportFunction ( functionImport , service ) ] ; }