UNPKG

@sap-cloud-sdk/odata-common

Version:

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

75 lines 3.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetAllRequestBuilderBase = void 0; const util_1 = require("@sap-cloud-sdk/util"); const order_1 = require("../order"); const count_request_builder_1 = require("./count-request-builder"); const get_request_builder_base_1 = require("./get-request-builder-base"); /** * Base class for the get all request builders {@link @sap-cloud-sdk/odata-v2!GetAllRequestBuilder | GetAllRequestBuilderV2} and {@link @sap-cloud-sdk/odata-v4!GetAllRequestBuilder | GetAllRequestBuilderV4}. * @typeParam EntityT - Type of the entity to be requested */ class GetAllRequestBuilderBase extends get_request_builder_base_1.GetRequestBuilderBase { /** * Creates an instance of GetAllRequestBuilder. * @param entityApi - Entity API for building and executing the request. * @param getAllRequestConfig - Request config of the get all request. * @param entityDeserializer - Entity deserializer. * @param dataAccessor - Object access functions for get requests. */ constructor(entityApi, getAllRequestConfig, entityDeserializer, dataAccessor) { super(entityApi, getAllRequestConfig); this.entityDeserializer = entityDeserializer; this.dataAccessor = dataAccessor; } select(first, ...rest) { this.requestConfig.selects = (0, util_1.transformVariadicArgumentToArray)(first, rest); return this; } orderBy(first, ...rest) { this.requestConfig.orderBy = (0, util_1.transformVariadicArgumentToArray)(first, rest).map(element => { if (!(0, order_1.isOrderable)(element)) { return (0, order_1.asc)(element); } return element; }); return this; } /** * Limit number of returned entities. * @param top - Maximum number of entities to return in the response. Can be less, if less entities match the request. * @returns The request builder itself, to facilitate method chaining. */ top(top) { this.requestConfig.top = top; return this; } /** * Skip number of entities. * @param skip - Number of matching entities to skip. Useful for paging. * @returns The request builder itself, to facilitate method chaining. */ skip(skip) { this.requestConfig.skip = skip; return this; } /** * Count the number of entities. * @returns A count request builder for execution. */ count() { return new count_request_builder_1.CountRequestBuilder(this); } /** * Execute request. * @param destination - Destination or DestinationFetchOptions to execute the request against. * @returns A promise resolving to the requested entities. */ async execute(destination) { return this.executeRaw(destination).then(response => this.dataAccessor .getCollectionResult(response.data) .map(json => this.entityDeserializer.deserializeEntity(json, this._entityApi, response.headers))); } } exports.GetAllRequestBuilderBase = GetAllRequestBuilderBase; //# sourceMappingURL=get-all-request-builder-base.js.map