import { Expandable , OneToManyLink , AllFields , Link , and , createGetFilter , getOrderBy , EntityApi } from '@sap-cloud-sdk/odata-common/internal' ; import { DeSerializers } from '../de-serializers' ; import { Entity } from '../entity' ; import { getSelect } from './get-select' ; import { uriConverter } from './uri-value-converter' ; function prependDollar ( param ) { return `$${ param }` ; } internal typeparam param expands param entityApi returns export function getExpand < EntityT extends Entity , DeSerializersT extends DeSerializers > ( expands = [ ] , entityApi ) { return expands . length ? { expand : expands . map ( expand => getExpandAsString ( expand , entityApi ) ) . join ( ',' ) } : { } ; } function getExpandAsString < EntityT extends Entity , DeSerializersT extends DeSerializers > ( expand , entityApi ) { if ( expand instanceof AllFields ) { return '*' ; } let params = { } ; if ( expand instanceof Link ) { params = { ... params , ... getSelect ( expand . _selects ) , ... getExpand ( expand . _expand , expand . _linkedEntityApi ) } ; if ( expand instanceof OneToManyLink ) { params = { ... params , ... createGetFilter ( uriConverter ) . getFilter ( and ( expand . _filters ?. filters || [ ] ) , entityApi ) , ... ( expand . _skip && { skip : expand . _skip } ) , ... ( expand . _top && { top : expand . _top } ) , ... ( expand . _orderBy && getOrderBy ( expand . _orderBy ) ) } ; } const subQuery = Object . entries ( params ) . map ( ( [ key , value ] ) => `${ prependDollar ( key ) }=${ value }` ) . join ( ';' ) ; const subQueryWithBrackets = subQuery ? `(${ subQuery })` : '' ; return `${ expand . _fieldName }${ subQueryWithBrackets }` ; } return '' ; }