@bejibun/core 0.1.53 → 0.1.55

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,38 @@ All notable changes to this project will be documented in this file.
3
3
 
4
4
  ---
5
5
 
6
+ ## [v0.1.55](https://github.com/crenata/bejibun-core/compare/v0.1.54...v0.1.55) - 2025-11-29
7
+
8
+ ### 🩹 Fixes
9
+ - Body parser for multiple keys - [#2](https://github.com/crenata/bejibun-core/issues/2)
10
+ - x402 on nester router - [#3](https://github.com/crenata/bejibun-core/issues/3)
11
+ - Storage directory undefined - [#4](https://github.com/crenata/bejibun-core/issues/4)
12
+ - Unknown actual error on runtime exception - [#5](https://github.com/crenata/bejibun-core/issues/5)
13
+
14
+ ### 📖 Changes
15
+ - Storage adjustment: random string filename.
16
+
17
+ ### ❤️Contributors
18
+ - Havea Crenata ([@crenata](https://github.com/crenata))
19
+
20
+ **Full Changelog**: https://github.com/crenata/bejibun-core/blob/master/CHANGELOG.md
21
+
22
+ ---
23
+
24
+ ## [v0.1.54](https://github.com/crenata/bejibun-core/compare/v0.1.53...v0.1.54) - 2025-11-28
25
+
26
+ ### 🩹 Fixes
27
+ - Fix x402 middleware for optional
28
+
29
+ ### 📖 Changes
30
+
31
+ ### ❤️Contributors
32
+ - Ghulje ([@ghulje](https://github.com/ghulje))
33
+
34
+ **Full Changelog**: https://github.com/crenata/bejibun-core/blob/master/CHANGELOG.md
35
+
36
+ ---
37
+
6
38
  ## [v0.1.53](https://github.com/crenata/bejibun-core/compare/v0.1.52...v0.1.53) - 2025-11-24
7
39
 
8
40
  ### 🩹 Fixes
@@ -111,7 +111,7 @@ export default class BaseController {
111
111
  else if (Array.isArray(current[part]))
112
112
  current[part].push(convertedValue);
113
113
  else
114
- current[part] = [current[part], convertedValue];
114
+ continue;
115
115
  }
116
116
  else {
117
117
  const isArrayIndex = /^\d+$/.test(nextPart);
@@ -17,6 +17,15 @@ export default class RouterBuilder {
17
17
  group(routes: RouterGroup | Array<RouterGroup>): RouterGroup;
18
18
  resources(controller: Record<string, HandlerType>, options?: ResourceOptions): RouterGroup;
19
19
  buildSingle(method: HttpMethodEnum, path: string, handler: string | HandlerType): RouterGroup;
20
+ connect(path: string, handler: string | HandlerType): RouterGroup;
21
+ delete(path: string, handler: string | HandlerType): RouterGroup;
22
+ get(path: string, handler: string | HandlerType): RouterGroup;
23
+ head(path: string, handler: string | HandlerType): RouterGroup;
24
+ options(path: string, handler: string | HandlerType): RouterGroup;
25
+ patch(path: string, handler: string | HandlerType): RouterGroup;
26
+ post(path: string, handler: string | HandlerType): RouterGroup;
27
+ put(path: string, handler: string | HandlerType): RouterGroup;
28
+ trace(path: string, handler: string | HandlerType): RouterGroup;
20
29
  match(methods: Array<HttpMethodEnum>, path: string, handler: string | HandlerType): RouterGroup;
21
30
  any(path: string, handler: string | HandlerType): RouterGroup;
22
31
  private joinPaths;
@@ -4,7 +4,6 @@ import HttpMethodEnum from "@bejibun/utils/enums/HttpMethodEnum";
4
4
  import Enum from "@bejibun/utils/facades/Enum";
5
5
  import path from "path";
6
6
  import RouterInvalidException from "../exceptions/RouterInvalidException";
7
- import X402Middleware from "../middlewares/X402Middleware";
8
7
  export default class RouterBuilder {
9
8
  basePath = "";
10
9
  middlewares = [];
@@ -24,6 +23,7 @@ export default class RouterBuilder {
24
23
  x402(config, facilitatorConfig, paywallConfig) {
25
24
  if (!isModuleExists("@bejibun/x402"))
26
25
  throw new RouterInvalidException("@bejibun/x402 is not installed.");
26
+ const X402Middleware = require("../middlewares/X402Middleware").default;
27
27
  this.middlewares.push(new X402Middleware(config, facilitatorConfig, paywallConfig));
28
28
  return this;
29
29
  }
@@ -92,6 +92,33 @@ export default class RouterBuilder {
92
92
  }
93
93
  };
94
94
  }
95
+ connect(path, handler) {
96
+ return this.buildSingle(HttpMethodEnum.Connect, path, handler);
97
+ }
98
+ delete(path, handler) {
99
+ return this.buildSingle(HttpMethodEnum.Delete, path, handler);
100
+ }
101
+ get(path, handler) {
102
+ return this.buildSingle(HttpMethodEnum.Get, path, handler);
103
+ }
104
+ head(path, handler) {
105
+ return this.buildSingle(HttpMethodEnum.Head, path, handler);
106
+ }
107
+ options(path, handler) {
108
+ return this.buildSingle(HttpMethodEnum.Options, path, handler);
109
+ }
110
+ patch(path, handler) {
111
+ return this.buildSingle(HttpMethodEnum.Patch, path, handler);
112
+ }
113
+ post(path, handler) {
114
+ return this.buildSingle(HttpMethodEnum.Post, path, handler);
115
+ }
116
+ put(path, handler) {
117
+ return this.buildSingle(HttpMethodEnum.Put, path, handler);
118
+ }
119
+ trace(path, handler) {
120
+ return this.buildSingle(HttpMethodEnum.Trace, path, handler);
121
+ }
95
122
  match(methods, path, handler) {
96
123
  const routeMap = {};
97
124
  for (const method of methods) {
@@ -0,0 +1,10 @@
1
+ export default class StorageBuilder {
2
+ protected file: any;
3
+ protected directory?: string;
4
+ protected name?: string;
5
+ constructor();
6
+ setFile(file: any): StorageBuilder;
7
+ setDirectory(directory: string): StorageBuilder;
8
+ setName(name: string): StorageBuilder;
9
+ save(): Promise<any>;
10
+ }
@@ -0,0 +1,31 @@
1
+ import App from "@bejibun/app";
2
+ import { isEmpty } from "@bejibun/utils";
3
+ import Luxon from "@bejibun/utils/facades/Luxon";
4
+ import Str from "@bejibun/utils/facades/Str";
5
+ import path from "path";
6
+ export default class StorageBuilder {
7
+ file;
8
+ directory;
9
+ name;
10
+ constructor() {
11
+ this.name = "";
12
+ this.directory = "general";
13
+ }
14
+ setFile(file) {
15
+ this.file = file;
16
+ return this;
17
+ }
18
+ setDirectory(directory) {
19
+ this.directory = directory;
20
+ return this;
21
+ }
22
+ setName(name) {
23
+ this.name = name;
24
+ return this;
25
+ }
26
+ async save() {
27
+ if (isEmpty(this.name))
28
+ this.name = Str.random();
29
+ await Bun.write(App.Path.storagePath(`app/public/${this.directory}/${Luxon.DateTime.now().toUnixInteger()}-${this.name}${path.extname(this.file?.name)}`), this.file);
30
+ }
31
+ }
@@ -1,4 +1,4 @@
1
1
  export default class RuntimeException extends Error {
2
2
  code: number;
3
- constructor(message?: string, code?: number);
3
+ constructor(message?: string, code?: number | undefined | null, stack?: string);
4
4
  }
@@ -2,10 +2,11 @@ import Logger from "@bejibun/logger";
2
2
  import { defineValue } from "@bejibun/utils";
3
3
  export default class RuntimeException extends Error {
4
4
  code;
5
- constructor(message, code) {
5
+ constructor(message, code, stack) {
6
6
  super(message);
7
7
  this.name = "RuntimeException";
8
8
  this.code = defineValue(code, 500);
9
+ this.stack = stack;
9
10
  Logger.setContext(this.name).error(this.message).trace(this.stack);
10
11
  if (Error.captureStackTrace) {
11
12
  Error.captureStackTrace(this, RuntimeException);
package/facades/Router.js CHANGED
@@ -1,4 +1,3 @@
1
- import HttpMethodEnum from "@bejibun/utils/enums/HttpMethodEnum";
2
1
  import RouterBuilder from "../builders/RouterBuilder";
3
2
  export default class Router {
4
3
  static prefix(basePath) {
@@ -25,31 +24,31 @@ export default class Router {
25
24
  return builder.group(routes);
26
25
  }
27
26
  static connect(path, handler) {
28
- return new RouterBuilder().buildSingle(HttpMethodEnum.Connect, path, handler);
27
+ return new RouterBuilder().connect(path, handler);
29
28
  }
30
29
  static delete(path, handler) {
31
- return new RouterBuilder().buildSingle(HttpMethodEnum.Delete, path, handler);
30
+ return new RouterBuilder().delete(path, handler);
32
31
  }
33
32
  static get(path, handler) {
34
- return new RouterBuilder().buildSingle(HttpMethodEnum.Get, path, handler);
33
+ return new RouterBuilder().get(path, handler);
35
34
  }
36
35
  static head(path, handler) {
37
- return new RouterBuilder().buildSingle(HttpMethodEnum.Head, path, handler);
36
+ return new RouterBuilder().head(path, handler);
38
37
  }
39
38
  static options(path, handler) {
40
- return new RouterBuilder().buildSingle(HttpMethodEnum.Options, path, handler);
39
+ return new RouterBuilder().options(path, handler);
41
40
  }
42
41
  static patch(path, handler) {
43
- return new RouterBuilder().buildSingle(HttpMethodEnum.Patch, path, handler);
42
+ return new RouterBuilder().patch(path, handler);
44
43
  }
45
44
  static post(path, handler) {
46
- return new RouterBuilder().buildSingle(HttpMethodEnum.Post, path, handler);
45
+ return new RouterBuilder().post(path, handler);
47
46
  }
48
47
  static put(path, handler) {
49
- return new RouterBuilder().buildSingle(HttpMethodEnum.Put, path, handler);
48
+ return new RouterBuilder().put(path, handler);
50
49
  }
51
50
  static trace(path, handler) {
52
- return new RouterBuilder().buildSingle(HttpMethodEnum.Trace, path, handler);
51
+ return new RouterBuilder().trace(path, handler);
53
52
  }
54
53
  static match(methods, path, handler) {
55
54
  return new RouterBuilder().match(methods, path, handler);
@@ -0,0 +1,3 @@
1
+ export default class Storage {
2
+ static save(file: any, directory?: string, name?: string): Promise<any>;
3
+ }
@@ -0,0 +1,12 @@
1
+ import { isNotEmpty } from "@bejibun/utils";
2
+ import StorageBuilder from "../builders/StorageBuilder";
3
+ export default class Storage {
4
+ static async save(file, directory, name) {
5
+ const builder = new StorageBuilder().setFile(file);
6
+ if (isNotEmpty(directory))
7
+ builder.setDirectory(directory);
8
+ if (isNotEmpty(name))
9
+ builder.setName(name);
10
+ return await builder.save();
11
+ }
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bejibun/core",
3
- "version": "0.1.53",
3
+ "version": "0.1.55",
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.21",
17
+ "@bejibun/utils": "^0.1.22",
18
18
  "@vinejs/vine": "^3.0.1",
19
19
  "commander": "^14.0.2",
20
20
  "luxon": "^3.7.2",
package/server.js CHANGED
@@ -10,24 +10,24 @@ let ExceptionHandler;
10
10
  try {
11
11
  ExceptionHandler = require(exceptionHandlerPath).default;
12
12
  }
13
- catch {
14
- throw new RuntimeException(`Missing exception handler class [${exceptionHandlerPath}].`);
13
+ catch (error) {
14
+ throw new RuntimeException(`Missing exception handler class [${exceptionHandlerPath}].`, null, error.message);
15
15
  }
16
16
  const apiRoutesPath = App.Path.routesPath("api.ts");
17
17
  let ApiRoutes;
18
18
  try {
19
19
  ApiRoutes = require(apiRoutesPath).default;
20
20
  }
21
- catch {
22
- throw new RuntimeException(`Missing api file on routes directory [${apiRoutesPath}].`);
21
+ catch (error) {
22
+ throw new RuntimeException(`Missing api file on routes directory [${apiRoutesPath}].`, null, error.message);
23
23
  }
24
24
  const webRoutesPath = App.Path.routesPath("web.ts");
25
25
  let WebRoutes;
26
26
  try {
27
27
  WebRoutes = require(webRoutesPath).default;
28
28
  }
29
- catch {
30
- throw new RuntimeException(`Missing web file on routes directory [${webRoutesPath}].`);
29
+ catch (error) {
30
+ throw new RuntimeException(`Missing web file on routes directory [${webRoutesPath}].`, null, error.message);
31
31
  }
32
32
  const server = Bun.serve({
33
33
  development: Bun.env.NODE_ENV !== "production" && {