angular-odata
Version:
Client side OData typescript library for Angular
153 lines (152 loc) • 6.02 kB
TypeScript
import { ODataCollection } from '../models/collection';
import { ODataModel } from '../models/model';
import { ParserOptions, StructuredTypeConfig, StructuredTypeFieldConfig } from '../types';
import { ODataParserSchemaElement } from './element';
import { JsonSchemaOptions, ODataEntityTypeKey, ODataStructuredTypeFieldParser, ODataStructuredTypeParser } from './parsers';
import { ODataSchema } from './schema';
export declare class ODataStructuredType<T> extends ODataParserSchemaElement<T, ODataStructuredTypeParser<T>> {
base?: string;
parent?: ODataStructuredType<any>;
children: ODataStructuredType<any>[];
model?: typeof ODataModel;
collection?: typeof ODataCollection;
constructor(config: StructuredTypeConfig, schema: ODataSchema);
configure({ options }: {
options: ParserOptions;
}): void;
/**
* Returns a boolean indicating if the structured type is a subtype of the given type.
* @param type String representation of the type
* @returns True if the callable is type of the given type
*/
isSubtypeOf(schema: ODataStructuredType<any>): boolean;
/**
* Returns a boolean indicating if the structured type is a supertype of the given type.
* @param type String representation of the type
* @returns True if the callable is type of the given type
*/
isSupertypeOf(schema: ODataStructuredType<any>): boolean;
/**
* Returns a boolean indicating if the structured type has a simple key.
* @returns True if the structured type has a simple key
*/
isSimpleKey(): boolean;
/**
* Returns a boolean indicating if the structured type has a compound key.
* @returns True if the structured type has a compound key.
*/
isCompoundKey(): boolean;
isOpenType(): boolean;
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>;
addField<F>(name: string, config: StructuredTypeFieldConfig): ODataStructuredTypeFieldParser<F>;
/**
* Find a parent schema of the structured type.
* @param predicate Function for evaluate the schemas in the hierarchy.
* @returns The schema that matches the predicate.
*/
findParentSchema(predicate: (p: ODataStructuredType<any>) => boolean): ODataStructuredType<any> | undefined;
findChildSchema(predicate: (p: ODataStructuredType<any>) => boolean): ODataStructuredType<any> | undefined;
/**
* Find a parent schema of the structured type for the given field.
* @param field Field that belongs to the structured type
* @returns The schema of the field
*/
findParentSchemaForField<E>(field: ODataStructuredTypeFieldParser<any>): ODataStructuredType<E>;
/**
* 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, }?: {
include_id?: boolean;
include_key?: boolean;
include_parents?: boolean;
include_navigation?: boolean;
include_computed?: boolean;
include_etag?: boolean;
}): Partial<T>;
/**
* Deseialize the given value from the structured type.
* @param value Value to deserialize
* @param options Options for deserialization
* @returns Deserialized value
*/
deserialize(value: any, options?: ParserOptions): T;
/**
* Serialize the given value for the structured type.
* @param value Value to serialize
* @param options Options for serialization
* @returns Serialized value
*/
serialize(value: T, options?: ParserOptions): any;
/**
* Encode the given value for the structured type.
* @param value Value to encode
* @param options Options for encoding
* @returns Encoded value
*/
encode(value: T, options?: ParserOptions): any;
/**
* 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[];
/**
* Resolve the key of the structured type for the given value.
* @param attrs Attributes of the value
* @returns Resolved key
*/
resolveKey(attrs: T | {
[name: string]: any;
}): any;
/**
* Returns the defaults values for the structured type.
* @returns Default values for the structured type
*/
defaults(): {
[name: string]: any;
};
/**
* Convert the structured type to json schema
* @param options Options for json schema
* @returns Json Schema
*/
toJsonSchema(options?: JsonSchemaOptions<T>): any;
/**
* Validate the given value against the structured type.
* @param attrs Attributes of the value
* @param method Method to use for the process validation
* @returns Object with the errors
*/
validate(attrs: Partial<T>, { method, navigation, }?: {
method?: 'create' | 'update' | 'modify';
navigation?: boolean;
}): {
[name: string]: any;
} | undefined;
}