vafast 0.4.1 → 0.4.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.
package/dist/index.js CHANGED
@@ -1,22 +1,25 @@
1
1
  // src/router.ts
2
2
  function flattenNestedRoutes(routes) {
3
3
  const flattened = [];
4
- function processRoute(route2, parentPath = "", parentMiddleware = []) {
4
+ function processRoute(route2, parentPath = "", parentMiddleware = [], parentName) {
5
5
  const currentPath = normalizePath(parentPath + route2.path);
6
6
  const currentMiddleware = [
7
7
  ...parentMiddleware,
8
8
  ...route2.middleware || []
9
9
  ];
10
+ const currentName = route2.name || parentName;
10
11
  if ("method" in route2 && "handler" in route2) {
11
12
  const leafRoute = route2;
12
13
  flattened.push({
13
14
  ...leafRoute,
14
15
  fullPath: currentPath,
15
- middlewareChain: currentMiddleware
16
+ middlewareChain: currentMiddleware,
17
+ parentName
18
+ // 保存父级名称
16
19
  });
17
20
  } else if ("children" in route2 && route2.children) {
18
21
  for (const child of route2.children) {
19
- processRoute(child, currentPath, currentMiddleware);
22
+ processRoute(child, currentPath, currentMiddleware, currentName);
20
23
  }
21
24
  }
22
25
  }