@tezx/devtools 1.0.1 → 1.0.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/cjs/devtools/dumpRoutes.js +30 -21
- package/cjs/html/routes.js +4 -6
- package/devtools/dumpRoutes.d.ts +11 -5
- package/devtools/dumpRoutes.js +29 -21
- package/html/routes.js +4 -6
- package/package.json +1 -1
|
@@ -1,41 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sanitizePathSplit = sanitizePathSplit;
|
|
3
4
|
exports.dumpRoutes = dumpRoutes;
|
|
5
|
+
function sanitizePathSplit(basePath, path) {
|
|
6
|
+
const parts = `${basePath}/${path}`
|
|
7
|
+
.replace(/\\/g, '')
|
|
8
|
+
.replace(/\/+/g, '/')
|
|
9
|
+
?.split("/")
|
|
10
|
+
.filter(Boolean);
|
|
11
|
+
return parts;
|
|
12
|
+
}
|
|
4
13
|
function collectRoutes(node, basePath = '/') {
|
|
5
14
|
const routes = [];
|
|
6
|
-
let fullPath =
|
|
7
|
-
if (node.isParam) {
|
|
8
|
-
fullPath = `${basePath}
|
|
15
|
+
let fullPath = basePath;
|
|
16
|
+
if (node.isParam && node.paramName) {
|
|
17
|
+
fullPath = `${basePath.replace(/\/+$/, "")}${node.paramName}`;
|
|
9
18
|
}
|
|
10
|
-
|
|
11
|
-
for (const [method,
|
|
19
|
+
const pathname = sanitizePathSplit("/", fullPath).join("/");
|
|
20
|
+
for (const [method, handler] of node.handlers.entries()) {
|
|
12
21
|
routes.push({
|
|
13
22
|
method,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
appliedMiddlewares: [..._handler.middlewares].map(r => r?.name || "anonymous")
|
|
23
|
+
endpoint: node.pathname,
|
|
24
|
+
pattern: `/${pathname}`,
|
|
25
|
+
appliedMiddlewares: [...(handler?.middlewares || [])].map((r) => r?.name || "anonymous"),
|
|
18
26
|
});
|
|
19
27
|
}
|
|
20
|
-
for (const
|
|
21
|
-
|
|
28
|
+
for (const [childPath, childNode] of node.children.entries()) {
|
|
29
|
+
const newPath = sanitizePathSplit(fullPath, childPath).join("/");
|
|
30
|
+
routes.push(...collectRoutes(childNode, newPath));
|
|
22
31
|
}
|
|
23
32
|
return routes;
|
|
24
33
|
}
|
|
25
34
|
function dumpRoutes(TezX) {
|
|
26
35
|
let app = TezX;
|
|
27
|
-
|
|
36
|
+
const triRoutes = collectRoutes(app.triRouter);
|
|
37
|
+
const staticRoutes = [];
|
|
28
38
|
for (const [path, handlers] of app.routers) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
tri.push({
|
|
39
|
+
for (const [method, handler] of handlers) {
|
|
40
|
+
staticRoutes.push({
|
|
32
41
|
match: true,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
method
|
|
36
|
-
appliedMiddlewares: [...
|
|
42
|
+
endpoint: `/${path}`,
|
|
43
|
+
pattern: `/${path}`,
|
|
44
|
+
method,
|
|
45
|
+
appliedMiddlewares: [...(handler?.middlewares || [])].map((r) => r?.name || "anonymous"),
|
|
37
46
|
});
|
|
38
|
-
}
|
|
47
|
+
}
|
|
39
48
|
}
|
|
40
|
-
return
|
|
49
|
+
return [...triRoutes, ...staticRoutes];
|
|
41
50
|
}
|
package/cjs/html/routes.js
CHANGED
|
@@ -15,7 +15,7 @@ function Routes(ctx, app) {
|
|
|
15
15
|
}
|
|
16
16
|
const rawJSON = JSON.stringify(allRoutes, null, 2);
|
|
17
17
|
const toCSV = (data) => {
|
|
18
|
-
const headers = ['method', '
|
|
18
|
+
const headers = ['method', 'endpoint', 'pattern', 'appliedMiddlewares'];
|
|
19
19
|
const csvRows = [
|
|
20
20
|
headers.join(','),
|
|
21
21
|
...data.map(r => headers.map(h => JSON.stringify(r[h] ?? '')).join(','))
|
|
@@ -74,7 +74,6 @@ function Routes(ctx, app) {
|
|
|
74
74
|
<tr>
|
|
75
75
|
<th>#</th>
|
|
76
76
|
<th>Method</th>
|
|
77
|
-
<th>Match</th>
|
|
78
77
|
<th>User Path</th>
|
|
79
78
|
<th>Route Pattern</th>
|
|
80
79
|
<th>Middlewares</th>
|
|
@@ -85,9 +84,8 @@ function Routes(ctx, app) {
|
|
|
85
84
|
<tr>
|
|
86
85
|
<td>${i + 1}</td>
|
|
87
86
|
<td>${r.method}</td>
|
|
88
|
-
<td>${r.
|
|
89
|
-
<td>${r.
|
|
90
|
-
<td>${r.routePattern}</td>
|
|
87
|
+
<td>${r.endpoint}</td>
|
|
88
|
+
<td>${r.pattern}</td>
|
|
91
89
|
<td>${(r.appliedMiddlewares || []).join(', ')}</td>
|
|
92
90
|
</tr>`).join('')}
|
|
93
91
|
</tbody>
|
|
@@ -109,7 +107,7 @@ function Routes(ctx, app) {
|
|
|
109
107
|
${Object.entries(middlewareRoutes).map(([mw, routes]) => `
|
|
110
108
|
<h3>🔹 ${mw} (${routes.length})</h3>
|
|
111
109
|
<ul>
|
|
112
|
-
${routes.map(r => `<li><code>${r.method} ${r.
|
|
110
|
+
${routes.map(r => `<li><code>${r.method} ${r.endpoint}</code></li>`).join('')}
|
|
113
111
|
</ul>
|
|
114
112
|
`).join('')}
|
|
115
113
|
</div>
|
package/devtools/dumpRoutes.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import { TezX } from "tezx";
|
|
1
|
+
import type { TezX } from "tezx";
|
|
2
|
+
export declare function sanitizePathSplit(basePath: string, path: string): string[];
|
|
2
3
|
export type RouteEntry = {
|
|
3
4
|
method: string;
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
pattern: string;
|
|
6
|
+
endpoint: string;
|
|
6
7
|
appliedMiddlewares: string[];
|
|
7
|
-
match: boolean;
|
|
8
8
|
};
|
|
9
|
-
export declare function dumpRoutes(TezX: TezX): RouteEntry
|
|
9
|
+
export declare function dumpRoutes(TezX: TezX<any>): (RouteEntry | {
|
|
10
|
+
match: boolean;
|
|
11
|
+
endpoint: string;
|
|
12
|
+
pattern: string;
|
|
13
|
+
method: any;
|
|
14
|
+
appliedMiddlewares: any[];
|
|
15
|
+
})[];
|
package/devtools/dumpRoutes.js
CHANGED
|
@@ -1,38 +1,46 @@
|
|
|
1
|
+
export function sanitizePathSplit(basePath, path) {
|
|
2
|
+
const parts = `${basePath}/${path}`
|
|
3
|
+
.replace(/\\/g, '')
|
|
4
|
+
.replace(/\/+/g, '/')
|
|
5
|
+
?.split("/")
|
|
6
|
+
.filter(Boolean);
|
|
7
|
+
return parts;
|
|
8
|
+
}
|
|
1
9
|
function collectRoutes(node, basePath = '/') {
|
|
2
10
|
const routes = [];
|
|
3
|
-
let fullPath =
|
|
4
|
-
if (node.isParam) {
|
|
5
|
-
fullPath = `${basePath}
|
|
11
|
+
let fullPath = basePath;
|
|
12
|
+
if (node.isParam && node.paramName) {
|
|
13
|
+
fullPath = `${basePath.replace(/\/+$/, "")}${node.paramName}`;
|
|
6
14
|
}
|
|
7
|
-
|
|
8
|
-
for (const [method,
|
|
15
|
+
const pathname = sanitizePathSplit("/", fullPath).join("/");
|
|
16
|
+
for (const [method, handler] of node.handlers.entries()) {
|
|
9
17
|
routes.push({
|
|
10
18
|
method,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
appliedMiddlewares: [..._handler.middlewares].map(r => r?.name || "anonymous")
|
|
19
|
+
endpoint: node.pathname,
|
|
20
|
+
pattern: `/${pathname}`,
|
|
21
|
+
appliedMiddlewares: [...(handler?.middlewares || [])].map((r) => r?.name || "anonymous"),
|
|
15
22
|
});
|
|
16
23
|
}
|
|
17
|
-
for (const
|
|
18
|
-
|
|
24
|
+
for (const [childPath, childNode] of node.children.entries()) {
|
|
25
|
+
const newPath = sanitizePathSplit(fullPath, childPath).join("/");
|
|
26
|
+
routes.push(...collectRoutes(childNode, newPath));
|
|
19
27
|
}
|
|
20
28
|
return routes;
|
|
21
29
|
}
|
|
22
30
|
export function dumpRoutes(TezX) {
|
|
23
31
|
let app = TezX;
|
|
24
|
-
|
|
32
|
+
const triRoutes = collectRoutes(app.triRouter);
|
|
33
|
+
const staticRoutes = [];
|
|
25
34
|
for (const [path, handlers] of app.routers) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
tri.push({
|
|
35
|
+
for (const [method, handler] of handlers) {
|
|
36
|
+
staticRoutes.push({
|
|
29
37
|
match: true,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
method
|
|
33
|
-
appliedMiddlewares: [...
|
|
38
|
+
endpoint: `/${path}`,
|
|
39
|
+
pattern: `/${path}`,
|
|
40
|
+
method,
|
|
41
|
+
appliedMiddlewares: [...(handler?.middlewares || [])].map((r) => r?.name || "anonymous"),
|
|
34
42
|
});
|
|
35
|
-
}
|
|
43
|
+
}
|
|
36
44
|
}
|
|
37
|
-
return
|
|
45
|
+
return [...triRoutes, ...staticRoutes];
|
|
38
46
|
}
|
package/html/routes.js
CHANGED
|
@@ -12,7 +12,7 @@ export function Routes(ctx, app) {
|
|
|
12
12
|
}
|
|
13
13
|
const rawJSON = JSON.stringify(allRoutes, null, 2);
|
|
14
14
|
const toCSV = (data) => {
|
|
15
|
-
const headers = ['method', '
|
|
15
|
+
const headers = ['method', 'endpoint', 'pattern', 'appliedMiddlewares'];
|
|
16
16
|
const csvRows = [
|
|
17
17
|
headers.join(','),
|
|
18
18
|
...data.map(r => headers.map(h => JSON.stringify(r[h] ?? '')).join(','))
|
|
@@ -71,7 +71,6 @@ export function Routes(ctx, app) {
|
|
|
71
71
|
<tr>
|
|
72
72
|
<th>#</th>
|
|
73
73
|
<th>Method</th>
|
|
74
|
-
<th>Match</th>
|
|
75
74
|
<th>User Path</th>
|
|
76
75
|
<th>Route Pattern</th>
|
|
77
76
|
<th>Middlewares</th>
|
|
@@ -82,9 +81,8 @@ export function Routes(ctx, app) {
|
|
|
82
81
|
<tr>
|
|
83
82
|
<td>${i + 1}</td>
|
|
84
83
|
<td>${r.method}</td>
|
|
85
|
-
<td>${r.
|
|
86
|
-
<td>${r.
|
|
87
|
-
<td>${r.routePattern}</td>
|
|
84
|
+
<td>${r.endpoint}</td>
|
|
85
|
+
<td>${r.pattern}</td>
|
|
88
86
|
<td>${(r.appliedMiddlewares || []).join(', ')}</td>
|
|
89
87
|
</tr>`).join('')}
|
|
90
88
|
</tbody>
|
|
@@ -106,7 +104,7 @@ export function Routes(ctx, app) {
|
|
|
106
104
|
${Object.entries(middlewareRoutes).map(([mw, routes]) => `
|
|
107
105
|
<h3>🔹 ${mw} (${routes.length})</h3>
|
|
108
106
|
<ul>
|
|
109
|
-
${routes.map(r => `<li><code>${r.method} ${r.
|
|
107
|
+
${routes.map(r => `<li><code>${r.method} ${r.endpoint}</code></li>`).join('')}
|
|
110
108
|
</ul>
|
|
111
109
|
`).join('')}
|
|
112
110
|
</div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tezx/devtools",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
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
5
|
"main": "cjs/index.js",
|
|
6
6
|
"module": "index.js",
|