@objectstack/core 0.9.1 → 1.0.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.
Files changed (94) hide show
  1. package/{ENHANCED_FEATURES.md → ADVANCED_FEATURES.md} +13 -13
  2. package/CHANGELOG.md +21 -0
  3. package/PHASE2_IMPLEMENTATION.md +388 -0
  4. package/README.md +12 -341
  5. package/REFACTORING_SUMMARY.md +40 -0
  6. package/dist/api-registry-plugin.test.js +23 -21
  7. package/dist/api-registry.test.js +2 -2
  8. package/dist/dependency-resolver.d.ts +62 -0
  9. package/dist/dependency-resolver.d.ts.map +1 -0
  10. package/dist/dependency-resolver.js +317 -0
  11. package/dist/dependency-resolver.test.d.ts +2 -0
  12. package/dist/dependency-resolver.test.d.ts.map +1 -0
  13. package/dist/dependency-resolver.test.js +241 -0
  14. package/dist/health-monitor.d.ts +65 -0
  15. package/dist/health-monitor.d.ts.map +1 -0
  16. package/dist/health-monitor.js +269 -0
  17. package/dist/health-monitor.test.d.ts +2 -0
  18. package/dist/health-monitor.test.d.ts.map +1 -0
  19. package/dist/health-monitor.test.js +68 -0
  20. package/dist/hot-reload.d.ts +79 -0
  21. package/dist/hot-reload.d.ts.map +1 -0
  22. package/dist/hot-reload.js +313 -0
  23. package/dist/index.d.ts +4 -1
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +5 -1
  26. package/dist/kernel-base.d.ts +2 -2
  27. package/dist/kernel-base.js +2 -2
  28. package/dist/kernel.d.ts +89 -31
  29. package/dist/kernel.d.ts.map +1 -1
  30. package/dist/kernel.js +430 -73
  31. package/dist/kernel.test.js +375 -122
  32. package/dist/lite-kernel.d.ts +55 -0
  33. package/dist/lite-kernel.d.ts.map +1 -0
  34. package/dist/lite-kernel.js +112 -0
  35. package/dist/lite-kernel.test.d.ts +2 -0
  36. package/dist/lite-kernel.test.d.ts.map +1 -0
  37. package/dist/lite-kernel.test.js +161 -0
  38. package/dist/logger.d.ts +2 -2
  39. package/dist/logger.d.ts.map +1 -1
  40. package/dist/logger.js +26 -7
  41. package/dist/plugin-loader.d.ts +15 -0
  42. package/dist/plugin-loader.d.ts.map +1 -1
  43. package/dist/plugin-loader.js +40 -10
  44. package/dist/plugin-loader.test.js +9 -0
  45. package/dist/security/index.d.ts +3 -0
  46. package/dist/security/index.d.ts.map +1 -1
  47. package/dist/security/index.js +4 -0
  48. package/dist/security/permission-manager.d.ts +96 -0
  49. package/dist/security/permission-manager.d.ts.map +1 -0
  50. package/dist/security/permission-manager.js +235 -0
  51. package/dist/security/permission-manager.test.d.ts +2 -0
  52. package/dist/security/permission-manager.test.d.ts.map +1 -0
  53. package/dist/security/permission-manager.test.js +220 -0
  54. package/dist/security/plugin-permission-enforcer.d.ts +1 -1
  55. package/dist/security/sandbox-runtime.d.ts +115 -0
  56. package/dist/security/sandbox-runtime.d.ts.map +1 -0
  57. package/dist/security/sandbox-runtime.js +310 -0
  58. package/dist/security/security-scanner.d.ts +92 -0
  59. package/dist/security/security-scanner.d.ts.map +1 -0
  60. package/dist/security/security-scanner.js +273 -0
  61. package/examples/{enhanced-kernel-example.ts → kernel-features-example.ts} +6 -6
  62. package/examples/phase2-integration.ts +355 -0
  63. package/package.json +3 -2
  64. package/src/api-registry-plugin.test.ts +23 -21
  65. package/src/api-registry.test.ts +2 -2
  66. package/src/dependency-resolver.test.ts +287 -0
  67. package/src/dependency-resolver.ts +388 -0
  68. package/src/health-monitor.test.ts +81 -0
  69. package/src/health-monitor.ts +316 -0
  70. package/src/hot-reload.ts +388 -0
  71. package/src/index.ts +6 -1
  72. package/src/kernel-base.ts +2 -2
  73. package/src/kernel.test.ts +471 -134
  74. package/src/kernel.ts +518 -76
  75. package/src/lite-kernel.test.ts +200 -0
  76. package/src/lite-kernel.ts +135 -0
  77. package/src/logger.ts +28 -7
  78. package/src/plugin-loader.test.ts +10 -1
  79. package/src/plugin-loader.ts +49 -13
  80. package/src/security/index.ts +19 -0
  81. package/src/security/permission-manager.test.ts +256 -0
  82. package/src/security/permission-manager.ts +336 -0
  83. package/src/security/plugin-permission-enforcer.test.ts +1 -1
  84. package/src/security/plugin-permission-enforcer.ts +1 -1
  85. package/src/security/sandbox-runtime.ts +432 -0
  86. package/src/security/security-scanner.ts +365 -0
  87. package/dist/enhanced-kernel.d.ts +0 -103
  88. package/dist/enhanced-kernel.d.ts.map +0 -1
  89. package/dist/enhanced-kernel.js +0 -403
  90. package/dist/enhanced-kernel.test.d.ts +0 -2
  91. package/dist/enhanced-kernel.test.d.ts.map +0 -1
  92. package/dist/enhanced-kernel.test.js +0 -412
  93. package/src/enhanced-kernel.test.ts +0 -535
  94. package/src/enhanced-kernel.ts +0 -496
