UNPKG

@odata2ts/odata-query-objects

Version:

Q-Objects are the magic sauce for the odata-query-builder and allow for renaming and type conversion

62 lines (61 loc) 2.9 kB
import { PartialDeep } from "type-fest"; import { QueryObjectModel } from "./QueryObjectModel"; export declare const ENUMERABLE_PROP_DEFINITION: { enumerable: boolean; }; export declare class QueryObject<T extends object = any> implements QueryObjectModel<T, PartialDeep<T>> { private __prefix?; private __propMapping?; protected readonly __subtypeMapping?: Record<string, string>; constructor(__prefix?: string | undefined); private __getPropMapping; /** * Adds the prefix of this QueryObject including a separating slash in front of the given path. * Only applies, if this QueryObject has a prefix. * * @param path the path to be prefixed * @protected */ protected withPrefix(path: string): string; /** * Convert the data model (or parts of it) as it is retrieved from the OData service to the data model * that the user is facing. This includes: * - renaming of property names * - converting property values to different types * - handling nested types * * Conversion rules: * - null & undefined are not converted, they're just passed back * - trying to convert primitive values will raise an error * - it's allowed to pass a single model or a collection of these * - unknown properties (not advertised in the metadata) are passed as they are * * @param odataModel data model as it is retrieved from the OData service * @returns the data model that the user is facing */ convertFromOData(odataModel: null): null; convertFromOData(odataModel: undefined): undefined; convertFromOData(odataModel: object): PartialDeep<T> | Array<PartialDeep<T>>; /** * Convert the data model (or parts of it) that the user is facing to the data model as it is * used by the OData service. This includes: * - renaming of property names * - converting property values to different types * - handling nested types * * Conversion rules: * - null & undefined are not converted, they're just passed back * - primitive values will raise an error * - it's allowed to pass a single model or a collection of these * - passing unknown properties is fine * - with the option failForUnknownProps=true passing unknown props results in errors * * @param userModel the data model the user is facing * @param failForUnknownProps (false by default) raise an error for unknown props * @retuns the data model that is consumable by the OData service */ convertToOData(userModel: null, failForUnknownProps?: boolean): null; convertToOData(userModel: undefined, failForUnknownProps?: boolean): undefined; convertToOData(userModel: PartialDeep<T>, failForUnknownProps?: boolean): object; convertToOData(userModel: Array<PartialDeep<T>>, failForUnknownProps?: boolean): Array<object>; }