@expressots/core 1.8.0 → 1.9.0
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/lib/CHANGELOG.md +141 -134
- package/lib/cjs/application/application.js +3 -2
- package/lib/cjs/common/color-service.provider.js +46 -0
- package/lib/cjs/common/package-resolver.provider.js +35 -0
- package/lib/cjs/console/console.js +10 -33
- package/lib/cjs/controller/base-controller.js +0 -2
- package/lib/cjs/error/app-error.js +26 -0
- package/lib/cjs/error/error-handler-middleware.js +16 -5
- package/lib/cjs/error/index.js +3 -1
- package/lib/cjs/error/report.js +17 -24
- package/lib/cjs/index.js +1 -2
- package/lib/cjs/provider/dto-validator/dto-validator.provider.js +62 -0
- package/lib/cjs/{environment/env-validator.js → provider/environment/env-validator.provider.js} +16 -10
- package/lib/cjs/provider/index.js +11 -0
- package/lib/cjs/provider/logger/logger-service.js +114 -0
- package/lib/cjs/provider/provider-service.js +36 -0
- package/lib/cjs/types/application/application.d.ts.map +1 -1
- package/lib/cjs/types/common/color-service.provider.d.ts +30 -0
- package/lib/cjs/types/common/color-service.provider.d.ts.map +1 -0
- package/lib/cjs/types/common/package-resolver.provider.d.ts +9 -0
- package/lib/cjs/types/common/package-resolver.provider.d.ts.map +1 -0
- package/lib/cjs/types/console/console.d.ts +1 -1
- package/lib/cjs/types/console/console.d.ts.map +1 -1
- package/lib/cjs/types/controller/base-controller.d.ts.map +1 -1
- package/lib/cjs/types/error/app-error.d.ts +30 -0
- package/lib/cjs/types/error/app-error.d.ts.map +1 -0
- package/lib/cjs/types/error/error-handler-middleware.d.ts +3 -4
- package/lib/cjs/types/error/error-handler-middleware.d.ts.map +1 -1
- package/lib/cjs/types/error/index.d.ts +1 -0
- package/lib/cjs/types/error/index.d.ts.map +1 -1
- package/lib/cjs/types/error/report.d.ts +7 -11
- package/lib/cjs/types/error/report.d.ts.map +1 -1
- package/lib/cjs/types/index.d.ts +1 -2
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/cjs/types/provider/dto-validator/dto-validator.provider.d.ts +12 -0
- package/lib/cjs/types/provider/dto-validator/dto-validator.provider.d.ts.map +1 -0
- package/lib/cjs/types/{environment/env-validator.d.ts → provider/environment/env-validator.provider.d.ts} +7 -4
- package/lib/cjs/types/provider/environment/env-validator.provider.d.ts.map +1 -0
- package/lib/cjs/types/provider/index.d.ts +5 -0
- package/lib/cjs/types/provider/index.d.ts.map +1 -0
- package/lib/cjs/types/provider/logger/logger-service.d.ts +50 -0
- package/lib/cjs/types/provider/logger/logger-service.d.ts.map +1 -0
- package/lib/cjs/types/{logger/general-logger.d.ts → provider/logger/winston-logger.d.ts} +1 -1
- package/lib/cjs/types/provider/logger/winston-logger.d.ts.map +1 -0
- package/lib/cjs/types/provider/provider-service.d.ts +31 -0
- package/lib/cjs/types/provider/provider-service.d.ts.map +1 -0
- package/lib/esm/application/application.js +3 -2
- package/lib/esm/common/color-service.provider.js +46 -0
- package/lib/esm/common/package-resolver.provider.js +35 -0
- package/lib/esm/console/console.js +10 -33
- package/lib/esm/controller/base-controller.js +0 -2
- package/lib/esm/error/app-error.js +37 -0
- package/lib/esm/error/error-handler-middleware.js +16 -5
- package/lib/esm/error/index.js +3 -1
- package/lib/esm/error/report.js +18 -23
- package/lib/esm/index.mjs +1 -2
- package/lib/esm/provider/dto-validator/dto-validator.provider.js +53 -0
- package/lib/esm/{environment/env-validator.js → provider/environment/env-validator.provider.js} +17 -10
- package/lib/esm/provider/index.js +11 -0
- package/lib/esm/provider/logger/logger-service.js +115 -0
- package/lib/esm/provider/provider-service.js +38 -0
- package/lib/esm/types/application/application.d.ts.map +1 -1
- package/lib/esm/types/common/color-service.provider.d.ts +30 -0
- package/lib/esm/types/common/color-service.provider.d.ts.map +1 -0
- package/lib/esm/types/common/package-resolver.provider.d.ts +9 -0
- package/lib/esm/types/common/package-resolver.provider.d.ts.map +1 -0
- package/lib/esm/types/console/console.d.ts +1 -1
- package/lib/esm/types/console/console.d.ts.map +1 -1
- package/lib/esm/types/controller/base-controller.d.ts.map +1 -1
- package/lib/esm/types/error/app-error.d.ts +30 -0
- package/lib/esm/types/error/app-error.d.ts.map +1 -0
- package/lib/esm/types/error/error-handler-middleware.d.ts +3 -4
- package/lib/esm/types/error/error-handler-middleware.d.ts.map +1 -1
- package/lib/esm/types/error/index.d.ts +1 -0
- package/lib/esm/types/error/index.d.ts.map +1 -1
- package/lib/esm/types/error/report.d.ts +7 -11
- package/lib/esm/types/error/report.d.ts.map +1 -1
- package/lib/esm/types/index.d.ts +1 -2
- package/lib/esm/types/index.d.ts.map +1 -1
- package/lib/esm/types/provider/dto-validator/dto-validator.provider.d.ts +12 -0
- package/lib/esm/types/provider/dto-validator/dto-validator.provider.d.ts.map +1 -0
- package/lib/esm/types/{environment/env-validator.d.ts → provider/environment/env-validator.provider.d.ts} +7 -4
- package/lib/esm/types/provider/environment/env-validator.provider.d.ts.map +1 -0
- package/lib/esm/types/provider/index.d.ts +5 -0
- package/lib/esm/types/provider/index.d.ts.map +1 -0
- package/lib/esm/types/provider/logger/logger-service.d.ts +50 -0
- package/lib/esm/types/provider/logger/logger-service.d.ts.map +1 -0
- package/lib/esm/types/{logger/general-logger.d.ts → provider/logger/winston-logger.d.ts} +1 -1
- package/lib/esm/types/provider/logger/winston-logger.d.ts.map +1 -0
- package/lib/esm/types/provider/provider-service.d.ts +31 -0
- package/lib/esm/types/provider/provider-service.d.ts.map +1 -0
- package/lib/package.json +7 -6
- package/package.json +7 -6
- package/lib/cjs/environment/index.js +0 -5
- package/lib/cjs/logger/index.js +0 -7
- package/lib/cjs/types/environment/env-validator.d.ts.map +0 -1
- package/lib/cjs/types/environment/index.d.ts +0 -2
- package/lib/cjs/types/environment/index.d.ts.map +0 -1
- package/lib/cjs/types/logger/general-logger.d.ts.map +0 -1
- package/lib/cjs/types/logger/index.d.ts +0 -2
- package/lib/cjs/types/logger/index.d.ts.map +0 -1
- package/lib/esm/environment/index.js +0 -5
- package/lib/esm/logger/index.js +0 -7
- package/lib/esm/types/environment/env-validator.d.ts.map +0 -1
- package/lib/esm/types/environment/index.d.ts +0 -2
- package/lib/esm/types/environment/index.d.ts.map +0 -1
- package/lib/esm/types/logger/general-logger.d.ts.map +0 -1
- package/lib/esm/types/logger/index.d.ts +0 -2
- package/lib/esm/types/logger/index.d.ts.map +0 -1
- /package/lib/cjs/{logger/general-logger.js → provider/logger/winston-logger.js} +0 -0
- /package/lib/esm/{logger/general-logger.js → provider/logger/winston-logger.js} +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The AppError class extends the built-in Error class in JavaScript,
|
|
6
|
+
* providing additional properties to manage custom application errors.
|
|
7
|
+
* It captures detailed information about the error, including a status code
|
|
8
|
+
* and an optional service identifier, which can be useful for error handling
|
|
9
|
+
* and logging within the application.
|
|
10
|
+
*
|
|
11
|
+
* @extends {Error}
|
|
12
|
+
*/
|
|
13
|
+
class AppError extends Error {
|
|
14
|
+
/**
|
|
15
|
+
* @param {string} message - The error message to be displayed.
|
|
16
|
+
* @param {number} [statusCode=500] - The HTTP status code associated with the error (default: 500).
|
|
17
|
+
* @param {string} [service] - The service identifier associated with the error.
|
|
18
|
+
*/
|
|
19
|
+
constructor(message, statusCode = 500, service) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.statusCode = statusCode;
|
|
22
|
+
this.service = service;
|
|
23
|
+
Error.captureStackTrace(this, this.constructor);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.AppError = AppError;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const app_error_1 = require("./app-error");
|
|
3
4
|
const status_code_1 = require("./status-code");
|
|
4
5
|
/**
|
|
5
6
|
* errorHandler is a custom Express error-handling middleware function.
|
|
@@ -9,9 +10,19 @@ const status_code_1 = require("./status-code");
|
|
|
9
10
|
* @param res - The Express response object.
|
|
10
11
|
* @param next - The Express next function for passing control to the next middleware function.
|
|
11
12
|
*/
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
function defaultErrorHandler(error, req, res,
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
15
|
+
next) {
|
|
16
|
+
if (error instanceof app_error_1.AppError) {
|
|
17
|
+
res
|
|
18
|
+
.status(error.statusCode)
|
|
19
|
+
.json({ statusCode: error.statusCode, error: error.message });
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
res.status(status_code_1.StatusCode.InternalServerError).json({
|
|
23
|
+
statusCode: status_code_1.StatusCode.InternalServerError,
|
|
24
|
+
error: "An unexpected error occurred.",
|
|
25
|
+
});
|
|
26
|
+
}
|
|
16
27
|
}
|
|
17
|
-
exports.default =
|
|
28
|
+
exports.default = defaultErrorHandler;
|
package/lib/cjs/error/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Report = exports.StatusCode = void 0;
|
|
3
|
+
exports.AppError = exports.Report = exports.StatusCode = void 0;
|
|
4
4
|
var status_code_1 = require("./status-code");
|
|
5
5
|
Object.defineProperty(exports, "StatusCode", { enumerable: true, get: function () { return status_code_1.StatusCode; } });
|
|
6
6
|
var report_1 = require("./report");
|
|
7
7
|
Object.defineProperty(exports, "Report", { enumerable: true, get: function () { return report_1.Report; } });
|
|
8
|
+
var app_error_1 = require("./app-error");
|
|
9
|
+
Object.defineProperty(exports, "AppError", { enumerable: true, get: function () { return app_error_1.AppError; } });
|
package/lib/cjs/error/report.js
CHANGED
|
@@ -5,57 +5,50 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
8
11
|
var Report_1;
|
|
9
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
13
|
exports.Report = void 0;
|
|
11
14
|
const inversify_binding_decorators_1 = require("inversify-binding-decorators");
|
|
12
|
-
const
|
|
15
|
+
const logger_service_1 = require("../provider/logger/logger-service");
|
|
16
|
+
const app_error_1 = require("./app-error");
|
|
13
17
|
/**
|
|
14
18
|
* Report class is a utility class to manage and log errors within the application.
|
|
15
19
|
* It is responsible for creating a standardized error object, logging it,
|
|
16
20
|
* and then throwing the error for further handling.
|
|
17
21
|
*/
|
|
18
22
|
let Report = Report_1 = class Report {
|
|
23
|
+
constructor() {
|
|
24
|
+
this.logger = new logger_service_1.Logger();
|
|
25
|
+
}
|
|
19
26
|
/**
|
|
20
27
|
* The Error method is responsible for generating a standardized error object,
|
|
21
28
|
* logging the error, and then throwing it for further handling.
|
|
22
|
-
* The error thrown is of the custom type
|
|
29
|
+
* The error thrown is of the custom type AppError, which extends the built-in Error class.
|
|
23
30
|
*
|
|
24
31
|
* @param error - An instance of Error or a string that describes the error.
|
|
25
32
|
* @param statusCode - The HTTP status code associated with the error (default is 500).
|
|
26
33
|
* @param service - The service name associated with the error. If not specified,
|
|
27
34
|
* it defaults to the name of the calling function.
|
|
28
35
|
*
|
|
29
|
-
* @throws An object of the custom type
|
|
36
|
+
* @throws An object of the custom type AppError, which includes details about the error.
|
|
30
37
|
*/
|
|
31
|
-
|
|
32
|
-
var _a, _b;
|
|
38
|
+
error(error, statusCode, service) {
|
|
33
39
|
let appError = {};
|
|
34
|
-
Error.captureStackTrace(this, this.Error);
|
|
35
|
-
const callerName = (_b = (_a = this.stack.split("\n")[1]) === null || _a === void 0 ? void 0 : _a.trim()) === null || _b === void 0 ? void 0 : _b.split(" ")[1];
|
|
36
40
|
if (error instanceof Error) {
|
|
37
|
-
appError =
|
|
38
|
-
statusCode: statusCode !== null && statusCode !== void 0 ? statusCode : 500,
|
|
39
|
-
message: error.message,
|
|
40
|
-
service: service !== null && service !== void 0 ? service : callerName,
|
|
41
|
-
name: error.name,
|
|
42
|
-
stack: error.stack,
|
|
43
|
-
};
|
|
41
|
+
appError = new app_error_1.AppError(error.message, statusCode, service);
|
|
44
42
|
}
|
|
45
43
|
else {
|
|
46
|
-
appError =
|
|
47
|
-
statusCode: statusCode !== null && statusCode !== void 0 ? statusCode : 500,
|
|
48
|
-
message: error,
|
|
49
|
-
service: service !== null && service !== void 0 ? service : callerName,
|
|
50
|
-
name: this.Error.name,
|
|
51
|
-
stack: this.stack,
|
|
52
|
-
};
|
|
44
|
+
appError = new app_error_1.AppError(error, statusCode, service);
|
|
53
45
|
}
|
|
54
|
-
|
|
55
|
-
|
|
46
|
+
this.logger.error(appError.message, appError.service || "service-undefined");
|
|
47
|
+
return appError;
|
|
56
48
|
}
|
|
57
49
|
};
|
|
58
50
|
exports.Report = Report;
|
|
59
51
|
exports.Report = Report = Report_1 = __decorate([
|
|
60
|
-
(0, inversify_binding_decorators_1.provide)(Report_1)
|
|
52
|
+
(0, inversify_binding_decorators_1.provide)(Report_1),
|
|
53
|
+
__metadata("design:paramtypes", [])
|
|
61
54
|
], Report);
|
package/lib/cjs/index.js
CHANGED
|
@@ -20,7 +20,6 @@ __exportStar(require("./console"), exports);
|
|
|
20
20
|
__exportStar(require("./container-module"), exports);
|
|
21
21
|
__exportStar(require("./controller"), exports);
|
|
22
22
|
__exportStar(require("./decorator"), exports);
|
|
23
|
-
__exportStar(require("./environment"), exports);
|
|
24
23
|
__exportStar(require("./error"), exports);
|
|
25
|
-
__exportStar(require("./
|
|
24
|
+
__exportStar(require("./provider"), exports);
|
|
26
25
|
__exportStar(require("./render"), exports);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ValidateDTO = void 0;
|
|
13
|
+
require("reflect-metadata");
|
|
14
|
+
const status_code_1 = require("../../error/status-code");
|
|
15
|
+
const package_resolver_provider_1 = require("../../common/package-resolver.provider");
|
|
16
|
+
const logger_service_1 = require("../logger/logger-service");
|
|
17
|
+
/**
|
|
18
|
+
* Validate the DTO using class-validator and class-transformer.
|
|
19
|
+
* @param type - The type of the DTO to validate.
|
|
20
|
+
* @returns A RequestHandler function.
|
|
21
|
+
* @throws An exception if the DTO is invalid.
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
function ValidateDTO(type) {
|
|
25
|
+
return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const logger = new logger_service_1.Logger();
|
|
27
|
+
const classValidator = (0, package_resolver_provider_1.packageResolver)("class-validator");
|
|
28
|
+
const classTransformer = (0, package_resolver_provider_1.packageResolver)("class-transformer");
|
|
29
|
+
if (!classValidator || !classTransformer) {
|
|
30
|
+
return next();
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const errors = yield classValidator.validate(classTransformer.plainToClass(type, req.body));
|
|
34
|
+
if (errors.length > 0) {
|
|
35
|
+
const DTO = errors.reduce((acc, error) => {
|
|
36
|
+
if (error.constraints) {
|
|
37
|
+
const propertyName = error.property;
|
|
38
|
+
if (!acc.some((e) => e.property === propertyName)) {
|
|
39
|
+
acc.push({ property: propertyName, messages: [] });
|
|
40
|
+
}
|
|
41
|
+
const target = acc.find((e) => e.property === propertyName);
|
|
42
|
+
target.messages.push(...Object.values(error.constraints));
|
|
43
|
+
}
|
|
44
|
+
return acc;
|
|
45
|
+
}, []);
|
|
46
|
+
res.status(status_code_1.StatusCode.BadRequest).json({
|
|
47
|
+
errorCode: status_code_1.StatusCode.BadRequest,
|
|
48
|
+
errorMessage: "Bad Request",
|
|
49
|
+
DTO,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
next();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
logger.error(`An exception occurred while validating the DTO: ${error}`, "validate-dto-provider");
|
|
58
|
+
next(error);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
exports.ValidateDTO = ValidateDTO;
|
package/lib/cjs/{environment/env-validator.js → provider/environment/env-validator.provider.js}
RENAMED
|
@@ -5,31 +5,36 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
8
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
13
|
};
|
|
11
14
|
var EnvValidatorProvider_1;
|
|
12
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.
|
|
16
|
+
exports.EnvValidatorProvider = void 0;
|
|
14
17
|
const fs_1 = __importDefault(require("fs"));
|
|
15
18
|
const path_1 = __importDefault(require("path"));
|
|
16
19
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
17
20
|
const inversify_binding_decorators_1 = require("inversify-binding-decorators");
|
|
18
|
-
const
|
|
21
|
+
const logger_service_1 = require("../logger/logger-service");
|
|
19
22
|
/**
|
|
20
23
|
* The EnvValidatorProvider class provides utility methods for working with environment variables.
|
|
21
24
|
* It validates, loads, and retrieves environment variables from the .env file.
|
|
22
25
|
* @provide EnvValidatorProvider
|
|
23
26
|
*/
|
|
24
27
|
let EnvValidatorProvider = EnvValidatorProvider_1 = class EnvValidatorProvider {
|
|
28
|
+
constructor() {
|
|
29
|
+
this.logger = new logger_service_1.Logger();
|
|
30
|
+
}
|
|
25
31
|
/**
|
|
26
32
|
* Retrieves the value of an environment variable, or a default value if the variable is not set.
|
|
27
33
|
* @param key - The key of the environment variable.
|
|
28
34
|
* @param defaultValue - The default value to return if the environment variable is not set.
|
|
29
35
|
* @returns The value of the environment variable, or the default value if not set.
|
|
30
36
|
*/
|
|
31
|
-
|
|
32
|
-
static get(key, defaultValue = undefined) {
|
|
37
|
+
get(key, defaultValue = undefined) {
|
|
33
38
|
var _a;
|
|
34
39
|
return (_a = process.env[key]) !== null && _a !== void 0 ? _a : defaultValue;
|
|
35
40
|
}
|
|
@@ -37,12 +42,12 @@ let EnvValidatorProvider = EnvValidatorProvider_1 = class EnvValidatorProvider {
|
|
|
37
42
|
* Validates and loads all environment variables from the .env file.
|
|
38
43
|
* If the .env file does not exist or any environment variables are not set, the process will exit with an error.
|
|
39
44
|
*/
|
|
40
|
-
|
|
45
|
+
checkAll() {
|
|
41
46
|
// Get the full path of the .env file
|
|
42
47
|
const envFilePath = path_1.default.join(process.cwd(), ".", ".env");
|
|
43
48
|
// Check if the .env file exists
|
|
44
49
|
if (!fs_1.default.existsSync(envFilePath)) {
|
|
45
|
-
|
|
50
|
+
this.logger.error("Environment file .env is not defined.", "env-validator-provider");
|
|
46
51
|
process.exit(1);
|
|
47
52
|
}
|
|
48
53
|
// Load the environment variables from the .env file
|
|
@@ -54,7 +59,7 @@ let EnvValidatorProvider = EnvValidatorProvider_1 = class EnvValidatorProvider {
|
|
|
54
59
|
for (const key of Object.keys(dotEnvParsed)) {
|
|
55
60
|
// Check if the environment variable is not defined or is an empty string
|
|
56
61
|
if (!process.env[key] || process.env[key] === "") {
|
|
57
|
-
|
|
62
|
+
this.logger.error(`Environment variable ${key} is not defined.`, "env-validator-provider");
|
|
58
63
|
hasError = true;
|
|
59
64
|
}
|
|
60
65
|
}
|
|
@@ -64,9 +69,10 @@ let EnvValidatorProvider = EnvValidatorProvider_1 = class EnvValidatorProvider {
|
|
|
64
69
|
}
|
|
65
70
|
}
|
|
66
71
|
};
|
|
67
|
-
exports.
|
|
68
|
-
exports.
|
|
69
|
-
(0, inversify_binding_decorators_1.provide)(EnvValidatorProvider_1)
|
|
72
|
+
exports.EnvValidatorProvider = EnvValidatorProvider;
|
|
73
|
+
exports.EnvValidatorProvider = EnvValidatorProvider = EnvValidatorProvider_1 = __decorate([
|
|
74
|
+
(0, inversify_binding_decorators_1.provide)(EnvValidatorProvider_1),
|
|
75
|
+
__metadata("design:paramtypes", [])
|
|
70
76
|
], EnvValidatorProvider);
|
|
71
77
|
String.prototype.AsBoolean = function () {
|
|
72
78
|
switch (this.toLowerCase().trim()) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidateDTO = exports.EnvValidatorProvider = exports.Logger = exports.Provider = void 0;
|
|
4
|
+
var provider_service_1 = require("./provider-service");
|
|
5
|
+
Object.defineProperty(exports, "Provider", { enumerable: true, get: function () { return provider_service_1.Provider; } });
|
|
6
|
+
var logger_service_1 = require("./logger/logger-service");
|
|
7
|
+
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_service_1.Logger; } });
|
|
8
|
+
var env_validator_provider_1 = require("./environment/env-validator.provider");
|
|
9
|
+
Object.defineProperty(exports, "EnvValidatorProvider", { enumerable: true, get: function () { return env_validator_provider_1.EnvValidatorProvider; } });
|
|
10
|
+
var dto_validator_provider_1 = require("./dto-validator/dto-validator.provider");
|
|
11
|
+
Object.defineProperty(exports, "ValidateDTO", { enumerable: true, get: function () { return dto_validator_provider_1.ValidateDTO; } });
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var Logger_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.Logger = void 0;
|
|
14
|
+
const inversify_binding_decorators_1 = require("inversify-binding-decorators");
|
|
15
|
+
const color_service_provider_1 = require("../../common/color-service.provider");
|
|
16
|
+
/**
|
|
17
|
+
* Applies a specified color to a text string.
|
|
18
|
+
*
|
|
19
|
+
* @param text - The text to be colored.
|
|
20
|
+
* @param color - The color to be applied.
|
|
21
|
+
* @returns The colored text.
|
|
22
|
+
*/
|
|
23
|
+
function colorText(text, color) {
|
|
24
|
+
return `${color_service_provider_1.colorCodes[color]}${text}\x1b[0m`;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Class that provides logging functionality with colorized text.
|
|
28
|
+
*/
|
|
29
|
+
let Logger = Logger_1 = class Logger {
|
|
30
|
+
constructor() {
|
|
31
|
+
this.pid = process.pid;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Formats the log message with color, timestamps, and log levels.
|
|
35
|
+
*
|
|
36
|
+
* @param logLevel - The level of the log (e.g. INFO, WARN).
|
|
37
|
+
* @param message - The main log message.
|
|
38
|
+
* @param module - Optional module name.
|
|
39
|
+
* @returns The formatted log message.
|
|
40
|
+
*/
|
|
41
|
+
formatMessage(logLevel = "NONE", message, module) {
|
|
42
|
+
const localDate = new Date();
|
|
43
|
+
const options = {
|
|
44
|
+
year: "numeric",
|
|
45
|
+
month: "2-digit",
|
|
46
|
+
day: "2-digit",
|
|
47
|
+
hour: "2-digit",
|
|
48
|
+
minute: "2-digit",
|
|
49
|
+
second: "2-digit",
|
|
50
|
+
};
|
|
51
|
+
const timestamp = colorText(localDate.toLocaleString(undefined, options).replace(",", ""), "white");
|
|
52
|
+
let logColor;
|
|
53
|
+
switch (logLevel) {
|
|
54
|
+
case "INFO":
|
|
55
|
+
logColor = "blue";
|
|
56
|
+
break;
|
|
57
|
+
case "WARN":
|
|
58
|
+
logColor = "yellow";
|
|
59
|
+
break;
|
|
60
|
+
case "ERROR":
|
|
61
|
+
logColor = "red";
|
|
62
|
+
break;
|
|
63
|
+
default:
|
|
64
|
+
logColor = "none";
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
const formattedLogLevel = colorText(logLevel.padEnd(5, " "), logColor);
|
|
68
|
+
if (logLevel === "NONE") {
|
|
69
|
+
return `${colorText("[ExpressoTS]", "none")} ${timestamp} ${colorText("[PID:" + this.pid + "]", "none")} ${formattedLogLevel} [${colorText(module || "", "none")}] ${colorText(message, logColor)}\n`;
|
|
70
|
+
}
|
|
71
|
+
return `${colorText("[ExpressoTS]", "green")} ${timestamp} ${colorText("[PID:" + this.pid + "]", "green")} ${formattedLogLevel} [${colorText(module || "", "green")}] ${colorText(message, logColor)}\n`;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Logs a generic message.
|
|
75
|
+
*
|
|
76
|
+
* @param message - The message to log.
|
|
77
|
+
* @param module - Optional module name.
|
|
78
|
+
*/
|
|
79
|
+
msg(message, module) {
|
|
80
|
+
process.stdout.write(this.formatMessage("NONE", message, module));
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Logs an informational message.
|
|
84
|
+
*
|
|
85
|
+
* @param message - The message to log.
|
|
86
|
+
* @param module - Optional module name.
|
|
87
|
+
*/
|
|
88
|
+
info(message, module) {
|
|
89
|
+
process.stdout.write(this.formatMessage("INFO", message, module));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Logs a warning message.
|
|
93
|
+
*
|
|
94
|
+
* @param message - The message to log.
|
|
95
|
+
* @param module - Optional module name.
|
|
96
|
+
*/
|
|
97
|
+
warn(message, module) {
|
|
98
|
+
process.stdout.write(this.formatMessage("WARN", message, module));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Logs an error message.
|
|
102
|
+
*
|
|
103
|
+
* @param message - The message to log.
|
|
104
|
+
* @param module - Optional module name.
|
|
105
|
+
*/
|
|
106
|
+
error(message, module) {
|
|
107
|
+
process.stderr.write(this.formatMessage("ERROR", message, module));
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
exports.Logger = Logger;
|
|
111
|
+
exports.Logger = Logger = Logger_1 = __decorate([
|
|
112
|
+
(0, inversify_binding_decorators_1.provide)(Logger_1),
|
|
113
|
+
__metadata("design:paramtypes", [])
|
|
114
|
+
], Logger);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var Provider_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.Provider = void 0;
|
|
14
|
+
const decorator_1 = require("../decorator");
|
|
15
|
+
const logger_service_1 = require("./logger/logger-service");
|
|
16
|
+
const env_validator_provider_1 = require("./environment/env-validator.provider");
|
|
17
|
+
/**
|
|
18
|
+
* Class responsible for providing singleton instances of various services.
|
|
19
|
+
*
|
|
20
|
+
* This class implements the IProvider interface and is decorated with a
|
|
21
|
+
* singleton provider to ensure a single instance is reused.
|
|
22
|
+
*/
|
|
23
|
+
let Provider = Provider_1 = class Provider {
|
|
24
|
+
/**
|
|
25
|
+
* Initializes the instances of the various providers.
|
|
26
|
+
*/
|
|
27
|
+
constructor() {
|
|
28
|
+
this.envValidator = new env_validator_provider_1.EnvValidatorProvider();
|
|
29
|
+
this.logger = new logger_service_1.Logger();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
exports.Provider = Provider;
|
|
33
|
+
exports.Provider = Provider = Provider_1 = __decorate([
|
|
34
|
+
(0, decorator_1.provideSingleton)(Provider_1),
|
|
35
|
+
__metadata("design:paramtypes", [])
|
|
36
|
+
], Provider);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/application/application.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,OAAO,EAAW,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAE3E,OAAO,EAAe,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAE/D;;GAEG;AACH,aAAK,iBAAiB;IACpB,WAAW,gBAAgB;IAC3B,OAAO,YAAY;IACnB,UAAU,eAAe;CAC1B;AAED;;;GAGG;AACH,cACM,WAAW;IACf,OAAO,CAAC,GAAG,CAAsB;IACjC,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,WAAW,CAAoB;IAEvC;;OAEG;;IAGH;;OAEG;IACH,SAAS,CAAC,iBAAiB,IAAI,IAAI;IAEnC;;OAEG;IACH,SAAS,CAAC,wBAAwB,IAAI,IAAI;IAE1C;;OAEG;IACH,SAAS,CAAC,cAAc,IAAI,IAAI;IAEhC;;OAEG;IACH,OAAO,CAAC,UAAU;IAKlB;;;;;OAKG;IACI,MAAM,CACX,SAAS,EAAE,SAAS,EACpB,WAAW,GAAE,KAAK,CAAC,OAAO,CAAC,cAAc,CAAM,GAC9C,WAAW;
|
|
1
|
+
{"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/application/application.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,OAAO,EAAW,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAE3E,OAAO,EAAe,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAE/D;;GAEG;AACH,aAAK,iBAAiB;IACpB,WAAW,gBAAgB;IAC3B,OAAO,YAAY;IACnB,UAAU,eAAe;CAC1B;AAED;;;GAGG;AACH,cACM,WAAW;IACf,OAAO,CAAC,GAAG,CAAsB;IACjC,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,WAAW,CAAoB;IAEvC;;OAEG;;IAGH;;OAEG;IACH,SAAS,CAAC,iBAAiB,IAAI,IAAI;IAEnC;;OAEG;IACH,SAAS,CAAC,wBAAwB,IAAI,IAAI;IAE1C;;OAEG;IACH,SAAS,CAAC,cAAc,IAAI,IAAI;IAEhC;;OAEG;IACH,OAAO,CAAC,UAAU;IAKlB;;;;;OAKG;IACI,MAAM,CACX,SAAS,EAAE,SAAS,EACpB,WAAW,GAAE,KAAK,CAAC,OAAO,CAAC,cAAc,CAAM,GAC9C,WAAW;IAqCd;;;;;OAKG;IACI,MAAM,CACX,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,iBAAiB,EAC9B,cAAc,CAAC,EAAE,4BAA4B,GAC5C,IAAI;IAuBP;;;;;;;;;;OAUG;IACI,SAAS,CAAC,CAAC,SAAS,qBAAqB,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI;CAQpE;AAED,QAAA,MAAM,iBAAiB,EAAE,WAA+B,CAAC;AAEzD,OAAO,EAAE,iBAAiB,IAAI,WAAW,EAAE,WAAW,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type representing supported text colors.
|
|
3
|
+
*/
|
|
4
|
+
type Color = "red" | "green" | "yellow" | "blue" | "white" | "black" | "none";
|
|
5
|
+
/**
|
|
6
|
+
* Mapping of text color codes.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Defines the ANSI escape codes for the corresponding colors in the terminal.
|
|
10
|
+
*/
|
|
11
|
+
declare const colorCodes: Record<Color, string>;
|
|
12
|
+
/**
|
|
13
|
+
* ANSI escape color codes mapping for different background colors.
|
|
14
|
+
*/
|
|
15
|
+
declare const bgColorCodes: Record<Color, string>;
|
|
16
|
+
/**
|
|
17
|
+
* Enum representing possible color styles for console output.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Enum values correspond to the string representations of colors.
|
|
21
|
+
*/
|
|
22
|
+
declare enum ColorStyle {
|
|
23
|
+
None = "none",
|
|
24
|
+
Yellow = "yellow",
|
|
25
|
+
Blue = "blue",
|
|
26
|
+
Green = "green",
|
|
27
|
+
Red = "red"
|
|
28
|
+
}
|
|
29
|
+
export { Color, ColorStyle, colorCodes, bgColorCodes };
|
|
30
|
+
//# sourceMappingURL=color-service.provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-service.provider.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/common/color-service.provider.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,KAAK,KAAK,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;AAE9E;;;;;GAKG;AACH,QAAA,MAAM,UAAU,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAQrC,CAAC;AAEF;;GAEG;AACH,QAAA,MAAM,YAAY,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAQvC,CAAC;AAEF;;;;;GAKG;AACH,aAAK,UAAU;IACb,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,KAAK,UAAU;IACf,GAAG,QAAQ;CACZ;AAED,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve package from the current working directory.
|
|
3
|
+
* @param packageName
|
|
4
|
+
* @param options
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
declare function packageResolver(packageName: string, ...options: Array<any>): any;
|
|
8
|
+
export { packageResolver };
|
|
9
|
+
//# sourceMappingURL=package-resolver.provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-resolver.provider.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/common/package-resolver.provider.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,iBAAS,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,GAAG,CA8BzE;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -22,7 +22,7 @@ declare class Console {
|
|
|
22
22
|
* @param environment - The server environment.
|
|
23
23
|
* @param consoleMessage - Optional application message details for console output.
|
|
24
24
|
*/
|
|
25
|
-
messageServer(port:
|
|
25
|
+
messageServer(port: number, environment: string, consoleMessage?: IApplicationMessageToConsole): Promise<void>;
|
|
26
26
|
}
|
|
27
27
|
export { Console, IApplicationMessageToConsole };
|
|
28
28
|
//# sourceMappingURL=console.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/console/console.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/console/console.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,UAAU,4BAA4B;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,cACM,OAAO;IACX;;;;OAIG;YACW,UAAU;IAWxB;;;;;OAKG;IACU,aAAa,CACxB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,cAAc,CAAC,EAAE,4BAA4B,GAC5C,OAAO,CAAC,IAAI,CAAC;CA6BjB;AAED,OAAO,EAAE,OAAO,EAAE,4BAA4B,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-controller.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/controller/base-controller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"base-controller.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/controller/base-controller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD;;;;GAIG;AACH,uBACe,cAAe,YAAW,UAAU,CAAC,UAAU;IAC5D,OAAO,CAAC,WAAW,CAAS;IAE5B;;;OAGG;gBACS,WAAW,GAAE,MAAW;IAIpC;;;;;OAKG;cACa,gBAAgB,CAC9B,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EACrB,GAAG,EAAE,GAAG,EACR,iBAAiB,EAAE,MAAM;IAK3B;;;;;OAKG;IACH,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM;IAIvE;;;;;;;;;;OAUG;IACH,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,KAAK,GAAG,IAAI;IAI5E;;;;;;;;;;OAUG;IACH,SAAS,CAAC,kBAAkB,CAC1B,GAAG,EAAE,QAAQ,EACb,QAAQ,EAAE,MAAM,EAChB,OAAO,KAAK,GACX,OAAO,CAAC,MAAM,CAAC;CAUnB;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The AppError class extends the built-in Error class in JavaScript,
|
|
3
|
+
* providing additional properties to manage custom application errors.
|
|
4
|
+
* It captures detailed information about the error, including a status code
|
|
5
|
+
* and an optional service identifier, which can be useful for error handling
|
|
6
|
+
* and logging within the application.
|
|
7
|
+
*
|
|
8
|
+
* @extends {Error}
|
|
9
|
+
*/
|
|
10
|
+
declare class AppError extends Error {
|
|
11
|
+
/**
|
|
12
|
+
* The HTTP status code associated with the error.
|
|
13
|
+
* Commonly used to define the HTTP response status code.
|
|
14
|
+
*/
|
|
15
|
+
statusCode: number;
|
|
16
|
+
/**
|
|
17
|
+
* The service identifier associated with the error.
|
|
18
|
+
* This property can be used to trace the origin of the error in the application.
|
|
19
|
+
* It is optional and can be left undefined.
|
|
20
|
+
*/
|
|
21
|
+
service?: string;
|
|
22
|
+
/**
|
|
23
|
+
* @param {string} message - The error message to be displayed.
|
|
24
|
+
* @param {number} [statusCode=500] - The HTTP status code associated with the error (default: 500).
|
|
25
|
+
* @param {string} [service] - The service identifier associated with the error.
|
|
26
|
+
*/
|
|
27
|
+
constructor(message: string, statusCode?: number, service?: string);
|
|
28
|
+
}
|
|
29
|
+
export { AppError };
|
|
30
|
+
//# sourceMappingURL=app-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-error.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/app-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,cAAM,QAAS,SAAQ,KAAK;IAC1B;;;OAGG;IACI,UAAU,EAAE,MAAM,CAAC;IAE1B;;;;OAIG;IACI,OAAO,CAAC,EAAE,MAAM,CAAC;IAExB;;;;OAIG;gBACS,OAAO,EAAE,MAAM,EAAE,UAAU,GAAE,MAAY,EAAE,OAAO,CAAC,EAAE,MAAM;CAMxE;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Request, Response } from "express";
|
|
2
|
-
import { IAppError } from "./report";
|
|
1
|
+
import { NextFunction, Request, Response } from "express";
|
|
3
2
|
/**
|
|
4
3
|
* errorHandler is a custom Express error-handling middleware function.
|
|
5
4
|
* It logs the error, sets the status code, and sends a JSON response containing the status code and error message.
|
|
@@ -8,6 +7,6 @@ import { IAppError } from "./report";
|
|
|
8
7
|
* @param res - The Express response object.
|
|
9
8
|
* @param next - The Express next function for passing control to the next middleware function.
|
|
10
9
|
*/
|
|
11
|
-
declare function
|
|
12
|
-
export default
|
|
10
|
+
declare function defaultErrorHandler(error: Error, req: Request, res: Response, next: NextFunction): void;
|
|
11
|
+
export default defaultErrorHandler;
|
|
13
12
|
//# sourceMappingURL=error-handler-middleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-handler-middleware.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/error-handler-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"error-handler-middleware.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/error-handler-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI1D;;;;;;;GAOG;AACH,iBAAS,mBAAmB,CAC1B,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EAEb,IAAI,EAAE,YAAY,GACjB,IAAI,CAWN;AAED,eAAe,mBAAmB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}
|