@bejibun/core 0.1.71 → 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 +28 -0
- package/builders/ResponseBuilder.d.ts +2 -0
- package/builders/ResponseBuilder.js +8 -1
- package/builders/RouterBuilder.d.ts +3 -2
- package/builders/RouterBuilder.js +50 -4
- package/facades/Response.d.ts +1 -0
- package/facades/Response.js +3 -0
- package/package.json +2 -2
- package/types/router.d.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,34 @@ 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
|
+
|
|
20
|
+
## [v0.1.72](https://github.com/Bejibun-Framework/bejibun-core/compare/v0.1.71...v0.1.72) - 2026-01-29
|
|
21
|
+
|
|
22
|
+
### 🩹 Fixes
|
|
23
|
+
|
|
24
|
+
### 📖 Changes
|
|
25
|
+
- Added `setCustom(custom?: Record<string, any>)` on Response builder.
|
|
26
|
+
|
|
27
|
+
### ❤️Contributors
|
|
28
|
+
- Havea Crenata ([@crenata](https://github.com/crenata))
|
|
29
|
+
|
|
30
|
+
**Full Changelog**: https://github.com/Bejibun-Framework/bejibun-core/blob/master/CHANGELOG.md
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
6
34
|
## [v0.1.71](https://github.com/Bejibun-Framework/bejibun-core/compare/v0.1.70...v0.1.71) - 2026-01-29
|
|
7
35
|
|
|
8
36
|
### 🩹 Fixes
|
|
@@ -2,10 +2,12 @@ export default class ResponseBuilder {
|
|
|
2
2
|
protected data?: any;
|
|
3
3
|
protected message: string;
|
|
4
4
|
protected status: number;
|
|
5
|
+
protected custom?: Record<string, any>;
|
|
5
6
|
constructor();
|
|
6
7
|
setData(data?: any): ResponseBuilder;
|
|
7
8
|
setMessage(message: string): ResponseBuilder;
|
|
8
9
|
setStatus(status: number): ResponseBuilder;
|
|
10
|
+
setCustom(custom?: Record<string, any>): ResponseBuilder;
|
|
9
11
|
send(): globalThis.Response;
|
|
10
12
|
stream(options?: ResponseInit): globalThis.Response;
|
|
11
13
|
}
|
|
@@ -3,10 +3,12 @@ export default class ResponseBuilder {
|
|
|
3
3
|
data;
|
|
4
4
|
message;
|
|
5
5
|
status;
|
|
6
|
+
custom;
|
|
6
7
|
constructor() {
|
|
7
8
|
this.data = null;
|
|
8
9
|
this.message = "Success";
|
|
9
10
|
this.status = 200;
|
|
11
|
+
this.custom = {};
|
|
10
12
|
}
|
|
11
13
|
setData(data) {
|
|
12
14
|
this.data = data;
|
|
@@ -20,11 +22,16 @@ export default class ResponseBuilder {
|
|
|
20
22
|
this.status = status;
|
|
21
23
|
return this;
|
|
22
24
|
}
|
|
25
|
+
setCustom(custom) {
|
|
26
|
+
this.custom = custom;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
23
29
|
send() {
|
|
24
30
|
return globalThis.Response.json({
|
|
25
31
|
data: this.data,
|
|
26
32
|
message: this.message,
|
|
27
|
-
status: this.status
|
|
33
|
+
status: this.status,
|
|
34
|
+
...this.custom
|
|
28
35
|
}, {
|
|
29
36
|
headers: {
|
|
30
37
|
...Cors.init
|
|
@@ -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/facades/Response.d.ts
CHANGED
package/facades/Response.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bejibun/core",
|
|
3
|
-
"version": "0.1.
|
|
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.
|
|
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