@sap-cloud-sdk/odata-common
Version:
SAP Cloud SDK for JavaScript common functions of OData client generator and OpenAPI clint generator.
76 lines • 2.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.OneToManyLink = void 0;
exports.toFilterableList = toFilterableList;
// eslint-disable-next-line import/no-internal-modules
const filter_link_1 = require("../filter/filter-link");
const link_1 = require("./link");
/**
* @param filters - filters
* @returns filtered list
* @internal
*/
function toFilterableList(filters) {
return filters.map(f => (f instanceof OneToManyLink ? f._filters : f));
}
/**
* Represents a one to many relation for OData v4 entities.
* For OData v2 entities the {@link Link} is used to represent one to many relation.
* See {@link Link} for more information.
*/
class OneToManyLink extends link_1.Link {
constructor() {
super(...arguments);
this._orderBy = [];
}
clone() {
const clonedLink = super.clone();
clonedLink._filters = this._filters;
clonedLink._orderBy = this._orderBy;
clonedLink._top = this._top;
clonedLink._skip = this._skip;
return clonedLink;
}
/**
* Create filter statements to be applied to the OData request based on the linked entity values.
* @param expressions - Filters based on the linked entity.
* @returns Newly created `FilterLink`.
*/
filter(...expressions) {
const link = this.clone();
link._filters = new filter_link_1.FilterLink(this, toFilterableList(expressions));
return link;
}
/**
* Add order-by statements to the request.
* @param orderBy - OrderBy statements to order the response by.
* @returns The request builder itself, to facilitate method chaining.
*/
orderBy(...orderBy) {
const link = this.clone();
link._orderBy = orderBy;
return link;
}
/**
* 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) {
const link = this.clone();
link._top = top;
return link;
}
/**
* 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) {
const link = this.clone();
link._skip = skip;
return link;
}
}
exports.OneToManyLink = OneToManyLink;
//# sourceMappingURL=one-to-many-link.js.map