/** * Created by Christophe on 10/10/2017. */ import { DataConnectorConfig } from "./data-connector-config.interface"; import { DataEntity } from "./data-structures/data-entity.class"; import { Observable } from "rxjs/Rx"; import { DataCollection } from "./data-structures/data-collection.class"; import { EntityDataSet, FilterData } from "./types"; import { ReplaySubject } from "rxjs/Rx"; import { EndpointConfig } from "./endpoint-config.interface"; import { InterfaceError } from "./data-interfaces/interface-error.class"; import { CollectionOptionsInterface } from "./collection-options.interface"; import { PaginatedCollection } from "./paginated-collection.interface"; import { CollectionPaginator } from "./collection-paginator.class"; import { Subject } from "rxjs"; /** * Data connector class */ export declare class DataConnector { configuration: DataConnectorConfig; /** * Available interfaces * @type {{}} External interfaces, indexed by name */ private interfaces; /** * Entities store * @type {{}} Entities stores, indexed by endpoint name */ private entitiesLiveStore; /** * Collections store * @type {{}} Collections stores, indexed by endpoint name */ private collectionsLiveStore; /** * Server push listeners * @type {{}} Listeners, indexed by endpoint name */ private pushListeners; /** * */ currentLanguage: string; /** * Built-in external interfaces * @type {{}} */ private builtInFactories; globalMessageSubject: ReplaySubject; /** * Delay before action retry */ private retryTimeout; /** * Max attempts number */ private maxRetry; /** * Create a dataConnector * @param {DataConnectorConfig} configuration Data connector configuration */ constructor(configuration: DataConnectorConfig); private sendMessage(error?); /** * * @param {string} type * @returns {number} */ getRetryTimeout(type: string): number; /** * * @param {string} type * @returns {number} */ getMaxRetry(type: string): number; /** * * @param {string} language */ setLanguage(language: string): void; /** * * @param {number} code */ globalCallback(code: number): void; /** * Get data interface by endpoint name * @param {string} type Endpoint name * @returns {ExternalInterface} External interface */ private getInterface(type); /** * Get endpoint configuration * @param {string} type Endpoint name * @returns {string | EndpointConfig} Type of the endpoint, or endpoint configuration object */ getEndpointConfiguration(type: string): string | EndpointConfig; /** * Get model schema used by the endpoint * @param {string} type Endpoint name * @returns {ModelSchema} The model schema */ private getEndpointStructureModel(type); /** * Get nesting attributes types * @param {string} type Endpoint name * @returns {{[p: string]: string}} The nested attributes types */ private getNesting(type); /** * * @param {string} type * @returns {{[p: string]: any}} */ private getDatas(type); /** * * @param {string} type * @returns {{[p: string]: string}} */ private getEmbeddings(type); /** * Is this endpoint using connector cache * @param {string} type Name of the endpoint * @returns {boolean} True if the endpoint use cache */ private useCache(type); /** * Get optional keys excluded for saving entities in this endpoint * @param {string} type Endpoint name * @returns {string[]} A list of string keys */ private getExclusions(type); /** * Get the observable associated to an entity from the store * @param {string} type Endpoint name * @param {number} id Id of the entity * @returns {Observable} The observable associated to the entity */ private getEntityObservableInStore(type, id); /** * Get the observable associated to the collection from the store * @param {string} type Endpoint name * @param {FilterData} filter Filter object * @param useCache * @returns {Observable} The observable associated to the collection */ private getCollectionObservableInStore(type, filter, useCache?); /** * Get the observable associated to an entity from the store, if the store is undefined, create it * @param {string} type Endpoint name * @param {number} id Id of the entity * @returns {Observable} The observable associated to the entity */ private getEntitySubject(type, id, createObservable?); /** * Register entity in the stores * @param {string} type Endpoint name * @param {number} id Id of the entity * @param {DataEntity} entity Entity * @param {Observable} entityObservable Observable to register * @returns {Observable} The observable associated to the entity */ registerEntity(type: string, id: number | string, entity: DataEntity, entityObservable: Observable): Observable; registerEntityByData(type: string, id: number | string, entityData: EntityDataSet): void; /** * * @param {string} type * @param {DataCollection} collection * @returns {Observable[]} */ private registerCollectionEntities(type, collection); private replaceCollectionEntities(type, collection, filter); /** * Associate an entity suject the the entity in the entity store * @param {string} type Endpoint name * @param {number} id Id of the entity * @param {ReplaySubject} subject Subject to associate */ private registerEntitySubject(type, id, subject); /** * Get observable associated to the collection from the store. If store is undefined, create it * @param {string} type Endpoint name * @param {FilterData} filter Filter object * @param useCache * @returns {Observable} Observable associated to the collection */ private getCollectionObservable(type, filter, useCache?); /** * Register the collection and collection entities in the store * @param {string} type Endpoint name * @param {FilterData} filter Filter object * @param {DataCollection} collection Collection to register * @param {boolean} refresh * @returns {Observable} The observable associated to the collection */ private registerCollection(type, filter, collection, refresh?); private paginatedRegisterCollection(type, filter, collection, refresh?); /** * Authenticate to the service * @param {string} serviceName Name of service on which we authenticate * @param {string} login User login * @param {string} password User password */ authenticate(serviceName: string, login: string, password: string): Observable; /** * * @param {string} serviceName * @returns {Observable} */ authenticated(serviceName: string): Observable; /** * * @returns {Observable} */ logout(serviceName: string): Observable; /** * Release endpoint if not used * @param {string} type Endpoint name */ release(type: string): void; clear(): void; /** * Listen for an endpoint to be notified when data is pushed from the backend * @param {string} type Endpoint name * @returns {Observable} DataEntity observable associated to this entity */ listen(type: string): Observable; /** * Load entity in specified endpoint * @param {string} type Endpoint name * @param {number} id Entity id * @returns {Observable} DataEntity observable associated to this entity */ loadEntity(type: string, id: number | string): Observable; /** * Load many entities * @param {string} type Endpoint name * @param {number[]} ids Entities ids array * @returns {Observable} The data entities */ loadEntities(type: string, ids: number[]): Observable; paginatedLoadCollection(type: string, options: CollectionOptionsInterface): PaginatedCollection; paginatedLoadCollectionExec(type: string, filter: { [key: string]: any; }, paginator: CollectionPaginator): PaginatedCollection; /** * Load collection from specified endpoint * @param {string} type Endpoint name * @param {FilterData} filter Filter object * @returns {Observable} Observable associated to this collection */ loadCollection(type: string, filter?: FilterData): Observable; sendReloadNotification(type: string, data?: Object): void; /** * Save entity * @param {DataEntity} entity Entity to save * @param {boolean} forceReload whether to reload data if nothing is saved or not * @param {boolean} dispatchBeforeResponse register entity before save happens * @returns {Observable} Observable associated to the entity */ saveEntity(entity: DataEntity, forceReload?: boolean, dispatchBeforeResponse?: boolean): Observable; /** * Create entity to the specified endpoint service * @param {string} type Endpoint name * @param {EntityDataSet} data Data used to create the entity * @returns {Observable} The observable associated to this entity */ createEntity(type: string, data?: { [key: string]: any; }, sendNotification?: boolean): Observable; /** * Creates an entity on the front only (will be saved on the server later) * @param {string} type Endpoint type * @param {{[p: string]: any}} data Data used to create the entity * @returns {Observable} The observable associated to this entity */ createTemporaryEntity(type: string, data?: { [key: string]: any; }): Observable; /** * Delete an entity * @param {DataEntity} entity Entity to delete * @returns {Observable} True if deletion success */ deleteEntity(entity: DataEntity): Observable; /** * Delete entity from store * @param {DataEntity} entity Entity to delete */ unregisterEntity(entity: DataEntity): void; /** * * @param {string} type * @param {number | string} id */ unregisterEntityTypeAndId(type: string, id: number | string): void; /** * Refresh entity (from refresh service) * @param {string} type Endpoint name * @param {number} id Entity id */ refreshEntity(type: string, id: number): void; /** * Refresh collection (from refresh service) * @param {string} type Endpoint name * @param {FilterData} filter Collection filter object */ refreshCollection(type: string, filter: FilterData): void; private objectMatchFilter(object, filter); refreshCollectionWithData(type: string, data: Object): void; refreshAllCollectionsOfType(type: string): void; getUnexpectedLogoutSubject(serviceName: string): Subject; }