@browdacode/adonisjs-debugbar 0.0.0-stage → 1.0.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.
- package/CHANGELOG.md +31 -0
- package/LICENSE +21 -0
- package/README.md +187 -2
- package/build/configure.d.ts +3 -0
- package/build/configure.d.ts.map +1 -0
- package/build/configure.js +14 -0
- package/build/configure.js.map +1 -0
- package/build/index.d.ts +9 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +9 -0
- package/build/index.js.map +1 -0
- package/build/providers/debugbar_provider.d.ts +14 -0
- package/build/providers/debugbar_provider.d.ts.map +1 -0
- package/build/providers/debugbar_provider.js +177 -0
- package/build/providers/debugbar_provider.js.map +1 -0
- package/build/services/debugbar.d.ts +4 -0
- package/build/services/debugbar.d.ts.map +1 -0
- package/build/services/debugbar.js +7 -0
- package/build/services/debugbar.js.map +1 -0
- package/build/src/collectors/context_collectors.d.ts +21 -0
- package/build/src/collectors/context_collectors.d.ts.map +1 -0
- package/build/src/collectors/context_collectors.js +183 -0
- package/build/src/collectors/context_collectors.js.map +1 -0
- package/build/src/config.d.ts +8 -0
- package/build/src/config.d.ts.map +1 -0
- package/build/src/config.js +51 -0
- package/build/src/config.js.map +1 -0
- package/build/src/context/request_tracker.d.ts +34 -0
- package/build/src/context/request_tracker.d.ts.map +1 -0
- package/build/src/context/request_tracker.js +21 -0
- package/build/src/context/request_tracker.js.map +1 -0
- package/build/src/debugbar.d.ts +105 -0
- package/build/src/debugbar.d.ts.map +1 -0
- package/build/src/debugbar.js +606 -0
- package/build/src/debugbar.js.map +1 -0
- package/build/src/hooks/runtime_hooks.d.ts +37 -0
- package/build/src/hooks/runtime_hooks.d.ts.map +1 -0
- package/build/src/hooks/runtime_hooks.js +279 -0
- package/build/src/hooks/runtime_hooks.js.map +1 -0
- package/build/src/middleware/debugbar_middleware.d.ts +10 -0
- package/build/src/middleware/debugbar_middleware.d.ts.map +1 -0
- package/build/src/middleware/debugbar_middleware.js +114 -0
- package/build/src/middleware/debugbar_middleware.js.map +1 -0
- package/build/src/storage/file_storage.d.ts +21 -0
- package/build/src/storage/file_storage.d.ts.map +1 -0
- package/build/src/storage/file_storage.js +102 -0
- package/build/src/storage/file_storage.js.map +1 -0
- package/build/src/storage/memory_storage.d.ts +19 -0
- package/build/src/storage/memory_storage.d.ts.map +1 -0
- package/build/src/storage/memory_storage.js +75 -0
- package/build/src/storage/memory_storage.js.map +1 -0
- package/build/src/types.d.ts +282 -0
- package/build/src/types.d.ts.map +1 -0
- package/build/src/types.js +2 -0
- package/build/src/types.js.map +1 -0
- package/build/src/ui/render_script.d.ts +10 -0
- package/build/src/ui/render_script.d.ts.map +1 -0
- package/build/src/ui/render_script.js +990 -0
- package/build/src/ui/render_script.js.map +1 -0
- package/build/src/ui/styles.d.ts +5 -0
- package/build/src/ui/styles.d.ts.map +1 -0
- package/build/src/ui/styles.js +540 -0
- package/build/src/ui/styles.js.map +1 -0
- package/build/src/utils/mask.d.ts +19 -0
- package/build/src/utils/mask.d.ts.map +1 -0
- package/build/src/utils/mask.js +155 -0
- package/build/src/utils/mask.js.map +1 -0
- package/build/stubs/config/debugbar.stub +49 -0
- package/build/stubs/main.d.ts +2 -0
- package/build/stubs/main.d.ts.map +1 -0
- package/build/stubs/main.js +4 -0
- package/build/stubs/main.js.map +1 -0
- package/build/tests/debugbar.test.d.ts +2 -0
- package/build/tests/debugbar.test.d.ts.map +1 -0
- package/build/tests/debugbar.test.js +532 -0
- package/build/tests/debugbar.test.js.map +1 -0
- package/package.json +81 -4
- package/stubs/config/debugbar.stub +49 -0
- package/stubs/main.ts +4 -0
|
@@ -0,0 +1,990 @@
|
|
|
1
|
+
import { DEBUGBAR_STYLES } from './styles.js';
|
|
2
|
+
function escapeJsonForScript(data) {
|
|
3
|
+
return JSON.stringify(data)
|
|
4
|
+
.replace(/</g, '\\u003c')
|
|
5
|
+
.replace(/>/g, '\\u003e')
|
|
6
|
+
.replace(/&/g, '\\u0026')
|
|
7
|
+
.replace(/\u2028/g, '\\u2028')
|
|
8
|
+
.replace(/\u2029/g, '\\u2029');
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Generates the self-contained Shadow DOM Debugbar snippet injected into HTML responses.
|
|
12
|
+
*/
|
|
13
|
+
export function renderDebugbarHtml(profile, routePrefix, standalone = false) {
|
|
14
|
+
const safeProfileJson = escapeJsonForScript(profile);
|
|
15
|
+
const safeStyles = escapeJsonForScript(DEBUGBAR_STYLES);
|
|
16
|
+
const safePrefix = escapeJsonForScript(routePrefix);
|
|
17
|
+
const safeStandalone = standalone ? 'true' : 'false';
|
|
18
|
+
return `
|
|
19
|
+
<!-- AdonisJS Debugbar -->
|
|
20
|
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
21
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
22
|
+
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap" rel="stylesheet">
|
|
23
|
+
<adonis-debugbar id="__adonis_debugbar__"></adonis-debugbar>
|
|
24
|
+
<script>
|
|
25
|
+
(function() {
|
|
26
|
+
if (window.__ADONIS_DEBUGBAR_INIT__) return;
|
|
27
|
+
window.__ADONIS_DEBUGBAR_INIT__ = true;
|
|
28
|
+
|
|
29
|
+
const INITIAL_PROFILE = ${safeProfileJson};
|
|
30
|
+
const STYLES = ${safeStyles};
|
|
31
|
+
const ROUTE_PREFIX = ${safePrefix};
|
|
32
|
+
const STANDALONE = ${safeStandalone};
|
|
33
|
+
|
|
34
|
+
class AdonisDebugbarElement extends HTMLElement {
|
|
35
|
+
constructor() {
|
|
36
|
+
super();
|
|
37
|
+
this.attachShadow({ mode: 'open' });
|
|
38
|
+
let savedTheme = 'dark';
|
|
39
|
+
try { savedTheme = localStorage.getItem('adonis-debugbar-theme') || 'dark'; } catch {}
|
|
40
|
+
this.state = {
|
|
41
|
+
open: STANDALONE,
|
|
42
|
+
collapsed: false,
|
|
43
|
+
theme: savedTheme === 'light' ? 'light' : 'dark',
|
|
44
|
+
activeTab: INITIAL_PROFILE.exception
|
|
45
|
+
? 'exception'
|
|
46
|
+
: (INITIAL_PROFILE.validation && INITIAL_PROFILE.validation.count > 0 ? 'validation' : 'overview'),
|
|
47
|
+
profile: INITIAL_PROFILE,
|
|
48
|
+
history: [],
|
|
49
|
+
sqlFilter: 'all',
|
|
50
|
+
sqlSearch: '',
|
|
51
|
+
sqlExplains: {},
|
|
52
|
+
liveConnected: false,
|
|
53
|
+
logLevel: 'all',
|
|
54
|
+
logSearch: '',
|
|
55
|
+
routeSearch: '',
|
|
56
|
+
drawerHeight: STANDALONE ? Math.max(460, window.innerHeight - 86) : 460
|
|
57
|
+
};
|
|
58
|
+
this.setAttribute('data-theme', this.state.theme);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
toggleTheme() {
|
|
62
|
+
this.state.theme = this.state.theme === 'dark' ? 'light' : 'dark';
|
|
63
|
+
this.setAttribute('data-theme', this.state.theme);
|
|
64
|
+
try { localStorage.setItem('adonis-debugbar-theme', this.state.theme); } catch {}
|
|
65
|
+
this.render();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
getCsrfToken() {
|
|
69
|
+
const match = document.cookie.match(/(?:^|;\\s*)XSRF-TOKEN=([^;]+)/);
|
|
70
|
+
return match ? decodeURIComponent(match[1]) : '';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
connectedCallback() {
|
|
74
|
+
this.render();
|
|
75
|
+
this.refreshHistory(false);
|
|
76
|
+
this.hookFetch();
|
|
77
|
+
this.hookKeyboard();
|
|
78
|
+
this.connectStream();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
disconnectedCallback() {
|
|
82
|
+
if (this._onKeyDown) {
|
|
83
|
+
window.removeEventListener('keydown', this._onKeyDown);
|
|
84
|
+
}
|
|
85
|
+
if (this._eventSource) {
|
|
86
|
+
this._eventSource.close();
|
|
87
|
+
this._eventSource = null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
connectStream() {
|
|
92
|
+
if (typeof EventSource === 'undefined') return;
|
|
93
|
+
try {
|
|
94
|
+
const es = new EventSource(ROUTE_PREFIX + '/api/stream');
|
|
95
|
+
this._eventSource = es;
|
|
96
|
+
es.onopen = () => {
|
|
97
|
+
this.state.liveConnected = true;
|
|
98
|
+
this.renderIfIdle();
|
|
99
|
+
};
|
|
100
|
+
es.addEventListener('request', (evt) => {
|
|
101
|
+
try {
|
|
102
|
+
const summary = JSON.parse(evt.data);
|
|
103
|
+
if (!summary || !summary.id) return;
|
|
104
|
+
this.state.history = [
|
|
105
|
+
summary,
|
|
106
|
+
...this.state.history.filter((h) => h.id !== summary.id),
|
|
107
|
+
].slice(0, 100);
|
|
108
|
+
this.renderIfIdle();
|
|
109
|
+
} catch {}
|
|
110
|
+
});
|
|
111
|
+
es.onerror = () => {
|
|
112
|
+
this.state.liveConnected = false;
|
|
113
|
+
};
|
|
114
|
+
} catch {}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
renderIfIdle() {
|
|
118
|
+
const activeEl = this.shadowRoot && this.shadowRoot.activeElement;
|
|
119
|
+
const tag = activeEl && activeEl.tagName ? activeEl.tagName.toLowerCase() : '';
|
|
120
|
+
if (tag === 'input' || tag === 'select' || tag === 'textarea') return;
|
|
121
|
+
this.render();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
hookKeyboard() {
|
|
125
|
+
this._onKeyDown = (e) => {
|
|
126
|
+
const pathTarget = typeof e.composedPath === 'function' ? e.composedPath()[0] : null;
|
|
127
|
+
const activeEl =
|
|
128
|
+
(this.shadowRoot && this.shadowRoot.activeElement) ||
|
|
129
|
+
pathTarget ||
|
|
130
|
+
document.activeElement;
|
|
131
|
+
const tag = activeEl && activeEl.tagName ? activeEl.tagName.toLowerCase() : '';
|
|
132
|
+
const isTyping =
|
|
133
|
+
tag === 'input' ||
|
|
134
|
+
tag === 'textarea' ||
|
|
135
|
+
tag === 'select' ||
|
|
136
|
+
Boolean(activeEl && activeEl.isContentEditable);
|
|
137
|
+
|
|
138
|
+
if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key.toLowerCase() === 'd') {
|
|
139
|
+
e.preventDefault();
|
|
140
|
+
this.state.collapsed = false;
|
|
141
|
+
this.state.open = !this.state.open;
|
|
142
|
+
this.render();
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (e.key === 'Escape' && this.state.open) {
|
|
147
|
+
e.preventDefault();
|
|
148
|
+
this.state.open = false;
|
|
149
|
+
this.render();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (!this.state.open || isTyping) return;
|
|
154
|
+
|
|
155
|
+
const tabs = this.getTabs(this.state.profile);
|
|
156
|
+
if (e.key === 'ArrowRight' || e.key === 'ArrowLeft') {
|
|
157
|
+
e.preventDefault();
|
|
158
|
+
const idx = tabs.findIndex(t => t.id === this.state.activeTab);
|
|
159
|
+
const dir = e.key === 'ArrowRight' ? 1 : -1;
|
|
160
|
+
const next = tabs[(idx + dir + tabs.length) % tabs.length];
|
|
161
|
+
if (next) {
|
|
162
|
+
this.state.activeTab = next.id;
|
|
163
|
+
this.render();
|
|
164
|
+
}
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (e.key >= '1' && e.key <= '9') {
|
|
169
|
+
const tab = tabs[Number(e.key) - 1];
|
|
170
|
+
if (tab) {
|
|
171
|
+
e.preventDefault();
|
|
172
|
+
this.state.activeTab = tab.id;
|
|
173
|
+
this.render();
|
|
174
|
+
}
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (e.key === '/') {
|
|
179
|
+
const searchInput = this.shadowRoot.querySelector('input.adb-input');
|
|
180
|
+
if (searchInput) {
|
|
181
|
+
e.preventDefault();
|
|
182
|
+
searchInput.focus();
|
|
183
|
+
}
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (e.key.toLowerCase() === 't') {
|
|
188
|
+
e.preventDefault();
|
|
189
|
+
this.toggleTheme();
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
window.addEventListener('keydown', this._onKeyDown);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async refreshHistory(loadLatest = false) {
|
|
196
|
+
try {
|
|
197
|
+
const res = await fetch(ROUTE_PREFIX + '/api/requests', { credentials: 'same-origin' });
|
|
198
|
+
if (res.ok) {
|
|
199
|
+
const data = await res.json();
|
|
200
|
+
this.state.history = Array.isArray(data.requests) ? data.requests : [];
|
|
201
|
+
if (loadLatest && this.state.history.length > 0) {
|
|
202
|
+
await this.loadProfile(this.state.history[0].id);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
this.render();
|
|
206
|
+
}
|
|
207
|
+
} catch {}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async loadProfile(id) {
|
|
211
|
+
try {
|
|
212
|
+
const res = await fetch(ROUTE_PREFIX + '/api/requests/' + encodeURIComponent(id), { credentials: 'same-origin' });
|
|
213
|
+
if (res.ok) {
|
|
214
|
+
this.state.profile = await res.json();
|
|
215
|
+
this.render();
|
|
216
|
+
}
|
|
217
|
+
} catch {}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async clearHistory() {
|
|
221
|
+
try {
|
|
222
|
+
const headers = {};
|
|
223
|
+
const csrf = this.getCsrfToken();
|
|
224
|
+
if (csrf) headers['X-XSRF-TOKEN'] = csrf;
|
|
225
|
+
let res = await fetch(ROUTE_PREFIX + '/api/requests', {
|
|
226
|
+
method: 'DELETE',
|
|
227
|
+
headers,
|
|
228
|
+
credentials: 'same-origin',
|
|
229
|
+
});
|
|
230
|
+
if (!res.ok) {
|
|
231
|
+
res = await fetch(ROUTE_PREFIX + '/api/clear', { credentials: 'same-origin' });
|
|
232
|
+
}
|
|
233
|
+
if (res.ok) {
|
|
234
|
+
this.state.history = [];
|
|
235
|
+
this.render();
|
|
236
|
+
}
|
|
237
|
+
} catch {}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
hookFetch() {
|
|
241
|
+
const origFetch = window.fetch;
|
|
242
|
+
const self = this;
|
|
243
|
+
window.fetch = async function(...args) {
|
|
244
|
+
const res = await origFetch.apply(this, args);
|
|
245
|
+
const url = typeof args[0] === 'string' ? args[0] : (args[0] && args[0].url) || '';
|
|
246
|
+
if (!url.includes(ROUTE_PREFIX) && res.headers.has('x-debugbar-id')) {
|
|
247
|
+
setTimeout(() => self.refreshHistory(), 120);
|
|
248
|
+
}
|
|
249
|
+
return res;
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
statusTone(code) {
|
|
254
|
+
if (code >= 500) return 'red';
|
|
255
|
+
if (code >= 400) return 'amber';
|
|
256
|
+
if (code >= 300) return 'cyan';
|
|
257
|
+
return 'green';
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
esc(val) {
|
|
261
|
+
return String(val ?? '')
|
|
262
|
+
.replace(/&/g, '&')
|
|
263
|
+
.replace(/</g, '<')
|
|
264
|
+
.replace(/>/g, '>')
|
|
265
|
+
.replace(/"/g, '"');
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
highlightSql(sql) {
|
|
269
|
+
let s = this.esc(sql);
|
|
270
|
+
const kws = ['SELECT', 'FROM', 'WHERE', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'SET', 'DELETE', 'JOIN', 'LEFT', 'RIGHT', 'INNER', 'ON', 'GROUP BY', 'ORDER BY', 'LIMIT', 'OFFSET', 'AS', 'AND', 'OR', 'IN', 'IS', 'NULL', 'NOT', 'RETURNING', 'BEGIN', 'COMMIT', 'ROLLBACK'];
|
|
271
|
+
const re = new RegExp('\\\\b(' + kws.join('|') + ')\\\\b', 'gi');
|
|
272
|
+
s = s.replace(re, '<span class="adb-sql-kw">$1</span>');
|
|
273
|
+
s = s.replace(/('[^']*')/g, '<span class="adb-sql-str">$1</span>');
|
|
274
|
+
s = s.replace(/\\b(\\d+)\\b/g, '<span class="adb-sql-num">$1</span>');
|
|
275
|
+
return s;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
formatBytes(bytes) {
|
|
279
|
+
if (!bytes && bytes !== 0) return '-';
|
|
280
|
+
const mb = bytes / (1024 * 1024);
|
|
281
|
+
return mb >= 1 ? mb.toFixed(1) + ' MB' : Math.round(bytes / 1024) + ' KB';
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
renderKvTable(obj, emptyMsg = 'No data') {
|
|
285
|
+
const entries = obj && typeof obj === 'object' ? Object.entries(obj) : [];
|
|
286
|
+
if (!entries.length) return '<div class="adb-empty">' + this.esc(emptyMsg) + '</div>';
|
|
287
|
+
return '<table class="adb-table"><tbody>' + entries.map(([k, v]) => {
|
|
288
|
+
const display = typeof v === 'object' && v !== null
|
|
289
|
+
? '<pre class="adb-pre">' + this.esc(JSON.stringify(v, null, 2)) + '</pre>'
|
|
290
|
+
: this.esc(String(v));
|
|
291
|
+
return '<tr><td class="adb-kv-key">' + this.esc(k) + '</td><td class="adb-kv-val">' + display + '</td></tr>';
|
|
292
|
+
}).join('') + '</tbody></table>';
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
renderOverview(p) {
|
|
296
|
+
const tone = this.statusTone(p.statusCode);
|
|
297
|
+
return \`
|
|
298
|
+
<div class="adb-grid">
|
|
299
|
+
<div class="adb-card">
|
|
300
|
+
<div class="adb-card-label">Request</div>
|
|
301
|
+
<div class="adb-card-value"><span class="adb-badge adb-badge-\${tone}">\${this.esc(p.method)} \${p.statusCode}</span></div>
|
|
302
|
+
</div>
|
|
303
|
+
<div class="adb-card">
|
|
304
|
+
<div class="adb-card-label">Duration</div>
|
|
305
|
+
<div class="adb-card-value">\${p.durationMs} ms</div>
|
|
306
|
+
</div>
|
|
307
|
+
<div class="adb-card">
|
|
308
|
+
<div class="adb-card-label">SQL Queries</div>
|
|
309
|
+
<div class="adb-card-value">\${p.sql.queries.length} <span style="font-size:11px;color:var(--adb-text-muted)">(\${p.sql.totalDurationMs} ms)</span></div>
|
|
310
|
+
</div>
|
|
311
|
+
<div class="adb-card">
|
|
312
|
+
<div class="adb-card-label">Heap Memory</div>
|
|
313
|
+
<div class="adb-card-value">\${this.formatBytes(p.memory.heapUsed)}</div>
|
|
314
|
+
</div>
|
|
315
|
+
</div>
|
|
316
|
+
<div class="adb-section">
|
|
317
|
+
<div class="adb-section-title">Route & Runtime</div>
|
|
318
|
+
\${this.renderKvTable({
|
|
319
|
+
URL: p.url,
|
|
320
|
+
Route: p.routePattern || '(unmatched)',
|
|
321
|
+
'Route Name': p.routeName || '-',
|
|
322
|
+
Controller: p.controller || '-',
|
|
323
|
+
'Client IP': p.ip || '-',
|
|
324
|
+
'Content-Type': p.contentType || '-',
|
|
325
|
+
'Node.js': p.app.nodeVersion + ' (' + p.app.platform + ')',
|
|
326
|
+
Environment: p.app.env
|
|
327
|
+
})}
|
|
328
|
+
</div>
|
|
329
|
+
<div class="adb-section"><div class="adb-section-title">Query Parameters</div>\${this.renderKvTable(p.request.query, 'No query parameters')}</div>
|
|
330
|
+
<div class="adb-section"><div class="adb-section-title">Route Parameters</div>\${this.renderKvTable(p.request.params, 'No route parameters')}</div>
|
|
331
|
+
<div class="adb-section"><div class="adb-section-title">Request Body</div>\${p.request.body !== undefined ? '<pre class="adb-pre">' + this.esc(JSON.stringify(p.request.body, null, 2)) + '</pre>' : '<div class="adb-empty">Empty body</div>'}</div>
|
|
332
|
+
<div class="adb-section"><div class="adb-section-title">Request Headers</div>\${this.renderKvTable(p.request.headers)}</div>
|
|
333
|
+
<div class="adb-section"><div class="adb-section-title">Response Headers</div>\${this.renderKvTable(p.response.headers)}</div>
|
|
334
|
+
\`;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
interpolateSql(sql, bindings) {
|
|
338
|
+
if (!Array.isArray(bindings) || !bindings.length) return sql;
|
|
339
|
+
const fmt = (v) => {
|
|
340
|
+
if (v === null || v === undefined) return 'NULL';
|
|
341
|
+
if (typeof v === 'number') return String(v);
|
|
342
|
+
if (typeof v === 'boolean') return v ? 'TRUE' : 'FALSE';
|
|
343
|
+
if (typeof v === 'object') return "'" + JSON.stringify(v).replace(/'/g, "''") + "'";
|
|
344
|
+
return "'" + String(v).replace(/'/g, "''") + "'";
|
|
345
|
+
};
|
|
346
|
+
if (/\\$\\d+/.test(sql)) {
|
|
347
|
+
return sql.replace(/\\$(\\d+)/g, (m, n) => {
|
|
348
|
+
const idx = Number(n) - 1;
|
|
349
|
+
return idx >= 0 && idx < bindings.length ? fmt(bindings[idx]) : m;
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
let i = 0;
|
|
353
|
+
return sql.replace(/\\?/g, () => (i < bindings.length ? fmt(bindings[i++]) : '?'));
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
async explainQuery(requestId, queryId) {
|
|
357
|
+
this.state.sqlExplains[queryId] = { loading: true };
|
|
358
|
+
this.render();
|
|
359
|
+
try {
|
|
360
|
+
const res = await fetch(
|
|
361
|
+
ROUTE_PREFIX + '/api/explain?requestId=' + encodeURIComponent(requestId) + '&queryId=' + encodeURIComponent(queryId),
|
|
362
|
+
{ credentials: 'same-origin' }
|
|
363
|
+
);
|
|
364
|
+
const data = await res.json();
|
|
365
|
+
this.state.sqlExplains[queryId] = res.ok
|
|
366
|
+
? { plan: data.plan }
|
|
367
|
+
: { error: data.error || 'Explain failed' };
|
|
368
|
+
} catch (err) {
|
|
369
|
+
this.state.sqlExplains[queryId] = { error: String(err) };
|
|
370
|
+
}
|
|
371
|
+
this.render();
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
renderSqlResults(p) {
|
|
375
|
+
const queries = p.sql.queries.filter(q => {
|
|
376
|
+
if (this.state.sqlFilter === 'slow' && !q.isSlow) return false;
|
|
377
|
+
if (this.state.sqlFilter === 'dup' && !q.isDuplicate) return false;
|
|
378
|
+
if (this.state.sqlSearch && !q.sql.toLowerCase().includes(this.state.sqlSearch.toLowerCase())) return false;
|
|
379
|
+
return true;
|
|
380
|
+
});
|
|
381
|
+
return queries.length ? queries.map((q, idx) => {
|
|
382
|
+
const isSelect = /^\\s*select\\b/i.test(q.sql);
|
|
383
|
+
const hasBindings = Array.isArray(q.bindings) && q.bindings.length > 0;
|
|
384
|
+
const interpolated = hasBindings ? this.interpolateSql(q.sql, q.bindings) : q.sql;
|
|
385
|
+
const explainState = this.state.sqlExplains[q.id];
|
|
386
|
+
return \`
|
|
387
|
+
<div class="adb-sql-card \${q.isSlow ? 'slow' : ''} \${q.isDuplicate ? 'dup' : ''}">
|
|
388
|
+
<div class="adb-sql-meta">
|
|
389
|
+
<div style="display:flex;align-items:center;gap:6px">
|
|
390
|
+
<span class="adb-badge adb-badge-indigo">#\${idx + 1}</span>
|
|
391
|
+
<span class="adb-badge adb-badge-cyan">\${this.esc(q.connection)}</span>
|
|
392
|
+
\${q.model ? '<span class="adb-badge adb-badge-muted">' + this.esc(q.model) + '</span>' : ''}
|
|
393
|
+
\${q.isSlow ? '<span class="adb-badge adb-badge-amber">SLOW</span>' : ''}
|
|
394
|
+
\${q.isDuplicate ? '<span class="adb-badge adb-badge-red">DUP ×' + (q.duplicateCount || 2) + '</span>' : ''}
|
|
395
|
+
</div>
|
|
396
|
+
<div style="display:flex;align-items:center;gap:6px;flex-wrap:wrap">
|
|
397
|
+
<span style="color:var(--adb-text-muted)">\${q.durationMs} ms</span>
|
|
398
|
+
<button class="adb-btn" data-copy-sql="\${this.esc(q.sql)}">Copy SQL</button>
|
|
399
|
+
\${hasBindings ? '<button class="adb-btn" data-copy-sql="' + this.esc(interpolated) + '">Copy w/ Bindings</button>' : ''}
|
|
400
|
+
\${isSelect ? '<button class="adb-btn" data-explain-id="' + this.esc(q.id) + '">Explain</button>' : ''}
|
|
401
|
+
</div>
|
|
402
|
+
</div>
|
|
403
|
+
<div class="adb-sql-code">\${this.highlightSql(q.sql)}</div>
|
|
404
|
+
\${q.caller ? '<div style="margin-top:5px;font-size:11px;color:var(--adb-text-dim)">Caller: <code>' + this.esc(q.caller) + '</code></div>' : ''}
|
|
405
|
+
\${hasBindings ? '<div style="margin-top:6px;font-size:11px;color:var(--adb-text-muted)">Bindings: <code>' + this.esc(JSON.stringify(q.bindings)) + '</code></div>' : ''}
|
|
406
|
+
\${explainState ? (
|
|
407
|
+
explainState.loading
|
|
408
|
+
? '<div style="margin-top:8px;font-size:11px;color:var(--adb-text-muted)">Running EXPLAIN...</div>'
|
|
409
|
+
: explainState.error
|
|
410
|
+
? '<div style="margin-top:8px;font-size:11px;color:var(--adb-red)">EXPLAIN Error: ' + this.esc(explainState.error) + '</div>'
|
|
411
|
+
: '<div style="margin-top:8px"><div style="font-size:10.5px;color:var(--adb-indigo-light);margin-bottom:4px">EXPLAIN PLAN</div><pre class="adb-pre">' + this.esc(JSON.stringify(explainState.plan, null, 2)) + '</pre></div>'
|
|
412
|
+
) : ''}
|
|
413
|
+
</div>
|
|
414
|
+
\`;
|
|
415
|
+
}).join('') : '<div class="adb-empty">No SQL queries captured for this request.</div>';
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
renderSql(p) {
|
|
419
|
+
return \`
|
|
420
|
+
<div class="adb-toolbar">
|
|
421
|
+
<button class="adb-btn" data-sql-filter="all">All (\${p.sql.queries.length})</button>
|
|
422
|
+
<button class="adb-btn" data-sql-filter="slow">Slow (\${p.sql.slowCount})</button>
|
|
423
|
+
<button class="adb-btn" data-sql-filter="dup">Duplicates / N+1 (\${p.sql.duplicateCount})</button>
|
|
424
|
+
<input class="adb-input" data-sql-search placeholder="Filter SQL..." value="\${this.esc(this.state.sqlSearch)}" style="min-width:220px" />
|
|
425
|
+
</div>
|
|
426
|
+
<div data-sql-results>\${this.renderSqlResults(p)}</div>
|
|
427
|
+
\`;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
renderTimeline(p) {
|
|
431
|
+
const total = Math.max(p.durationMs, 1);
|
|
432
|
+
if (!p.timeline.length) return '<div class="adb-empty">No timeline spans recorded. Use <code>debugbar.startMeasure()</code> or run SQL queries.</div>';
|
|
433
|
+
return '<div class="adb-section"><div class="adb-section-title"><span>Request Waterfall</span><span>' + total + ' ms total</span></div>' +
|
|
434
|
+
p.timeline.map(span => {
|
|
435
|
+
const left = Math.min(100, (span.startOffsetMs / total) * 100);
|
|
436
|
+
const width = Math.max(1, Math.min(100 - left, (span.durationMs / total) * 100));
|
|
437
|
+
return \`
|
|
438
|
+
<div class="adb-tl-row">
|
|
439
|
+
<div style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap" title="\${this.esc(span.label)}">\${this.esc(span.label)}</div>
|
|
440
|
+
<div class="adb-tl-track"><div class="adb-tl-bar \${this.esc(span.category)}" style="left:\${left}%;width:\${width}%"></div></div>
|
|
441
|
+
<div style="text-align:right;color:var(--adb-text-muted)">\${span.durationMs} ms</div>
|
|
442
|
+
</div>
|
|
443
|
+
\`;
|
|
444
|
+
}).join('') + '</div>';
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
renderAuth(p) {
|
|
448
|
+
if (!p.auth.available) {
|
|
449
|
+
return '<div class="adb-empty">@adonisjs/auth is not active on this request context.</div>';
|
|
450
|
+
}
|
|
451
|
+
return \`
|
|
452
|
+
<div class="adb-section">
|
|
453
|
+
<div class="adb-section-title">Authentication</div>
|
|
454
|
+
\${this.renderKvTable({
|
|
455
|
+
Authenticated: p.auth.authenticated ? 'Yes' : 'No (Guest)',
|
|
456
|
+
Guard: p.auth.guard || 'default'
|
|
457
|
+
})}
|
|
458
|
+
</div>
|
|
459
|
+
<div class="adb-section">
|
|
460
|
+
<div class="adb-section-title">Authenticated User</div>
|
|
461
|
+
\${p.auth.user ? '<pre class="adb-pre">' + this.esc(JSON.stringify(p.auth.user, null, 2)) + '</pre>' : '<div class="adb-empty">Guest user</div>'}
|
|
462
|
+
</div>
|
|
463
|
+
\`;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
renderSession(p) {
|
|
467
|
+
return \`
|
|
468
|
+
<div class="adb-section">
|
|
469
|
+
<div class="adb-section-title">Session Metadata</div>
|
|
470
|
+
\${this.renderKvTable({
|
|
471
|
+
Available: p.session.available ? 'Yes' : 'No',
|
|
472
|
+
'Session ID': p.session.id || '-',
|
|
473
|
+
Driver: p.session.driver || '-'
|
|
474
|
+
})}
|
|
475
|
+
</div>
|
|
476
|
+
<div class="adb-section"><div class="adb-section-title">Session Data</div>\${this.renderKvTable(p.session.values, 'Empty session')}</div>
|
|
477
|
+
<div class="adb-section"><div class="adb-section-title">Flash Messages</div>\${this.renderKvTable(p.session.flashMessages, 'No flash messages')}</div>
|
|
478
|
+
<div class="adb-section"><div class="adb-section-title">Cookies</div>\${this.renderKvTable(p.session.cookies, 'No cookies')}</div>
|
|
479
|
+
\`;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
renderLogResults(p) {
|
|
483
|
+
const logs = p.logs.filter(l => {
|
|
484
|
+
if (this.state.logLevel !== 'all' && l.level !== this.state.logLevel) return false;
|
|
485
|
+
if (this.state.logSearch && !l.message.toLowerCase().includes(this.state.logSearch.toLowerCase())) return false;
|
|
486
|
+
return true;
|
|
487
|
+
});
|
|
488
|
+
return logs.length ? '<div class="adb-section"><table class="adb-table"><thead><tr><th>Level</th><th>Message</th><th>Context</th></tr></thead><tbody>' + logs.map(l => {
|
|
489
|
+
const badge = l.level === 'error' || l.level === 'fatal' ? 'red' : l.level === 'warn' ? 'amber' : l.level === 'info' ? 'cyan' : 'muted';
|
|
490
|
+
return '<tr><td><span class="adb-badge adb-badge-' + badge + '">' + this.esc(l.level.toUpperCase()) + '</span></td><td>' + this.esc(l.message) + '</td><td>' + (l.context ? '<pre class="adb-pre">' + this.esc(JSON.stringify(l.context, null, 2)) + '</pre>' : '-') + '</td></tr>';
|
|
491
|
+
}).join('') + '</tbody></table></div>' : '<div class="adb-empty">No logs recorded for this request.</div>';
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
renderLogs(p) {
|
|
495
|
+
return \`
|
|
496
|
+
<div class="adb-toolbar">
|
|
497
|
+
<select class="adb-select" data-log-level>
|
|
498
|
+
<option value="all" \${this.state.logLevel === 'all' ? 'selected' : ''}>All Levels</option>
|
|
499
|
+
<option value="debug" \${this.state.logLevel === 'debug' ? 'selected' : ''}>Debug</option>
|
|
500
|
+
<option value="info" \${this.state.logLevel === 'info' ? 'selected' : ''}>Info</option>
|
|
501
|
+
<option value="warn" \${this.state.logLevel === 'warn' ? 'selected' : ''}>Warn</option>
|
|
502
|
+
<option value="error" \${this.state.logLevel === 'error' ? 'selected' : ''}>Error</option>
|
|
503
|
+
</select>
|
|
504
|
+
<input class="adb-input" data-log-search placeholder="Filter logs..." value="\${this.esc(this.state.logSearch)}" style="min-width:220px" />
|
|
505
|
+
</div>
|
|
506
|
+
<div data-log-results>\${this.renderLogResults(p)}</div>
|
|
507
|
+
\`;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
renderRouteResults(p) {
|
|
511
|
+
const q = this.state.routeSearch.toLowerCase();
|
|
512
|
+
const routes = p.routes.filter(r => !q || r.pattern.toLowerCase().includes(q) || (r.name || '').toLowerCase().includes(q) || r.handler.toLowerCase().includes(q));
|
|
513
|
+
return routes.length ? '<div class="adb-section"><table class="adb-table"><thead><tr><th>Methods</th><th>Pattern</th><th>Name</th><th>Handler</th></tr></thead><tbody>' + routes.map(r => \`
|
|
514
|
+
<tr class="\${r.isCurrent ? 'adb-row-highlight' : ''}">
|
|
515
|
+
<td>\${r.methods.map(m => '<span class="adb-badge adb-badge-indigo" style="margin-right:3px">' + this.esc(m) + '</span>').join('')}</td>
|
|
516
|
+
<td>\${this.esc(r.pattern)} \${r.isCurrent ? '<span class="adb-badge adb-badge-green">CURRENT</span>' : ''}</td>
|
|
517
|
+
<td>\${this.esc(r.name || '-')}</td>
|
|
518
|
+
<td style="color:var(--adb-text-muted)">\${this.esc(r.handler)}</td>
|
|
519
|
+
</tr>
|
|
520
|
+
\`).join('') + '</tbody></table></div>' : '<div class="adb-empty">No matching routes.</div>';
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
renderRoutes(p) {
|
|
524
|
+
return \`
|
|
525
|
+
<div class="adb-toolbar">
|
|
526
|
+
<input class="adb-input" data-route-search placeholder="Search routes (pattern, name, handler)..." value="\${this.esc(this.state.routeSearch)}" style="min-width:280px" />
|
|
527
|
+
<span style="color:var(--adb-text-muted)">\${p.routes.length} routes</span>
|
|
528
|
+
</div>
|
|
529
|
+
<div data-route-results>\${this.renderRouteResults(p)}</div>
|
|
530
|
+
\`;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
renderEvents(p) {
|
|
534
|
+
if (!p.events.length) return '<div class="adb-empty">No events recorded for this request.</div>';
|
|
535
|
+
return '<div class="adb-section"><table class="adb-table"><thead><tr><th>Offset</th><th>Event</th><th>Payload</th></tr></thead><tbody>' +
|
|
536
|
+
p.events.map(e => '<tr><td>+' + e.offsetMs + ' ms</td><td><span class="adb-badge adb-badge-indigo">' + this.esc(e.name) + '</span></td><td>' + (e.payload !== undefined ? '<pre class="adb-pre">' + this.esc(JSON.stringify(e.payload, null, 2)) + '</pre>' : '-') + '</td></tr>').join('') +
|
|
537
|
+
'</tbody></table></div>';
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
renderViews(p) {
|
|
541
|
+
const all = p.views || [];
|
|
542
|
+
if (!all.length) {
|
|
543
|
+
return '<div class="adb-empty">No Edge or Inertia views rendered during this request.</div>';
|
|
544
|
+
}
|
|
545
|
+
const mainViews = all.filter(v => !v.kind || v.kind === 'view');
|
|
546
|
+
const layouts = all.filter(v => v.kind === 'layout');
|
|
547
|
+
const components = all.filter(v => v.kind === 'component');
|
|
548
|
+
const partials = all.filter(v => v.kind === 'partial' || v.kind === 'template');
|
|
549
|
+
|
|
550
|
+
const kindBadge = (k) => {
|
|
551
|
+
if (k === 'layout') return 'cyan';
|
|
552
|
+
if (k === 'component') return 'green';
|
|
553
|
+
if (k === 'partial') return 'amber';
|
|
554
|
+
return 'indigo';
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
return \`
|
|
558
|
+
<div class="adb-grid">
|
|
559
|
+
<div class="adb-card"><div class="adb-card-label">Views</div><div class="adb-card-value">\${mainViews.length}</div></div>
|
|
560
|
+
<div class="adb-card"><div class="adb-card-label">Layouts</div><div class="adb-card-value">\${layouts.length}</div></div>
|
|
561
|
+
<div class="adb-card"><div class="adb-card-label">Components</div><div class="adb-card-value">\${components.length}</div></div>
|
|
562
|
+
<div class="adb-card"><div class="adb-card-label">Partials / Includes</div><div class="adb-card-value">\${partials.length}</div></div>
|
|
563
|
+
</div>
|
|
564
|
+
\${all.length ? \`
|
|
565
|
+
<div class="adb-section">
|
|
566
|
+
<div class="adb-section-title">Loaded Templates, Layouts & Components</div>
|
|
567
|
+
<table class="adb-table">
|
|
568
|
+
<thead><tr><th>Kind</th><th>Engine</th><th>Template</th><th>Duration</th><th>Resolved Path</th></tr></thead>
|
|
569
|
+
<tbody>
|
|
570
|
+
\${all.map(v => \`
|
|
571
|
+
<tr>
|
|
572
|
+
<td><span class="adb-badge adb-badge-\${kindBadge(v.kind || 'view')}">\${this.esc((v.kind || 'view').toUpperCase())}</span></td>
|
|
573
|
+
<td><span class="adb-badge adb-badge-muted">\${this.esc(v.engine.toUpperCase())}</span></td>
|
|
574
|
+
<td class="adb-kv-key">\${this.esc(v.template)}</td>
|
|
575
|
+
<td>\${v.durationMs} ms</td>
|
|
576
|
+
<td style="color:var(--adb-text-dim)">\${this.esc(v.resolvedPath || '-')}</td>
|
|
577
|
+
</tr>
|
|
578
|
+
\`).join('')}
|
|
579
|
+
</tbody>
|
|
580
|
+
</table>
|
|
581
|
+
</div>
|
|
582
|
+
\` : ''}
|
|
583
|
+
\${mainViews.filter(v => v.data).map((v, idx) => \`
|
|
584
|
+
<div class="adb-section">
|
|
585
|
+
<div class="adb-section-title">
|
|
586
|
+
<span>View State #\${idx + 1}: \${this.esc(v.template)}</span>
|
|
587
|
+
<span style="color:var(--adb-text-muted)">\${v.durationMs} ms</span>
|
|
588
|
+
</div>
|
|
589
|
+
<pre class="adb-pre">\${this.esc(JSON.stringify(v.data, null, 2))}</pre>
|
|
590
|
+
</div>
|
|
591
|
+
\`).join('')}
|
|
592
|
+
\`;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
renderMails(p) {
|
|
596
|
+
const mails = p.mails || [];
|
|
597
|
+
if (!mails.length) {
|
|
598
|
+
return '<div class="adb-empty">No emails sent during this request.</div>';
|
|
599
|
+
}
|
|
600
|
+
return mails.map((m, idx) => \`
|
|
601
|
+
<div class="adb-section">
|
|
602
|
+
<div class="adb-section-title">
|
|
603
|
+
<div style="display:flex;align-items:center;gap:6px">
|
|
604
|
+
<span class="adb-badge adb-badge-indigo">#\${idx + 1}</span>
|
|
605
|
+
<span class="adb-badge adb-badge-\${m.status === 'sent' ? 'green' : 'amber'}">\${this.esc(m.status.toUpperCase())}</span>
|
|
606
|
+
<span>\${this.esc(m.subject)}</span>
|
|
607
|
+
</div>
|
|
608
|
+
<span style="color:var(--adb-text-muted)">\${this.esc(m.mailer || 'default')}</span>
|
|
609
|
+
</div>
|
|
610
|
+
\${this.renderKvTable({
|
|
611
|
+
From: m.from || '-',
|
|
612
|
+
To: (m.to || []).join(', ') || '-',
|
|
613
|
+
Subject: m.subject
|
|
614
|
+
})}
|
|
615
|
+
\${m.text ? '<pre class="adb-pre">' + this.esc(m.text) + '</pre>' : ''}
|
|
616
|
+
</div>
|
|
617
|
+
\`).join('');
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
renderCacheDrive(p) {
|
|
621
|
+
const cache = p.cache || [];
|
|
622
|
+
const drive = p.drive || [];
|
|
623
|
+
if (!cache.length && !drive.length) {
|
|
624
|
+
return '<div class="adb-empty">No Cache, Redis, or Drive operations recorded for this request.</div>';
|
|
625
|
+
}
|
|
626
|
+
const hits = cache.filter(c => c.operation === 'hit').length;
|
|
627
|
+
const misses = cache.filter(c => c.operation === 'miss').length;
|
|
628
|
+
const hitRatio = (hits + misses) > 0 ? Math.round((hits / (hits + misses)) * 100) + '%' : '-';
|
|
629
|
+
const opBadge = (op) => {
|
|
630
|
+
if (op === 'hit' || op === 'get') return 'green';
|
|
631
|
+
if (op === 'miss') return 'amber';
|
|
632
|
+
if (op === 'delete' || op === 'clear') return 'red';
|
|
633
|
+
return 'cyan';
|
|
634
|
+
};
|
|
635
|
+
return \`
|
|
636
|
+
<div class="adb-grid">
|
|
637
|
+
<div class="adb-card"><div class="adb-card-label">Cache Hits</div><div class="adb-card-value">\${hits}</div></div>
|
|
638
|
+
<div class="adb-card"><div class="adb-card-label">Cache Misses</div><div class="adb-card-value">\${misses}</div></div>
|
|
639
|
+
<div class="adb-card"><div class="adb-card-label">Hit Ratio</div><div class="adb-card-value">\${hitRatio}</div></div>
|
|
640
|
+
<div class="adb-card"><div class="adb-card-label">Drive Ops</div><div class="adb-card-value">\${drive.length}</div></div>
|
|
641
|
+
</div>
|
|
642
|
+
\${cache.length ? \`
|
|
643
|
+
<div class="adb-section">
|
|
644
|
+
<div class="adb-section-title">Cache & Redis Operations (\${cache.length})</div>
|
|
645
|
+
<table class="adb-table">
|
|
646
|
+
<thead><tr><th>Driver</th><th>Op</th><th>Key / Command</th><th>Store</th><th>Duration</th></tr></thead>
|
|
647
|
+
<tbody>
|
|
648
|
+
\${cache.map(c => \`
|
|
649
|
+
<tr>
|
|
650
|
+
<td><span class="adb-badge adb-badge-indigo">\${this.esc(c.driver.toUpperCase())}</span></td>
|
|
651
|
+
<td><span class="adb-badge adb-badge-\${opBadge(c.operation)}">\${this.esc(c.operation.toUpperCase())}</span></td>
|
|
652
|
+
<td class="adb-kv-key">\${this.esc(c.key)}</td>
|
|
653
|
+
<td>\${this.esc(c.store || '-')}</td>
|
|
654
|
+
<td>\${c.durationMs !== undefined ? c.durationMs + ' ms' : '-'}</td>
|
|
655
|
+
</tr>
|
|
656
|
+
\`).join('')}
|
|
657
|
+
</tbody>
|
|
658
|
+
</table>
|
|
659
|
+
</div>
|
|
660
|
+
\` : ''}
|
|
661
|
+
\${drive.length ? \`
|
|
662
|
+
<div class="adb-section">
|
|
663
|
+
<div class="adb-section-title">Drive Operations (\${drive.length})</div>
|
|
664
|
+
<table class="adb-table">
|
|
665
|
+
<thead><tr><th>Disk</th><th>Op</th><th>Key</th><th>Size</th><th>Duration</th></tr></thead>
|
|
666
|
+
<tbody>
|
|
667
|
+
\${drive.map(d => \`
|
|
668
|
+
<tr>
|
|
669
|
+
<td><span class="adb-badge adb-badge-indigo">\${this.esc(d.disk)}</span></td>
|
|
670
|
+
<td><span class="adb-badge adb-badge-\${opBadge(d.operation)}">\${this.esc(d.operation.toUpperCase())}</span></td>
|
|
671
|
+
<td class="adb-kv-key">\${this.esc(d.key)}</td>
|
|
672
|
+
<td>\${d.sizeBytes !== undefined ? this.formatBytes(d.sizeBytes) : '-'}</td>
|
|
673
|
+
<td>\${d.durationMs !== undefined ? d.durationMs + ' ms' : '-'}</td>
|
|
674
|
+
</tr>
|
|
675
|
+
\`).join('')}
|
|
676
|
+
</tbody>
|
|
677
|
+
</table>
|
|
678
|
+
</div>
|
|
679
|
+
\` : ''}
|
|
680
|
+
\`;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
renderValidation(p) {
|
|
684
|
+
const v = p.validation || { count: 0, source: 'none', errors: [] };
|
|
685
|
+
if (!v.errors.length) {
|
|
686
|
+
return '<div class="adb-empty">No validation errors recorded for this request.</div>';
|
|
687
|
+
}
|
|
688
|
+
return \`
|
|
689
|
+
<div class="adb-section">
|
|
690
|
+
<div class="adb-section-title">
|
|
691
|
+
<span>Validation Errors (\${v.count})</span>
|
|
692
|
+
<span class="adb-badge adb-badge-amber">Source: \${this.esc(v.source)}</span>
|
|
693
|
+
</div>
|
|
694
|
+
<table class="adb-table">
|
|
695
|
+
<thead><tr><th>Field</th><th>Rule</th><th>Message</th></tr></thead>
|
|
696
|
+
<tbody>
|
|
697
|
+
\${v.errors.map(err => \`
|
|
698
|
+
<tr>
|
|
699
|
+
<td class="adb-kv-key">\${this.esc(err.field)}</td>
|
|
700
|
+
<td>\${err.rule ? '<span class="adb-badge adb-badge-indigo">' + this.esc(err.rule) + '</span>' : '-'}</td>
|
|
701
|
+
<td><span class="adb-badge adb-badge-red">\${this.esc(err.message)}</span></td>
|
|
702
|
+
</tr>
|
|
703
|
+
\`).join('')}
|
|
704
|
+
</tbody>
|
|
705
|
+
</table>
|
|
706
|
+
</div>
|
|
707
|
+
\`;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
renderException(p) {
|
|
711
|
+
if (!p.exception) return '<div class="adb-empty">No exceptions thrown during this request.</div>';
|
|
712
|
+
return \`
|
|
713
|
+
<div class="adb-section">
|
|
714
|
+
<div class="adb-section-title" style="color:var(--adb-red)">\${this.esc(p.exception.name)}: \${this.esc(p.exception.message)}</div>
|
|
715
|
+
\${p.exception.stack ? '<pre class="adb-pre">' + this.esc(p.exception.stack) + '</pre>' : ''}
|
|
716
|
+
</div>
|
|
717
|
+
\`;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
renderTabBody(p) {
|
|
721
|
+
switch (this.state.activeTab) {
|
|
722
|
+
case 'sql': return this.renderSql(p);
|
|
723
|
+
case 'timeline': return this.renderTimeline(p);
|
|
724
|
+
case 'auth': return this.renderAuth(p);
|
|
725
|
+
case 'session': return this.renderSession(p);
|
|
726
|
+
case 'logs': return this.renderLogs(p);
|
|
727
|
+
case 'routes': return this.renderRoutes(p);
|
|
728
|
+
case 'events': return this.renderEvents(p);
|
|
729
|
+
case 'cache': return this.renderCacheDrive(p);
|
|
730
|
+
case 'views': return this.renderViews(p);
|
|
731
|
+
case 'mails': return this.renderMails(p);
|
|
732
|
+
case 'validation': return this.renderValidation(p);
|
|
733
|
+
case 'exception': return this.renderException(p);
|
|
734
|
+
default: return this.renderOverview(p);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
getTabs(p) {
|
|
739
|
+
const valCount = (p.validation && p.validation.count) || 0;
|
|
740
|
+
const viewCount = (p.views && p.views.length) || 0;
|
|
741
|
+
const mailCount = (p.mails && p.mails.length) || 0;
|
|
742
|
+
const cacheCount = ((p.cache && p.cache.length) || 0) + ((p.drive && p.drive.length) || 0);
|
|
743
|
+
const tabs = [
|
|
744
|
+
{ id: 'overview', label: 'Overview' },
|
|
745
|
+
{ id: 'sql', label: 'SQL (' + p.sql.queries.length + ')' },
|
|
746
|
+
{ id: 'views', label: 'Edge (' + viewCount + ')' },
|
|
747
|
+
{ id: 'validation', label: 'Validation' + (valCount ? ' (' + valCount + ')' : '') },
|
|
748
|
+
{ id: 'timeline', label: 'Timeline' },
|
|
749
|
+
{ id: 'auth', label: 'Auth' },
|
|
750
|
+
{ id: 'session', label: 'Session' },
|
|
751
|
+
{ id: 'logs', label: 'Logs (' + p.logs.length + ')' },
|
|
752
|
+
{ id: 'routes', label: 'Routes (' + p.routes.length + ')' },
|
|
753
|
+
{ id: 'events', label: 'Events (' + p.events.length + ')' },
|
|
754
|
+
{ id: 'cache', label: 'Cache (' + cacheCount + ')' },
|
|
755
|
+
];
|
|
756
|
+
if (mailCount) tabs.push({ id: 'mails', label: 'Mail (' + mailCount + ')' });
|
|
757
|
+
if (p.exception) tabs.unshift({ id: 'exception', label: 'Exception!' });
|
|
758
|
+
return tabs;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
render() {
|
|
762
|
+
const p = this.state.profile;
|
|
763
|
+
const tone = this.statusTone(p.statusCode);
|
|
764
|
+
const authLabel = p.auth.available ? (p.auth.authenticated ? (p.auth.user?.email || p.auth.user?.id || 'Auth') : 'Guest') : 'No Auth';
|
|
765
|
+
const valCount = (p.validation && p.validation.count) || 0;
|
|
766
|
+
const tabs = this.getTabs(p);
|
|
767
|
+
|
|
768
|
+
const svg = (path) => '<span class="adb-icon"><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round">' + path + '</svg></span>';
|
|
769
|
+
const adonisIcon = '<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path d="m13.333 1.333-.596 1.193-2.404 4.807L8 2.667l-8 16h4.667l-2 4H24zm0 2.982 8.51 17.018H4.823l1.334-2.666H16l-4.922-9.843z"/></svg>';
|
|
770
|
+
const icons = {
|
|
771
|
+
clock: svg('<circle cx="12" cy="12" r="9"/><polyline points="12 7 12 12 15 14"/>'),
|
|
772
|
+
db: svg('<ellipse cx="12" cy="5" rx="8" ry="3"/><path d="M4 5v14c0 1.66 3.58 3 8 3s8-1.34 8-3V5"/><path d="M4 12c0 1.66 3.58 3 8 3s8-1.34 8-3"/>'),
|
|
773
|
+
user: svg('<path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/>'),
|
|
774
|
+
logs: svg('<polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/>'),
|
|
775
|
+
edge: svg('<polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/>'),
|
|
776
|
+
mem: svg('<rect x="4" y="4" width="16" height="16" rx="2"/><rect x="9" y="9" width="6" height="6"/><line x1="9" y1="1" x2="9" y2="4"/><line x1="15" y1="1" x2="15" y2="4"/><line x1="9" y1="20" x2="9" y2="23"/><line x1="15" y1="20" x2="15" y2="23"/>'),
|
|
777
|
+
sun: svg('<circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41"/>'),
|
|
778
|
+
moon: svg('<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>'),
|
|
779
|
+
refresh: svg('<polyline points="23 4 23 10 17 10"/><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/>'),
|
|
780
|
+
trash: svg('<polyline points="3 6 5 6 21 6"/><path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/><path d="M10 11v6M14 11v6"/>'),
|
|
781
|
+
close: svg('<line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/>'),
|
|
782
|
+
chevron: svg('<polyline points="6 9 12 15 18 9"/>')
|
|
783
|
+
};
|
|
784
|
+
const themeIcon = this.state.theme === 'dark' ? icons.sun : icons.moon;
|
|
785
|
+
|
|
786
|
+
this.shadowRoot.innerHTML = \`
|
|
787
|
+
<style>\${STYLES}</style>
|
|
788
|
+
\${this.state.open ? \`
|
|
789
|
+
<div class="adb-drawer" style="height:\${this.state.drawerHeight}px">
|
|
790
|
+
<div class="adb-resizer" data-resizer></div>
|
|
791
|
+
<div class="adb-header">
|
|
792
|
+
<div class="adb-tabs">
|
|
793
|
+
\${tabs.map(t => \`<button class="adb-tab \${this.state.activeTab === t.id ? 'active' : ''}" data-tab="\${t.id}">\${this.esc(t.label)}</button>\`).join('')}
|
|
794
|
+
</div>
|
|
795
|
+
<div class="adb-actions">
|
|
796
|
+
\${this.state.liveConnected ? '<span class="adb-badge adb-badge-green" title="Live SSE Stream Connected"><span class="adb-live-dot" style="margin-right:5px"></span>LIVE</span>' : ''}
|
|
797
|
+
<select class="adb-select" data-history-select title="Inspect captured requests">
|
|
798
|
+
<option value="\${this.esc(p.id)}">\${this.esc(p.method)} \${this.esc(p.path)} (\${p.statusCode} · \${p.durationMs}ms)</option>
|
|
799
|
+
\${this.state.history.filter(h => h.id !== p.id).map(h => \`
|
|
800
|
+
<option value="\${this.esc(h.id)}">\${this.esc(h.method)} \${this.esc(h.path)} (\${h.statusCode} · \${h.durationMs}ms)</option>
|
|
801
|
+
\`).join('')}
|
|
802
|
+
</select>
|
|
803
|
+
<button class="adb-btn" data-theme-toggle title="Toggle Light/Dark Theme">\${themeIcon}</button>
|
|
804
|
+
<button class="adb-btn" data-refresh title="Refresh requests">\${icons.refresh}<span>Refresh</span></button>
|
|
805
|
+
<button class="adb-btn" data-clear title="Clear history">\${icons.trash}<span>Clear</span></button>
|
|
806
|
+
<button class="adb-btn" data-close title="Close (Esc)">\${icons.close}</button>
|
|
807
|
+
</div>
|
|
808
|
+
</div>
|
|
809
|
+
<div class="adb-body">
|
|
810
|
+
\${p.redirectedFrom ? \`
|
|
811
|
+
<div class="adb-redirect-banner">
|
|
812
|
+
<div>
|
|
813
|
+
<span class="adb-badge adb-badge-cyan" style="margin-right:6px">\${p.redirectedFrom.statusCode}</span>
|
|
814
|
+
Redirected from <strong>\${this.esc(p.redirectedFrom.method)} \${this.esc(p.redirectedFrom.path)}</strong>
|
|
815
|
+
</div>
|
|
816
|
+
<button class="adb-btn" data-load-profile="\${this.esc(p.redirectedFrom.id)}">Inspect Previous Request</button>
|
|
817
|
+
</div>
|
|
818
|
+
\` : ''}
|
|
819
|
+
\${this.renderTabBody(p)}
|
|
820
|
+
</div>
|
|
821
|
+
</div>
|
|
822
|
+
\` : ''}
|
|
823
|
+
<div class="adb-pill-wrap \${this.state.collapsed ? 'collapsed' : ''}">
|
|
824
|
+
<button class="adb-logo-btn" data-toggle-open title="Toggle AdonisJS Debugbar (Ctrl/Cmd+Shift+D)">
|
|
825
|
+
\${adonisIcon}
|
|
826
|
+
\${this.state.collapsed ? '' : '<span>AdonisJS</span>'}
|
|
827
|
+
</button>
|
|
828
|
+
\${this.state.collapsed ? '' : \`
|
|
829
|
+
<button class="adb-pill-item" data-open-tab="overview">
|
|
830
|
+
<span class="adb-badge adb-badge-\${tone}">\${this.esc(p.method)} \${p.statusCode}</span>
|
|
831
|
+
<span>\${this.esc(p.path)}</span>
|
|
832
|
+
</button>
|
|
833
|
+
<div class="adb-sep"></div>
|
|
834
|
+
<button class="adb-pill-item" data-open-tab="timeline">\${icons.clock}<span>\${p.durationMs}ms</span></button>
|
|
835
|
+
<button class="adb-pill-item" data-open-tab="sql">
|
|
836
|
+
\${icons.db}<span>\${p.sql.queries.length} SQL</span>
|
|
837
|
+
\${p.sql.duplicateCount ? '<span class="adb-badge adb-badge-red">N+1</span>' : ''}
|
|
838
|
+
\${p.sql.slowCount ? '<span class="adb-badge adb-badge-amber">Slow</span>' : ''}
|
|
839
|
+
</button>
|
|
840
|
+
<button class="adb-pill-item" data-open-tab="auth">\${icons.user}<span>\${this.esc(authLabel)}</span></button>
|
|
841
|
+
<button class="adb-pill-item" data-open-tab="logs">\${icons.logs}<span>\${p.logs.length}</span></button>
|
|
842
|
+
\${(p.views && p.views.length) ? '<button class="adb-pill-item" data-open-tab="views">' + icons.edge + '<span>' + p.views.length + ' Edge</span></button>' : ''}
|
|
843
|
+
<button class="adb-pill-item" data-open-tab="overview">\${icons.mem}<span>\${this.formatBytes(p.memory.heapUsed)}</span></button>
|
|
844
|
+
\${valCount ? '<button class="adb-pill-item" data-open-tab="validation"><span class="adb-badge adb-badge-amber">Validation (' + valCount + ')</span></button>' : ''}
|
|
845
|
+
\${p.exception ? '<button class="adb-pill-item" data-open-tab="exception"><span class="adb-badge adb-badge-red">ERR</span></button>' : ''}
|
|
846
|
+
<div class="adb-sep"></div>
|
|
847
|
+
<button class="adb-pill-item" data-theme-toggle title="Toggle Light/Dark Theme">\${themeIcon}</button>
|
|
848
|
+
<button class="adb-pill-item" data-collapse title="Minimize">\${icons.chevron}</button>
|
|
849
|
+
\`}
|
|
850
|
+
</div>
|
|
851
|
+
\`;
|
|
852
|
+
|
|
853
|
+
this.bindEvents();
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
bindEvents() {
|
|
857
|
+
const root = this.shadowRoot;
|
|
858
|
+
root.querySelector('[data-toggle-open]')?.addEventListener('click', () => {
|
|
859
|
+
if (this.state.collapsed) {
|
|
860
|
+
this.state.collapsed = false;
|
|
861
|
+
} else {
|
|
862
|
+
this.state.open = !this.state.open;
|
|
863
|
+
}
|
|
864
|
+
this.render();
|
|
865
|
+
});
|
|
866
|
+
root.querySelector('[data-collapse]')?.addEventListener('click', () => {
|
|
867
|
+
this.state.open = false;
|
|
868
|
+
this.state.collapsed = true;
|
|
869
|
+
this.render();
|
|
870
|
+
});
|
|
871
|
+
root.querySelector('[data-close]')?.addEventListener('click', () => {
|
|
872
|
+
this.state.open = false;
|
|
873
|
+
this.render();
|
|
874
|
+
});
|
|
875
|
+
root.querySelectorAll('[data-open-tab]').forEach(el => {
|
|
876
|
+
el.addEventListener('click', () => {
|
|
877
|
+
this.state.activeTab = el.getAttribute('data-open-tab');
|
|
878
|
+
this.state.open = true;
|
|
879
|
+
this.render();
|
|
880
|
+
});
|
|
881
|
+
});
|
|
882
|
+
root.querySelectorAll('[data-tab]').forEach(el => {
|
|
883
|
+
el.addEventListener('click', () => {
|
|
884
|
+
this.state.activeTab = el.getAttribute('data-tab');
|
|
885
|
+
this.render();
|
|
886
|
+
});
|
|
887
|
+
});
|
|
888
|
+
root.querySelector('[data-history-select]')?.addEventListener('change', (e) => {
|
|
889
|
+
this.loadProfile(e.target.value);
|
|
890
|
+
});
|
|
891
|
+
root.querySelectorAll('[data-theme-toggle]').forEach(el => {
|
|
892
|
+
el.addEventListener('click', () => this.toggleTheme());
|
|
893
|
+
});
|
|
894
|
+
root.querySelector('[data-refresh]')?.addEventListener('click', () => this.refreshHistory(true));
|
|
895
|
+
root.querySelector('[data-clear]')?.addEventListener('click', () => this.clearHistory());
|
|
896
|
+
|
|
897
|
+
root.querySelectorAll('[data-sql-filter]').forEach(el => {
|
|
898
|
+
el.addEventListener('click', () => {
|
|
899
|
+
this.state.sqlFilter = el.getAttribute('data-sql-filter');
|
|
900
|
+
this.render();
|
|
901
|
+
});
|
|
902
|
+
});
|
|
903
|
+
root.querySelector('[data-sql-search]')?.addEventListener('input', (e) => {
|
|
904
|
+
this.state.sqlSearch = e.target.value;
|
|
905
|
+
const container = root.querySelector('[data-sql-results]');
|
|
906
|
+
if (container) {
|
|
907
|
+
container.innerHTML = this.renderSqlResults(this.state.profile);
|
|
908
|
+
this.bindSqlResultActions(container);
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
this.bindSqlResultActions(root);
|
|
912
|
+
root.querySelectorAll('[data-load-profile]').forEach(el => {
|
|
913
|
+
el.addEventListener('click', () => {
|
|
914
|
+
const id = el.getAttribute('data-load-profile');
|
|
915
|
+
if (id) this.loadProfile(id);
|
|
916
|
+
});
|
|
917
|
+
});
|
|
918
|
+
root.querySelector('[data-log-level]')?.addEventListener('change', (e) => {
|
|
919
|
+
this.state.logLevel = e.target.value;
|
|
920
|
+
this.render();
|
|
921
|
+
});
|
|
922
|
+
root.querySelector('[data-log-search]')?.addEventListener('input', (e) => {
|
|
923
|
+
this.state.logSearch = e.target.value;
|
|
924
|
+
const container = root.querySelector('[data-log-results]');
|
|
925
|
+
if (container) container.innerHTML = this.renderLogResults(this.state.profile);
|
|
926
|
+
});
|
|
927
|
+
root.querySelector('[data-route-search]')?.addEventListener('input', (e) => {
|
|
928
|
+
this.state.routeSearch = e.target.value;
|
|
929
|
+
const container = root.querySelector('[data-route-results]');
|
|
930
|
+
if (container) container.innerHTML = this.renderRouteResults(this.state.profile);
|
|
931
|
+
});
|
|
932
|
+
|
|
933
|
+
const resizer = root.querySelector('[data-resizer]');
|
|
934
|
+
if (resizer) {
|
|
935
|
+
resizer.addEventListener('mousedown', (startEvt) => {
|
|
936
|
+
startEvt.preventDefault();
|
|
937
|
+
const startY = startEvt.clientY;
|
|
938
|
+
const startH = this.state.drawerHeight;
|
|
939
|
+
const onMove = (moveEvt) => {
|
|
940
|
+
const delta = startY - moveEvt.clientY;
|
|
941
|
+
this.state.drawerHeight = Math.max(220, Math.min(window.innerHeight - 90, startH + delta));
|
|
942
|
+
const drawer = root.querySelector('.adb-drawer');
|
|
943
|
+
if (drawer) drawer.style.height = this.state.drawerHeight + 'px';
|
|
944
|
+
};
|
|
945
|
+
const onUp = () => {
|
|
946
|
+
window.removeEventListener('mousemove', onMove);
|
|
947
|
+
window.removeEventListener('mouseup', onUp);
|
|
948
|
+
};
|
|
949
|
+
window.addEventListener('mousemove', onMove);
|
|
950
|
+
window.addEventListener('mouseup', onUp);
|
|
951
|
+
});
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
bindSqlResultActions(scope) {
|
|
956
|
+
scope.querySelectorAll('[data-copy-sql]').forEach(el => {
|
|
957
|
+
el.addEventListener('click', () => {
|
|
958
|
+
navigator.clipboard?.writeText(el.getAttribute('data-copy-sql') || '');
|
|
959
|
+
const prev = el.textContent;
|
|
960
|
+
el.textContent = 'Copied!';
|
|
961
|
+
setTimeout(() => { el.textContent = prev; }, 900);
|
|
962
|
+
});
|
|
963
|
+
});
|
|
964
|
+
scope.querySelectorAll('[data-explain-id]').forEach(el => {
|
|
965
|
+
el.addEventListener('click', () => {
|
|
966
|
+
const qid = el.getAttribute('data-explain-id');
|
|
967
|
+
if (qid) this.explainQuery(this.state.profile.id, qid);
|
|
968
|
+
});
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
if (!customElements.get('adonis-debugbar')) {
|
|
974
|
+
customElements.define('adonis-debugbar', AdonisDebugbarElement);
|
|
975
|
+
}
|
|
976
|
+
})();
|
|
977
|
+
</script>
|
|
978
|
+
`;
|
|
979
|
+
}
|
|
980
|
+
/**
|
|
981
|
+
* Injects the debugbar HTML snippet before `</body>` (or appends it if no `</body>` tag exists).
|
|
982
|
+
*/
|
|
983
|
+
export function injectDebugbarIntoHtml(html, snippet) {
|
|
984
|
+
const idx = html.lastIndexOf('</body>');
|
|
985
|
+
if (idx !== -1) {
|
|
986
|
+
return `${html.slice(0, idx)}${snippet}\n${html.slice(idx)}`;
|
|
987
|
+
}
|
|
988
|
+
return `${html}\n${snippet}`;
|
|
989
|
+
}
|
|
990
|
+
//# sourceMappingURL=render_script.js.map
|