jerkjs 2.5.6 → 2.6.1

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 (46) hide show
  1. package/CHANGELOG.md +167 -79
  2. package/README.md +134 -146
  3. package/RESULTADOS_WAF.md +63 -0
  4. package/doc-2.5/ADMIN_EXTENSION_COMMANDS_MANUAL.md +261 -0
  5. package/doc-2.5/ADMIN_EXTENSION_HOOK_EXAMPLE.md +28 -0
  6. package/doc-2.5/ADMIN_EXTENSION_INTEGRATION_MANUAL.md +232 -0
  7. package/doc-2.5/CACHE_SYSTEM_MAP.md +206 -0
  8. package/doc-2.5/MANUAL_MODULOS_ADMIN.md +287 -0
  9. package/doc-2.5/QUEUE_CLI_MODULE_MANUAL.md +289 -0
  10. package/doc-2.5/QUEUE_SYSTEM_MANUAL.md +320 -0
  11. package/doc-2.5/ROUTE_CACHE_MODULE_MANUAL.md +205 -0
  12. package/doc-2.5/WAF_MODULE_MANUAL.md +229 -0
  13. package/index.js +19 -4
  14. package/jerk-admin-client/README.md +69 -0
  15. package/jerk-admin-client/package.json +23 -0
  16. package/jerk-admin-client.js +257 -0
  17. package/lib/admin/AdminExtension.js +491 -0
  18. package/lib/admin/ModuleLoader.js +77 -0
  19. package/lib/admin/config.js +21 -0
  20. package/lib/admin/modules/CacheModule.js +145 -0
  21. package/lib/admin/modules/ControllerGeneratorModule.js +414 -0
  22. package/lib/admin/modules/QueueManagementModule.js +265 -0
  23. package/lib/admin/modules/RouteCacheModule.js +227 -0
  24. package/lib/admin/modules/RouteManagerModule.js +468 -0
  25. package/lib/admin/modules/STATS_MODULE_README.md +113 -0
  26. package/lib/admin/modules/StatsModule.js +140 -0
  27. package/lib/admin/modules/SystemModule.js +140 -0
  28. package/lib/admin/modules/TimeModule.js +95 -0
  29. package/lib/admin/modules/ViewCacheStatsModule.js +92 -0
  30. package/lib/admin/modules/WAFModule.js +737 -0
  31. package/lib/cache/CacheHooks.js +141 -0
  32. package/lib/core/server.js +223 -77
  33. package/lib/middleware/firewall.js +112 -17
  34. package/lib/mvc/viewEngine.js +89 -5
  35. package/lib/queue/GlobalQueueStorage.js +38 -0
  36. package/lib/queue/QueueSystem.js +451 -0
  37. package/lib/queue/admin_example.js +114 -0
  38. package/lib/queue/example.js +268 -0
  39. package/lib/queue/integration.js +109 -0
  40. package/lib/router/RouteMatcher.js +242 -54
  41. package/lib/utils/globalStats.js +16 -0
  42. package/lib/utils/globalViewCacheInfo.js +16 -0
  43. package/lib/utils/globalWAFStats.js +54 -0
  44. package/package.json +2 -2
  45. package/test-colors.js +46 -0
  46. package/test-help-alias.js +31 -0
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Sistema de Hooks y Filters para el Manejo de Caché en JERK Framework
3
+ * Implementación del componente cache/cacheHooks.js
4
+ */
5
+
6
+ class CacheHooks {
7
+ /**
8
+ * Constructor del sistema de hooks de caché
9
+ * @param {Object} hooksSystem - Instancia del sistema de hooks principal
10
+ */
11
+ constructor(hooksSystem) {
12
+ this.hooks = hooksSystem;
13
+ this.initializeCacheHooks();
14
+ }
15
+
16
+ /**
17
+ * Inicializa los hooks relacionados con el sistema de caché
18
+ */
19
+ initializeCacheHooks() {
20
+ // Hook para cuando se añade una entrada al caché de rutas
21
+ this.hooks.addAction('route_regex_cached', (path, regex) => {
22
+ console.log(`[CACHE] Expresión regular cacheada para ruta: ${path}`);
23
+ });
24
+
25
+ // Hook para cuando se añade una vista al caché
26
+ this.hooks.addAction('view_cached', (viewPath, content) => {
27
+ console.log(`[CACHE] Vista cacheada: ${viewPath}`);
28
+ });
29
+
30
+ // Hook para cuando se limpia el caché de rutas
31
+ this.hooks.addAction('route_cache_cleared', () => {
32
+ console.log('[CACHE] Caché de rutas limpiado');
33
+ });
34
+
35
+ // Hook para cuando se limpia el caché de vistas
36
+ this.hooks.addAction('view_cache_cleared', () => {
37
+ console.log('[CACHE] Caché de vistas limpiado');
38
+ });
39
+
40
+ // Filter para permitir modificar el contenido antes de ser cacheado
41
+ this.hooks.addFilter('before_view_cache', (content, viewPath) => {
42
+ // Permitir a otros módulos modificar el contenido antes de cachear
43
+ return content;
44
+ });
45
+
46
+ // Filter para permitir modificar la decisión de si se debe cachear una vista
47
+ this.hooks.addFilter('should_cache_view', (shouldCache, viewPath, content) => {
48
+ // Por defecto, se cachea si está habilitado globalmente
49
+ return shouldCache;
50
+ });
51
+
52
+ // Filter para permitir modificar la decisión de si se debe cachear una expresión regular
53
+ this.hooks.addFilter('should_cache_route_regex', (shouldCache, path, regex) => {
54
+ // Por defecto, se cachea si está habilitado globalmente
55
+ return shouldCache;
56
+ });
57
+ }
58
+
59
+ /**
60
+ * Dispara el hook cuando se añade una entrada al caché de rutas
61
+ * @param {string} path - Ruta que se está cacheando
62
+ * @param {RegExp} regex - Expresión regular que se está cacheando
63
+ */
64
+ triggerRouteRegexCached(path, regex) {
65
+ if (this.hooks) {
66
+ this.hooks.doAction('route_regex_cached', path, regex);
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Dispara el hook cuando se añade una vista al caché
72
+ * @param {string} viewPath - Ruta de la vista que se está cacheando
73
+ * @param {string} content - Contenido de la vista que se está cacheando
74
+ */
75
+ triggerViewCached(viewPath, content) {
76
+ if (this.hooks) {
77
+ this.hooks.doAction('view_cached', viewPath, content);
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Dispara el hook cuando se limpia el caché de rutas
83
+ */
84
+ triggerRouteCacheCleared() {
85
+ if (this.hooks) {
86
+ this.hooks.doAction('route_cache_cleared');
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Dispara el hook cuando se limpia el caché de vistas
92
+ */
93
+ triggerViewCacheCleared() {
94
+ if (this.hooks) {
95
+ this.hooks.doAction('view_cache_cleared');
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Aplica el filter antes de cachear una vista
101
+ * @param {string} content - Contenido de la vista
102
+ * @param {string} viewPath - Ruta de la vista
103
+ * @returns {string} - Contenido procesado por los filters
104
+ */
105
+ applyBeforeViewCacheFilter(content, viewPath) {
106
+ if (this.hooks) {
107
+ return this.hooks.applyFilters('before_view_cache', content, viewPath);
108
+ }
109
+ return content;
110
+ }
111
+
112
+ /**
113
+ * Aplica el filter para decidir si se debe cachear una vista
114
+ * @param {boolean} shouldCache - Valor por defecto
115
+ * @param {string} viewPath - Ruta de la vista
116
+ * @param {string} content - Contenido de la vista
117
+ * @returns {boolean} - Decisión final de si se debe cachear
118
+ */
119
+ applyShouldCacheViewFilter(shouldCache, viewPath, content) {
120
+ if (this.hooks) {
121
+ return this.hooks.applyFilters('should_cache_view', shouldCache, viewPath, content);
122
+ }
123
+ return shouldCache;
124
+ }
125
+
126
+ /**
127
+ * Aplica el filter para decidir si se debe cachear una expresión regular
128
+ * @param {boolean} shouldCache - Valor por defecto
129
+ * @param {string} path - Ruta para la que se va a cachear la expresión regular
130
+ * @param {RegExp} regex - Expresión regular a cachear
131
+ * @returns {boolean} - Decisión final de si se debe cachear
132
+ */
133
+ applyShouldCacheRouteRegexFilter(shouldCache, path, regex) {
134
+ if (this.hooks) {
135
+ return this.hooks.applyFilters('should_cache_route_regex', shouldCache, path, regex);
136
+ }
137
+ return shouldCache;
138
+ }
139
+ }
140
+
141
+ module.exports = CacheHooks;