synthia-cache-system
Version:
Synthia Engine Cache System - 核心缓存系统实现,提供多级缓存、版本管理、性能监控等功能
323 lines (318 loc) • 8.37 kB
TypeScript
import { a as CacheConfig, S as SynthiaCacheManager, m as CacheManagerWithPlugins, h as CacheVersionManager, i as CacheStrategyManager, j as CacheMetricsCollector } from './cache-plugin-manager-DN8Y1tpu.js';
/**
* Synthia 插件系统核心接口
* 参考 Rust Cargo 插件设计,支持动态注册命令
*/
/**
* 插件日志接口
*/
interface PluginLogger {
info: (message: string, ...args: any[]) => void;
warn: (message: string, ...args: any[]) => void;
error: (message: string, ...args: any[]) => void;
debug: (message: string, ...args: any[]) => void;
success: (message: string, ...args: any[]) => void;
}
/**
* 插件文件系统接口
*/
interface PluginFileSystem {
readFile: (filePath: string, encoding?: string) => Promise<string>;
writeFile: (filePath: string, content: string, encoding?: string) => Promise<void>;
exists: (path: string) => Promise<boolean>;
mkdir: (path: string, recursive?: boolean) => Promise<void>;
readdir: (path: string) => Promise<string[]>;
remove: (path: string) => Promise<void>;
copy: (src: string, dest: string) => Promise<void>;
move: (src: string, dest: string) => Promise<void>;
}
/**
* 插件 HTTP 客户端接口
*/
interface PluginHttpClient {
get: (url: string) => Promise<any>;
post: (url: string, data?: any) => Promise<any>;
put: (url: string, data?: any) => Promise<any>;
delete: (url: string) => Promise<any>;
}
/**
* 插件缓存接口
*/
interface PluginCache {
set: (key: string, value: any) => Promise<void>;
get: (key: string) => Promise<any>;
delete: (key: string) => Promise<void>;
clear: () => Promise<void>;
has: (key: string) => Promise<boolean>;
}
/**
* 插件元数据(向后兼容)
*/
interface PluginMetadata {
/** 插件名称 */
name: string;
/** 插件版本 */
version: string;
/** 插件描述 */
description: string;
/** 插件作者 */
author?: string;
/** 插件许可证 */
license?: string;
/** 插件主页 */
homepage?: string;
/** 插件仓库 */
repository?: string;
/** 插件关键词 */
keywords?: string[];
/** 插件依赖的 Synthia 版本 */
synthiaVersion?: string;
/** 插件兼容的平台 */
platforms?: string[];
}
/**
* 插件命令定义
*/
interface PluginCommand {
/** 命令名称 */
name: string;
/** 命令描述 */
description: string;
/** 命令别名 */
aliases?: string[];
/** 命令选项 */
options?: PluginCommandOption[];
/** 命令参数 */
arguments?: PluginCommandArgument[];
/** 命令执行函数 */
action: (options: any, ...args: any[]) => Promise<void> | void;
/** 命令帮助信息 */
help?: string;
/** 命令示例 */
examples?: string[];
}
/**
* 插件命令选项
*/
interface PluginCommandOption {
/** 选项标识符 */
flags: string;
/** 选项描述 */
description: string;
/** 默认值 */
defaultValue?: any;
/** 是否必需 */
required?: boolean;
/** 选项类型 */
type?: 'string' | 'number' | 'boolean' | 'array';
/** 选项验证函数 */
validator?: (value: any) => boolean | string;
}
/**
* 插件命令参数
*/
interface PluginCommandArgument {
/** 参数名称 */
name: string;
/** 参数描述 */
description: string;
/** 是否必需 */
required?: boolean;
/** 参数类型 */
type?: 'string' | 'number' | 'boolean' | 'array';
/** 参数验证函数 */
validator?: (value: any) => boolean | string;
}
/**
* 插件上下文
*/
interface PluginContext {
/** 项目根目录 */
projectRoot: string;
/** 配置文件路径 */
configPath?: string;
/** 插件配置 */
pluginConfig?: Record<string, any>;
/** 全局选项 */
globalOptions: Record<string, any>;
/** 日志记录器 */
logger: PluginLogger;
/** 文件系统操作 */
fs: PluginFileSystem;
/** 网络请求 */
http: PluginHttpClient;
/** 缓存操作 */
cache: PluginCache;
}
/**
* 开发模式上下文
*/
interface DevContext {
/** 项目信息 */
project: {
name: string;
version: string;
root: string;
};
/** 开发服务器配置 */
devServer: {
port: number;
host: string;
https: boolean;
open: boolean;
hot: boolean;
};
/** 命令行选项 */
options: {
cache?: boolean;
port?: number;
host?: string;
open?: boolean;
https?: boolean;
[]: any;
};
/** 缓存接口 */
cache: PluginCache;
/** 日志记录器 */
logger: PluginLogger;
}
/**
* 构建上下文
*/
interface BuildContext {
/** 项目信息 */
project: {
name: string;
version: string;
root: string;
sourceFiles: string[];
};
/** 构建配置 */
build: {
platform: string;
target: string;
format: string;
outDir: string;
assetsDir: string;
minify: boolean;
sourcemap: boolean;
output?: any;
stats?: any;
};
/** 命令行选项 */
options: {
cache?: boolean;
watch?: boolean;
minify?: boolean;
sourcemap?: boolean;
[]: any;
};
/** 缓存接口 */
cache: PluginCache;
/** 日志记录器 */
logger: PluginLogger;
}
/**
* 清理上下文
*/
interface CleanContext {
/** 项目信息 */
project: {
name: string;
version: string;
root: string;
};
/** 清理目标 */
targets: string[];
/** 命令行选项 */
options: {
cache?: boolean;
all?: boolean;
[]: any;
};
/** 缓存接口 */
cache: PluginCache;
/** 日志记录器 */
logger: PluginLogger;
}
/**
* 插件生命周期钩子
*/
interface PluginHooks {
/** 插件安装前 */
beforeInstall?: () => Promise<void>;
/** 插件安装后 */
afterInstall?: () => Promise<void>;
/** 插件卸载前 */
beforeUninstall?: () => Promise<void>;
/** 插件卸载后 */
afterUninstall?: () => Promise<void>;
/** 插件激活前 */
beforeActivate?: () => Promise<void>;
/** 插件激活后 */
afterActivate?: () => Promise<void>;
/** 插件停用前 */
beforeDeactivate?: () => Promise<void>;
/** 插件停用后 */
afterDeactivate?: () => Promise<void>;
/** 开发模式启动前 */
beforeDev?: (context: DevContext) => Promise<void>;
/** 开发模式启动后 */
afterDev?: (context: DevContext) => Promise<void>;
/** 构建前 */
beforeBuild?: (context: BuildContext) => Promise<void>;
/** 构建后 */
afterBuild?: (context: BuildContext) => Promise<void>;
/** 清理前 */
beforeClean?: (context: CleanContext) => Promise<void>;
/** 清理后 */
afterClean?: (context: CleanContext) => Promise<void>;
}
/**
* 插件主接口
*/
interface SynthiaPlugin {
/** 插件元数据 */
metadata: PluginMetadata;
/** 插件命令列表 */
commands: PluginCommand[];
/** 插件生命周期钩子 */
hooks?: PluginHooks;
/** 插件初始化函数 */
initialize?: (context: PluginContext) => Promise<void>;
/** 插件清理函数 */
cleanup?: () => Promise<void>;
}
/**
* Synthia Cache System 插件
* 提供命令行工具的缓存功能,支持 dev 和 build 命令
*/
/**
* 设置缓存配置
*/
declare function setCacheConfig(config: Partial<CacheConfig>): void;
/**
* 获取缓存管理器
*/
declare function getCacheManager(): SynthiaCacheManager | null;
/**
* 获取增强的缓存管理器
*/
declare function getEnhancedCacheManager(): CacheManagerWithPlugins | null;
/**
* 获取版本管理器
*/
declare function getVersionManager(): CacheVersionManager | null;
/**
* 获取策略管理器
*/
declare function getStrategyManager(): CacheStrategyManager | null;
/**
* 获取指标收集器
*/
declare function getMetricsCollector(): CacheMetricsCollector | null;
/**
* 缓存系统插件实例
*/
declare const plugin: SynthiaPlugin;
export { plugin as default, getCacheManager, getEnhancedCacheManager, getMetricsCollector, getStrategyManager, getVersionManager, setCacheConfig };