jcc-express-mvc 1.3.0 → 1.3.1
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/cli.d.ts +2 -0
- package/cli.d.ts.map +1 -0
- package/cli.js +1 -0
- package/index.d.ts +0 -2
- package/index.d.ts.map +1 -1
- package/index.js +20 -28
- package/lib/App.js +13 -19
- package/lib/Auth/AuthMiddleware.js +3 -6
- package/lib/Auth/index.js +5 -10
- package/lib/Command-Line/NodeArtisanCommand.js +14 -21
- package/lib/Command-Line/command.js +29 -34
- package/lib/Command-Line/files/Controller.js +1 -3
- package/lib/Command-Line/files/Migration.js +1 -3
- package/lib/Command-Line/files/Models.js +1 -3
- package/lib/Command-Line/files/Request.js +1 -3
- package/lib/Command-Line/files/ResourcesController.js +1 -3
- package/lib/Command-Line/utils.js +1 -5
- package/lib/Config/Config.js +4 -9
- package/lib/Error/AppError.js +1 -5
- package/lib/Error/AppErrorHandler.d.ts +2 -3
- package/lib/Error/AppErrorHandler.d.ts.map +1 -1
- package/lib/Error/AppErrorHandler.js +32 -25
- package/lib/Error/Constants/error.d.ts +30 -0
- package/lib/Error/Constants/error.d.ts.map +1 -1
- package/lib/Error/Constants/error.js +42 -15
- package/lib/Error/Constants/index.js +3 -6
- package/lib/Error/DisplayErrorCode.d.ts +6 -0
- package/lib/Error/DisplayErrorCode.d.ts.map +1 -0
- package/lib/Error/DisplayErrorCode.js +21 -0
- package/lib/Error/ErrorHigtlig.d.ts +5 -0
- package/lib/Error/ErrorHigtlig.d.ts.map +1 -0
- package/lib/Error/ErrorHigtlig.js +88 -0
- package/lib/HttpKernel/HttpKernel.js +1 -3
- package/lib/Interface/index.js +1 -2
- package/lib/Middlewares/index.js +23 -30
- package/lib/Middlewares/isLogin.js +1 -5
- package/lib/Passport/config.js +10 -17
- package/lib/Request/FormRequest.js +1 -5
- package/lib/Request/request.js +6 -10
- package/lib/Response/index.js +1 -5
- package/lib/Routes/RouteBuilder.js +10 -14
- package/lib/Routes/Router.js +5 -9
- package/lib/Server/index.d.ts +1 -1
- package/lib/Server/index.js +9 -16
- package/lib/Services/ServiceContainer.js +4 -7
- package/lib/Services/ServiceProvider.js +1 -5
- package/lib/Templating-engine/engineHelper.js +6 -13
- package/lib/Templating-engine/expressions.js +1 -5
- package/lib/Templating-engine/index.js +8 -14
- package/lib/Type/index.js +1 -2
- package/lib/Validation/index.js +7 -11
- package/lib/Validation/rules.js +6 -10
- package/lib/Validation/validate.js +47 -54
- package/lib/util/index.js +37 -59
- package/package.json +1 -1
package/cli.d.ts
ADDED
package/cli.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../framework/cli.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAC"}
|
package/cli.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./lib/Command-Line/NodeArtisanCommand";
|
package/index.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ import Authentication from "./lib/Auth";
|
|
|
4
4
|
import { AppRequest, AppResponse, AppNext } from "./lib/Interface";
|
|
5
5
|
import { FormRequest as AppFormRequest } from "./lib/Request/FormRequest";
|
|
6
6
|
import { bcrypt as appBcrypt, verifyHash as appVerifyHash, jwtSign as appJwtSign, jwtVerify as appjwtVerify } from "./lib/util";
|
|
7
|
-
import { NodeArtisanCommand } from "./lib/Command-Line/NodeArtisanCommand";
|
|
8
7
|
export declare const Route: import("./lib/Routes/Router").Router<any>;
|
|
9
8
|
export declare const ApiRoute: import("./lib/Routes/Router").Router<any>;
|
|
10
9
|
export declare const server: any;
|
|
@@ -18,7 +17,6 @@ export declare const bcrypt: typeof appBcrypt;
|
|
|
18
17
|
export declare const jwtSign: typeof appJwtSign;
|
|
19
18
|
export declare const jwtVerify: typeof appjwtVerify;
|
|
20
19
|
export declare const verifyHash: typeof appVerifyHash;
|
|
21
|
-
export declare const artisanCommand: typeof NodeArtisanCommand;
|
|
22
20
|
export type Request = AppRequest;
|
|
23
21
|
export type Response = AppResponse;
|
|
24
22
|
export type Next = AppNext;
|
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;
|
|
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"}
|
package/index.js
CHANGED
|
@@ -1,28 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
exports.auth = AuthMiddleware_1.authMiddleware.auth;
|
|
22
|
-
exports.apiAuth = AuthMiddleware_1.authMiddleware.apiAuth;
|
|
23
|
-
exports.FormRequest = FormRequest_1.FormRequest;
|
|
24
|
-
exports.bcrypt = util_1.bcrypt;
|
|
25
|
-
exports.jwtSign = util_1.jwtSign;
|
|
26
|
-
exports.jwtVerify = util_1.jwtVerify;
|
|
27
|
-
exports.verifyHash = util_1.verifyHash;
|
|
28
|
-
exports.artisanCommand = NodeArtisanCommand_1.NodeArtisanCommand;
|
|
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;
|
package/lib/App.js
CHANGED
|
@@ -1,46 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const Config_1 = __importDefault(require("./Config/Config"));
|
|
9
|
-
const Middlewares_1 = require("./Middlewares");
|
|
10
|
-
const Server_1 = require("./Server");
|
|
11
|
-
const util_1 = require("./util");
|
|
12
|
-
const Constants_1 = require("./Error/Constants");
|
|
13
|
-
class App extends Server_1.HttpSever {
|
|
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 {
|
|
14
8
|
// private app = express();
|
|
15
9
|
constructor() {
|
|
16
10
|
super();
|
|
17
|
-
new
|
|
11
|
+
new Middleware(this.express, this.app);
|
|
18
12
|
}
|
|
19
13
|
webRoutes() {
|
|
20
|
-
return new
|
|
14
|
+
return new Router(this.app, { prefixUrl: "", basePath: "" });
|
|
21
15
|
}
|
|
22
16
|
/**
|
|
23
17
|
* Method to define API routes.
|
|
24
18
|
* @returns {object} - Instance of Routes class for API routes.
|
|
25
19
|
*/
|
|
26
20
|
apiRoutes() {
|
|
27
|
-
return new
|
|
21
|
+
return new Router(this.app, { basePath: "/api", prefixUrl: "" });
|
|
28
22
|
}
|
|
29
23
|
/**
|
|
30
24
|
* Method to configure and start the server.
|
|
31
25
|
* @returns {object} - Object containing server run method and server instance.
|
|
32
26
|
*/
|
|
33
27
|
httpServer() {
|
|
34
|
-
const server = this.server(Number(
|
|
28
|
+
const server = this.server(Number(config.get(PORT, "3000")));
|
|
35
29
|
const httpErrors = this.httpErrors;
|
|
36
30
|
const app = this.app;
|
|
37
31
|
return {
|
|
38
32
|
listen() {
|
|
39
|
-
|
|
33
|
+
loadRoutes();
|
|
40
34
|
httpErrors(app);
|
|
41
35
|
return server;
|
|
42
36
|
},
|
|
43
37
|
};
|
|
44
38
|
}
|
|
45
39
|
}
|
|
46
|
-
|
|
40
|
+
export const app = new App();
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.authMiddleware = void 0;
|
|
4
|
-
const util_1 = require("../util");
|
|
1
|
+
import { jwtVerify } from "../util";
|
|
5
2
|
class AuthMiddleware {
|
|
6
3
|
apiAuth(request, response, next) {
|
|
7
4
|
let token;
|
|
@@ -19,7 +16,7 @@ class AuthMiddleware {
|
|
|
19
16
|
return response.json({ message: "Not authorize" }).status(401);
|
|
20
17
|
}
|
|
21
18
|
try {
|
|
22
|
-
request.id =
|
|
19
|
+
request.id = jwtVerify(token);
|
|
23
20
|
// request.id = jwtVerify(token, process.env.JWT_SECRET);
|
|
24
21
|
//
|
|
25
22
|
next();
|
|
@@ -40,4 +37,4 @@ class AuthMiddleware {
|
|
|
40
37
|
: response.redirect(url ? `/login?redirect=${url}` : "/login");
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
|
-
|
|
40
|
+
export const authMiddleware = new AuthMiddleware();
|
package/lib/Auth/index.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
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
|
|
9
4
|
class Authentication {
|
|
10
5
|
// Method to authenticate user login
|
|
11
6
|
static async login(data = {}, password = "") {
|
|
@@ -72,7 +67,7 @@ class Authentication {
|
|
|
72
67
|
const appRedirect = req.session["appRedirect"]; // Retrieve redirect URL from session
|
|
73
68
|
const redirectPath = appRedirect ? appRedirect : "/home"; // Determine the redirect path
|
|
74
69
|
// Use Passport's local authentication strategy
|
|
75
|
-
return
|
|
70
|
+
return passport.authenticate("local", {
|
|
76
71
|
successRedirect: redirectPath, // Redirect on successful authentication
|
|
77
72
|
failureRedirect: `${redirectBack ? redirectBack : "/login"}`, // Redirect on failed authentication
|
|
78
73
|
failureFlash: true, // Enable flash messages on failed authentication
|
|
@@ -91,4 +86,4 @@ class Authentication {
|
|
|
91
86
|
});
|
|
92
87
|
}
|
|
93
88
|
}
|
|
94
|
-
|
|
89
|
+
export default Authentication;
|
|
@@ -1,69 +1,62 @@
|
|
|
1
|
-
|
|
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"));
|
|
1
|
+
import runCommand from "./command";
|
|
8
2
|
/**
|
|
9
3
|
Function to parse command line arguments and execute corresponding commands
|
|
10
4
|
@param {commandArg} commandArg -string
|
|
11
5
|
@returns {any} -any
|
|
12
6
|
* */
|
|
13
|
-
const NodeArtisanCommand = (commandArg = []) => {
|
|
7
|
+
export const NodeArtisanCommand = (commandArg = []) => {
|
|
14
8
|
let index = commandArg.findIndex((arg, index) => arg.includes(":")); //commandArg[0].split(":")[1] || commandArg[1].split(":")[1]; // Extract the command type from the first argument
|
|
15
9
|
let command = commandArg[index].split(":")[1];
|
|
16
10
|
// If the command is for creating an API controller with resources
|
|
17
11
|
if (commandArg.length === index + 4 &&
|
|
18
12
|
(command === "apiController" || command === "ApiController") &&
|
|
19
13
|
(commandArg[index + 3] === "--resources" || commandArg[index + 3] === "-r")) {
|
|
20
|
-
|
|
21
|
-
return
|
|
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
|
|
22
16
|
}
|
|
23
17
|
// If the command is for creating a web controller with resources
|
|
24
18
|
if (commandArg.length === 4 &&
|
|
25
19
|
(command === "controller" || command === "Controller") &&
|
|
26
20
|
(commandArg[3] === "--resources" || commandArg[3] === "-r")) {
|
|
27
|
-
|
|
28
|
-
return
|
|
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
|
|
29
23
|
}
|
|
30
24
|
// If the command is for creating an admin controller with resources
|
|
31
25
|
// If the command is for creating a web controller
|
|
32
26
|
if (commandArg.length === index + 3 &&
|
|
33
27
|
(command === "controller" || command === "Controller")) {
|
|
34
|
-
return
|
|
28
|
+
return runCommand.addWeb(commandArg[index + 1], commandArg[index + 2]); // Add a web controller
|
|
35
29
|
}
|
|
36
30
|
// If the command is for creating an API controller
|
|
37
31
|
if (commandArg.length === index + 3 &&
|
|
38
32
|
(command === "apiController" || command === "ApiController")) {
|
|
39
|
-
return
|
|
33
|
+
return runCommand.addApi(commandArg[index + 1], commandArg[index + 2]); // Add an API controller
|
|
40
34
|
}
|
|
41
35
|
// If the command is for creating a model
|
|
42
36
|
if (commandArg.length === index + 2 &&
|
|
43
37
|
(command === "model" || command === "Model")) {
|
|
44
|
-
return
|
|
38
|
+
return runCommand.addModel(commandArg[index + 1]); // Add a model
|
|
45
39
|
}
|
|
46
40
|
// If the command is for creating a web controller without specifying a model
|
|
47
41
|
if (commandArg.length === index + 2 &&
|
|
48
42
|
(command === "controller" || command === "Controller")) {
|
|
49
|
-
return
|
|
43
|
+
return runCommand.addWeb(commandArg[index + 1], false); // Add a web controller without a model
|
|
50
44
|
}
|
|
51
45
|
// If the command is for creating an API controller without specifying a model
|
|
52
46
|
if (commandArg.length === index + 2 &&
|
|
53
47
|
(command === "apiController" || command === "ApiController")) {
|
|
54
|
-
return
|
|
48
|
+
return runCommand.addApi(commandArg[index + 1], false); // Add an API controller without a model
|
|
55
49
|
}
|
|
56
50
|
// If the command is for creating a request file
|
|
57
51
|
if (commandArg.length === index + 2 &&
|
|
58
52
|
(command === "Request" || command === "request")) {
|
|
59
|
-
return
|
|
53
|
+
return runCommand.addRequest(commandArg[index + 1]); // Add a request file
|
|
60
54
|
}
|
|
61
55
|
// If the command is for creating a request file
|
|
62
56
|
if (commandArg.length === index + 2 &&
|
|
63
57
|
(command === "Migration" || command === "migration")) {
|
|
64
|
-
return
|
|
58
|
+
return runCommand.addMigration(commandArg[index + 1]); // Add a request file
|
|
65
59
|
}
|
|
66
60
|
// If the command is not recognized, display "Command not found"
|
|
67
|
-
return
|
|
61
|
+
return runCommand.notFound();
|
|
68
62
|
};
|
|
69
|
-
exports.NodeArtisanCommand = NodeArtisanCommand;
|
|
@@ -1,33 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
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;
|
|
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;
|
|
16
11
|
class Command {
|
|
17
12
|
// Method to add a web controller
|
|
18
13
|
addWeb(controllerName, modelName = false) {
|
|
19
14
|
try {
|
|
20
|
-
let webControllerPath =
|
|
21
|
-
if (
|
|
15
|
+
let webControllerPath = path.resolve(`${rootPath}/app/Http/Controllers`); // Resolve path to web controllers directory
|
|
16
|
+
if (fs.existsSync(`${webControllerPath}/${controllerName}.ts`)) {
|
|
22
17
|
// Check if controller file already exists
|
|
23
18
|
return console.log(`${controllerName} already exist`.yellow); // Log a warning if controller already exists
|
|
24
19
|
}
|
|
25
20
|
if (modelName && typeof modelName === "string") {
|
|
26
21
|
// If model name is provided, create a resource controller
|
|
27
|
-
|
|
22
|
+
fs.writeFileSync(`${webControllerPath}/${controllerName}.ts`, resourceController(controllerName, modelName));
|
|
28
23
|
return console.log(`${controllerName} added successfully`.green); // Log success message
|
|
29
24
|
}
|
|
30
|
-
|
|
25
|
+
fs.writeFileSync(`${webControllerPath}/${controllerName}.ts`, createController(controllerName));
|
|
31
26
|
return console.log(`${controllerName} added successfully`.green); // Log success message
|
|
32
27
|
}
|
|
33
28
|
catch (err) {
|
|
@@ -37,17 +32,17 @@ class Command {
|
|
|
37
32
|
// Method to add an API controller
|
|
38
33
|
addApi(controllerName, modelName = false) {
|
|
39
34
|
try {
|
|
40
|
-
let apiPath =
|
|
41
|
-
if (
|
|
35
|
+
let apiPath = path.resolve(`${rootPath}/app/Http/ApiControllers`); // Resolve path to API controllers directory
|
|
36
|
+
if (fs.existsSync(`${apiPath}/${controllerName}.ts`)) {
|
|
42
37
|
// Check if API controller file already exists
|
|
43
38
|
return console.log(`${controllerName} api controller already exist`.yellow); // Log a warning if API controller already exists
|
|
44
39
|
}
|
|
45
40
|
if (modelName && typeof modelName === "string") {
|
|
46
41
|
// If model name is provided, create a resource controller
|
|
47
|
-
|
|
42
|
+
fs.writeFileSync(`${apiPath}/${controllerName}.ts`, resourceController(controllerName, modelName));
|
|
48
43
|
return console.log(`${controllerName} added successfully`.green); // Log success message
|
|
49
44
|
}
|
|
50
|
-
|
|
45
|
+
fs.writeFileSync(`${apiPath}/${controllerName}.ts`, createController(controllerName));
|
|
51
46
|
return console.log(`${controllerName} added successfully`.green); // Log success message
|
|
52
47
|
}
|
|
53
48
|
catch (err) {
|
|
@@ -58,12 +53,12 @@ class Command {
|
|
|
58
53
|
// Method to add a model
|
|
59
54
|
addModel(modelName) {
|
|
60
55
|
try {
|
|
61
|
-
let modelPath =
|
|
62
|
-
if (
|
|
56
|
+
let modelPath = path.resolve(`${rootPath}/app/Models`); // Resolve path to models directory
|
|
57
|
+
if (fs.existsSync(`${modelPath}/${modelName}.ts`)) {
|
|
63
58
|
// Check if model file already exists
|
|
64
59
|
return console.log(`${modelName} model already exist`.yellow); // Log a warning if model already exists
|
|
65
60
|
}
|
|
66
|
-
|
|
61
|
+
fs.writeFileSync(`${modelPath}/${modelName}.ts`, createModel(modelName)); // Create a model file
|
|
67
62
|
return console.log(`${modelName} model added successfully`.green); // Log success message
|
|
68
63
|
}
|
|
69
64
|
catch (err) {
|
|
@@ -73,12 +68,12 @@ class Command {
|
|
|
73
68
|
// Method to add a request file
|
|
74
69
|
addRequest(requestName) {
|
|
75
70
|
try {
|
|
76
|
-
let requestPath =
|
|
77
|
-
if (
|
|
71
|
+
let requestPath = path.resolve(`${rootPath}/app/Http/Requests`); // Resolve path to request files directory
|
|
72
|
+
if (fs.existsSync(`${requestPath}/${requestName}.ts`)) {
|
|
78
73
|
// Check if request file already exists
|
|
79
74
|
return console.log(`${requestName} already exist`.yellow); // Log a warning if request file already exists
|
|
80
75
|
}
|
|
81
|
-
|
|
76
|
+
fs.writeFileSync(`${requestPath}/${requestName}.ts`, createRequest(requestName));
|
|
82
77
|
return console.log(`${requestName} added successfully`.green); // Log success message
|
|
83
78
|
}
|
|
84
79
|
catch (err) {
|
|
@@ -89,14 +84,14 @@ class Command {
|
|
|
89
84
|
addMigration(migrationName) {
|
|
90
85
|
try {
|
|
91
86
|
const tableName = migrationName.replace(/(create_|_table)/g, "");
|
|
92
|
-
let migrationPath =
|
|
87
|
+
let migrationPath = path.resolve(`${rootPath}/database/migrations`);
|
|
93
88
|
// Resolve path to request files directory
|
|
94
|
-
const fullName = `${
|
|
95
|
-
if (
|
|
89
|
+
const fullName = `${formatDate()}_${migrationName}`;
|
|
90
|
+
if (fs.existsSync(`${migrationPath}/${fullName}.ts`)) {
|
|
96
91
|
// Check if request file already exists
|
|
97
92
|
return console.log(`${tableName} already exist`.yellow); // Log a warning if request file already exists
|
|
98
93
|
}
|
|
99
|
-
|
|
94
|
+
fs.writeFileSync(`${migrationPath}/${fullName}.ts`, createMigration(tableName));
|
|
100
95
|
return console.log(`${fullName} added successfully`.green); // Log success message
|
|
101
96
|
}
|
|
102
97
|
catch (err) {
|
|
@@ -108,4 +103,4 @@ class Command {
|
|
|
108
103
|
return console.log(`Command not found`.bgRed); // Log a message indicating the command was not found
|
|
109
104
|
}
|
|
110
105
|
}
|
|
111
|
-
|
|
106
|
+
export default new Command(); // Export an instance of the Command class
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
/**
|
|
4
2
|
* Function to create a controller file
|
|
5
3
|
* @param name string
|
|
@@ -74,4 +72,4 @@ const createController = (name) => {
|
|
|
74
72
|
}
|
|
75
73
|
`;
|
|
76
74
|
};
|
|
77
|
-
|
|
75
|
+
export default createController;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
const inflection = require("inflection");
|
|
4
2
|
const createMigration = (table) => {
|
|
5
3
|
return `
|
|
@@ -15,4 +13,4 @@ class Migration {
|
|
|
15
13
|
}
|
|
16
14
|
`;
|
|
17
15
|
};
|
|
18
|
-
|
|
16
|
+
export default createMigration;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
/**
|
|
4
2
|
* Function to create a model file
|
|
5
3
|
* @param name - string
|
|
@@ -18,4 +16,4 @@ const createModel = (name) => {
|
|
|
18
16
|
|
|
19
17
|
`;
|
|
20
18
|
};
|
|
21
|
-
|
|
19
|
+
export default createModel;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
/**
|
|
4
2
|
* Function to create a request file
|
|
5
3
|
* @param name - string
|
|
@@ -30,4 +28,4 @@ const createRequest = (fileName) => {
|
|
|
30
28
|
|
|
31
29
|
`;
|
|
32
30
|
};
|
|
33
|
-
|
|
31
|
+
export default createRequest;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
/**
|
|
4
2
|
* Function to create a resources file
|
|
5
3
|
* @param name - string
|
|
@@ -74,4 +72,4 @@ const resourceController = (controller, model) => {
|
|
|
74
72
|
}
|
|
75
73
|
`;
|
|
76
74
|
};
|
|
77
|
-
|
|
75
|
+
export default resourceController;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatDate = void 0;
|
|
4
|
-
const formatDate = () => {
|
|
1
|
+
export const formatDate = () => {
|
|
5
2
|
const date = new Date();
|
|
6
3
|
const year = date.getFullYear();
|
|
7
4
|
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
@@ -11,4 +8,3 @@ const formatDate = () => {
|
|
|
11
8
|
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
12
9
|
return `${year}_${month}_${day}_${hours}_${minutes}_${seconds}`;
|
|
13
10
|
};
|
|
14
|
-
exports.formatDate = formatDate;
|
package/lib/Config/Config.js
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
7
|
-
const app_root_path_1 = __importDefault(require("app-root-path"));
|
|
1
|
+
import dotenv from "dotenv";
|
|
2
|
+
import appRootPath from "app-root-path";
|
|
8
3
|
class Config {
|
|
9
4
|
constructor() {
|
|
10
|
-
|
|
5
|
+
dotenv.config({ path: `${appRootPath.path}/.env` });
|
|
11
6
|
this.config = process.env;
|
|
12
7
|
}
|
|
13
8
|
get(key, defaultValue = "") {
|
|
14
9
|
return this.config[key] || defaultValue;
|
|
15
10
|
}
|
|
16
11
|
}
|
|
17
|
-
|
|
12
|
+
export default new Config();
|
package/lib/Error/AppError.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AppError = void 0;
|
|
4
|
-
class AppError extends Error {
|
|
1
|
+
export class AppError extends Error {
|
|
5
2
|
constructor(message, type, errorFile) {
|
|
6
3
|
super(message);
|
|
7
4
|
this.message = message;
|
|
@@ -9,4 +6,3 @@ class AppError extends Error {
|
|
|
9
6
|
this.errorFile = errorFile;
|
|
10
7
|
}
|
|
11
8
|
}
|
|
12
|
-
exports.AppError = AppError;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Application } from "express";
|
|
2
|
-
import { AppNext, AppRequest, AppResponse } from "../Interface";
|
|
3
|
-
import { AppError } from "./AppError";
|
|
4
2
|
export declare class AppErrorHandler {
|
|
5
3
|
private app;
|
|
6
4
|
constructor(app: Application);
|
|
7
5
|
errorRoutesHandler(): Application;
|
|
8
|
-
|
|
6
|
+
getErrorPath(errorStack: Array<any>): any;
|
|
7
|
+
handler(app: any): void;
|
|
9
8
|
}
|
|
10
9
|
//# sourceMappingURL=AppErrorHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AppErrorHandler.d.ts","sourceRoot":"","sources":["../../../framework/lib/Error/AppErrorHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"AppErrorHandler.d.ts","sourceRoot":"","sources":["../../../framework/lib/Error/AppErrorHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAUtC,qBAAa,eAAe;IAC1B,OAAO,CAAC,GAAG,CAAc;gBACb,GAAG,EAAE,WAAW;IAIrB,kBAAkB;IAMzB,YAAY,CAAC,UAAU,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,GAAG;IAMzC,OAAO,CAAC,GAAG,EAAE,GAAG;CA8BjB"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const error_1 = require("./Constants/error");
|
|
5
|
-
class AppErrorHandler {
|
|
1
|
+
import { API_VALIDATION_ERROR, FIRST_METHOD_ERROR, VALIDATION_ERROR, } from "./Constants/error";
|
|
2
|
+
import { DisplayError } from "./DisplayErrorCode";
|
|
3
|
+
export class AppErrorHandler {
|
|
6
4
|
constructor(app) {
|
|
7
5
|
this.app = app;
|
|
8
6
|
}
|
|
@@ -11,25 +9,34 @@ class AppErrorHandler {
|
|
|
11
9
|
return res.sendFile(__dirname + "/public/pageNotFound.html");
|
|
12
10
|
});
|
|
13
11
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
12
|
+
getErrorPath(errorStack) {
|
|
13
|
+
const getLastindex = errorStack[errorStack.length - 1];
|
|
14
|
+
const arr = getLastindex.split(/\s/g);
|
|
15
|
+
return arr[arr.length - 1];
|
|
16
|
+
}
|
|
17
|
+
handler(app) {
|
|
18
|
+
app.use((err, req, res, next) => {
|
|
19
|
+
let error = { ...err };
|
|
20
|
+
let statusCode = 0;
|
|
21
|
+
if (err.type === VALIDATION_ERROR) {
|
|
22
|
+
error.message = err.message;
|
|
23
|
+
// console.log("object");
|
|
24
|
+
return res.status(400).redirectBack();
|
|
25
|
+
}
|
|
26
|
+
if (err.type === API_VALIDATION_ERROR) {
|
|
27
|
+
return res.json({ message: err.message }).status(400);
|
|
28
|
+
}
|
|
29
|
+
if (err.type === FIRST_METHOD_ERROR) {
|
|
30
|
+
const errArray = err.stack?.split(/\n/g) || [];
|
|
31
|
+
const errorPath = this.getErrorPath(errArray);
|
|
32
|
+
return DisplayError.show(errorPath, err.message, res);
|
|
33
|
+
}
|
|
34
|
+
return res
|
|
35
|
+
.json({
|
|
36
|
+
message: err.message,
|
|
37
|
+
stack: err.stack,
|
|
38
|
+
})
|
|
39
|
+
.status(statusCode || 500);
|
|
40
|
+
});
|
|
33
41
|
}
|
|
34
42
|
}
|
|
35
|
-
exports.AppErrorHandler = AppErrorHandler;
|