@bejibun/core 0.1.39 → 0.1.41

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.
Files changed (60) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/bases/BaseController.d.ts +1 -2
  3. package/bases/BaseModel.js +3 -3
  4. package/builders/RouterBuilder.d.ts +4 -0
  5. package/builders/RouterBuilder.js +30 -7
  6. package/commands/Kernel.d.ts +1 -0
  7. package/commands/Kernel.js +28 -13
  8. package/commands/{DbSeedCommand.d.ts → db/DbSeedCommand.d.ts} +2 -2
  9. package/commands/{DbSeedCommand.js → db/DbSeedCommand.js} +2 -2
  10. package/commands/maintenance/MaintenanceDownCommand.d.ts +27 -0
  11. package/commands/maintenance/MaintenanceDownCommand.js +40 -0
  12. package/commands/{MigrateFreshCommand.d.ts → migrate/MigrateFreshCommand.d.ts} +2 -2
  13. package/commands/{MigrateFreshCommand.js → migrate/MigrateFreshCommand.js} +5 -4
  14. package/commands/{MigrateLatestCommand.d.ts → migrate/MigrateLatestCommand.d.ts} +2 -2
  15. package/commands/{MigrateLatestCommand.js → migrate/MigrateLatestCommand.js} +2 -2
  16. package/commands/{MigrateRollbackCommand.d.ts → migrate/MigrateRollbackCommand.d.ts} +2 -2
  17. package/commands/{MigrateRollbackCommand.js → migrate/MigrateRollbackCommand.js} +5 -4
  18. package/commands/{MigrateStatusCommand.d.ts → migrate/MigrateStatusCommand.d.ts} +2 -2
  19. package/commands/{MigrateStatusCommand.js → migrate/MigrateStatusCommand.js} +5 -4
  20. package/config/database.js +2 -2
  21. package/exceptions/ModelNotFoundException.js +2 -0
  22. package/exceptions/RouterInvalidException.js +2 -0
  23. package/exceptions/ValidatorException.js +2 -0
  24. package/facades/Router.d.ts +1 -0
  25. package/facades/Router.js +5 -14
  26. package/package.json +6 -5
  27. package/types/router.d.ts +1 -1
  28. package/bun.lock +0 -266
  29. package/src/ace.ts +0 -22
  30. package/src/bases/BaseController.ts +0 -139
  31. package/src/bases/BaseModel.ts +0 -108
  32. package/src/bases/BaseValidator.ts +0 -8
  33. package/src/bases/index.ts +0 -3
  34. package/src/bootstrap.ts +0 -5
  35. package/src/builders/ResponseBuilder.ts +0 -54
  36. package/src/builders/RouterBuilder.ts +0 -173
  37. package/src/commands/DbSeedCommand.ts +0 -57
  38. package/src/commands/Kernel.ts +0 -49
  39. package/src/commands/MigrateFreshCommand.ts +0 -76
  40. package/src/commands/MigrateLatestCommand.ts +0 -56
  41. package/src/commands/MigrateRollbackCommand.ts +0 -72
  42. package/src/commands/MigrateStatusCommand.ts +0 -64
  43. package/src/config/database.ts +0 -41
  44. package/src/exceptions/ModelNotFoundException.ts +0 -15
  45. package/src/exceptions/RouterInvalidException.ts +0 -15
  46. package/src/exceptions/ValidatorException.ts +0 -15
  47. package/src/exceptions/index.ts +0 -3
  48. package/src/facades/Response.ts +0 -15
  49. package/src/facades/Router.ts +0 -89
  50. package/src/facades/SoftDeletes.ts +0 -66
  51. package/src/facades/index.ts +0 -3
  52. package/src/index.ts +0 -5
  53. package/src/types/index.d.ts +0 -4
  54. package/src/types/middleware.d.ts +0 -7
  55. package/src/types/router.d.ts +0 -5
  56. package/src/types/validator.d.ts +0 -3
  57. package/src/types/vine.d.ts +0 -13
  58. package/src/utils/vine.ts +0 -2
  59. package/src/utils/vines/exists.ts +0 -41
  60. package/src/utils/vines/unique.ts +0 -41
