@geogirafe/lib-geoportal
Version:
GeoGirafe is a flexible application to build online geoportals.
58 lines (57 loc) • 2.72 kB
TypeScript
import GirafeSingleton from '../../base/GirafeSingleton';
/**
* Manages user data storage and retrieval across different storage sources.
* The class supports localStorage and server as storage options (server-side implementation currently not available).
* It provides functionality to set, get, save, and delete user data while maintaining the flexibility to target specific paths
* within the user data object.
*/
declare class UserDataManager extends GirafeSingleton {
private readonly storageKey;
private source?;
private readonly WARNING_UNKNOWN_SOURCE;
private readonly WARNING_NOT_IMPLEMENTED;
setSource(source: string): void;
/**
* Retrieves a specific part of the user data defined by the storage path.
* @param storagePath path in the user data object to the requested value.
* @param forceLocalStorage if true, reads user data from the local storage, ignoring the source.
* @returns the partial user data object.
*/
getUserData(storagePath: string, forceLocalStorage?: boolean): unknown;
/**
* Saves user data to a specific path in the storage.
* @param storagePath path in the user data object where the value is saved to.
* @param newValue user data value to save.
* @param forceLocalStorage if true, saves user data to the local storage, ignoring the source.
*/
saveUserData(storagePath: string, newValue: unknown, forceLocalStorage?: boolean): void;
/**
* Delete a specific part of the user data defined by the storage path.
* @param storagePath path in the user data object that will be deleted.
* @param forceLocalStorage if true, deletes user data in the local storage, ignoring the source.
*/
deleteUserData(storagePath: string, forceLocalStorage?: boolean): void;
/**
* Deletes all user data in storage.
* @param forceLocalStorage Force deletion from local storage regardless of the currently set data source.
*/
deleteAllUserData(forceLocalStorage?: boolean): void;
/**
* Helper: Load data from the user data storage.
* @param forceLocalStorage forces loading data from local storage, independent of the specified source.
* @returns the full user data object in the storage.
*/
private load;
/**
* Helper: Save user data to storage.
* @param fullUserDataObject full user data object that is saved.
* @param forceLocalStorage forces saving data to local storage, independent of the specified source.
* @private
*/
private save;
/**
* Helper: Determines if a particular operation should use the local browser storage.
*/
private isInLocalStorage;
}
export default UserDataManager;