UNPKG

angular-odata

Version:

Client side OData typescript library for Angular

173 lines (172 loc) 6.19 kB
import { ParserOptions, Parser, StructuredTypeConfig, StructuredTypeFieldConfig, FieldParser, EdmType } from '../../types'; import { ODataAnnotatable } from '../annotation'; import { ODataEnumTypeParser } from './enum-type'; type JsonSchemaSelect<T> = Array<keyof T>; type JsonSchemaCustom<T> = { [P in keyof T]?: (schema: any, field: ODataStructuredTypeFieldParser<T[P]>) => any; }; type JsonSchemaExpand<T> = { [P in keyof T]?: JsonSchemaOptions<T[P]>; }; type JsonSchemaRequired<T> = { [P in keyof T]?: boolean; }; export type JsonSchemaOptions<T> = { select?: JsonSchemaSelect<T>; custom?: JsonSchemaCustom<T>; expand?: JsonSchemaExpand<T>; required?: JsonSchemaRequired<T>; }; export declare class ODataEntityTypeKey { name: string; alias?: string; constructor({ name, alias }: { name: string; alias?: string; }); } export declare class ODataReferential { property: string; referencedProperty: string; constructor({ property, referencedProperty, }: { property: string; referencedProperty: string; }); } export declare class ODataStructuredTypeFieldParser<T> extends ODataAnnotatable implements FieldParser<T> { name: string; private structured; type: string | EdmType; private parser; collection: boolean; navigation: boolean; nullable?: boolean; default?: any; maxLength?: number; precision?: number; scale?: number | 'variable'; referentials: ODataReferential[]; parserOptions?: ParserOptions; constructor(name: string, structured: ODataStructuredTypeParser<any>, field: StructuredTypeFieldConfig); validate(value: any, { method, navigation, }?: { method?: 'create' | 'update' | 'modify'; navigation?: boolean; }): { [name: string]: any; } | { [name: string]: any; }[] | string[] | undefined; private parse; deserialize(value: any, options?: ParserOptions): T; private toJson; serialize(value: T, options?: ParserOptions): any; encode(value: T, options?: ParserOptions): string; configure({ options, parserForType, }: { options: ParserOptions; parserForType: (type: string) => Parser<any>; }): void; toJsonSchema(options?: JsonSchemaOptions<T>): any; isKey(): boolean; hasReferentials(): boolean; isEdmType(): boolean; isEnumType(): boolean; enumType(): ODataEnumTypeParser<T>; isStructuredType(): boolean; structuredType(): ODataStructuredTypeParser<T>; field<F>(name: string): ODataStructuredTypeFieldParser<F>; } export declare class ODataStructuredTypeParser<T> extends ODataAnnotatable implements Parser<T> { name: string; namespace: string; open: boolean; children: ODataStructuredTypeParser<any>[]; alias?: string; base?: string; parent?: ODataStructuredTypeParser<any>; private _keys?; private _fields; parserOptions?: ParserOptions; constructor(config: StructuredTypeConfig, namespace: string, alias?: string); addField<F>(name: string, config: StructuredTypeFieldConfig): ODataStructuredTypeFieldParser<F>; /** * Create a nicer looking title. * Titleize is meant for creating pretty output. * @param term The term of the annotation to find. * @returns The titleized string. */ titleize(term?: string | RegExp): string; isTypeOf(type: string): boolean; isSubtypeOf(type: string): boolean; isSupertypeOf(type: string): boolean; isOpenType(): boolean; findChildParser(predicate: (p: ODataStructuredTypeParser<any>) => boolean): ODataStructuredTypeParser<any> | undefined; childParser(predicate: (p: ODataStructuredTypeParser<any>) => boolean): Parser<any>; deserialize(value: any, options?: ParserOptions): T; serialize(value: Partial<T>, options?: ParserOptions): any; encode(value: T, options?: ParserOptions): any; configure({ options, parserForType, }: { options: ParserOptions; parserForType: (type: string) => Parser<any>; }): void; /** * Returns all fields of the structured type. * @param include_navigation Include navigation properties in the result. * @param include_parents Include the parent types in the result. * @returns All fields of the structured type. */ fields({ include_navigation, include_parents, }: { include_parents: boolean; include_navigation: boolean; }): ODataStructuredTypeFieldParser<any>[]; /** * Returns the keys of the structured type. * @param include_parents Include the parent fields * @returns The keys of the structured type */ keys({ include_parents, }: { include_parents: boolean; }): ODataEntityTypeKey[]; isEntityType(): boolean; isComplexType(): boolean; /** * Find the field parser for the given field name. * @param name Name of the field * @returns The field parser */ field<F>(name: keyof T): ODataStructuredTypeFieldParser<F>; /** * Picks the fields from attributes. * @param attrs * @param include_parents Include the parent fields * @param include_navigation Include the navigation fields * @param include_etag Include the etag field * @returns The picked fields */ pick(attrs: { [name: string]: any; }, { include_id, include_key, include_parents, include_navigation, include_computed, include_etag, options, }?: { include_id?: boolean; include_key?: boolean; include_parents?: boolean; include_navigation?: boolean; include_computed?: boolean; include_etag?: boolean; options?: ParserOptions; }): Partial<T>; resolveKey(value: any, { resolve, single, }?: { resolve?: boolean; single?: boolean; }): any; defaults(): { [name: string]: any; }; toJsonSchema(options?: JsonSchemaOptions<T>): any; validate(attrs: any, { method, navigation, }?: { create?: boolean; method?: 'create' | 'update' | 'modify'; navigation?: boolean; }): { [name: string]: any; } | undefined; } export {};