@sap-cloud-sdk/odata-common
Version:
SAP Cloud SDK for JavaScript common functions of OData client generator and OpenAPI clint generator.
100 lines (99 loc) • 5.2 kB
TypeScript
import { ODataUpdateRequestConfig } from '../request';
import { MethodRequestBuilder } from './request-builder-base';
import type { HttpResponse } from '@sap-cloud-sdk/http-client';
import type { EntityBase, EntityIdentifiable } from '../entity-base';
import type { EntitySerializer } from '../entity-serializer';
import type { ODataRequest, BatchReference, WithBatchReference } from '../request';
import type { ODataUri } from '../uri-conversion';
import type { Selectable } from '../selectable';
import type { DeSerializers } from '../de-serializers';
import type { EntityApi } from '../entity-api';
/**
* Abstract class to create OData query to update an entity containing methods shared for OData v2 and v4.
* @typeParam EntityT - Type of the entity to be updated
*/
export declare abstract class UpdateRequestBuilderBase<EntityT extends EntityBase, DeSerializersT extends DeSerializers> extends MethodRequestBuilder<ODataUpdateRequestConfig<EntityT, DeSerializersT>> implements EntityIdentifiable<EntityT, DeSerializersT>, WithBatchReference {
readonly _entityApi: EntityApi<EntityT, DeSerializersT>;
readonly _entity: EntityT;
readonly oDataUri: ODataUri<DeSerializersT>;
readonly entitySerializer: EntitySerializer;
readonly extractODataEtag: (json: Record<string, any>) => string | undefined;
readonly payloadManipulator: (body: Record<string, any>) => Record<string, any>;
readonly _deSerializers: DeSerializersT;
private ignored;
private required;
private _batchReference;
/**
* Creates an instance of UpdateRequestBuilder.
* @param _entityApi - Entity API for building and executing the request.
* @param _entity - Entity to be updated.
* @param oDataUri - URI conversion functions.
* @param entitySerializer - Entity serializer.
* @param extractODataEtag - Extractor for ETag from payload.
* @param payloadManipulator - Manipulator for the payload.
*/
constructor(_entityApi: EntityApi<EntityT, DeSerializersT>, _entity: EntityT, oDataUri: ODataUri<DeSerializersT>, entitySerializer: EntitySerializer, extractODataEtag: (json: Record<string, any>) => string | undefined, payloadManipulator: (body: Record<string, any>) => Record<string, any>);
get entity(): EntityT;
/**
* Gets identifier for the batch request.
* @returns Batch request identifier.
*/
getBatchReference(): BatchReference;
/**
* Sets user-defined identifier for the batch reference.
* @param id - User-defined batch request identifier.
*/
setBatchId(id: string): void;
/**
* Explicitly configure 'PUT' as the method of the update request. By default, only the properties that have changed compared to the last known remote state are sent using 'PATCH', while with 'PUT', the whole entity is sent.
* @returns The entity itself, to facilitate method chaining.
*/
replaceWholeEntityWithPut(): this;
/**
* Sets required entity keys for the update request.
* @param fields - Enumeration of the fields to be required.
* @returns The entity itself, to facilitate method chaining.
*/
setRequiredFields(...fields: Selectable<EntityT, DeSerializersT>[]): this;
setRequiredFields(fields: Selectable<EntityT, DeSerializersT>[]): this;
/**
* Sets entity fields to ignore by the update request.
* @param fields - Enumeration of the fields to be ignored.
* @returns The entity itself, to facilitate method chaining.
*/
setIgnoredFields(...fields: Selectable<EntityT, DeSerializersT>[]): this;
setIgnoredFields(fields: Selectable<EntityT, DeSerializersT>[]): this;
/**
* Instructs the request to force an overwrite of the entity by sending an 'If-Match: *' header instead of sending the ETag version identifier.
* @returns The request itself to ease chaining while executing the request.
*/
ignoreVersionIdentifier(): this;
/**
* Sets ETag version identifier of the entity to update.
* @param etag - Custom ETag version identifier to be sent in the header of the request.
* @returns The request itself to ease chaining while executing the request.
*/
setVersionIdentifier(etag: string): this;
/**
* Executes the query.
* @param request - Request object to be executed.
* @returns A promise resolving to the entity once it was updated.
*/
protected executeRequest(request: ODataRequest<ODataUpdateRequestConfig<EntityT, DeSerializersT>>): Promise<EntityT>;
protected executeRequestRaw(request: ODataRequest<ODataUpdateRequestConfig<EntityT, DeSerializersT>>): Promise<HttpResponse>;
protected getPayload(): Record<string, any>;
protected isEmptyObject(obj: any): boolean;
private addRequiredFields;
private getKeyFieldNames;
private toSet;
private serializedDiff;
private removeKeyFields;
private removeIgnoredFields;
}
/**
* @param condition - condition to remove
* @param body - body
* @returns body without condition
* @internal
*/
export declare function removePropertyOnCondition(condition: (objectEntry: [string, any]) => boolean, body: Record<string, any>): Record<string, any>;