UNPKG

@sap-cloud-sdk/core

Version:
174 lines • 8.26 kB
import { EntityBuilder } from './entity-builder'; import { Link, Field, Selectable, CustomField } from './selectable'; import { RequestBuilder } from './request-builder'; export declare type ODataVersionOf<T extends Entity> = T['_oDataVersion']; /** * @hidden */ export interface Constructable<EntityT extends Entity, EntityTypeT = unknown> { _serviceName: string; _entityName: string; _defaultServicePath: string; _allFields: (Selectable<EntityT> | Field<EntityT, boolean, boolean> | Link<EntityT>)[]; _keyFields: (Selectable<EntityT> | Field<EntityT, boolean, boolean>)[]; _keys: { [keys: string]: Selectable<EntityT> | Field<EntityT, boolean, boolean>; }; new (...args: any[]): EntityT; requestBuilder(): RequestBuilder<EntityT>; builder(): EntityBuilderType<EntityT, EntityTypeT>; customField(fieldName: string, isNullable?: boolean): CustomField<EntityT, boolean>; } export declare type EntityBuilderType<EntityT extends Entity, EntityTypeT> = { [property in keyof Required<EntityTypeT>]: (value: EntityTypeT[property]) => EntityBuilderType<EntityT, EntityTypeT>; } & EntityBuilder<EntityT, EntityTypeT>; /** * Super class for all representations of OData entity types. */ export declare abstract class Entity { static _serviceName: string; static _entityName: string; static _defaultServicePath: string; protected static entityBuilder<EntityT extends Entity, EntityTypeT>(entityConstructor: Constructable<EntityT, EntityTypeT>): EntityBuilderType<EntityT, EntityTypeT>; /** * The remote state of the entity. * Remote state refers to the last known state of the entity on the remote system from which it has been retrieved or to which it has been posted. * It is stored as map, where the keys are stored in the format of the original OData properties. */ protected remoteState: { [keys: string]: any; }; /** * The current ETag version of the entity in the remote system. * The ETag identified the version of the in the remote system. It will be automatically set in the "if-match" header of update requests and can be set as a custom header for delete requests. * When no ETag is provided by the remote system the value of this variable defaults to "*". */ protected _versionIdentifier: string; /** * A mapper representing custom fields in an entity. * Custom fields are represented by their field names and the corresponding values. * A custom field can be added or updated using [[setCustomField]] method. */ protected _customFields: Record<string, any>; abstract readonly _oDataVersion: any; constructor(); /** * ETag version identifier accessor. * @returns The ETag version identifier of the retrieved entity, returns `undefined` if not retrieved. */ get versionIdentifier(): string; /** * Returns a map that contains all entity custom fields. * @returns A map of all defined custom fields in the entity */ getCustomFields(): Record<string, any>; /** * Custom field value getter. * @param fieldName - The name of the custom field * @returns The value of the corresponding custom field */ getCustomField(fieldName: string): any; /** * Sets a new custom field in the entity or updates it. * Throws an error, if the provided custom field name is already defined by an original field in entity. * @param fieldName - The name of the custom field to update * @param value - The value of the field * @returns The entity itself, to facilitate method chaining */ setCustomField(fieldName: string, value: any): this; /** * Validates whether a custom field exists in the entity. * @param fieldName - The name of the custom field to update * @returns A boolean value, that indicates whether a custom field is defined in entity */ hasCustomField(fieldName: string): boolean; /** * Sets custom fields on an entity. * @param customFields - Custom fields to set on the entity. * @returns The entity itself, to facilitate method chaining */ setCustomFields(customFields: Record<string, any>): this; /** * @deprecated Since v1.34.1. Use [[setCustomFields]] instead. * Sets all retrieved custom fields in entity. * @param customFields - Extracted custom fields from a retrieved entity. * @returns The entity itself, to facilitate method chaining. */ initializeCustomFields(customFields: Record<string, any>): this; /** * Set the ETag version identifier of the retrieved entity. * @param etag - The returned ETag version of the entity. * @returns The entity itself, to facilitate method chaining. */ setVersionIdentifier(etag: string | undefined): this; /** * @deprecated Since 1.12.0. Will be hidden in version 2.0. * Initializes or sets the remoteState of the entity. * This function is called on all read, create and update requests. * This function should be called after [[initializeCustomFields]], if custom fields are defined. * @param state - State to be set as remote state. * @returns The entity itself, to facilitate method chaining */ setOrInitializeRemoteState(state?: Record<string, any>): this; /** * Returns all updated custom field properties compared to the last known remote state. * @returns An object containing all updated custom properties, with their new values. */ getUpdatedCustomFields(): Record<string, any>; /** * Returns all changed properties compared to the last known remote state. * The returned properties do not include custom fields. * Use [[getUpdatedCustomFields]], if you need custom fields. * @returns Entity with all properties that changed */ getUpdatedProperties(): Record<string, any>; /** * Returns all changed property names compared to the last known remote state. * The returned properties names do not include custom fields. * Use [[getUpdatedCustomFields]], if you need custom fields. * @returns Entity with all properties that changed */ getUpdatedPropertyNames(): string[]; /** * @deprecated Since v1.34.1. Use [[asObject]] instead. * Returns a map of all defined fields in entity to their current values. * @param visitedEntities - List of entities to check in case of circular dependencies. * @returns Entity with all defined entity fields */ protected getCurrentMapKeys(visitedEntities?: Entity[]): any; protected isVisitedEntity<EntityT extends Entity>(entity: EntityT, visitedEntities?: Entity[]): boolean; protected getCurrentStateForKey(key: string, visitedEntities?: Entity[]): any; /** * Validates whether a field name does not conflict with an original field name and thus can be defined as custom fields. * @param customFieldName - Field name to check * @returns Boolean value that describes whether a field name can be defined as custom field */ protected isConflictingCustomField(customFieldName: string): boolean; /** * Creates an object containing all defined properties, navigation properties and custom fields in the entity. * @param visitedEntities - List of entities to check in case of circular dependencies. * @returns Entity as an object with all defined entity fields */ protected asObject(visitedEntities?: Entity[]): Record<string, any>; } /** * @hidden */ export interface EntityIdentifiable<T extends Entity> { readonly _entityConstructor: Constructable<T>; readonly _entity: T; } /** * @hidden */ export declare function isSelectedProperty<EntityT extends Entity>(json: any, field: Field<EntityT> | Link<EntityT>): boolean; /** * @hidden */ export declare function isExistentProperty<EntityT extends Entity, LinkedEntityT extends Entity>(json: any, link: Link<EntityT, LinkedEntityT>): boolean; /** * @hidden */ export declare function isExpandedProperty<EntityT extends Entity, LinkedEntityT extends Entity>(json: any, link: Link<EntityT, LinkedEntityT>): boolean; export { Entity as EntityBase }; //# sourceMappingURL=entity.d.ts.map