@bejibun/core 0.1.54 → 0.1.56

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,24 @@ 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
+
6
24
  ## [v0.1.54](https://github.com/crenata/bejibun-core/compare/v0.1.53...v0.1.54) - 2025-11-28
7
25
 
8
26
  ### 🩹 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;
@@ -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) {
@@ -1,6 +1,7 @@
1
1
  import App from "@bejibun/app";
2
2
  import { isEmpty } from "@bejibun/utils";
3
3
  import Luxon from "@bejibun/utils/facades/Luxon";
4
+ import Str from "@bejibun/utils/facades/Str";
4
5
  import path from "path";
5
6
  export default class StorageBuilder {
6
7
  file;
@@ -8,6 +9,7 @@ export default class StorageBuilder {
8
9
  name;
9
10
  constructor() {
10
11
  this.name = "";
12
+ this.directory = "general";
11
13
  }
12
14
  setFile(file) {
13
15
  this.file = file;
@@ -23,7 +25,7 @@ export default class StorageBuilder {
23
25
  }
24
26
  async save() {
25
27
  if (isEmpty(this.name))
26
- this.name = `${Luxon.DateTime.now().toUnixInteger()}-${Math.random().toString(36).substring(2, 2 + 16)}`;
27
- await Bun.write(App.Path.storagePath(`app/public/${this.directory}/${this.name}${path.extname(this.file?.name)}`), this.file);
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);
28
30
  }
29
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bejibun/core",
3
- "version": "0.1.54",
3
+ "version": "0.1.56",
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" && {
@@ -4,6 +4,8 @@ import BaseModel from "../../bases/BaseModel";
4
4
  const exists = async (value, options, field) => {
5
5
  if (!field.isValid)
6
6
  return;
7
+ if (options.nullable)
8
+ return;
7
9
  const column = defineValue(options.column, field.name);
8
10
  let query = options.table;
9
11
  if (options.withTrashed)
@@ -16,10 +18,10 @@ const exists = async (value, options, field) => {
16
18
  };
17
19
  const existsRule = vine.createRule(exists, { isAsync: true });
18
20
  const registerExistsMacro = (Type) => {
19
- Type.macro("exists", function (tableOrOptions, column, withTrashed) {
21
+ Type.macro("exists", function (tableOrOptions, column, withTrashed, nullable) {
20
22
  const isModel = typeof tableOrOptions === "function" && Object.prototype.isPrototypeOf.call(BaseModel, tableOrOptions);
21
23
  const options = isModel
22
- ? { table: tableOrOptions, column, withTrashed }
24
+ ? { table: tableOrOptions, column, withTrashed, nullable }
23
25
  : tableOrOptions;
24
26
  return this.use(existsRule(options));
25
27
  });
@@ -4,6 +4,8 @@ import BaseModel from "../../bases/BaseModel";
4
4
  const unique = async (value, options, field) => {
5
5
  if (!field.isValid)
6
6
  return;
7
+ if (options.nullable)
8
+ return;
7
9
  const column = defineValue(options.column, field.name);
8
10
  let query = options.table;
9
11
  if (options.withTrashed)
@@ -16,10 +18,10 @@ const unique = async (value, options, field) => {
16
18
  };
17
19
  const uniqueRule = vine.createRule(unique, { isAsync: true });
18
20
  const registerUniqueMacro = (Type) => {
19
- Type.macro("unique", function (tableOrOptions, column, withTrashed) {
21
+ Type.macro("unique", function (tableOrOptions, column, withTrashed, nullable) {
20
22
  const isModel = typeof tableOrOptions === "function" && Object.prototype.isPrototypeOf.call(BaseModel, tableOrOptions);
21
23
  const options = isModel
22
- ? { table: tableOrOptions, column, withTrashed }
24
+ ? { table: tableOrOptions, column, withTrashed, nullable }
23
25
  : tableOrOptions;
24
26
  return this.use(uniqueRule(options));
25
27
  });