UNPKG

@pisell/pisellos

Version:

一个可扩展的前端模块化SDK框架,支持插件系统

121 lines (120 loc) 3.46 kB
/** * pisell OS 核心类型定义 */ export interface Plugin { name: string; version: string; initialize: () => Promise<void> | void; destroy?: () => Promise<void> | void; } export interface PluginOptions { dependencies?: string[]; } export interface Module { name: string; version: string; initialize: (core: PisellCore, options: ModuleOptions) => Promise<void> | void; destroy?: () => Promise<void> | void; exports?: Record<string, any>; isSolution?: boolean; [key: string]: any; } export interface ModuleOptions { dependencies?: string[]; plugins?: string[]; hooks?: any; store?: Record<string, any>; initialState?: Record<string, any>; otherParams?: Record<string, any>; } export type EventHandler = (data?: any) => void; export interface PisellCore { registerPlugin: (plugin: Plugin, options?: PluginOptions) => void; getPlugin: <T extends Plugin>(name: string) => T | null; hasPlugin: (name: string) => boolean; registerModule: (module: Module, options?: ModuleOptions) => void; unregisterModule: (module: Module, options?: ModuleOptions) => void; getModule: <T extends Module>(name: string) => T | null; getModuleExports: <T = any>(name: string) => T | null; hasModule: (name: string) => boolean; effects: { on: (event: string, callback: (payload: any) => void) => () => void; once: (event: string, callback: (payload: any) => void) => () => void; only: (event: string, callback: (payload: any) => void) => () => void; off: (event: string, callback: (payload: any) => void) => void; emit: (event: string, payload: any, value?: any) => Promise<{ status: boolean; data: any; }>; offByModuleDestroy: (module: string) => void; }; context: BusinessContext; validateContext: (config: ModuleContextConfig) => boolean; serverOptions?: ServerOptions; server?: any; setContext: (ctx: Partial<BusinessContext>) => void; } /** * 业务上下文接口 */ export interface BusinessContext { userId?: string; companyId?: string; locale?: string; [key: string]: any; } /** * 上下文验证规则 */ export interface ContextValidationRule { name: string; required: boolean; validate?: (value: any) => boolean; message?: string; } /** * 模块上下文配置 */ export interface ModuleContextConfig { name: string; validations: ContextValidationRule[]; } /** * Server 模块配置 */ export interface ServerModuleConfig { /** 模块名称 */ name: string; /** 是否自动预加载数据 */ preload?: boolean; /** 模块配置参数 */ config?: Record<string, any>; } /** * Server 配置选项 */ export interface ServerOptions { All_DATA_SOURCES: Record<string, any>; /** 要启用的模块列表 */ modules?: string[] | ServerModuleConfig[]; /** 是否自动初始化数据 */ autoInitData?: boolean; } export interface PisellOSOptions { debug?: boolean; plugins?: Array<{ plugin: Plugin; options?: PluginOptions; }>; modules?: Array<{ module: Module; options?: ModuleOptions; }>; context?: BusinessContext; /** Server 配置 */ server?: ServerOptions; } export interface InitializeServerOptions { onModuleLoad?: (module: string) => void; onModuleLoadComplete?: (module: string) => void; }