import { Selectable , Link } from '@sap-cloud-sdk/odata-common/internal' ; import { DeSerializers } from '../de-serializers' ; import { Entity } from '../entity' ; internal typeparam typeparam param selects returns export function getExpand < EntityT extends Entity , DeSerializersT extends DeSerializers > ( selects = [ ] ) { const expand = getExpandsAsString ( selects ) ; return expand . length ? { expand : expand . join ( ',' ) } : { } ; } function getExpandsAsString < EntityT extends Entity , DeSerializersT extends DeSerializers > ( selectables , initialExpand = [ ] , parent = '' ) { return selectables . reduce ( ( combination , selectable ) => { const fullFieldName = getPath ( parent , selectable . _fieldName ) ; if ( selectable instanceof Link ) { combination = [ ... combination , fullFieldName ] ; if ( selectable . _selects . length ) { return getExpandsAsString ( selectable . _selects , combination , fullFieldName ) ; } } return combination ; } , initialExpand ) ; } function getPath ( parent , fieldName ) { if ( parent ) { return `${ parent }/${ fieldName }` ; } return fieldName ; }