|
1 | 1 | import { Plugin, PluginContext } from './types.js'; |
2 | 2 | import { createLogger, ObjectLogger } from './logger.js'; |
3 | 3 | import type { LoggerConfig } from '@objectstack/spec/system'; |
| 4 | +import { ServiceRequirementDef } from '@objectstack/spec/system'; |
4 | 5 | import { PluginLoader, PluginMetadata, ServiceLifecycle, ServiceFactory, PluginStartupResult } from './plugin-loader.js'; |
5 | 6 |
|
6 | 7 | /** |
@@ -185,6 +186,44 @@ export class ObjectKernel { |
185 | 186 | return this; |
186 | 187 | } |
187 | 188 |
|
| 189 | + /** |
| 190 | + * Validate Critical System Requirements |
| 191 | + */ |
| 192 | + private validateSystemRequirements() { |
| 193 | + this.logger.debug('Validating system service requirements...'); |
| 194 | + const missingServices: string[] = []; |
| 195 | + const missingCoreServices: string[] = []; |
| 196 | + |
| 197 | + // Iterate through all defined requirements |
| 198 | + for (const [serviceName, criticality] of Object.entries(ServiceRequirementDef)) { |
| 199 | + const hasService = this.services.has(serviceName) || this.pluginLoader.hasService(serviceName); |
| 200 | + |
| 201 | + if (!hasService) { |
| 202 | + if (criticality === 'required') { |
| 203 | + this.logger.error(`CRITICAL: Required service missing: ${serviceName}`); |
| 204 | + missingServices.push(serviceName); |
| 205 | + } else if (criticality === 'core') { |
| 206 | + this.logger.warn(`CORE: Core service missing, functionality may be degraded: ${serviceName}`); |
| 207 | + missingCoreServices.push(serviceName); |
| 208 | + } else { |
| 209 | + this.logger.info(`Info: Optional service not present: ${serviceName}`); |
| 210 | + } |
| 211 | + } |
| 212 | + } |
| 213 | + |
| 214 | + if (missingServices.length > 0) { |
| 215 | + const errorMsg = `System failed to start. Missing critical services: ${missingServices.join(', ')}`; |
| 216 | + this.logger.error(errorMsg); |
| 217 | + throw new Error(errorMsg); |
| 218 | + } |
| 219 | + |
| 220 | + if (missingCoreServices.length > 0) { |
| 221 | + this.logger.warn(`System started with degraded capabilities. Missing core services: ${missingCoreServices.join(', ')}`); |
| 222 | + } |
| 223 | + |
| 224 | + this.logger.info('System requirement check passed'); |
| 225 | + } |
| 226 | + |
188 | 227 | /** |
189 | 228 | * Bootstrap the kernel with enhanced features |
190 | 229 | */ |
@@ -231,6 +270,7 @@ export class ObjectKernel { |
231 | 270 | } |
232 | 271 |
|
233 | 272 | // Phase 3: Trigger kernel:ready hook |
| 273 | + this.validateSystemRequirements(); // Final check before ready |
234 | 274 | this.logger.debug('Triggering kernel:ready hook'); |
235 | 275 | await this.context.trigger('kernel:ready'); |
236 | 276 |
|
|
0 commit comments