UNPKG

angular-odata

Version:

Client side OData typescript library for Angular

284 lines (283 loc) 7.83 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 ApiOptions { 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 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: StructuredTypeFieldConfig; } 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 Cache { put<T>(key: string, payload: T, ...opts: any[]): void; get<T>(key: string, ...opts: any[]): T | undefined; } export type ApiConfig = { serviceRootUrl: string; metadataUrl?: string; name?: string; version?: ODataVersion; default?: boolean; creation?: Date; cache?: Cache; errorHandler?: (error: any, caught: Observable<any>) => Observable<never>; options?: ApiOptions; parsers?: { [type: string]: Parser<any>; }; schemas?: SchemaConfig[]; references?: ReferenceConfig[]; }; export type AnnotationConfig = { term: string; string?: string; bool?: boolean; int?: number; permissions?: string[]; properties?: string[]; }; export type ReferenceConfig = { uri: string; includes?: string; annotations?: AnnotationConfig[]; enums?: EnumTypeConfig[]; entities?: StructuredTypeConfig[]; callables?: CallableConfig[]; containers?: EntityContainerConfig[]; }; export type SchemaConfig = { namespace: string; alias?: string; annotations?: AnnotationConfig[]; enums?: EnumTypeConfig[]; entities?: StructuredTypeConfig[]; callables?: CallableConfig[]; containers?: EntityContainerConfig[]; }; export type EntityContainerConfig = { name: string; annotations?: AnnotationConfig[]; entitySets?: EntitySetConfig[]; singletons?: SingletonConfig[]; }; export type EnumTypeFieldConfig = { value: number; annotations?: AnnotationConfig[]; }; export type EnumTypeConfig = { name: string; flags?: boolean; annotations?: AnnotationConfig[]; members: { [name: string]: number; } | { [value: number]: string; }; fields: { [member: string]: EnumTypeFieldConfig; }; }; export type StructuredTypeFieldConfig = { type: string; default?: any; maxLength?: number; key?: boolean; collection?: boolean; nullable?: boolean; navigation?: boolean; precision?: number; annotations?: AnnotationConfig[]; scale?: number | 'variable'; referentials?: { property: string; referencedProperty: string; }[]; referential?: string; referenced?: string; }; export type StructuredTypeConfig = { name: string; base?: string; open?: boolean; model?: { new (...params: any[]): any; }; collection?: { new (...params: any[]): any; }; annotations?: AnnotationConfig[]; keys?: { name: string; alias?: string; }[]; fields?: { [name: string]: StructuredTypeFieldConfig; }; }; export type ParameterConfig = { type: string; nullable?: boolean; collection?: boolean; }; export type CallableConfig = { name: string; entitySetPath?: string; bound?: boolean; composable?: boolean; parameters?: { [name: string]: ParameterConfig; }; return?: { type: string; collection?: boolean; }; }; export type EntitySetConfig = { name: string; entityType: string; service: { new (...params: any[]): any; }; annotations?: AnnotationConfig[]; }; export type SingletonConfig = { name: string; type: string; service: { new (...params: any[]): any; }; annotations?: AnnotationConfig[]; };