adonisjs-server-stats 1.10.0 → 1.10.3

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 (210) hide show
  1. package/README.md +23 -14
  2. package/dist/core/config-utils.d.ts +8 -0
  3. package/dist/core/constants.d.ts +4 -0
  4. package/dist/core/dashboard-data-controller.d.ts +16 -0
  5. package/dist/core/dashboard-data-helpers.d.ts +12 -0
  6. package/dist/core/debug-data-controller.d.ts +4 -0
  7. package/dist/core/define-config-helpers.d.ts +25 -0
  8. package/dist/core/feature-detect-helpers.d.ts +36 -0
  9. package/dist/core/formatters-helpers.d.ts +23 -0
  10. package/dist/core/index.js +594 -509
  11. package/dist/core/log-utils-helpers.d.ts +13 -0
  12. package/dist/core/metrics.d.ts +3 -28
  13. package/dist/core/pagination.d.ts +0 -9
  14. package/dist/core/server-stats-controller.d.ts +6 -0
  15. package/dist/core/transmit-helpers.d.ts +7 -0
  16. package/dist/core/types-dashboard.d.ts +178 -0
  17. package/dist/core/types-diagnostics.d.ts +85 -0
  18. package/dist/core/types.d.ts +10 -442
  19. package/dist/react/{CacheSection-UCMptWyn.js → CacheSection-baMZotSn.js} +2 -2
  20. package/dist/react/CacheTab-2cw_rMzj.js +117 -0
  21. package/dist/react/{ConfigSection-DfFd-WRq.js → ConfigSection-DGgqjAal.js} +1 -1
  22. package/dist/react/{ConfigTab-Bdg8YMer.js → ConfigTab-H3OnYqmK.js} +1 -1
  23. package/dist/react/CustomPaneTab-B6r7ha0u.js +98 -0
  24. package/dist/react/{EmailsSection-CM7stSyh.js → EmailsSection-C-UZISG-.js} +2 -2
  25. package/dist/react/EmailsTab-DbK4Eobn.js +139 -0
  26. package/dist/react/{EventsSection-ByQ-9blq.js → EventsSection-C7RQW_LY.js} +2 -2
  27. package/dist/react/EventsTab-CfVr7AiM.js +57 -0
  28. package/dist/react/{FilterBar-DQRXpWrb.js → FilterBar-CQ7bD669.js} +15 -15
  29. package/dist/react/{JobsSection-DF3qEv9O.js → JobsSection-CQHNK_Ls.js} +2 -2
  30. package/dist/react/{JobsTab-BbrBWIOb.js → JobsTab-znzf6jzk.js} +54 -42
  31. package/dist/react/{LogsSection-DcFTZY7b.js → LogsSection-Dmm3rE2B.js} +9 -3
  32. package/dist/react/LogsTab-D8unMV5P.js +108 -0
  33. package/dist/react/{OverviewSection-C4T1ur51.js → OverviewSection-ABP9ueBo.js} +1 -1
  34. package/dist/react/{QueriesSection-PswteoF9.js → QueriesSection-CnmSkznA.js} +2 -2
  35. package/dist/react/{QueriesTab-osLUWd4L.js → QueriesTab-BQzcxEiW.js} +37 -40
  36. package/dist/react/{RelatedLogs-DFDOyUMr.js → RelatedLogs-3A8RuGKH.js} +15 -3
  37. package/dist/react/{RequestsSection-Nag30rEA.js → RequestsSection-kW79_M7k.js} +3 -3
  38. package/dist/react/{RoutesSection-BUSkM6PY.js → RoutesSection-BRhxrtjZ.js} +2 -2
  39. package/dist/react/RoutesTab-CpYH5lUw.js +68 -0
  40. package/dist/react/{TimelineTab-Covg5weo.js → TimelineTab-DjLR35Ce.js} +47 -53
  41. package/dist/react/index-CsImORX6.js +1121 -0
  42. package/dist/react/index.js +1 -1
  43. package/dist/react/react/components/{Dashboard/shared → shared}/FilterBar.d.ts +4 -3
  44. package/dist/react/react/hooks/useDashboardData.d.ts +4 -8
  45. package/dist/react/style.css +1 -1
  46. package/dist/src/collectors/app_collector.d.ts +0 -8
  47. package/dist/src/collectors/app_collector.js +45 -52
  48. package/dist/src/collectors/auto_detect.d.ts +0 -23
  49. package/dist/src/collectors/auto_detect.js +33 -55
  50. package/dist/src/collectors/db_pool_collector.d.ts +14 -16
  51. package/dist/src/collectors/db_pool_collector.js +72 -57
  52. package/dist/src/collectors/log_collector.d.ts +0 -47
  53. package/dist/src/collectors/log_collector.js +36 -65
  54. package/dist/src/collectors/queue_collector.d.ts +0 -20
  55. package/dist/src/collectors/queue_collector.js +60 -76
  56. package/dist/src/collectors/redis_collector.d.ts +10 -10
  57. package/dist/src/collectors/redis_collector.js +69 -66
  58. package/dist/src/config/deprecation_migration.d.ts +7 -0
  59. package/dist/src/config/deprecation_migration.js +201 -0
  60. package/dist/src/controller/debug_controller.d.ts +1 -1
  61. package/dist/src/controller/debug_controller.js +87 -81
  62. package/dist/src/dashboard/cache_handlers.d.ts +14 -0
  63. package/dist/src/dashboard/cache_handlers.js +52 -0
  64. package/dist/src/dashboard/chart_aggregator.d.ts +0 -7
  65. package/dist/src/dashboard/chart_aggregator.js +68 -50
  66. package/dist/src/dashboard/coalesce_cache.d.ts +25 -0
  67. package/dist/src/dashboard/coalesce_cache.js +47 -0
  68. package/dist/src/dashboard/dashboard_controller.d.ts +11 -37
  69. package/dist/src/dashboard/dashboard_controller.js +51 -544
  70. package/dist/src/dashboard/dashboard_page_assets.d.ts +17 -0
  71. package/dist/src/dashboard/dashboard_page_assets.js +51 -0
  72. package/dist/src/dashboard/dashboard_store.d.ts +19 -218
  73. package/dist/src/dashboard/dashboard_store.js +115 -1116
  74. package/dist/src/dashboard/dashboard_types.d.ts +83 -0
  75. package/dist/src/dashboard/dashboard_types.js +4 -0
  76. package/dist/src/dashboard/detail_queries.d.ts +19 -0
  77. package/dist/src/dashboard/detail_queries.js +98 -0
  78. package/dist/src/dashboard/email_event_builder.d.ts +8 -0
  79. package/dist/src/dashboard/email_event_builder.js +65 -0
  80. package/dist/src/dashboard/explain_query.d.ts +8 -0
  81. package/dist/src/dashboard/explain_query.js +22 -0
  82. package/dist/src/dashboard/filter_handlers.d.ts +23 -0
  83. package/dist/src/dashboard/filter_handlers.js +56 -0
  84. package/dist/src/dashboard/filtered_queries.d.ts +15 -0
  85. package/dist/src/dashboard/filtered_queries.js +155 -0
  86. package/dist/src/dashboard/flush_manager.d.ts +25 -0
  87. package/dist/src/dashboard/flush_manager.js +107 -0
  88. package/dist/src/dashboard/format_helpers.d.ts +126 -0
  89. package/dist/src/dashboard/format_helpers.js +140 -0
  90. package/dist/src/dashboard/inspector_manager.d.ts +36 -0
  91. package/dist/src/dashboard/inspector_manager.js +102 -0
  92. package/dist/src/dashboard/integrations/config_inspector.js +11 -13
  93. package/dist/src/dashboard/integrations/queue_inspector.d.ts +3 -3
  94. package/dist/src/dashboard/integrations/queue_inspector.js +13 -10
  95. package/dist/src/dashboard/jobs_handlers.d.ts +14 -0
  96. package/dist/src/dashboard/jobs_handlers.js +61 -0
  97. package/dist/src/dashboard/knex_factory.d.ts +18 -0
  98. package/dist/src/dashboard/knex_factory.js +91 -0
  99. package/dist/src/dashboard/migrator.js +30 -159
  100. package/dist/src/dashboard/migrator_tables.d.ts +19 -0
  101. package/dist/src/dashboard/migrator_tables.js +153 -0
  102. package/dist/src/dashboard/overview_queries.d.ts +66 -0
  103. package/dist/src/dashboard/overview_queries.js +155 -0
  104. package/dist/src/dashboard/overview_query_runners.d.ts +25 -0
  105. package/dist/src/dashboard/overview_query_runners.js +84 -0
  106. package/dist/src/dashboard/overview_store_queries.d.ts +40 -0
  107. package/dist/src/dashboard/overview_store_queries.js +69 -0
  108. package/dist/src/dashboard/paginate_helper.d.ts +12 -0
  109. package/dist/src/dashboard/paginate_helper.js +33 -0
  110. package/dist/src/dashboard/query_explain_handler.d.ts +10 -0
  111. package/dist/src/dashboard/query_explain_handler.js +80 -0
  112. package/dist/src/dashboard/read_queries.d.ts +32 -0
  113. package/dist/src/dashboard/read_queries.js +107 -0
  114. package/dist/src/dashboard/saved_filter_queries.d.ts +10 -0
  115. package/dist/src/dashboard/saved_filter_queries.js +24 -0
  116. package/dist/src/dashboard/storage_stats.d.ts +41 -0
  117. package/dist/src/dashboard/storage_stats.js +81 -0
  118. package/dist/src/dashboard/write_queue.d.ts +106 -0
  119. package/dist/src/dashboard/write_queue.js +225 -0
  120. package/dist/src/data/data_access.d.ts +2 -39
  121. package/dist/src/data/data_access.js +17 -193
  122. package/dist/src/data/data_access_helpers.d.ts +130 -0
  123. package/dist/src/data/data_access_helpers.js +212 -0
  124. package/dist/src/debug/debug_store.js +37 -32
  125. package/dist/src/debug/email_collector.d.ts +1 -10
  126. package/dist/src/debug/email_collector.js +78 -81
  127. package/dist/src/debug/event_collector.d.ts +0 -9
  128. package/dist/src/debug/event_collector.js +79 -62
  129. package/dist/src/debug/query_collector.js +23 -19
  130. package/dist/src/debug/route_inspector.d.ts +1 -5
  131. package/dist/src/debug/route_inspector.js +50 -51
  132. package/dist/src/debug/trace_collector.d.ts +9 -1
  133. package/dist/src/debug/trace_collector.js +21 -15
  134. package/dist/src/debug/types.d.ts +1 -1
  135. package/dist/src/define_config.d.ts +0 -65
  136. package/dist/src/define_config.js +93 -333
  137. package/dist/src/edge/client/dashboard.js +2 -2
  138. package/dist/src/edge/client/debug-panel-deferred.js +1 -1
  139. package/dist/src/edge/client/stats-bar.js +1 -1
  140. package/dist/src/edge/client-vue/dashboard.js +5 -5
  141. package/dist/src/edge/client-vue/debug-panel-deferred.js +3 -3
  142. package/dist/src/edge/client-vue/stats-bar.js +3 -3
  143. package/dist/src/edge/plugin.d.ts +0 -16
  144. package/dist/src/edge/plugin.js +57 -64
  145. package/dist/src/engine/request_metrics.d.ts +1 -0
  146. package/dist/src/engine/request_metrics.js +32 -42
  147. package/dist/src/middleware/request_tracking_middleware.d.ts +2 -8
  148. package/dist/src/middleware/request_tracking_middleware.js +65 -93
  149. package/dist/src/provider/auth_middleware_detector.d.ts +16 -0
  150. package/dist/src/provider/auth_middleware_detector.js +97 -0
  151. package/dist/src/provider/boot_helpers.d.ts +20 -0
  152. package/dist/src/provider/boot_helpers.js +91 -0
  153. package/dist/src/provider/boot_initializer.d.ts +28 -0
  154. package/dist/src/provider/boot_initializer.js +35 -0
  155. package/dist/src/provider/dashboard_init.d.ts +30 -0
  156. package/dist/src/provider/dashboard_init.js +138 -0
  157. package/dist/src/provider/dashboard_setup.d.ts +25 -0
  158. package/dist/src/provider/dashboard_setup.js +78 -0
  159. package/dist/src/provider/diagnostics.d.ts +134 -0
  160. package/dist/src/provider/diagnostics.js +127 -0
  161. package/dist/src/provider/email_bridge.d.ts +43 -0
  162. package/dist/src/provider/email_bridge.js +80 -0
  163. package/dist/src/provider/email_helpers.d.ts +13 -0
  164. package/dist/src/provider/email_helpers.js +68 -0
  165. package/dist/src/provider/pino_hook.d.ts +17 -0
  166. package/dist/src/provider/pino_hook.js +35 -0
  167. package/dist/src/provider/provider_helpers_extra.d.ts +47 -0
  168. package/dist/src/provider/provider_helpers_extra.js +177 -0
  169. package/dist/src/provider/server_stats_provider.d.ts +39 -85
  170. package/dist/src/provider/server_stats_provider.js +132 -951
  171. package/dist/src/provider/shutdown_helpers.d.ts +43 -0
  172. package/dist/src/provider/shutdown_helpers.js +70 -0
  173. package/dist/src/provider/toolbar_setup.d.ts +57 -0
  174. package/dist/src/provider/toolbar_setup.js +141 -0
  175. package/dist/src/routes/dashboard_routes.d.ts +14 -0
  176. package/dist/src/routes/dashboard_routes.js +197 -0
  177. package/dist/src/routes/debug_routes.d.ts +14 -0
  178. package/dist/src/routes/debug_routes.js +101 -0
  179. package/dist/src/routes/register_routes.d.ts +0 -78
  180. package/dist/src/routes/register_routes.js +22 -352
  181. package/dist/src/routes/stats_routes.d.ts +5 -0
  182. package/dist/src/routes/stats_routes.js +14 -0
  183. package/dist/src/styles/components.css +96 -0
  184. package/dist/src/styles/dashboard.css +8 -90
  185. package/dist/src/styles/debug-panel.css +1 -31
  186. package/dist/src/types.d.ts +305 -14
  187. package/dist/vue/{CacheSection-oFAJL3mo.js → CacheSection-ITqvpfH5.js} +1 -1
  188. package/dist/vue/{ConfigSection-BhfJ4KqL.js → ConfigSection-DTn3GslE.js} +1 -1
  189. package/dist/vue/{EmailsSection-BcNyhyHs.js → EmailsSection-DtLJ4XoS.js} +1 -1
  190. package/dist/vue/{EventsSection-r60Q5Lmu.js → EventsSection-BOYYz0Ty.js} +1 -1
  191. package/dist/vue/{JobsSection-BHL-hkQw.js → JobsSection-BazTxcJL.js} +1 -1
  192. package/dist/vue/{LogsSection-DRMGzJmg.js → LogsSection-D55PjTKX.js} +9 -3
  193. package/dist/vue/{LogsTab-Bg3o0Mm6.js → LogsTab-47zEK7jL.js} +4 -1
  194. package/dist/vue/{OverviewSection-CXh6Ja1B.js → OverviewSection-1uBKo-Tu.js} +1 -1
  195. package/dist/vue/{QueriesSection-IodIsCJ-.js → QueriesSection-rpoZ4ogd.js} +1 -1
  196. package/dist/vue/{RequestsSection-BPuMdmMc.js → RequestsSection-x7LvT0MC.js} +1 -1
  197. package/dist/vue/{RoutesSection-NKo3Rbq3.js → RoutesSection-CCD0zZqQ.js} +1 -1
  198. package/dist/vue/composables/useDashboardData.d.ts +12 -23
  199. package/dist/vue/index-C8MxnS7Q.js +1232 -0
  200. package/dist/vue/index.js +1 -1
  201. package/dist/vue/style.css +1 -1
  202. package/package.json +1 -1
  203. package/dist/react/CacheTab-CA8LB1J5.js +0 -123
  204. package/dist/react/CustomPaneTab-Bxtv_8Rw.js +0 -104
  205. package/dist/react/EmailsTab-BDhEiomM.js +0 -153
  206. package/dist/react/EventsTab-CMfY98Rl.js +0 -63
  207. package/dist/react/LogsTab-CicucmVk.js +0 -103
  208. package/dist/react/RoutesTab-DgVzd2PZ.js +0 -74
  209. package/dist/react/index-Cflz9Ebj.js +0 -1069
  210. package/dist/vue/index-Dtgysd26.js +0 -1229
