import { ErrorWithCause } from '@sap-cloud-sdk/util' ; import { Destination , DestinationFetchOptions } from '@sap-cloud-sdk/connectivity' ; import { HttpResponse } from '@sap-cloud-sdk/http-client' ; import type { EntitySerializer } from '../entity-serializer' ; import type { ODataUri } from '../uri-conversion' ; import type { EntityApi , EntityBase , EntityIdentifiable } from '../entity-base' ; import type { EntityDeserializer } from '../entity-deserializer' ; import type { ResponseDataAccessor } from '../response-data-accessor' ; import { ODataCreateRequestConfig } from '../request' ; import { Link } from '../selectable' ; import { DeSerializers } from '../de-serializers' ; import { MethodRequestBuilder } from './request-builder-base' ; typeparam internal export abstract class CreateRequestBuilderBase < EntityT extends EntityBase , DeSerializersT extends DeSerializers > extends MethodRequestBuilder < ODataCreateRequestConfig < EntityT , DeSerializersT > > implements EntityIdentifiable < EntityT , DeSerializersT > { readonly _deSerializers : DeSerializersT ; param _entityApi param _entity param oDataUri param serializer param deserializer param responseDataAccessor constructor ( readonly _entityApi , readonly _entity , readonly oDataUri , readonly serializer , readonly deserializer , readonly responseDataAccessor ) { super ( new ODataCreateRequestConfig ( _entityApi , oDataUri ) ) ; this . requestConfig . payload = serializer . serializeEntity ( this . _entity , this . _entityApi ) ; } get entity ( ) : EntityT { return this . _entity ; } param parentEntity param linkField returns asChildOf < ParentEntityT extends EntityBase > ( parentEntity , linkField ) { this . requestConfig . parentKeys = this . oDataUri . getEntityKeys ( parentEntity , linkField . _entityApi ) ; this . requestConfig . childField = linkField ; return this ; } param destination returns async execute ( destination ) { return this . executeRaw ( destination ) . then ( response => this . deserializer . deserializeEntity ( this . responseDataAccessor . getSingleResult ( response . data ) , this . _entityApi , response . headers ) ) . catch ( error => { throw new ErrorWithCause ( 'Create request failed!' , error ) ; } ) ; } param destination returns async executeRaw ( destination ) { return this . build ( destination ) . then ( request => request . execute ( ) ) ; } }