import { Destination , DestinationFetchOptions } from '@sap-cloud-sdk/connectivity' ; import { HttpResponse } from '@sap-cloud-sdk/http-client' ; import { first } from '@sap-cloud-sdk/util' ; import { MethodRequestBuilder } from '../request-builder-base' ; import { ODataBatchRequestConfig , ODataRequest } from '../../request' ; import { DefaultDeSerializers , DeSerializers } from '../../de-serializers' ; import { EntityApi , EntityBase } from '../../entity-base' ; import { GetAllRequestBuilderBase } from '../get-all-request-builder-base' ; import { GetByKeyRequestBuilderBase } from '../get-by-key-request-builder-base' ; import { BatchChangeSet } from './batch-change-set' ; import { BatchSubRequestPathType } from './batch-request-options' ; import { serializeBatchRequest } from './batch-request-serializer' ; internal export class BatchRequestBuilder < DeSerializersT extends DeSerializers = DefaultDeSerializers > extends MethodRequestBuilder < ODataBatchRequestConfig > { readonly deSerializers : DeSerializersT | undefined ; param defaultServicePath param requests param entityToConstructorMap constructor ( readonly defaultServicePath , readonly requests ) { super ( new ODataBatchRequestConfig ( defaultServicePath ) ) ; this . deSerializers = first ( Object . values ( this . getEntityToApiMap ( ) ) ) ?. deSerializers ; } withSubRequestPathType ( subRequestPathType ) { this . requestConfig . withSubRequestPathType ( subRequestPathType ) ; return this ; } build ( ) ; build ( destination ) ; build ( destination ? ) { return destination ? super . build ( destination ! ) . then ( request => this . setPayload ( request ) ) : this . setPayload ( super . build ( ) ) ; } param destination returns async executeRaw ( destination ) { return this . build ( destination ) . then ( request => request . execute ( ) ) ; } protected getEntityToApiMap ( ) { return this . requests . reduce ( ( apis , request ) => ( { ... apis , ... ( request instanceof BatchChangeSet ? request . requests . reduce ( ( changeSetApis , changesetReq ) => ( { ... changeSetApis , [ changesetReq . _entityApi . entityConstructor . _entityName ] : changesetReq . _entityApi } ) , { } ) : { [ request . _entityApi . entityConstructor . _entityName ] : request . _entityApi } ) } ) , { } ) ; } private setPayload ( request ) { request . config . payload = serializeBatchRequest ( this , { subRequestPathType : request . config . subRequestPathType , destination : request . destination ! } ) ; return request ; } }