import { createLogger , isNullish } from '@sap-cloud-sdk/util' ; import { Destination , DestinationFetchOptions } from '@sap-cloud-sdk/connectivity' ; import { HttpResponse } from '@sap-cloud-sdk/http-client' ; import { EntityIdentifiable , ODataRequest , ODataUpdateRequestConfig , UpdateRequestBuilderBase , isNavigationProperty , removePropertyOnCondition , EntityApi , entitySerializer } from '@sap-cloud-sdk/odata-common/internal' ; import { Entity } from '../entity' ; import { extractODataEtag } from '../extract-odata-etag' ; import { DeSerializers } from '../de-serializers' ; import { createODataUri } from '../uri-conversion' ; const logger = createLogger ( { package : 'odata-v2' , messageContext : 'update-request-builder-v2' } ) ; typeparam export class UpdateRequestBuilder < EntityT extends Entity , DeSerializersT extends DeSerializers > extends UpdateRequestBuilderBase < EntityT , DeSerializersT > implements EntityIdentifiable < EntityT , DeSerializersT > { param entityApi param _entity constructor ( entityApi , readonly _entity ) { super ( entityApi , _entity , createODataUri ( entityApi . deSerializers ) , entitySerializer ( entityApi . deSerializers ) , extractODataEtag , removeNavPropsAndComplexTypes ) ; } param destination param options returns async execute ( destination ) { if ( this . isEmptyObject ( this . requestConfig . payload ) ) { return this . _entity ; } const request = await this . build ( destination ) ; warnIfNavigation ( request , this . _entity , this . _entityApi . schema ) ; return super . executeRequest ( request ) ; } param destination param options returns async executeRaw ( destination ) { if ( this . isEmptyObject ( this . requestConfig . payload ) ) { logger . info ( 'The request is not executed because no properties of the entity are modified.' ) ; return ; } const request = await this . build ( destination ) ; warnIfNavigation ( request , this . _entity , this . _entityApi . schema ) ; return super . executeRequestRaw ( request ) ; } } function warnIfNavigation < EntityT extends Entity , DeSerializersT extends DeSerializers > ( request , entity , schema ) { const setNavigationProperties = Object . keys ( entity ) . filter ( key => ! isNullish ( entity [ key ] ) && isNavigationProperty ( key , schema ) ) ; if ( setNavigationProperties . length ) { logger . warn ( `The navigation properties ${ setNavigationProperties } have been included in your update request. Update of navigation properties is not supported and will be ignored.` ) ; } return request ; } function removeNavPropsAndComplexTypes ( body ) { return removePropertyOnCondition ( ( [ , val ] ) => typeof val === 'object' , body ) ; }