UNPKG

2.42 kBTypeScriptView Raw
1import { Entity, Constructable, ComplexTypeNamespace, EdmTypeShared } from '../odata-common';
2import { EdmToPrimitive as EdmToPrimitiveV2, EdmType as EdmTypeV2 } from '../odata-v2';
3import { EdmToPrimitive as EdmToPrimitiveV4, EdmType as EdmTypeV4 } from '../odata-v4';
4/**
5 * Interface representing the return type of the builder function [[entityDeserializer]]
6 */
7export interface EntityDeserializer<EntityT extends Entity = any> {
8 deserializeEntity: (json: any, entityConstructor: Constructable<EntityT>, requestHeader?: any) => EntityT;
9 deserializeComplexType: (json: Record<string, any>, complexType: ComplexTypeNamespace<any>) => any;
10}
11declare type EdmToTsTypeV2<EdmT extends EdmTypeV2 = any> = (value: any, edmType: EdmTypeShared<'v2'>) => EdmToPrimitiveV2<EdmT>;
12declare type EdmToTsTypeV4<EdmT extends EdmTypeV4 = any> = (value: any, edmType: EdmTypeShared<'v4'>) => EdmToPrimitiveV4<EdmT>;
13declare type ExtractODataETagType = (json: Record<string, any>) => string | undefined;
14declare type ExtractDataFromOneToManyLinkType = (data: any) => any[];
15/**
16 * Constructs an entityDeserializer given the OData v2 or v4 specific methods.
17 * The concrete deserializers are created in odata/v2/entity-deserializer.ts and odata/v4/entity-deserializer.ts
18 * @param edmToTs - Converters emd input to ts values.
19 * @param extractODataETag - Extractor for the ETag.
20 * @param extractDataFromOneToManyLink - Extractor for data related to one to many links.
21 * @returns a entity deserializer as defined by [[EntityDeserializer]]
22 */
23export declare function entityDeserializer(edmToTs: EdmToTsTypeV2 | EdmToTsTypeV4, extractODataETag: ExtractODataETagType, extractDataFromOneToManyLink: ExtractDataFromOneToManyLinkType): EntityDeserializer;
24export declare function extractEtagFromHeader(headers: any): string | undefined;
25/**
26 * Extracts all custom fields from the JSON payload for a single entity.
27 * In this context, a custom fields is every property that is not known in the corresponding entity class.
28 * @param json - The JSON payload.
29 * @param entityConstructor - The constructor function of the entity class.
30 * @returns An object containing the custom fields as key-value pairs.
31 */
32export declare function extractCustomFields<EntityT extends Entity, JsonT>(json: Partial<JsonT>, entityConstructor: Constructable<EntityT>): Record<string, any>;
33export {};
34//# sourceMappingURL=entity-deserializer.d.ts.map
\No newline at end of file