import { Observable, Subject, ReplaySubject } from 'rxjs'; import { ModelSchema } from 'octopus-model'; import * as i0 from '@angular/core'; import { ModuleWithProviders } from '@angular/core'; declare enum OrderDirection { ASC = "asc", DESC = "desc" } interface OrderCriteria { field: string; direction: OrderDirection; } interface CollectionOptionsInterface { filter?: { [key: string]: any; }; page?: number; offset?: number; range?: number; urlExtension?: string; orderOptions?: OrderCriteria[]; } /** * Local storage interface configuration */ interface LocalStorageConfiguration { /** * Optional prefix for indexing in localstorage */ prefix?: string; } /** * Entity raw data */ type EntityDataSet = T & { id?: number; }; /** * Collection raw data */ interface CollectionDataSet { /** * Entities data, indexed by id */ [key: number]: EntityDataSet; } /** * Filter object */ interface FilterData { /** * Filter properties, indexed by string key name */ [key: string]: any; } /** * Base external interface */ declare abstract class ExternalInterface { get authenticated(): Observable>; unexpectedLogoutSubject: Subject; /** * if true, the save method will only send the modified properties to the service */ useDiff: boolean; retryTimeout: number; maxRetry: number; /** * Load an entity from the service * @param type Name of the endpoint * @param id Id of the entity * @param errorHandler Function used to handle errors * @returns A set of data, or an observable */ loadEntity(type: string, id: number | string, errorHandler?: Function): EntityDataSet | Observable>; /** * Load an entity collection from the service * @param type Name of the endpoint * @param filter Collection filter object * @param errorHandler Function used to handle errors * @returns A collection set of data, or an observable */ loadCollection(type: string, filter: FilterData, errorHandler?: Function): CollectionDataSet | Observable>; /** * */ clear(): void; paginatedLoadCollection(type: string, options: CollectionOptionsInterface, paginator: CollectionPaginator, errorHandler?: Function): CollectionDataSet | Observable>; /** * Create an entity on the service * @param type Endpoint name * @param data Base data used to create the entity * @param errorHandler Function used to handle errors * @returns A set of data, or an observable */ createEntity(type: string, data: EntityDataSet, errorHandler?: Function): EntityDataSet | Observable>; /** * Delete an entity from the service * @param type Name of the endpoint * @param id Id of the entity * @param errorHandler Function used to handle errors * @returns True if deletion success */ deleteEntity(type: string, id: number | string, errorHandler?: Function): boolean | Observable; /** * Save an entity on the service * @param data Data to Save * @param type Name of the endpoint * @param id Id of the entity * @param errorHandler Function used to handle errors * @returns The saved data */ saveEntity(data: EntityDataSet, type: string, id: number | string, errorHandler?: Function): EntityDataSet | Observable>; /** * Authenticating to the service * @param login User login * @param password User password * @param errorHandler Function used to handle errors */ authenticate(login: string, password: string, errorHandler?: Function): Observable>; logout(): Observable; /** * Release an endpoint if not useful anymore * @param type Name of the endpoint */ release(type: string): void; /** * Sends an error message * @param code Error code * @param originalMessage Error original text message * @param errorHandler Error handler Function */ sendError(code: number, originalMessage: string, errorHandler: Function, data?: Object): void; } interface HttpEndpointConfiguration { apiUrl?: string; } /** * Individual endpoint config */ interface EndpointConfig { /** * Service used by this endpoint */ type: string; /** * Model structure associated to this endpoint */ structure?: ModelSchema; /** * Does the endpoint use the connector cache ? */ cached?: boolean; /** * */ useLanguage?: boolean; /** * List of data attributes keys excluded in save and create actions, used in some services */ exclusions?: string[]; /** * List of nested attributes: key is attributeName, value is endpoint name */ nesting?: { [key: string]: string; }; /** * */ embeddings?: { [key: string]: string; }; /** * Optional data */ datas?: HttpEndpointConfiguration; /** * Is automatic refresh enabled */ refreshEnabled?: boolean; /** * If true, no authentication data need on this endpoint */ authenticationFree?: boolean; } /** * Http interface configuration */ interface HttpConfiguration { /** * Base url of the api */ apiUrl: string | Function; /** * List of header which will be sent with the requests */ headers?: { [key: string]: string; }; /** * */ useApiExtension?: boolean; } interface NodejsConfiguration { socketUrl: string; messagePrefix?: string; retrievePrefix?: string; connectionCommand?: string; } /** * Drupal8 interface configuration */ interface Drupal8Configuration { /** * Base url of the api */ apiUrl: string | Function; /** * List of header which will be sent with the requests */ headers?: { [key: string]: string; }; clientId: string; clientSecret?: string; scope?: string; } interface CordovaLocalConfiguration { } /** * Connector main configuration */ interface DataConnectorConfig { /** * Interface used when no interface name specified for an endpoint */ defaultInterface: string; language?: string | Observable; /** * Delay before action retry */ retryTimeout?: number; /** * Max attempts number */ maxRetry?: number; /** * Base configurations for each service type */ configuration: { [key: string]: HttpConfiguration | LocalStorageConfiguration | NodejsConfiguration | Drupal8Configuration | CordovaLocalConfiguration; }; declarations?: { [key: string]: string; }; /** * Individual endpoint configuration */ map?: { [key: string]: string | EndpointConfig; }; interfaces?: { [key: string]: ExternalInterface; }; globalCallback?: Function; liveRefreshService?: string; } /** * Data entity unit object */ declare class DataEntity { type: string; private connector; id: number | string; private embeddingsConf; /** * Entity attributes */ attributes: T; /** * Nested entities */ nesting: T; relationship: { [key: string]: DataEntity; }; /** * Reference object for diff */ private attributesRef; /** * */ private embeddings; /** * Create the data entity * @param type Type of the entity * @param data Entity data * @param connector Reference to the connector * @param id Entity id * @param embeddingsConf Embeddings configuration */ constructor(type: string, data: EntityDataSet<{ [key: string]: any; }>, connector?: DataConnector, id?: number | string, embeddingsConf?: { [key: string]: string; }); /** * Set an attribute by key * @param key Key name * @param value New value */ set(key: keyof (T | U), value: any): void; /** * Get an attribute by key * @param key Key name * @returns Value */ get(key: U): T[U]; get hasChanges(): boolean; getEmbed>(name: string): V | V[]; /** * Save the entity * @returns The observable associated to the entity in connector stores */ save(forceReload?: boolean, dispatchBeforeResponse?: boolean): Observable>; saveAction(forceReload?: boolean, dispatchBeforeResponse?: boolean): Observable>; /** * Delete the entity * @returns True if deletion success */ remove(): Observable; /** * Copy the attributes to generate the new reference object (for diff) */ private generateReferenceObject; /** * Get an attributes cloned object * @returns The cloned attributes object */ getClone(): EntityDataSet; /** * Return the diff (only updated properties since last save action) * @returns Diff object */ getDiff(): EntityDataSet; } /** * Data collection object */ declare class DataCollection { type: string; private connector; paginated: boolean; count: number; /** * Entities contained by the collection */ entities: DataEntity[]; /** * Observables of entities contained by the collection */ entitiesObservables: Observable>[]; /** * Creates the collection */ constructor(type: string, data: CollectionDataSet | EntityDataSet[], connector?: DataConnector, structure?: ModelSchema, embeddings?: { [key: string]: string; }); /** * Remove entity from collection * @param id Id of the entity to delete */ deleteEntity(id: number | string): void; /** * Register entity in collection, if not already contained by the collection * @param entity Entity to register * @param entityObservable Entity observable to register */ registerEntity(entity: DataEntity, entityObservable: Observable>): void; } declare class InterfaceError { code: number; message: string; originalMessage: string; data: Object; constructor(code?: number, message?: string, originalMessage?: string, data?: Object); } interface PaginatedCollection { collectionObservable: Observable>; paginator: CollectionPaginator; } /** * Data connector class */ 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 */ private builtInFactories; globalMessageSubject: ReplaySubject; /** * Delay before action retry */ private retryTimeout; /** * Max attempts number */ private maxRetry; /** * Create a dataConnector * @param configuration Data connector configuration */ constructor(configuration: DataConnectorConfig); private sendMessage; getRetryTimeout(type: string): number; getMaxRetry(type: string): number; setLanguage(language: string): void; globalCallback(code: number): void; /** * Get data interface by endpoint name * @param type Endpoint name * @returns External interface */ private getInterface; /** * Get endpoint configuration * @param type Endpoint name * @returns Type of the endpoint, or endpoint configuration object */ getEndpointConfiguration(type: string): string | EndpointConfig; /** * Get model schema used by the endpoint * @param type Endpoint name * @returns The model schema */ private getEndpointStructureModel; /** * Get nesting attributes types * @param type Endpoint name * @returns The nested attributes types */ private getNesting; private getDatas; private getEmbeddings; /** * Is this endpoint using connector cache * @param type Name of the endpoint * @returns True if the endpoint use cache */ private useCache; /** * Get optional keys excluded for saving entities in this endpoint * @param type Endpoint name * @returns A list of string keys */ private getExclusions; /** * Get the observable associated to an entity from the store * @param type Endpoint name * @param id Id of the entity * @returns The observable associated to the entity */ private getEntityObservableInStore; /** * Get the observable associated to the collection from the store * @param type Endpoint name * @param filter Filter object * @param useCache Store the result in cache or retrieve it from cache * @param createIfNotExisted Create the observable if not existed * @returns The observable associated to the collection */ private getCollectionObservableInStore; /** * Get the observable associated to an entity from the store, if the store is undefined, create it * @param type Endpoint name * @param id Id of the entity * @param createObservable * @returns The observable associated to the entity */ private getEntitySubject; /** * Register entity in the stores * @param type Endpoint name * @param id Id of the entity * @param entity Entity * @param entityObservable Observable to register * @returns 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; private registerCollectionEntities; private replaceCollectionEntities; /** * Associate an entity suject the the entity in the entity store * @param type Endpoint name * @param id Id of the entity * @param subject Subject to associate */ private registerEntitySubject; /** * Get observable associated to the collection from the store. If store is undefined, create it * @param type Endpoint name * @param filter Filter object * @param useCache * @returns Observable associated to the collection */ private getCollectionObservable; /** * Register the collection and collection entities in the store * @param type Endpoint name * @param filter Filter object * @param collection Collection to register * @param refresh * @returns The observable associated to the collection */ private registerCollection; private paginatedRegisterCollection; /** * Authenticate to the service * @param serviceName Name of service on which we authenticate * @param login User login * @param password User password */ authenticate(serviceName: string, login: string, password: string): Observable>; authenticated(serviceName: string): Observable>; logout(serviceName: string): Observable; /** * Release endpoint if not used * @param type Endpoint name */ release(type: string): void; clear(): void; /** * Listen for an endpoint to be notified when data is pushed from the backend * @param type Endpoint name * @returns DataEntity observable associated to this entity */ listen(type: string): Observable>; /** * Load entity in specified endpoint * @param type Endpoint name * @param id Entity id * @returns DataEntity observable associated to this entity */ loadEntity(type: string, id: number | string): Observable>; /** * Load many entities * @param type Endpoint name * @param ids Entities ids array * @returns 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 type Endpoint name * @param filter Filter object * @returns Observable associated to this collection */ loadCollection(type: string, filter?: FilterData): Observable>; sendReloadNotification(type: string, data?: Object): void; /** * Save entity * @param entity Entity to save * @param forceReload whether to reload data if nothing is saved or not * @param dispatchBeforeResponse register entity before save happens * @returns Observable associated to the entity */ saveEntity(entity: DataEntity, forceReload?: boolean, dispatchBeforeResponse?: boolean): Observable>; /** * Create entity to the specified endpoint service * @param type Endpoint name * @param data Data used to create the entity * @returns The observable associated to this entity */ createEntity(type: string, data?: any, sendNotification?: boolean): Observable>; /** * Creates an entity on the front only (will be saved on the server later) * @param type Endpoint type * @param data Data used to create the entity * @returns The observable associated to this entity */ createTemporaryEntity(type: string, data?: EntityDataSet): Observable>; /** * Delete an entity * @param entity Entity to delete * @returns True if deletion success */ deleteEntity(entity: DataEntity): Observable; /** * Delete entity from store * @param entity Entity to delete */ unregisterEntity(entity: DataEntity): void; unregisterEntityTypeAndId(type: string, id: number | string): void; /** * Refresh entity (from refresh service) * @param type Endpoint name * @param id Entity id */ refreshEntity(type: string, id: number): void; /** * Refresh collection (from refresh service) * @param type Endpoint name * @param filter Collection filter object */ refreshCollection(type: string, filter: FilterData): void; private objectMatchFilter; refreshCollectionWithData(type: string, data: Object): void; refreshAllCollectionsOfType(type: string): void; getUnexpectedLogoutSubject(serviceName: string): Subject; } declare class CollectionPaginator { private connector; private type; private options; mfilter: { [key: string]: any; }; private _page; private _offset; private _range; private _urlExtension; private _orderOptions; private _filter; count: number; hasNextPage: boolean; hasPreviousPage: boolean; constructor(connector: DataConnector, type: string, options: CollectionOptionsInterface, mfilter: { [key: string]: any; }); get filter(): { [key: string]: any; }; set filter(value: { [key: string]: any; }); get page(): number; set page(value: number); get offset(): number; set offset(value: number); get range(): number; set range(value: number); get urlExtension(): string; set urlExtension(value: string); get orderOptions(): OrderCriteria[]; set orderOptions(value: OrderCriteria[]); updateCount(count: number): Promise; reload(): void; } declare class OctopusConnectModule { static forRoot(configuration: DataConnectorConfig): ModuleWithProviders; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵmod: i0.ɵɵNgModuleDeclaration; static ɵinj: i0.ɵɵInjectorDeclaration; } declare class ConfigurationProvider { configuration: DataConnectorConfig; constructor(configuration: DataConnectorConfig); static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } declare class OctopusConnectService extends DataConnector { configurationProvider: ConfigurationProvider; constructor(configurationProvider: ConfigurationProvider); static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } export { CollectionPaginator, DataCollection, DataConnector, DataEntity, ExternalInterface, InterfaceError, OctopusConnectModule, OctopusConnectService, OrderDirection }; export type { CollectionDataSet, CollectionOptionsInterface, DataConnectorConfig, EntityDataSet, FilterData, OrderCriteria, PaginatedCollection };