jcc-express-mvc 1.3.1 → 1.3.2

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 (46) hide show
  1. package/cli.js +17 -1
  2. package/index.d.ts +1 -1
  3. package/index.d.ts.map +1 -1
  4. package/index.js +26 -20
  5. package/lib/App.js +16 -13
  6. package/lib/Auth/AuthMiddleware.js +6 -3
  7. package/lib/Auth/index.js +10 -5
  8. package/lib/Command-Line/NodeArtisanCommand.js +21 -14
  9. package/lib/Command-Line/command.js +34 -29
  10. package/lib/Command-Line/files/Controller.js +3 -1
  11. package/lib/Command-Line/files/Migration.js +3 -1
  12. package/lib/Command-Line/files/Models.js +3 -1
  13. package/lib/Command-Line/files/Request.js +3 -1
  14. package/lib/Command-Line/files/ResourcesController.js +3 -1
  15. package/lib/Command-Line/utils.js +5 -1
  16. package/lib/Config/Config.d.ts +2 -2
  17. package/lib/Config/Config.d.ts.map +1 -1
  18. package/lib/Config/Config.js +10 -4
  19. package/lib/Error/AppError.js +5 -1
  20. package/lib/Error/AppErrorHandler.js +11 -7
  21. package/lib/Error/Constants/error.js +45 -42
  22. package/lib/Error/Constants/index.js +6 -3
  23. package/lib/Error/DisplayErrorCode.js +11 -4
  24. package/lib/Error/ErrorHigtlig.js +10 -3
  25. package/lib/HttpKernel/HttpKernel.js +3 -1
  26. package/lib/Interface/index.js +2 -1
  27. package/lib/Middlewares/index.js +30 -23
  28. package/lib/Middlewares/isLogin.js +5 -1
  29. package/lib/Passport/config.js +17 -10
  30. package/lib/Request/FormRequest.js +5 -1
  31. package/lib/Request/request.js +10 -6
  32. package/lib/Response/index.js +5 -1
  33. package/lib/Routes/RouteBuilder.js +14 -10
  34. package/lib/Routes/Router.js +9 -5
  35. package/lib/Server/index.js +15 -8
  36. package/lib/Services/ServiceContainer.js +7 -4
  37. package/lib/Services/ServiceProvider.js +5 -1
  38. package/lib/Templating-engine/engineHelper.js +13 -6
  39. package/lib/Templating-engine/expressions.js +5 -1
  40. package/lib/Templating-engine/index.js +14 -8
  41. package/lib/Type/index.js +2 -1
  42. package/lib/Validation/index.js +11 -7
  43. package/lib/Validation/rules.js +10 -6
  44. package/lib/Validation/validate.js +54 -47
  45. package/lib/util/index.js +59 -37
  46. package/package.json +1 -1
package/cli.js CHANGED
@@ -1 +1,17 @@
1
- export * from "./lib/Command-Line/NodeArtisanCommand";
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./lib/Command-Line/NodeArtisanCommand"), exports);
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import appConfig from "./lib/Config/Config";
1
+ import { config as appConfig } from "./lib/Config/Config";
2
2
  import Kernel from "./lib/HttpKernel/HttpKernel";
3
3
  import Authentication from "./lib/Auth";
4
4
  import { AppRequest, AppResponse, AppNext } from "./lib/Interface";