package/CHANGELOG.md CHANGED
@@ -3,6 +3,57 @@ All notable changes to this project will be documented in this file.
3
3
 
4
4
  ---
5
5
 
6
+ ## [v0.1.41](https://github.com/crenata/bejibun-core/compare/v0.1.40...v0.1.41) - 2025-10-20
7
+
8
+ ### 🩹 Fixes
9
+
10
+ ### 📖 Changes
11
+ Chore :
12
+ - Refactor some codes to bun native
13
+ - Adding log when throwing exceptions
14
+
15
+ ### ❤️Contributors
16
+ - Havea Crenata ([@crenata](https://github.com/crenata))
17
+ - Ghulje ([@ghulje](https://github.com/ghulje))
18
+
19
+ **Full Changelog**: https://github.com/crenata/bejibun-core/blob/master/CHANGELOG.md
20
+
21
+ ---
22
+
23
+ ## [v0.1.40](https://github.com/crenata/bejibun-core/compare/v0.1.39...v0.1.40) - 2025-10-19
24
+
25
+ ### 🩹 Fixes
26
+ - Fix router any invalid route structure
27
+
28
+ ### 📖 Changes
29
+ What's New :
30
+ - Support commands from your root bejibun framework
31
+ - Support nested directory commands
32
+ - Adding router namespace
33
+
34
+ ### ❤️Contributors
35
+ - Havea Crenata ([@crenata](https://github.com/crenata))
36
+ - Ghulje ([@ghulje](https://github.com/ghulje))
37
+
38
+ **Full Changelog**: https://github.com/crenata/bejibun-core/blob/master/CHANGELOG.md
39
+
40
+ ---
41
+
42
+ ## [v0.1.39](https://github.com/crenata/bejibun-core/compare/v0.1.38...v0.1.39) - 2025-10-17
43
+
44
+ ### 🩹 Fixes
45
+ - Fix load database configuration on bootstrap & base model
46
+
47
+ ### 📖 Changes
48
+
49
+ ### ❤️Contributors
50
+ - Havea Crenata ([@crenata](https://github.com/crenata))
51
+ - Ghulje ([@ghulje](https://github.com/ghulje))
52
+
53
+ **Full Changelog**: https://github.com/crenata/bejibun-core/blob/master/CHANGELOG.md
54
+
55
+ ---
56
+
6
57
  ## [v0.1.38](https://github.com/crenata/bejibun-core/compare/v0.1.36...v0.1.38) - 2025-10-17
7
58
 
8
59
  ### 🩹 Fixes
@@ -1,8 +1,7 @@
1
1
  import { VineValidator } from "@vinejs/vine";
2
- import { BunRequest } from "bun";
3
2
  import Response from "../facades/Response";
4
3
  export default class BaseController {
5
- parse(request: BunRequest): Promise<Record<string, any>>;
4
+ parse(request: Bun.BunRequest): Promise<Record<string, any>>;
6
5
  get response(): typeof Response;
7
6
  validate(validator: VineValidator<any, Record<string, any> | undefined>, body: Record<string, any>): Promise<any>;
8
7
  private serialize;
@@ -1,3 +1,4 @@
1
+ import App from "@bejibun/app";
1
2
  import { defineValue, isEmpty } from "@bejibun/utils";
2
3
  import Str from "@bejibun/utils/facades/Str";
3
4
  import { DateTime } from "luxon";
@@ -25,8 +26,7 @@ export default class BaseModel extends Model {
25
26
  static QueryBuilder = BunQueryBuilder;
26
27
  static get namespace() {
27
28
  const filePath = fileURLToPath(import.meta.url);
28
- const appRoot = process.cwd();
29
- const rel = relative(appRoot, filePath);
29
+ const rel = relative(App.rootPath(), filePath);
30
30
  const withoutExt = rel.replace(/\.[tj]s$/, "");
31
31
  const namespaces = withoutExt.split(sep);
32
32
  namespaces.pop();
@@ -63,7 +63,7 @@ export default class BaseModel extends Model {
63
63
  static async findOrFail(id) {
64
64
  const result = await this.find(id);
65
65
  if (isEmpty(result))
66
- throw new ModelNotFoundException(`[ModelNotFoundException]: No query results for model [${this.namespace}] [${id}].`);
66
+ throw new ModelNotFoundException(`No query results for model [${this.namespace}] [${id}].`);
67
67
  return result;
68
68
  }
69
69
  }
@@ -8,11 +8,15 @@ export interface ResourceOptions {
8
8
  export default class RouterBuilder {
9
9
  private basePath;
10
10
  private middlewares;
11
+ private baseNamespace;
11
12
  prefix(basePath: string): RouterBuilder;
12
13
  middleware(...middlewares: Array<IMiddleware>): RouterBuilder;
14
+ namespace(baseNamespace: string): RouterBuilder;
13
15
  group(routes: RouterGroup | Array<RouterGroup>): RouterGroup;
14
16
  resources(controller: Record<string, HandlerType>, options?: ResourceOptions): RouterGroup;
15
17
  buildSingle(method: HttpMethodEnum, path: string, handler: string | HandlerType): RouterGroup;
18
+ match(methods: Array<HttpMethodEnum>, path: string, handler: string | HandlerType): RouterGroup;
19
+ any(path: string, handler: string | HandlerType): RouterGroup;
16
20
  private joinPaths;
17
21
  private resolveControllerString;
18
22
  private resolveIncludedActions;
@@ -1,9 +1,13 @@
1
+ import App from "@bejibun/app";
1
2
  import { isEmpty } from "@bejibun/utils";
3
+ import HttpMethodEnum from "@bejibun/utils/enums/HttpMethodEnum";
4
+ import Enum from "@bejibun/utils/facades/Enum";
2
5
  import path from "path";
3
6
  import RouterInvalidException from "../exceptions/RouterInvalidException";
4
7
  export default class RouterBuilder {
5
8
  basePath = "";
6
9
  middlewares = [];
10
+ baseNamespace = "app/controllers";
7
11
  prefix(basePath) {
8
12
  this.basePath = basePath;
9
13
  return this;
@@ -12,6 +16,10 @@ export default class RouterBuilder {
12
16
  this.middlewares.push(...middlewares);
13
17
  return this;
14
18
  }
19
+ namespace(baseNamespace) {
20
+ this.baseNamespace = baseNamespace;
21
+ return this;
22
+ }
15
23
  group(routes) {
16
24
  const routeList = Array.isArray(routes) ? routes : [routes];
17
25
  const newRoutes = {};
@@ -77,18 +85,33 @@ export default class RouterBuilder {
77
85
  }
78
86
  };
79
87
  }
88
+ match(methods, path, handler) {
89
+ const routeMap = {};
90
+ for (const method of methods) {
91
+ const single = this.buildSingle(method, path, handler);
92
+ const fullPath = Object.keys(single)[0];
93
+ const handlers = single[fullPath];
94
+ if (isEmpty(routeMap[fullPath]))
95
+ routeMap[fullPath] = {};
96
+ Object.assign(routeMap[fullPath], handlers);
97
+ }
98
+ return routeMap;
99
+ }
100
+ any(path, handler) {
101
+ return this.match(Enum.setEnums(HttpMethodEnum).toArray().map((value) => value.value), path, handler);
102
+ }
80
103
  joinPaths(base, path) {
81
104
  base = base.replace(/\/+$/, "");
82
105
  path = path.replace(/^\/+/, "");
83
- return "/" + [base, path].filter(Boolean).join("/");
106
+ return `/${[base, path].filter(Boolean).join("/")}`;
84
107
  }
85
108
  resolveControllerString(definition) {
86
109
  const [controllerName, methodName] = definition.split("@");
87
110
  if (isEmpty(controllerName) || isEmpty(methodName)) {
88
- throw new RouterInvalidException(`[RouterInvalidException]: Invalid router controller definition: ${definition}.`);
111
+ throw new RouterInvalidException(`Invalid router controller definition: ${definition}.`);
89
112
  }
90
- const controllerPath = path.resolve(process.cwd(), "app/controllers");
91
- const location = `${controllerPath}/${controllerName}`;
113
+ const controllerPath = path.resolve(App.rootPath(), this.baseNamespace);
114
+ const location = Bun.resolveSync(`${controllerName}.ts`, controllerPath);
92
115
  let ControllerClass;
93
116
  try {
94
117
  ControllerClass = require(location).default;
@@ -99,17 +122,17 @@ export default class RouterBuilder {
99
122
  const ESMController = module.default;
100
123
  const instance = new ESMController();
101
124
  if (typeof instance[methodName] !== "function") {
102
- throw new RouterInvalidException(`[RouterInvalidException]: Method "${methodName}" not found in ${controllerName}.`);
125
+ throw new RouterInvalidException(`Method "${methodName}" not found in ${controllerName}.`);
103
126
  }
104
127
  return instance[methodName](...args);
105
128
  };
106
129
  }
107
130
  if (isEmpty(ControllerClass)) {
108
- throw new RouterInvalidException(`[RouterInvalidException]: Controller not found: ${controllerName}.`);
131
+ throw new RouterInvalidException(`Controller not found: ${controllerName}.`);
109
132
  }
110
133
  const instance = new ControllerClass();
111
134
  if (typeof instance[methodName] !== "function") {
112
- throw new RouterInvalidException(`[RouterInvalidException]: Method "${methodName}" not found in ${controllerName}.`);
135
+ throw new RouterInvalidException(`Method "${methodName}" not found in ${controllerName}.`);
113
136
  }
114
137
  return instance[methodName].bind(instance);
115
138
  }
@@ -1,4 +1,5 @@
1
1
  import type { Command } from "commander";
2
2
  export default class Kernel {
3
3
  static registerCommands(program: Command): void;
4
+ private static commands;
4
5
  }
@@ -1,24 +1,20 @@
1
+ import App from "@bejibun/app";
1
2
  import { defineValue, isEmpty } from "@bejibun/utils";
2
3
  import { readdirSync } from "fs";
3
4
  import path from "path";
4
5
  export default class Kernel {
5
6
  static registerCommands(program) {
6
- const commandsDir = path.resolve(__dirname);
7
- const files = readdirSync(commandsDir).filter((file) => {
8
- return (/\.(m?js|ts)$/.test(file) &&
9
- !file.endsWith(".d.ts") &&
10
- !file.includes("Kernel"));
11
- });
7
+ const commandsDirectoryCore = path.resolve(__dirname);
8
+ const files = this.commands(commandsDirectoryCore)
9
+ .concat(this.commands(App.commandsPath()));
12
10
  for (const file of files) {
13
- const modulePath = path.join(commandsDir, file);
14
- const { default: CommandClass } = require(modulePath);
11
+ const { default: CommandClass } = require(file);
15
12
  const instance = new CommandClass();
16
13
  if (isEmpty(instance.$signature) || typeof instance.handle !== "function")
17
14
  continue;
18
15
  const cmd = program
19
16
  .command(instance.$signature)
20
- .description(defineValue(instance.$description, ""))
21
- .action(instance.handle);
17
+ .description(defineValue(instance.$description, ""));
22
18
  if (Array.isArray(instance.$options)) {
23
19
  for (const option of instance.$options) {
24
20
  cmd.option(...option);
@@ -30,10 +26,29 @@ export default class Kernel {
30
26
  }
31
27
  }
32
28
  cmd.action(async (...args) => {
33
- const lastArg = args[args.length - 1];
34
- const options = defineValue(lastArg, {});
35
- await instance.handle(options, args.slice(0, -1));
29
+ const commandObj = args[args.length - 1];
30
+ const options = typeof commandObj.opts === "function" ? commandObj.opts() : commandObj;
31
+ const positionalArgs = args.slice(0, -1);
32
+ await instance.handle(options, positionalArgs);
36
33
  });
37
34
  }
38
35
  }
36
+ static commands(directory) {
37
+ const entries = readdirSync(directory, {
38
+ withFileTypes: true
39
+ });
40
+ const files = [];
41
+ for (const entry of entries) {
42
+ const fullPath = path.join(directory, entry.name);
43
+ if (entry.isDirectory()) {
44
+ files.push(...this.commands(fullPath));
45
+ }
46
+ else if (/\.(m?js|ts)$/.test(entry.name) &&
47
+ !entry.name.endsWith(".d.ts") &&
48
+ !entry.name.includes("Kernel")) {
49
+ files.push(fullPath);
50
+ }
51
+ }
52
+ return files;
53
+ }
39
54
  }
@@ -14,9 +14,9 @@ export default class DbSeedCommand {
14
14
  /**
15
15
  * The options or optional flag of the console command.
16
16
  *
17
- * @var $options Array<Array<string>>
17
+ * @var $options Array<Array<any>>
18
18
  */
19
- protected $options: Array<Array<string>>;
19
+ protected $options: Array<Array<any>>;
20
20
  /**
21
21
  * The arguments of the console command.
22
22
  *
@@ -1,7 +1,7 @@
1
1
  import Chalk from "@bejibun/logger/facades/Chalk";
2
2
  import ora from "ora";
3
3
  import path from "path";
4
- import { initDatabase } from "../config/database";
4
+ import { initDatabase } from "../../config/database";
5
5
  export default class DbSeedCommand {
6
6
  /**
7
7
  * The name and signature of the console command.
@@ -18,7 +18,7 @@ export default class DbSeedCommand {
18
18
  /**
19
19
  * The options or optional flag of the console command.
20
20
  *
21
- * @var $options Array<Array<string>>
21
+ * @var $options Array<Array<any>>
22
22
  */
23
23
  $options = [];
24
24
  /**
@@ -0,0 +1,27 @@
1
+ export default class MaintenanceDownCommand {
2
+ /**
3
+ * The name and signature of the console command.
4
+ *
5
+ * @var $signature string
6
+ */
7
+ protected $signature: string;
8
+ /**
9
+ * The console command description.
10
+ *
11
+ * @var $description string
12
+ */
13
+ protected $description: string;
14
+ /**
15
+ * The options or optional flag of the console command.
16
+ *
17
+ * @var $options Array<Array<any>>
18
+ */
19
+ protected $options: Array<Array<any>>;
20
+ /**
21
+ * The arguments of the console command.
22
+ *
23
+ * @var $arguments Array<Array<string>>
24
+ */
25
+ protected $arguments: Array<Array<string>>;
26
+ handle(options: any, args: Array<string>): Promise<void>;
27
+ }
@@ -0,0 +1,40 @@
1
+ import App from "@bejibun/app";
2
+ import Logger from "@bejibun/logger";
3
+ import { DateTime } from "luxon";
4
+ export default class MaintenanceDownCommand {
5
+ /**
6
+ * The name and signature of the console command.
7
+ *
8
+ * @var $signature string
9
+ */
10
+ $signature = "maintenance:down";
11
+ /**
12
+ * The console command description.
13
+ *
14
+ * @var $description string
15
+ */
16
+ $description = "Turn app into maintenance mode";
17
+ /**
18
+ * The options or optional flag of the console command.
19
+ *
20
+ * @var $options Array<Array<any>>
21
+ */
22
+ $options = [
23
+ ["-a, --allows <ips>", "Whitelist IPs from accessing application in maintenance mode. e.g. --allows=127.0.0.1,127.0.0.2", (value) => value.split(","), []]
24
+ ];
25
+ /**
26
+ * The arguments of the console command.
27
+ *
28
+ * @var $arguments Array<Array<string>>
29
+ */
30
+ $arguments = [];
31
+ async handle(options, args) {
32
+ await Bun.write(App.storagePath("framework/maintenance.down.json"), JSON.stringify({
33
+ message: "🚧 We're doing maintenance. Please check back soon.",
34
+ status: 503,
35
+ allows: options.allows,
36
+ unix: Math.floor(DateTime.now().toSeconds())
37
+ }, null, 2));
38
+ Logger.setContext("APP").info("Application turned into maintenance mode.");
39
+ }
40
+ }
@@ -14,9 +14,9 @@ export default class MigrateFreshCommand {
14
14
  /**
15
15
  * The options or optional flag of the console command.
16
16
  *
17
- * @var $options Array<Array<string>>
17
+ * @var $options Array<Array<any>>
18
18
  */
19
- protected $options: Array<Array<string>>;
19
+ protected $options: Array<Array<any>>;
20
20
  /**
21
21
  * The arguments of the console command.
22
22
  *
@@ -1,7 +1,8 @@
1
+ import Logger from "@bejibun/logger";
1
2
  import Chalk from "@bejibun/logger/facades/Chalk";
2
3
  import { ask, isNotEmpty } from "@bejibun/utils";
3
4
  import ora from "ora";
4
- import { initDatabase } from "../config/database";
5
+ import { initDatabase } from "../../config/database";
5
6
  export default class MigrateFreshCommand {
6
7
  /**
7
8
  * The name and signature of the console command.
@@ -18,10 +19,10 @@ export default class MigrateFreshCommand {
18
19
  /**
19
20
  * The options or optional flag of the console command.
20
21
  *
21
- * @var $options Array<Array<string>>
22
+ * @var $options Array<Array<any>>
22
23
  */
23
24
  $options = [
24
- ["-f, --force", "Skip command confirmation."]
25
+ ["-f, --force", "Skip command confirmation"]
25
26
  ];
26
27
  /**
27
28
  * The arguments of the console command.
@@ -40,7 +41,7 @@ export default class MigrateFreshCommand {
40
41
  .show());
41
42
  if (confirm.toUpperCase() === "Y") {
42
43
  if (!bypass)
43
- console.log();
44
+ Logger.empty();
44
45
  const spinner = ora(Chalk.setValue("Rollback...")
45
46
  .info()
46
47
  .show()).start();
@@ -14,9 +14,9 @@ export default class MigrateLatestCommand {
14
14
  /**
15
15
  * The options or optional flag of the console command.
16
16
  *
17
- * @var $options Array<Array<string>>
17
+ * @var $options Array<Array<any>>
18
18
  */
19
- protected $options: Array<Array<string>>;
19
+ protected $options: Array<Array<any>>;
20
20
  /**
21
21
  * The arguments of the console command.
22
22
  *
@@ -1,6 +1,6 @@
1
1
  import Chalk from "@bejibun/logger/facades/Chalk";
2
2
  import ora from "ora";
3
- import { initDatabase } from "../config/database";
3
+ import { initDatabase } from "../../config/database";
4
4
  export default class MigrateLatestCommand {
5
5
  /**
6
6
  * The name and signature of the console command.
@@ -17,7 +17,7 @@ export default class MigrateLatestCommand {
17
17
  /**
18
18
  * The options or optional flag of the console command.
19
19
  *
20
- * @var $options Array<Array<string>>
20
+ * @var $options Array<Array<any>>
21
21
  */
22
22
  $options = [];
23
23
  /**
@@ -14,9 +14,9 @@ export default class MigrateRollbackCommand {
14
14
  /**
15
15
  * The options or optional flag of the console command.
16
16
  *
17
- * @var $options Array<Array<string>>
17
+ * @var $options Array<Array<any>>
18
18
  */
19
- protected $options: Array<Array<string>>;
19
+ protected $options: Array<Array<any>>;
20
20
  /**
21
21
  * The arguments of the console command.
22
22
  *
@@ -1,7 +1,8 @@
1
+ import Logger from "@bejibun/logger";
1
2
  import Chalk from "@bejibun/logger/facades/Chalk";
2
3
  import { ask, isNotEmpty } from "@bejibun/utils";
3
4
  import ora from "ora";
4
- import { initDatabase } from "../config/database";
5
+ import { initDatabase } from "../../config/database";
5
6
  export default class MigrateRollbackCommand {
6
7
  /**
7
8
  * The name and signature of the console command.
@@ -18,10 +19,10 @@ export default class MigrateRollbackCommand {
18
19
  /**
19
20
  * The options or optional flag of the console command.
20
21
  *
21
- * @var $options Array<Array<string>>
22
+ * @var $options Array<Array<any>>
22
23
  */
23
24
  $options = [
24
- ["-f, --force", "Skip command confirmation."]
25
+ ["-f, --force", "Skip command confirmation"]
25
26
  ];
26
27
  /**
27
28
  * The arguments of the console command.
@@ -40,7 +41,7 @@ export default class MigrateRollbackCommand {
40
41
  .show());
41
42
  if (confirm.toUpperCase() === "Y") {
42
43
  if (!bypass)
43
- console.log();
44
+ Logger.empty();
44
45
  const spinner = ora(Chalk.setValue("Rollback...")
45
46
  .info()
46
47
  .show()).start();
@@ -14,9 +14,9 @@ export default class MigrateStatusCommand {
14
14
  /**
15
15
  * The options or optional flag of the console command.
16
16
  *
17
- * @var $options Array<Array<string>>
17
+ * @var $options Array<Array<any>>
18
18
  */
19
- protected $options: Array<Array<string>>;
19
+ protected $options: Array<Array<any>>;
20
20
  /**
21
21
  * The arguments of the console command.
22
22
  *
@@ -1,6 +1,7 @@
1
+ import Logger from "@bejibun/logger";
1
2
  import Chalk from "@bejibun/logger/facades/Chalk";
2
3
  import ora from "ora";
3
- import { initDatabase } from "../config/database";
4
+ import { initDatabase } from "../../config/database";
4
5
  export default class MigrateStatusCommand {
5
6
  /**
6
7
  * The name and signature of the console command.
@@ -17,10 +18,10 @@ export default class MigrateStatusCommand {
17
18
  /**
18
19
  * The options or optional flag of the console command.
19
20
  *
20
- * @var $options Array<Array<string>>
21
+ * @var $options Array<Array<any>>
21
22
  */
22
23
  $options = [
23
- ["-f, --force", "Skip command confirmation."]
24
+ ["-f, --force", "Skip command confirmation"]
24
25
  ];
25
26
  /**
26
27
  * The arguments of the console command.
@@ -40,7 +41,7 @@ export default class MigrateStatusCommand {
40
41
  completed.forEach((migration) => spinner.succeed(migration.name));
41
42
  else
42
43
  spinner.succeed("No migrations were completed.");
43
- console.log();
44
+ Logger.empty();
44
45
  spinner.succeed("Pending Migrations :");
45
46
  if (pending.length > 0)
46
47
  pending.forEach((migration) => spinner.succeed(migration.file));
@@ -1,6 +1,6 @@
1
+ import App from "@bejibun/app";
1
2
  import fs from "fs";
2
3
  import knex from "knex";
3
- import path from "path";
4
4
  const config = {
5
5
  client: "pg",
6
6
  connection: {
@@ -25,7 +25,7 @@ const config = {
25
25
  }
26
26
  };
27
27
  export const initDatabase = () => {
28
- const configPath = path.resolve(process.cwd(), "config/database.ts");
28
+ const configPath = App.configPath("database.ts");
29
29
  let _config;
30
30
  if (fs.existsSync(configPath))
31
31
  _config = require(configPath).default;
@@ -1,3 +1,4 @@
1
+ import Logger from "@bejibun/logger";
1
2
  import { defineValue } from "@bejibun/utils";
2
3
  export default class ModelNotFoundException extends Error {
3
4
  code;
@@ -5,6 +6,7 @@ export default class ModelNotFoundException extends Error {
5
6
  super(message);
6
7
  this.name = "ModelNotFoundException";
7
8
  this.code = defineValue(code, 404);
9
+ Logger.setContext(this.name).error(this.message).trace(this.stack);
8
10
  if (Error.captureStackTrace) {
9
11
  Error.captureStackTrace(this, ModelNotFoundException);
10
12
  }
@@ -1,3 +1,4 @@
1
+ import Logger from "@bejibun/logger";
1
2
  import { defineValue } from "@bejibun/utils";
2
3
  export default class RouterInvalidException extends Error {
3
4
  code;
@@ -5,6 +6,7 @@ export default class RouterInvalidException extends Error {
5
6
  super(message);
6
7
  this.name = "RouterInvalidException";
7
8
  this.code = defineValue(code, 500);
9
+ Logger.setContext(this.name).error(this.message).trace(this.stack);
8
10
  if (Error.captureStackTrace) {
9
11
  Error.captureStackTrace(this, RouterInvalidException);
10
12
  }
@@ -1,3 +1,4 @@
1
+ import Logger from "@bejibun/logger";
1
2
  import { defineValue } from "@bejibun/utils";
2
3
  export default class ValidatorException extends Error {
3
4
  code;
@@ -5,6 +6,7 @@ export default class ValidatorException extends Error {
5
6
  super(message);
6
7
  this.name = "ValidatorException";
7
8
  this.code = defineValue(code, 422);
9
+ Logger.setContext(this.name).error(this.message).trace(this.stack);
8
10
  if (Error.captureStackTrace) {
9
11
  Error.captureStackTrace(this, ValidatorException);
10
12
  }
@@ -5,6 +5,7 @@ import RouterBuilder, { ResourceOptions } from "../builders/RouterBuilder";
5
5
  export default class Router {
6
6
  static prefix(basePath: string): RouterBuilder;
7
7
  static middleware(...middlewares: Array<IMiddleware>): RouterBuilder;
8
+ static namespace(baseNamespace: string): RouterBuilder;
8
9
  static resources(controller: Record<string, HandlerType>, options?: ResourceOptions): RouterGroup;
9
10
  static group(routes: RouterGroup, prefix?: string, middlewares?: Array<IMiddleware>): RouterGroup;
10
11
  static connect(path: string, handler: string | HandlerType): RouterGroup;
package/facades/Router.js CHANGED
@@ -1,6 +1,4 @@
1
- import { isEmpty } from "@bejibun/utils";
2
1
  import HttpMethodEnum from "@bejibun/utils/enums/HttpMethodEnum";
3
- import Enum from "@bejibun/utils/facades/Enum";
4
2
  import RouterBuilder from "../builders/RouterBuilder";
5
3
  export default class Router {
6
4
  static prefix(basePath) {
@@ -9,6 +7,9 @@ export default class Router {
9
7
  static middleware(...middlewares) {
10
8
  return new RouterBuilder().middleware(...middlewares);
11
9
  }
10
+ static namespace(baseNamespace) {
11
+ return new RouterBuilder().namespace(baseNamespace);
12
+ }
12
13
  static resources(controller, options) {
13
14
  return new RouterBuilder().resources(controller, options);
14
15
  }
@@ -48,19 +49,9 @@ export default class Router {
48
49
  return new RouterBuilder().buildSingle(HttpMethodEnum.Trace, path, handler);
49
50
  }
50
51
  static match(methods, path, handler) {
51
- const builder = new RouterBuilder();
52
- const routeMap = {};
53
- for (const method of methods) {
54
- const single = builder.buildSingle(method, path, handler);
55
- const fullPath = Object.keys(single)[0];
56
- const handlers = single[fullPath];
57
- if (isEmpty(routeMap[fullPath]))
58
- routeMap[fullPath] = {};
59
- Object.assign(routeMap[fullPath], handlers);
60
- }
61
- return routeMap;
52
+ return new RouterBuilder().match(methods, path, handler);
62
53
  }
63
54
  static any(path, handler) {
64
- return this.match(Enum.setEnums(HttpMethodEnum).toArray(), path, handler);
55
+ return new RouterBuilder().any(path, handler);
65
56
  }
66
57
  }