UNPKG

@sap-cloud-sdk/odata-common

Version:

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

58 lines (57 loc) 3.34 kB
import type { DeSerializers } from '../de-serializers'; import type { EntityBase, EntityIdentifiable } from '../entity-base'; import type { Expandable } from '../expandable'; import type { EntityApi, EntityType } from '../entity-api'; import type { Selectable } from './selectable'; /** * Represents a navigation property of an OData entity. * * OData is a relational data model, i.e. entities can be related to one another. * For example, BusinessPartner is in a 1:n relation with BusinessPartnerAddress and in a 1:1 relation with Customer. * Like normal properties, navigation properties can be used for selecting (expanding) and filtering. * For example, when constructing a query on the BusinessPartner entity, an instance of `Link<BusinessPartner, Customer>` * can be passed as argument to the select function, e.g. `BusinessPartner.TO_CUSTOMER`. * * NOTE: Due to historical development the Link and its extensions are used in the following way: * OData v2 entity: 1:N is a {@link Link}, 1:0..1 is a {@link OneToOneLink} * OData v4 entity: 1:N is a {@link OneToManyLink}, 1:0..1 is a {@link OneToOneLink}. * * See also: {@link Selectable}. * @typeParam EntityT - Type of the entity to be linked from. * @typeParam LinkedEntityT - Type of the entity to be linked to. */ export declare class Link<EntityT extends EntityBase, DeSerializersT extends DeSerializers, LinkedEntityApiT extends EntityApi<EntityBase, DeSerializersT>> implements EntityIdentifiable<EntityT, DeSerializersT> { readonly _fieldName: string; readonly _entityApi: EntityApi<EntityT, DeSerializersT>; readonly _linkedEntityApi: LinkedEntityApiT; readonly _entity: EntityT; readonly _deSerializers: DeSerializersT; /** * List of selectables on the linked entity. */ _selects: Selectable<EntityType<LinkedEntityApiT>, DeSerializersT>[]; _expand: Expandable<EntityType<LinkedEntityApiT>, DeSerializersT, EntityApi<EntityBase, DeSerializersT>>[]; /** * Creates an instance of Link. * @param _fieldName - Name of the linking field to be used in the OData request. * @param _entityApi - Entity API for building and executing the request. * @param _linkedEntityApi - Constructor of the linked entity. */ constructor(_fieldName: string, _entityApi: EntityApi<EntityT, DeSerializersT>, _linkedEntityApi: LinkedEntityApiT); /** * Creates a selection on a linked entity. Has the same behavior as {@link @sap-cloud-sdk/odata-v2!GetAllRequestBuilder.select | GetAllRequestBuilderV2.select} and {@link @sap-cloud-sdk/odata-v4!GetByKeyRequestBuilder.select | GetByKeyRequestBuilderV4.select} but for linked entities. * * See also, {@link Selectable}. * @param selects - Selection of fields or links on a linked entity. * @returns The link itself, to facilitate method chaining. */ select(...selects: Selectable<EntityType<LinkedEntityApiT>, DeSerializersT>[]): this; expand(...expands: Expandable<EntityType<LinkedEntityApiT>, DeSerializersT, EntityApi<EntityBase, DeSerializersT>>[]): this; /** * Create a new link based on a given link. * @typeParam EntityT - Type of the entity to be linked from. * @typeParam LinkedEntityT - Type of the entity to be linked to. * @returns Newly created link. */ clone(): this; }