import { createLogger } from '@sap-cloud-sdk/util' ; import { ResponseDataAccessor } from '@sap-cloud-sdk/odata-common/internal' ; const logger = createLogger ( { package : 'odata-v2' , messageContext : 'response-data-accessor' } ) ; /**
 * Methods to extract the data from OData v2 responses.
 */ param data returns internal export function getCollectionResult ( data ) { validateCollectionResult ( data ) ; return isCollectionResult ( data ) ? data ?. d ?. results : [ ] ; } param data returns internal export function isCollectionResult ( data ) { return Array . isArray ( data ?. d ?. results ) ; } function validateCollectionResult ( data ) { if ( ! isCollectionResult ( data ) ) { logger . warn ( 'The given response data does not have the standard OData v2 format for collections.' ) ; } } param data returns internal export function getLinkedCollectionResult ( data ) { if ( Array . isArray ( data ?. results ) ) { return data . results ; } return Array . isArray ( data ) ? data : [ ] ; } param data returns internal export function getSingleResult ( data ) { validateSingleResult ( data ) ; return isSingleResultAsCollection ( data ) ? data ?. d ?. results : data ?. d || { } ; } function isSingleResultAsCollection ( data ) { return ! ! data ?. d ?. results && ! isCollectionResult ( data ) ; } function validateSingleResult ( data ) { if ( isSingleResultAsCollection ( data ) ) { logger . warn ( 'The given response data has the format for collections instead of the standard OData v2 format for single results.' ) ; } if ( ! data ?. d ) { logger . warn ( 'The given response data does not have the standard OData v2 format for single results.' ) ; } } internal export const responseDataAccessor = { getCollectionResult , getLinkedCollectionResult , getSingleResult , isCollectionResult } ;