package/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../framework/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,qBAAqB,CAAC;AAE5C,OAAO,MAAM,MAAM,6BAA6B,CAAC;AACjD,OAAO,cAAc,MAAM,YAAY,CAAC;AAExC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,WAAW,IAAI,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EACL,MAAM,IAAI,SAAS,EACnB,UAAU,IAAI,aAAa,EAC3B,OAAO,IAAI,UAAU,EACrB,SAAS,IAAI,YAAY,EAC1B,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,KAAK,2CAAkB,CAAC;AACrC,eAAO,MAAM,QAAQ,2CAAkB,CAAC;AACxC,eAAO,MAAM,MAAM,KAAmB,CAAC;AACvC,eAAO,MAAM,UAAU,eAAS,CAAC;AACjC,eAAO,MAAM,MAAM,EAAE,OAAO,SAAqB,CAAC;AAClD,eAAO,MAAM,IAAI,EAAE,OAAO,cAA+B,CAAC;AAC1D,eAAO,MAAM,IAAI,oEAAsB,CAAC;AACxC,eAAO,MAAM,OAAO,oEAAyB,CAAC;AAC9C,eAAO,MAAM,WAAW,EAAE,OAAO,cAA+B,CAAC;AACjE,eAAO,MAAM,MAAM,EAAE,OAAO,SAAqB,CAAC;AAClD,eAAO,MAAM,OAAO,EAAE,OAAO,UAAuB,CAAC;AACrD,eAAO,MAAM,SAAS,EAAE,OAAO,YAA2B,CAAC;AAC3D,eAAO,MAAM,UAAU,EAAE,OAAO,aAA6B,CAAC;AAG9D,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC;AACjC,MAAM,MAAM,QAAQ,GAAG,WAAW,CAAC;AACnC,MAAM,MAAM,IAAI,GAAG,OAAO,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../framework/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,MAAM,MAAM,6BAA6B,CAAC;AACjD,OAAO,cAAc,MAAM,YAAY,CAAC;AAExC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,WAAW,IAAI,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EACL,MAAM,IAAI,SAAS,EACnB,UAAU,IAAI,aAAa,EAC3B,OAAO,IAAI,UAAU,EACrB,SAAS,IAAI,YAAY,EAC1B,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,KAAK,2CAAkB,CAAC;AACrC,eAAO,MAAM,QAAQ,2CAAkB,CAAC;AACxC,eAAO,MAAM,MAAM,KAAmB,CAAC;AACvC,eAAO,MAAM,UAAU,eAAS,CAAC;AACjC,eAAO,MAAM,MAAM,EAAE,OAAO,SAAqB,CAAC;AAClD,eAAO,MAAM,IAAI,EAAE,OAAO,cAA+B,CAAC;AAC1D,eAAO,MAAM,IAAI,oEAAsB,CAAC;AACxC,eAAO,MAAM,OAAO,oEAAyB,CAAC;AAC9C,eAAO,MAAM,WAAW,EAAE,OAAO,cAA+B,CAAC;AACjE,eAAO,MAAM,MAAM,EAAE,OAAO,SAAqB,CAAC;AAClD,eAAO,MAAM,OAAO,EAAE,OAAO,UAAuB,CAAC;AACrD,eAAO,MAAM,SAAS,EAAE,OAAO,YAA2B,CAAC;AAC3D,eAAO,MAAM,UAAU,EAAE,OAAO,aAA6B,CAAC;AAG9D,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC;AACjC,MAAM,MAAM,QAAQ,GAAG,WAAW,CAAC;AACnC,MAAM,MAAM,IAAI,GAAG,OAAO,CAAC"}
package/index.js CHANGED
@@ -1,20 +1,26 @@
1
- import appConfig from "./lib/Config/Config";
2
- import { app } from "./lib/App";
3
- import Kernel from "./lib/HttpKernel/HttpKernel";
4
- import Authentication from "./lib/Auth";
5
- import { authMiddleware } from "./lib/Auth/AuthMiddleware";
6
- import { FormRequest as AppFormRequest } from "./lib/Request/FormRequest";
7
- import { bcrypt as appBcrypt, verifyHash as appVerifyHash, jwtSign as appJwtSign, jwtVerify as appjwtVerify, } from "./lib/util";
8
- export const Route = app.webRoutes();
9
- export const ApiRoute = app.apiRoutes();
10
- export const server = app.httpServer();
11
- export const HttpKernel = Kernel;
12
- export const config = appConfig;
13
- export const Auth = Authentication;
14
- export const auth = authMiddleware.auth;
15
- export const apiAuth = authMiddleware.apiAuth;
16
- export const FormRequest = AppFormRequest;
17
- export const bcrypt = appBcrypt;
18
- export const jwtSign = appJwtSign;
19
- export const jwtVerify = appjwtVerify;
20
- export const verifyHash = appVerifyHash;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.verifyHash = exports.jwtVerify = exports.jwtSign = exports.bcrypt = exports.FormRequest = exports.apiAuth = exports.auth = exports.Auth = exports.config = exports.HttpKernel = exports.server = exports.ApiRoute = exports.Route = void 0;
7
+ const Config_1 = require("./lib/Config/Config");
8
+ const App_1 = require("./lib/App");
9
+ const HttpKernel_1 = __importDefault(require("./lib/HttpKernel/HttpKernel"));
10
+ const Auth_1 = __importDefault(require("./lib/Auth"));
11
+ const AuthMiddleware_1 = require("./lib/Auth/AuthMiddleware");
12
+ const FormRequest_1 = require("./lib/Request/FormRequest");
13
+ const util_1 = require("./lib/util");
14
+ exports.Route = App_1.app.webRoutes();
15
+ exports.ApiRoute = App_1.app.apiRoutes();
16
+ exports.server = App_1.app.httpServer();
17
+ exports.HttpKernel = HttpKernel_1.default;
18
+ exports.config = Config_1.config;
19
+ exports.Auth = Auth_1.default;
20
+ exports.auth = AuthMiddleware_1.authMiddleware.auth;
21
+ exports.apiAuth = AuthMiddleware_1.authMiddleware.apiAuth;
22
+ exports.FormRequest = FormRequest_1.FormRequest;
23
+ exports.bcrypt = util_1.bcrypt;
24
+ exports.jwtSign = util_1.jwtSign;
25
+ exports.jwtVerify = util_1.jwtVerify;
26
+ exports.verifyHash = util_1.verifyHash;
package/lib/App.js CHANGED
@@ -1,40 +1,43 @@
1
- import { Router } from "./Routes/Router";
2
- import config from "./Config/Config";
3
- import { Middleware } from "./Middlewares";
4
- import { HttpSever } from "./Server";
5
- import { loadRoutes } from "./util";
6
- import { PORT } from "./Error/Constants";
7
- class App extends HttpSever {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.app = void 0;
4
+ const Router_1 = require("./Routes/Router");
5
+ const Config_1 = require("./Config/Config");
6
+ const Middlewares_1 = require("./Middlewares");
7
+ const Server_1 = require("./Server");
8
+ const util_1 = require("./util");
9
+ const Constants_1 = require("./Error/Constants");
10
+ class App extends Server_1.HttpSever {
8
11
  // private app = express();
9
12
  constructor() {
10
13
  super();
11
- new Middleware(this.express, this.app);
14
+ new Middlewares_1.Middleware(this.express, this.app);
12
15
  }
13
16
  webRoutes() {
14
- return new Router(this.app, { prefixUrl: "", basePath: "" });
17
+ return new Router_1.Router(this.app, { prefixUrl: "", basePath: "" });
15
18
  }
16
19
  /**
17
20
  * Method to define API routes.
18
21
  * @returns {object} - Instance of Routes class for API routes.
19
22
  */
20
23
  apiRoutes() {
21
- return new Router(this.app, { basePath: "/api", prefixUrl: "" });
24
+ return new Router_1.Router(this.app, { basePath: "/api", prefixUrl: "" });
22
25
  }
23
26
  /**
24
27
  * Method to configure and start the server.
25
28
  * @returns {object} - Object containing server run method and server instance.
26
29
  */
27
30
  httpServer() {
28
- const server = this.server(Number(config.get(PORT, "3000")));
31
+ const server = this.server(Number(Config_1.config.get(Constants_1.PORT, "3000")));
29
32
  const httpErrors = this.httpErrors;
30
33
  const app = this.app;
31
34
  return {
32
35
  listen() {
33
- loadRoutes();
36
+ (0, util_1.loadRoutes)();
34
37
  httpErrors(app);
35
38
  return server;
36
39
  },
37
40
  };
38
41
  }
39
42
  }
40
- export const app = new App();
43
+ exports.app = new App();
@@ -1,4 +1,7 @@
1
- import { jwtVerify } from "../util";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.authMiddleware = void 0;
4
+ const util_1 = require("../util");
2
5
  class AuthMiddleware {
3
6
  apiAuth(request, response, next) {
4
7
  let token;
@@ -16,7 +19,7 @@ class AuthMiddleware {
16
19
  return response.json({ message: "Not authorize" }).status(401);
17
20
  }
18
21
  try {
19
- request.id = jwtVerify(token);
22
+ request.id = (0, util_1.jwtVerify)(token);
20
23
  // request.id = jwtVerify(token, process.env.JWT_SECRET);
21
24
  //
22
25
  next();
@@ -37,4 +40,4 @@ class AuthMiddleware {
37
40
  : response.redirect(url ? `/login?redirect=${url}` : "/login");
38
41
  }
39
42
  }
40
- export const authMiddleware = new AuthMiddleware();
43
+ exports.authMiddleware = new AuthMiddleware();
package/lib/Auth/index.js CHANGED
@@ -1,6 +1,11 @@
1
- import passport from "passport"; // Import Passport for authentication
2
- import { getModel } from "../util"; // Import helper functions for database operations and password hashing
3
- const User = getModel("User"); // Get the User model from database
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const passport_1 = __importDefault(require("passport")); // Import Passport for authentication
7
+ const util_1 = require("../util"); // Import helper functions for database operations and password hashing
8
+ const User = (0, util_1.getModel)("User"); // Get the User model from database
4
9
  class Authentication {
5
10
  // Method to authenticate user login
6
11
  static async login(data = {}, password = "") {
@@ -67,7 +72,7 @@ class Authentication {
67
72
  const appRedirect = req.session["appRedirect"]; // Retrieve redirect URL from session
68
73
  const redirectPath = appRedirect ? appRedirect : "/home"; // Determine the redirect path
69
74
  // Use Passport's local authentication strategy
70
- return passport.authenticate("local", {
75
+ return passport_1.default.authenticate("local", {
71
76
  successRedirect: redirectPath, // Redirect on successful authentication
72
77
  failureRedirect: `${redirectBack ? redirectBack : "/login"}`, // Redirect on failed authentication
73
78
  failureFlash: true, // Enable flash messages on failed authentication
@@ -86,4 +91,4 @@ class Authentication {
86
91
  });
87
92
  }
88
93
  }
89
- export default Authentication;
94
+ exports.default = Authentication;
@@ -1,62 +1,69 @@
1
- import runCommand from "./command";
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.NodeArtisanCommand = void 0;
7
+ const command_1 = __importDefault(require("./command"));
2
8
  /**
3
9
  Function to parse command line arguments and execute corresponding commands
4
10
  @param {commandArg} commandArg -string
5
11
  @returns {any} -any
6
12
  * */
7
- export const NodeArtisanCommand = (commandArg = []) => {
13
+ const NodeArtisanCommand = (commandArg = []) => {
8
14
  let index = commandArg.findIndex((arg, index) => arg.includes(":")); //commandArg[0].split(":")[1] || commandArg[1].split(":")[1]; // Extract the command type from the first argument
9
15
  let command = commandArg[index].split(":")[1];
10
16
  // If the command is for creating an API controller with resources
11
17
  if (commandArg.length === index + 4 &&
12
18
  (command === "apiController" || command === "ApiController") &&
13
19
  (commandArg[index + 3] === "--resources" || commandArg[index + 3] === "-r")) {
14
- runCommand.addModel(commandArg[2]); // Add a model with the provided name
15
- return runCommand.addApi(commandArg[index + 1], commandArg[index + 2]); // Add an API controller with resources
20
+ command_1.default.addModel(commandArg[2]); // Add a model with the provided name
21
+ return command_1.default.addApi(commandArg[index + 1], commandArg[index + 2]); // Add an API controller with resources
16
22
  }
17
23
  // If the command is for creating a web controller with resources
18
24
  if (commandArg.length === 4 &&
19
25
  (command === "controller" || command === "Controller") &&
20
26
  (commandArg[3] === "--resources" || commandArg[3] === "-r")) {
21
- runCommand.addModel(commandArg[2]); // Add a model with the provided name
22
- return runCommand.addWeb(commandArg[1], commandArg[2]); // Add a web controller with resources
27
+ command_1.default.addModel(commandArg[2]); // Add a model with the provided name
28
+ return command_1.default.addWeb(commandArg[1], commandArg[2]); // Add a web controller with resources
23
29
  }
24
30
  // If the command is for creating an admin controller with resources
25
31
  // If the command is for creating a web controller
26
32
  if (commandArg.length === index + 3 &&
27
33
  (command === "controller" || command === "Controller")) {
28
- return runCommand.addWeb(commandArg[index + 1], commandArg[index + 2]); // Add a web controller
34
+ return command_1.default.addWeb(commandArg[index + 1], commandArg[index + 2]); // Add a web controller
29
35
  }
30
36
  // If the command is for creating an API controller
31
37
  if (commandArg.length === index + 3 &&
32
38
  (command === "apiController" || command === "ApiController")) {
33
- return runCommand.addApi(commandArg[index + 1], commandArg[index + 2]); // Add an API controller
39
+ return command_1.default.addApi(commandArg[index + 1], commandArg[index + 2]); // Add an API controller
34
40
  }
35
41
  // If the command is for creating a model
36
42
  if (commandArg.length === index + 2 &&
37
43
  (command === "model" || command === "Model")) {
38
- return runCommand.addModel(commandArg[index + 1]); // Add a model
44
+ return command_1.default.addModel(commandArg[index + 1]); // Add a model
39
45
  }
40
46
  // If the command is for creating a web controller without specifying a model
41
47
  if (commandArg.length === index + 2 &&
42
48
  (command === "controller" || command === "Controller")) {
43
- return runCommand.addWeb(commandArg[index + 1], false); // Add a web controller without a model
49
+ return command_1.default.addWeb(commandArg[index + 1], false); // Add a web controller without a model
44
50
  }
45
51
  // If the command is for creating an API controller without specifying a model
46
52
  if (commandArg.length === index + 2 &&
47
53
  (command === "apiController" || command === "ApiController")) {
48
- return runCommand.addApi(commandArg[index + 1], false); // Add an API controller without a model
54
+ return command_1.default.addApi(commandArg[index + 1], false); // Add an API controller without a model
49
55
  }
50
56
  // If the command is for creating a request file
51
57
  if (commandArg.length === index + 2 &&
52
58
  (command === "Request" || command === "request")) {
53
- return runCommand.addRequest(commandArg[index + 1]); // Add a request file
59
+ return command_1.default.addRequest(commandArg[index + 1]); // Add a request file
54
60
  }
55
61
  // If the command is for creating a request file
56
62
  if (commandArg.length === index + 2 &&
57
63
  (command === "Migration" || command === "migration")) {
58
- return runCommand.addMigration(commandArg[index + 1]); // Add a request file
64
+ return command_1.default.addMigration(commandArg[index + 1]); // Add a request file
59
65
  }
60
66
  // If the command is not recognized, display "Command not found"
61
- return runCommand.notFound();
67
+ return command_1.default.notFound();
62
68
  };
69
+ exports.NodeArtisanCommand = NodeArtisanCommand;
@@ -1,28 +1,33 @@
1
- import path from "path";
2
- import fs from "fs";
3
- import appRootPath from "app-root-path";
4
- import createController from "./files/Controller";
5
- import createModel from "./files/Models";
6
- import resourceController from "./files/ResourcesController";
7
- import createRequest from "./files/Request";
8
- import createMigration from "./files/Migration";
9
- import { formatDate } from "./utils";
10
- const rootPath = appRootPath.path;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const app_root_path_1 = __importDefault(require("app-root-path"));
9
+ const Controller_1 = __importDefault(require("./files/Controller"));
10
+ const Models_1 = __importDefault(require("./files/Models"));
11
+ const ResourcesController_1 = __importDefault(require("./files/ResourcesController"));
12
+ const Request_1 = __importDefault(require("./files/Request"));
13
+ const Migration_1 = __importDefault(require("./files/Migration"));
14
+ const utils_1 = require("./utils");
15
+ const rootPath = app_root_path_1.default.path;
11
16
  class Command {
12
17
  // Method to add a web controller
13
18
  addWeb(controllerName, modelName = false) {
14
19
  try {
15
- let webControllerPath = path.resolve(`${rootPath}/app/Http/Controllers`); // Resolve path to web controllers directory
16
- if (fs.existsSync(`${webControllerPath}/${controllerName}.ts`)) {
20
+ let webControllerPath = path_1.default.resolve(`${rootPath}/app/Http/Controllers`); // Resolve path to web controllers directory
21
+ if (fs_1.default.existsSync(`${webControllerPath}/${controllerName}.ts`)) {
17
22
  // Check if controller file already exists
18
23
  return console.log(`${controllerName} already exist`.yellow); // Log a warning if controller already exists
19
24
  }
20
25
  if (modelName && typeof modelName === "string") {
21
26
  // If model name is provided, create a resource controller
22
- fs.writeFileSync(`${webControllerPath}/${controllerName}.ts`, resourceController(controllerName, modelName));
27
+ fs_1.default.writeFileSync(`${webControllerPath}/${controllerName}.ts`, (0, ResourcesController_1.default)(controllerName, modelName));
23
28
  return console.log(`${controllerName} added successfully`.green); // Log success message
24
29
  }
25
- fs.writeFileSync(`${webControllerPath}/${controllerName}.ts`, createController(controllerName));
30
+ fs_1.default.writeFileSync(`${webControllerPath}/${controllerName}.ts`, (0, Controller_1.default)(controllerName));
26
31
  return console.log(`${controllerName} added successfully`.green); // Log success message
27
32
  }
28
33
  catch (err) {
@@ -32,17 +37,17 @@ class Command {
32
37
  // Method to add an API controller
33
38
  addApi(controllerName, modelName = false) {
34
39
  try {
35
- let apiPath = path.resolve(`${rootPath}/app/Http/ApiControllers`); // Resolve path to API controllers directory
36
- if (fs.existsSync(`${apiPath}/${controllerName}.ts`)) {
40
+ let apiPath = path_1.default.resolve(`${rootPath}/app/Http/ApiControllers`); // Resolve path to API controllers directory
41
+ if (fs_1.default.existsSync(`${apiPath}/${controllerName}.ts`)) {
37
42
  // Check if API controller file already exists
38
43
  return console.log(`${controllerName} api controller already exist`.yellow); // Log a warning if API controller already exists
39
44
  }
40
45
  if (modelName && typeof modelName === "string") {
41
46
  // If model name is provided, create a resource controller
42
- fs.writeFileSync(`${apiPath}/${controllerName}.ts`, resourceController(controllerName, modelName));
47
+ fs_1.default.writeFileSync(`${apiPath}/${controllerName}.ts`, (0, ResourcesController_1.default)(controllerName, modelName));
43
48
  return console.log(`${controllerName} added successfully`.green); // Log success message
44
49
  }
45
- fs.writeFileSync(`${apiPath}/${controllerName}.ts`, createController(controllerName));
50
+ fs_1.default.writeFileSync(`${apiPath}/${controllerName}.ts`, (0, Controller_1.default)(controllerName));
46
51
  return console.log(`${controllerName} added successfully`.green); // Log success message
47
52
  }
48
53
  catch (err) {
@@ -53,12 +58,12 @@ class Command {
53
58
  // Method to add a model
54
59
  addModel(modelName) {
55
60
  try {
56
- let modelPath = path.resolve(`${rootPath}/app/Models`); // Resolve path to models directory
57
- if (fs.existsSync(`${modelPath}/${modelName}.ts`)) {
61
+ let modelPath = path_1.default.resolve(`${rootPath}/app/Models`); // Resolve path to models directory
62
+ if (fs_1.default.existsSync(`${modelPath}/${modelName}.ts`)) {
58
63
  // Check if model file already exists
59
64
  return console.log(`${modelName} model already exist`.yellow); // Log a warning if model already exists
60
65
  }
61
- fs.writeFileSync(`${modelPath}/${modelName}.ts`, createModel(modelName)); // Create a model file
66
+ fs_1.default.writeFileSync(`${modelPath}/${modelName}.ts`, (0, Models_1.default)(modelName)); // Create a model file
62
67
  return console.log(`${modelName} model added successfully`.green); // Log success message
63
68
  }
64
69
  catch (err) {
@@ -68,12 +73,12 @@ class Command {
68
73
  // Method to add a request file
69
74
  addRequest(requestName) {
70
75
  try {
71
- let requestPath = path.resolve(`${rootPath}/app/Http/Requests`); // Resolve path to request files directory
72
- if (fs.existsSync(`${requestPath}/${requestName}.ts`)) {
76
+ let requestPath = path_1.default.resolve(`${rootPath}/app/Http/Requests`); // Resolve path to request files directory
77
+ if (fs_1.default.existsSync(`${requestPath}/${requestName}.ts`)) {
73
78
  // Check if request file already exists
74
79
  return console.log(`${requestName} already exist`.yellow); // Log a warning if request file already exists
75
80
  }
76
- fs.writeFileSync(`${requestPath}/${requestName}.ts`, createRequest(requestName));
81
+ fs_1.default.writeFileSync(`${requestPath}/${requestName}.ts`, (0, Request_1.default)(requestName));
77
82
  return console.log(`${requestName} added successfully`.green); // Log success message
78
83
  }
79
84
  catch (err) {
@@ -84,14 +89,14 @@ class Command {
84
89
  addMigration(migrationName) {
85
90
  try {
86
91
  const tableName = migrationName.replace(/(create_|_table)/g, "");
87
- let migrationPath = path.resolve(`${rootPath}/database/migrations`);
92
+ let migrationPath = path_1.default.resolve(`${rootPath}/database/migrations`);
88
93
  // Resolve path to request files directory
89
- const fullName = `${formatDate()}_${migrationName}`;
90
- if (fs.existsSync(`${migrationPath}/${fullName}.ts`)) {
94
+ const fullName = `${(0, utils_1.formatDate)()}_${migrationName}`;
95
+ if (fs_1.default.existsSync(`${migrationPath}/${fullName}.ts`)) {
91
96
  // Check if request file already exists
92
97
  return console.log(`${tableName} already exist`.yellow); // Log a warning if request file already exists
93
98
  }
94
- fs.writeFileSync(`${migrationPath}/${fullName}.ts`, createMigration(tableName));
99
+ fs_1.default.writeFileSync(`${migrationPath}/${fullName}.ts`, (0, Migration_1.default)(tableName));
95
100
  return console.log(`${fullName} added successfully`.green); // Log success message
96
101
  }
97
102
  catch (err) {
@@ -103,4 +108,4 @@ class Command {
103
108
  return console.log(`Command not found`.bgRed); // Log a message indicating the command was not found
104
109
  }
105
110
  }
106
- export default new Command(); // Export an instance of the Command class
111
+ exports.default = new Command(); // Export an instance of the Command class
@@ -1,3 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
1
3
  /**
2
4
  * Function to create a controller file
3
5
  * @param name string
@@ -72,4 +74,4 @@ const createController = (name) => {
72
74
  }
73
75
  `;
74
76
  };
75
- export default createController;
77
+ exports.default = createController;
@@ -1,3 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
1
3
  const inflection = require("inflection");
2
4
  const createMigration = (table) => {
3
5
  return `
@@ -13,4 +15,4 @@ class Migration {
13
15
  }
14
16
  `;
15
17
  };
16
- export default createMigration;
18
+ exports.default = createMigration;
@@ -1,3 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
1
3
  /**
2
4
  * Function to create a model file
3
5
  * @param name - string
@@ -16,4 +18,4 @@ const createModel = (name) => {
16
18
 
17
19
  `;
18
20
  };
19
- export default createModel;
21
+ exports.default = createModel;
@@ -1,3 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
1
3
  /**
2
4
  * Function to create a request file
3
5
  * @param name - string
@@ -28,4 +30,4 @@ const createRequest = (fileName) => {
28
30
 
29
31
  `;
30
32
  };
31
- export default createRequest;
33
+ exports.default = createRequest;
@@ -1,3 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
1
3
  /**
2
4
  * Function to create a resources file
3
5
  * @param name - string
@@ -72,4 +74,4 @@ const resourceController = (controller, model) => {
72
74
  }
73
75
  `;
74
76
  };
75
- export default resourceController;
77
+ exports.default = resourceController;
@@ -1,4 +1,7 @@
1
- export const formatDate = () => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatDate = void 0;
4
+ const formatDate = () => {
2
5
  const date = new Date();
3
6
  const year = date.getFullYear();
4
7
  const month = String(date.getMonth() + 1).padStart(2, "0");
@@ -8,3 +11,4 @@ export const formatDate = () => {
8
11
  const seconds = String(date.getSeconds()).padStart(2, "0");
9
12
  return `${year}_${month}_${day}_${hours}_${minutes}_${seconds}`;
10
13
  };
14
+ exports.formatDate = formatDate;
@@ -3,6 +3,6 @@ declare class Config {
3
3
  constructor();
4
4
  get(key: string, defaultValue?: string): string;
5
5
  }
6
- declare const _default: Config;
7
- export default _default;
6
+ export declare const config: Config;
7
+ export {};
8
8
  //# sourceMappingURL=Config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../../framework/lib/Config/Config.ts"],"names":[],"mappings":"AAGA,cAAM,MAAM;IACV,OAAO,CAAC,MAAM,CAAwC;;IAO/C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,GAAE,MAAW,GAAG,MAAM;CAG3D;;AAED,wBAA4B"}
1
+ {"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../../framework/lib/Config/Config.ts"],"names":[],"mappings":"AAGA,cAAM,MAAM;IACV,OAAO,CAAC,MAAM,CAAwC;;IAO/C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,GAAE,MAAW,GAAG,MAAM;CAG3D;AAED,eAAO,MAAM,MAAM,QAAe,CAAC"}
@@ -1,12 +1,18 @@
1
- import dotenv from "dotenv";
2
- import appRootPath from "app-root-path";
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.config = void 0;
7
+ const dotenv_1 = __importDefault(require("dotenv"));
8
+ const app_root_path_1 = __importDefault(require("app-root-path"));
3
9
  class Config {
4
10
  constructor() {
5
- dotenv.config({ path: `${appRootPath.path}/.env` });
11
+ dotenv_1.default.config({ path: `${app_root_path_1.default.path}/.env` });
6
12
  this.config = process.env;
7
13
  }
8
14
  get(key, defaultValue = "") {
9
15
  return this.config[key] || defaultValue;
10
16
  }
11
17
  }
12
- export default new Config();
18
+ exports.config = new Config();
@@ -1,4 +1,7 @@
1
- export class AppError extends Error {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppError = void 0;
4
+ class AppError extends Error {
2
5
  constructor(message, type, errorFile) {
3
6
  super(message);
4
7
  this.message = message;
@@ -6,3 +9,4 @@ export class AppError extends Error {
6
9
  this.errorFile = errorFile;
7
10
  }
8
11
  }
12
+ exports.AppError = AppError;
@@ -1,6 +1,9 @@
1
- import { API_VALIDATION_ERROR, FIRST_METHOD_ERROR, VALIDATION_ERROR, } from "./Constants/error";
2
- import { DisplayError } from "./DisplayErrorCode";
3
- export class AppErrorHandler {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppErrorHandler = void 0;
4
+ const error_1 = require("./Constants/error");
5
+ const DisplayErrorCode_1 = require("./DisplayErrorCode");
6
+ class AppErrorHandler {
4
7
  constructor(app) {
5
8
  this.app = app;
6
9
  }
@@ -18,18 +21,18 @@ export class AppErrorHandler {
18
21
  app.use((err, req, res, next) => {
19
22
  let error = { ...err };
20
23
  let statusCode = 0;
21
- if (err.type === VALIDATION_ERROR) {
24
+ if (err.type === error_1.VALIDATION_ERROR) {
22
25
  error.message = err.message;
23
26
  // console.log("object");
24
27
  return res.status(400).redirectBack();
25
28
  }
26
- if (err.type === API_VALIDATION_ERROR) {
29
+ if (err.type === error_1.API_VALIDATION_ERROR) {
27
30
  return res.json({ message: err.message }).status(400);
28
31
  }
29
- if (err.type === FIRST_METHOD_ERROR) {
32
+ if (err.type === error_1.FIRST_METHOD_ERROR) {
30
33
  const errArray = err.stack?.split(/\n/g) || [];
31
34
  const errorPath = this.getErrorPath(errArray);
32
- return DisplayError.show(errorPath, err.message, res);
35
+ return DisplayErrorCode_1.DisplayError.show(errorPath, err.message, res);
33
36
  }
34
37
  return res
35
38
  .json({
@@ -40,3 +43,4 @@ export class AppErrorHandler {
40
43
  });
41
44
  }
42
45
  }
46
+ exports.AppErrorHandler = AppErrorHandler;