@@ -0,0 +1,317 @@
1
+ /**
2
+ * Semantic Version Parser and Comparator
3
+ *
4
+ * Implements semantic versioning comparison and constraint matching
5
+ */
6
+ export class SemanticVersionManager {
7
+ /**
8
+ * Parse a version string into semantic version components
9
+ */
10
+ static parse(versionStr) {
11
+ // Remove 'v' prefix if present
12
+ const cleanVersion = versionStr.replace(/^v/, '');
13
+ // Match semver pattern: major.minor.patch[-prerelease][+build]
14
+ const match = cleanVersion.match(/^(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9.-]+))?(?:\+([a-zA-Z0-9.-]+))?$/);
15
+ if (!match) {
16
+ throw new Error(`Invalid semantic version: ${versionStr}`);
17
+ }
18
+ return {
19
+ major: parseInt(match[1], 10),
20
+ minor: parseInt(match[2], 10),
21
+ patch: parseInt(match[3], 10),
22
+ preRelease: match[4],
23
+ build: match[5],
24
+ };
25
+ }
26
+ /**
27
+ * Convert semantic version back to string
28
+ */
29
+ static toString(version) {
30
+ let str = `${version.major}.${version.minor}.${version.patch}`;
31
+ if (version.preRelease) {
32
+ str += `-${version.preRelease}`;
33
+ }
34
+ if (version.build) {
35
+ str += `+${version.build}`;
36
+ }
37
+ return str;
38
+ }
39
+ /**
40
+ * Compare two semantic versions
41
+ * Returns: -1 if a < b, 0 if a === b, 1 if a > b
42
+ */
43
+ static compare(a, b) {
44
+ // Compare major, minor, patch
45
+ if (a.major !== b.major)
46
+ return a.major - b.major;
47
+ if (a.minor !== b.minor)
48
+ return a.minor - b.minor;
49
+ if (a.patch !== b.patch)
50
+ return a.patch - b.patch;
51
+ // Pre-release versions have lower precedence
52
+ if (a.preRelease && !b.preRelease)
53
+ return -1;
54
+ if (!a.preRelease && b.preRelease)
55
+ return 1;
56
+ // Compare pre-release versions
57
+ if (a.preRelease && b.preRelease) {
58
+ return a.preRelease.localeCompare(b.preRelease);
59
+ }
60
+ return 0;
61
+ }
62
+ /**
63
+ * Check if version satisfies constraint
64
+ */
65
+ static satisfies(version, constraint) {
66
+ const constraintStr = constraint;
67
+ // Any version
68
+ if (constraintStr === '*' || constraintStr === 'latest') {
69
+ return true;
70
+ }
71
+ // Exact version
72
+ if (/^[\d.]+$/.test(constraintStr)) {
73
+ const exact = this.parse(constraintStr);
74
+ return this.compare(version, exact) === 0;
75
+ }
76
+ // Caret range (^): Compatible with version
77
+ if (constraintStr.startsWith('^')) {
78
+ const base = this.parse(constraintStr.slice(1));
79
+ return (version.major === base.major &&
80
+ this.compare(version, base) >= 0);
81
+ }
82
+ // Tilde range (~): Approximately equivalent
83
+ if (constraintStr.startsWith('~')) {
84
+ const base = this.parse(constraintStr.slice(1));
85
+ return (version.major === base.major &&
86
+ version.minor === base.minor &&
87
+ this.compare(version, base) >= 0);
88
+ }
89
+ // Greater than or equal
90
+ if (constraintStr.startsWith('>=')) {
91
+ const base = this.parse(constraintStr.slice(2));
92
+ return this.compare(version, base) >= 0;
93
+ }
94
+ // Greater than
95
+ if (constraintStr.startsWith('>')) {
96
+ const base = this.parse(constraintStr.slice(1));
97
+ return this.compare(version, base) > 0;
98
+ }
99
+ // Less than or equal
100
+ if (constraintStr.startsWith('<=')) {
101
+ const base = this.parse(constraintStr.slice(2));
102
+ return this.compare(version, base) <= 0;
103
+ }
104
+ // Less than
105
+ if (constraintStr.startsWith('<')) {
106
+ const base = this.parse(constraintStr.slice(1));
107
+ return this.compare(version, base) < 0;
108
+ }
109
+ // Range (1.2.3 - 2.3.4)
110
+ const rangeMatch = constraintStr.match(/^([\d.]+)\s*-\s*([\d.]+)$/);
111
+ if (rangeMatch) {
112
+ const min = this.parse(rangeMatch[1]);
113
+ const max = this.parse(rangeMatch[2]);
114
+ return this.compare(version, min) >= 0 && this.compare(version, max) <= 0;
115
+ }
116
+ return false;
117
+ }
118
+ /**
119
+ * Determine compatibility level between two versions
120
+ */
121
+ static getCompatibilityLevel(from, to) {
122
+ const cmp = this.compare(from, to);
123
+ // Same version
124
+ if (cmp === 0) {
125
+ return 'fully-compatible';
126
+ }
127
+ // Major version changed - breaking changes
128
+ if (from.major !== to.major) {
129
+ return 'breaking-changes';
130
+ }
131
+ // Minor version increased - backward compatible
132
+ if (from.minor < to.minor) {
133
+ return 'backward-compatible';
134
+ }
135
+ // Patch version increased - fully compatible
136
+ if (from.patch < to.patch) {
137
+ return 'fully-compatible';
138
+ }
139
+ // Downgrade - incompatible
140
+ return 'incompatible';
141
+ }
142
+ }
143
+ /**
144
+ * Plugin Dependency Resolver
145
+ *
146
+ * Resolves plugin dependencies using topological sorting and conflict detection
147
+ */
148
+ export class DependencyResolver {
149
+ constructor(logger) {
150
+ this.logger = logger.child({ component: 'DependencyResolver' });
151
+ }
152
+ /**
153
+ * Resolve dependencies using topological sort
154
+ */
155
+ resolve(plugins) {
156
+ const graph = new Map();
157
+ const inDegree = new Map();
158
+ // Build dependency graph
159
+ for (const [pluginName, pluginInfo] of plugins) {
160
+ if (!graph.has(pluginName)) {
161
+ graph.set(pluginName, []);
162
+ inDegree.set(pluginName, 0);
163
+ }
164
+ const deps = pluginInfo.dependencies || [];
165
+ for (const dep of deps) {
166
+ // Check if dependency exists
167
+ if (!plugins.has(dep)) {
168
+ throw new Error(`Missing dependency: ${pluginName} requires ${dep}`);
169
+ }
170
+ // Add edge
171
+ if (!graph.has(dep)) {
172
+ graph.set(dep, []);
173
+ inDegree.set(dep, 0);
174
+ }
175
+ graph.get(dep).push(pluginName);
176
+ inDegree.set(pluginName, (inDegree.get(pluginName) || 0) + 1);
177
+ }
178
+ }
179
+ // Topological sort using Kahn's algorithm
180
+ const queue = [];
181
+ const result = [];
182
+ // Add all nodes with no incoming edges
183
+ for (const [node, degree] of inDegree) {
184
+ if (degree === 0) {
185
+ queue.push(node);
186
+ }
187
+ }
188
+ while (queue.length > 0) {
189
+ const node = queue.shift();
190
+ result.push(node);
191
+ // Reduce in-degree for dependent nodes
192
+ const dependents = graph.get(node) || [];
193
+ for (const dependent of dependents) {
194
+ const newDegree = (inDegree.get(dependent) || 0) - 1;
195
+ inDegree.set(dependent, newDegree);
196
+ if (newDegree === 0) {
197
+ queue.push(dependent);
198
+ }
199
+ }
200
+ }
201
+ // Check for circular dependencies
202
+ if (result.length !== plugins.size) {
203
+ const remaining = Array.from(plugins.keys()).filter(p => !result.includes(p));
204
+ this.logger.error('Circular dependency detected', { remaining });
205
+ throw new Error(`Circular dependency detected among: ${remaining.join(', ')}`);
206
+ }
207
+ this.logger.debug('Dependencies resolved', { order: result });
208
+ return result;
209
+ }
210
+ /**
211
+ * Detect dependency conflicts
212
+ */
213
+ detectConflicts(plugins) {
214
+ const conflicts = [];
215
+ const versionRequirements = new Map();
216
+ // Collect all version requirements
217
+ for (const [pluginName, pluginInfo] of plugins) {
218
+ if (!pluginInfo.dependencies)
219
+ continue;
220
+ for (const [depName, constraint] of Object.entries(pluginInfo.dependencies)) {
221
+ if (!versionRequirements.has(depName)) {
222
+ versionRequirements.set(depName, new Map());
223
+ }
224
+ versionRequirements.get(depName).set(pluginName, constraint);
225
+ }
226
+ }
227
+ // Check for version mismatches
228
+ for (const [depName, requirements] of versionRequirements) {
229
+ const depInfo = plugins.get(depName);
230
+ if (!depInfo)
231
+ continue;
232
+ const depVersion = SemanticVersionManager.parse(depInfo.version);
233
+ const unsatisfied = [];
234
+ for (const [requiringPlugin, constraint] of requirements) {
235
+ if (!SemanticVersionManager.satisfies(depVersion, constraint)) {
236
+ unsatisfied.push({
237
+ pluginId: requiringPlugin,
238
+ version: constraint,
239
+ });
240
+ }
241
+ }
242
+ if (unsatisfied.length > 0) {
243
+ conflicts.push({
244
+ type: 'version-mismatch',
245
+ severity: 'error',
246
+ description: `Version mismatch for ${depName}: detected ${unsatisfied.length} unsatisfied requirements`,
247
+ plugins: [
248
+ { pluginId: depName, version: depInfo.version },
249
+ ...unsatisfied,
250
+ ],
251
+ resolutions: [{
252
+ strategy: 'upgrade',
253
+ description: `Upgrade ${depName} to satisfy all constraints`,
254
+ targetPlugins: [depName],
255
+ automatic: false,
256
+ }],
257
+ });
258
+ }
259
+ }
260
+ // Check for circular dependencies (will be caught by resolve())
261
+ try {
262
+ this.resolve(new Map(Array.from(plugins.entries()).map(([name, info]) => [
263
+ name,
264
+ { version: info.version, dependencies: info.dependencies ? Object.keys(info.dependencies) : [] }
265
+ ])));
266
+ }
267
+ catch (error) {
268
+ if (error instanceof Error && error.message.includes('Circular dependency')) {
269
+ conflicts.push({
270
+ type: 'circular-dependency',
271
+ severity: 'critical',
272
+ description: error.message,
273
+ plugins: [], // Would need to extract from error
274
+ resolutions: [{
275
+ strategy: 'manual',
276
+ description: 'Remove circular dependency by restructuring plugins',
277
+ automatic: false,
278
+ }],
279
+ });
280
+ }
281
+ }
282
+ return conflicts;
283
+ }
284
+ /**
285
+ * Find best version that satisfies all constraints
286
+ */
287
+ findBestVersion(availableVersions, constraints) {
288
+ // Parse and sort versions (highest first)
289
+ const versions = availableVersions
290
+ .map(v => ({ str: v, parsed: SemanticVersionManager.parse(v) }))
291
+ .sort((a, b) => -SemanticVersionManager.compare(a.parsed, b.parsed));
292
+ // Find highest version that satisfies all constraints
293
+ for (const version of versions) {
294
+ const satisfiesAll = constraints.every(constraint => SemanticVersionManager.satisfies(version.parsed, constraint));
295
+ if (satisfiesAll) {
296
+ return version.str;
297
+ }
298
+ }
299
+ return undefined;
300
+ }
301
+ /**
302
+ * Check if dependencies form a valid DAG (no cycles)
303
+ */
304
+ isAcyclic(dependencies) {
305
+ try {
306
+ const plugins = new Map(Array.from(dependencies.entries()).map(([name, deps]) => [
307
+ name,
308
+ { dependencies: deps }
309
+ ]));
310
+ this.resolve(plugins);
311
+ return true;
312
+ }
313
+ catch {
314
+ return false;
315
+ }
316
+ }
317
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=dependency-resolver.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependency-resolver.test.d.ts","sourceRoot":"","sources":["../src/dependency-resolver.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,241 @@
1
+ import { describe, it, expect, beforeEach } from 'vitest';
2
+ import { SemanticVersionManager, DependencyResolver } from './dependency-resolver.js';
3
+ import { createLogger } from './logger.js';
4
+ describe('SemanticVersionManager', () => {
5
+ describe('parse', () => {
6
+ it('should parse standard semver', () => {
7
+ const version = SemanticVersionManager.parse('1.2.3');
8
+ expect(version).toEqual({
9
+ major: 1,
10
+ minor: 2,
11
+ patch: 3,
12
+ preRelease: undefined,
13
+ build: undefined,
14
+ });
15
+ });
16
+ it('should parse semver with pre-release', () => {
17
+ const version = SemanticVersionManager.parse('1.2.3-alpha.1');
18
+ expect(version).toEqual({
19
+ major: 1,
20
+ minor: 2,
21
+ patch: 3,
22
+ preRelease: 'alpha.1',
23
+ build: undefined,
24
+ });
25
+ });
26
+ it('should parse semver with build metadata', () => {
27
+ const version = SemanticVersionManager.parse('1.2.3+build.123');
28
+ expect(version).toEqual({
29
+ major: 1,
30
+ minor: 2,
31
+ patch: 3,
32
+ preRelease: undefined,
33
+ build: 'build.123',
34
+ });
35
+ });
36
+ it('should parse semver with both pre-release and build', () => {
37
+ const version = SemanticVersionManager.parse('1.2.3-beta.2+build.456');
38
+ expect(version).toEqual({
39
+ major: 1,
40
+ minor: 2,
41
+ patch: 3,
42
+ preRelease: 'beta.2',
43
+ build: 'build.456',
44
+ });
45
+ });
46
+ it('should handle v prefix', () => {
47
+ const version = SemanticVersionManager.parse('v1.2.3');
48
+ expect(version.major).toBe(1);
49
+ expect(version.minor).toBe(2);
50
+ expect(version.patch).toBe(3);
51
+ });
52
+ });
53
+ describe('compare', () => {
54
+ it('should compare major versions', () => {
55
+ const v1 = SemanticVersionManager.parse('2.0.0');
56
+ const v2 = SemanticVersionManager.parse('1.0.0');
57
+ expect(SemanticVersionManager.compare(v1, v2)).toBeGreaterThan(0);
58
+ expect(SemanticVersionManager.compare(v2, v1)).toBeLessThan(0);
59
+ });
60
+ it('should compare minor versions', () => {
61
+ const v1 = SemanticVersionManager.parse('1.2.0');
62
+ const v2 = SemanticVersionManager.parse('1.1.0');
63
+ expect(SemanticVersionManager.compare(v1, v2)).toBeGreaterThan(0);
64
+ });
65
+ it('should compare patch versions', () => {
66
+ const v1 = SemanticVersionManager.parse('1.0.2');
67
+ const v2 = SemanticVersionManager.parse('1.0.1');
68
+ expect(SemanticVersionManager.compare(v1, v2)).toBeGreaterThan(0);
69
+ });
70
+ it('should handle equal versions', () => {
71
+ const v1 = SemanticVersionManager.parse('1.2.3');
72
+ const v2 = SemanticVersionManager.parse('1.2.3');
73
+ expect(SemanticVersionManager.compare(v1, v2)).toBe(0);
74
+ });
75
+ it('should treat pre-release as lower than release', () => {
76
+ const v1 = SemanticVersionManager.parse('1.0.0-alpha');
77
+ const v2 = SemanticVersionManager.parse('1.0.0');
78
+ expect(SemanticVersionManager.compare(v1, v2)).toBeLessThan(0);
79
+ });
80
+ });
81
+ describe('satisfies', () => {
82
+ it('should match exact version', () => {
83
+ const version = SemanticVersionManager.parse('1.2.3');
84
+ expect(SemanticVersionManager.satisfies(version, '1.2.3')).toBe(true);
85
+ expect(SemanticVersionManager.satisfies(version, '1.2.4')).toBe(false);
86
+ });
87
+ it('should match caret range', () => {
88
+ const version = SemanticVersionManager.parse('1.2.5');
89
+ expect(SemanticVersionManager.satisfies(version, '^1.2.3')).toBe(true);
90
+ expect(SemanticVersionManager.satisfies(version, '^1.3.0')).toBe(false);
91
+ expect(SemanticVersionManager.satisfies(version, '^2.0.0')).toBe(false);
92
+ });
93
+ it('should match tilde range', () => {
94
+ const version = SemanticVersionManager.parse('1.2.5');
95
+ expect(SemanticVersionManager.satisfies(version, '~1.2.3')).toBe(true);
96
+ expect(SemanticVersionManager.satisfies(version, '~1.3.0')).toBe(false);
97
+ });
98
+ it('should match greater than or equal', () => {
99
+ const version = SemanticVersionManager.parse('1.2.5');
100
+ expect(SemanticVersionManager.satisfies(version, '>=1.2.3')).toBe(true);
101
+ expect(SemanticVersionManager.satisfies(version, '>=1.2.5')).toBe(true);
102
+ expect(SemanticVersionManager.satisfies(version, '>=1.3.0')).toBe(false);
103
+ });
104
+ it('should match less than', () => {
105
+ const version = SemanticVersionManager.parse('1.2.5');
106
+ expect(SemanticVersionManager.satisfies(version, '<1.3.0')).toBe(true);
107
+ expect(SemanticVersionManager.satisfies(version, '<1.2.5')).toBe(false);
108
+ });
109
+ it('should match range', () => {
110
+ const version = SemanticVersionManager.parse('1.2.5');
111
+ expect(SemanticVersionManager.satisfies(version, '1.2.0 - 1.3.0')).toBe(true);
112
+ expect(SemanticVersionManager.satisfies(version, '1.3.0 - 1.4.0')).toBe(false);
113
+ });
114
+ it('should match wildcard', () => {
115
+ const version = SemanticVersionManager.parse('1.2.5');
116
+ expect(SemanticVersionManager.satisfies(version, '*')).toBe(true);
117
+ expect(SemanticVersionManager.satisfies(version, 'latest')).toBe(true);
118
+ });
119
+ });
120
+ describe('getCompatibilityLevel', () => {
121
+ it('should detect fully compatible versions', () => {
122
+ const from = SemanticVersionManager.parse('1.2.3');
123
+ const to = SemanticVersionManager.parse('1.2.3');
124
+ expect(SemanticVersionManager.getCompatibilityLevel(from, to)).toBe('fully-compatible');
125
+ });
126
+ it('should detect backward compatible versions', () => {
127
+ const from = SemanticVersionManager.parse('1.2.3');
128
+ const to = SemanticVersionManager.parse('1.3.0');
129
+ expect(SemanticVersionManager.getCompatibilityLevel(from, to)).toBe('backward-compatible');
130
+ });
131
+ it('should detect breaking changes', () => {
132
+ const from = SemanticVersionManager.parse('1.2.3');
133
+ const to = SemanticVersionManager.parse('2.0.0');
134
+ expect(SemanticVersionManager.getCompatibilityLevel(from, to)).toBe('breaking-changes');
135
+ });
136
+ it('should detect incompatible (downgrade)', () => {
137
+ const from = SemanticVersionManager.parse('1.3.0');
138
+ const to = SemanticVersionManager.parse('1.2.0');
139
+ expect(SemanticVersionManager.getCompatibilityLevel(from, to)).toBe('incompatible');
140
+ });
141
+ });
142
+ });
143
+ describe('DependencyResolver', () => {
144
+ let resolver;
145
+ let logger;
146
+ beforeEach(() => {
147
+ logger = createLogger({ level: 'silent' });
148
+ resolver = new DependencyResolver(logger);
149
+ });
150
+ describe('resolve', () => {
151
+ it('should resolve dependencies in topological order', () => {
152
+ const plugins = new Map([
153
+ ['a', { dependencies: [] }],
154
+ ['b', { dependencies: ['a'] }],
155
+ ['c', { dependencies: ['a', 'b'] }],
156
+ ]);
157
+ const order = resolver.resolve(plugins);
158
+ expect(order.indexOf('a')).toBeLessThan(order.indexOf('b'));
159
+ expect(order.indexOf('b')).toBeLessThan(order.indexOf('c'));
160
+ });
161
+ it('should handle plugins with no dependencies', () => {
162
+ const plugins = new Map([
163
+ ['a', { dependencies: [] }],
164
+ ['b', { dependencies: [] }],
165
+ ]);
166
+ const order = resolver.resolve(plugins);
167
+ expect(order).toHaveLength(2);
168
+ expect(order).toContain('a');
169
+ expect(order).toContain('b');
170
+ });
171
+ it('should detect circular dependencies', () => {
172
+ const plugins = new Map([
173
+ ['a', { dependencies: ['b'] }],
174
+ ['b', { dependencies: ['a'] }],
175
+ ]);
176
+ expect(() => resolver.resolve(plugins)).toThrow('Circular dependency');
177
+ });
178
+ it('should detect missing dependencies', () => {
179
+ const plugins = new Map([
180
+ ['a', { dependencies: ['missing'] }],
181
+ ]);
182
+ expect(() => resolver.resolve(plugins)).toThrow('Missing dependency');
183
+ });
184
+ });
185
+ describe('detectConflicts', () => {
186
+ it('should detect version mismatches', () => {
187
+ const plugins = new Map([
188
+ ['core', { version: '1.0.0', dependencies: {} }],
189
+ ['plugin-a', { version: '1.0.0', dependencies: { core: '^2.0.0' } }],
190
+ ]);
191
+ const conflicts = resolver.detectConflicts(plugins);
192
+ expect(conflicts.length).toBeGreaterThan(0);
193
+ expect(conflicts[0].type).toBe('version-mismatch');
194
+ });
195
+ it('should return no conflicts for compatible versions', () => {
196
+ const plugins = new Map([
197
+ ['core', { version: '1.2.0', dependencies: {} }],
198
+ ['plugin-a', { version: '1.0.0', dependencies: { core: '^1.0.0' } }],
199
+ ]);
200
+ const conflicts = resolver.detectConflicts(plugins);
201
+ expect(conflicts.length).toBe(0);
202
+ });
203
+ });
204
+ describe('findBestVersion', () => {
205
+ it('should find highest matching version', () => {
206
+ const available = ['1.0.0', '1.1.0', '1.2.0', '2.0.0'];
207
+ const constraints = ['^1.0.0'];
208
+ const best = resolver.findBestVersion(available, constraints);
209
+ expect(best).toBe('1.2.0');
210
+ });
211
+ it('should satisfy all constraints', () => {
212
+ const available = ['1.0.0', '1.1.0', '1.2.0', '2.0.0'];
213
+ const constraints = ['^1.0.0', '>=1.1.0', '<2.0.0'];
214
+ const best = resolver.findBestVersion(available, constraints);
215
+ expect(best).toBe('1.2.0');
216
+ });
217
+ it('should return undefined if no version satisfies', () => {
218
+ const available = ['1.0.0', '1.1.0'];
219
+ const constraints = ['^2.0.0'];
220
+ const best = resolver.findBestVersion(available, constraints);
221
+ expect(best).toBeUndefined();
222
+ });
223
+ });
224
+ describe('isAcyclic', () => {
225
+ it('should detect acyclic graph', () => {
226
+ const deps = new Map([
227
+ ['a', []],
228
+ ['b', ['a']],
229
+ ['c', ['a', 'b']],
230
+ ]);
231
+ expect(resolver.isAcyclic(deps)).toBe(true);
232
+ });
233
+ it('should detect cyclic graph', () => {
234
+ const deps = new Map([
235
+ ['a', ['b']],
236
+ ['b', ['a']],
237
+ ]);
238
+ expect(resolver.isAcyclic(deps)).toBe(false);
239
+ });
240
+ });
241
+ });
@@ -0,0 +1,65 @@
1
+ import type { PluginHealthStatus, PluginHealthCheck, PluginHealthReport } from '@objectstack/spec/kernel';
2
+ import type { ObjectLogger } from './logger.js';
3
+ import type { Plugin } from './types.js';
4
+ /**
5
+ * Plugin Health Monitor
6
+ *
7
+ * Monitors plugin health status and performs automatic recovery actions.
8
+ * Implements the advanced lifecycle health monitoring protocol.
9
+ */
10
+ export declare class PluginHealthMonitor {
11
+ private logger;
12
+ private healthChecks;
13
+ private healthStatus;
14
+ private healthReports;
15
+ private checkIntervals;
16
+ private failureCounters;
17
+ private successCounters;
18
+ private restartAttempts;
19
+ constructor(logger: ObjectLogger);
20
+ /**
21
+ * Register a plugin for health monitoring
22
+ */
23
+ registerPlugin(pluginName: string, config: PluginHealthCheck): void;
24
+ /**
25
+ * Start monitoring a plugin
26
+ */
27
+ startMonitoring(pluginName: string, plugin: Plugin): void;
28
+ /**
29
+ * Stop monitoring a plugin
30
+ */
31
+ stopMonitoring(pluginName: string): void;
32
+ /**
33
+ * Perform a health check on a plugin
34
+ */
35
+ private performHealthCheck;
36
+ /**
37
+ * Attempt to restart a plugin
38
+ */
39
+ private attemptRestart;
40
+ /**
41
+ * Calculate backoff delay for restarts
42
+ */
43
+ private calculateBackoff;
44
+ /**
45
+ * Get current health status of a plugin
46
+ */
47
+ getHealthStatus(pluginName: string): PluginHealthStatus | undefined;
48
+ /**
49
+ * Get latest health report for a plugin
50
+ */
51
+ getHealthReport(pluginName: string): PluginHealthReport | undefined;
52
+ /**
53
+ * Get all health statuses
54
+ */
55
+ getAllHealthStatuses(): Map<string, PluginHealthStatus>;
56
+ /**
57
+ * Shutdown health monitor
58
+ */
59
+ shutdown(): void;
60
+ /**
61
+ * Timeout helper
62
+ */
63
+ private timeout;
64
+ }
65
+ //# sourceMappingURL=health-monitor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health-monitor.d.ts","sourceRoot":"","sources":["../src/health-monitor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC;;;;;GAKG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,YAAY,CAAwC;IAC5D,OAAO,CAAC,YAAY,CAAyC;IAC7D,OAAO,CAAC,aAAa,CAAyC;IAC9D,OAAO,CAAC,cAAc,CAAqC;IAC3D,OAAO,CAAC,eAAe,CAA6B;IACpD,OAAO,CAAC,eAAe,CAA6B;IACpD,OAAO,CAAC,eAAe,CAA6B;gBAExC,MAAM,EAAE,YAAY;IAIhC;;OAEG;IACH,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,GAAG,IAAI;IAanE;;OAEG;IACH,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAgCzD;;OAEG;IACH,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IASxC;;OAEG;YACW,kBAAkB;IAoGhC;;OAEG;YACW,cAAc;IAoD5B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAexB;;OAEG;IACH,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAInE;;OAEG;IACH,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAInE;;OAEG;IACH,oBAAoB,IAAI,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC;IAIvD;;OAEG;IACH,QAAQ,IAAI,IAAI;IAgBhB;;OAEG;IACH,OAAO,CAAC,OAAO;CAKhB"}