import moment from 'moment' ; import { FilterFunctionParameterType , BooleanFilterFunction , NumberFilterFunction , StringFilterFunction , FilterFunctionReturnType as FilterFunctionReturnTypeBase , createFilterFunction , numberReturnTypeMapping , CollectionFilterFunction } from '@sap-cloud-sdk/odata-common/internal' ; import { Entity } from './entity' ; import { DateFilterFunction } from './filter' ; export function filterFunction < EntityT extends Entity > ( functionName , returnType , ... parameters ) ; export function filterFunction < EntityT extends Entity > ( functionName , returnType , ... parameters ) ; export function filterFunction < EntityT extends Entity > ( functionName , returnType , ... parameters ) ; export function filterFunction < EntityT extends Entity > ( functionName , returnType , ... parameters ) ; export function filterFunction < EntityT extends Entity > ( functionName , returnType , ... parameters ) ; export function filterFunction < EntityT extends Entity > ( functionName , returnType , ... parameters ) ; export function filterFunction < EntityT extends Entity > ( functionName , returnType , ... parameters ) ; export function filterFunction < EntityT extends Entity > ( functionName , returnType , ... parameters ) ; param functionName param returnType param parameters returns export function filterFunction < EntityT extends Entity > ( functionName , returnType , ... parameters ) { if ( returnType === 'datetimeoffset' ) { return new DateFilterFunction ( functionName , parameters ) ; } if ( isCollectionReturnType ( returnType ) ) { const edmType = returnTypeMapping [ returnType . replace ( '[]' , '' ) ] ; if ( edmType ) { return new CollectionFilterFunction ( functionName , parameters , edmType ) ; } throw new Error ( `Cannot create filter function for unknown return type ${ returnType }.` ) ; } return createFilterFunction ( functionName , returnType , ... parameters ) ; } function isCollectionReturnType ( returnType ) { return returnType . endsWith ( '[]' ) ; } type CollectionReturnType = 'datetimeoffset[]' | 'boolean[]' | 'int[]' | 'double[]' | 'decimal[]' | 'string[]' ; type FilterFunctionReturnType = FilterFunctionReturnTypeBase | CollectionReturnType | 'datetimeoffset' ; const returnTypeMapping = { datetimeoffset : 'Edm.DateTimeOffset' , boolean : 'Edm.Boolean' , string : 'Edm.String' , ... numberReturnTypeMapping } ;