UNPKG

@ima/plugin-http-client

Version:

Generic http client for the IMA application framework.

86 lines 2.92 kB
import type { DataFieldValue } from './mapper/BaseMapper'; export interface EntityConstructor { new (data: object): Entity; } export interface Entity { serialize: (data: object) => any; deserialize: (data: object) => any; } /** * The base class for typed REST API entities. Usage of typed entities may be * optional and is dependent on the specific implementation of the REST API * client. */ export declare class BaseEntity { #private; /** * Returns the description of automatic mapping of the raw data exchanged * between the REST API, and the properties of this * entity. * * The keys of the returned object are the names of the API properties. * * The value associated with key is one of the following: * * - The new name of the property in this entity. This is useful when the * property only needs to be renamed. * * - The mapper instance of BaseMapper. This is useful when the property only needs to changed format but not renamed. * * - The MapperItem object eg.: { mapper: new EntityListMapper(BaseEntity), newKey: 'authors' }. * This is useful when the property needs changed format and renamed too. * */ get dataFieldMapping(): { [key: string]: DataFieldValue; }; /** * Initializes the entity. * * @param data, which will be directly * assigned to the entity's fields. * @param data */ constructor(data: object); /** * Serializes this entity into a JSON-compatible plain JavaScript object * that has a structure that is compatible with the entity's REST API * resource. * * Note that this method may not receive a representation of the entity's * complete state if invoked by the {@linkcode cloneAndPatch()} method. * * The default implementation of this method implements a mapping based on * the {@linkcode dataFieldMapping} property's value. * * @param data */ serialize(data?: any): any; /** * Pre-processes the provided data obtained from the REST API into a form * that can be assigned to this entity. * * This method can be used to format data, rename fields, generated * computed fields, etc. * * Note that this method may not receive a representation of the entity's * complete state in some cases. * * The default implementation of this method implements a mapping based on * the {@linkcode dataFieldMapping} property's value. * * @param data */ deserialize(data: object): any; /** * Creates a clone of this entity. */ clone(): any; /** * Creates a clone of this entity with its state patched using the provided * state patch object. * @param statePatch */ cloneAndPatch(statePatch: any): any; } //# sourceMappingURL=BaseEntity.d.ts.map