UNPKG

@sap-cloud-sdk/odata-common

Version:

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

79 lines 3.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeleteRequestBuilderBase = void 0; const util_1 = require("@sap-cloud-sdk/util"); const uuid_1 = require("uuid"); const entity_base_1 = require("../entity-base"); const request_1 = require("../request"); const request_builder_base_1 = require("./request-builder-base"); /** * Abstract class to delete an entity holding the shared parts between OData v2 and v4. * @typeParam EntityT - Type of the entity to be deleted */ class DeleteRequestBuilderBase extends request_builder_base_1.MethodRequestBuilder { /** * Creates an instance of DeleteRequestBuilder. If the entity is passed, version identifier will also be added. * @param _entityApi - Entity API for building and executing the request. * @param oDataUri - URI conversion functions. * @param keysOrEntity - Entity or key-value pairs of key properties for the given entity. */ constructor(_entityApi, oDataUri, keysOrEntity) { super(new request_1.ODataDeleteRequestConfig(_entityApi, oDataUri)); this._entityApi = _entityApi; if (keysOrEntity instanceof entity_base_1.EntityBase) { this.requestConfig.keys = oDataUri.getEntityKeys(keysOrEntity, _entityApi); this.setVersionIdentifier(keysOrEntity.versionIdentifier); } else { this.requestConfig.keys = keysOrEntity; } } /** * 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 }; } /** * Instructs the request to force an overwrite of the entity by sending an 'If-Match: *' header instead of sending the ETag version identifier. * @returns The request itself to ease chaining while executing the request. */ ignoreVersionIdentifier() { this.requestConfig.versionIdentifierIgnored = true; return this; } /** * Execute query. * @param destination - Destination or DestinationFetchOptions to execute the request against. * @returns A promise resolving once the entity was deleted. */ async execute(destination) { return (this.executeRaw(destination) // Transform response to void .then(() => Promise.resolve()) .catch(error => { throw new util_1.ErrorWithCause('OData delete request failed!', error); })); } /** * 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()); } } exports.DeleteRequestBuilderBase = DeleteRequestBuilderBase; //# sourceMappingURL=delete-request-builder-base.js.map