import { flat } from '@sap-cloud-sdk/util' ; import { forceArray } from '../../generator-utils' ; import { EdmxComplexTypeBase , EdmxEntitySetBase , EdmxEntityTypeBase } from './edmx-types' ; internal export function parseComplexTypesBase ( root ) { return getMergedPropertyWithNamespace ( root , 'ComplexType' ) . map ( c => ( { ... c , Property : forceArray ( c . Property ) , Namespace : c . Namespace } ) ) ; } internal export function parseEntityTypesBase ( root ) { return getMergedPropertyWithNamespace ( root , 'EntityType' ) . map ( e => ( { ... e , Key : { PropertyRef : forceArray ( e . Key ?. PropertyRef ) } , NavigationProperty : forceArray ( e . NavigationProperty ) , Property : forceArray ( e . Property ) , Namespace : e . Namespace } ) ) ; } internal export function parseEntitySetsBase ( root ) { return getPropertyFromEntityContainer ( root , 'EntitySet' ) ; } internal export function getPropertyFromEntityContainer ( schema , entityContainerProperty ) { return flat ( forceArray ( schema ) . filter ( s => s . EntityContainer ) . map ( s => forceArray ( s [ 'EntityContainer' ] [ entityContainerProperty ] ) . map ( p => addNamespace ( p , schema . Namespace ) ) ) ) ; } function addNamespace < T > ( obj , namespace ) { return { ... obj , Namespace : namespace } ; } param root param property returns internal export function getMergedPropertyWithNamespace ( root , property ) { return flat ( forceArray ( root ) . map ( s => forceArray ( s [ property ] ) . map ( p => addNamespace ( p , s . Namespace ) ) ) ) ; }