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.
- package/README.md +23 -14
- package/dist/core/config-utils.d.ts +8 -0
- package/dist/core/constants.d.ts +4 -0
- package/dist/core/dashboard-data-controller.d.ts +16 -0
- package/dist/core/dashboard-data-helpers.d.ts +12 -0
- package/dist/core/debug-data-controller.d.ts +4 -0
- package/dist/core/define-config-helpers.d.ts +25 -0
- package/dist/core/feature-detect-helpers.d.ts +36 -0
- package/dist/core/formatters-helpers.d.ts +23 -0
- package/dist/core/index.js +594 -509
- package/dist/core/log-utils-helpers.d.ts +13 -0
- package/dist/core/metrics.d.ts +3 -28
- package/dist/core/pagination.d.ts +0 -9
- package/dist/core/server-stats-controller.d.ts +6 -0
- package/dist/core/transmit-helpers.d.ts +7 -0
- package/dist/core/types-dashboard.d.ts +178 -0
- package/dist/core/types-diagnostics.d.ts +85 -0
- package/dist/core/types.d.ts +10 -442
- package/dist/react/{CacheSection-UCMptWyn.js → CacheSection-baMZotSn.js} +2 -2
- package/dist/react/CacheTab-2cw_rMzj.js +117 -0
- package/dist/react/{ConfigSection-DfFd-WRq.js → ConfigSection-DGgqjAal.js} +1 -1
- package/dist/react/{ConfigTab-Bdg8YMer.js → ConfigTab-H3OnYqmK.js} +1 -1
- package/dist/react/CustomPaneTab-B6r7ha0u.js +98 -0
- package/dist/react/{EmailsSection-CM7stSyh.js → EmailsSection-C-UZISG-.js} +2 -2
- package/dist/react/EmailsTab-DbK4Eobn.js +139 -0
- package/dist/react/{EventsSection-ByQ-9blq.js → EventsSection-C7RQW_LY.js} +2 -2
- package/dist/react/EventsTab-CfVr7AiM.js +57 -0
- package/dist/react/{FilterBar-DQRXpWrb.js → FilterBar-CQ7bD669.js} +15 -15
- package/dist/react/{JobsSection-DF3qEv9O.js → JobsSection-CQHNK_Ls.js} +2 -2
- package/dist/react/{JobsTab-BbrBWIOb.js → JobsTab-znzf6jzk.js} +54 -42
- package/dist/react/{LogsSection-DcFTZY7b.js → LogsSection-Dmm3rE2B.js} +9 -3
- package/dist/react/LogsTab-D8unMV5P.js +108 -0
- package/dist/react/{OverviewSection-C4T1ur51.js → OverviewSection-ABP9ueBo.js} +1 -1
- package/dist/react/{QueriesSection-PswteoF9.js → QueriesSection-CnmSkznA.js} +2 -2
- package/dist/react/{QueriesTab-osLUWd4L.js → QueriesTab-BQzcxEiW.js} +37 -40
- package/dist/react/{RelatedLogs-DFDOyUMr.js → RelatedLogs-3A8RuGKH.js} +15 -3
- package/dist/react/{RequestsSection-Nag30rEA.js → RequestsSection-kW79_M7k.js} +3 -3
- package/dist/react/{RoutesSection-BUSkM6PY.js → RoutesSection-BRhxrtjZ.js} +2 -2
- package/dist/react/RoutesTab-CpYH5lUw.js +68 -0
- package/dist/react/{TimelineTab-Covg5weo.js → TimelineTab-DjLR35Ce.js} +47 -53
- package/dist/react/index-CsImORX6.js +1121 -0
- package/dist/react/index.js +1 -1
- package/dist/react/react/components/{Dashboard/shared → shared}/FilterBar.d.ts +4 -3
- package/dist/react/react/hooks/useDashboardData.d.ts +4 -8
- package/dist/react/style.css +1 -1
- package/dist/src/collectors/app_collector.d.ts +0 -8
- package/dist/src/collectors/app_collector.js +45 -52
- package/dist/src/collectors/auto_detect.d.ts +0 -23
- package/dist/src/collectors/auto_detect.js +33 -55
- package/dist/src/collectors/db_pool_collector.d.ts +14 -16
- package/dist/src/collectors/db_pool_collector.js +72 -57
- package/dist/src/collectors/log_collector.d.ts +0 -47
- package/dist/src/collectors/log_collector.js +36 -65
- package/dist/src/collectors/queue_collector.d.ts +0 -20
- package/dist/src/collectors/queue_collector.js +60 -76
- package/dist/src/collectors/redis_collector.d.ts +10 -10
- package/dist/src/collectors/redis_collector.js +69 -66
- package/dist/src/config/deprecation_migration.d.ts +7 -0
- package/dist/src/config/deprecation_migration.js +201 -0
- package/dist/src/controller/debug_controller.d.ts +1 -1
- package/dist/src/controller/debug_controller.js +87 -81
- package/dist/src/dashboard/cache_handlers.d.ts +14 -0
- package/dist/src/dashboard/cache_handlers.js +52 -0
- package/dist/src/dashboard/chart_aggregator.d.ts +0 -7
- package/dist/src/dashboard/chart_aggregator.js +68 -50
- package/dist/src/dashboard/coalesce_cache.d.ts +25 -0
- package/dist/src/dashboard/coalesce_cache.js +47 -0
- package/dist/src/dashboard/dashboard_controller.d.ts +11 -37
- package/dist/src/dashboard/dashboard_controller.js +51 -544
- package/dist/src/dashboard/dashboard_page_assets.d.ts +17 -0
- package/dist/src/dashboard/dashboard_page_assets.js +51 -0
- package/dist/src/dashboard/dashboard_store.d.ts +19 -218
- package/dist/src/dashboard/dashboard_store.js +115 -1116
- package/dist/src/dashboard/dashboard_types.d.ts +83 -0
- package/dist/src/dashboard/dashboard_types.js +4 -0
- package/dist/src/dashboard/detail_queries.d.ts +19 -0
- package/dist/src/dashboard/detail_queries.js +98 -0
- package/dist/src/dashboard/email_event_builder.d.ts +8 -0
- package/dist/src/dashboard/email_event_builder.js +65 -0
- package/dist/src/dashboard/explain_query.d.ts +8 -0
- package/dist/src/dashboard/explain_query.js +22 -0
- package/dist/src/dashboard/filter_handlers.d.ts +23 -0
- package/dist/src/dashboard/filter_handlers.js +56 -0
- package/dist/src/dashboard/filtered_queries.d.ts +15 -0
- package/dist/src/dashboard/filtered_queries.js +155 -0
- package/dist/src/dashboard/flush_manager.d.ts +25 -0
- package/dist/src/dashboard/flush_manager.js +107 -0
- package/dist/src/dashboard/format_helpers.d.ts +126 -0
- package/dist/src/dashboard/format_helpers.js +140 -0
- package/dist/src/dashboard/inspector_manager.d.ts +36 -0
- package/dist/src/dashboard/inspector_manager.js +102 -0
- package/dist/src/dashboard/integrations/config_inspector.js +11 -13
- package/dist/src/dashboard/integrations/queue_inspector.d.ts +3 -3
- package/dist/src/dashboard/integrations/queue_inspector.js +13 -10
- package/dist/src/dashboard/jobs_handlers.d.ts +14 -0
- package/dist/src/dashboard/jobs_handlers.js +61 -0
- package/dist/src/dashboard/knex_factory.d.ts +18 -0
- package/dist/src/dashboard/knex_factory.js +91 -0
- package/dist/src/dashboard/migrator.js +30 -159
- package/dist/src/dashboard/migrator_tables.d.ts +19 -0
- package/dist/src/dashboard/migrator_tables.js +153 -0
- package/dist/src/dashboard/overview_queries.d.ts +66 -0
- package/dist/src/dashboard/overview_queries.js +155 -0
- package/dist/src/dashboard/overview_query_runners.d.ts +25 -0
- package/dist/src/dashboard/overview_query_runners.js +84 -0
- package/dist/src/dashboard/overview_store_queries.d.ts +40 -0
- package/dist/src/dashboard/overview_store_queries.js +69 -0
- package/dist/src/dashboard/paginate_helper.d.ts +12 -0
- package/dist/src/dashboard/paginate_helper.js +33 -0
- package/dist/src/dashboard/query_explain_handler.d.ts +10 -0
- package/dist/src/dashboard/query_explain_handler.js +80 -0
- package/dist/src/dashboard/read_queries.d.ts +32 -0
- package/dist/src/dashboard/read_queries.js +107 -0
- package/dist/src/dashboard/saved_filter_queries.d.ts +10 -0
- package/dist/src/dashboard/saved_filter_queries.js +24 -0
- package/dist/src/dashboard/storage_stats.d.ts +41 -0
- package/dist/src/dashboard/storage_stats.js +81 -0
- package/dist/src/dashboard/write_queue.d.ts +106 -0
- package/dist/src/dashboard/write_queue.js +225 -0
- package/dist/src/data/data_access.d.ts +2 -39
- package/dist/src/data/data_access.js +17 -193
- package/dist/src/data/data_access_helpers.d.ts +130 -0
- package/dist/src/data/data_access_helpers.js +212 -0
- package/dist/src/debug/debug_store.js +37 -32
- package/dist/src/debug/email_collector.d.ts +1 -10
- package/dist/src/debug/email_collector.js +78 -81
- package/dist/src/debug/event_collector.d.ts +0 -9
- package/dist/src/debug/event_collector.js +79 -62
- package/dist/src/debug/query_collector.js +23 -19
- package/dist/src/debug/route_inspector.d.ts +1 -5
- package/dist/src/debug/route_inspector.js +50 -51
- package/dist/src/debug/trace_collector.d.ts +9 -1
- package/dist/src/debug/trace_collector.js +21 -15
- package/dist/src/debug/types.d.ts +1 -1
- package/dist/src/define_config.d.ts +0 -65
- package/dist/src/define_config.js +93 -333
- package/dist/src/edge/client/dashboard.js +2 -2
- package/dist/src/edge/client/debug-panel-deferred.js +1 -1
- package/dist/src/edge/client/stats-bar.js +1 -1
- package/dist/src/edge/client-vue/dashboard.js +5 -5
- package/dist/src/edge/client-vue/debug-panel-deferred.js +3 -3
- package/dist/src/edge/client-vue/stats-bar.js +3 -3
- package/dist/src/edge/plugin.d.ts +0 -16
- package/dist/src/edge/plugin.js +57 -64
- package/dist/src/engine/request_metrics.d.ts +1 -0
- package/dist/src/engine/request_metrics.js +32 -42
- package/dist/src/middleware/request_tracking_middleware.d.ts +2 -8
- package/dist/src/middleware/request_tracking_middleware.js +65 -93
- package/dist/src/provider/auth_middleware_detector.d.ts +16 -0
- package/dist/src/provider/auth_middleware_detector.js +97 -0
- package/dist/src/provider/boot_helpers.d.ts +20 -0
- package/dist/src/provider/boot_helpers.js +91 -0
- package/dist/src/provider/boot_initializer.d.ts +28 -0
- package/dist/src/provider/boot_initializer.js +35 -0
- package/dist/src/provider/dashboard_init.d.ts +30 -0
- package/dist/src/provider/dashboard_init.js +138 -0
- package/dist/src/provider/dashboard_setup.d.ts +25 -0
- package/dist/src/provider/dashboard_setup.js +78 -0
- package/dist/src/provider/diagnostics.d.ts +134 -0
- package/dist/src/provider/diagnostics.js +127 -0
- package/dist/src/provider/email_bridge.d.ts +43 -0
- package/dist/src/provider/email_bridge.js +80 -0
- package/dist/src/provider/email_helpers.d.ts +13 -0
- package/dist/src/provider/email_helpers.js +68 -0
- package/dist/src/provider/pino_hook.d.ts +17 -0
- package/dist/src/provider/pino_hook.js +35 -0
- package/dist/src/provider/provider_helpers_extra.d.ts +47 -0
- package/dist/src/provider/provider_helpers_extra.js +177 -0
- package/dist/src/provider/server_stats_provider.d.ts +39 -85
- package/dist/src/provider/server_stats_provider.js +132 -951
- package/dist/src/provider/shutdown_helpers.d.ts +43 -0
- package/dist/src/provider/shutdown_helpers.js +70 -0
- package/dist/src/provider/toolbar_setup.d.ts +57 -0
- package/dist/src/provider/toolbar_setup.js +141 -0
- package/dist/src/routes/dashboard_routes.d.ts +14 -0
- package/dist/src/routes/dashboard_routes.js +197 -0
- package/dist/src/routes/debug_routes.d.ts +14 -0
- package/dist/src/routes/debug_routes.js +101 -0
- package/dist/src/routes/register_routes.d.ts +0 -78
- package/dist/src/routes/register_routes.js +22 -352
- package/dist/src/routes/stats_routes.d.ts +5 -0
- package/dist/src/routes/stats_routes.js +14 -0
- package/dist/src/styles/components.css +96 -0
- package/dist/src/styles/dashboard.css +8 -90
- package/dist/src/styles/debug-panel.css +1 -31
- package/dist/src/types.d.ts +305 -14
- package/dist/vue/{CacheSection-oFAJL3mo.js → CacheSection-ITqvpfH5.js} +1 -1
- package/dist/vue/{ConfigSection-BhfJ4KqL.js → ConfigSection-DTn3GslE.js} +1 -1
- package/dist/vue/{EmailsSection-BcNyhyHs.js → EmailsSection-DtLJ4XoS.js} +1 -1
- package/dist/vue/{EventsSection-r60Q5Lmu.js → EventsSection-BOYYz0Ty.js} +1 -1
- package/dist/vue/{JobsSection-BHL-hkQw.js → JobsSection-BazTxcJL.js} +1 -1
- package/dist/vue/{LogsSection-DRMGzJmg.js → LogsSection-D55PjTKX.js} +9 -3
- package/dist/vue/{LogsTab-Bg3o0Mm6.js → LogsTab-47zEK7jL.js} +4 -1
- package/dist/vue/{OverviewSection-CXh6Ja1B.js → OverviewSection-1uBKo-Tu.js} +1 -1
- package/dist/vue/{QueriesSection-IodIsCJ-.js → QueriesSection-rpoZ4ogd.js} +1 -1
- package/dist/vue/{RequestsSection-BPuMdmMc.js → RequestsSection-x7LvT0MC.js} +1 -1
- package/dist/vue/{RoutesSection-NKo3Rbq3.js → RoutesSection-CCD0zZqQ.js} +1 -1
- package/dist/vue/composables/useDashboardData.d.ts +12 -23
- package/dist/vue/index-C8MxnS7Q.js +1232 -0
- package/dist/vue/index.js +1 -1
- package/dist/vue/style.css +1 -1
- package/package.json +1 -1
- package/dist/react/CacheTab-CA8LB1J5.js +0 -123
- package/dist/react/CustomPaneTab-Bxtv_8Rw.js +0 -104
- package/dist/react/EmailsTab-BDhEiomM.js +0 -153
- package/dist/react/EventsTab-CMfY98Rl.js +0 -63
- package/dist/react/LogsTab-CicucmVk.js +0 -103
- package/dist/react/RoutesTab-DgVzd2PZ.js +0 -74
- package/dist/react/index-Cflz9Ebj.js +0 -1069
- package/dist/vue/index-Dtgysd26.js +0 -1229
|
@@ -1,41 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
21
|
+
}
|
|
22
|
+
/** Apply dashboard config onto the result. */
|
|
23
|
+
function applyDashboardConfig(dashboard, result) {
|
|
34
24
|
if (dashboard === true) {
|
|
35
|
-
result.enabled = true;
|
|
25
|
+
result.enabled = true;
|
|
36
26
|
result.dashboard = true;
|
|
27
|
+
return;
|
|
37
28
|
}
|
|
38
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
155
|
-
|
|
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
|
-
*
|
|
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
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
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
|
-
|
|
245
|
-
|
|
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
|
-
|
|
254
|
-
|
|
255
|
-
entries.push(buildDevToolbarMigration(config.devToolbar));
|
|
73
|
+
else if (config.toolbar === false) {
|
|
74
|
+
result.enabled = false;
|
|
256
75
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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
|
-
|
|
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
|
|
285
|
-
*
|
|
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
|
|
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
|
-
* //
|
|
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
|
-
*
|
|
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
|
}
|