import { EntityApi } from '@sap-cloud-sdk/odata-common/internal' ; import { Entity } from '../entity' ; import { DeSerializers , entityDeserializer } from '../de-serializers' ; import { getSingleResult , getCollectionResult } from './response-data-accessor' ; export function transformReturnValueForUndefined < ReturnT > ( data , builderFn ) { return builderFn ( data ) ; } export function transformReturnValueForEntity < ReturnT extends Entity , DeSerializersT extends DeSerializers > ( data , entityApi ) { return entityDeserializer ( entityApi . deSerializers ) . deserializeEntity ( getSingleResult ( data ) , entityApi ) . setOrInitializeRemoteState ( ) as ReturnT ; } export function transformReturnValueForEntityList < ReturnT extends Entity , DeSerializersT extends DeSerializers > ( data , entityApi ) { const deserializeEntity = entityDeserializer ( entityApi . deSerializers ) . deserializeEntity ; return getCollectionResult ( data ) . map ( entityJson => deserializeEntity ( entityJson , entityApi ) . setOrInitializeRemoteState ( ) as ReturnT ) ; } export function transformReturnValueForComplexType < ReturnT > ( data , builderFn ) { return builderFn ( getSingleResult ( data ) ) as ReturnT ; } export function transformReturnValueForComplexTypeList < ReturnT > ( data , builderFn ) { return getCollectionResult ( data ) . map ( json => builderFn ( json ) ) ; } export function transformReturnValueForEdmType < ReturnT > ( data , builderFn ) { return builderFn ( getSingleResult ( data ) ) ; } export function transformReturnValueForEdmTypeList < ReturnT > ( data , builderFn ) { return getCollectionResult ( data ) . map ( builderFn ) ; }