UNPKG

@sap-cloud-sdk/odata-common

Version:

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

44 lines 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CountRequestBuilder = void 0; const request_1 = require("../request"); const request_builder_base_1 = require("./request-builder-base"); /** * Create an OData request to count entities based on the configuration of the request. * A `CountRequestBuilder` allows only for execution of the request. * If you want to apply query parameters like filter, skip or top do it on the {@link GetAllRequestBuilderBase | GetAllRequestBuilder} the count is created from. * @typeParam EntityT - Type of the entity to be requested */ class CountRequestBuilder extends request_builder_base_1.MethodRequestBuilder { /** * Creates an instance of CountRequestBuilder. * @param getAllRequest - Get all request builder to count result for. */ constructor(getAllRequest) { super(new request_1.ODataCountRequestConfig(getAllRequest)); this.getAllRequest = getAllRequest; } /** * Execute request. * @param destination - Destination or DestinationFetchOptions to execute the request against. * @returns A promise resolving to the number of entities. */ async execute(destination) { return this.executeRaw(destination).then(response => { if (typeof response.data !== 'number') { throw new Error('Count request did not return a bare number.'); } return response.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()); } } exports.CountRequestBuilder = CountRequestBuilder; //# sourceMappingURL=count-request-builder.js.map