import type { Agile } from '../agile'; import { StorageKey } from './storage'; export declare class Persistent { agileInstance: () => Agile; static placeHolderKey: string; config: PersistentConfigInterface; _key: PersistentKey; ready: boolean; isPersisted: boolean; onLoad: ((success: boolean) => void) | undefined; storageKeys: StorageKey[]; /** * A Persistent manages the permanent persistence * of an Agile Class such as the `State Class` in external Storages. * * Note that the Persistent itself is no standalone class * and should be adapted to the Agile Class needs it belongs to. * * @internal * @param agileInstance - Instance of Agile the Persistent belongs to. * @param config - Configuration object */ constructor(agileInstance: Agile, config?: CreatePersistentConfigInterface); /** * Updates the key/name identifier of the Persistent. * * @public * @param value - New key/name identifier. */ set key(value: StorageKey); /** * Returns the key/name identifier of the Persistent. * * @public */ get key(): StorageKey; /** * Updates the key/name identifier of the Persistent. * * @public * @param value - New key/name identifier. */ setKey(value?: StorageKey): Promise; /** * Instantiates the Persistent by assigning the specified Storage keys to it * and validating it to make sure everything was setup correctly. * * This was moved out of the `constructor()` * because some classes (that extend the Persistent) need to configure some * things before they can properly instantiate the parent Persistent. * * @internal * @param config - Configuration object */ instantiatePersistent(config?: InstantiatePersistentConfigInterface): void; /** * Returns a boolean indicating whether the Persistent was setup correctly * and is able to persist a value permanently in an external Storage. * * Based on the tapped boolean value, * the Persistent's `ready` property is updated. * * @internal */ validatePersistent(): boolean; /** * Assigns the specified Storage identifiers to the Persistent * and extracts the default Storage if necessary. * * When no Storage key was provided the default Storage * of the Agile Instance is applied to the Persistent. * * @internal * @param storageKeys - Key/Name identifier of the Storages to be assigned. * @param defaultStorageKey - Key/Name identifier of the default Storage. */ assignStorageKeys(storageKeys?: StorageKey[], defaultStorageKey?: StorageKey): void; /** * Stores or loads the Persistent value * from the external Storages for the first time. * * @internal */ initialLoading(): Promise; /** * Loads the Persistent value from the corresponding Storage. * * Note that this method should be overwritten * to correctly apply the changes to the Agile Class * the Persistent belongs to. * * @internal * @param storageItemKey - Storage key of the to load value. * | default = Persistent.key | * @return Whether the loading of the persisted value was successful. */ loadPersistedValue(storageItemKey?: PersistentKey): Promise; /** * Persists the Persistent value in the corresponding Storage. * * Note that this method should be overwritten * to correctly apply the changes to the Agile Class * the Persistent belongs to. * * @internal * @param storageItemKey - Storage key of the to persist value * | default = Persistent.key | * @return Whether the persisting of the value was successful. */ persistValue(storageItemKey?: PersistentKey): Promise; /** * Removes the Persistent value from the corresponding Storage. * -> Persistent value is no longer persisted * * Note that this method should be overwritten * to correctly apply the changes to the Agile Class * the Persistent belongs to. * * @internal * @param storageItemKey - Storage key of the to remove value. * | default = Persistent.key | * @return Whether the removal of the persisted value was successful. */ removePersistedValue(storageItemKey?: PersistentKey): Promise; /** * Formats the specified key so that it can be used as a valid Storage key * and returns the formatted variant of it. * * Note that this method should be overwritten * to correctly apply the changes to the Agile Class * the Persistent belongs to. * * @internal * @param key - Storage key to be formatted. */ formatKey(key?: PersistentKey): PersistentKey | undefined; } export declare type PersistentKey = string | number; export interface CreatePersistentConfigInterface { /** * Key/Name identifier of the Persistent. */ key?: PersistentKey; /** * Key/Name identifier of Storages * in which the Persistent value is to be persisted * or is already persisted. * @default [`defaultStorageKey`] */ storageKeys?: StorageKey[]; /** * Key/Name identifier of the default Storage of the specified Storage keys. * * The persisted value is loaded from the default Storage by default, * since only one persisted value can be applied. * If the loading of the value from the default Storage failed, * an attempt is made to load the value from the remaining Storages. * * @default first index of the specified Storage keys or the Agile Instance's default Storage key */ defaultStorageKey?: StorageKey; /** * Whether the Persistent should load/persist the value immediately * or whether this should be done manually. * @default true */ loadValue?: boolean; } export interface PersistentConfigInterface { /** * Key/Name identifier of the default Storage of the specified Storage keys. * * The persisted value is loaded from the default Storage by default, * since only one persisted value can be applied. * If the loading of the value from the default Storage failed, * an attempt is made to load the value from the remaining Storages. * * @default first index of the specified Storage keys or the Agile Instance's default Storage key */ defaultStorageKey: StorageKey | null; } export interface InstantiatePersistentConfigInterface { /** * Key/Name identifier of the Persistent. */ key?: PersistentKey; /** * Key/Name identifier of Storages * in which the Persistent value is to be persisted * or is already persisted. * @default [`defaultStorageKey`] */ storageKeys?: StorageKey[]; /** * Key/Name identifier of the default Storage of the specified Storage keys. * * The persisted value is loaded from the default Storage by default, * since only one persisted value can be applied. * If the loading of the value from the default Storage failed, * an attempt is made to load the value from the remaining Storages. * * @default first index of the specified Storage keys or the Agile Instance's default Storage key */ defaultStorageKey?: StorageKey; }