outers
Version:
outers - a all in one package for your day to day use
64 lines (63 loc) • 3.51 kB
TypeScript
import { ShortStorage } from "../Config/Interfaces/Storage Management/ShortStorage.interface";
/**
* Represents a short storage for saving and retrieving data.
*/
export default class CreateNewShortStorage {
#private;
/**
* Constructs a new instance of the ShortStorage class.
* @param {string} [StorageName] - The name of the storage. Defaults to "outers" if not provided.
* @param {number} [MaxStorageSize] - The maximum size of the storage in Megabytes. Defaults to 1MB if not provided.
* @param {string} [EncryptionKey] - The encryption key for the storage. If not provided, a default encryption key will be generated based on the storage name, storage path, and the current version of Node.js.
* @param {string} [StoragePath] - The path where the storage is located. Defaults to "Cache/" if not provided.
*/
constructor(StorageName?: string, MaxStorageSize?: number, EncryptionKey?: string, StoragePath?: string);
/**
* Saves the provided data with the given title to the storage.
* @param {string} Title - The title of the data.
* @param {any} Data - The data to be saved.
* @returns {Promise<ShortStorage>} - A promise that resolves when the data is successfully saved.
*/
Save(Title: string, Data: any): Promise<ShortStorage>;
/**
* Retrieves data from the storage based on the provided title.
* @param Title - The title of the data to retrieve.
* @returns A promise that resolves to an object containing the status, message, and retrieved data.
*/
Get(Title?: string): Promise<ShortStorage>;
/**
* Updates the data in the Short Storage with the specified title.
* If the data is not found, returns a 404 status with a "Data Not Found" message.
* Otherwise, deletes the old data, adds the new data, and writes the updated data to the storage file.
* Returns a 200 status with a "Data Updated Successfully" message and the updated data.
* @param {string} Title - The title of the data to be updated.
* @param {any} NewData - The new data to be added.
* @returns {Promise<{ status: number, message: string, Data?: { Title: string, Data: any } }>} - The status, message, and updated data (if successful).
*/
Update(Title: string, NewData: any): Promise<ShortStorage>;
/**
* Deletes a data entry from the storage based on the provided title.
* @param {string} Title - The title of the data entry to be deleted.
* @returns {Promise<ShortStorage>} A promise that resolves to the deleted data entry or an error object.
*/
Delete(Title: string): Promise<ShortStorage>;
/**
* Deletes the storage directory and file.
*
* @returns A promise that resolves to a ShortStorage object with the status and message.
* If the storage is deleted successfully, the object will also contain the data and total data count.
* If the storage is not found, the object will have a status of 404 and a corresponding error message.
*/
DeleteStorage(): Promise<ShortStorage>;
/**
* Creates a short storage by checking if the directory exists and creating it if not.
* Then, it creates a short storage file with an empty JSON object.
*/
private createShortStorage;
/**
* Encrypts the provided data using the encryption key.
* @param UnEncryptedData - The data to be encrypted.
* @returns The encrypted data.
*/
private CreateEncryptedData;
}