@objectstack/core 4.0.4 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -10
- package/dist/index.cjs +172 -507
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -223
- package/dist/index.d.ts +24 -223
- package/dist/index.js +178 -505
- package/dist/index.js.map +1 -1
- package/dist/logger.cjs +177 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +26 -0
- package/dist/logger.d.ts +26 -0
- package/dist/logger.js +158 -0
- package/dist/logger.js.map +1 -0
- package/package.json +36 -15
- package/.turbo/turbo-build.log +0 -22
- package/ADVANCED_FEATURES.md +0 -380
- package/API_REGISTRY.md +0 -392
- package/CHANGELOG.md +0 -472
- package/PHASE2_IMPLEMENTATION.md +0 -388
- package/REFACTORING_SUMMARY.md +0 -40
- package/examples/api-registry-example.ts +0 -559
- package/examples/kernel-features-example.ts +0 -311
- package/examples/phase2-integration.ts +0 -357
- package/src/api-registry-plugin.test.ts +0 -393
- package/src/api-registry-plugin.ts +0 -89
- package/src/api-registry.test.ts +0 -1089
- package/src/api-registry.ts +0 -739
- package/src/contracts/data-engine.ts +0 -57
- package/src/contracts/http-server.ts +0 -151
- package/src/contracts/logger.ts +0 -72
- package/src/dependency-resolver.test.ts +0 -287
- package/src/dependency-resolver.ts +0 -390
- package/src/fallbacks/fallbacks.test.ts +0 -281
- package/src/fallbacks/index.ts +0 -26
- package/src/fallbacks/memory-cache.ts +0 -34
- package/src/fallbacks/memory-i18n.ts +0 -112
- package/src/fallbacks/memory-job.ts +0 -23
- package/src/fallbacks/memory-metadata.ts +0 -50
- package/src/fallbacks/memory-queue.ts +0 -28
- package/src/health-monitor.test.ts +0 -81
- package/src/health-monitor.ts +0 -318
- package/src/hot-reload.ts +0 -382
- package/src/index.ts +0 -50
- package/src/kernel-base.ts +0 -273
- package/src/kernel.test.ts +0 -624
- package/src/kernel.ts +0 -631
- package/src/lite-kernel.test.ts +0 -248
- package/src/lite-kernel.ts +0 -137
- package/src/logger.test.ts +0 -116
- package/src/logger.ts +0 -355
- package/src/namespace-resolver.test.ts +0 -130
- package/src/namespace-resolver.ts +0 -188
- package/src/package-manager.test.ts +0 -225
- package/src/package-manager.ts +0 -428
- package/src/plugin-loader.test.ts +0 -421
- package/src/plugin-loader.ts +0 -484
- package/src/qa/adapter.ts +0 -16
- package/src/qa/http-adapter.ts +0 -116
- package/src/qa/index.ts +0 -5
- package/src/qa/runner.ts +0 -189
- package/src/security/index.ts +0 -50
- package/src/security/permission-manager.test.ts +0 -256
- package/src/security/permission-manager.ts +0 -338
- package/src/security/plugin-config-validator.test.ts +0 -276
- package/src/security/plugin-config-validator.ts +0 -193
- package/src/security/plugin-permission-enforcer.test.ts +0 -251
- package/src/security/plugin-permission-enforcer.ts +0 -436
- package/src/security/plugin-signature-verifier.ts +0 -403
- package/src/security/sandbox-runtime.ts +0 -462
- package/src/security/security-scanner.ts +0 -367
- package/src/types.ts +0 -120
- package/src/utils/env.test.ts +0 -62
- package/src/utils/env.ts +0 -53
- package/tsconfig.json +0 -10
- package/vitest.config.ts +0 -10
package/PHASE2_IMPLEMENTATION.md
DELETED
|
@@ -1,388 +0,0 @@
|
|
|
1
|
-
# ObjectStack Phase 2 Implementation
|
|
2
|
-
|
|
3
|
-
This document describes the Phase 2 implementation of the ObjectStack Microkernel and Plugin Architecture Improvement Plan.
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
Phase 2 implements the core runtime features for advanced plugin lifecycle management, dependency resolution, and security sandboxing. These components build upon the protocol definitions from Phase 1 and provide production-ready implementations.
|
|
8
|
-
|
|
9
|
-
## Components
|
|
10
|
-
|
|
11
|
-
### 1. Health Monitor (`health-monitor.ts`)
|
|
12
|
-
|
|
13
|
-
The Health Monitor provides real-time health checking and auto-recovery for plugins.
|
|
14
|
-
|
|
15
|
-
**Features:**
|
|
16
|
-
- Configurable health check intervals
|
|
17
|
-
- Automatic failure detection with thresholds
|
|
18
|
-
- Auto-restart with backoff strategies (fixed, linear, exponential)
|
|
19
|
-
- Health status tracking (healthy, degraded, unhealthy, failed, recovering, unknown)
|
|
20
|
-
- Metrics collection (uptime, memory, CPU, connections, error rate)
|
|
21
|
-
|
|
22
|
-
**Usage:**
|
|
23
|
-
|
|
24
|
-
```typescript
|
|
25
|
-
import { PluginHealthMonitor } from '@objectstack/core';
|
|
26
|
-
|
|
27
|
-
const monitor = new PluginHealthMonitor(logger);
|
|
28
|
-
|
|
29
|
-
// Register a plugin for monitoring
|
|
30
|
-
monitor.registerPlugin('my-plugin', {
|
|
31
|
-
interval: 30000, // Check every 30 seconds
|
|
32
|
-
timeout: 5000, // 5 second timeout
|
|
33
|
-
failureThreshold: 3, // Mark unhealthy after 3 failures
|
|
34
|
-
successThreshold: 1, // Mark healthy after 1 success
|
|
35
|
-
autoRestart: true, // Auto-restart on failure
|
|
36
|
-
maxRestartAttempts: 3, // Max 3 restart attempts
|
|
37
|
-
restartBackoff: 'exponential',
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// Start monitoring
|
|
41
|
-
monitor.startMonitoring('my-plugin', pluginInstance);
|
|
42
|
-
|
|
43
|
-
// Get health status
|
|
44
|
-
const status = monitor.getHealthStatus('my-plugin');
|
|
45
|
-
const report = monitor.getHealthReport('my-plugin');
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### 2. Hot Reload Manager (`hot-reload.ts`)
|
|
49
|
-
|
|
50
|
-
The Hot Reload Manager enables zero-downtime plugin updates with state preservation.
|
|
51
|
-
|
|
52
|
-
**Features:**
|
|
53
|
-
- State preservation strategies (memory, disk, distributed, none)
|
|
54
|
-
- File watching integration points
|
|
55
|
-
- Debounced reload scheduling
|
|
56
|
-
- Graceful shutdown with configurable timeout
|
|
57
|
-
- Before/after reload hooks
|
|
58
|
-
- State checksum verification
|
|
59
|
-
|
|
60
|
-
**Usage:**
|
|
61
|
-
|
|
62
|
-
```typescript
|
|
63
|
-
import { HotReloadManager } from '@objectstack/core';
|
|
64
|
-
|
|
65
|
-
const hotReload = new HotReloadManager(logger);
|
|
66
|
-
|
|
67
|
-
// Register plugin for hot reload
|
|
68
|
-
hotReload.registerPlugin('my-plugin', {
|
|
69
|
-
enabled: true,
|
|
70
|
-
watchPatterns: ['src/**/*.ts'],
|
|
71
|
-
debounceDelay: 1000,
|
|
72
|
-
preserveState: true,
|
|
73
|
-
stateStrategy: 'memory',
|
|
74
|
-
shutdownTimeout: 30000,
|
|
75
|
-
beforeReload: ['plugin:beforeReload'],
|
|
76
|
-
afterReload: ['plugin:afterReload'],
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
// Trigger reload
|
|
80
|
-
await hotReload.reloadPlugin(
|
|
81
|
-
'my-plugin',
|
|
82
|
-
pluginInstance,
|
|
83
|
-
'1.2.0',
|
|
84
|
-
() => ({ /* current state */ }),
|
|
85
|
-
(state) => { /* restore state */ }
|
|
86
|
-
);
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### 3. Dependency Resolver (`dependency-resolver.ts`)
|
|
90
|
-
|
|
91
|
-
The Dependency Resolver provides semantic versioning and dependency management.
|
|
92
|
-
|
|
93
|
-
**Features:**
|
|
94
|
-
- Full SemVer parsing and comparison
|
|
95
|
-
- Version constraint matching (^, ~, >=, <=, <, >, -, *, latest)
|
|
96
|
-
- Topological sorting (Kahn's algorithm)
|
|
97
|
-
- Circular dependency detection
|
|
98
|
-
- Version conflict detection
|
|
99
|
-
- Compatibility level assessment
|
|
100
|
-
- Best version selection
|
|
101
|
-
|
|
102
|
-
**Usage:**
|
|
103
|
-
|
|
104
|
-
```typescript
|
|
105
|
-
import {
|
|
106
|
-
SemanticVersionManager,
|
|
107
|
-
DependencyResolver
|
|
108
|
-
} from '@objectstack/core';
|
|
109
|
-
|
|
110
|
-
// Parse and compare versions
|
|
111
|
-
const v1 = SemanticVersionManager.parse('1.2.3');
|
|
112
|
-
const v2 = SemanticVersionManager.parse('1.3.0');
|
|
113
|
-
const cmp = SemanticVersionManager.compare(v1, v2); // -1
|
|
114
|
-
|
|
115
|
-
// Check if version satisfies constraint
|
|
116
|
-
const satisfies = SemanticVersionManager.satisfies(v1, '^1.0.0'); // true
|
|
117
|
-
|
|
118
|
-
// Get compatibility level
|
|
119
|
-
const compat = SemanticVersionManager.getCompatibilityLevel(v1, v2);
|
|
120
|
-
// 'backward-compatible'
|
|
121
|
-
|
|
122
|
-
// Resolve dependencies
|
|
123
|
-
const resolver = new DependencyResolver(logger);
|
|
124
|
-
|
|
125
|
-
const plugins = new Map([
|
|
126
|
-
['core', { dependencies: [] }],
|
|
127
|
-
['plugin-a', { dependencies: ['core'] }],
|
|
128
|
-
['plugin-b', { dependencies: ['core', 'plugin-a'] }],
|
|
129
|
-
]);
|
|
130
|
-
|
|
131
|
-
const order = resolver.resolve(plugins);
|
|
132
|
-
// ['core', 'plugin-a', 'plugin-b']
|
|
133
|
-
|
|
134
|
-
// Detect conflicts
|
|
135
|
-
const conflicts = resolver.detectConflicts(pluginsWithVersions);
|
|
136
|
-
|
|
137
|
-
// Find best version
|
|
138
|
-
const best = resolver.findBestVersion(
|
|
139
|
-
['1.0.0', '1.1.0', '1.2.0', '2.0.0'],
|
|
140
|
-
['^1.0.0', '>=1.1.0']
|
|
141
|
-
);
|
|
142
|
-
// '1.2.0'
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
### 4. Permission Manager (`security/permission-manager.ts`)
|
|
146
|
-
|
|
147
|
-
The Permission Manager enforces fine-grained access control for plugins.
|
|
148
|
-
|
|
149
|
-
**Features:**
|
|
150
|
-
- Resource-level permissions (data, UI, system, storage, network, process)
|
|
151
|
-
- Action-based access control (create, read, update, delete, execute, etc.)
|
|
152
|
-
- Permission scopes (global, tenant, user, resource, plugin)
|
|
153
|
-
- Grant/revoke mechanisms
|
|
154
|
-
- Permission expiration
|
|
155
|
-
- Required vs optional permissions
|
|
156
|
-
- Field-level access control
|
|
157
|
-
|
|
158
|
-
**Usage:**
|
|
159
|
-
|
|
160
|
-
```typescript
|
|
161
|
-
import { PluginPermissionManager } from '@objectstack/core/security';
|
|
162
|
-
|
|
163
|
-
const permManager = new PluginPermissionManager(logger);
|
|
164
|
-
|
|
165
|
-
// Register permissions
|
|
166
|
-
permManager.registerPermissions('my-plugin', {
|
|
167
|
-
permissions: [
|
|
168
|
-
{
|
|
169
|
-
id: 'read-customer-data',
|
|
170
|
-
resource: 'data.object',
|
|
171
|
-
actions: ['read'],
|
|
172
|
-
scope: 'plugin',
|
|
173
|
-
description: 'Read customer data',
|
|
174
|
-
required: true,
|
|
175
|
-
filter: {
|
|
176
|
-
resourceIds: ['customer'],
|
|
177
|
-
fields: ['name', 'email'],
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
],
|
|
181
|
-
defaultGrant: 'prompt',
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
// Grant permission
|
|
185
|
-
permManager.grantPermission('my-plugin', 'read-customer-data', 'admin');
|
|
186
|
-
|
|
187
|
-
// Check access
|
|
188
|
-
const result = permManager.checkAccess(
|
|
189
|
-
'my-plugin',
|
|
190
|
-
'data.object',
|
|
191
|
-
'read',
|
|
192
|
-
'customer'
|
|
193
|
-
);
|
|
194
|
-
|
|
195
|
-
if (result.allowed) {
|
|
196
|
-
// Proceed with operation
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Check all required permissions
|
|
200
|
-
const hasAll = permManager.hasAllRequiredPermissions('my-plugin');
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
### 5. Sandbox Runtime (`security/sandbox-runtime.ts`)
|
|
204
|
-
|
|
205
|
-
The Sandbox Runtime provides isolated execution environments with resource limits.
|
|
206
|
-
|
|
207
|
-
**Features:**
|
|
208
|
-
- Multiple isolation levels (none, minimal, standard, strict, paranoid)
|
|
209
|
-
- File system access control (allowed/denied paths)
|
|
210
|
-
- Network access control (allowed/blocked hosts)
|
|
211
|
-
- Process spawning control
|
|
212
|
-
- Environment variable access control
|
|
213
|
-
- Resource limit enforcement (memory, CPU, connections)
|
|
214
|
-
- Resource usage monitoring
|
|
215
|
-
|
|
216
|
-
**Usage:**
|
|
217
|
-
|
|
218
|
-
```typescript
|
|
219
|
-
import { PluginSandboxRuntime } from '@objectstack/core/security';
|
|
220
|
-
|
|
221
|
-
const sandbox = new PluginSandboxRuntime(logger);
|
|
222
|
-
|
|
223
|
-
// Create sandbox
|
|
224
|
-
const context = sandbox.createSandbox('my-plugin', {
|
|
225
|
-
enabled: true,
|
|
226
|
-
level: 'standard',
|
|
227
|
-
filesystem: {
|
|
228
|
-
mode: 'restricted',
|
|
229
|
-
allowedPaths: ['/app/plugins/my-plugin'],
|
|
230
|
-
deniedPaths: ['/etc', '/root'],
|
|
231
|
-
},
|
|
232
|
-
network: {
|
|
233
|
-
mode: 'restricted',
|
|
234
|
-
allowedHosts: ['api.example.com'],
|
|
235
|
-
blockedHosts: ['malicious.com'],
|
|
236
|
-
maxConnections: 10,
|
|
237
|
-
},
|
|
238
|
-
process: {
|
|
239
|
-
allowSpawn: false,
|
|
240
|
-
},
|
|
241
|
-
memory: {
|
|
242
|
-
maxHeap: 100 * 1024 * 1024, // 100 MB
|
|
243
|
-
},
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
// Check resource access
|
|
247
|
-
const fileAccess = sandbox.checkResourceAccess(
|
|
248
|
-
'my-plugin',
|
|
249
|
-
'file',
|
|
250
|
-
'/app/plugins/my-plugin/data.json'
|
|
251
|
-
);
|
|
252
|
-
|
|
253
|
-
const netAccess = sandbox.checkResourceAccess(
|
|
254
|
-
'my-plugin',
|
|
255
|
-
'network',
|
|
256
|
-
'https://api.example.com/data'
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
// Check resource limits
|
|
260
|
-
const { withinLimits, violations } = sandbox.checkResourceLimits('my-plugin');
|
|
261
|
-
|
|
262
|
-
// Get resource usage
|
|
263
|
-
const usage = sandbox.getResourceUsage('my-plugin');
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
### 6. Security Scanner (`security/security-scanner.ts`)
|
|
267
|
-
|
|
268
|
-
The Security Scanner performs comprehensive security analysis of plugins.
|
|
269
|
-
|
|
270
|
-
**Features:**
|
|
271
|
-
- Code vulnerability scanning
|
|
272
|
-
- Dependency vulnerability detection (CVE database integration)
|
|
273
|
-
- Malware pattern detection
|
|
274
|
-
- License compliance checking
|
|
275
|
-
- Configuration security analysis
|
|
276
|
-
- Security scoring (0-100)
|
|
277
|
-
- Issue categorization (critical, high, medium, low, info)
|
|
278
|
-
|
|
279
|
-
**Usage:**
|
|
280
|
-
|
|
281
|
-
```typescript
|
|
282
|
-
import { PluginSecurityScanner } from '@objectstack/core/security';
|
|
283
|
-
|
|
284
|
-
const scanner = new PluginSecurityScanner(logger);
|
|
285
|
-
|
|
286
|
-
// Perform security scan
|
|
287
|
-
const result = await scanner.scan({
|
|
288
|
-
pluginId: 'my-plugin',
|
|
289
|
-
version: '1.0.0',
|
|
290
|
-
files: ['src/**/*.ts'],
|
|
291
|
-
dependencies: {
|
|
292
|
-
'express': '4.18.0',
|
|
293
|
-
'lodash': '4.17.21',
|
|
294
|
-
},
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
console.log(`Security Score: ${result.score}/100`);
|
|
298
|
-
console.log(`Passed: ${result.passed}`);
|
|
299
|
-
console.log(`Issues:`, result.summary);
|
|
300
|
-
|
|
301
|
-
// Add vulnerability to database
|
|
302
|
-
scanner.addVulnerability('lodash', '4.17.20', {
|
|
303
|
-
cve: 'CVE-2021-23337',
|
|
304
|
-
severity: 'high',
|
|
305
|
-
affectedVersions: ['<=4.17.20'],
|
|
306
|
-
fixedIn: ['4.17.21'],
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
// Update vulnerability database
|
|
310
|
-
await scanner.updateVulnerabilityDatabase();
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
## Integration with Kernel
|
|
314
|
-
|
|
315
|
-
These components are designed to integrate with the existing ObjectKernel:
|
|
316
|
-
|
|
317
|
-
```typescript
|
|
318
|
-
import {
|
|
319
|
-
ObjectKernel,
|
|
320
|
-
PluginHealthMonitor,
|
|
321
|
-
HotReloadManager,
|
|
322
|
-
DependencyResolver,
|
|
323
|
-
PluginPermissionManager,
|
|
324
|
-
PluginSandboxRuntime,
|
|
325
|
-
PluginSecurityScanner
|
|
326
|
-
} from '@objectstack/core';
|
|
327
|
-
|
|
328
|
-
const kernel = new ObjectKernel({ logger: { level: 'info' } });
|
|
329
|
-
|
|
330
|
-
// Initialize Phase 2 components
|
|
331
|
-
const healthMonitor = new PluginHealthMonitor(kernel.logger);
|
|
332
|
-
const hotReload = new HotReloadManager(kernel.logger);
|
|
333
|
-
const depResolver = new DependencyResolver(kernel.logger);
|
|
334
|
-
const permManager = new PluginPermissionManager(kernel.logger);
|
|
335
|
-
const sandbox = new PluginSandboxRuntime(kernel.logger);
|
|
336
|
-
const scanner = new PluginSecurityScanner(kernel.logger);
|
|
337
|
-
|
|
338
|
-
// Register plugins with enhanced features
|
|
339
|
-
// ... plugin registration code ...
|
|
340
|
-
|
|
341
|
-
// Bootstrap kernel
|
|
342
|
-
await kernel.bootstrap();
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
## Testing
|
|
346
|
-
|
|
347
|
-
Comprehensive unit tests are provided for all components:
|
|
348
|
-
|
|
349
|
-
- `health-monitor.test.ts` - Health monitoring tests
|
|
350
|
-
- `dependency-resolver.test.ts` - SemVer and dependency resolution tests
|
|
351
|
-
- `security/permission-manager.test.ts` - Permission management tests
|
|
352
|
-
|
|
353
|
-
Run tests with:
|
|
354
|
-
|
|
355
|
-
```bash
|
|
356
|
-
npm test
|
|
357
|
-
```
|
|
358
|
-
|
|
359
|
-
## Performance Considerations
|
|
360
|
-
|
|
361
|
-
- Health checks run in separate intervals to avoid blocking
|
|
362
|
-
- State preservation uses checksums for integrity verification
|
|
363
|
-
- Dependency resolution uses efficient topological sorting
|
|
364
|
-
- Resource monitoring is throttled (default 5 seconds)
|
|
365
|
-
- Security scanning can be run asynchronously
|
|
366
|
-
|
|
367
|
-
## Security
|
|
368
|
-
|
|
369
|
-
- All permissions must be explicitly granted
|
|
370
|
-
- Sandbox provides multiple isolation levels
|
|
371
|
-
- Security scanner integrates with CVE databases
|
|
372
|
-
- Resource limits prevent DoS attacks
|
|
373
|
-
- State preservation uses checksums to detect tampering
|
|
374
|
-
|
|
375
|
-
## Future Enhancements
|
|
376
|
-
|
|
377
|
-
Phase 3 and beyond will add:
|
|
378
|
-
- Plugin marketplace integration
|
|
379
|
-
- AI-powered plugin development
|
|
380
|
-
- Enhanced monitoring and observability
|
|
381
|
-
- Distributed plugin management
|
|
382
|
-
- Advanced security features
|
|
383
|
-
|
|
384
|
-
## References
|
|
385
|
-
|
|
386
|
-
- [MICROKERNEL_IMPROVEMENT_PLAN.md](../../MICROKERNEL_IMPROVEMENT_PLAN.md)
|
|
387
|
-
- [ARCHITECTURE.md](../../ARCHITECTURE.md)
|
|
388
|
-
- [Protocol Definitions](../spec/src/system/)
|
package/REFACTORING_SUMMARY.md
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# Kernel Refactoring Summary
|
|
2
|
-
|
|
3
|
-
This document summarizes the critical architectural improvements made to the `packages/core` module to address stability, performance, and correctness issues.
|
|
4
|
-
|
|
5
|
-
## 1. Dependency Injection Context Fix
|
|
6
|
-
**Problem:** Service factories were receiving an empty object `{}` instead of the real `PluginContext`.
|
|
7
|
-
**Fix:**
|
|
8
|
-
- Updated `PluginLoader.createServiceInstance` to ensure `this.context` is passed to factories.
|
|
9
|
-
- Added `PluginLoader.setContext` method to inject the context from the Kernel.
|
|
10
|
-
- Kernel now properly injects itself and the loader into the context before initialization.
|
|
11
|
-
|
|
12
|
-
## 2. Sync/Async Gap (Service Availability)
|
|
13
|
-
**Problem:** Services created asynchronously (via `awaitFactory`) were not accessible synchronously immediately after initialization, breaking code that expected `getService` to return an instance if the plugin was loaded.
|
|
14
|
-
**Fix:**
|
|
15
|
-
- Implemented L2 caching via `PluginLoader.getServiceInstance<T>(name: string)`.
|
|
16
|
-
- Kernel's `getService` now checks this synchronous cache first before falling back to the async path.
|
|
17
|
-
- Ensured singleton instances are stored in `serviceInstances` immediately upon creation.
|
|
18
|
-
|
|
19
|
-
## 3. Runtime Circular Dependency Detection
|
|
20
|
-
**Problem:** Complex service graphs could deadlock or crash the stack if factories recursively requested each other. Static analysis was insufficient for dynamic factories.
|
|
21
|
-
**Fix:**
|
|
22
|
-
- Added a `creating` Set to `PluginLoader`.
|
|
23
|
-
- `createServiceInstance` now tracks which services are currently being built.
|
|
24
|
-
- Throws a descriptive error if a loop is detected (e.g., `Circular dependency detected: serviceA -> serviceB -> serviceA`).
|
|
25
|
-
|
|
26
|
-
## 4. Enhanced Error Handling
|
|
27
|
-
**Problem:** The Kernel swallowed errors from service factories (like database connection failures) and threw a generic "Service not found" error, making debugging impossible.
|
|
28
|
-
**Fix:**
|
|
29
|
-
- Refined `Kernel.getService` to distinguish between "service registration missing" and "factory execution failed".
|
|
30
|
-
- Factory errors are now re-thrown with their original stack trace and message.
|
|
31
|
-
|
|
32
|
-
## 5. Configuration Validation
|
|
33
|
-
**Problem:** Configuration validation was a scaffold without implementation.
|
|
34
|
-
**Fix:**
|
|
35
|
-
- Integrated `PluginConfigValidator` (Zod-based) into `PluginLoader`.
|
|
36
|
-
- `validatePluginConfig` now performs actual schema validation against `plugin.configSchema`.
|
|
37
|
-
|
|
38
|
-
## Verification
|
|
39
|
-
- **Build:** Clean build of `dist` artifacts.
|
|
40
|
-
- **Tests:** 100% Pass rate (380/380 tests) across 22 test suites.
|