/** * DataContext - Centralized data storage management * Refactored to eliminate code duplication using service orchestration */ import type { Logger } from "i45-jslogger"; import { SampleData } from "i45-sample-data"; import { StorageLocations, type StorageLocation } from "../models/storageLocations.js"; import type { DataContextConfig } from "../models/DataContextConfig.js"; /** * Export dependencies for use in consuming modules */ export { SampleData, StorageLocations }; export type { Logger }; /** * DataContext - Service provider for managing data storage across multiple storage types * * @class DataContext * @template T - The type of items stored in the context * * @property {string} storageKey - The key used to store data (defaults to "Items") * @property {StorageLocation} storageLocation - The storage location (localStorage or sessionStorage) * @property {boolean} loggingEnabled - Enable/disable logging * @property {Logger | null} logger - Logger instance for logging events and errors * * @example * // Basic usage with defaults * const context = new DataContext(); * await context.store([{ id: 1, name: "Item 1" }]); * const items = await context.retrieve(); * * @example * // Custom configuration * const context = new DataContext({ * storageKey: "MyData", * storageLocation: StorageLocations.SessionStorage, * loggingEnabled: true, * logger: new Logger() * }); */ export declare class DataContext { #private; /** * Creates a new DataContext instance * * @param config - Configuration options or storage key (for backward compatibility) * @param storageLocation - Storage location (for backward compatibility) * * @example * // New config object approach (recommended) * const context = new DataContext({ * storageKey: "Items", * storageLocation: StorageLocations.LocalStorage, * loggingEnabled: true * }); * * @example * // Legacy parameter approach (maintained for backward compatibility) * const context = new DataContext("Items", StorageLocations.LocalStorage); */ constructor(config?: string | DataContextConfig, storageLocation?: StorageLocation); /** * Gets whether logging is enabled */ get loggingEnabled(): boolean; /** * Sets whether logging is enabled */ set loggingEnabled(value: boolean); /** * Gets the logger instance */ get logger(): Logger | null; /** * Sets the logger instance */ set logger(value: Logger | null); /** * Gets the storage key */ get storageKey(): string; /** * Sets the storage key */ set storageKey(value: string); /** * Gets the storage location */ get storageLocation(): StorageLocation; /** * Sets the storage location */ set storageLocation(value: StorageLocation); /** * Gets the current DataContext settings * * @returns Current storage key and location */ getCurrentSettings(): { storageKey: string; storageLocation: StorageLocation; }; /** * Gets a copy of the current data stores log * * @returns Copy of data stores array */ getData(): any[]; /** * Prints the logger's event history * * @returns Array of logged events */ printLog(): any[]; /** * Adds a client to the logger service * * @param client - The client to add to the logger * @returns The current DataContext instance */ addClient(client: any): this; /** * Stores items using default storage key and location * * @param items - Array of items to store * @returns The current DataContext instance * * @example * await context.store([{ id: 1, name: "Item 1" }]); */ store(items: T[]): Promise; /** * Stores items using a custom storage key with default location * * @param storageKey - The key to store items under * @param items - Array of items to store * @returns The current DataContext instance * * @example * await context.storeAs("CustomKey", [{ id: 1 }]); */ storeAs(storageKey: string, items: T[]): Promise; /** * Stores items using a custom storage key and location * * @param storageKey - The key to store items under * @param storageLocation - The storage location * @param items - Array of items to store * @returns The current DataContext instance * * @example * await context.storeAt("Key", StorageLocations.SessionStorage, [{ id: 1 }]); */ storeAt(storageKey: string, storageLocation: StorageLocation, items: T[]): Promise; /** * Retrieves items from default storage key and location * * @returns Array of stored items * * @example * const items = await context.retrieve(); */ retrieve(): Promise; /** * Retrieves items from a custom storage key with default location * * @param storageKey - The key to retrieve items from * @returns Array of stored items * * @example * const items = await context.retrieveFrom("CustomKey"); */ retrieveFrom(storageKey: string): Promise; /** * Retrieves items from a custom storage key and location * * @param storageKey - The key to retrieve items from * @param storageLocation - The storage location * @returns Array of stored items * * @example * const items = await context.retrieveAt("Key", StorageLocations.SessionStorage); */ retrieveAt(storageKey: string, storageLocation: StorageLocation): Promise; /** * Removes items from default storage key and location * * @returns The current DataContext instance * * @example * await context.remove(); */ remove(): Promise; /** * Removes items from a custom storage key with default location * * @param storageKey - The key to remove items from * @returns The current DataContext instance * * @example * await context.removeFrom("CustomKey"); */ removeFrom(storageKey: string): Promise; /** * Removes items from a custom storage key and location * * @param storageKey - The key to remove items from * @param storageLocation - The storage location * @returns The current DataContext instance * * @example * await context.removeAt("Key", StorageLocations.SessionStorage); */ removeAt(storageKey: string, storageLocation: StorageLocation): Promise; /** * Clears all data from the default storage location * * @returns The current DataContext instance * * @example * await context.clear(); */ clear(): Promise; } //# sourceMappingURL=DataContext.d.ts.map