@tezx/devtools 1.0.0 → 1.0.2

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.
@@ -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 = node.pathname;
7
- if (node.isParam) {
8
- fullPath = `${basePath}/:${node.paramName}`;
15
+ let fullPath = basePath;
16
+ if (node.isParam && node.paramName) {
17
+ fullPath = `${basePath.replace(/\/+$/, "")}${node.paramName}`;
9
18
  }
10
- let pathname = fullPath?.replace(/\/+/g, '/');
11
- for (const [method, _handler] of node.handlers.entries()) {
19
+ const pathname = sanitizePathSplit("/", fullPath).join("/");
20
+ for (const [method, handler] of node.handlers.entries()) {
12
21
  routes.push({
13
22
  method,
14
- match: node.pathname == pathname,
15
- userPath: node.pathname,
16
- routePattern: pathname,
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 child of node.children.values()) {
21
- routes.push(...collectRoutes(child, fullPath));
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
- let tri = collectRoutes(app.triRouter);
36
+ const triRoutes = collectRoutes(app.triRouter);
37
+ const staticRoutes = [];
28
38
  for (const [path, handlers] of app.routers) {
29
- handlers.forEach((_, key) => {
30
- console.log();
31
- tri.push({
39
+ for (const [method, handler] of handlers) {
40
+ staticRoutes.push({
32
41
  match: true,
33
- userPath: `/${path}`,
34
- routePattern: `/${path}`,
35
- method: key,
36
- appliedMiddlewares: [..._?.middlewares]?.map(r => r?.name || "anonymous")
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 tri;
49
+ return [...triRoutes, ...staticRoutes];
41
50
  }
@@ -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', 'match', 'userPath', 'routePattern', 'appliedMiddlewares'];
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.match}</td>
89
- <td>${r.userPath}</td>
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.userPath}</code></li>`).join('')}
110
+ ${routes.map(r => `<li><code>${r.method} ${r.endpoint}</code></li>`).join('')}
113
111
  </ul>
114
112
  `).join('')}
115
113
  </div>
package/cjs/index.js CHANGED
@@ -275,14 +275,14 @@ function DevTools(app, options = { disableTabs: [], extraTabs: [] }) {
275
275
  ${find?.doc_title}
276
276
  </h1>
277
277
  ${find?.content}
278
- <section>
278
+ </section>
279
279
  <script>
280
280
 
281
281
  const themeCookieName = "tezx-theme";
282
282
 
283
283
  function setCookie(name, value, days = 30) {
284
284
  const expires = new Date(Date.now() + days * 864e5).toUTCString();
285
- document.cookie = ${"`${ name }=${ value }; expires = ${ expires }; path =/`"};
285
+ document.cookie = name +"="+ value +"; expires = "+ expires +"; path =/";
286
286
  }
287
287
  function getCookie(name) {
288
288
  return document.cookie.split('; ').reduce((acc, cookie) => {
@@ -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
- routePattern: string;
5
- userPath: string;
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
+ })[];
@@ -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 = node.pathname;
4
- if (node.isParam) {
5
- fullPath = `${basePath}/:${node.paramName}`;
11
+ let fullPath = basePath;
12
+ if (node.isParam && node.paramName) {
13
+ fullPath = `${basePath.replace(/\/+$/, "")}${node.paramName}`;
6
14
  }
7
- let pathname = fullPath?.replace(/\/+/g, '/');
8
- for (const [method, _handler] of node.handlers.entries()) {
15
+ const pathname = sanitizePathSplit("/", fullPath).join("/");
16
+ for (const [method, handler] of node.handlers.entries()) {
9
17
  routes.push({
10
18
  method,
11
- match: node.pathname == pathname,
12
- userPath: node.pathname,
13
- routePattern: pathname,
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 child of node.children.values()) {
18
- routes.push(...collectRoutes(child, fullPath));
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
- let tri = collectRoutes(app.triRouter);
32
+ const triRoutes = collectRoutes(app.triRouter);
33
+ const staticRoutes = [];
25
34
  for (const [path, handlers] of app.routers) {
26
- handlers.forEach((_, key) => {
27
- console.log();
28
- tri.push({
35
+ for (const [method, handler] of handlers) {
36
+ staticRoutes.push({
29
37
  match: true,
30
- userPath: `/${path}`,
31
- routePattern: `/${path}`,
32
- method: key,
33
- appliedMiddlewares: [..._?.middlewares]?.map(r => r?.name || "anonymous")
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 tri;
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', 'match', 'userPath', 'routePattern', 'appliedMiddlewares'];
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.match}</td>
86
- <td>${r.userPath}</td>
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.userPath}</code></li>`).join('')}
107
+ ${routes.map(r => `<li><code>${r.method} ${r.endpoint}</code></li>`).join('')}
110
108
  </ul>
111
109
  `).join('')}
112
110
  </div>
package/index.d.ts CHANGED
@@ -4,5 +4,5 @@ export type Options = {
4
4
  extraTabs?: TabType;
5
5
  disableTabs?: Tab[];
6
6
  };
7
- export declare function DevTools(app: TezX, options?: Options): Callback;
7
+ export declare function DevTools(app: TezX<any>, options?: Options): Callback;
8
8
  export default DevTools;
package/index.js CHANGED
@@ -272,14 +272,14 @@ export function DevTools(app, options = { disableTabs: [], extraTabs: [] }) {
272
272
  ${find?.doc_title}
273
273
  </h1>
274
274
  ${find?.content}
275
- <section>
275
+ </section>
276
276
  <script>
277
277
 
278
278
  const themeCookieName = "tezx-theme";
279
279
 
280
280
  function setCookie(name, value, days = 30) {
281
281
  const expires = new Date(Date.now() + days * 864e5).toUTCString();
282
- document.cookie = ${"`${ name }=${ value }; expires = ${ expires }; path =/`"};
282
+ document.cookie = name +"="+ value +"; expires = "+ expires +"; path =/";
283
283
  }
284
284
  function getCookie(name) {
285
285
  return document.cookie.split('; ').reduce((acc, cookie) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tezx/devtools",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
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",