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.
- package/cli.js +17 -1
- package/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/index.js +26 -20
- package/lib/App.js +16 -13
- package/lib/Auth/AuthMiddleware.js +6 -3
- package/lib/Auth/index.js +10 -5
- package/lib/Command-Line/NodeArtisanCommand.js +21 -14
- package/lib/Command-Line/command.js +34 -29
- package/lib/Command-Line/files/Controller.js +3 -1
- package/lib/Command-Line/files/Migration.js +3 -1
- package/lib/Command-Line/files/Models.js +3 -1
- package/lib/Command-Line/files/Request.js +3 -1
- package/lib/Command-Line/files/ResourcesController.js +3 -1
- package/lib/Command-Line/utils.js +5 -1
- package/lib/Config/Config.d.ts +2 -2
- package/lib/Config/Config.d.ts.map +1 -1
- package/lib/Config/Config.js +10 -4
- package/lib/Error/AppError.js +5 -1
- package/lib/Error/AppErrorHandler.js +11 -7
- package/lib/Error/Constants/error.js +45 -42
- package/lib/Error/Constants/index.js +6 -3
- package/lib/Error/DisplayErrorCode.js +11 -4
- package/lib/Error/ErrorHigtlig.js +10 -3
- package/lib/HttpKernel/HttpKernel.js +3 -1
- package/lib/Interface/index.js +2 -1
- package/lib/Middlewares/index.js +30 -23
- package/lib/Middlewares/isLogin.js +5 -1
- package/lib/Passport/config.js +17 -10
- package/lib/Request/FormRequest.js +5 -1
- package/lib/Request/request.js +10 -6
- package/lib/Response/index.js +5 -1
- package/lib/Routes/RouteBuilder.js +14 -10
- package/lib/Routes/Router.js +9 -5
- package/lib/Server/index.js +15 -8
- package/lib/Services/ServiceContainer.js +7 -4
- package/lib/Services/ServiceProvider.js +5 -1
- package/lib/Templating-engine/engineHelper.js +13 -6
- package/lib/Templating-engine/expressions.js +5 -1
- package/lib/Templating-engine/index.js +14 -8
- package/lib/Type/index.js +2 -1
- package/lib/Validation/index.js +11 -7
- package/lib/Validation/rules.js +10 -6
- package/lib/Validation/validate.js +54 -47
- package/lib/util/index.js +59 -37
- package/package.json +1 -1
|
@@ -1,42 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LOAD_RELATION_ERROR = exports.VALIDATE_RELATED_TYPE = exports.BUILD_ERROR_RELATION = exports.ALL_METHOD_ERROR = exports.CREATE_METHOD_ERROR = exports.AVG_METHOD_ERROR = exports.SUM_METHOD_ERROR = exports.MIN_METHOD_ERROR = exports.MAX_METHOD_ERROR = exports.COUNT_METHOD_ERROR = exports.NOT_EXIST_METHOD_ERROR = exports.EXISTS_METHOD_ERROR = exports.VALUE_METHOD_ERROR = exports.EACH_METHOD_ERROR = exports.MAP_METHOD_ERROR = exports.GET_METHOD_ERROR = exports.FIRST_METHOD_ERROR = exports.UPADTE_ERROR = exports.INSERT_ERROR = exports.INSTANCE_ERROR = exports.HIDDEN_VALUE_ERROR = exports.SCHEMA_CREATE_ERROR = exports.SQL_TABLE_ERROR = exports.DATE_TIMESTAMP_ERROR = exports.TIMESTAMP_ERROR = exports.DATE_FORMAT_ERROR = exports.CAST_ATTRIBUTE = exports.UNKNOWN_CAST_ERROR = exports.CASTING_TYPE_ERROR = exports.CAST_DAtA_ERROR = exports.PASSPORT_DESERIALIZE_ERROR = exports.PASSPORT_LOCAL_STRATEGY_ERROR = exports.JWT_SIGN_ERROR = exports.JWT_VERIFY_ERROR = exports.VALIDATION_RULE_ERROR = exports.VALIDATION_METHOD_ERROR = exports.DEFAULT_ENGINE_ERROR = exports.SERVICE_CONTAINER_ERROR = exports.ROUTE_BUILDER_ERROR = exports.ROUTE_CALLBACK_ERROR = exports.VALIDATION_ERROR = exports.API_VALIDATION_ERROR = void 0;
|
|
4
|
+
exports.API_VALIDATION_ERROR = "api_validation_errors";
|
|
5
|
+
exports.VALIDATION_ERROR = "validation_errors";
|
|
6
|
+
exports.ROUTE_CALLBACK_ERROR = "route_callback";
|
|
7
|
+
exports.ROUTE_BUILDER_ERROR = "route_builder";
|
|
8
|
+
exports.SERVICE_CONTAINER_ERROR = "serivce_container";
|
|
9
|
+
exports.DEFAULT_ENGINE_ERROR = "js_blade_engine";
|
|
10
|
+
exports.VALIDATION_METHOD_ERROR = "validation_method";
|
|
11
|
+
exports.VALIDATION_RULE_ERROR = "validation_error";
|
|
12
|
+
exports.JWT_VERIFY_ERROR = "jwt_verify_error";
|
|
13
|
+
exports.JWT_SIGN_ERROR = "jwt_sign";
|
|
14
|
+
exports.PASSPORT_LOCAL_STRATEGY_ERROR = "local_strategy_error";
|
|
15
|
+
exports.PASSPORT_DESERIALIZE_ERROR = "passport_deserialize_error";
|
|
16
|
+
exports.CAST_DAtA_ERROR = "cast_data_error";
|
|
17
|
+
exports.CASTING_TYPE_ERROR = "casting_type_error";
|
|
18
|
+
exports.UNKNOWN_CAST_ERROR = "unkown_cast_method";
|
|
19
|
+
exports.CAST_ATTRIBUTE = "cast_attribute_error";
|
|
20
|
+
exports.DATE_FORMAT_ERROR = "date_format_error";
|
|
21
|
+
exports.TIMESTAMP_ERROR = "timestamp_error";
|
|
22
|
+
exports.DATE_TIMESTAMP_ERROR = "date_timestamp_error";
|
|
23
|
+
exports.SQL_TABLE_ERROR = "sql_table_error";
|
|
24
|
+
exports.SCHEMA_CREATE_ERROR = "schema_create_error";
|
|
25
|
+
exports.HIDDEN_VALUE_ERROR = "hidden_value_error";
|
|
26
|
+
exports.INSTANCE_ERROR = "instance_error";
|
|
27
|
+
exports.INSERT_ERROR = "insert_error";
|
|
28
|
+
exports.UPADTE_ERROR = "update_error";
|
|
29
|
+
exports.FIRST_METHOD_ERROR = "first_method_error";
|
|
30
|
+
exports.GET_METHOD_ERROR = "get_method_error";
|
|
31
|
+
exports.MAP_METHOD_ERROR = "map_method_error";
|
|
32
|
+
exports.EACH_METHOD_ERROR = "each_method_error";
|
|
33
|
+
exports.VALUE_METHOD_ERROR = "value_method_error";
|
|
34
|
+
exports.EXISTS_METHOD_ERROR = "exists_method_error";
|
|
35
|
+
exports.NOT_EXIST_METHOD_ERROR = "not_exist_method_error";
|
|
36
|
+
exports.COUNT_METHOD_ERROR = "count_method_error";
|
|
37
|
+
exports.MAX_METHOD_ERROR = "max_method_error";
|
|
38
|
+
exports.MIN_METHOD_ERROR = "min_method_error";
|
|
39
|
+
exports.SUM_METHOD_ERROR = "sum_method_error";
|
|
40
|
+
exports.AVG_METHOD_ERROR = "avg_method_error";
|
|
41
|
+
exports.CREATE_METHOD_ERROR = "create_method_error";
|
|
42
|
+
exports.ALL_METHOD_ERROR = "all_method_error";
|
|
43
|
+
exports.BUILD_ERROR_RELATION = "build_relation_error";
|
|
44
|
+
exports.VALIDATE_RELATED_TYPE = "validate_related_type";
|
|
45
|
+
exports.LOAD_RELATION_ERROR = "load_relation_error";
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JWT_SECRET = exports.TEMPLATE_ENGINE = exports.PORT = void 0;
|
|
4
|
+
exports.PORT = "PORT";
|
|
5
|
+
exports.TEMPLATE_ENGINE = "TEMPLATE_ENGINE";
|
|
6
|
+
exports.JWT_SECRET = "JWT_SECRET";
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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.DisplayError = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const ErrorHigtlig_1 = require("./ErrorHigtlig");
|
|
9
|
+
class DisplayError extends ErrorHigtlig_1.ErrorSytnaxFunctionality {
|
|
4
10
|
static show(errorPath, message, res) {
|
|
5
11
|
// const d = ;
|
|
6
12
|
const paths = errorPath.replace(/\(|\)/g, "").split(/\//g);
|
|
7
13
|
const lastIndex = paths.length - 1;
|
|
8
14
|
const [actualPath, startLine, endLine] = paths[lastIndex].split(/\:/);
|
|
9
15
|
paths[lastIndex] = actualPath;
|
|
10
|
-
const code =
|
|
16
|
+
const code = fs_1.default.readFileSync(paths.join("/"), "utf8");
|
|
11
17
|
let content = code.split(/\n/g);
|
|
12
18
|
let newContent = content
|
|
13
19
|
.map((line, index) => `${index + 1}. ${line}`)
|
|
@@ -19,3 +25,4 @@ export class DisplayError extends ErrorSytnaxFunctionality {
|
|
|
19
25
|
return res.sendFile(__dirname + "/public/error.html");
|
|
20
26
|
}
|
|
21
27
|
}
|
|
28
|
+
exports.DisplayError = DisplayError;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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.ErrorSytnaxFunctionality = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
class ErrorSytnaxFunctionality {
|
|
3
9
|
static htmlCode(code, line, message) {
|
|
4
10
|
// <link rel="stylesheet" href="/css/main.css" />
|
|
5
11
|
return `
|
|
@@ -79,10 +85,11 @@ export class ErrorSytnaxFunctionality {
|
|
|
79
85
|
}
|
|
80
86
|
static codeCompiler(code, line, message) {
|
|
81
87
|
try {
|
|
82
|
-
return
|
|
88
|
+
return fs_1.default.writeFileSync(__dirname + "/public/error.html", this.htmlCode(code, line, message));
|
|
83
89
|
}
|
|
84
90
|
catch (error) {
|
|
85
91
|
console.log(error.message);
|
|
86
92
|
}
|
|
87
93
|
}
|
|
88
94
|
}
|
|
95
|
+
exports.ErrorSytnaxFunctionality = ErrorSytnaxFunctionality;
|
package/lib/Interface/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/lib/Middlewares/index.js
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
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.Middleware = void 0;
|
|
7
|
+
const app_root_path_1 = __importDefault(require("app-root-path"));
|
|
8
|
+
const passport_1 = __importDefault(require("passport"));
|
|
9
|
+
const isLogin_1 = require("./isLogin");
|
|
10
|
+
const Config_1 = require("../Config/Config");
|
|
11
|
+
const Templating_engine_1 = require("../Templating-engine");
|
|
12
|
+
const Response_1 = require("../Response");
|
|
13
|
+
const request_1 = require("../Request/request");
|
|
14
|
+
const Constants_1 = require("../Error/Constants");
|
|
15
|
+
const { Kernel } = require(`${app_root_path_1.default.path}/app/Http/kernel.ts`);
|
|
16
|
+
const { templateEngine } = require(`${app_root_path_1.default.path}/app/Config/engine.ts`);
|
|
17
|
+
const config_1 = require("../Passport/config");
|
|
12
18
|
//
|
|
13
|
-
|
|
19
|
+
class Middleware extends Kernel {
|
|
14
20
|
constructor(appExpress, app) {
|
|
15
21
|
super();
|
|
16
22
|
this.app = app;
|
|
@@ -48,8 +54,8 @@ export class Middleware extends Kernel {
|
|
|
48
54
|
* @returns {object} - Express application instance.
|
|
49
55
|
*/
|
|
50
56
|
defaultTemplatingEngine(app) {
|
|
51
|
-
app.engine("blade.html", jsBladeEngine.render.bind(jsBladeEngine));
|
|
52
|
-
app.set("views", `${
|
|
57
|
+
app.engine("blade.html", Templating_engine_1.jsBladeEngine.render.bind(Templating_engine_1.jsBladeEngine));
|
|
58
|
+
app.set("views", `${app_root_path_1.default.path}/resources/views`);
|
|
53
59
|
return app.set("view engine", ".blade.html");
|
|
54
60
|
}
|
|
55
61
|
/**
|
|
@@ -57,10 +63,10 @@ export class Middleware extends Kernel {
|
|
|
57
63
|
* @returns {object} - Express application instance.
|
|
58
64
|
*/
|
|
59
65
|
passportMiddleware() {
|
|
60
|
-
const passportAuth = new PassportAuth();
|
|
61
|
-
passportAuth.localPassport(
|
|
62
|
-
this.app.use(
|
|
63
|
-
return this.app.use(
|
|
66
|
+
const passportAuth = new config_1.PassportAuth();
|
|
67
|
+
passportAuth.localPassport(passport_1.default);
|
|
68
|
+
this.app.use(passport_1.default.initialize());
|
|
69
|
+
return this.app.use(passport_1.default.session());
|
|
64
70
|
}
|
|
65
71
|
/**
|
|
66
72
|
* Apply global middlewares.
|
|
@@ -75,8 +81,8 @@ export class Middleware extends Kernel {
|
|
|
75
81
|
*/
|
|
76
82
|
setEngine() {
|
|
77
83
|
try {
|
|
78
|
-
if (config.get(TEMPLATE_ENGINE) == "false" ||
|
|
79
|
-
!config.get(TEMPLATE_ENGINE)) {
|
|
84
|
+
if (Config_1.config.get(Constants_1.TEMPLATE_ENGINE) == "false" ||
|
|
85
|
+
!Config_1.config.get(Constants_1.TEMPLATE_ENGINE)) {
|
|
80
86
|
return this.defaultTemplatingEngine(this.app);
|
|
81
87
|
}
|
|
82
88
|
return templateEngine(this.app);
|
|
@@ -93,10 +99,11 @@ export class Middleware extends Kernel {
|
|
|
93
99
|
this.globalMiddlewares();
|
|
94
100
|
this.passportMiddleware();
|
|
95
101
|
app.use((req, res, next) => {
|
|
96
|
-
new HttpResponse(req, res);
|
|
97
|
-
new HttpRequest(req, res);
|
|
102
|
+
new Response_1.HttpResponse(req, res);
|
|
103
|
+
new request_1.HttpRequest(req, res);
|
|
98
104
|
next();
|
|
99
105
|
});
|
|
100
|
-
new isLogIn(this.app);
|
|
106
|
+
new isLogin_1.isLogIn(this.app);
|
|
101
107
|
}
|
|
102
108
|
}
|
|
109
|
+
exports.Middleware = Middleware;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isLogIn = void 0;
|
|
4
|
+
class isLogIn {
|
|
2
5
|
/**
|
|
3
6
|
* Initializes the middleware.
|
|
4
7
|
* @param {object} app - The Express application instance.
|
|
@@ -23,3 +26,4 @@ export class isLogIn {
|
|
|
23
26
|
});
|
|
24
27
|
}
|
|
25
28
|
}
|
|
29
|
+
exports.isLogIn = isLogIn;
|
package/lib/Passport/config.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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.PassportAuth = void 0;
|
|
7
|
+
const passport_local_1 = __importDefault(require("passport-local"));
|
|
8
|
+
const LocalStrategy = passport_local_1.default.Strategy;
|
|
9
|
+
const util_1 = require("../util");
|
|
10
|
+
const AppError_1 = require("../Error/AppError");
|
|
11
|
+
const error_1 = require("../Error/Constants/error");
|
|
12
|
+
const { User } = (0, util_1.getModel)("User.ts");
|
|
7
13
|
let db = new User();
|
|
8
|
-
|
|
14
|
+
class PassportAuth {
|
|
9
15
|
/**
|
|
10
16
|
* Configures Passport.js to use a local authentication strategy.
|
|
11
17
|
* This strategy validates user credentials against the local database.
|
|
@@ -30,7 +36,7 @@ export class PassportAuth {
|
|
|
30
36
|
return done(null, false, { message: "Invalid credentials" });
|
|
31
37
|
}
|
|
32
38
|
// Verifying password hash
|
|
33
|
-
const isMatch = await verifyHash(password, user.password);
|
|
39
|
+
const isMatch = await (0, util_1.verifyHash)(password, user.password);
|
|
34
40
|
// If password matches, return user
|
|
35
41
|
if (isMatch) {
|
|
36
42
|
return done(null, user);
|
|
@@ -40,7 +46,7 @@ export class PassportAuth {
|
|
|
40
46
|
}
|
|
41
47
|
catch (error) {
|
|
42
48
|
// Handling any errors that occur during authentication
|
|
43
|
-
throw new AppError(error.message, PASSPORT_LOCAL_STRATEGY_ERROR);
|
|
49
|
+
throw new AppError_1.AppError(error.message, error_1.PASSPORT_LOCAL_STRATEGY_ERROR);
|
|
44
50
|
}
|
|
45
51
|
}));
|
|
46
52
|
// Serializing user to be stored in the session
|
|
@@ -55,8 +61,9 @@ export class PassportAuth {
|
|
|
55
61
|
}
|
|
56
62
|
catch (error) {
|
|
57
63
|
// Handling any errors that occur during deserialization
|
|
58
|
-
new AppError(error.message, PASSPORT_DESERIALIZE_ERROR);
|
|
64
|
+
new AppError_1.AppError(error.message, error_1.PASSPORT_DESERIALIZE_ERROR);
|
|
59
65
|
}
|
|
60
66
|
});
|
|
61
67
|
}
|
|
62
68
|
}
|
|
69
|
+
exports.PassportAuth = PassportAuth;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FormRequest = void 0;
|
|
4
|
+
class FormRequest {
|
|
2
5
|
constructor(req) {
|
|
3
6
|
// Initializing FormRequest instance with the provided Express request object
|
|
4
7
|
this.req = req;
|
|
@@ -45,3 +48,4 @@ export class FormRequest {
|
|
|
45
48
|
return this.req.apiValidate(formData);
|
|
46
49
|
}
|
|
47
50
|
}
|
|
51
|
+
exports.FormRequest = FormRequest;
|
package/lib/Request/request.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpRequest = void 0;
|
|
4
|
+
const Validation_1 = require("../Validation");
|
|
5
|
+
const error_1 = require("../Error/Constants/error");
|
|
3
6
|
/**
|
|
4
7
|
* Initializes a Request object.
|
|
5
8
|
* This class helps in handling validation errors and provides methods for validation.
|
|
6
9
|
* @param {Object} request - The HTTP request object.
|
|
7
10
|
* @param {Object} response - The HTTP response object.
|
|
8
11
|
*/
|
|
9
|
-
|
|
12
|
+
class HttpRequest {
|
|
10
13
|
constructor(request, response) {
|
|
11
14
|
this.validationErrors(request, response);
|
|
12
15
|
}
|
|
@@ -19,14 +22,15 @@ export class HttpRequest {
|
|
|
19
22
|
const errors = {};
|
|
20
23
|
const flashError = request.flash("error") || [];
|
|
21
24
|
const flashOld = request.flash("old") || [];
|
|
22
|
-
const validationError = request.flash(VALIDATION_ERROR) || [];
|
|
25
|
+
const validationError = request.flash(error_1.VALIDATION_ERROR) || [];
|
|
23
26
|
errors["email"] = flashError[0] || "";
|
|
24
27
|
response.locals.errors = validationError[0];
|
|
25
28
|
response.locals.old = flashOld[0];
|
|
26
29
|
response.locals.error = errors;
|
|
27
30
|
// Adds a validate method to the request object for validation based on validationErrors
|
|
28
|
-
request.validate = async (validationData) => validateRequest(VALIDATION_ERROR, request, validationData);
|
|
29
|
-
request.apiValidate = async (validationData = {}) => validateRequest(API_VALIDATION_ERROR, request, validationData);
|
|
31
|
+
request.validate = async (validationData) => (0, Validation_1.validateRequest)(error_1.VALIDATION_ERROR, request, validationData);
|
|
32
|
+
request.apiValidate = async (validationData = {}) => (0, Validation_1.validateRequest)(error_1.API_VALIDATION_ERROR, request, validationData);
|
|
30
33
|
return;
|
|
31
34
|
}
|
|
32
35
|
}
|
|
36
|
+
exports.HttpRequest = HttpRequest;
|
package/lib/Response/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpResponse = void 0;
|
|
1
4
|
const reqUrls = [];
|
|
2
5
|
/**
|
|
3
6
|
* Initializes a Response object.
|
|
@@ -5,7 +8,7 @@ const reqUrls = [];
|
|
|
5
8
|
* @param {Object} request - The HTTP request object.
|
|
6
9
|
* @param {Object} response - The HTTP response object.
|
|
7
10
|
*/
|
|
8
|
-
|
|
11
|
+
class HttpResponse {
|
|
9
12
|
// private reqUrls: Array<string> = [];
|
|
10
13
|
constructor(request, response) {
|
|
11
14
|
this.request = request;
|
|
@@ -40,3 +43,4 @@ export class HttpResponse {
|
|
|
40
43
|
: this.response.redirect(reqUrls[0]);
|
|
41
44
|
}
|
|
42
45
|
}
|
|
46
|
+
exports.HttpResponse = HttpResponse;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RouteBuilder = void 0;
|
|
4
|
+
const AppError_1 = require("../Error/AppError");
|
|
5
|
+
const util_1 = require("../util");
|
|
6
|
+
const error_1 = require("../Error/Constants/error");
|
|
7
|
+
class RouteBuilder {
|
|
5
8
|
constructor(app, appPath) {
|
|
6
9
|
this.app = app;
|
|
7
10
|
this.basePath = appPath.basePath || "";
|
|
@@ -50,7 +53,7 @@ export class RouteBuilder {
|
|
|
50
53
|
const instance = new Controller();
|
|
51
54
|
return instance[method];
|
|
52
55
|
}
|
|
53
|
-
throw new AppError(`Method not define ${callback[0]}`, ROUTE_CALLBACK_ERROR);
|
|
56
|
+
throw new AppError_1.AppError(`Method not define ${callback[0]}`, error_1.ROUTE_CALLBACK_ERROR);
|
|
54
57
|
}
|
|
55
58
|
return callback;
|
|
56
59
|
}
|
|
@@ -70,17 +73,18 @@ export class RouteBuilder {
|
|
|
70
73
|
if (this.controllerValidator() && typeof callback === "string") {
|
|
71
74
|
const instance = new RouteBuilder.controller();
|
|
72
75
|
return middleware.length > 0
|
|
73
|
-
? this.app[httpMethod](this.resolvePath(url), middleware, asyncHandler(instance[callback]))
|
|
74
|
-
: this.app[httpMethod](this.resolvePath(url), asyncHandler(instance[callback]));
|
|
76
|
+
? this.app[httpMethod](this.resolvePath(url), middleware, (0, util_1.asyncHandler)(instance[callback]))
|
|
77
|
+
: this.app[httpMethod](this.resolvePath(url), (0, util_1.asyncHandler)(instance[callback]));
|
|
75
78
|
}
|
|
76
79
|
if (typeof callback === "function" || Array.isArray(callback)) {
|
|
77
80
|
return middleware.length > 0
|
|
78
|
-
? this.app[httpMethod](this.resolvePath(url), middleware, asyncHandler(this.validateCallback(callback)))
|
|
79
|
-
: this.app[httpMethod](this.resolvePath(url), asyncHandler(this.validateCallback(callback)));
|
|
81
|
+
? this.app[httpMethod](this.resolvePath(url), middleware, (0, util_1.asyncHandler)(this.validateCallback(callback)))
|
|
82
|
+
: this.app[httpMethod](this.resolvePath(url), (0, util_1.asyncHandler)(this.validateCallback(callback)));
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
catch (error) {
|
|
83
|
-
throw new AppError(error.message, ROUTE_BUILDER_ERROR);
|
|
86
|
+
throw new AppError_1.AppError(error.message, error_1.ROUTE_BUILDER_ERROR);
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
}
|
|
90
|
+
exports.RouteBuilder = RouteBuilder;
|
package/lib/Routes/Router.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Router = void 0;
|
|
4
|
+
const RouteBuilder_1 = require("./RouteBuilder");
|
|
5
|
+
class Router {
|
|
3
6
|
// protected basePath: string;
|
|
4
7
|
constructor(app, appPaths) {
|
|
5
8
|
// this.basePath = appPaths.basePath ||"";
|
|
6
9
|
this.app = app;
|
|
7
10
|
this.appPath = appPaths;
|
|
8
|
-
this.routeBuilder = new RouteBuilder(app, appPaths);
|
|
11
|
+
this.routeBuilder = new RouteBuilder_1.RouteBuilder(app, appPaths);
|
|
9
12
|
}
|
|
10
13
|
/**
|
|
11
14
|
* Sets the controller for the routes.
|
|
@@ -13,7 +16,7 @@ export class Router {
|
|
|
13
16
|
* @returns {Routes} - Returns the Routes instance.
|
|
14
17
|
*/
|
|
15
18
|
controller(controller) {
|
|
16
|
-
RouteBuilder.setController(controller);
|
|
19
|
+
RouteBuilder_1.RouteBuilder.setController(controller);
|
|
17
20
|
return this;
|
|
18
21
|
}
|
|
19
22
|
/**
|
|
@@ -31,7 +34,7 @@ export class Router {
|
|
|
31
34
|
* @returns {Router} - Returns the router instance.
|
|
32
35
|
*/
|
|
33
36
|
middleware(middleware) {
|
|
34
|
-
RouteBuilder.setMiddle(middleware);
|
|
37
|
+
RouteBuilder_1.RouteBuilder.setMiddle(middleware);
|
|
35
38
|
return this;
|
|
36
39
|
}
|
|
37
40
|
/**
|
|
@@ -89,3 +92,4 @@ export class Router {
|
|
|
89
92
|
return this.routeBuilder.buildRoute("delete", url, callback);
|
|
90
93
|
}
|
|
91
94
|
}
|
|
95
|
+
exports.Router = Router;
|
package/lib/Server/index.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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.HttpSever = void 0;
|
|
7
|
+
const express_1 = __importDefault(require("express"));
|
|
8
|
+
const net_1 = __importDefault(require("net"));
|
|
9
|
+
const AppErrorHandler_1 = require("../Error/AppErrorHandler");
|
|
10
|
+
class HttpSever {
|
|
5
11
|
constructor() {
|
|
6
|
-
this.express =
|
|
7
|
-
this.app =
|
|
12
|
+
this.express = express_1.default;
|
|
13
|
+
this.app = (0, express_1.default)();
|
|
8
14
|
}
|
|
9
15
|
server(port) {
|
|
10
|
-
const server =
|
|
16
|
+
const server = net_1.default.createServer();
|
|
11
17
|
// this.httpErrors();
|
|
12
18
|
server.once("error", (err) => {
|
|
13
19
|
if (err.code === "EADDRINUSE") {
|
|
@@ -31,8 +37,9 @@ export class HttpSever {
|
|
|
31
37
|
});
|
|
32
38
|
}
|
|
33
39
|
httpErrors(app) {
|
|
34
|
-
const error = new AppErrorHandler(app);
|
|
40
|
+
const error = new AppErrorHandler_1.AppErrorHandler(app);
|
|
35
41
|
error.errorRoutesHandler();
|
|
36
42
|
return error.handler(app);
|
|
37
43
|
}
|
|
38
44
|
}
|
|
45
|
+
exports.HttpSever = HttpSever;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.container = void 0;
|
|
4
|
+
const AppError_1 = require("../Error/AppError");
|
|
5
|
+
const error_1 = require("../Error/Constants/error");
|
|
3
6
|
class ServiceContainer {
|
|
4
7
|
constructor() {
|
|
5
8
|
this.services = new Map();
|
|
@@ -14,7 +17,7 @@ class ServiceContainer {
|
|
|
14
17
|
}
|
|
15
18
|
const service = this.services.get(key);
|
|
16
19
|
if (!service) {
|
|
17
|
-
throw new AppError(`Service ${key} not found`, SERVICE_CONTAINER_ERROR);
|
|
20
|
+
throw new AppError_1.AppError(`Service ${key} not found`, error_1.SERVICE_CONTAINER_ERROR);
|
|
18
21
|
}
|
|
19
22
|
const { Constructor, isSingleton } = service;
|
|
20
23
|
const instance = new Constructor();
|
|
@@ -24,4 +27,4 @@ class ServiceContainer {
|
|
|
24
27
|
return instance;
|
|
25
28
|
}
|
|
26
29
|
}
|
|
27
|
-
|
|
30
|
+
exports.container = new ServiceContainer();
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServiceProvier = void 0;
|
|
4
|
+
class ServiceProvier {
|
|
2
5
|
constructor(app) {
|
|
3
6
|
this.bootingCallbacks = [];
|
|
4
7
|
this.bootedCallbacks = [];
|
|
@@ -22,6 +25,7 @@ export class ServiceProvier {
|
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
27
|
}
|
|
28
|
+
exports.ServiceProvier = ServiceProvier;
|
|
25
29
|
ServiceProvier.publishes = [];
|
|
26
30
|
ServiceProvier.publishGroups = [];
|
|
27
31
|
/*
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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.EngineHelpers = void 0;
|
|
7
|
+
const expressions_1 = require("./expressions");
|
|
8
|
+
const app_root_path_1 = __importDefault(require("app-root-path"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
class EngineHelpers extends expressions_1.TemplateRegex {
|
|
5
11
|
//
|
|
6
12
|
/**
|
|
7
13
|
* Extracts content before and after a match within a string.
|
|
@@ -76,8 +82,8 @@ export class EngineHelpers extends TemplateRegex {
|
|
|
76
82
|
*/
|
|
77
83
|
readFile(path) {
|
|
78
84
|
const resolvePath = path.replace(/\./g, "/").replace(/\"/g, "");
|
|
79
|
-
return
|
|
80
|
-
.readFileSync(`${
|
|
85
|
+
return fs_1.default
|
|
86
|
+
.readFileSync(`${app_root_path_1.default.path}/resources/views/${resolvePath}.blade.html`)
|
|
81
87
|
.toString();
|
|
82
88
|
}
|
|
83
89
|
/**
|
|
@@ -118,3 +124,4 @@ export class EngineHelpers extends TemplateRegex {
|
|
|
118
124
|
}
|
|
119
125
|
}
|
|
120
126
|
}
|
|
127
|
+
exports.EngineHelpers = EngineHelpers;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TemplateRegex = void 0;
|
|
4
|
+
class TemplateRegex {
|
|
2
5
|
constructor() {
|
|
3
6
|
//
|
|
4
7
|
this.directives = {
|
|
@@ -14,3 +17,4 @@ export class TemplateRegex {
|
|
|
14
17
|
this.sectionRegex = /@section\((?<sectionValue>['"]([^'"]+)['"])\)(?<sectionBody>([\s\S\t\n\r]+?))(?<sectionEnd>@endsection)|@section\((?<placeholder>[\s\S]+?)\)/;
|
|
15
18
|
}
|
|
16
19
|
}
|
|
20
|
+
exports.TemplateRegex = TemplateRegex;
|