123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- /**
- * 共享组件版本注册表
- * 用于管理跨Feature的共享组件版本兼容性
- */
- export interface ComponentVersion {
- version: string
- compatibleRange: string
- breaking: boolean
- description: string
- dependents: string[]
- }
- export interface FeatureDependency {
- featureName: string
- requiredComponents: Record<string, string>
- optionalComponents: Record<string, string>
- }
- /**
- * 全局共享组件注册表
- */
- export const SHARED_COMPONENTS: Record<string, ComponentVersion> = {
- 'AccountManager': {
- version: '2.1.0',
- compatibleRange: '^2.0.0',
- breaking: false,
- description: '账户管理器 - 处理账户状态、余额、仓位管理',
- dependents: ['001-specManager-perp', '003-delta-50-80']
- },
- 'PriceManager': {
- version: '1.5.0',
- compatibleRange: '^1.4.0',
- breaking: false,
- description: '价格管理器 - 实时价格获取和缓存',
- dependents: ['001-specManager-perp', '003-delta-50-80']
- },
- 'OrderExecutor': {
- version: '3.0.0',
- compatibleRange: '^3.0.0',
- breaking: true,
- description: '订单执行器 - 统一的订单执行接口',
- dependents: ['001-specManager-perp', '003-delta-50-80']
- },
- 'CredentialService': {
- version: '1.0.0',
- compatibleRange: '^1.0.0',
- breaking: false,
- description: '凭证管理服务 - 多平台凭证存储和签名',
- dependents: ['002-credential-manager', '003-delta-50-80']
- },
- 'PacificaProxyClient': {
- version: '2.3.0',
- compatibleRange: '^2.0.0',
- breaking: false,
- description: 'Pacifica代理客户端 - HTTP+代理网络访问',
- dependents: ['001-specManager-perp', '003-delta-50-80']
- },
- 'RiskManager': {
- version: '1.2.0',
- compatibleRange: '^1.0.0',
- breaking: false,
- description: '风险管理器 - 风险控制和监控',
- dependents: ['001-specManager-perp', '003-delta-50-80']
- }
- }
- /**
- * Feature依赖声明
- */
- export const FEATURE_DEPENDENCIES: Record<string, FeatureDependency> = {
- '001-specManager-perp': {
- featureName: '多平台Delta中性控制平面',
- requiredComponents: {
- 'AccountManager': '^2.0.0',
- 'PriceManager': '^1.4.0',
- 'OrderExecutor': '^3.0.0',
- 'PacificaProxyClient': '^2.0.0',
- 'RiskManager': '^1.0.0'
- },
- optionalComponents: {}
- },
- '002-credential-manager': {
- featureName: '多平台账户凭据管理与签名服务',
- requiredComponents: {
- 'CredentialService': '^1.0.0'
- },
- optionalComponents: {
- 'AccountManager': '^2.0.0'
- }
- },
- '003-delta-50-80': {
- featureName: '50%-80%资金利用率的Delta中性控制',
- requiredComponents: {
- 'AccountManager': '^2.1.0',
- 'PriceManager': '^1.5.0',
- 'OrderExecutor': '^3.0.0',
- 'CredentialService': '^1.0.0',
- 'PacificaProxyClient': '^2.0.0',
- 'RiskManager': '^1.2.0'
- },
- optionalComponents: {}
- }
- }
- /**
- * 检查版本兼容性
- */
- export function checkVersionCompatibility(
- componentName: string,
- requiredVersion: string
- ): { compatible: boolean; message: string } {
- const component = SHARED_COMPONENTS[componentName]
- if (!component) {
- return {
- compatible: false,
- message: `未知组件: ${componentName}`
- }
- }
- // 简单的版本检查逻辑
- const currentVersion = component.version
- const semverRegex = /^(\^|~)?(\d+)\.(\d+)\.(\d+)$/
- const currentMatch = currentVersion.match(semverRegex)
- const requiredMatch = requiredVersion.match(semverRegex)
- if (!currentMatch || !requiredMatch) {
- return {
- compatible: false,
- message: `版本格式错误: current=${currentVersion}, required=${requiredVersion}`
- }
- }
- const [, requiredPrefix, reqMajor, reqMinor, reqPatch] = requiredMatch
- const [, , curMajor, curMinor, curPatch] = currentMatch
- const reqMajorNum = parseInt(reqMajor)
- const reqMinorNum = parseInt(reqMinor)
- const reqPatchNum = parseInt(reqPatch)
- const curMajorNum = parseInt(curMajor)
- const curMinorNum = parseInt(curMinor)
- const curPatchNum = parseInt(curPatch)
- if (requiredPrefix === '^') {
- // 兼容主版本
- if (curMajorNum !== reqMajorNum) {
- return {
- compatible: false,
- message: `主版本不兼容: current=${currentVersion}, required=${requiredVersion}`
- }
- }
- if (curMinorNum < reqMinorNum ||
- (curMinorNum === reqMinorNum && curPatchNum < reqPatchNum)) {
- return {
- compatible: false,
- message: `版本过低: current=${currentVersion}, required=${requiredVersion}`
- }
- }
- }
- return {
- compatible: true,
- message: `版本兼容: current=${currentVersion}, required=${requiredVersion}`
- }
- }
- /**
- * 检查Feature依赖
- */
- export function checkFeatureDependencies(featureName: string): {
- success: boolean
- issues: string[]
- warnings: string[]
- } {
- const dependency = FEATURE_DEPENDENCIES[featureName]
- if (!dependency) {
- return {
- success: false,
- issues: [`未找到Feature依赖定义: ${featureName}`],
- warnings: []
- }
- }
- const issues: string[] = []
- const warnings: string[] = []
- // 检查必需组件
- for (const [componentName, requiredVersion] of Object.entries(dependency.requiredComponents)) {
- const check = checkVersionCompatibility(componentName, requiredVersion)
- if (!check.compatible) {
- issues.push(`${componentName}: ${check.message}`)
- }
- }
- // 检查可选组件
- for (const [componentName, requiredVersion] of Object.entries(dependency.optionalComponents)) {
- const check = checkVersionCompatibility(componentName, requiredVersion)
- if (!check.compatible) {
- warnings.push(`${componentName} (可选): ${check.message}`)
- }
- }
- return {
- success: issues.length === 0,
- issues,
- warnings
- }
- }
- /**
- * 获取组件的所有依赖Feature
- */
- export function getComponentDependents(componentName: string): string[] {
- const component = SHARED_COMPONENTS[componentName]
- return component ? component.dependents : []
- }
- /**
- * 检查组件更新对其他Feature的影响
- */
- export function checkComponentUpdateImpact(
- componentName: string,
- newVersion: string
- ): {
- affectedFeatures: string[]
- breakingChanges: boolean
- recommendations: string[]
- } {
- const component = SHARED_COMPONENTS[componentName]
- if (!component) {
- return {
- affectedFeatures: [],
- breakingChanges: false,
- recommendations: [`组件 ${componentName} 不存在`]
- }
- }
- const affectedFeatures = component.dependents
- const recommendations: string[] = []
- // 检查是否为破坏性变更
- const currentMajor = parseInt(component.version.split('.')[0])
- const newMajor = parseInt(newVersion.split('.')[0])
- const breakingChanges = newMajor > currentMajor
- if (breakingChanges) {
- recommendations.push(`⚠️ 主版本升级,需要更新所有依赖Feature`)
- recommendations.push(`建议创建迁移指南`)
- recommendations.push(`建议分阶段更新Feature`)
- } else {
- recommendations.push(`✅ 向后兼容的更新`)
- recommendations.push(`可以直接更新,无需修改依赖Feature`)
- }
- return {
- affectedFeatures,
- breakingChanges,
- recommendations
- }
- }
|