UNPKG

@sap-cloud-sdk/odata-common

Version:

SAP Cloud SDK for JavaScript common functions of OData client generator and OpenAPI clint generator.

65 lines 2.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OperationRequestBuilderBase = void 0; const uuid_1 = require("uuid"); const request_builder_base_1 = require("./request-builder-base"); /** * Create OData request to execute an action or function. * @typeParam DeSerializersT - Type of the (de-)serializers. * @typeParam ReturnT - Type of the function return value. * @typeParam RequestConfigT - Type of the request config. */ class OperationRequestBuilderBase extends request_builder_base_1.MethodRequestBuilder { /** * Base class for function and action request builder. * @param responseTransformer - Transformation function for the response. * @param requestConfig - Request config for an action or function. * @param _deSerializers - (De-)serializers used for transformation. */ constructor(responseTransformer, requestConfig, _deSerializers) { super(requestConfig); this.responseTransformer = responseTransformer; this._deSerializers = _deSerializers; } /** * Execute request. * @param destination - Destination or DestinationFetchOptions to execute the request against. * @param dataAccessor - A function to modify the received response data. * @returns A promise resolving to the requested return type. */ async execute(destination, dataAccessor) { return this.executeRaw(destination).then(response => { const data = dataAccessor ? { d: dataAccessor(response.data) } : response.data; return this.responseTransformer(data); }); } /** * Execute request and return an {@link @sap-cloud-sdk/http-client!HttpResponse}. * @param destination - Destination or DestinationFetchOptions to execute the request against. * @returns A promise resolving to an {@link @sap-cloud-sdk/http-client!HttpResponse}. */ async executeRaw(destination) { return this.build(destination).then(request => request.execute()); } /** * Gets identifier for the batch request. * @returns Batch request identifier. */ getBatchReference() { if (!this._batchReference) { this.setBatchId((0, uuid_1.v4)()); } return this._batchReference; } /** * Sets user-defined identifier for the batch reference. * @param id - User-defined batch request identifier. */ setBatchId(id) { this._batchReference = { id }; } } exports.OperationRequestBuilderBase = OperationRequestBuilderBase; //# sourceMappingURL=operation-request-builder-base.js.map