import { getMergedPropertyWithNamespace , getPropertyFromEntityContainer , parseComplexTypesBase , parseEntitySetsBase , parseEntityTypesBase } from '../common/edmx-parser' ; import { forceArray } from '../../generator-utils' ; import { joinEntityTypes } from '../../edmx-to-vdm/v4' ; import { stripNamespace } from '../../edmx-to-vdm' ; import { EdmxAction , EdmxActionImport , EdmxComplexType , EdmxDerivedType , EdmxEntitySet , EdmxEntityTypeV4 , EdmxEnumType , EdmxFunction , EdmxFunctionImportV4 , EdmxNavigationPropertyBinding } from './edm-types' ; internal export function joinComplexTypes < T extends EdmxComplexType > ( complexType , baseType ) { return { ... complexType , Property : [ ... complexType . Property , ... baseType . Property ] } ; } internal export function joinTypesWithBaseTypes < T extends EdmxDerivedType > ( types , joinTypes ) { return types . map ( type => joinTypeWithBaseType ( type , types , joinTypes ) ) ; } param type param types param joinTypes returns function joinTypeWithBaseType < T extends EdmxDerivedType > ( type , types , joinTypes ) { if ( type . BaseType ) { const baseType = types . find ( e => e . Name === stripNamespace ( type . BaseType ! ) ) ; if ( ! baseType ) { throw new Error ( `Type ${ type . BaseType } not found, but defined as BaseType of Type ${ type . Name }.` ) ; } return joinTypes ( type , joinTypeWithBaseType ( baseType , types , joinTypes ) ) ; } return type ; } internal export function parseComplexTypesV4 ( root ) { return joinTypesWithBaseTypes ( parseComplexTypesBase ( root ) , joinComplexTypes ) ; } internal export function parseEnumTypes ( root ) { return getMergedPropertyWithNamespace ( root , 'EnumType' ) . map ( edmxEnumType => ( { Name : edmxEnumType . Name , UnderlyingType : edmxEnumType . UnderlyingType , Member : forceArray ( edmxEnumType . Member ) , Namespace : edmxEnumType . Namespace } ) ) ; } internal export function parseEntityType ( root ) { const entityTypes = parseEntityTypesBase ( root ) ; return joinTypesWithBaseTypes ( entityTypes , joinEntityTypes ) ; } internal export function parseEntitySetsV4 ( root ) { return parseEntitySetsBase ( root ) . map ( entitySet => ( { ... entitySet , NavigationPropertyBinding : parseNavigationPropertyBinding ( entitySet ) } ) ) ; } function parseNavigationPropertyBinding ( entitySet ) { return forceArray ( entitySet . NavigationPropertyBinding ) ; } internal export function parseFunctionImportsV4 ( root ) { return getPropertyFromEntityContainer ( root , 'FunctionImport' ) ; } internal export function parseActionImport ( root ) { return getPropertyFromEntityContainer ( root , 'ActionImport' ) ; } function parseActionsFunctions ( root , actionFunctionKey ) { return getMergedPropertyWithNamespace ( root , actionFunctionKey ) . map ( actionOrFunction => ( { ... actionOrFunction , Parameter : forceArray ( actionOrFunction . Parameter ) , IsBound : false } ) ) ; } internal export function parseFunctions ( root ) { return parseActionsFunctions ( root , 'Function' ) ; } internal export function parseActions ( root ) { return parseActionsFunctions ( root , 'Action' ) ; }