@@ -1,41 +1,32 @@
1
- import { bold, dim, setVerbose } from './utils/logger.js';
2
- /**
3
- * Resolve `toolbar`, `dashboard`, and `advanced` aliases into a
4
- * {@link DevToolbarOptions} object, merging with any existing
5
- * `devToolbar` settings the user provided.
6
- */
7
- function resolveToolbarAliases(config, existing) {
8
- const toolbar = config.toolbar;
9
- const dashboard = config.dashboard;
10
- const advanced = config.advanced;
11
- // Start from existing devToolbar or a new object
12
- const result = { ...existing, enabled: existing?.enabled ?? false };
13
- // toolbar: true | ToolbarConfig enables the toolbar
14
- if (toolbar === true) {
15
- result.enabled = true;
16
- }
17
- else if (toolbar && typeof toolbar === 'object') {
18
- result.enabled = true;
19
- if (toolbar.slowQueryThreshold !== undefined)
20
- result.slowQueryThresholdMs = toolbar.slowQueryThreshold;
21
- if (toolbar.tracing !== undefined)
22
- result.tracing = toolbar.tracing;
23
- if (toolbar.persist !== undefined)
24
- result.persistDebugData = toolbar.persist;
25
- if (toolbar.panes !== undefined)
26
- result.panes = toolbar.panes;
27
- if (toolbar.excludeFromTracing !== undefined)
28
- result.excludeFromTracing = toolbar.excludeFromTracing;
29
- }
30
- else if (toolbar === false) {
31
- result.enabled = false;
1
+ import { logDeprecationWarnings } from './config/deprecation_migration.js';
2
+ import { setVerbose } from './utils/logger.js';
3
+ // ---------------------------------------------------------------------------
4
+ // Toolbar alias resolution helpers
5
+ // ---------------------------------------------------------------------------
6
+ /** Apply toolbar config object fields onto the result. */
7
+ function applyToolbarConfig(toolbar, result) {
8
+ result.enabled = true;
9
+ const fields = [
10
+ ['slowQueryThreshold', 'slowQueryThresholdMs'],
11
+ ['tracing', 'tracing'],
12
+ ['persist', 'persistDebugData'],
13
+ ['panes', 'panes'],
14
+ ['excludeFromTracing', 'excludeFromTracing'],
15
+ ];
16
+ for (const [src, dst] of fields) {
17
+ const v = toolbar[src];
18
+ if (v !== undefined)
19
+ result[dst] = v;
32
20
  }
33
- // dashboard: true | DashboardConfig
21
+ }
22
+ /** Apply dashboard config onto the result. */
23
+ function applyDashboardConfig(dashboard, result) {
34
24
  if (dashboard === true) {
35
- result.enabled = true; // dashboard implies toolbar enabled
25
+ result.enabled = true;
36
26
  result.dashboard = true;
27
+ return;
37
28
  }
38
- else if (dashboard && typeof dashboard === 'object') {
29
+ if (dashboard && typeof dashboard === 'object') {
39
30
  result.enabled = true;
40
31
  result.dashboard = true;
41
32
  if (dashboard.path !== undefined)
@@ -43,343 +34,112 @@ function resolveToolbarAliases(config, existing) {
43
34
  if (dashboard.retentionDays !== undefined)
44
35
  result.retentionDays = dashboard.retentionDays;
45
36
  }
46
- // advanced options
47
- if (advanced) {
48
- if (advanced.debugEndpoint !== undefined)
49
- result.debugEndpoint = advanced.debugEndpoint;
50
- if (advanced.renderer !== undefined)
51
- result.renderer = advanced.renderer;
52
- if (advanced.dbPath !== undefined)
53
- result.dbPath = advanced.dbPath;
54
- if (advanced.persistPath !== undefined) {
55
- result.persistDebugData = advanced.persistPath;
56
- }
57
- if (advanced.maxQueries !== undefined)
58
- result.maxQueries = advanced.maxQueries;
59
- if (advanced.maxEvents !== undefined)
60
- result.maxEvents = advanced.maxEvents;
61
- if (advanced.maxEmails !== undefined)
62
- result.maxEmails = advanced.maxEmails;
63
- if (advanced.maxTraces !== undefined)
64
- result.maxTraces = advanced.maxTraces;
65
- }
66
- return result;
67
37
  }
68
- /**
69
- * Build a concrete migration hint for `devToolbar` based on which sub-fields
70
- * the user actually configured. The result splits `devToolbar` into the new
71
- * `toolbar`, `dashboard`, and `advanced` config sections.
72
- */
73
- function buildDevToolbarMigration(dt) {
74
- const beforeParts = [];
75
- const afterParts = [];
76
- // Reconstruct a readable "before" snapshot
77
- beforeParts.push('devToolbar: {');
78
- if (dt.enabled !== undefined)
79
- beforeParts.push(` enabled: ${dt.enabled},`);
80
- if (dt.dashboard !== undefined)
81
- beforeParts.push(` dashboard: ${dt.dashboard},`);
82
- if (dt.dashboardPath !== undefined)
83
- beforeParts.push(` dashboardPath: '${dt.dashboardPath}',`);
84
- if (dt.retentionDays !== undefined)
85
- beforeParts.push(` retentionDays: ${dt.retentionDays},`);
86
- if (dt.slowQueryThresholdMs !== undefined)
87
- beforeParts.push(` slowQueryThresholdMs: ${dt.slowQueryThresholdMs},`);
88
- if (dt.tracing !== undefined)
89
- beforeParts.push(` tracing: ${dt.tracing},`);
90
- if (dt.persistDebugData !== undefined)
91
- beforeParts.push(` persistDebugData: ${JSON.stringify(dt.persistDebugData)},`);
92
- if (dt.maxQueries !== undefined)
93
- beforeParts.push(` maxQueries: ${dt.maxQueries},`);
94
- if (dt.maxEvents !== undefined)
95
- beforeParts.push(` maxEvents: ${dt.maxEvents},`);
96
- if (dt.maxEmails !== undefined)
97
- beforeParts.push(` maxEmails: ${dt.maxEmails},`);
98
- if (dt.maxTraces !== undefined)
99
- beforeParts.push(` maxTraces: ${dt.maxTraces},`);
100
- if (dt.renderer !== undefined)
101
- beforeParts.push(` renderer: '${dt.renderer}',`);
102
- if (dt.panes !== undefined)
103
- beforeParts.push(` panes: [...],`);
104
- if (dt.excludeFromTracing !== undefined)
105
- beforeParts.push(` excludeFromTracing: [...],`);
106
- if (dt.debugEndpoint !== undefined)
107
- beforeParts.push(` debugEndpoint: '${dt.debugEndpoint}',`);
108
- if (dt.dbPath !== undefined)
109
- beforeParts.push(` dbPath: '${dt.dbPath}',`);
110
- beforeParts.push('}');
111
- // -- toolbar --
112
- const hasSlowQuery = dt.slowQueryThresholdMs !== undefined;
113
- const hasTracing = dt.tracing !== undefined;
114
- const hasPersist = dt.persistDebugData !== undefined;
115
- const hasPanes = dt.panes !== undefined;
116
- const hasExclude = dt.excludeFromTracing !== undefined;
117
- const hasToolbarDetails = hasSlowQuery || hasTracing || hasPersist || hasPanes || hasExclude;
118
- if (dt.enabled && hasToolbarDetails) {
119
- const parts = [];
120
- if (hasSlowQuery)
121
- parts.push(` slowQueryThreshold: ${dt.slowQueryThresholdMs},`);
122
- if (hasTracing)
123
- parts.push(` tracing: ${dt.tracing},`);
124
- if (hasPersist)
125
- parts.push(` persist: ${JSON.stringify(dt.persistDebugData)},`);
126
- if (hasPanes)
127
- parts.push(` panes: [...],`);
128
- if (hasExclude)
129
- parts.push(` excludeFromTracing: [...],`);
130
- afterParts.push('toolbar: {');
131
- afterParts.push(...parts);
132
- afterParts.push('}');
133
- }
134
- else if (dt.enabled) {
135
- afterParts.push('toolbar: true');
136
- }
137
- // -- dashboard --
138
- const hasCustomPath = dt.dashboardPath !== undefined;
139
- const hasRetention = dt.retentionDays !== undefined;
140
- const hasDashboardDetails = hasCustomPath || hasRetention;
141
- if (dt.dashboard && hasDashboardDetails) {
142
- const parts = [];
143
- if (hasCustomPath)
144
- parts.push(` path: '${dt.dashboardPath}',`);
145
- if (hasRetention)
146
- parts.push(` retentionDays: ${dt.retentionDays},`);
147
- afterParts.push('dashboard: {');
148
- afterParts.push(...parts);
149
- afterParts.push('}');
150
- }
151
- else if (dt.dashboard) {
152
- afterParts.push('dashboard: true');
38
+ /** Advanced config field mappings. */
39
+ const ADVANCED_FIELDS = [
40
+ ['debugEndpoint', 'debugEndpoint'],
41
+ ['renderer', 'renderer'],
42
+ ['dbPath', 'dbPath'],
43
+ ['maxQueries', 'maxQueries'],
44
+ ['maxEvents', 'maxEvents'],
45
+ ['maxEmails', 'maxEmails'],
46
+ ['maxTraces', 'maxTraces'],
47
+ ];
48
+ /** Apply advanced config onto the result. */
49
+ function applyAdvancedConfig(advanced, result) {
50
+ if (!advanced)
51
+ return;
52
+ for (const [src, dst] of ADVANCED_FIELDS) {
53
+ const v = advanced[src];
54
+ if (v !== undefined)
55
+ result[dst] = v;
153
56
  }
154
- // -- advanced --
155
- const advancedParts = [];
156
- if (dt.maxQueries !== undefined)
157
- advancedParts.push(` maxQueries: ${dt.maxQueries},`);
158
- if (dt.maxEvents !== undefined)
159
- advancedParts.push(` maxEvents: ${dt.maxEvents},`);
160
- if (dt.maxEmails !== undefined)
161
- advancedParts.push(` maxEmails: ${dt.maxEmails},`);
162
- if (dt.maxTraces !== undefined)
163
- advancedParts.push(` maxTraces: ${dt.maxTraces},`);
164
- if (dt.renderer !== undefined)
165
- advancedParts.push(` renderer: '${dt.renderer}',`);
166
- if (dt.debugEndpoint !== undefined)
167
- advancedParts.push(` debugEndpoint: '${dt.debugEndpoint}',`);
168
- if (dt.dbPath !== undefined)
169
- advancedParts.push(` dbPath: '${dt.dbPath}',`);
170
- if (advancedParts.length > 0) {
171
- afterParts.push('advanced: {');
172
- afterParts.push(...advancedParts);
173
- afterParts.push('}');
57
+ if (advanced.persistPath !== undefined) {
58
+ result.persistDebugData = advanced.persistPath;
174
59
  }
175
- return {
176
- old: 'devToolbar',
177
- new: [
178
- dt.enabled !== undefined ? 'toolbar' : '',
179
- dt.dashboard ? 'dashboard' : '',
180
- advancedParts.length > 0 ? 'advanced' : '',
181
- ]
182
- .filter(Boolean)
183
- .join(' + ') || 'toolbar + dashboard + advanced',
184
- before: beforeParts,
185
- after: afterParts,
186
- };
187
60
  }
188
61
  /**
189
- * Detect deprecated config names and log a single grouped warning block.
190
- *
191
- * Only warns for fields the user **actually set** (not undefined).
192
- * The output is designed to be immediately actionable: each deprecated
193
- * field gets a before/after code snippet so users can copy-paste.
62
+ * Resolve `toolbar`, `dashboard`, and `advanced` aliases into a
63
+ * {@link DevToolbarOptions} object.
194
64
  */
195
- function logDeprecationWarnings(config) {
196
- const entries = [];
197
- // intervalMs -> pollInterval
198
- if (config.intervalMs !== undefined) {
199
- entries.push({
200
- old: 'intervalMs',
201
- new: 'pollInterval',
202
- before: [`intervalMs: ${config.intervalMs}`],
203
- after: [`pollInterval: ${config.intervalMs}`],
204
- });
205
- }
206
- // transport -> realtime
207
- if (config.transport !== undefined) {
208
- const realtimeValue = config.transport === 'transmit';
209
- entries.push({
210
- old: 'transport',
211
- new: 'realtime',
212
- before: [`transport: '${config.transport}'`],
213
- after: [`realtime: ${realtimeValue}`],
214
- });
215
- }
216
- // endpoint -> statsEndpoint
217
- if (config.endpoint !== undefined) {
218
- const endpointDisplay = config.endpoint === false ? 'false' : `'${config.endpoint}'`;
219
- entries.push({
220
- old: 'endpoint',
221
- new: 'statsEndpoint',
222
- before: [`endpoint: ${endpointDisplay}`],
223
- after: [`statsEndpoint: ${endpointDisplay}`],
224
- });
225
- }
226
- // shouldShow -> authorize
227
- if (config.shouldShow !== undefined) {
228
- entries.push({
229
- old: 'shouldShow',
230
- new: 'authorize',
231
- before: ['shouldShow: (ctx) => ...'],
232
- after: ['authorize: (ctx) => ...'],
233
- });
234
- }
235
- // channelName -> advanced.channelName
236
- if (config.channelName !== undefined) {
237
- entries.push({
238
- old: 'channelName',
239
- new: 'advanced.channelName',
240
- before: [`channelName: '${config.channelName}'`],
241
- after: [`advanced: { channelName: '${config.channelName}' }`],
242
- });
65
+ function resolveToolbarAliases(config, existing) {
66
+ const result = { ...existing, enabled: existing?.enabled ?? false };
67
+ if (config.toolbar === true) {
68
+ result.enabled = true;
243
69
  }
244
- // skipInTest -> advanced.skipInTest
245
- if (config.skipInTest !== undefined) {
246
- entries.push({
247
- old: 'skipInTest',
248
- new: 'advanced.skipInTest',
249
- before: [`skipInTest: ${config.skipInTest}`],
250
- after: [`advanced: { skipInTest: ${config.skipInTest} }`],
251
- });
70
+ else if (config.toolbar && typeof config.toolbar === 'object') {
71
+ applyToolbarConfig(config.toolbar, result);
252
72
  }
253
- // devToolbar -> toolbar + dashboard + advanced
254
- if (config.devToolbar !== undefined) {
255
- entries.push(buildDevToolbarMigration(config.devToolbar));
73
+ else if (config.toolbar === false) {
74
+ result.enabled = false;
256
75
  }
257
- if (entries.length === 0)
258
- return;
259
- // Build the warning block
260
- const TAG = '\x1b[36m[ \x1b[1m\uD83D\uDD0D server-stats\x1b[0m\x1b[36m ]\x1b[0m';
261
- const lines = [];
262
- lines.push('');
263
- lines.push(`${TAG} Some config options have been renamed — here's how to update:`);
264
- lines.push('');
265
- for (const entry of entries) {
266
- lines.push(` ${dim(entry.old)} ${dim('\u2192')} ${bold(entry.new)}`);
267
- lines.push('');
268
- for (const line of entry.before) {
269
- lines.push(` ${dim('before:')} ${dim(line)}`);
270
- }
271
- for (const line of entry.after) {
272
- lines.push(` ${dim('after:')} ${line}`);
273
- }
274
- lines.push('');
76
+ applyDashboardConfig(config.dashboard, result);
77
+ applyAdvancedConfig(config.advanced, result);
78
+ return result;
79
+ }
80
+ // ---------------------------------------------------------------------------
81
+ // Config resolution helpers
82
+ // ---------------------------------------------------------------------------
83
+ /** Resolve transport from new and deprecated config options. */
84
+ function resolveTransport(config) {
85
+ if (config.realtime !== undefined) {
86
+ return config.realtime ? 'transmit' : 'none';
275
87
  }
276
- lines.push(` ${dim('No rush — the old names still work. They will be removed in the next major version.')}`);
277
- lines.push(` ${dim('Update')} ${bold('config/server_stats.ts')} ${dim('when you get a chance.')}`);
278
- lines.push('');
279
- console.log(lines.join('\n'));
88
+ return config.transport ?? 'transmit';
280
89
  }
90
+ /** Resolve devToolbar from aliases. */
91
+ function resolveDevToolbar(config) {
92
+ const hasAliases = config.toolbar !== undefined || config.dashboard !== undefined || config.advanced !== undefined;
93
+ if (hasAliases)
94
+ return resolveToolbarAliases(config, config.devToolbar);
95
+ return config.devToolbar;
96
+ }
97
+ // ---------------------------------------------------------------------------
98
+ // Main defineConfig
99
+ // ---------------------------------------------------------------------------
281
100
  /**
282
101
  * Define the server stats configuration with full type safety.
283
102
  *
284
- * All top-level fields are optional. Sensible defaults are applied
285
- * for any omitted fields:
286
- *
287
- * | Field | Default |
288
- * |---------------|--------------------------------|
289
- * | `intervalMs` | `3000` |
290
- * | `transport` | `'transmit'` |
291
- * | `channelName` | `'admin/server-stats'` |
292
- * | `endpoint` | `'/admin/api/server-stats'` |
293
- * | `collectors` | `'auto'` |
294
- * | `skipInTest` | `true` |
295
- *
296
- * New simplified aliases (Phase 1) are also supported. When both the
297
- * old name and its alias are provided, the **new name takes precedence**.
298
- *
299
- * | Alias | Resolves to |
300
- * |------------------|------------------|
301
- * | `pollInterval` | `intervalMs` |
302
- * | `realtime` | `transport` |
303
- * | `statsEndpoint` | `endpoint` |
304
- * | `authorize` | `shouldShow` |
305
- * | `toolbar` | `devToolbar` |
306
- * | `dashboard` | `devToolbar` |
307
- * | `advanced` | various |
308
- *
309
- * This is the main entry point for configuring `adonisjs-server-stats`.
310
- * Call it in `config/server_stats.ts` and export the result as default.
103
+ * All fields are optional. Sensible defaults are applied for anything
104
+ * you omit -- `defineConfig({})` works out of the box with zero config.
311
105
  *
312
106
  * @example
313
107
  * ```ts
314
- * // config/server_stats.ts minimal (all defaults)
108
+ * // Zero config -- auto-detects everything
315
109
  * import { defineConfig } from 'adonisjs-server-stats'
316
- *
317
110
  * export default defineConfig({})
318
111
  * ```
319
112
  *
320
113
  * @example
321
114
  * ```ts
322
- * // config/server_stats.ts explicit collectors
323
- * import { defineConfig } from 'adonisjs-server-stats'
324
- * import { processCollector, httpCollector } from 'adonisjs-server-stats/collectors'
325
- *
326
- * export default defineConfig({
327
- * intervalMs: 3000,
328
- * transport: 'transmit',
329
- * collectors: [processCollector(), httpCollector()],
330
- * })
331
- * ```
332
- *
333
- * @example
334
- * ```ts
335
- * // config/server_stats.ts — new simplified aliases
115
+ * // Common setup with auth and all features
336
116
  * import { defineConfig } from 'adonisjs-server-stats'
337
117
  *
338
118
  * export default defineConfig({
339
- * pollInterval: 3000,
340
- * realtime: true,
119
+ * authorize: (ctx) => ctx.auth?.user?.role === 'admin',
341
120
  * toolbar: true,
342
121
  * dashboard: true,
343
122
  * })
344
123
  * ```
345
124
  */
125
+ /** Resolve a value from primary, fallback, then default. */
126
+ function first(primary, fallback, defaultVal) {
127
+ return primary ?? fallback ?? defaultVal;
128
+ }
346
129
  export function defineConfig(config) {
347
- // Apply verbose setting early so all subsequent log.info calls respect it
348
130
  const verbose = config.verbose ?? false;
349
131
  setVerbose(verbose);
350
- // Resolve aliases (new names take precedence over old)
351
- const intervalMs = config.pollInterval ?? config.intervalMs ?? 3000;
352
- let transport;
353
- if (config.realtime !== undefined) {
354
- transport = config.realtime ? 'transmit' : 'none';
355
- }
356
- else {
357
- transport = config.transport ?? 'transmit';
358
- }
359
- const endpoint = config.statsEndpoint ?? config.endpoint ?? '/admin/api/server-stats';
360
- const shouldShow = config.authorize ?? config.shouldShow;
361
- // Resolve toolbar/dashboard aliases into devToolbar
362
- let devToolbar = config.devToolbar;
363
- if (config.toolbar !== undefined ||
364
- config.dashboard !== undefined ||
365
- config.advanced !== undefined) {
366
- devToolbar = resolveToolbarAliases(config, devToolbar);
367
- }
368
- // Resolve advanced.channelName, advanced.skipInTest etc
369
- const channelName = config.advanced?.channelName ?? config.channelName ?? 'admin/server-stats';
370
- const skipInTest = config.advanced?.skipInTest ?? config.skipInTest ?? true;
371
- // Log friendly deprecation warnings for any old config names the user set
372
132
  logDeprecationWarnings(config);
373
133
  return {
374
- intervalMs,
375
- transport,
376
- channelName,
377
- endpoint,
134
+ intervalMs: first(config.pollInterval, config.intervalMs, 3000),
135
+ transport: resolveTransport(config),
136
+ channelName: first(config.advanced?.channelName, config.channelName, 'admin/server-stats'),
137
+ endpoint: first(config.statsEndpoint, config.endpoint, '/admin/api/server-stats'),
378
138
  collectors: config.collectors ?? 'auto',
379
- skipInTest,
139
+ skipInTest: first(config.advanced?.skipInTest, config.skipInTest, true),
380
140
  onStats: config.onStats,
381
- devToolbar,
382
- shouldShow,
141
+ devToolbar: resolveDevToolbar(config),
142
+ shouldShow: config.authorize ?? config.shouldShow,
383
143
  verbose,
384
144
  };
385
145
  }