@bejibun/core 0.1.72 → 0.1.73

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 CHANGED
@@ -3,6 +3,20 @@ All notable changes to this project will be documented in this file.
3
3
 
4
4
  ---
5
5
 
6
+ ## [v0.1.73](https://github.com/Bejibun-Framework/bejibun-core/compare/v0.1.72...v0.1.73) - 2026-02-02
7
+
8
+ ### 🩹 Fixes
9
+ - Fix infinite nested router - [#14](https://github.com/Bejibun-Framework/bejibun-core/pull/14)
10
+
11
+ ### 📖 Changes
12
+
13
+ ### ❤️Contributors
14
+ - Havea Crenata ([@crenata](https://github.com/crenata))
15
+
16
+ **Full Changelog**: https://github.com/Bejibun-Framework/bejibun-core/blob/master/CHANGELOG.md
17
+
18
+ ---
19
+
6
20
  ## [v0.1.72](https://github.com/Bejibun-Framework/bejibun-core/compare/v0.1.71...v0.1.72) - 2026-01-29
7
21
 
8
22
  ### 🩹 Fixes
@@ -1,6 +1,6 @@
1
1
  import type { TFacilitator, TPaywall, TX402Config } from "@bejibun/x402";
2
2
  import type { IMiddleware } from "../types/middleware";
3
- import type { HandlerType, ResourceAction, Route, RouterGroup } from "../types/router";
3
+ import type { HandlerType, RawsRoute, ResourceAction, Route, RouterGroup } from "../types/router";
4
4
  import HttpMethodEnum from "@bejibun/utils/enums/HttpMethodEnum";
5
5
  import BaseController from "../bases/BaseController";
6
6
  export interface ResourceOptions {
@@ -29,12 +29,13 @@ export default class RouterBuilder {
29
29
  trace(path: string, handler: string | HandlerType): Route;
30
30
  match(methods: Array<HttpMethodEnum>, path: string, handler: string | HandlerType): RouterGroup;
31
31
  any(path: string, handler: string | HandlerType): RouterGroup;
32
- serialize(routes: Route | Array<Route> | RouterGroup | Array<RouterGroup>): RouterGroup;
32
+ serialize(routes: Route | Array<Route> | RouterGroup | Array<RouterGroup> | Array<RawsRoute>): RouterGroup;
33
33
  private mergeRoutes;
34
34
  private joinPaths;
35
35
  private resolveControllerString;
36
36
  private resolveIncludedActions;
37
37
  private hasRaw;
38
+ private hasRaws;
38
39
  private isMethodMap;
39
40
  private applyGroup;
40
41
  }
@@ -31,9 +31,36 @@ export default class RouterBuilder {
31
31
  group(routes) {
32
32
  const rawGroups = [];
33
33
  let routeGroups = {};
34
+ if (this.hasRaws(routes)) {
35
+ const routeList = Array.isArray(routes) ? routes.flat() : [routes];
36
+ const routerGroups = routeList.filter((value) => !this.hasRaws(value) && !this.hasRaw(value));
37
+ const rawRoutes = routeList.filter((value) => this.hasRaws(value)).map((value) => value.raws).flat();
38
+ const newRoutes = {};
39
+ for (const route of rawRoutes) {
40
+ const middlewares = this.middlewares.concat(defineValue(route.raw.middlewares, []));
41
+ const effectiveNamespace = defineValue(this.baseNamespace, route.raw.namespace);
42
+ const cleanPath = this.joinPaths(defineValue(route.raw.prefix, this.basePath), route.raw.path);
43
+ let resolvedHandler = typeof route.raw.handler === "string" ?
44
+ this.resolveControllerString(route.raw.handler, effectiveNamespace) :
45
+ route.raw.handler;
46
+ for (const middleware of [...middlewares].reverse()) {
47
+ resolvedHandler = middleware.handle(resolvedHandler);
48
+ }
49
+ if (isEmpty(newRoutes[cleanPath]))
50
+ newRoutes[cleanPath] = {};
51
+ Object.assign(newRoutes[cleanPath], {
52
+ [route.raw.method]: resolvedHandler
53
+ });
54
+ route.raw.middlewares = middlewares;
55
+ route.raw.namespace = effectiveNamespace;
56
+ route.raw.path = cleanPath;
57
+ rawGroups.push(route);
58
+ }
59
+ routeGroups = Object.assign({}, ...routerGroups.map((value) => this.applyGroup(value)), newRoutes);
60
+ }
34
61
  if (this.hasRaw(routes)) {
35
62
  const routeList = Array.isArray(routes) ? routes.flat() : [routes];
36
- const routerGroups = routeList.filter((value) => !this.hasRaw(value));
63
+ const routerGroups = routeList.filter((value) => !this.hasRaws(value) && !this.hasRaw(value));
37
64
  const rawRoutes = routeList.filter((value) => this.hasRaw(value));
38
65
  const newRoutes = {};
39
66
  for (const route of rawRoutes) {
@@ -196,13 +223,15 @@ export default class RouterBuilder {
196
223
  if (Array.isArray(routes)) {
197
224
  if (this.hasRaw(routes))
198
225
  routes = routes.map((value) => value.route);
226
+ if (this.hasRaws(routes))
227
+ routes = routes.map((value) => value.routes).flat();
199
228
  }
200
229
  else {
201
230
  if (this.hasRaw(routes))
202
231
  routes = routes.route;
232
+ if (this.hasRaws(routes))
233
+ routes = routes.routes;
203
234
  }
204
- if ("raws" in routes)
205
- routes = routes.routes;
206
235
  const mergedRoutes = this.mergeRoutes(routes);
207
236
  if (Array.isArray(mergedRoutes))
208
237
  return Object.assign({}, ...mergedRoutes);
@@ -289,10 +318,17 @@ export default class RouterBuilder {
289
318
  typeof routes === "object" &&
290
319
  "raw" in routes);
291
320
  }
321
+ hasRaws(routes) {
322
+ if (Array.isArray(routes))
323
+ return routes.flat().some(route => isNotEmpty(route) && "raws" in route);
324
+ return (isNotEmpty(routes) &&
325
+ typeof routes === "object" &&
326
+ "raws" in routes);
327
+ }
292
328
  isMethodMap(value) {
293
329
  return (isNotEmpty(value) &&
294
330
  typeof value === "object" &&
295
- Object.values(value).every(v => typeof v === "function"));
331
+ Object.values(value).every((v) => typeof v === "function"));
296
332
  }
297
333
  applyGroup(route) {
298
334
  if (isEmpty(route))
@@ -301,6 +337,7 @@ export default class RouterBuilder {
301
337
  const routeList = Array.isArray(route) ? route.flat() : [route];
302
338
  const rawRoutes = routeList.filter((value) => this.hasRaw(value));
303
339
  const newRoutes = {};
340
+ const rawGroups = [];
304
341
  for (const route of rawRoutes) {
305
342
  const middlewares = route.raw.middlewares.concat(defineValue(this.middlewares, []));
306
343
  const cleanPath = this.joinPaths(defineValue(route.raw.prefix, this.basePath), route.raw.path);
@@ -318,7 +355,16 @@ export default class RouterBuilder {
318
355
  Object.assign(newRoutes[cleanPath], {
319
356
  [route.raw.method]: resolvedHandler
320
357
  });
358
+ route.raw.middlewares = middlewares;
359
+ route.raw.namespace = effectiveNamespace;
360
+ route.raw.path = cleanPath;
361
+ rawGroups.push(route);
321
362
  }
363
+ if (isNotEmpty(rawGroups))
364
+ return {
365
+ raws: rawGroups,
366
+ routes: newRoutes
367
+ };
322
368
  return newRoutes;
323
369
  }
324
370
  const result = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bejibun/core",
3
- "version": "0.1.72",
3
+ "version": "0.1.73",
4
4
  "author": "Havea Crenata <havea.crenata@gmail.com>",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,7 +16,7 @@
16
16
  "@bejibun/logger": "^0.1.22",
17
17
  "@bejibun/utils": "^0.1.28",
18
18
  "@vinejs/vine": "^4.2.0",
19
- "commander": "^14.0.2",
19
+ "commander": "^14.0.3",
20
20
  "luxon": "^3.7.2",
21
21
  "objection": "^3.1.5"
22
22
  },
package/types/router.d.ts CHANGED
@@ -15,4 +15,8 @@ export type Route = {
15
15
  raw: RawRoute,
16
16
  route: RouterGroup
17
17
  };
18
+ export type RawsRoute = {
19
+ raws: Array<Route>,
20
+ routes: Array<RouterGroup>
21
+ };
18
22
  export type ResourceAction = "index" | "store" | "show" | "update" | "destroy";