import type { OnyxKey, OnyxValue } from '../../types'; import type { FastMergeReplaceNullPatch } from '../../utils'; type StorageKeyValuePair = [key: OnyxKey, value: OnyxValue, replaceNullPatches?: FastMergeReplaceNullPatch[]]; type StorageKeyList = OnyxKey[]; type DatabaseSize = { bytesUsed: number; bytesRemaining: number; }; type OnStorageKeyChanged = (key: TKey, value: OnyxValue) => void; type StorageProvider = { store: TStore; /** * The name of the provider that can be printed to the logs */ name: string; /** * Initializes the storage provider */ init: () => void; /** * Gets the value of a given key or return `null` if it's not available in storage */ getItem: (key: TKey) => Promise>; /** * Get multiple key-value pairs for the given array of keys in a batch */ multiGet: (keys: StorageKeyList) => Promise; /** * Sets the value for a given key. The only requirement is that the value should be serializable to JSON string */ setItem: (key: TKey, value: OnyxValue) => Promise; /** * Stores multiple key-value pairs in a batch */ multiSet: (pairs: StorageKeyValuePair[]) => Promise; /** * Multiple merging of existing and new values in a batch */ multiMerge: (pairs: StorageKeyValuePair[]) => Promise; /** * Merges an existing value with a new one * @param change - the change to merge with the existing value */ mergeItem: (key: TKey, change: OnyxValue, replaceNullPatches?: FastMergeReplaceNullPatch[]) => Promise; /** * Returns all keys available in storage */ getAllKeys: () => Promise; /** * Returns all key-value pairs from storage in a single batch operation. * More efficient than getAllKeys + multiGet for loading the entire database. */ getAll: () => Promise; /** * Removes given key and its value from storage */ removeItem: (key: OnyxKey) => Promise; /** * Removes given keys and their values from storage */ removeItems: (keys: StorageKeyList) => Promise; /** * Clears absolutely everything from storage */ clear: () => Promise; /** * Gets the total bytes of the database file */ getDatabaseSize: () => Promise; /** * @param onStorageKeyChanged Storage synchronization mechanism keeping all opened tabs in sync */ keepInstancesSync?: (onStorageKeyChanged: OnStorageKeyChanged) => void; }; export default StorageProvider; export type { StorageKeyList, StorageKeyValuePair, OnStorageKeyChanged };