import { BehaviorSubject, Observable, ReplaySubject } from 'rxjs'; import { Agent } from './agent'; import { EntityService } from './entity'; import { CalculatedProperty, Catalog, Cube, Entity, EntitySet, EntityType, IDimensionMember, Indicator, MDCube, Schema, SemanticModel } from './models'; import { Dimension } from './types'; import { Type } from './utils/index'; export type DataSourceFactory = () => Promise>; export declare enum AuthenticationMethod { none = "none", basic = "basic", saml = "saml", independent = "independent" } /** * Property settings related to data source type */ export interface DataSourceSettings { dataSourceId?: string; database?: string; language?: string; ignoreUnknownProperty?: boolean; } export interface DataSources { [name: string]: DataSourceOptions; } /** * Data source configuration items * Actually corresponds to a semantic model rather than a data source * * @TODO needs to be redefined using the CSDL concept * * entityTypes configures multiple entities under this data source * * entityType configures the type field of each entity * * annotations configures the annotations of each entity */ export interface DataSourceOptions extends SemanticModel { settings?: DataSourceSettings; authMethod?: string; useLocalAgent?: boolean; /** * Default: client * - client: in client send query options to server * - server: query xmla */ mode?: 'client' | 'server'; /** * Runtime calculated measures, indexed by cube name */ calculatedMeasures?: Record; /** * Is draft semantic model */ isDraft?: boolean; /** * Is use indicators draft */ isIndicatorsDraft?: boolean; /** * Key-value pairs of parameters for cube */ parameters?: Record>; } /** * Abstract interface of data source * - options configuration items * - createEntityService creates entityService * - getAnnotation gets annotation */ export interface DataSource { id: string; options: DataSourceOptions; agent: Agent; refresh(): void; /** * Update options of DataSource */ updateOptions(fn: (options: DataSourceOptions) => DataSourceOptions): void; /** * @deprecated use discoverDBCatalogs */ getCatalogs(): Observable>; /** * Discover catalogs or schemas from DataSource's Database: The data service catalog is used to distinguish different data entity categories, such as Catalog of ODataService, CATALOG_NAME of XMLA, etc. */ discoverDBCatalogs(options?: { throwError?: boolean; }): Observable>; /** * Discover tables from DataSource's Database */ discoverDBTables(refresh?: boolean): Observable>; /** * Discover cubes from api or schema defination of DataSource */ discoverMDCubes(refresh?: boolean): Observable>; /** * Discover members of dimension * * @param entity * @param dimension */ discoverMDMembers(entity: string, dimension: Dimension): Observable; /** * @deprecated use selectEntitySets */ getEntitySets(refresh?: boolean): Observable>; /** * Observe entity sets from DataSource * * @param refresh Force refresh cache in browser */ selectEntitySets(refresh?: boolean): Observable>; /** * @deprecated The EntityType interface should not be exposed directly at runtime, use the selectEntitySet method */ getEntityType(entity: string): Observable; /** * @deprecated use selectMembers */ getMembers(entity: string, dimension: Dimension): Observable; /** * Observe members of dimension in entity (cube) from DataSource * * @param entity Cube name * @param dimension Dimension, include name and hierarchy */ selectMembers(entity: string, dimension: Dimension): Observable; /** * Creates a corresponding entityService based on the specified entitySet name */ createEntityService(entity: string): EntityService; /** * Observe options */ selectOptions(): Observable; /** * Observe runtime schema */ selectSchema(): Observable; /** * Setting a custom Schema * * @param schema EDMSchema */ setSchema(schema: Schema): void; /** * Update the schema * * @param fn */ updateSchema(fn: (schema: Schema) => Schema): void; /** * Update a single cube definition * * @param cube */ updateCube(cube: Cube): void; /** * Update the value of parameters in cube * * @param cube Cube name * @param fn Update function */ updateParameters(cube: string, fn: (state: Record) => Record): void; /** * Insert or update a indicator by `code` */ upsertIndicator(indicator: Indicator): void; /** * Observe to Entity type definition changes, merge runtime and user enhancements * * @param entity */ selectEntitySet(entity: string): Observable; /** * Set up EntityType individually * * @param entityType EntityType */ setEntityType(entityType: EntityType): void; /** * Observe type defination of entity (or Error) (combine runtime type and custom types) * * @param entity */ selectEntityType(entity: string): Observable; /** * Observe indicators of entity * * @param entitySet Cube name */ selectIndicators(entity: string): Observable>; /** * Observe an indicator by code from model */ selectIndicator(cube: string, code: string): Observable; /** * Get an indicator by id from entity * * @param idOrCode Indicator `ID` or `Code` * @param cube Cube name */ getIndicator(idOrCode: string, cube?: string): Indicator; /** * Create DB Table * * @param name * @param columns * @param data */ createEntity(name: string, columns: any, data?: any): Observable; /** * Drop DB Table * * @param name */ dropEntity(name: string): Promise; /** * Use statement query * * @param statement */ query(options: { statement: string; forceRefresh?: boolean; timeout?: number; }): Observable; /** * Clear the browser cache * * @deprecated */ clearCache(): Promise; /** Completes all relevant Observable streams. */ onDestroy(): void; } /** * Implement common functions of the data source model, including obtaining metadata, executing some operations and queries unrelated to specific model entities, creating entity services, etc. * */ export declare abstract class AbstractDataSource implements DataSource { agent: Agent; id: string; protected readonly destroySubject$: ReplaySubject; readonly destroy$: Observable; private options$; get options(): T; readonly calculatedMeasures$: Observable>; protected _entitySets: {}; constructor(options: T, agent: Agent); readonly refresh$: BehaviorSubject; abstract discoverDBCatalogs(): Observable>; abstract discoverDBTables(): Observable>; abstract discoverMDCubes(refresh?: boolean): Observable>; abstract discoverMDMembers(entity: string, dimension: Dimension): Observable; abstract createEntityService(entity: string): EntityService; abstract getEntitySets(refresh?: boolean): Observable>; abstract selectEntitySets(refresh?: boolean): Observable>; abstract getEntityType(entity: string): Observable; abstract getCatalogs(): Observable>; abstract getMembers(entity: string, dimension: Dimension): Observable; abstract selectMembers(entity: string, dimension: Dimension): Observable; abstract createEntity(name: string, columns: any[], data?: any[]): Observable; abstract dropEntity(name: string): Promise; abstract query(options: { statement: string; forceRefresh?: boolean; timeout?: number; }): Observable; refresh(): void; updateOptions(fn: (options: T) => T): void; setSchema(schema: Schema): void; updateSchema(fn: (schema: Schema) => Schema): void; updateCube(cube: Cube): void; updateParameters(cube: string, fn: (state: Record) => Record): void; upsertIndicator(indicator: Indicator): void; selectOptions(): Observable; selectSchema(): Observable; setEntityType(entityType: EntityType): void; /** * This is only responsible for the EntitySet setting during merge runtime, not for Cube type compilation, * which is done when getEntityType gets the original type. * * @param entity * @returns */ selectEntitySet(entity: string): Observable; selectEntityType(entity: string): Observable; selectIndicators(entity: string): Observable; selectIndicator(cube: string, code: string): Observable; getIndicator(id: string, entity?: string): Indicator; selectCalculatedMeasures(cube: string): Observable; clearCache(key?: string): Promise; onDestroy(): void; } /** * Compile indicator to measures * * @param indicator * @returns */ export declare function mapIndicatorToMeasures(indicator: Indicator): any[]; export interface DBCatalog { name: string; label: string; } export interface DBTable extends Entity { catalog?: string; name: string; /** * @deprecated use caption */ label?: string; columns?: DBColumn[]; } export interface DBColumn { name: string; label?: string; type: string; dbType?: string; nullable?: boolean; position?: number; /** * 应该等同于 label */ comment?: string; }