import { Observable, Subscription } from 'rxjs'; import { ChangeRecord, DataCompartmentState } from './Compartments'; import { DataCompartmentOptions, IDataCompartment } from './Compartments'; import { DataStoreToken } from './DataStoreToken'; /** * Represents an individual compartment of data that exposes lifecycle and observable functions to interact * with the cached value(s). */ export declare class DataCompartment implements IDataCompartment { private readonly initialized; private readonly loading; private readonly lastLoaded; private readonly latch; private readonly value; private readonly systemClock; private readonly appCache; private readonly policies; /** * The options used to configure the compartment. */ readonly options: DataCompartmentOptions; /** * The unique identifier of the compartment. */ readonly token: DataStoreToken; /** * Constructs a new instance of DataCompartment. * @param key The identifier of the compartment. * @param options The options used to configured the behavior of the compartment. * @returns A new instance of DataCompartment. */ constructor(token: DataStoreToken, options: DataCompartmentOptions); /** * Initializes the compartment. */ private initialize; private load; /** * Provides an observable that emits true when initialization is complete. * @returns An observable that emits true when initialization is complete. */ get initialized$(): Observable; /** * Provides an observable that emits true when the compartment is loading. * @returns An observable that emits true when initialization is complete. */ get loading$(): Observable; /** * Provides an observable that emits a timestamp when the compartment was last loaded. */ get lastLoaded$(): Observable; /** * Provides an observable that emits the value resolved from the configured source. * This will also emit when the value is modified via mutations, resetting the compartment, and reloading the compartment. */ get value$(): Observable; /** * Attempts to update the cached value (if the comparer detects an update). * @param value The value to store and emit. */ next(value: Model): void; /** * The unique identifier of the compartment. */ get key(): string; get isExpired(): boolean; setData(value: never): void; getData(): unknown; shouldPublish(previous: Model, current: Model): boolean; getCompartmentState(): DataCompartmentState; /** * Reloads the compartment. * Note: This triggers the `reload` event. */ reload(): Promise; /** * Resets the compartment to the default value. * If a retention policy was configured, this will also bust the token. */ reset(): Promise; addEventListener(type: EventType, listener: CompartmentEventListener): Subscription; } export type ChangeEvent = ChangeRecord; export type InitializedEvent = { value: any; }; export type ResetEvent = { value: any; }; export type CompartmentEvent = ChangeEvent | InitializedEvent | ResetEvent; export type EventType = 'change' | 'initialized' | 'reset'; export type EventEnvelope = { type: EventType; timestamp: number; details: CompartmentEvent; }; export type CompartmentEventListener = (envelope: EventEnvelope) => void; export declare function createEventEnvelope(type: EventType, event: CompartmentEvent): EventEnvelope;