@bejibun/core 0.1.57 → 0.1.58
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 +15 -0
- package/bases/BaseController.d.ts +0 -1
- package/bases/BaseController.js +4 -50
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,21 @@ All notable changes to this project will be documented in this file.
|
|
|
3
3
|
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
## [v0.1.58](https://github.com/crenata/bejibun-core/compare/v0.1.57...v0.1.58) - 2025-12-09
|
|
7
|
+
|
|
8
|
+
### 🩹 Fixes
|
|
9
|
+
|
|
10
|
+
### 📖 Changes
|
|
11
|
+
#### Upgrade [@bejibun/utils](https://github.com/crenata/bejibun-utils) to v0.1.25
|
|
12
|
+
- Implement `serialize` and `parseFormData` to `BaseController` for cleaner data and more actual data validation.
|
|
13
|
+
|
|
14
|
+
### ❤️Contributors
|
|
15
|
+
- Ghulje ([@ghulje](https://github.com/ghulje))
|
|
16
|
+
|
|
17
|
+
**Full Changelog**: https://github.com/crenata/bejibun-core/blob/master/CHANGELOG.md
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
6
21
|
## [v0.1.57](https://github.com/crenata/bejibun-core/compare/v0.1.55...v0.1.57) - 2025-12-05
|
|
7
22
|
|
|
8
23
|
### 🩹 Fixes
|
|
@@ -4,5 +4,4 @@ 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 parseForm;
|
|
8
7
|
}
|
package/bases/BaseController.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { defineValue,
|
|
1
|
+
import { defineValue, isNotEmpty } from "@bejibun/utils";
|
|
2
|
+
import { default as Bobject } from "@bejibun/utils/facades/Object";
|
|
2
3
|
import ValidatorException from "../exceptions/ValidatorException";
|
|
3
4
|
import Response from "../facades/Response";
|
|
4
5
|
export default class BaseController {
|
|
@@ -7,7 +8,7 @@ export default class BaseController {
|
|
|
7
8
|
const formData = new FormData();
|
|
8
9
|
try {
|
|
9
10
|
if (contentType.includes("application/json"))
|
|
10
|
-
return await request.json();
|
|
11
|
+
return Bobject.serialize(await request.json());
|
|
11
12
|
for (const [key, value] of Object.entries(request.params)) {
|
|
12
13
|
formData.append(key, value);
|
|
13
14
|
}
|
|
@@ -29,7 +30,7 @@ export default class BaseController {
|
|
|
29
30
|
catch {
|
|
30
31
|
// do nothing
|
|
31
32
|
}
|
|
32
|
-
return
|
|
33
|
+
return Bobject.parseFormData(formData);
|
|
33
34
|
}
|
|
34
35
|
get response() {
|
|
35
36
|
return Response;
|
|
@@ -48,51 +49,4 @@ export default class BaseController {
|
|
|
48
49
|
throw new ValidatorException(message);
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
|
-
parseForm(formData) {
|
|
52
|
-
const result = {};
|
|
53
|
-
for (const [key, value] of formData.entries()) {
|
|
54
|
-
const keys = key.replace(/]/g, "").split("[");
|
|
55
|
-
let current = result;
|
|
56
|
-
for (let i = 0; i < keys.length; i++) {
|
|
57
|
-
const part = keys[i];
|
|
58
|
-
const nextPart = keys[i + 1];
|
|
59
|
-
if (i === keys.length - 1) {
|
|
60
|
-
let convertedValue;
|
|
61
|
-
if (value instanceof File) {
|
|
62
|
-
convertedValue = value;
|
|
63
|
-
}
|
|
64
|
-
else if (value.trim() === "" || value === "null" || value === "undefined") {
|
|
65
|
-
convertedValue = null;
|
|
66
|
-
}
|
|
67
|
-
else if (Number.isNaN(value)) {
|
|
68
|
-
convertedValue = Number(value);
|
|
69
|
-
}
|
|
70
|
-
else if (value === "true" || value === "false") {
|
|
71
|
-
convertedValue = value === "true";
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
try {
|
|
75
|
-
convertedValue = JSON.parse(value);
|
|
76
|
-
}
|
|
77
|
-
catch {
|
|
78
|
-
convertedValue = value;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (current[part] === undefined)
|
|
82
|
-
current[part] = convertedValue;
|
|
83
|
-
else if (Array.isArray(current[part]))
|
|
84
|
-
current[part].push(convertedValue);
|
|
85
|
-
else
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
const isArrayIndex = /^\d+$/.test(nextPart);
|
|
90
|
-
if (isEmpty(current[part]))
|
|
91
|
-
current[part] = isArrayIndex ? [] : {};
|
|
92
|
-
current = current[part];
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return result;
|
|
97
|
-
}
|
|
98
52
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bejibun/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.58",
|
|
4
4
|
"author": "Havea Crenata <havea.crenata@gmail.com>",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,7 +14,7 @@
|
|
|
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.25",
|
|
18
18
|
"@vinejs/vine": "^3.0.1",
|
|
19
19
|
"commander": "^14.0.2",
|
|
20
20
|
"luxon": "^3.7.2",
|