UNPKG

@aituber-onair/kizuna

Version:

A sophisticated bond system (絆 - Kizuna) for managing relationships between users and AI characters in AITuber OnAir.

110 lines (109 loc) 2.73 kB
/** * ExternalStorageProvider - Storage provider with dependency injection * * Allows users to provide their own file system implementation * for Node.js, Deno, or any other environment */ import { StorageProvider, type StorageInfo } from "./StorageProvider"; /** * External storage adapter interface * Users implement this interface to provide file system operations */ export interface ExternalStorageAdapter { /** * Read file contents as string */ readFile(filePath: string): Promise<string>; /** * Write string data to file */ writeFile(filePath: string, data: string): Promise<void>; /** * Delete a file */ deleteFile(filePath: string): Promise<void>; /** * List files in a directory */ listFiles(dirPath: string): Promise<string[]>; /** * Ensure directory exists (create if necessary) */ ensureDir(dirPath: string): Promise<void>; /** * Check if file or directory exists */ exists(path: string): Promise<boolean>; /** * Get file stats (size, etc.) */ getFileStats?(filePath: string): Promise<{ size: number; }>; /** * Join path components */ joinPath(...components: string[]): string; } /** * ExternalStorageProvider configuration */ export interface ExternalStorageConfig { /** Path to data directory */ dataDir: string; /** File encoding */ encoding?: "utf8" | "utf-8"; /** Whether to format JSON */ prettyJson?: boolean; /** Whether to auto-create directory if it doesn't exist */ autoCreateDir?: boolean; } /** * ExternalStorageProvider * Data persistence using external file system adapter */ export declare class ExternalStorageProvider extends StorageProvider { private adapter; private config; constructor(adapter: ExternalStorageAdapter, config?: Partial<ExternalStorageConfig>); /** * Save data */ save(key: string, data: unknown): Promise<void>; /** * Load data */ load<T>(key: string): Promise<T | null>; /** * Remove data */ remove(key: string): Promise<void>; /** * Clear storage */ clear(): Promise<void>; /** * Get all keys */ getAllKeys(): Promise<string[]>; /** * Check if storage is available */ isAvailable(): boolean; /** * Check if data can be stored */ canStore(data: unknown): Promise<boolean>; /** * Get storage information */ getStorageInfo(): Promise<StorageInfo>; /** * Get file path */ private getFilePath; /** * Ensure directory exists and create if necessary */ private ensureDirectoryExists; }