import { Observable, Subject } from 'rxjs'; import { Disposable } from '../../data/disposable'; import { LogLevel } from '../../diagnostics/log-level'; import { RxjsLifetimeManager } from '../rxjs-lifetime-manager'; /** * Defines a base class for interchangeable single value data stores * This class is intended to be an abstraction from getting, setting, and clearing a value from a data source. * Unlike a "database" the idea here is that the store is concerned with a single value from an underlying storage mechanism. * This mechanism could a database, a REST API, browser storage, even a variable in memory. The point is to abstract the storage * implementation away from the management of the value */ export declare abstract class DataStore implements Disposable { /** * The source name to use for logging */ protected abstract readonly logSourceName: string; /** * Container for active subscriptions that should be cleaned up in the OnDestroy call. */ protected rxjsLifetime: RxjsLifetimeManager; /** * Observable that emits whenever the data has changed */ readonly dataChanged: Observable; /** * Backing subject for dataChanged property */ protected dataChangedSubject: Subject; /** * Observable that emits whenever the data has been cleared */ readonly dataCleared: Observable; /** * Backing subject for dataCleared property */ protected dataClearedSubject: Subject; /** * Implementation to get the stored data * Called when the consumer wants to retrieve a value from the store. * The result of this method will be processed through the transformFromStore * method before giving the value to the consumer */ protected abstract getData(): Observable; /** * Implementation to set the stored data * Called when the consumer wants to assign a value to the store. * It is called after processing the value through the transformToStore method */ protected abstract setData(data: TStoredData): Observable; /** * Implementation to clear the stored data. * Called when the consumer wants to remove or destroy the data. * This may have slightly different meaning in different contexts, * but is generally different than simply setting the value to null (although that may be effectively the same in some scenarios) * dataCleared will be emitted immediately after this method is executed */ protected abstract clearData(): Observable; /** * Initializes a new instance of DataStore */ constructor(); /** * Shortcut to log a record. The source name is automatically picked up from the class instance * @param message the message of the log record * @param level (optional) the log level (defaults to Debug) * @param params (optional) the parameters to log * @param source (optional) the source of the log message. Defaults to the name of the constructor that instantiated this instance * @return Promise settle to resolve if buffered. */ protected log(message: string, level?: LogLevel, params?: any, source?: string): Promise; /** * Disposes this data store, freeing any resources consumed by this instance */ dispose(): void; /** * Gets the data value from the data store */ get(): Observable; /** * Sets the data value in the data store */ set(data: TData): Observable; /** * clears the data value, effectively removing the value from the backing storage mechanism */ clear(): Observable; /** * Transforms data in preparation for storage. Default behavior is no operation */ protected transformToStore(data: TData): TStoredData; /** * Transforms data in preparation for usage. Default behavior is no operation */ protected transformFromStore(storedData: TStoredData): TData; }