@tamyla/clodo-framework 3.1.10 → 3.1.11

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 (73) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/bin/clodo-service-old.js +2 -2
  3. package/dist/bin/commands/create.js +1 -1
  4. package/dist/bin/commands/diagnose.js +1 -1
  5. package/dist/bin/commands/update.js +1 -1
  6. package/dist/bin/commands/validate.js +1 -1
  7. package/dist/bin/database/enterprise-db-manager.js +3 -3
  8. package/dist/bin/deployment/enterprise-deploy.js +3 -3
  9. package/dist/bin/deployment/master-deploy.js +3 -3
  10. package/dist/bin/deployment/modular-enterprise-deploy.js +3 -3
  11. package/dist/bin/deployment/modules/DeploymentOrchestrator.js +1 -1
  12. package/dist/bin/deployment/modules/EnvironmentManager.js +2 -2
  13. package/dist/bin/portfolio/portfolio-manager.js +3 -3
  14. package/dist/bin/security/security-cli.js +1 -1
  15. package/dist/bin/service-management/create-service.js +1 -1
  16. package/dist/bin/service-management/init-service.js +1 -1
  17. package/dist/bin/shared/cloudflare/domain-manager.js +1 -1
  18. package/dist/bin/shared/validation/ValidationRegistry.js +1 -1
  19. package/package.json +1 -6
  20. package/bin/README.md +0 -71
  21. package/bin/clodo-service.js +0 -72
  22. package/bin/database/README.md +0 -33
  23. package/bin/database/deployment-db-manager.js +0 -527
  24. package/bin/database/enterprise-db-manager.js +0 -738
  25. package/bin/database/wrangler-d1-manager.js +0 -775
  26. package/bin/security/security-cli.js +0 -117
  27. package/bin/service-management/README.md +0 -74
  28. package/bin/service-management/create-service.js +0 -129
  29. package/bin/service-management/init-service.js +0 -103
  30. package/bin/service-management/init-service.js.backup +0 -889
  31. package/bin/shared/cloudflare/domain-discovery.js +0 -637
  32. package/bin/shared/cloudflare/domain-manager.js +0 -952
  33. package/bin/shared/cloudflare/index.js +0 -8
  34. package/bin/shared/cloudflare/ops.js +0 -401
  35. package/bin/shared/config/ConfigurationManager.js +0 -539
  36. package/bin/shared/config/cache.js +0 -1230
  37. package/bin/shared/config/command-config-manager.js +0 -184
  38. package/bin/shared/config/index.js +0 -21
  39. package/bin/shared/config/manager.js +0 -315
  40. package/bin/shared/database/connection-manager.js +0 -374
  41. package/bin/shared/database/index.js +0 -7
  42. package/bin/shared/database/orchestrator.js +0 -727
  43. package/bin/shared/deployment/auditor.js +0 -970
  44. package/bin/shared/deployment/index.js +0 -10
  45. package/bin/shared/deployment/rollback-manager.js +0 -570
  46. package/bin/shared/deployment/validator.js +0 -779
  47. package/bin/shared/index.js +0 -32
  48. package/bin/shared/logging/Logger.js +0 -214
  49. package/bin/shared/monitoring/health-checker.js +0 -484
  50. package/bin/shared/monitoring/index.js +0 -8
  51. package/bin/shared/monitoring/memory-manager.js +0 -387
  52. package/bin/shared/monitoring/production-monitor.js +0 -403
  53. package/bin/shared/production-tester/api-tester.js +0 -82
  54. package/bin/shared/production-tester/auth-tester.js +0 -132
  55. package/bin/shared/production-tester/core.js +0 -197
  56. package/bin/shared/production-tester/database-tester.js +0 -109
  57. package/bin/shared/production-tester/index.js +0 -77
  58. package/bin/shared/production-tester/load-tester.js +0 -131
  59. package/bin/shared/production-tester/performance-tester.js +0 -103
  60. package/bin/shared/security/api-token-manager.js +0 -312
  61. package/bin/shared/security/index.js +0 -8
  62. package/bin/shared/security/secret-generator.js +0 -942
  63. package/bin/shared/security/secure-token-manager.js +0 -398
  64. package/bin/shared/utils/ErrorHandler.js +0 -675
  65. package/bin/shared/utils/error-recovery.js +0 -245
  66. package/bin/shared/utils/file-manager.js +0 -162
  67. package/bin/shared/utils/formatters.js +0 -247
  68. package/bin/shared/utils/graceful-shutdown-manager.js +0 -390
  69. package/bin/shared/utils/index.js +0 -19
  70. package/bin/shared/utils/interactive-prompts.js +0 -146
  71. package/bin/shared/utils/interactive-utils.js +0 -530
  72. package/bin/shared/utils/rate-limiter.js +0 -246
  73. package/bin/shared/validation/ValidationRegistry.js +0 -143
