import { EntityBase } from '../entity-base' ; import { Orderable , OrderLink , Order } from '../order' ; typeparam param orderBy returns internal export function getOrderBy < EntityT extends EntityBase > ( orderBy ) { if ( typeof orderBy !== 'undefined' && orderBy . length ) { return { orderby : getODataOrderByExpressions ( orderBy ) . join ( ',' ) } ; } return { } ; } function getODataOrderByExpressions < OrderByEntityT extends EntityBase > ( orderBys , parentFieldNames = [ ] ) { return orderBys . reduce ( ( expressions , orderBy ) => { if ( orderBy instanceof OrderLink ) { return [ ... expressions , getOrderByExpressionForOrderLink ( orderBy , [ ... parentFieldNames ] ) ] ; } return [ ... expressions , getOrderByExpressionForOrder ( orderBy , parentFieldNames ) ] ; } , [ ] ) ; } function getOrderByExpressionForOrderLink < OrderByEntityT extends EntityBase , LinkedEntityT extends EntityBase > ( orderBy , parentFieldNames = [ ] ) { return getODataOrderByExpressions ( orderBy . orderBy , [ ... parentFieldNames , orderBy . link . _fieldName ] ) . join ( ',' ) ; } function getOrderByExpressionForOrder < OrderByEntityT extends EntityBase > ( orderBy , parentFieldNames = [ ] ) { return [ [ ... parentFieldNames , orderBy . _fieldName ] . join ( '/' ) , orderBy . orderType ] . join ( encodeURIComponent ( ' ' ) ) ; }