/** * BooleanValueStorageWrapper provides a type-safe wrapper for storing and retrieving boolean values. * This class implements the StorageWrapper interface specifically for boolean values, * automatically handling string conversion for storage compatibility. * Uses '1' for true and '0' for false to minimize storage usage. */ export declare class BooleanValueStorageWrapper implements StorageWrapper { private storage; private key; /** * Creates a new instance of BooleanValueStorageWrapper. * @param {Storage} storage - The underlying storage implementation to use * @param {string} key - The key under which the boolean value will be stored */ constructor(storage: Storage_2, key: string); /** * Finds a boolean value from storage. * @returns {Promise} A promise that resolves to the stored boolean value or undefined if not found * @throws {Error} If there's an error accessing the storage */ find(): Promise; /** * Retrieves a boolean value from storage. * Unlike find(), this method throws an error if no value is found. * * @returns {Promise} A promise that resolves to the stored boolean value * @throws {Error} If no value is found or if there's an error accessing the storage */ retrieve(): Promise; /** * Saves a boolean value to storage. * Converts the boolean to '1' for true and '0' for false to minimize storage usage. * * @param {boolean} value - The boolean value to store * @returns {Promise} A promise that resolves when the value has been saved * @throws {Error} If there's an error saving to storage */ save(value: boolean): Promise; /** * Removes a boolean value from storage. * @returns {Promise} A promise that resolves when the value has been removed * @throws {Error} If there's an error removing from storage */ remove(): Promise; } /** * Type definition for comparing two items of type T. * @template T - The type of items to compare * @param itemA - The first item to compare * @param itemB - The second item to compare * @returns A number indicating the comparison result: * - Negative if itemA < itemB * - Zero if itemA === itemB * - Positive if itemA > itemB */ export declare type CompareItem = (itemA: T, itemB: T) => number; /** * DateValueStorageWrapper provides a type-safe wrapper for storing and retrieving Date values. * This class implements the StorageWrapper interface specifically for Date values, * automatically handling conversion between Date and number (timestamp) for storage compatibility. * Uses getTime() to store dates as numbers to minimize storage usage and avoid parsing overhead. */ export declare class DateValueStorageWrapper implements StorageWrapper { private storage; private key; /** * Creates a new instance of DateValueStorageWrapper. * @param {Storage} storage - The underlying storage implementation to use * @param {string} key - The key under which the Date value will be stored */ constructor(storage: Storage_2, key: string); /** * Finds a Date value from storage. * @returns {Promise} A promise that resolves to the stored Date value or undefined if not found * @throws {Error} If there's an error accessing the storage */ find(): Promise; /** * Retrieves a Date value from storage. * Unlike find(), this method throws an error if no value is found. * * @returns {Promise} A promise that resolves to the stored Date value * @throws {Error} If no value is found or if there's an error accessing the storage */ retrieve(): Promise; /** * Saves a Date value to storage. * Converts the Date to a timestamp (number) before saving to ensure compatibility with storage. * * @param {Date} value - The Date value to store * @returns {Promise} A promise that resolves when the value has been saved * @throws {Error} If there's an error saving to storage */ save(value: Date): Promise; /** * Removes a Date value from storage. * @returns {Promise} A promise that resolves when the value has been removed * @throws {Error} If there's an error removing from storage */ remove(): Promise; } /** * Type definition for filtering items of type T. * @template T - The type of items to filter * @param item - The item to evaluate * @returns true if the item should be included, false otherwise */ export declare type FilterItem = (item: T) => boolean; /** * JsonValuesStorageWrapper provides a type-safe wrapper for storing and retrieving arrays of JSON values. * This class extends JsonValueStorageWrapper to handle arrays of items, providing additional methods * for managing collections of data with filtering, sorting, and item manipulation capabilities. * * @template T - The type of items stored in the array * * @example * ```typescript * interface User { * id: number; * name: string; * } * * const storage = new WebRegularStorage(); * const compareItem: CompareItem = (a, b) => a.id.localeCompare(b.id); * const usersStorage = new JsonValuesStorageWrapper(storage, 'users', compareItem); * * const user = { id: 1, name: 'John' }; * * // Add a new user * await usersStorage.addItem(user); * * // Update a user * user.name = 'John Doe'; * await usersStorage.updateItem(user); * * // Remove a user * await usersStorage.removeItem(user); * * // Get all users * const users = await usersStorage.find(); * * // Filter users * const activeUsers = await usersStorage.getItemsByFilter(user => user.active); * * // Sort users by name * const sortedUsers = await usersStorage.sortItems((a, b) => a.name.localeCompare(b.name)); * ``` */ export declare class JsonValuesStorageWrapper extends JsonValueStorageWrapper_2 { protected compareItem: CompareItem; /** * Creates a new instance of JsonValuesStorageWrapper. * @param storage - The underlying storage implementation to use * @param key - The key under which the array of values will be stored * @param compareItem - The comparison function to use for sorting and filtering */ constructor(storage: Storage_3, key: string, compareItem: CompareItem); /** * Adds a new item to the stored array. * If no array exists, creates a new array with the item. * * @param item - The item to add to the array * @returns A promise that resolves when the item has been added */ addItem(item: T): Promise; /** * Adds multiple items to the stored array. * If no array exists, creates a new array with the items. * * @param items - The items to add to the array * @returns A promise that resolves when the items have been added */ addItems(items: T[]): Promise; /** * Updates an existing item in the stored array. * This method uses the provided comparison function to identify the item to update. * * @param item - The updated item to save * @returns A promise that resolves when the item has been updated * @throws {Error} If the item is not found or if there's an error accessing the storage */ updateItem(item: T): Promise; /** * Updates existing items in the stored array. * This method iterates through the current items in storage and updates them if a match is found in the provided items array. * The comparison function is used to identify items that need to be updated. * * @param items - The items to update in the array. These items will replace existing items in storage if a match is found. * @returns A promise that resolves when the items have been updated in storage. * @throws {Error} If there's an error accessing the storage, such as a failure to read or write data. */ updateItems(items: T[]): Promise; /** * Removes an item from the stored array. * This method uses the class's internal comparison function to identify the item to remove. * * @param item - The item to remove from the array * @returns A promise that resolves when the item has been removed * @throws {Error} If the item is not found or if there's an error accessing the storage */ removeItem(item: T): Promise; /** * Removes items from the stored array. * This method iterates through the provided items array and removes each item from the stored array if a match is found using the class's internal comparison function. * * @param items - The items to remove from the array * @returns A promise that resolves when the items have been removed * @throws {Error} If there's an error accessing the storage */ removeItems(items: T[]): Promise; /** * Retrieves items from the stored array that match the provided filter. * * @param filterItem - Function to filter items * @returns A promise that resolves to an array of items matching the filter * @throws {Error} If there's an error accessing the storage */ getItemsByFilter(filterItem: FilterItem): Promise; /** * Sorts the stored array using the provided comparison function. * Returns a new sorted array without modifying the stored array. * * @param compareItem - Function to compare items for sorting * @returns A promise that resolves to a sorted array of items * @throws {Error} If there's an error accessing the storage */ sortItems(compareItem?: CompareItem): Promise; } /** * JsonValueStorageWrapper provides a type-safe wrapper for storing and retrieving JSON values. * This class implements the StorageWrapper interface specifically for JSON data, * automatically handling JSON serialization/deserialization for storage compatibility. */ export declare class JsonValueStorageWrapper implements StorageWrapper { private storage; private key; /** * Creates a new instance of JsonValueStorageWrapper. * @param {Storage} storage - The underlying storage implementation to use * @param {string} key - The key under which the JSON value will be stored */ constructor(storage: Storage_2, key: string); /** * Finds a JSON value from storage. * @returns {Promise} A promise that resolves to the stored JSON value or undefined if not found * @throws {Error} If there's an error accessing the storage or parsing the JSON */ find(): Promise; /** * Retrieves a JSON value from storage. * Unlike find(), this method throws an error if no value is found. * * @returns {Promise} A promise that resolves to the stored JSON value * @throws {Error} If no value is found, if there's an error accessing the storage, or if parsing fails */ retrieve(): Promise; /** * Saves a JSON value to storage. * Converts the value to a JSON string before saving to ensure compatibility with storage. * * @param {T} value - The JSON value to store * @returns {Promise} A promise that resolves when the value has been saved * @throws {Error} If there's an error saving to storage or if serialization fails */ save(value: T): Promise; /** * Removes a JSON value from storage. * @returns {Promise} A promise that resolves when the value has been removed * @throws {Error} If there's an error removing from storage */ remove(): Promise; } /** * JsonValueStorageWrapper provides a type-safe wrapper for storing and retrieving JSON values. * This class implements the StorageWrapper interface specifically for JSON data, * automatically handling JSON serialization/deserialization for storage compatibility. */ declare class JsonValueStorageWrapper_2 implements StorageWrapper_2 { private storage: Storage_3; private key: string; /** * Creates a new instance of JsonValueStorageWrapper. * @param {Storage} storage - The underlying storage implementation to use * @param {string} key - The key under which the JSON value will be stored */ constructor(storage: Storage_3, key: string) { this.storage = storage; this.key = key; } /** * Finds a JSON value from storage. * @returns {Promise} A promise that resolves to the stored JSON value or undefined if not found * @throws {Error} If there's an error accessing the storage or parsing the JSON */ async find(): Promise { const storedValue = await this.storage.find(this.key); if (storedValue === undefined) { return undefined; } try { return JSON.parse(storedValue) as T; } catch (error) { throw new Error( `Failed to parse JSON for key ${this.key}: ${ error instanceof Error ? error.message : String(error) }`, ); } } /** * Retrieves a JSON value from storage. * Unlike find(), this method throws an error if no value is found. * * @returns {Promise} A promise that resolves to the stored JSON value * @throws {Error} If no value is found, if there's an error accessing the storage, or if parsing fails */ async retrieve(): Promise { const value = await this.find(); if (value === undefined) { throw new Error(`No value found for key ${this.key}`); } return value; } /** * Saves a JSON value to storage. * Converts the value to a JSON string before saving to ensure compatibility with storage. * * @param {T} value - The JSON value to store * @returns {Promise} A promise that resolves when the value has been saved * @throws {Error} If there's an error saving to storage or if serialization fails */ async save(value: T): Promise { try { const jsonString = JSON.stringify(value); return this.storage.save(this.key, jsonString); } catch (error) { throw new Error( `Failed to stringify JSON for key ${this.key}: ${ error instanceof Error ? error.message : String(error) }`, ); } } /** * Removes a JSON value from storage. * @returns {Promise} A promise that resolves when the value has been removed * @throws {Error} If there's an error removing from storage */ async remove(): Promise { return this.storage.remove(this.key); } } /** * NumberValueStorageWrapper provides a type-safe wrapper for storing and retrieving number values. * This class implements the StorageWrapper interface specifically for number values, * automatically handling base64 encoding/decoding for storage compatibility. * */ export declare class NumberValueStorageWrapper implements StorageWrapper { private storage; private key; /** * Creates a new instance of NumberValueStorageWrapper. * @param {Storage} storage - The underlying storage implementation to use * @param {string} key - The key under which the number value will be stored */ constructor(storage: Storage_2, key: string); /** * Finds a number value from storage. * @returns {Promise} A promise that resolves to the stored number value or undefined if not found * @throws {Error} If there's an error accessing the storage */ find(): Promise; /** * Retrieves a number value from storage. * Unlike find(), this method throws an error if no value is found. * * @returns {Promise} A promise that resolves to the stored number value * @throws {Error} If no value is found or if there's an error accessing the storage */ retrieve(): Promise; /** * Saves a number value to storage. * Converts the number to a string before saving to ensure compatibility with storage. * * @param {number} value - The number value to store * @returns {Promise} A promise that resolves when the value has been saved * @throws {Error} If there's an error saving to storage */ save(value: number): Promise; /** * Removes a number value from storage. * @returns {Promise} A promise that resolves when the value has been removed * @throws {Error} If there's an error removing from storage */ remove(): Promise; } /** * Universal Storage interface that works across all platforms (web and native). */ declare interface Storage_2 { /** * Retrieves a value from storage. * * @param key - The key of the item to retrieve. * @returns A promise that resolves to the retrieved value or undefined if not found. */ find: (key: string) => Promise; /** * Saves a value to storage. * * @param key - The key under which the value should be stored. * @param value - The value to store. * @returns A promise that resolves when the value has been saved. */ save: (key: string, value: string) => Promise; /** * Removes a value from storage. * * @param key - The key of the item to remove. * @returns A promise that resolves when the value has been removed. */ remove: (key: string) => Promise; } export { Storage_2 as Storage } /** * Universal Storage interface that works across all platforms (web and native). */ declare interface Storage_3 { /** * Retrieves a value from storage. * * @param key - The key of the item to retrieve. * @returns A promise that resolves to the retrieved value or undefined if not found. */ find: (key: string) => Promise; /** * Saves a value to storage. * * @param key - The key under which the value should be stored. * @param value - The value to store. * @returns A promise that resolves when the value has been saved. */ save: (key: string, value: string) => Promise; /** * Removes a value from storage. * * @param key - The key of the item to remove. * @returns A promise that resolves when the value has been removed. */ remove: (key: string) => Promise; } /** * StorageWrapper provides a type-safe wrapper around storage operations for a specific key. * This interface abstracts the storage operations and provides a more convenient API * for working with typed data in storage. * * @template T - The type of data being stored and retrieved * * @example * ```typescript * const userStorage = new StorageWrapper(storage, 'user-key'); * await userStorage.save({ id: 1, name: 'John' }); * const user = await userStorage.find(); * ``` */ export declare interface StorageWrapper { /** * Finds a value from storage. * @returns {Promise} A promise that resolves to the stored value or undefined if not found * @throws {Error} If there's an error accessing the storage */ find(): Promise; /** * Retrieves a value from storage. * Unlike find(), this method throws an error if no value is found. * * @returns {Promise} A promise that resolves to the stored value * @throws {Error} If no value is found or if there's an error accessing the storage */ retrieve(): Promise; /** * Saves a value to storage. * @param {T} value - The value to store * @returns {Promise} A promise that resolves when the value has been saved * @throws {Error} If there's an error saving to storage */ save(value: T): Promise; /** * Removes a value from storage. * @returns {Promise} A promise that resolves when the value has been removed * @throws {Error} If there's an error removing from storage */ remove(): Promise; } /** * StorageWrapper provides a type-safe wrapper around storage operations for a specific key. * This interface abstracts the storage operations and provides a more convenient API * for working with typed data in storage. * * @template T - The type of data being stored and retrieved * * @example * ```typescript * const userStorage = new StorageWrapper(storage, 'user-key'); * await userStorage.save({ id: 1, name: 'John' }); * const user = await userStorage.find(); * ``` */ declare interface StorageWrapper_2 { /** * Finds a value from storage. * @returns {Promise} A promise that resolves to the stored value or undefined if not found * @throws {Error} If there's an error accessing the storage */ find(): Promise; /** * Retrieves a value from storage. * Unlike find(), this method throws an error if no value is found. * * @returns {Promise} A promise that resolves to the stored value * @throws {Error} If no value is found or if there's an error accessing the storage */ retrieve(): Promise; /** * Saves a value to storage. * @param {T} value - The value to store * @returns {Promise} A promise that resolves when the value has been saved * @throws {Error} If there's an error saving to storage */ save(value: T): Promise; /** * Removes a value from storage. * @returns {Promise} A promise that resolves when the value has been removed * @throws {Error} If there's an error removing from storage */ remove(): Promise; } /** * StringValueStorageWrapper provides a type-safe wrapper for storing and retrieving string values. * This class implements the StorageWrapper interface specifically for string values, * providing a convenient API for working with string data in storage. * * @template T - The specific string type to store. Must extend string. * @example * ```typescript * const storage = new WebRegularStorage(); * const userTokenStorage = new StringValueStorageWrapper(storage, 'user-token'); * await userTokenStorage.save('abc123'); * const token = await userTokenStorage.retrieve(); * ``` * * @example * ```typescript * // Using with a specific string type * type UserRole = 'admin' | 'user' | 'guest'; * const roleStorage = new StringValueStorageWrapper(storage, 'user-role'); * await roleStorage.save('admin'); // Type-safe: only 'admin', 'user', or 'guest' allowed * const role = await roleStorage.retrieve(); // Type is UserRole * ``` */ export declare class StringValueStorageWrapper implements StorageWrapper { protected storage: Storage_2; protected key: string; /** * Creates a new instance of StringValueStorageWrapper. * @param {Storage} storage - The underlying storage implementation to use * @param {string} key - The key under which the string value will be stored */ constructor(storage: Storage_2, key: string); /** * Finds a string value from storage. * @returns {Promise} A promise that resolves to the stored string value or undefined if not found * @throws {Error} If there's an error accessing the storage */ find(): Promise; /** * Retrieves a string value from storage. * Unlike find(), this method throws an error if no value is found. * * @returns {Promise} A promise that resolves to the stored string value * @throws {Error} If no value is found or if there's an error accessing the storage */ retrieve(): Promise; /** * Saves a string value to storage. * @param {T} value - The string value to store * @returns {Promise} A promise that resolves when the value has been saved * @throws {Error} If there's an error saving to storage */ save(value: T): Promise; /** * Removes a string value from storage. * @returns {Promise} A promise that resolves when the value has been removed * @throws {Error} If there's an error removing from storage */ remove(): Promise; } /** * Uint8ArrayValueStorageWrapper provides a type-safe wrapper for storing and retrieving binary data. * This class implements the StorageWrapper interface specifically for Uint8Array values, * automatically handling base64 encoding/decoding for storage compatibility. * * @example * ```typescript * const storage = new WebRegularStorage(); * const binaryStorage = new Uint8ArrayValueStorageWrapper(storage, 'binary-data'); * const data = new Uint8Array([1, 2, 3, 4, 5]); * await binaryStorage.save(data); * const retrievedData = await binaryStorage.retrieve(); * ``` */ export declare class Uint8ArrayValueStorageWrapper implements StorageWrapper { private storage; private key; /** * Creates a new instance of Uint8ArrayValueStorageWrapper. * @param {Storage} storage - The underlying storage implementation to use * @param {string} key - The key under which the binary data will be stored */ constructor(storage: Storage_2, key: string); /** * Finds binary data from storage. * Automatically decodes the stored base64 string back to Uint8Array. * * @returns {Promise} A promise that resolves to the stored binary data or undefined if not found * @throws {Error} If there's an error accessing the storage or decoding the data */ find(): Promise; /** * Retrieves binary data from storage. * Unlike find(), this method throws an error if no value is found. * Automatically decodes the stored base64 string back to Uint8Array. * * @returns {Promise} A promise that resolves to the stored binary data * @throws {Error} If no value is found or if there's an error accessing/decoding the storage */ retrieve(): Promise; /** * Saves binary data to storage. * Automatically encodes the Uint8Array to base64 for storage. * * @param {Uint8Array} value - The binary data to store * @returns {Promise} A promise that resolves when the value has been saved * @throws {Error} If there's an error saving to storage or encoding the data */ save(value: Uint8Array): Promise; /** * Removes binary data from storage. * @returns {Promise} A promise that resolves when the value has been removed * @throws {Error} If there's an error removing from storage */ remove(): Promise; } export { }