@aituber-onair/kizuna
Version:
A sophisticated bond system (絆 - Kizuna) for managing relationships between users and AI characters in AITuber OnAir.
125 lines (124 loc) • 3.28 kB
TypeScript
/**
* StorageProvider - Abstract class for storage providers
*
* Provides a unified interface for different storage systems
* (LocalStorage, IndexedDB, external APIs, etc.)
*/
import type { StorageProvider as IStorageProvider } from "../types";
/**
* Abstract base class for storage providers
*/
export declare abstract class StorageProvider implements IStorageProvider {
/**
* Save data
* @param key Storage key
* @param data Data to save
*/
abstract save(key: string, data: unknown): Promise<void>;
/**
* Load data
* @param key Storage key
* @returns Loaded data, or null if not exists
*/
abstract load<T>(key: string): Promise<T | null>;
/**
* Remove data
* @param key Key to remove
*/
abstract remove(key: string): Promise<void>;
/**
* Get all keys
* @returns Array of keys
*/
abstract getAllKeys(): Promise<string[]>;
/**
* Clear storage
*/
abstract clear(): Promise<void>;
/**
* Check if storage is available
*/
abstract isAvailable(): boolean;
/**
* Check storage size limit
* @param data Data to be saved
* @returns Whether it can be stored
*/
abstract canStore(data: unknown): Promise<boolean>;
/**
* Get storage usage
* @returns Usage information
*/
abstract getStorageInfo(): Promise<StorageInfo>;
/**
* Serialize data
*/
protected serialize(data: unknown): string;
/**
* Deserialize data
*/
protected deserialize<T>(data: string): T;
/**
* Validate data
*/
protected validateKey(key: string): void;
/**
* Get data size (in bytes)
*/
protected getDataSize(data: string): number;
/**
* Generate safe key name
*/
protected sanitizeKey(key: string): string;
/**
* Replacer function for JSON.stringify
* Properly serializes special objects like Date and Map
*/
private replacer;
/**
* Reviver function for JSON.parse
* Restores serialized special objects
*/
private reviver;
}
/**
* Storage information
*/
export interface StorageInfo {
/** Usage (bytes) */
used: number;
/** Available space (bytes, undefined if unknown) */
available?: number;
/** Total capacity (bytes, undefined if unknown) */
total?: number;
/** Number of keys */
keyCount: number;
/** Last update time */
lastUpdated: Date;
}
/**
* Storage error class
*/
export declare class StorageError extends Error {
readonly code: StorageErrorCode;
readonly originalError?: Error | undefined;
constructor(message: string, code: StorageErrorCode, originalError?: Error | undefined);
}
/**
* Storage error codes
*/
export declare enum StorageErrorCode {
NOT_AVAILABLE = "NOT_AVAILABLE",
QUOTA_EXCEEDED = "QUOTA_EXCEEDED",
PERMISSION_DENIED = "PERMISSION_DENIED",
NETWORK_ERROR = "NETWORK_ERROR",
INVALID_KEY = "INVALID_KEY",
INVALID_DATA = "INVALID_DATA",
SERIALIZATION_ERROR = "SERIALIZATION_ERROR",
UNKNOWN_ERROR = "UNKNOWN_ERROR",
SAVE_ERROR = "SAVE_ERROR",
LOAD_ERROR = "LOAD_ERROR",
REMOVE_ERROR = "REMOVE_ERROR",
CLEAR_ERROR = "CLEAR_ERROR",
INFO_ERROR = "INFO_ERROR"
}