@bejibun/core 0.1.39 → 0.1.40

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 (56) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/bases/BaseController.d.ts +1 -1
  3. package/builders/RouterBuilder.d.ts +4 -0
  4. package/builders/RouterBuilder.js +24 -2
  5. package/bun.lock +12 -5
  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/facades/Router.d.ts +1 -0
  22. package/facades/Router.js +5 -14
  23. package/package.json +4 -3
  24. package/types/router.d.ts +1 -1
  25. package/src/ace.ts +0 -22
  26. package/src/bases/BaseController.ts +0 -139
  27. package/src/bases/BaseModel.ts +0 -108
  28. package/src/bases/BaseValidator.ts +0 -8
  29. package/src/bases/index.ts +0 -3
  30. package/src/bootstrap.ts +0 -5
  31. package/src/builders/ResponseBuilder.ts +0 -54
  32. package/src/builders/RouterBuilder.ts +0 -173
  33. package/src/commands/DbSeedCommand.ts +0 -57
  34. package/src/commands/Kernel.ts +0 -49
  35. package/src/commands/MigrateFreshCommand.ts +0 -76
  36. package/src/commands/MigrateLatestCommand.ts +0 -56
  37. package/src/commands/MigrateRollbackCommand.ts +0 -72
  38. package/src/commands/MigrateStatusCommand.ts +0 -64
  39. package/src/config/database.ts +0 -41
  40. package/src/exceptions/ModelNotFoundException.ts +0 -15
  41. package/src/exceptions/RouterInvalidException.ts +0 -15
  42. package/src/exceptions/ValidatorException.ts +0 -15
  43. package/src/exceptions/index.ts +0 -3
  44. package/src/facades/Response.ts +0 -15
  45. package/src/facades/Router.ts +0 -89
  46. package/src/facades/SoftDeletes.ts +0 -66
  47. package/src/facades/index.ts +0 -3
  48. package/src/index.ts +0 -5
  49. package/src/types/index.d.ts +0 -4
  50. package/src/types/middleware.d.ts +0 -7
  51. package/src/types/router.d.ts +0 -5
  52. package/src/types/validator.d.ts +0 -3
  53. package/src/types/vine.d.ts +0 -13
  54. package/src/utils/vine.ts +0 -2
  55. package/src/utils/vines/exists.ts +0 -41
  56. package/src/utils/vines/unique.ts +0 -41
package/CHANGELOG.md CHANGED
@@ -3,6 +3,40 @@ All notable changes to this project will be documented in this file.
3
3
 
4
4
  ---
5
5
 
