UNPKG

@pisell/pisellos

Version:

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

87 lines (86 loc) 2.4 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; emit: (event: string, payload: any, value?: any) => Promise<{ status: boolean; data: any; }>; offByModuleDestroy: (module: string) => void; }; context: BusinessContext; validateContext: (config: ModuleContextConfig) => boolean; } /** * 业务上下文接口 */ export interface BusinessContext { userId?: string; companyId?: string; [key: string]: any; } /** * 上下文验证规则 */ export interface ContextValidationRule { name: string; required: boolean; validate?: (value: any) => boolean; message?: string; } /** * 模块上下文配置 */ export interface ModuleContextConfig { name: string; validations: ContextValidationRule[]; } export interface PisellOSOptions { debug?: boolean; plugins?: Array<{ plugin: Plugin; options?: PluginOptions; }>; modules?: Array<{ module: Module; options?: ModuleOptions; }>; context?: BusinessContext; }