UNPKG

@sap-cloud-sdk/core

Version:
34 lines 2.42 kB
import { Entity, Constructable, ComplexTypeNamespace, EdmTypeShared } from '../odata-common'; import { EdmToPrimitive as EdmToPrimitiveV2, EdmType as EdmTypeV2 } from '../odata-v2'; import { EdmToPrimitive as EdmToPrimitiveV4, EdmType as EdmTypeV4 } from '../odata-v4'; /** * Interface representing the return type of the builder function [[entityDeserializer]] */ export interface EntityDeserializer<EntityT extends Entity = any> { deserializeEntity: (json: any, entityConstructor: Constructable<EntityT>, requestHeader?: any) => EntityT; deserializeComplexType: (json: Record<string, any>, complexType: ComplexTypeNamespace<any>) => any; } declare type EdmToTsTypeV2<EdmT extends EdmTypeV2 = any> = (value: any, edmType: EdmTypeShared<'v2'>) => EdmToPrimitiveV2<EdmT>; declare type EdmToTsTypeV4<EdmT extends EdmTypeV4 = any> = (value: any, edmType: EdmTypeShared<'v4'>) => EdmToPrimitiveV4<EdmT>; declare type ExtractODataETagType = (json: Record<string, any>) => string | undefined; declare type ExtractDataFromOneToManyLinkType = (data: any) => any[]; /** * Constructs an entityDeserializer given the OData v2 or v4 specific methods. * The concrete deserializers are created in odata/v2/entity-deserializer.ts and odata/v4/entity-deserializer.ts * @param edmToTs - Converters emd input to ts values. * @param extractODataETag - Extractor for the ETag. * @param extractDataFromOneToManyLink - Extractor for data related to one to many links. * @returns a entity deserializer as defined by [[EntityDeserializer]] */ export declare function entityDeserializer(edmToTs: EdmToTsTypeV2 | EdmToTsTypeV4, extractODataETag: ExtractODataETagType, extractDataFromOneToManyLink: ExtractDataFromOneToManyLinkType): EntityDeserializer; export declare function extractEtagFromHeader(headers: any): string | undefined; /** * Extracts all custom fields from the JSON payload for a single entity. * In this context, a custom fields is every property that is not known in the corresponding entity class. * @param json - The JSON payload. * @param entityConstructor - The constructor function of the entity class. * @returns An object containing the custom fields as key-value pairs. */ export declare function extractCustomFields<EntityT extends Entity, JsonT>(json: Partial<JsonT>, entityConstructor: Constructable<EntityT>): Record<string, any>; export {}; //# sourceMappingURL=entity-deserializer.d.ts.map