@bejibun/core 0.1.56 → 0.1.57
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 +27 -0
- package/bases/BaseController.d.ts +0 -1
- package/bases/BaseController.js +8 -36
- package/builders/RouterBuilder.js +10 -10
- package/exceptions/ExceptionHandler.d.ts +2 -2
- package/exceptions/ExceptionHandler.js +2 -2
- package/exceptions/{RouterInvalidException.d.ts → RouterException.d.ts} +1 -1
- package/exceptions/{RouterInvalidException.js → RouterException.js} +3 -3
- package/exceptions/index.d.ts +1 -1
- package/exceptions/index.js +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,33 @@ All notable changes to this project will be documented in this file.
|
|
|
3
3
|
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
## [v0.1.57](https://github.com/crenata/bejibun-core/compare/v0.1.55...v0.1.57) - 2025-12-05
|
|
7
|
+
|
|
8
|
+
### 🩹 Fixes
|
|
9
|
+
- Hang, when redis not connected - [#7](https://github.com/crenata/bejibun-core/issues/7)
|
|
10
|
+
- Handling for invalid syntax validation - [#8](https://github.com/crenata/bejibun-core/issues/8)
|
|
11
|
+
- Body serialize for empty form data field - [#9](https://github.com/crenata/bejibun-core/issues/9)
|
|
12
|
+
|
|
13
|
+
#### [@bejibun/utils](https://github.com/crenata/bejibun-utils)
|
|
14
|
+
- Empty validation for file - [#1](https://github.com/crenata/bejibun-utils/issues/1)
|
|
15
|
+
|
|
16
|
+
### 📖 Changes
|
|
17
|
+
#### Upgrade [@bejibun/utils](https://github.com/crenata/bejibun-utils) to v0.1.23
|
|
18
|
+
- Empty validation for file
|
|
19
|
+
|
|
20
|
+
#### Upgrade [@bejibun/cache](https://github.com/crenata/bejibun-cache) to v0.1.12
|
|
21
|
+
- Adding `local` connection for file schema.
|
|
22
|
+
|
|
23
|
+
Now, [@bejibun/cache](https://github.com/crenata/bejibun-cache) has local and redis for cache system.
|
|
24
|
+
If the connection use local, this will cache data as file on storage/cache.
|
|
25
|
+
|
|
26
|
+
### ❤️Contributors
|
|
27
|
+
- Havea Crenata ([@crenata](https://github.com/crenata))
|
|
28
|
+
|
|
29
|
+
**Full Changelog**: https://github.com/crenata/bejibun-core/blob/master/CHANGELOG.md
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
6
33
|
## [v0.1.55](https://github.com/crenata/bejibun-core/compare/v0.1.54...v0.1.55) - 2025-11-29
|
|
7
34
|
|
|
8
35
|
### 🩹 Fixes
|
|
@@ -4,6 +4,5 @@ export default class BaseController {
|
|
|
4
4
|
parse(request: Bun.BunRequest): Promise<Record<string, any>>;
|
|
5
5
|
get response(): typeof Response;
|
|
6
6
|
validate(validator: VineValidator<any, Record<string, any> | undefined>, body: Record<string, any>): Promise<any>;
|
|
7
|
-
private serialize;
|
|
8
7
|
private parseForm;
|
|
9
8
|
}
|
package/bases/BaseController.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { defineValue, isEmpty, isNotEmpty } from "@bejibun/utils";
|
|
2
|
-
import { DateTime } from "luxon";
|
|
3
2
|
import ValidatorException from "../exceptions/ValidatorException";
|
|
4
3
|
import Response from "../facades/Response";
|
|
5
4
|
export default class BaseController {
|
|
@@ -40,42 +39,15 @@ export default class BaseController {
|
|
|
40
39
|
return await validator.validate(body);
|
|
41
40
|
}
|
|
42
41
|
catch (error) {
|
|
43
|
-
|
|
42
|
+
const defaultMessage = "Invalid syntax validation.";
|
|
43
|
+
let message = defaultMessage;
|
|
44
|
+
if (isNotEmpty(error?.messages))
|
|
45
|
+
message = defineValue(error?.messages[0]?.message, defaultMessage);
|
|
46
|
+
else
|
|
47
|
+
message = defineValue(error?.message, defaultMessage);
|
|
48
|
+
throw new ValidatorException(message);
|
|
44
49
|
}
|
|
45
50
|
}
|
|
46
|
-
serialize(data) {
|
|
47
|
-
if (Array.isArray(data))
|
|
48
|
-
return data.map((value) => this.serialize(value));
|
|
49
|
-
if (data === null || data === undefined)
|
|
50
|
-
return null;
|
|
51
|
-
if (data instanceof DateTime)
|
|
52
|
-
return data.isValid ? data.toISO() : null;
|
|
53
|
-
if (data instanceof Date)
|
|
54
|
-
return Number.isNaN(data.getTime()) ? null : data.toISOString();
|
|
55
|
-
if (typeof data === "object" && !(data instanceof File)) {
|
|
56
|
-
if (Object.keys(data).length === 0)
|
|
57
|
-
return null;
|
|
58
|
-
const nested = {};
|
|
59
|
-
Object.keys(data).forEach((key) => {
|
|
60
|
-
nested[key] = this.serialize(data[key]);
|
|
61
|
-
});
|
|
62
|
-
return nested;
|
|
63
|
-
}
|
|
64
|
-
if (typeof data === "string") {
|
|
65
|
-
const trimmed = data.trim();
|
|
66
|
-
if (trimmed === "")
|
|
67
|
-
return null;
|
|
68
|
-
if (trimmed === "true")
|
|
69
|
-
return true;
|
|
70
|
-
if (trimmed === "false")
|
|
71
|
-
return false;
|
|
72
|
-
const numeric = Number(trimmed);
|
|
73
|
-
if (!Number.isNaN(numeric) && trimmed === numeric.toString())
|
|
74
|
-
return numeric;
|
|
75
|
-
return trimmed;
|
|
76
|
-
}
|
|
77
|
-
return data;
|
|
78
|
-
}
|
|
79
51
|
parseForm(formData) {
|
|
80
52
|
const result = {};
|
|
81
53
|
for (const [key, value] of formData.entries()) {
|
|
@@ -89,7 +61,7 @@ export default class BaseController {
|
|
|
89
61
|
if (value instanceof File) {
|
|
90
62
|
convertedValue = value;
|
|
91
63
|
}
|
|
92
|
-
else if (value.trim() === "") {
|
|
64
|
+
else if (value.trim() === "" || value === "null" || value === "undefined") {
|
|
93
65
|
convertedValue = null;
|
|
94
66
|
}
|
|
95
67
|
else if (Number.isNaN(value)) {
|
|
@@ -3,7 +3,7 @@ import { isEmpty, isModuleExists } from "@bejibun/utils";
|
|
|
3
3
|
import HttpMethodEnum from "@bejibun/utils/enums/HttpMethodEnum";
|
|
4
4
|
import Enum from "@bejibun/utils/facades/Enum";
|
|
5
5
|
import path from "path";
|
|
6
|
-
import
|
|
6
|
+
import RouterException from "../exceptions/RouterException";
|
|
7
7
|
export default class RouterBuilder {
|
|
8
8
|
basePath = "";
|
|
9
9
|
middlewares = [];
|
|
@@ -22,7 +22,7 @@ export default class RouterBuilder {
|
|
|
22
22
|
}
|
|
23
23
|
x402(config, facilitatorConfig, paywallConfig) {
|
|
24
24
|
if (!isModuleExists("@bejibun/x402"))
|
|
25
|
-
throw new
|
|
25
|
+
throw new RouterException("@bejibun/x402 is not installed.");
|
|
26
26
|
const X402Middleware = require("../middlewares/X402Middleware").default;
|
|
27
27
|
this.middlewares.push(new X402Middleware(config, facilitatorConfig, paywallConfig));
|
|
28
28
|
return this;
|
|
@@ -32,7 +32,7 @@ export default class RouterBuilder {
|
|
|
32
32
|
const newRoutes = {};
|
|
33
33
|
for (const route of routeList) {
|
|
34
34
|
for (const path in route) {
|
|
35
|
-
const
|
|
35
|
+
const cleanPath = this.joinPaths(this.basePath, path);
|
|
36
36
|
const routeHandlers = route[path];
|
|
37
37
|
const wrappedHandlers = {};
|
|
38
38
|
for (const method in routeHandlers) {
|
|
@@ -42,9 +42,9 @@ export default class RouterBuilder {
|
|
|
42
42
|
}
|
|
43
43
|
wrappedHandlers[method] = handler;
|
|
44
44
|
}
|
|
45
|
-
if (isEmpty(newRoutes[
|
|
46
|
-
newRoutes[
|
|
47
|
-
Object.assign(newRoutes[
|
|
45
|
+
if (isEmpty(newRoutes[cleanPath]))
|
|
46
|
+
newRoutes[cleanPath] = {};
|
|
47
|
+
Object.assign(newRoutes[cleanPath], wrappedHandlers);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
return newRoutes;
|
|
@@ -142,7 +142,7 @@ export default class RouterBuilder {
|
|
|
142
142
|
resolveControllerString(definition) {
|
|
143
143
|
const [controllerName, methodName] = definition.split("@");
|
|
144
144
|
if (isEmpty(controllerName) || isEmpty(methodName)) {
|
|
145
|
-
throw new
|
|
145
|
+
throw new RouterException(`Invalid router controller definition: ${definition}.`);
|
|
146
146
|
}
|
|
147
147
|
const controllerPath = path.resolve(App.Path.rootPath(), this.baseNamespace);
|
|
148
148
|
const location = Bun.resolveSync(`./${controllerName}.ts`, controllerPath);
|
|
@@ -156,17 +156,17 @@ export default class RouterBuilder {
|
|
|
156
156
|
const ESMController = module.default;
|
|
157
157
|
const instance = new ESMController();
|
|
158
158
|
if (typeof instance[methodName] !== "function") {
|
|
159
|
-
throw new
|
|
159
|
+
throw new RouterException(`Method "${methodName}" not found in ${controllerName}.`);
|
|
160
160
|
}
|
|
161
161
|
return instance[methodName](...args);
|
|
162
162
|
};
|
|
163
163
|
}
|
|
164
164
|
if (isEmpty(ControllerClass)) {
|
|
165
|
-
throw new
|
|
165
|
+
throw new RouterException(`Controller not found: ${controllerName}.`);
|
|
166
166
|
}
|
|
167
167
|
const instance = new ControllerClass();
|
|
168
168
|
if (typeof instance[methodName] !== "function") {
|
|
169
|
-
throw new
|
|
169
|
+
throw new RouterException(`Method "${methodName}" not found in ${controllerName}.`);
|
|
170
170
|
}
|
|
171
171
|
return instance[methodName].bind(instance);
|
|
172
172
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ValidationError } from "objection";
|
|
2
2
|
import ModelNotFoundException from "../exceptions/ModelNotFoundException";
|
|
3
3
|
import RateLimiterException from "../exceptions/RateLimiterException";
|
|
4
|
-
import
|
|
4
|
+
import RouterException from "../exceptions/RouterException";
|
|
5
5
|
import RuntimeException from "../exceptions/RuntimeException";
|
|
6
6
|
import ValidatorException from "../exceptions/ValidatorException";
|
|
7
7
|
export default class ExceptionHandler {
|
|
8
|
-
handle(error: Bun.ErrorLike | ModelNotFoundException | RateLimiterException |
|
|
8
|
+
handle(error: Bun.ErrorLike | ModelNotFoundException | RateLimiterException | RouterException | RuntimeException | ValidatorException | ValidationError): globalThis.Response;
|
|
9
9
|
route(request: Bun.BunRequest): globalThis.Response;
|
|
10
10
|
}
|
|
@@ -4,7 +4,7 @@ import HttpMethodEnum from "@bejibun/utils/enums/HttpMethodEnum";
|
|
|
4
4
|
import { ValidationError } from "objection";
|
|
5
5
|
import ModelNotFoundException from "../exceptions/ModelNotFoundException";
|
|
6
6
|
import RateLimiterException from "../exceptions/RateLimiterException";
|
|
7
|
-
import
|
|
7
|
+
import RouterException from "../exceptions/RouterException";
|
|
8
8
|
import RuntimeException from "../exceptions/RuntimeException";
|
|
9
9
|
import ValidatorException from "../exceptions/ValidatorException";
|
|
10
10
|
import Response from "../facades/Response";
|
|
@@ -13,7 +13,7 @@ export default class ExceptionHandler {
|
|
|
13
13
|
Logger.setContext("APP").error(error.message).trace(error.stack);
|
|
14
14
|
if (error instanceof ModelNotFoundException ||
|
|
15
15
|
error instanceof RateLimiterException ||
|
|
16
|
-
error instanceof
|
|
16
|
+
error instanceof RouterException ||
|
|
17
17
|
error instanceof RuntimeException ||
|
|
18
18
|
error instanceof ValidatorException)
|
|
19
19
|
return Response
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import Logger from "@bejibun/logger";
|
|
2
2
|
import { defineValue } from "@bejibun/utils";
|
|
3
|
-
export default class
|
|
3
|
+
export default class RouterException extends Error {
|
|
4
4
|
code;
|
|
5
5
|
constructor(message, code) {
|
|
6
6
|
super(message);
|
|
7
|
-
this.name = "
|
|
7
|
+
this.name = "RouterException";
|
|
8
8
|
this.code = defineValue(code, 500);
|
|
9
9
|
Logger.setContext(this.name).error(this.message).trace(this.stack);
|
|
10
10
|
if (Error.captureStackTrace) {
|
|
11
|
-
Error.captureStackTrace(this,
|
|
11
|
+
Error.captureStackTrace(this, RouterException);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
}
|
package/exceptions/index.d.ts
CHANGED
package/exceptions/index.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.57",
|
|
4
4
|
"author": "Havea Crenata <havea.crenata@gmail.com>",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
"module": "index.js",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@bejibun/app": "^0.1.22",
|
|
13
|
-
"@bejibun/cache": "^0.1.
|
|
13
|
+
"@bejibun/cache": "^0.1.12",
|
|
14
14
|
"@bejibun/cors": "^0.1.16",
|
|
15
15
|
"@bejibun/database": "^0.1.19",
|
|
16
16
|
"@bejibun/logger": "^0.1.22",
|
|
17
|
-
"@bejibun/utils": "^0.1.
|
|
17
|
+
"@bejibun/utils": "^0.1.23",
|
|
18
18
|
"@vinejs/vine": "^3.0.1",
|
|
19
19
|
"commander": "^14.0.2",
|
|
20
20
|
"luxon": "^3.7.2",
|