@@ -1,387 +0,0 @@
1
- /**
2
- * Memory Manager
3
- * Implements memory leak prevention and cleanup routines for long-running processes
4
- */
5
-
6
- export class MemoryManager {
7
- constructor(options = {}) {
8
- this.config = {
9
- gcInterval: options.gcInterval || 300000, // 5 minutes
10
- memoryThreshold: options.memoryThreshold || 0.8, // 80% of heap
11
- maxHeapSize: options.maxHeapSize || 512 * 1024 * 1024, // 512MB
12
- enableGcHints: options.enableGcHints !== false,
13
- cleanupInterval: options.cleanupInterval || 60000, // 1 minute
14
- leakDetection: options.leakDetection !== false,
15
- ...options
16
- };
17
-
18
- this.gcIntervalId = null;
19
- this.cleanupIntervalId = null;
20
- this.memoryStats = [];
21
- this.eventListeners = new Set();
22
- this.timers = new Set();
23
- this.intervals = new Set();
24
- this.isMonitoring = false;
25
-
26
- // Bind methods to preserve context
27
- this.gcCallback = this.gcCallback.bind(this);
28
- this.cleanupCallback = this.cleanupCallback.bind(this);
29
- }
30
-
31
- /**
32
- * Start memory monitoring and cleanup
33
- */
34
- startMonitoring() {
35
- if (this.isMonitoring) return;
36
-
37
- this.isMonitoring = true;
38
-
39
- if (this.config.enableGcHints) {
40
- this.gcIntervalId = setInterval(this.gcCallback, this.config.gcInterval);
41
- this.gcIntervalId.unref?.(); // Don't keep process alive
42
- }
43
-
44
- this.cleanupIntervalId = setInterval(this.cleanupCallback, this.config.cleanupInterval);
45
- this.cleanupIntervalId.unref?.();
46
-
47
- // Register process cleanup handlers
48
- this.registerProcessHandlers();
49
-
50
- console.log('🧠 Memory monitoring started');
51
- }
52
-
53
- /**
54
- * Stop memory monitoring
55
- */
56
- stopMonitoring() {
57
- if (!this.isMonitoring) return;
58
-
59
- this.isMonitoring = false;
60
-
61
- if (this.gcIntervalId) {
62
- clearInterval(this.gcIntervalId);
63
- this.gcIntervalId = null;
64
- }
65
-
66
- if (this.cleanupIntervalId) {
67
- clearInterval(this.cleanupIntervalId);
68
- this.cleanupIntervalId = null;
69
- }
70
-
71
- this.unregisterProcessHandlers();
72
-
73
- console.log('🧠 Memory monitoring stopped');
74
- }
75
-
76
- /**
77
- * Garbage collection callback
78
- */
79
- gcCallback() {
80
- const memUsage = process.memoryUsage();
81
-
82
- // Store memory stats for trend analysis
83
- this.memoryStats.push({
84
- timestamp: Date.now(),
85
- ...memUsage
86
- });
87
-
88
- // Keep only last 100 readings
89
- if (this.memoryStats.length > 100) {
90
- this.memoryStats.shift();
91
- }
92
-
93
- // Check memory thresholds
94
- const heapUsagePercent = memUsage.heapUsed / memUsage.heapTotal;
95
-
96
- if (heapUsagePercent > this.config.memoryThreshold) {
97
- console.warn(`⚠️ High memory usage detected: ${(heapUsagePercent * 100).toFixed(1)}%`);
98
-
99
- // Force garbage collection if available
100
- if (global.gc) {
101
- console.log('🗑️ Running forced garbage collection');
102
- global.gc();
103
- }
104
-
105
- // Run cleanup routines
106
- this.runCleanupRoutines();
107
- }
108
-
109
- // Check for memory leaks
110
- if (this.config.leakDetection) {
111
- this.detectMemoryLeaks();
112
- }
113
- }
114
-
115
- /**
116
- * Cleanup callback
117
- */
118
- cleanupCallback() {
119
- this.runCleanupRoutines();
120
- }
121
-
122
- /**
123
- * Run cleanup routines
124
- */
125
- runCleanupRoutines() {
126
- // Clear expired cache entries
127
- this.clearExpiredCache();
128
-
129
- // Clean up event listeners
130
- this.cleanupEventListeners();
131
-
132
- // Clean up timers and intervals
133
- this.cleanupTimers();
134
-
135
- // Force garbage collection hint
136
- if (global.gc) {
137
- global.gc();
138
- }
139
- }
140
-
141
- /**
142
- * Clear expired cache entries
143
- */
144
- clearExpiredCache() {
145
- // This would integrate with cache managers
146
- // For now, just hint that caches should be cleaned
147
- if (typeof global !== 'undefined' && global.cacheManagers) {
148
- global.cacheManagers.forEach(manager => {
149
- if (typeof manager.cleanup === 'function') {
150
- manager.cleanup();
151
- }
152
- });
153
- }
154
- }
155
-
156
- /**
157
- * Clean up event listeners
158
- */
159
- cleanupEventListeners() {
160
- // Remove listeners that are no longer needed
161
- // This is a placeholder - actual implementation would track listeners
162
- }
163
-
164
- /**
165
- * Clean up timers and intervals
166
- */
167
- cleanupTimers() {
168
- // Clear any timers that may have been leaked
169
- // This is a placeholder - actual implementation would track timers
170
- }
171
-
172
- /**
173
- * Detect memory leaks
174
- */
175
- detectMemoryLeaks() {
176
- if (this.memoryStats.length < 10) return;
177
-
178
- const recent = this.memoryStats.slice(-10);
179
- const older = this.memoryStats.slice(-20, -10);
180
-
181
- if (recent.length === 0 || older.length === 0) return;
182
-
183
- const recentAvg = recent.reduce((sum, stat) => sum + stat.heapUsed, 0) / recent.length;
184
- const olderAvg = older.reduce((sum, stat) => sum + stat.heapUsed, 0) / older.length;
185
-
186
- const growthRate = (recentAvg - olderAvg) / olderAvg;
187
-
188
- if (growthRate > 0.1) { // 10% growth
189
- console.warn(`🚨 Potential memory leak detected: ${(growthRate * 100).toFixed(1)}% growth over time`);
190
- }
191
- }
192
-
193
- /**
194
- * Register process signal handlers
195
- */
196
- registerProcessHandlers() {
197
- // Handle graceful shutdown
198
- process.on('SIGTERM', () => this.gracefulShutdown('SIGTERM'));
199
- process.on('SIGINT', () => this.gracefulShutdown('SIGINT'));
200
-
201
- // Handle uncaught exceptions
202
- process.on('uncaughtException', (error) => {
203
- console.error('💥 Uncaught exception:', error);
204
- this.gracefulShutdown('uncaughtException');
205
- });
206
-
207
- // Handle unhandled promise rejections
208
- process.on('unhandledRejection', (reason, promise) => {
209
- console.error('💥 Unhandled rejection at:', promise, 'reason:', reason);
210
- this.gracefulShutdown('unhandledRejection');
211
- });
212
- }
213
-
214
- /**
215
- * Unregister process signal handlers
216
- */
217
- unregisterProcessHandlers() {
218
- process.removeAllListeners('SIGTERM');
219
- process.removeAllListeners('SIGINT');
220
- process.removeAllListeners('uncaughtException');
221
- process.removeAllListeners('unhandledRejection');
222
- }
223
-
224
- /**
225
- * Graceful shutdown
226
- */
227
- gracefulShutdown(reason) {
228
- console.log(`🛑 Graceful shutdown initiated: ${reason}`);
229
-
230
- // Stop monitoring
231
- this.stopMonitoring();
232
-
233
- // Run final cleanup
234
- this.runCleanupRoutines();
235
-
236
- // Force final garbage collection
237
- if (global.gc) {
238
- global.gc();
239
- }
240
-
241
- // Exit gracefully
242
- process.exit(0);
243
- }
244
-
245
- /**
246
- * Track an event listener for cleanup
247
- */
248
- trackEventListener(emitter, event, listener) {
249
- const tracked = { emitter, event, listener };
250
- this.eventListeners.add(tracked);
251
-
252
- // Return cleanup function
253
- return () => {
254
- emitter.removeListener(event, listener);
255
- this.eventListeners.delete(tracked);
256
- };
257
- }
258
-
259
- /**
260
- * Track a timer for cleanup
261
- */
262
- trackTimer(timerId) {
263
- this.timers.add(timerId);
264
-
265
- // Return cleanup function
266
- return () => {
267
- clearTimeout(timerId);
268
- this.timers.delete(timerId);
269
- };
270
- }
271
-
272
- /**
273
- * Track an interval for cleanup
274
- */
275
- trackInterval(intervalId) {
276
- this.intervals.add(intervalId);
277
-
278
- // Return cleanup function
279
- return () => {
280
- clearInterval(intervalId);
281
- this.intervals.delete(intervalId);
282
- };
283
- }
284
-
285
- /**
286
- * Get memory statistics
287
- */
288
- getMemoryStats() {
289
- const memUsage = process.memoryUsage();
290
-
291
- return {
292
- current: {
293
- rss: memUsage.rss / 1024 / 1024, // MB
294
- heapUsed: memUsage.heapUsed / 1024 / 1024, // MB
295
- heapTotal: memUsage.heapTotal / 1024 / 1024, // MB
296
- external: memUsage.external / 1024 / 1024, // MB
297
- heapUsagePercent: (memUsage.heapUsed / memUsage.heapTotal) * 100
298
- },
299
- history: this.memoryStats.slice(-10), // Last 10 readings
300
- thresholds: {
301
- memoryThreshold: this.config.memoryThreshold * 100,
302
- maxHeapSize: this.config.maxHeapSize / 1024 / 1024
303
- },
304
- tracking: {
305
- eventListeners: this.eventListeners.size,
306
- timers: this.timers.size,
307
- intervals: this.intervals.size
308
- }
309
- };
310
- }
311
-
312
- /**
313
- * Force garbage collection (if available)
314
- */
315
- forceGc() {
316
- if (global.gc) {
317
- console.log('🗑️ Forced garbage collection');
318
- global.gc();
319
- return true;
320
- }
321
- return false;
322
- }
323
-
324
- /**
325
- * Create a memory-safe interval
326
- */
327
- createSafeInterval(callback, delay) {
328
- const intervalId = setInterval(() => {
329
- try {
330
- callback();
331
- } catch (error) {
332
- console.error('Error in safe interval:', error);
333
- // Could remove the interval if it keeps failing
334
- }
335
- }, delay);
336
-
337
- intervalId.unref?.();
338
- return this.trackInterval(intervalId);
339
- }
340
-
341
- /**
342
- * Create a memory-safe timeout
343
- */
344
- createSafeTimeout(callback, delay) {
345
- const timeoutId = setTimeout(() => {
346
- try {
347
- callback();
348
- } catch (error) {
349
- console.error('Error in safe timeout:', error);
350
- }
351
- }, delay);
352
-
353
- timeoutId.unref?.();
354
- return this.trackTimer(timeoutId);
355
- }
356
- }
357
-
358
- // Global memory manager instance
359
- let globalMemoryManager = null;
360
-
361
- /**
362
- * Get the global memory manager instance
363
- */
364
- export function getMemoryManager(options = {}) {
365
- if (!globalMemoryManager) {
366
- globalMemoryManager = new MemoryManager(options);
367
- }
368
- return globalMemoryManager;
369
- }
370
-
371
- /**
372
- * Start global memory monitoring
373
- */
374
- export function startMemoryMonitoring(options = {}) {
375
- const manager = getMemoryManager(options);
376
- manager.startMonitoring();
377
- return manager;
378
- }
379
-
380
- /**
381
- * Stop global memory monitoring
382
- */
383
- export function stopMemoryMonitoring() {
384
- if (globalMemoryManager) {
385
- globalMemoryManager.stopMonitoring();
386
- }
387
- }