@tezx/devtools 1.0.8 โ 1.0.9
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 +1 -1
- package/dist/index.d.ts +31 -0
- package/dist/index.js +838 -0
- package/dist/index.mjs +831 -0
- package/package.json +11 -14
- package/cjs/devtools/dumpRoutes.js +0 -41
- package/cjs/devtools/index.js +0 -7
- package/cjs/devtools/middlewares.js +0 -33
- package/cjs/html/cookies.js +0 -164
- package/cjs/html/env.js +0 -145
- package/cjs/html/index.js +0 -36
- package/cjs/html/middlewares.js +0 -184
- package/cjs/html/routes.js +0 -187
- package/cjs/index.js +0 -339
- package/devtools/dumpRoutes.d.ts +0 -13
- package/devtools/dumpRoutes.js +0 -38
- package/devtools/index.d.ts +0 -3
- package/devtools/index.js +0 -2
- package/devtools/middlewares.d.ts +0 -7
- package/devtools/middlewares.js +0 -30
- package/html/cookies.d.ts +0 -2
- package/html/cookies.js +0 -161
- package/html/env.d.ts +0 -2
- package/html/env.js +0 -142
- package/html/index.d.ts +0 -9
- package/html/index.js +0 -33
- package/html/middlewares.d.ts +0 -7
- package/html/middlewares.js +0 -181
- package/html/routes.d.ts +0 -2
- package/html/routes.js +0 -184
- package/index.d.ts +0 -9
- package/index.js +0 -333
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tezx/devtools",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "Developer tools for the TezX framework, including route inspector, cookie manager, and real-time diagnostics. Lightweight and plug-and-play compatible with Node.js, Bun, and Deno.",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.mjs",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"typings": "dist/index.d.ts",
|
|
9
10
|
"scripts": {},
|
|
10
11
|
"repository": {
|
|
11
12
|
"type": "git",
|
|
@@ -17,18 +18,14 @@
|
|
|
17
18
|
"homepage": "https://github.com/tezxjs/tezx-toolkit/tree/main/helpers/tezx-devtools#readme",
|
|
18
19
|
"exports": {
|
|
19
20
|
".": {
|
|
20
|
-
"import": "./index.
|
|
21
|
-
"require": "./cjs/index.js",
|
|
22
|
-
"types": "./index.d.ts"
|
|
23
|
-
"default": "./index.js"
|
|
21
|
+
"import": "./dist/index.mjs",
|
|
22
|
+
"require": "./dist/cjs/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts"
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
|
+
"sideEffects": false,
|
|
26
27
|
"files": [
|
|
27
|
-
"
|
|
28
|
-
"devtools/",
|
|
29
|
-
"html/",
|
|
30
|
-
"index.js",
|
|
31
|
-
"index.d.ts"
|
|
28
|
+
"dist/"
|
|
32
29
|
],
|
|
33
30
|
"keywords": [
|
|
34
31
|
"devtools",
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dumpRoutes = dumpRoutes;
|
|
4
|
-
const helper_1 = require("tezx/helper");
|
|
5
|
-
function collectRoutes(node, basePath = "/") {
|
|
6
|
-
const routes = [];
|
|
7
|
-
let fullPath = basePath;
|
|
8
|
-
if (node.isParam && node.paramName) {
|
|
9
|
-
fullPath = `${basePath.replace(/\/+$/, "")}${node.paramName}`;
|
|
10
|
-
}
|
|
11
|
-
const pathname = (0, helper_1.sanitizePathSplit)("/", fullPath).join("/");
|
|
12
|
-
for (const [method, handler] of node.handlers.entries()) {
|
|
13
|
-
routes.push({
|
|
14
|
-
method,
|
|
15
|
-
endpoint: node.pathname,
|
|
16
|
-
pattern: `/${pathname}`,
|
|
17
|
-
appliedMiddlewares: [...(handler?.middlewares || [])].map((r) => r?.name || "anonymous"),
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
for (const [childPath, childNode] of node.children.entries()) {
|
|
21
|
-
const newPath = (0, helper_1.sanitizePathSplit)(fullPath, childPath).join("/");
|
|
22
|
-
routes.push(...collectRoutes(childNode, newPath));
|
|
23
|
-
}
|
|
24
|
-
return routes;
|
|
25
|
-
}
|
|
26
|
-
function dumpRoutes(TezX) {
|
|
27
|
-
let app = TezX;
|
|
28
|
-
const triRoutes = collectRoutes(app.triRouter);
|
|
29
|
-
const staticRoutes = [];
|
|
30
|
-
for (const [path, handlers] of app.routers) {
|
|
31
|
-
for (const [method, handler] of handlers) {
|
|
32
|
-
staticRoutes.push({
|
|
33
|
-
endpoint: path?.replace(/^string:\/\//, "/").replace(/^regex:\/\//, ""),
|
|
34
|
-
pattern: path,
|
|
35
|
-
method,
|
|
36
|
-
appliedMiddlewares: [...(handler?.middlewares || [])].map((r) => r?.name || "anonymous"),
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return [...triRoutes, ...staticRoutes];
|
|
41
|
-
}
|
package/cjs/devtools/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dumpMiddlewares = exports.dumpRoutes = void 0;
|
|
4
|
-
var dumpRoutes_js_1 = require("./dumpRoutes.js");
|
|
5
|
-
Object.defineProperty(exports, "dumpRoutes", { enumerable: true, get: function () { return dumpRoutes_js_1.dumpRoutes; } });
|
|
6
|
-
var middlewares_js_1 = require("./middlewares.js");
|
|
7
|
-
Object.defineProperty(exports, "dumpMiddlewares", { enumerable: true, get: function () { return middlewares_js_1.dumpMiddlewares; } });
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dumpMiddlewares = dumpMiddlewares;
|
|
4
|
-
const helper_1 = require("tezx/helper");
|
|
5
|
-
function detectRouteType(pathname, isOptional) {
|
|
6
|
-
if (pathname.includes("*"))
|
|
7
|
-
return "wildcard";
|
|
8
|
-
if (pathname.includes(":"))
|
|
9
|
-
return "dynamic params";
|
|
10
|
-
if (isOptional)
|
|
11
|
-
return "optional params";
|
|
12
|
-
return "static";
|
|
13
|
-
}
|
|
14
|
-
function collectMiddlewares(node, basePath = "/") {
|
|
15
|
-
const routes = [];
|
|
16
|
-
const fullPath = (0, helper_1.sanitizePathSplit)("/", basePath).join("/");
|
|
17
|
-
const routeType = detectRouteType(fullPath, node.isOptional);
|
|
18
|
-
routes.push({
|
|
19
|
-
type: routeType,
|
|
20
|
-
pattern: `/${fullPath}`,
|
|
21
|
-
appliedMiddlewares: Array.isArray(node.middlewares)
|
|
22
|
-
? node.middlewares.map((mw) => mw?.name || "anonymous")
|
|
23
|
-
: Array.from(node.middlewares).map((mw) => mw?.name || "anonymous"),
|
|
24
|
-
});
|
|
25
|
-
for (const [childPath, childNode] of node.children.entries()) {
|
|
26
|
-
const newPath = (0, helper_1.sanitizePathSplit)(basePath, childPath).join("/");
|
|
27
|
-
routes.push(...collectMiddlewares(childNode, newPath));
|
|
28
|
-
}
|
|
29
|
-
return routes;
|
|
30
|
-
}
|
|
31
|
-
function dumpMiddlewares(TezX) {
|
|
32
|
-
return collectMiddlewares(TezX.triMiddlewares);
|
|
33
|
-
}
|
package/cjs/html/cookies.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CookiesInspector = CookiesInspector;
|
|
4
|
-
function CookiesInspector(ctx) {
|
|
5
|
-
const cookies = ctx.cookies.all();
|
|
6
|
-
const html = `
|
|
7
|
-
<style>
|
|
8
|
-
td[contenteditable="true"] {
|
|
9
|
-
outline: 0px;
|
|
10
|
-
}
|
|
11
|
-
td[contenteditable="true"]:focus {
|
|
12
|
-
outline: 1px solid var(--accent);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
.delete-btn,
|
|
16
|
-
.copy-btn {
|
|
17
|
-
background: #dc2626;
|
|
18
|
-
color: white;
|
|
19
|
-
border: none;
|
|
20
|
-
border-radius: 0.375rem;
|
|
21
|
-
padding: 0.3rem 0.6rem;
|
|
22
|
-
font-size: 0.8rem;
|
|
23
|
-
cursor: pointer;
|
|
24
|
-
margin-left: 4px;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
.copy-btn {
|
|
28
|
-
background: #2563eb;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
.delete-btn:hover {
|
|
32
|
-
background: #b91c1c;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
.copy-btn:hover {
|
|
36
|
-
background: #1e40af;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
pre#json-output {
|
|
40
|
-
margin-top: 1rem;
|
|
41
|
-
padding: 1rem;
|
|
42
|
-
border-radius: 0.5rem;
|
|
43
|
-
font-size: 0.875rem;
|
|
44
|
-
overflow-x: auto;
|
|
45
|
-
display: none;
|
|
46
|
-
background: #f3f4f6;
|
|
47
|
-
}
|
|
48
|
-
</style>
|
|
49
|
-
|
|
50
|
-
<div class="tabs">
|
|
51
|
-
<a onclick="addCookieRow()">โ Add Cookie</a>
|
|
52
|
-
<a onclick="saveCookies()">๐พ Save All</a>
|
|
53
|
-
<a onclick="exportCookies()">๐ค Export JSON</a>
|
|
54
|
-
</div>
|
|
55
|
-
|
|
56
|
-
<div class="table-container">
|
|
57
|
-
<table>
|
|
58
|
-
<thead>
|
|
59
|
-
<tr>
|
|
60
|
-
<th>#</th>
|
|
61
|
-
<th>Key</th>
|
|
62
|
-
<th>Value</th>
|
|
63
|
-
<th>Actions</th>
|
|
64
|
-
</tr>
|
|
65
|
-
</thead>
|
|
66
|
-
<tbody id="cookie-body"></tbody>
|
|
67
|
-
</table>
|
|
68
|
-
</div>
|
|
69
|
-
|
|
70
|
-
<pre class="json-view" id="json-output"></pre>
|
|
71
|
-
|
|
72
|
-
<script>
|
|
73
|
-
function getCookies() {
|
|
74
|
-
const cookies = {};
|
|
75
|
-
document.cookie.split(';').forEach(c => {
|
|
76
|
-
const [k, ...v] = c.trim().split('=');
|
|
77
|
-
cookies[k] = decodeURIComponent(v.join('='));
|
|
78
|
-
});
|
|
79
|
-
return cookies;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function renderCookies() {
|
|
83
|
-
const tbody = document.getElementById('cookie-body');
|
|
84
|
-
tbody.innerHTML = '';
|
|
85
|
-
const cookies = getCookies();
|
|
86
|
-
let index = 1;
|
|
87
|
-
for (const [key, val] of Object.entries(cookies)) {
|
|
88
|
-
const row = document.createElement('tr');
|
|
89
|
-
row.innerHTML = \`
|
|
90
|
-
<td>\${index++}</td>
|
|
91
|
-
<td contenteditable="true" class="cookie-key" style="white-space: nowrap">\${key}</td>
|
|
92
|
-
<td contenteditable="true" class="cookie-value">\${val}</td>
|
|
93
|
-
<td class="action">
|
|
94
|
-
<button class="copy-btn" onclick="copyRow(this)">๐</button>
|
|
95
|
-
<button class="delete-btn" onclick="deleteRow(this)">Delete</button>
|
|
96
|
-
</td>
|
|
97
|
-
\`;
|
|
98
|
-
tbody.appendChild(row);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function addCookieRow() {
|
|
103
|
-
const tbody = document.getElementById('cookie-body');
|
|
104
|
-
const row = document.createElement('tr');
|
|
105
|
-
row.innerHTML = \`
|
|
106
|
-
<td>\${tbody.children.length + 1}</td>
|
|
107
|
-
<td contenteditable="true" class="cookie-key" style="white-space: nowrap"></td>
|
|
108
|
-
<td contenteditable="true" class="cookie-value"></td>
|
|
109
|
-
<td class="action">
|
|
110
|
-
<button class="copy-btn" onclick="copyRow(this)">๐</button>
|
|
111
|
-
<button class="delete-btn" onclick="deleteRow(this)">Delete</button>
|
|
112
|
-
</td>
|
|
113
|
-
\`;
|
|
114
|
-
tbody.appendChild(row);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function deleteRow(button) {
|
|
118
|
-
const row = button.closest('tr');
|
|
119
|
-
const key = row.querySelector('.cookie-key')?.innerText.trim();
|
|
120
|
-
if (key) {
|
|
121
|
-
document.cookie = key + '=; Max-Age=0; path=/';
|
|
122
|
-
}
|
|
123
|
-
row.remove();
|
|
124
|
-
renderCookies();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function saveCookies() {
|
|
128
|
-
const rows = document.querySelectorAll('#cookie-body tr');
|
|
129
|
-
rows.forEach(row => {
|
|
130
|
-
const key = row.querySelector('.cookie-key')?.innerText.trim();
|
|
131
|
-
const value = row.querySelector('.cookie-value')?.innerText.trim();
|
|
132
|
-
if (key) {
|
|
133
|
-
document.cookie = key + '=' + encodeURIComponent(value) + '; path=/';
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
renderCookies();
|
|
137
|
-
alert('โ
Cookies saved!');
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function exportCookies() {
|
|
141
|
-
const cookies = getCookies();
|
|
142
|
-
const output = document.getElementById('json-output');
|
|
143
|
-
output.textContent = JSON.stringify(cookies, null, 2);
|
|
144
|
-
output.style.display = 'block';
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function copyRow(button) {
|
|
148
|
-
const row = button.closest('tr');
|
|
149
|
-
const key = row.querySelector('.cookie-key')?.innerText.trim();
|
|
150
|
-
const value = row.querySelector('.cookie-value')?.innerText.trim();
|
|
151
|
-
if (key) {
|
|
152
|
-
navigator.clipboard.writeText(\`\${key}: \${value}\`)
|
|
153
|
-
.then(() => {
|
|
154
|
-
button.innerText = 'โ
';
|
|
155
|
-
setTimeout(() => button.innerText = '๐', 1000);
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
renderCookies();
|
|
161
|
-
</script>
|
|
162
|
-
`;
|
|
163
|
-
return html;
|
|
164
|
-
}
|
package/cjs/html/env.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EnvInspector = EnvInspector;
|
|
4
|
-
function EnvInspector(ctx) {
|
|
5
|
-
const env = ctx.env;
|
|
6
|
-
const entries = Object.entries(env);
|
|
7
|
-
const tableRows = entries.length
|
|
8
|
-
? entries
|
|
9
|
-
.map(([key, value], i) => {
|
|
10
|
-
const safeKey = key.replace(/"/g, """);
|
|
11
|
-
const safeValue = value.replace(/`/g, "\\`").replace(/"/g, """);
|
|
12
|
-
return `
|
|
13
|
-
<tr data-key="${safeKey.toLowerCase()}" data-value="${value.toLowerCase()}">
|
|
14
|
-
<td>${i + 1}</td>
|
|
15
|
-
<td>${safeKey}</td>
|
|
16
|
-
<td>${value}</td>
|
|
17
|
-
<td><button onclick="copyRowEnv('${safeKey}', \`${safeValue}\`)">๐</button></td>
|
|
18
|
-
</tr>
|
|
19
|
-
`;
|
|
20
|
-
})
|
|
21
|
-
.join("")
|
|
22
|
-
: `
|
|
23
|
-
<tr>
|
|
24
|
-
<td colspan="4">
|
|
25
|
-
<p>โ ๏ธ <strong>No environment variables found.</strong></p>
|
|
26
|
-
<pre style="margin-top: 1rem; background: #f1f5f9; padding: 1rem; border-radius: 0.5rem;">
|
|
27
|
-
const env = loadEnv();
|
|
28
|
-
|
|
29
|
-
export const app = new TezX({
|
|
30
|
-
env: env,
|
|
31
|
-
debugMode: true,
|
|
32
|
-
// basePath: 'v1',
|
|
33
|
-
allowDuplicateMw: true,
|
|
34
|
-
});
|
|
35
|
-
</pre>
|
|
36
|
-
</td>
|
|
37
|
-
</tr>`;
|
|
38
|
-
return `
|
|
39
|
-
<style>
|
|
40
|
-
table td button {
|
|
41
|
-
background: #e2e8f0;
|
|
42
|
-
border: none;
|
|
43
|
-
padding: 0.3rem 0.6rem;
|
|
44
|
-
border-radius: 0.375rem;
|
|
45
|
-
cursor: pointer;
|
|
46
|
-
}
|
|
47
|
-
table td button:hover {
|
|
48
|
-
background: #cbd5e1;
|
|
49
|
-
}
|
|
50
|
-
pre#json-output {
|
|
51
|
-
margin-top: 1rem;
|
|
52
|
-
padding: 1rem;
|
|
53
|
-
border-radius: 0.5rem;
|
|
54
|
-
background: #f9fafb;
|
|
55
|
-
border: 1px solid #e5e7eb;
|
|
56
|
-
font-size: 0.875rem;
|
|
57
|
-
overflow-x: auto;
|
|
58
|
-
display: none;
|
|
59
|
-
}
|
|
60
|
-
.search-container {
|
|
61
|
-
margin-bottom: 1rem;
|
|
62
|
-
}
|
|
63
|
-
.search-container input {
|
|
64
|
-
padding: 0.5rem;
|
|
65
|
-
width: 100%;
|
|
66
|
-
max-width: 400px;
|
|
67
|
-
border: 1px solid #e5e7eb;
|
|
68
|
-
border-radius: 0.375rem;
|
|
69
|
-
}
|
|
70
|
-
</style>
|
|
71
|
-
|
|
72
|
-
<div class="tabs">
|
|
73
|
-
<a onclick="exportEnv()">๐ค Export JSON</a>
|
|
74
|
-
<a onclick="copyAllEnv()">๐ Copy All</a>
|
|
75
|
-
</div>
|
|
76
|
-
|
|
77
|
-
<div class="search-container">
|
|
78
|
-
<input type="text" id="env-search" placeholder="๐ Search environment variables..." oninput="filterEnvTable()" />
|
|
79
|
-
</div>
|
|
80
|
-
|
|
81
|
-
<div class="table-container">
|
|
82
|
-
<table>
|
|
83
|
-
<thead>
|
|
84
|
-
<tr>
|
|
85
|
-
<th>#</th>
|
|
86
|
-
<th>Key</th>
|
|
87
|
-
<th>Value</th>
|
|
88
|
-
<th>Copy</th>
|
|
89
|
-
</tr>
|
|
90
|
-
</thead>
|
|
91
|
-
<tbody id="env-body">
|
|
92
|
-
${tableRows}
|
|
93
|
-
</tbody>
|
|
94
|
-
</table>
|
|
95
|
-
</div>
|
|
96
|
-
|
|
97
|
-
<pre id="json-output">${JSON.stringify(env, null, 2)}</pre>
|
|
98
|
-
|
|
99
|
-
<script>
|
|
100
|
-
function exportEnv() {
|
|
101
|
-
const output = document.getElementById('json-output');
|
|
102
|
-
const blob = new Blob([output.textContent], { type: 'application/json' });
|
|
103
|
-
const url = URL.createObjectURL(blob);
|
|
104
|
-
const a = document.createElement('a');
|
|
105
|
-
a.href = url;
|
|
106
|
-
a.download = 'env.json';
|
|
107
|
-
a.click();
|
|
108
|
-
URL.revokeObjectURL(url);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function copyAllEnv() {
|
|
112
|
-
const output = document.getElementById('json-output');
|
|
113
|
-
navigator.clipboard.writeText(output.textContent).then(() => {
|
|
114
|
-
alert('โ
All environment variables copied!');
|
|
115
|
-
}).catch(err => {
|
|
116
|
-
alert('โ Failed to copy: ' + err);
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function copyRowEnv(key, value) {
|
|
121
|
-
const text = \`\${key}=\${value}\`;
|
|
122
|
-
navigator.clipboard.writeText(text).then(() => {
|
|
123
|
-
alert(\`โ
Copied: \${text}\`);
|
|
124
|
-
}).catch(err => {
|
|
125
|
-
alert('โ Failed to copy: ' + err);
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function filterEnvTable() {
|
|
130
|
-
const input = document.getElementById('env-search').value.toLowerCase();
|
|
131
|
-
const rows = document.querySelectorAll('#env-body tr');
|
|
132
|
-
|
|
133
|
-
rows.forEach(row => {
|
|
134
|
-
const key = row.getAttribute('data-key') || '';
|
|
135
|
-
const value = row.getAttribute('data-value') || '';
|
|
136
|
-
if (key.includes(input) || value.includes(input)) {
|
|
137
|
-
row.style.display = '';
|
|
138
|
-
} else {
|
|
139
|
-
row.style.display = 'none';
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
</script>
|
|
144
|
-
`;
|
|
145
|
-
}
|
package/cjs/html/index.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.html = html;
|
|
4
|
-
const cookies_js_1 = require("./cookies.js");
|
|
5
|
-
const env_js_1 = require("./env.js");
|
|
6
|
-
const middlewares_js_1 = require("./middlewares.js");
|
|
7
|
-
const routes_js_1 = require("./routes.js");
|
|
8
|
-
function html(ctx, app) {
|
|
9
|
-
let tabDb = [
|
|
10
|
-
{
|
|
11
|
-
doc_title: "DevTools - Route Inspector",
|
|
12
|
-
label: "Routes",
|
|
13
|
-
tab: "routes",
|
|
14
|
-
content: (0, routes_js_1.Routes)(ctx, app),
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
doc_title: "DevTools - Middleware Inspector",
|
|
18
|
-
label: "Middlewares",
|
|
19
|
-
tab: "middleware",
|
|
20
|
-
content: (0, middlewares_js_1.Middlewares)(ctx, app),
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
tab: "cookies",
|
|
24
|
-
label: "Cookies",
|
|
25
|
-
doc_title: "DevTools - Cookie Inspector",
|
|
26
|
-
content: (0, cookies_js_1.CookiesInspector)(ctx),
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
tab: ".env",
|
|
30
|
-
label: "Environment",
|
|
31
|
-
doc_title: "DevTools - Environment",
|
|
32
|
-
content: (0, env_js_1.EnvInspector)(ctx),
|
|
33
|
-
},
|
|
34
|
-
];
|
|
35
|
-
return tabDb;
|
|
36
|
-
}
|
package/cjs/html/middlewares.js
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Middlewares = Middlewares;
|
|
4
|
-
const index_js_1 = require("../devtools/index.js");
|
|
5
|
-
function Middlewares(ctx, app) {
|
|
6
|
-
const allRoutes = (0, index_js_1.dumpMiddlewares)(app);
|
|
7
|
-
const totalRoutes = allRoutes.length;
|
|
8
|
-
const middlewareRoutes = {};
|
|
9
|
-
for (const route of allRoutes) {
|
|
10
|
-
for (const mw of route.appliedMiddlewares || []) {
|
|
11
|
-
(middlewareRoutes[mw] ||= []).push(route);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
const rawJSON = JSON.stringify(allRoutes, null, 2);
|
|
15
|
-
const toCSV = (data) => {
|
|
16
|
-
const headers = ["pattern", "type", "appliedMiddlewares"];
|
|
17
|
-
const csvRows = [
|
|
18
|
-
headers.join(","),
|
|
19
|
-
...data.map((r) => headers.map((h) => JSON.stringify(r[h] ?? "")).join(",")),
|
|
20
|
-
];
|
|
21
|
-
return csvRows.join("\n");
|
|
22
|
-
};
|
|
23
|
-
const csvString = toCSV(allRoutes).replace(/"/g, """);
|
|
24
|
-
return `
|
|
25
|
-
<style>
|
|
26
|
-
.download {
|
|
27
|
-
margin-top: 1rem;
|
|
28
|
-
display: flex;
|
|
29
|
-
gap: 1rem;
|
|
30
|
-
}
|
|
31
|
-
.download a {
|
|
32
|
-
padding: 0.5rem 1rem;
|
|
33
|
-
border: 1px solid var(--accent);
|
|
34
|
-
color: var(--accent);
|
|
35
|
-
text-decoration: none;
|
|
36
|
-
border-radius: 6px;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
.download a:hover {
|
|
40
|
-
background: var(--accent);
|
|
41
|
-
color: white;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
#searchBar {
|
|
45
|
-
margin: 1rem 0;
|
|
46
|
-
display: flex;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
#searchBar input {
|
|
50
|
-
flex: 1;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
table td button {
|
|
54
|
-
background: #e2e8f0;
|
|
55
|
-
border: none;
|
|
56
|
-
padding: 0.2rem 0.5rem;
|
|
57
|
-
border-radius: 0.375rem;
|
|
58
|
-
cursor: pointer;
|
|
59
|
-
margin-left: 0.5rem;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
table td button:hover {
|
|
63
|
-
background: #cbd5e1;
|
|
64
|
-
}
|
|
65
|
-
</style>
|
|
66
|
-
|
|
67
|
-
<div class="tabs toolbar">
|
|
68
|
-
<a class="tab-btn active counting" data-count="${totalRoutes}" onclick="showTab('routes')">๐ Routes</a>
|
|
69
|
-
<a class="tab-btn counting" data-count="${Object.keys(middlewareRoutes).length}" onclick="showTab('middlewares')">๐งฉ Middlewares</a>
|
|
70
|
-
<a class="tab-btn" onclick="showTab('json')">๐งพ Raw JSON</a>
|
|
71
|
-
<a class="tab-btn" onclick="showTab('export')">๐ค Export</a>
|
|
72
|
-
</div>
|
|
73
|
-
|
|
74
|
-
<div id="searchBar">
|
|
75
|
-
<input type="text" id="search" placeholder="Filter by pattern/type/middleware..." />
|
|
76
|
-
</div>
|
|
77
|
-
|
|
78
|
-
<!-- ROUTES -->
|
|
79
|
-
<div id="routesTab" class="table-container">
|
|
80
|
-
<table id="routesTable">
|
|
81
|
-
<thead>
|
|
82
|
-
<tr>
|
|
83
|
-
<th>#</th>
|
|
84
|
-
<th>Pattern</th>
|
|
85
|
-
<th>Type</th>
|
|
86
|
-
<th>Middlewares</th>
|
|
87
|
-
</tr>
|
|
88
|
-
</thead>
|
|
89
|
-
<tbody>
|
|
90
|
-
${allRoutes
|
|
91
|
-
.map((r, i) => `
|
|
92
|
-
<tr>
|
|
93
|
-
<td>${i + 1}</td>
|
|
94
|
-
<td>
|
|
95
|
-
${r.pattern}
|
|
96
|
-
<button onclick="copyText(\`${r.pattern}\`)">๐</button>
|
|
97
|
-
</td>
|
|
98
|
-
<td>
|
|
99
|
-
<span style="
|
|
100
|
-
display: inline-block;
|
|
101
|
-
padding: 0.2rem 0.5rem;
|
|
102
|
-
border-radius: 0.375rem;
|
|
103
|
-
color: white;
|
|
104
|
-
font-size: 0.75rem;
|
|
105
|
-
background-color: ${r.type === "static"
|
|
106
|
-
? "#16a34a"
|
|
107
|
-
: r.type === "wildcard"
|
|
108
|
-
? "#f97316"
|
|
109
|
-
: r.type === "optional params"
|
|
110
|
-
? "#3b82f6"
|
|
111
|
-
: r.type === "dynamic params"
|
|
112
|
-
? "#9333ea"
|
|
113
|
-
: "#6b7280"};
|
|
114
|
-
">
|
|
115
|
-
${r.type}
|
|
116
|
-
</span>
|
|
117
|
-
</td>
|
|
118
|
-
<td>${(r.appliedMiddlewares || []).join(", ")}</td>
|
|
119
|
-
</tr>
|
|
120
|
-
`)
|
|
121
|
-
.join("")}
|
|
122
|
-
</tbody>
|
|
123
|
-
</table>
|
|
124
|
-
</div>
|
|
125
|
-
|
|
126
|
-
<!-- MIDDLEWARES -->
|
|
127
|
-
<div id="middlewaresTab" style="display:none">
|
|
128
|
-
${Object.entries(middlewareRoutes)
|
|
129
|
-
.map(([mw, routes]) => `
|
|
130
|
-
<h3>๐น ${mw} (${routes.length})</h3>
|
|
131
|
-
<ul>
|
|
132
|
-
${routes.map((r) => `<li><code>${r.pattern}</code> <span>(${r.type})</span></li>`).join("")}
|
|
133
|
-
</ul>
|
|
134
|
-
`)
|
|
135
|
-
.join("")}
|
|
136
|
-
</div>
|
|
137
|
-
|
|
138
|
-
<!-- RAW JSON -->
|
|
139
|
-
<div id="jsonTab" style="display:none">
|
|
140
|
-
<div class="json-view"><pre>${rawJSON}</pre></div>
|
|
141
|
-
</div>
|
|
142
|
-
|
|
143
|
-
<!-- EXPORT -->
|
|
144
|
-
<div id="exportTab" style="display:none">
|
|
145
|
-
<div class="download">
|
|
146
|
-
<a href="data:text/json;charset=utf-8,${encodeURIComponent(rawJSON)}" download="middlewares.json">๐ฅ JSON</a>
|
|
147
|
-
<a href="data:text/csv;charset=utf-8,${csvString}" download="middlewares.csv">๐ฅ CSV</a>
|
|
148
|
-
</div>
|
|
149
|
-
</div>
|
|
150
|
-
|
|
151
|
-
<script>
|
|
152
|
-
const tabs = ['routes', 'middlewares', 'json', 'export'];
|
|
153
|
-
const tabBtns = document.querySelectorAll('.tab-btn');
|
|
154
|
-
|
|
155
|
-
function showTab(tab) {
|
|
156
|
-
tabs.forEach(t => {
|
|
157
|
-
document.getElementById(t + 'Tab').style.display = t === tab ? 'block' : 'none';
|
|
158
|
-
document.getElementById(t + 'Tab').classList.toggle('active', t === tab);
|
|
159
|
-
});
|
|
160
|
-
tabBtns.forEach(btn => {
|
|
161
|
-
const active = btn.textContent.toLowerCase().includes(tab);
|
|
162
|
-
btn.classList.toggle('active', active);
|
|
163
|
-
});
|
|
164
|
-
document.getElementById('searchBar').style.display = (tab === 'routes') ? 'flex' : 'none';
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
document.getElementById('search').addEventListener('input', (e) => {
|
|
168
|
-
const keyword = e.target.value.toLowerCase();
|
|
169
|
-
const rows = document.querySelectorAll('#routesTable tbody tr');
|
|
170
|
-
rows.forEach(row => {
|
|
171
|
-
row.style.display = row.textContent.toLowerCase().includes(keyword) ? '' : 'none';
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
function copyText(text) {
|
|
176
|
-
navigator.clipboard.writeText(text).then(() => {
|
|
177
|
-
alert('โ
Copied: ' + text);
|
|
178
|
-
}).catch(err => {
|
|
179
|
-
alert('โ Failed to copy: ' + err);
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
</script>
|
|
183
|
-
`;
|
|
184
|
-
}
|