|
| 1 | +import { StorageKeys, StorageModel } from "./StorageModel"; |
| 2 | +import { StorageExtension } from "./StorageExtension"; |
| 3 | + |
| 4 | +/** |
| 5 | + * AsyncStorage Interface |
| 6 | + * Provides methods for managing asynchronous storage operations. |
| 7 | + * @typeParam S - type of the storage model. |
| 8 | + * @typeParam E - type of the storage extension, or unknown, if no extension is provided. |
| 9 | + */ |
| 10 | +export interface AsyncStorage< |
| 11 | + S extends StorageModel, |
| 12 | + E extends StorageExtension | unknown = unknown |
| 13 | +> { |
| 14 | + /** |
| 15 | + * Retrieves a single item from storage based on the provided key. |
| 16 | + * @param key - The key to identify the item within the storage. |
| 17 | + * @returns Promise resolving to the value associated with the key, |
| 18 | + * or null if the key does not exist. |
| 19 | + */ |
| 20 | + getItem<K extends StorageKeys<S>>(key: K): Promise<S[K]>; |
| 21 | + |
| 22 | + /** |
| 23 | + * Sets the value of the specified item in the storage. |
| 24 | + * @param key - The key under which the value should be stored. |
| 25 | + * @param value - The value to be stored. |
| 26 | + * @returns Promise that resolves when the operation is completed. |
| 27 | + */ |
| 28 | + setItem<K extends StorageKeys<S>>(key: K, value: S[K]): Promise<void>; |
| 29 | + |
| 30 | + /** |
| 31 | + * Removes the item from storage identified by the provided key. |
| 32 | + * @param key - The key of the item to be removed. |
| 33 | + * @returns Promise that resolves when the operation is completed. |
| 34 | + */ |
| 35 | + removeItem<K extends StorageKeys<S>>(key: K): Promise<void>; |
| 36 | + |
| 37 | + /** |
| 38 | + * Retrieves multiple items from storage based on the provided keys. |
| 39 | + * @param keys - An array of keys to identify the items to be retrieved. |
| 40 | + * @returns Promise resolving to an object with key-value pairs, |
| 41 | + * where the values are associated with the keys, |
| 42 | + * or null if a key does not exist. |
| 43 | + */ |
| 44 | + getMany<K extends StorageKeys<S>>(keys: K[]): Promise<{ [k in K]: S[k] }>; |
| 45 | + |
| 46 | + /** |
| 47 | + * Sets multiple items in the storage. |
| 48 | + * @param entries - An object containing key-value pairs to be stored. |
| 49 | + * @returns Promise that resolves when the operation is completed. |
| 50 | + */ |
| 51 | + setMany<K extends StorageKeys<S>>(entries: { |
| 52 | + [k in K]: S[k]; |
| 53 | + }): Promise<void>; |
| 54 | + |
| 55 | + /** |
| 56 | + * Removes multiple items from storage based on the provided keys. |
| 57 | + * @param keys - An array of keys identifying the items to be removed. |
| 58 | + * @returns Promise that resolves when the operation is completed. |
| 59 | + */ |
| 60 | + removeMany<K extends StorageKeys<S>>(keys: K[]): Promise<void>; |
| 61 | + |
| 62 | + /** |
| 63 | + * Clears all the data from the storage. |
| 64 | + * @returns Promise that resolves when the operation is completed. |
| 65 | + */ |
| 66 | + clear(): Promise<void>; |
| 67 | + |
| 68 | + /** |
| 69 | + * Represents the extension for providing additional functionality |
| 70 | + * beyond the standard storage interface. |
| 71 | + * See {@link StorageExtension} for more details. |
| 72 | + */ |
| 73 | + ext: E; |
| 74 | +} |
0 commit comments