UNPKG

angular-odata

Version:

Client side OData typescript library for Angular

286 lines (285 loc) 8.14 kB
import { Observable } from 'rxjs'; export type ODataVersion = '2.0' | '3.0' | '4.0'; export type FetchPolicy = 'cache-first' | 'cache-and-network' | 'network-only' | 'no-cache' | 'cache-only'; export type ODataMetadataType = 'minimal' | 'full' | 'none'; export type CacheCacheability = 'public' | 'private' | 'no-cache' | 'no-store'; export declare enum PathSegment { batch = "batch", metadata = "metadata", entitySet = "entitySet", singleton = "singleton", type = "type", property = "property", navigationProperty = "navigationProperty", reference = "reference", value = "value", count = "count", function = "function", action = "action" } export declare enum QueryOption { select = "select", expand = "expand", compute = "compute", apply = "apply", filter = "filter", search = "search", transform = "transform", orderBy = "orderBy", top = "top", skip = "skip", skiptoken = "skiptoken", format = "format", levels = "levels", count = "count" } export declare enum EdmType { Guid = "Edm.Guid", Int16 = "Edm.Int16", String = "Edm.String", Boolean = "Edm.Boolean", Byte = "Edm.Byte", SByte = "Edm.SByte", Int32 = "Edm.Int32", Int64 = "Edm.Int64", Date = "Edm.Date", TimeOfDay = "Edm.TimeOfDay", DateTimeOffset = "Edm.DateTimeOffset", Duration = "Edm.Duration", Decimal = "Edm.Decimal", Double = "Edm.Double", Single = "Edm.Single", Binary = "Edm.Binary", Stream = "Edm.Stream", Geography = "Edm.Geography", GeographyPoint = "Edm.GeographyPoint", GeographyLineString = "Edm.GeographyLineString", GeographyPolygon = "Edm.GeographyPolygon", GeographyMultiPoint = "Edm.GeographyMultiPoint", GeographyMultiLineString = "Edm.GeographyMultiLineString", GeographyMultiPolygon = "Edm.GeographyMultiPolygon", GeographyCollection = "Edm.GeographyCollection", Geometry = "Edm.Geometry", GeometryPoint = "Edm.GeometryPoint", GeometryLineString = "Edm.GeometryLineString", GeometryPolygon = "Edm.GeometryPolygon", GeometryMultiPoint = "Edm.GeometryMultiPoint", GeometryMultiLineString = "Edm.GeometryMultiLineString", GeometryMultiPolygon = "Edm.GeometryMultiPolygon", GeometryCollection = "Edm.GeometryCollection" } export declare enum JsonType { string = "string", number = "number", integer = "integer", object = "object", array = "array", boolean = "boolean", null = "null" } export interface ParserOptions { version?: ODataVersion; exponentialDecimals?: boolean; metadata?: ODataMetadataType; ieee754Compatible?: boolean; streaming?: boolean; stringAsEnum?: boolean; deleteRefBy?: 'path' | 'id'; nonParenthesisForEmptyParameterFunction?: boolean; } export interface ResponseOptions extends ParserOptions { cacheability?: CacheCacheability; maxAge?: number; } export interface StructuredTypeFieldOptions extends ParserOptions { field: ODataStructuredTypeFieldConfig; } export interface Parser<T> { deserialize(value: any, options?: ParserOptions | StructuredTypeFieldOptions): T; serialize(value: any, options?: ParserOptions | StructuredTypeFieldOptions): any; encode(value: any, options?: ParserOptions | StructuredTypeFieldOptions): any; } export interface FieldParser<T> extends Parser<T> { nullable?: boolean; default?: any; maxLength?: number; precision?: number; scale?: number | 'variable'; } export declare const NONE_PARSER: Parser<any>; export interface ODataCache { put<T>(key: string, payload: T, ...opts: any[]): void; get<T>(key: string, ...opts: any[]): T | undefined; handleRequest(req: any, res$: Observable<any>): Observable<any>; flush(): void; } export interface ODataApiConfigOptions { version?: ODataVersion; params?: { [param: string]: string | string[]; }; headers?: { [param: string]: string | string[]; }; withCredentials?: boolean; accept?: { exponentialDecimals?: boolean; metadata?: ODataMetadataType; ieee754Compatible?: boolean; streaming?: boolean; }; etag?: { ifMatch?: boolean; ifNoneMatch?: boolean; }; prefer?: { maxPageSize?: number; return?: 'representation' | 'minimal'; continueOnError?: boolean; includeAnnotations?: string; }; stripMetadata?: ODataMetadataType; fetchPolicy?: FetchPolicy; bodyQueryOptions?: QueryOption[]; stringAsEnum?: boolean; deleteRefBy?: 'path' | 'id'; nonParenthesisForEmptyParameterFunction?: boolean; jsonBatchFormat?: boolean; relativeUrls?: boolean; } export type ODataApiConfig = { serviceRootUrl: string; metadataUrl?: string; name?: string; version?: ODataVersion; default?: boolean; creation?: Date; cache?: ODataCache; errorHandler?: (error: any, caught: Observable<any>) => Observable<never>; options?: ODataApiConfigOptions; parsers?: { [type: string]: Parser<any>; }; schemas?: ODataSchemaConfig[]; references?: ODataReferenceConfig[]; }; export type ODataAnnotationConfig = { term: string; string?: string; bool?: boolean; int?: number; permissions?: string[]; properties?: string[]; }; export type ODataReferenceConfig = { uri: string; includes?: string; annotations?: ODataAnnotationConfig[]; enums?: ODataEnumTypeConfig[]; entities?: ODataStructuredTypeConfig[]; callables?: ODataCallableConfig[]; containers?: ODataEntityContainerConfig[]; }; export type ODataSchemaConfig = { namespace: string; alias?: string; annotations?: ODataAnnotationConfig[]; enums?: ODataEnumTypeConfig[]; entities?: ODataStructuredTypeConfig[]; callables?: ODataCallableConfig[]; containers?: ODataEntityContainerConfig[]; }; export type ODataEntityContainerConfig = { name: string; annotations?: ODataAnnotationConfig[]; entitySets?: ODataEntitySetConfig[]; singletons?: ODataSingletonConfig[]; }; export type ODataEnumTypeFieldConfig = { value: number; annotations?: ODataAnnotationConfig[]; }; export type ODataEnumTypeConfig = { name: string; flags?: boolean; annotations?: ODataAnnotationConfig[]; members: { [name: string]: number; } | { [value: number]: string; }; fields: { [member: string]: ODataEnumTypeFieldConfig; }; }; export type ODataStructuredTypeFieldConfig = { type: string; default?: any; maxLength?: number; key?: boolean; collection?: boolean; nullable?: boolean; navigation?: boolean; precision?: number; annotations?: ODataAnnotationConfig[]; scale?: number | 'variable'; referentials?: { property: string; referencedProperty: string; }[]; referential?: string; referenced?: string; }; export type ODataStructuredTypeConfig = { name: string; base?: string; open?: boolean; model?: { new (...params: any[]): any; }; collection?: { new (...params: any[]): any; }; annotations?: ODataAnnotationConfig[]; keys?: { name: string; alias?: string; }[]; fields?: { [name: string]: ODataStructuredTypeFieldConfig; }; }; export type ODataParameterConfig = { type: string; nullable?: boolean; collection?: boolean; }; export type ODataCallableConfig = { name: string; entitySetPath?: string; bound?: boolean; composable?: boolean; parameters?: { [name: string]: ODataParameterConfig; }; return?: { type: string; collection?: boolean; }; }; export type ODataEntitySetConfig = { name: string; entityType: string; service: { new (...params: any[]): any; }; annotations?: ODataAnnotationConfig[]; }; export type ODataSingletonConfig = { name: string; type: string; service: { new (...params: any[]): any; }; annotations?: ODataAnnotationConfig[]; };