6
+ ## [v0.1.40](https://github.com/crenata/bejibun-core/compare/v0.1.39...v0.1.40) - 2025-10-19
7
+
8
+ ### 🩹 Fixes
9
+ - Fix router any invalid route structure
10
+
11
+ ### 📖 Changes
12
+ What's New :
13
+ - Support commands from your root bejibun framework
14
+ - Support nested directory commands
15
+ - Adding router namespace
16
+
17
+ ### ❤️Contributors
18
+ - Havea Crenata ([@crenata](https://github.com/crenata))
19
+ - Ghulje ([@ghulje](https://github.com/ghulje))
20
+
21
+ **Full Changelog**: https://github.com/crenata/bejibun-core/blob/master/CHANGELOG.md
22
+
23
+ ---
24
+
25
+ ## [v0.1.39](https://github.com/crenata/bejibun-core/compare/v0.1.38...v0.1.39) - 2025-10-17
26
+
27
+ ### 🩹 Fixes
28
+ - Fix load database configuration on bootstrap & base model
29
+
30
+ ### 📖 Changes
31
+
32
+ ### ❤️Contributors
33
+ - Havea Crenata ([@crenata](https://github.com/crenata))
34
+ - Ghulje ([@ghulje](https://github.com/ghulje))
35
+
36
+ **Full Changelog**: https://github.com/crenata/bejibun-core/blob/master/CHANGELOG.md
37
+
38
+ ---
39
+
6
40
  ## [v0.1.38](https://github.com/crenata/bejibun-core/compare/v0.1.36...v0.1.38) - 2025-10-17
7
41
 
8
42
  ### 🩹 Fixes
@@ -1,5 +1,5 @@
1
+ import type { BunRequest } from "bun";
1
2
  import { VineValidator } from "@vinejs/vine";
2
- import { BunRequest } from "bun";
3
3
  import Response from "../facades/Response";
4
4
  export default class BaseController {
5
5
  parse(request: BunRequest): Promise<Record<string, any>>;
@@ -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,12 @@
1
1
  import { isEmpty } from "@bejibun/utils";
2
+ import HttpMethodEnum from "@bejibun/utils/enums/HttpMethodEnum";
3
+ import Enum from "@bejibun/utils/facades/Enum";
2
4
  import path from "path";
3
5
  import RouterInvalidException from "../exceptions/RouterInvalidException";
4
6
  export default class RouterBuilder {
5
7
  basePath = "";
6
8
  middlewares = [];
9
+ baseNamespace = "app/controllers";
7
10
  prefix(basePath) {
8
11
  this.basePath = basePath;
9
12
  return this;
@@ -12,6 +15,10 @@ export default class RouterBuilder {
12
15
  this.middlewares.push(...middlewares);
13
16
  return this;
14
17
  }
18
+ namespace(baseNamespace) {
19
+ this.baseNamespace = baseNamespace;
20
+ return this;
21
+ }
15
22
  group(routes) {
16
23
  const routeList = Array.isArray(routes) ? routes : [routes];
17
24
  const newRoutes = {};
@@ -77,17 +84,32 @@ export default class RouterBuilder {
77
84
  }
78
85
  };
79
86
  }
87
+ match(methods, path, handler) {
88
+ const routeMap = {};
89
+ for (const method of methods) {
90
+ const single = this.buildSingle(method, path, handler);
91
+ const fullPath = Object.keys(single)[0];
92
+ const handlers = single[fullPath];
93
+ if (isEmpty(routeMap[fullPath]))
94
+ routeMap[fullPath] = {};
95
+ Object.assign(routeMap[fullPath], handlers);
96
+ }
97
+ return routeMap;
98
+ }
99
+ any(path, handler) {
100
+ return this.match(Enum.setEnums(HttpMethodEnum).toArray().map((value) => value.value), path, handler);
101
+ }
80
102
  joinPaths(base, path) {
81
103
  base = base.replace(/\/+$/, "");
82
104
  path = path.replace(/^\/+/, "");
83
- return "/" + [base, path].filter(Boolean).join("/");
105
+ return `/${[base, path].filter(Boolean).join("/")}`;
84
106
  }
85
107
  resolveControllerString(definition) {
86
108
  const [controllerName, methodName] = definition.split("@");
87
109
  if (isEmpty(controllerName) || isEmpty(methodName)) {
88
110
  throw new RouterInvalidException(`[RouterInvalidException]: Invalid router controller definition: ${definition}.`);
89
111
  }
90
- const controllerPath = path.resolve(process.cwd(), "app/controllers");
112
+ const controllerPath = path.resolve(process.cwd(), this.baseNamespace);
91
113
  const location = `${controllerPath}/${controllerName}`;
92
114
  let ControllerClass;
93
115
  try {
package/bun.lock CHANGED
@@ -4,9 +4,10 @@
4
4
  "": {
5
5
  "name": "@bejibun/core",
6
6
  "dependencies": {
7
- "@bejibun/cors": "^0.1.0",
8
- "@bejibun/logger": "^0.1.13",
9
- "@bejibun/utils": "^0.1.1",
7
+ "@bejibun/app": "^0.1.11",
8
+ "@bejibun/cors": "^0.1.1",
9
+ "@bejibun/logger": "^0.1.16",
10
+ "@bejibun/utils": "^0.1.13",
10
11
  "@vinejs/vine": "^3.0.1",
11
12
  "commander": "^14.0.1",
12
13
  "knex": "^3.1.0",
@@ -23,11 +24,13 @@
23
24
  },
24
25
  },
25
26
  "packages": {
27
+ "@bejibun/app": ["@bejibun/app@0.1.11", "", { "dependencies": { "@bejibun/utils": "^0.1.1" } }, "sha512-UjhG3KuBhswCXK46vnw+oNDdeAbA9CcC5h3MMBPEC5E+lBkoep82NrGbwUqQTC6uCVZUfeCfnMWteAsiQJXYDQ=="],
28
+
26
29
  "@bejibun/cors": ["@bejibun/cors@0.1.1", "", { "dependencies": { "@bejibun/utils": "^0.1.0" } }, "sha512-9riA6+yZbCyS1KSB+DnUqF7EevecqbwwMWlJsq29Cqq15fX7YJJr6T/GIt6t905dlAQkbMOloPUp1mpKCKBhFg=="],
27
30
 
28
- "@bejibun/logger": ["@bejibun/logger@0.1.14", "", { "dependencies": { "@bejibun/utils": "^0.1.0", "chalk": "^5.6.2", "luxon": "^3.7.2" } }, "sha512-Y0rwHMUaJpKE2G3ZRsXKlpwKPQAVlqut44laFJfltTUS7vMZbnKMuWYdfaCp3rX6DCUNxeaChX+8Jte3tYJ50g=="],
31
+ "@bejibun/logger": ["@bejibun/logger@0.1.16", "", { "dependencies": { "@bejibun/utils": "^0.1.1", "chalk": "^5.6.2", "luxon": "^3.7.2" } }, "sha512-K6OhJbEatMBSU4SzBcAtmVF3cHos4s52bua0YUZkwtcuiq9CA4A984AXDW3E3e5taqPck7/M9odW7dT4zD8Qtw=="],
29
32
 
30
- "@bejibun/utils": ["@bejibun/utils@0.1.1", "", {}, "sha512-8TofYYN+EhPQgNOkyovMaAamRqbK/PisrAxjspXFlqVLj8bnmdOsZjosTpNXesLGIftn4rKkaFsfaafD//31Hg=="],
33
+ "@bejibun/utils": ["@bejibun/utils@0.1.13", "", {}, "sha512-dB8jo6sxeiGBEFd9NVZQKWC76yNCg0GYvWGKYhnjznuJdmGCQYS2g7U8SeB2pkGZkT06N+klSkiFbXp7XTKeeQ=="],
31
34
 
32
35
  "@nodelib/fs.scandir": ["@nodelib/fs.scandir@2.1.5", "", { "dependencies": { "@nodelib/fs.stat": "2.0.5", "run-parallel": "^1.1.9" } }, "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g=="],
33
36
 
@@ -257,6 +260,10 @@
257
260
 
258
261
  "yoctocolors": ["yoctocolors@2.1.2", "", {}, "sha512-CzhO+pFNo8ajLM2d2IW/R93ipy99LWjtwblvC1RsoSUMZgyLbYFr221TnSNT7GjGdYui6P459mw9JH/g/zW2ug=="],
259
262
 
263
+ "@bejibun/cors/@bejibun/utils": ["@bejibun/utils@0.1.1", "", {}, "sha512-8TofYYN+EhPQgNOkyovMaAamRqbK/PisrAxjspXFlqVLj8bnmdOsZjosTpNXesLGIftn4rKkaFsfaafD//31Hg=="],
264
+
265
+ "@bejibun/logger/@bejibun/utils": ["@bejibun/utils@0.1.1", "", {}, "sha512-8TofYYN+EhPQgNOkyovMaAamRqbK/PisrAxjspXFlqVLj8bnmdOsZjosTpNXesLGIftn4rKkaFsfaafD//31Hg=="],
266
+
260
267
  "knex/commander": ["commander@10.0.1", "", {}, "sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug=="],
261
268
 
262
269
  "pg/pg-connection-string": ["pg-connection-string@2.9.1", "", {}, "sha512-nkc6NpDcvPVpZXxrreI/FOtX3XemeLl8E0qFr6F2Lrm/I8WOnaWNhIPK2Z7OHpw7gh5XJThi6j6ppgNoaT1w4w=="],
@@ -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/facades/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;
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bejibun/core",
3
- "version": "0.1.39",
3
+ "version": "0.1.40",
4
4
  "author": "Havea Crenata <havea.crenata@gmail.com>",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,9 +9,10 @@
9
9
  "main": "index.js",
10
10
  "module": "index.js",
11
11
  "dependencies": {
12
+ "@bejibun/app": "^0.1.11",
12
13
  "@bejibun/cors": "^0.1.1",
13
- "@bejibun/logger": "^0.1.14",
14
- "@bejibun/utils": "^0.1.1",
14
+ "@bejibun/logger": "^0.1.16",
15
+ "@bejibun/utils": "^0.1.13",
15
16
  "@vinejs/vine": "^3.0.1",
16
17
  "commander": "^14.0.1",
17
18
  "knex": "^3.1.0",
package/types/router.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import {BunRequest} from "bun";
1
+ import type {BunRequest} from "bun";
2
2
 
3
3
  export type HandlerType = (request: BunRequest) => Promise<Response>;
4
4
  export type RouterGroup = Record<string, Record<string, HandlerType>>;
package/src/ace.ts DELETED
@@ -1,22 +0,0 @@
1
- import Str from "@bejibun/utils/facades/Str";
2
- import {program} from "commander";
3
- import os from "os";
4
- import Kernel from "@/commands/Kernel";
5
- import {version} from "package.json";
6
-
7
- const commandExec = "ace";
8
-
9
- program
10
- .name(commandExec)
11
- .version(version, "-v, --version", "Show the current version")
12
- .description(`${Str.toPascalCase(commandExec)} for your commander${os.EOL}Author: Havea Crenata <havea.crenata@gmail.com>`)
13
- .addHelpText("after", [
14
- `${os.EOL}Examples:`,
15
- `$ bun ${commandExec} --help`,
16
- `$ bun ${commandExec} --version`,
17
- `$ bun ${commandExec} migrate:latest`
18
- ].join(`${os.EOL} `));
19
-
20
- Kernel.registerCommands(program);
21
-
22
- program.parse();