UNPKG

angular-odata

Version:

Client side OData typescript library for Angular

177 lines (176 loc) 8.39 kB
import { Observable } from 'rxjs'; import { EntityKey, ODataActionOptions, ODataEntityResource, ODataFunctionOptions, ODataNavigationPropertyResource, ODataOptions, ODataPropertyResource, ODataQueryArgumentsOptions, ODataQueryOptionsHandler, ODataResource, ODataSingletonResource } from '../resources'; import { ODataStructuredType } from '../schema'; import { ODataCollection } from './collection'; import { ModelOptions, ODataModelField, ODataModelOptions, ODataModelAttribute, ODataModelEventEmitter, ModelInterface } from './options'; import { EdmType, ParserOptions } from '../types'; import { ODataEntityAnnotations } from '../annotations'; export declare class ODataModel<T> { static options: ModelOptions; static meta: ODataModelOptions<any>; _parent: [ ODataModel<any> | ODataCollection<any, ODataModel<any>>, ODataModelField<any> | null ] | null; _resource: ODataResource<T> | null; _resources: { parent: [ ODataModel<any> | ODataCollection<any, ODataModel<any>>, ODataModelField<any> | null ] | null; resource: ODataResource<T> | null; }[]; _attributes: Map<string, ODataModelAttribute<any>>; _annotations: ODataEntityAnnotations<T>; _meta: ODataModelOptions<any>; events$: ODataModelEventEmitter<T>; static buildMetaOptions<T>({ config, structuredType, }: { config?: ModelOptions; structuredType: ODataStructuredType<T>; }): ODataModelOptions<T>; constructor(data?: Partial<T> | { [name: string]: any; }, { parent, resource, annots, reset, }?: { parent?: [ ODataModel<any> | ODataCollection<any, ODataModel<any>>, ODataModelField<any> | null ]; resource?: ODataResource<T> | null; annots?: ODataEntityAnnotations<T>; reset?: boolean; }); resource(): ODataEntityResource<T> | ODataNavigationPropertyResource<T> | ODataPropertyResource<T> | ODataSingletonResource<T> | null; pushResource(resource: ODataEntityResource<T> | ODataNavigationPropertyResource<T> | ODataPropertyResource<T> | ODataSingletonResource<T> | null): void; popResource(): { parent: [ODataModel<any> | ODataCollection<any, ODataModel<any>>, ODataModelField<any> | null] | null; resource: ODataResource<T> | null; } | undefined; navigationProperty<N>(name: keyof T | string): ODataNavigationPropertyResource<N>; property<N>(name: string): ODataPropertyResource<N>; attach(resource: ODataEntityResource<T> | ODataNavigationPropertyResource<T> | ODataPropertyResource<T> | ODataSingletonResource<T>): void; schema(): ODataStructuredType<any>; annots(): ODataEntityAnnotations<T>; key({ field_mapping, resolve, }?: { field_mapping?: boolean; resolve?: boolean; }): EntityKey<T> | { [name: string]: any; } | undefined; isOpenModel(): boolean; isParentOf(child: ODataModel<any> | ODataCollection<any, ODataModel<any>>): boolean; referential(attr: ODataModelAttribute<any> | ODataModelField<any>, { field_mapping, resolve, }?: { field_mapping?: boolean; resolve?: boolean; }): { [name: string]: any; } | null | undefined; referenced(attr: ODataModelAttribute<any> | ODataModelField<any>, { field_mapping, resolve, }?: { field_mapping?: boolean; resolve?: boolean; }): { [name: string]: any; } | null | undefined; _errors?: { [name: string]: any; }; validate({ method, navigation, }?: { method?: 'create' | 'update' | 'modify'; navigation?: boolean; }): { [name: string]: string[]; } | undefined; isValid({ method, navigation, }?: { method?: 'create' | 'update' | 'modify'; navigation?: boolean; }): boolean; defaults(): any; toEntity({ client_id, include_navigation, include_concurrency, include_computed, include_key, include_id, include_non_field, changes_only, field_mapping, chain, }?: { client_id?: boolean; include_navigation?: boolean; include_concurrency?: boolean; include_computed?: boolean; include_key?: boolean; include_id?: boolean; include_non_field?: boolean; changes_only?: boolean; field_mapping?: boolean; chain?: (ODataModel<any> | ODataCollection<any, ODataModel<any>>)[]; }): T | { [name: string]: any; }; toJson(): T | { [name: string]: any; }; set(path: keyof T | string | string[], value: any, { type }?: { type?: EdmType | string; }): any; get(path: keyof T | string | string[]): any; has(path: keyof T | string | string[]): boolean; reset({ path, silent, }?: { path?: keyof T | string | string[]; silent?: boolean; }): void; clear({ silent }?: { silent?: boolean; }): void; assign(entity: Partial<T> | { [name: string]: any; }, { add, merge, remove, reset, reparent, silent, }?: { add?: boolean; merge?: boolean; remove?: boolean; reset?: boolean; reparent?: boolean; silent?: boolean; }): this; clone<M extends ODataModel<T>>(): M; private _request; fetch({ ...options }?: ODataOptions & { options?: ODataOptions; }): Observable<this>; save({ method, navigation, validate, ...options }?: ODataOptions & { method?: 'create' | 'update' | 'modify'; navigation?: boolean; validate?: boolean; options?: ODataOptions; }): Observable<this>; destroy({ ...options }?: ODataOptions & { options?: ODataOptions; }): Observable<any>; /** * Create an execution context for change the internal query of a resource * @param ctx Function to execute */ query(ctx: (q: ODataQueryOptionsHandler<T>, s?: ODataStructuredType<T>) => void): this; /** * Perform a check on the internal state of the model and return true if the model is changed. * @param include_navigation Check in navigation properties * @returns true if the model has changed, false otherwise */ hasChanged({ include_navigation, }?: { include_navigation?: boolean; }): boolean; encode<E>(name: keyof T, options?: ParserOptions): any; isNew(): boolean; withResource<R>(resource: any, ctx: (model: this) => R): R; /** * Create an execution context for a given function, where the model is bound to its entity endpoint * @param ctx Context function * @returns The result of the context */ asEntity<R>(ctx: (model: this) => R): R; callFunction<P, R>(name: string, params: P | null, responseType: 'property' | 'model' | 'collection' | 'none' | 'blob' | 'arraybuffer', options?: ODataFunctionOptions<R>): Observable<R | ODataModel<R> | ODataCollection<R, ODataModel<R>> | null | Blob | ArrayBuffer>; callAction<P, R>(name: string, params: P | null, responseType?: 'property' | 'model' | 'collection' | 'none' | 'blob' | 'arraybuffer', { ...options }?: {} & ODataActionOptions<R>): Observable<R | ODataModel<R> | ODataCollection<R, ODataModel<R>> | null | Blob | ArrayBuffer>; cast<S>(type: string, ModelType?: typeof ODataModel): ODataModel<T> & ModelInterface<T>; cast<S, M extends ODataModel<S>>(type: string, ModelType?: typeof ODataModel): M; fetchNavigationProperty<S>(name: keyof T | string, responseType: 'model' | 'collection', options?: ODataQueryArgumentsOptions<S>): Observable<ODataModel<S> | ODataCollection<S, ODataModel<S>> | null>; fetchAttribute<P>(name: keyof T, options?: ODataQueryArgumentsOptions<P>): Observable<P | ODataModel<P> | ODataCollection<P, ODataModel<P>> | null>; getAttribute<P>(name: keyof T | string): P | ODataModel<P> | ODataCollection<P, ODataModel<P>> | null; setAttribute<N>(name: keyof T, model: ODataModel<N> | ODataCollection<N, ODataModel<N>> | null, options?: ODataOptions): Observable<this>; setReference<N>(name: keyof T | string, model: ODataModel<N> | ODataCollection<N, ODataModel<N>> | null, options?: ODataOptions): Observable<this>; get [Symbol.toStringTag](): string; equals(other: ODataModel<T>): boolean; collection(): ODataCollection<T, ODataModel<T>> | undefined; next(): ODataModel<T> | undefined; prev(): ODataModel<T> | undefined; }