opticore-webapp 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/index.cjs +139 -667
  2. package/dist/index.d.cts +5 -378
  3. package/dist/index.d.ts +5 -378
  4. package/dist/index.js +146 -661
  5. package/package.json +7 -6
  6. package/src/application/service/core.service.ts +11 -8
  7. package/src/core/handlers/eventProcess.handler.ts +8 -5
  8. package/src/core/utils/logMessage.utils.ts +2 -2
  9. package/src/core/utils/modulesLoaded.utils.ts +5 -4
  10. package/src/core/webServer.core.ts +25 -21
  11. package/src/domains/interfaces/routeDefinition.interface.ts +2 -2
  12. package/src/domains/types/kernelModule.type.ts +1 -1
  13. package/src/index.ts +1 -10
  14. package/tsup.config.ts +1 -1
  15. package/src/application/http/response.http.ts +0 -67
  16. package/src/core/events/errors/serverListen.event.error.ts +0 -335
  17. package/src/core/events/requestCalls.event.ts +0 -83
  18. package/src/core/handlers/errors/base/stackTraceError.ts +0 -23
  19. package/src/core/handlers/errors/stackTraceAssertionError.ts +0 -13
  20. package/src/core/handlers/errors/stackTraceEvalError.ts +0 -12
  21. package/src/core/handlers/errors/stackTraceGeneralError.ts +0 -13
  22. package/src/core/handlers/errors/stackTraceOpenSSLError.ts +0 -12
  23. package/src/core/handlers/errors/stackTraceRangeError.ts +0 -12
  24. package/src/core/handlers/errors/stackTraceReferenceError.ts +0 -13
  25. package/src/core/handlers/errors/stackTraceSyntaxError.ts +0 -12
  26. package/src/core/handlers/errors/stackTraceSystemError.ts +0 -14
  27. package/src/core/handlers/errors/stackTraceTypeError.ts +0 -13
  28. package/src/core/handlers/errors/stackTraceURIError.ts +0 -13
  29. package/src/domains/constants/errorName.constant.ts +0 -12
  30. package/src/domains/constants/event.constant.ts +0 -15
  31. package/src/domains/constants/eventNameError.constant.ts +0 -8
  32. package/src/domains/constants/httpStatusCodes.constant.ts +0 -375
  33. package/src/domains/constants/logLevel.constant.ts +0 -6
  34. package/src/domains/env/access.env.ts +0 -23
  35. package/src/domains/interfaces/envVariables.interface.ts +0 -16
  36. package/src/domains/interfaces/kernelModule.interface.ts +0 -6
  37. package/src/infrastructure/events/.gitkeep +0 -0
  38. package/src/infrastructure/handlers/.gitkeep +0 -0
  39. package/src/presentation/middleware/.gitkeep +0 -0
  40. /package/src/core/{errors → events}/.gitkeep +0 -0
package/dist/index.js CHANGED
@@ -1,121 +1,118 @@
1
1
  // src/core/webServer.core.ts
2
- import express2 from "express";
3
2
  import corsOrigin from "cors";
4
-
5
- // src/domains/env/access.env.ts
6
- import dotenv from "dotenv";
7
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B;
8
- var getEnvVariable = {
9
- appHost: String((_b = (_a = dotenv.config()) == null ? void 0 : _a.parsed) == null ? void 0 : _b.APP_HOST),
10
- appPort: String((_d = (_c = dotenv.config()) == null ? void 0 : _c.parsed) == null ? void 0 : _d.APP_PORT),
11
- prodEnv: String((_f = (_e = dotenv.config()) == null ? void 0 : _e.parsed) == null ? void 0 : _f.ENV_PROD),
12
- devEnv: String((_h = (_g = dotenv.config()) == null ? void 0 : _g.parsed) == null ? void 0 : _h.ENV_DEV),
13
- dataBaseHost: String((_j = (_i = dotenv.config()) == null ? void 0 : _i.parsed) == null ? void 0 : _j.DATA_BASE_HOST),
14
- dataBasePort: String((_l = (_k = dotenv.config()) == null ? void 0 : _k.parsed) == null ? void 0 : _l.DATA_BASE_PORT),
15
- dataBaseUser: String((_n = (_m = dotenv.config()) == null ? void 0 : _m.parsed) == null ? void 0 : _n.DATA_BASE_USER),
16
- dataBasePassword: String((_p = (_o = dotenv.config()) == null ? void 0 : _o.parsed) == null ? void 0 : _p.DATA_BASE_PASSWORD),
17
- dataBaseName: String((_r = (_q = dotenv.config()) == null ? void 0 : _q.parsed) == null ? void 0 : _r.DATA_BASE_NAME),
18
- apiVersion: String((_t = (_s = dotenv.config()) == null ? void 0 : _s.parsed) == null ? void 0 : _t.API_VERSION),
19
- usernameField: String((_v = (_u = dotenv.config()) == null ? void 0 : _u.parsed) == null ? void 0 : _v.USERNAME_FIELD),
20
- passwordField: String((_x = (_w = dotenv.config()) == null ? void 0 : _w.parsed) == null ? void 0 : _x.PASSWORD_FIELD),
21
- argumentsDatabaseConnection: String((_z = (_y = dotenv.config()) == null ? void 0 : _y.parsed) == null ? void 0 : _z.ARGUMENTS_DATABASE_CONNECTION),
22
- logEnv: String((_B = (_A = dotenv.config()) == null ? void 0 : _A.parsed) == null ? void 0 : _B.LOG_ENVIRONMENT)
23
- };
24
-
25
- // src/domains/constants/httpStatusCodes.constant.ts
26
- var HttpStatusCodesConstant = /* @__PURE__ */ ((HttpStatusCodesConstant2) => {
27
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["CONTINUE"] = 100] = "CONTINUE";
28
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
29
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["PROCESSING"] = 102] = "PROCESSING";
30
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["OK"] = 200] = "OK";
31
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["CREATED"] = 201] = "CREATED";
32
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["ACCEPTED"] = 202] = "ACCEPTED";
33
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
34
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["NO_CONTENT"] = 204] = "NO_CONTENT";
35
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["RESET_CONTENT"] = 205] = "RESET_CONTENT";
36
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
37
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["MULTI_STATUS"] = 207] = "MULTI_STATUS";
38
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["ALREADY_REPORTED"] = 208] = "ALREADY_REPORTED";
39
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["IM_USED"] = 226] = "IM_USED";
40
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
41
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
42
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["FOUND"] = 302] = "FOUND";
43
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["SEE_OTHER"] = 303] = "SEE_OTHER";
44
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
45
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["USE_PROXY"] = 305] = "USE_PROXY";
46
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["SWITCH_PROXY"] = 306] = "SWITCH_PROXY";
47
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
48
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
49
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["BAD_REQUEST"] = 400] = "BAD_REQUEST";
50
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
51
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
52
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["FORBIDDEN"] = 403] = "FORBIDDEN";
53
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["NOT_FOUND"] = 404] = "NOT_FOUND";
54
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
55
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
56
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
57
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
58
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["CONFLICT"] = 409] = "CONFLICT";
59
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["GONE"] = 410] = "GONE";
60
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
61
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
62
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
63
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
64
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
65
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["RANGE_NOT_SATISFIABLE"] = 416] = "RANGE_NOT_SATISFIABLE";
66
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
67
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["I_AM_A_TEAPOT"] = 418] = "I_AM_A_TEAPOT";
68
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
69
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
70
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["LOCKED"] = 423] = "LOCKED";
71
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
72
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
73
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
74
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
75
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
76
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
77
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
78
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
79
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
80
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
81
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
82
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
83
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
84
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
85
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
86
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
87
- HttpStatusCodesConstant2[HttpStatusCodesConstant2["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
88
- return HttpStatusCodesConstant2;
89
- })(HttpStatusCodesConstant || {});
90
-
91
- // src/core/handlers/errors/base/stackTraceError.ts
92
- var StackTraceError = class extends Error {
93
- // Centralized error objet that derives from Node's Error.
94
- constructor(props, name, httpCode, isOperational) {
95
- super(props);
96
- Object.setPrototypeOf(this, new.target.prototype);
97
- this.name = name;
98
- this.httpCode = httpCode;
99
- this.isOperational = isOperational;
100
- Error.captureStackTrace(this);
101
- }
102
- };
3
+ import {
4
+ CEventNameError as eventName2,
5
+ StackTraceError as StackTraceError2,
6
+ ServerListenEventError as eventErrorOnListeningServer
7
+ } from "opticore-catch-exception-error";
8
+ import { express as express2 } from "opticore-express";
9
+ import { getEnvVariable } from "opticore-env-access";
10
+ import { requestCallsEvent } from "opticore-requests-called-events";
11
+ import { HttpStatusCode } from "opticore-http-response";
103
12
 
104
13
  // src/core/handlers/eventProcess.handler.ts
105
- import express from "express";
106
- import process2 from "node:process";
14
+ import process from "node:process";
107
15
  import EventEmitter from "node:events";
16
+ import { express } from "opticore-express";
17
+ import {
18
+ ServerListenEventError,
19
+ CEventNameError as eventName,
20
+ CEvent as event
21
+ } from "opticore-catch-exception-error";
22
+ function eventProcessHandler() {
23
+ const errorEmitter = new EventEmitter();
24
+ const app = express();
25
+ errorEmitter.on(eventName.error, (error) => {
26
+ ServerListenEventError.listenerError(error);
27
+ });
28
+ process.on(event.beforeExit, (code) => {
29
+ setTimeout(() => {
30
+ ServerListenEventError.processBeforeExit(code);
31
+ }, 100);
32
+ });
33
+ process.on(event.disconnect, () => {
34
+ ServerListenEventError.processDisconnected();
35
+ });
36
+ process.on(event.exit, (code) => {
37
+ ServerListenEventError.exited(code);
38
+ });
39
+ process.on(event.rejectionHandled, (promise) => {
40
+ ServerListenEventError.promiseRejectionHandled(promise);
41
+ });
42
+ process.on(event.uncaughtException, (error) => {
43
+ ServerListenEventError.uncaughtException(error);
44
+ });
45
+ process.on(event.uncaughtExceptionMonitor, (error) => {
46
+ ServerListenEventError.uncaughtExceptionMonitor(error);
47
+ });
48
+ process.on(event.unhandledRejection, (reason, promise) => {
49
+ ServerListenEventError.unhandledRejection(reason, promise);
50
+ });
51
+ process.on(event.warning, (warning) => {
52
+ ServerListenEventError.warning(warning);
53
+ });
54
+ process.on(event.message, (message) => {
55
+ ServerListenEventError.message(message);
56
+ });
57
+ process.on(event.multipleResolves, (type, promise, reason) => {
58
+ ServerListenEventError.multipleResolves(type, promise, reason);
59
+ });
60
+ process.on(event.sigint, () => {
61
+ ServerListenEventError.processInterrupted();
62
+ });
63
+ process.on(event.sigterm, (signal) => {
64
+ ServerListenEventError.sigtermSignalReceived(signal);
65
+ });
66
+ app.use((err, req, res, next) => {
67
+ ServerListenEventError.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
68
+ });
69
+ }
108
70
 
109
- // src/core/events/errors/serverListen.event.error.ts
110
- import process from "process";
111
- import colors2 from "ansi-colors";
71
+ // src/application/service/core.service.ts
72
+ import process2 from "node:process";
112
73
  import chalk from "chalk";
74
+ import * as path from "path";
75
+ import * as fs from "fs";
76
+ import colors4 from "ansi-colors";
77
+ import { HttpStatusCode as status } from "opticore-http-response";
78
+ import { StackTraceError } from "opticore-catch-exception-error";
79
+
80
+ // src/core/utils/modulesLoaded.utils.ts
81
+ import colors2 from "ansi-colors";
113
82
 
114
83
  // src/core/utils/dateTimeFormatted.utils.ts
115
84
  var dateTimeFormattedUtils = `${(/* @__PURE__ */ new Date()).getMonth()}-${(/* @__PURE__ */ new Date()).getDate()}-${(/* @__PURE__ */ new Date()).getFullYear()} ${(/* @__PURE__ */ new Date()).getHours()}:${(/* @__PURE__ */ new Date()).getMinutes()}:${(/* @__PURE__ */ new Date()).getSeconds()}`;
116
85
 
117
- // src/application/exceptions/messages.exception.ts
86
+ // src/core/utils/logMessage.utils.ts
118
87
  import colors from "ansi-colors";
88
+ var LogMessageUtils = class {
89
+ static success(title, action, contentAction) {
90
+ console.log(`${colors.green(`\u2714`)} ${colors.bgGreen(` ${colors.bold(`${colors.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${colors.bgGreen(`${colors.white(` Success `)}`)} [ ${action} ] ${contentAction} - [ Status ] ${colors.bgGreen(`${colors.white(` 200 `)}`)}`);
91
+ }
92
+ static warning(title, action, contentAction) {
93
+ console.warn(`${colors.yellow(`\u26A0\uFE0F`)} ${colors.bgYellow(` ${colors.bold(`${colors.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${colors.bgYellow(`${colors.white(` Warning `)}`)} ${contentAction}`);
94
+ }
95
+ static info(title, action, contentAction) {
96
+ console.info(`${colors.cyan(`\u24D8`)} ${colors.bgCyan(` ${colors.bold(`${colors.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${colors.bgCyan(`${colors.white(` Info `)}`)} ${contentAction}`);
97
+ }
98
+ static error(title, errorType, stackTrace, messageContent, httpCodeValue) {
99
+ console.error(`${colors.red(`\u2718`)} ${colors.bgRed(` ${colors.bold(`${colors.white(`${title}`)}`)} `)} | ${dateTimeFormattedUtils} | [ ${colors.red(`${colors.bold(` ${errorType} `)}`)} ] | [ ${colors.bold(`stack trace`)} ] ${colors.red(`${stackTrace}`)} - ${colors.red(`${messageContent}`)} - [ ${colors.red(`${colors.bold(` HttpCode `)}`)} ] ${colors.red(`${colors.bold(` ${httpCodeValue} `)}`)} `);
100
+ }
101
+ static requestError(title, errorName, errorMessage, errorCode) {
102
+ console.error(`[ ${colors.red(`${title}`)} ] ${dateTimeFormattedUtils} | ${colors.bgRed(`${colors.white(` ERROR `)}`)} ${colors.red(`[ ${errorName} ]`)} ${colors.red(`${errorMessage}`)} - [ Status ] ${colors.bgRed(`${colors.white(` ${errorCode} `)}`)}`);
103
+ }
104
+ };
105
+
106
+ // src/core/utils/modulesLoaded.utils.ts
107
+ function modulesLoadedUtils(allAppRoutes, dbConChecker) {
108
+ LogMessageUtils.success("Kernel", "load kernel", "Modules app have been successfully loaded");
109
+ console.log(`${colors2.whiteBright(` content`)} ${colors2.green("Kernel :")} ${colors2.cyan(`${colors2.bold(`server side`)}`)} has been loaded successfully ${colors2.green(`\u2714`)}`);
110
+ allAppRoutes ? console.log(`${colors2.whiteBright(` content`)} ${colors2.green("Kernel :")} ${colors2.cyan(`${colors2.bold(`Routers service`)} `)} has been loaded successfully ${colors2.green(`\u2714`)}`) : console.log(`${colors2.red(`\u2718`)} ${colors2.bgRed(` ${colors2.bold(`${colors2.white(` Register routes `)}`)} `)} | ${dateTimeFormattedUtils} | [ ${colors2.red(`${colors2.bold(` fail `)}`)} ] | [ ${colors2.bold(` loading `)} ] - ${colors2.red(` routers `)} - The route register failed to load `);
111
+ typeof dbConChecker == "function" ? console.log(`${colors2.whiteBright(` content`)} ${colors2.green("Kernel :")} ${colors2.cyan(`${colors2.bold(`database checker connection`)}`)} has been loaded successfully ${colors2.green(`\u2714`)}`) : "";
112
+ }
113
+
114
+ // src/application/exceptions/messages.exception.ts
115
+ import colors3 from "ansi-colors";
119
116
  var messageException = {
120
117
  dbConnection: "DataBase connection",
121
118
  dbConnectionClosed: "MySQL connection is closed",
@@ -179,485 +176,9 @@ var messageException = {
179
176
  errorHost: "The host can't be empty or blank. Please define a string host in .env",
180
177
  accessDeniedToDBCon: (user, password) => `Access denied for user ${user}. Database credentials in .env file are User: ${user} and Password: ${password}. '${user}''${password}'@'localhost'. Try to set user and password in .env file`,
181
178
  unknownDB: (database) => `Database ${database} is unknown. Please try to use Database CLI to create your database, or do it manually in your Database Management System`,
182
- errorDBHost: (host) => `A database host ${host} does not allow connection. Please either set the host like this: ${colors.bgRed(`${colors.white(`localhost`)}`)} in your .env file`
183
- };
184
-
185
- // src/domains/constants/eventNameError.constant.ts
186
- var CEventNameError = {
187
- error: "error",
188
- listening: "listening",
189
- close: "close",
190
- connection: "connection",
191
- drop: "drop",
192
- request: "request"
179
+ errorDBHost: (host) => `A database host ${host} does not allow connection. Please either set the host like this: ${colors3.bgRed(`${colors3.white(`localhost`)}`)} in your .env file`
193
180
  };
194
181
 
195
- // src/core/events/errors/serverListen.event.error.ts
196
- import { LoggerCore } from "opticore-logger";
197
- var ServerListenEventError = class {
198
- /**
199
- *
200
- */
201
- static hostPortUndefined() {
202
- this.stackTrace = this.traceError(messageException.errorHostUrl, messageException.listening, 400 /* BAD_REQUEST */);
203
- this.logger.error(this.stackTrace.message, messageException.webServer, messageException.badHost, this.stackTrace.stack, 400 /* BAD_REQUEST */);
204
- process.exit();
205
- }
206
- /**
207
- *
208
- */
209
- static hostUndefined() {
210
- this.stackTrace = this.traceError(messageException.badHost, messageException.listening, 400 /* BAD_REQUEST */);
211
- this.logger.error(this.stackTrace.message, messageException.webServer, messageException.badHost, this.stackTrace.stack, 400 /* BAD_REQUEST */);
212
- process.exit();
213
- }
214
- /**
215
- *
216
- */
217
- static portUndefined() {
218
- this.stackTrace = this.traceError(messageException.badPort, messageException.listening, 400 /* BAD_REQUEST */);
219
- this.logger.error(this.stackTrace.message, messageException.webServer, messageException.badHost, this.stackTrace.stack, 400 /* BAD_REQUEST */);
220
- process.exit();
221
- }
222
- /**
223
- *
224
- * @param err
225
- */
226
- static onEventError(err) {
227
- this.logger.error(err.message, "Server start error", "Error", err.stack, 503 /* SERVICE_UNAVAILABLE */);
228
- }
229
- /**
230
- *
231
- * @param error
232
- */
233
- static listenerError(error) {
234
- this.stackTrace = this.traceError(error.message, error.name, 400 /* BAD_REQUEST */);
235
- this.logger.error(this.stackTrace.message, "Event error", "Error", error.stack, 400 /* BAD_REQUEST */);
236
- }
237
- /**
238
- *
239
- * @param code
240
- */
241
- static processBeforeExit(code) {
242
- this.stackTrace = this.traceError(`Process will exit with code: ${code}`, "BeforeExit", 503 /* SERVICE_UNAVAILABLE */);
243
- this.logger.error(this.stackTrace.message, "BeforeExit", "process before exit", this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
244
- process.exit(code);
245
- }
246
- /**
247
- *
248
- */
249
- static processDisconnected() {
250
- this.stackTrace = this.traceError("Child process disconnected", "process disconnected", 503 /* SERVICE_UNAVAILABLE */);
251
- this.logger.error(this.stackTrace.message, "Disconnected", "process disconnected", this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
252
- process.exit();
253
- }
254
- /**
255
- *
256
- * @param code
257
- */
258
- static exited(code) {
259
- switch (code) {
260
- case 0:
261
- this.logger.success("completed", "The process finished as expected and everything is ok");
262
- console.log("");
263
- const paddingLength = 35;
264
- const msg0 = " ".padEnd(paddingLength, " ");
265
- console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, " ")));
266
- console.log(`${colors2.bgGreen(` [OK] The server shutting down `)}`);
267
- console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, " ")));
268
- break;
269
- case 1:
270
- this.stackTrace = this.traceError("Something went wrong", "General Errors", 503 /* SERVICE_UNAVAILABLE */);
271
- this.logger.error(this.stackTrace.message, "Exited", "General Errors", this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
272
- break;
273
- case 2:
274
- this.stackTrace = this.traceError("Incorrect using of shell commands", "Misuse of shell builtins", 503 /* SERVICE_UNAVAILABLE */);
275
- this.logger.error(this.stackTrace.message, "Exited", "Incorrect using of shell commands", this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
276
- break;
277
- case 126:
278
- this.stackTrace = this.traceError(
279
- "Incorrect using of shell commands",
280
- "The command is found but is not executable (e.g., trying to execute a directory)",
281
- 503 /* SERVICE_UNAVAILABLE */
282
- );
283
- this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
284
- break;
285
- case 127:
286
- this.stackTrace = this.traceError(
287
- "Command not found",
288
- "The command was not found in the system's PATH or is misspelled",
289
- 503 /* SERVICE_UNAVAILABLE */
290
- );
291
- this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
292
- break;
293
- case 128:
294
- this.stackTrace = this.traceError(
295
- "The command was not found in the system's PATH or is misspelled",
296
- "Invalid argument",
297
- 503 /* SERVICE_UNAVAILABLE */
298
- );
299
- this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
300
- break;
301
- case 130:
302
- this.stackTrace = this.traceError(
303
- "Indicates that the script was manually terminated by the user using the Control-C (SIGINT) signal",
304
- "Script terminated",
305
- 503 /* SERVICE_UNAVAILABLE */
306
- );
307
- this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
308
- break;
309
- case 137:
310
- this.stackTrace = this.traceError(
311
- "Indicates that the process was terminated by a SIGKILL signal, possibly due to an out-of-memory situation",
312
- "SIGKILL",
313
- 503 /* SERVICE_UNAVAILABLE */
314
- );
315
- this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
316
- break;
317
- case 139:
318
- this.stackTrace = this.traceError(
319
- "Indicates that the process accessed an illegal memory address (segfault)",
320
- "Segmentation fault",
321
- 503 /* SERVICE_UNAVAILABLE */
322
- );
323
- this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
324
- break;
325
- case 143:
326
- this.stackTrace = this.traceError(
327
- "Indicates that the process received a SIGTERM signal to terminate",
328
- "process received a SIGTERM",
329
- 503 /* SERVICE_UNAVAILABLE */
330
- );
331
- this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
332
- break;
333
- case 255:
334
- this.stackTrace = this.traceError(
335
- "An exit code that is outside the allowable range (0-255 for Unix-like systems)",
336
- "out of range",
337
- 503 /* SERVICE_UNAVAILABLE */
338
- );
339
- this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
340
- break;
341
- default:
342
- this.stackTrace = this.traceError(
343
- "Error is occurring",
344
- "errors",
345
- 503 /* SERVICE_UNAVAILABLE */
346
- );
347
- this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
348
- break;
349
- }
350
- }
351
- /**
352
- *
353
- * @param promise
354
- */
355
- static promiseRejectionHandled(promise) {
356
- this.stackTrace = this.traceError(
357
- `Promise rejection is handled at : ${promise}`,
358
- "rejection promise",
359
- 503 /* SERVICE_UNAVAILABLE */
360
- );
361
- this.logger.error(this.stackTrace.message, "PromiseRejectionHandled", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
362
- }
363
- /**
364
- *
365
- * @param error
366
- */
367
- static uncaughtException(error) {
368
- if (error.message === "'app.router' is deprecated!\nPlease see the 3.x to 4.x migration guide for details on how to update your app.") {
369
- console.log("");
370
- } else {
371
- this.stackTrace = this.traceError(error.message, "uncaught exception handled", 503 /* SERVICE_UNAVAILABLE */);
372
- this.logger.error(this.stackTrace.message, "UncaughtException", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
373
- }
374
- }
375
- /**
376
- *
377
- * @param error
378
- */
379
- static uncaughtExceptionMonitor(error) {
380
- if (error.message === "'app.router' is deprecated!\nPlease see the 3.x to 4.x migration guide for details on how to update your app.") {
381
- console.log("");
382
- }
383
- }
384
- /**
385
- *
386
- * @param reason
387
- * @param promise
388
- */
389
- static unhandledRejection(reason, promise) {
390
- this.stackTrace = this.traceError(
391
- `Unhandled Rejection at: Promise ${promise} -- reason ${reason}`,
392
- "Unhandled rejection",
393
- 503 /* SERVICE_UNAVAILABLE */
394
- );
395
- this.logger.error(this.stackTrace.message, "UnhandledRejection", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
396
- }
397
- /**
398
- *
399
- * @param warning
400
- */
401
- static warning(warning) {
402
- this.stackTrace = this.traceError(warning.message, "warning", 503 /* SERVICE_UNAVAILABLE */);
403
- this.logger.error(this.stackTrace.message, "Warning", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
404
- }
405
- /**
406
- *
407
- * @param message
408
- */
409
- static message(message) {
410
- this.stackTrace = this.traceError(
411
- `process got message ${message}`,
412
- "message exception",
413
- 503 /* SERVICE_UNAVAILABLE */
414
- );
415
- this.logger.error(this.stackTrace.message, "Message", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
416
- }
417
- /**
418
- *
419
- * @param type
420
- * @param promise
421
- * @param reason
422
- */
423
- static multipleResolves(type, promise, reason) {
424
- this.stackTrace = this.traceError(
425
- `${promise} -- ${reason}`,
426
- `Multiple resolves detected : ${type}`,
427
- 503 /* SERVICE_UNAVAILABLE */
428
- );
429
- this.logger.error(this.stackTrace.message, "multipleResolves", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
430
- }
431
- /**
432
- *
433
- */
434
- static processInterrupted() {
435
- this.logger.success("[ OK ] Success", "The Web server has been stopped !");
436
- process.exit(0);
437
- }
438
- /**
439
- *
440
- * @param signal
441
- */
442
- static sigtermSignalReceived(signal) {
443
- this.stackTrace = this.traceError(
444
- `Process ${process.pid} received a SIGTERM signal : ${signal.toString()}`,
445
- "SIGTERM",
446
- 406 /* NOT_ACCEPTABLE */
447
- );
448
- this.logger.error(this.stackTrace.message, "SIGTERM", this.stackTrace.name, this.stackTrace.stack, 406 /* NOT_ACCEPTABLE */);
449
- process.exit(0);
450
- }
451
- /**
452
- *
453
- */
454
- static serverClosing() {
455
- console.log(`${colors2.bgCyanBright(` ${colors2.bold(`${colors2.white(` INFO `)}`)}`)} All processes are stopped`);
456
- console.log(" Server is closed");
457
- process.exit();
458
- }
459
- /**
460
- *
461
- */
462
- static dropNewConnection() {
463
- console.log(`${colors2.cyan(`\u24D8`)} ${colors2.bgCyan(` ${colors2.bold(`${colors2.white(` Server maxConnection `)}`)} `)} ${dateTimeFormattedUtils} | ${colors2.bgCyan(`${colors2.white(` Info `)}`)} The server dropped new connections`);
464
- }
465
- /**
466
- *
467
- * @param errorEmitter
468
- * @param err
469
- * @param req
470
- * @param res
471
- * @param next
472
- */
473
- static expressErrorHandlingMiddleware(errorEmitter, err, req, res, next) {
474
- if (err) {
475
- errorEmitter.emit(CEventNameError.error, err);
476
- if (typeof res.status === "function") {
477
- res.status(500).send("Internal Server Error");
478
- } else {
479
- console.error("res.status is not a function");
480
- }
481
- this.stackTrace = this.traceError(err.message, "Express error", 406 /* NOT_ACCEPTABLE */);
482
- this.logger.error(this.stackTrace.message, "Express error-handling middleware", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
483
- } else {
484
- next();
485
- }
486
- }
487
- static traceError(props, name, status) {
488
- return new StackTraceError(props, name, status, true);
489
- }
490
- };
491
- ServerListenEventError.logger = new LoggerCore();
492
-
493
- // src/core/handlers/eventProcess.handler.ts
494
- function eventProcessHandler() {
495
- const errorEmitter = new EventEmitter();
496
- const app = express();
497
- errorEmitter.on(CEventNameError.error, (error) => {
498
- ServerListenEventError.listenerError(error);
499
- });
500
- process2.on(CEvent.beforeExit, (code) => {
501
- setTimeout(() => {
502
- ServerListenEventError.processBeforeExit(code);
503
- }, 100);
504
- });
505
- process2.on(CEvent.disconnect, () => {
506
- ServerListenEventError.processDisconnected();
507
- });
508
- process2.on(CEvent.exit, (code) => {
509
- ServerListenEventError.exited(code);
510
- });
511
- process2.on(CEvent.rejectionHandled, (promise) => {
512
- ServerListenEventError.promiseRejectionHandled(promise);
513
- });
514
- process2.on(CEvent.uncaughtException, (error) => {
515
- ServerListenEventError.uncaughtException(error);
516
- });
517
- process2.on(CEvent.uncaughtExceptionMonitor, (error) => {
518
- ServerListenEventError.uncaughtExceptionMonitor(error);
519
- });
520
- process2.on(CEvent.unhandledRejection, (reason, promise) => {
521
- ServerListenEventError.unhandledRejection(reason, promise);
522
- });
523
- process2.on(CEvent.warning, (warning) => {
524
- ServerListenEventError.warning(warning);
525
- });
526
- process2.on(CEvent.message, (message) => {
527
- ServerListenEventError.message(message);
528
- });
529
- process2.on(CEvent.multipleResolves, (type, promise, reason) => {
530
- ServerListenEventError.multipleResolves(type, promise, reason);
531
- });
532
- process2.on(CEvent.sigint, () => {
533
- ServerListenEventError.processInterrupted();
534
- });
535
- process2.on(CEvent.sigterm, (signal) => {
536
- ServerListenEventError.sigtermSignalReceived(signal);
537
- });
538
- app.use((err, req, res, next) => {
539
- ServerListenEventError.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
540
- });
541
- }
542
-
543
- // src/core/events/requestCalls.event.ts
544
- import colors3 from "ansi-colors";
545
- import { LoggerCore as LoggerCore2 } from "opticore-logger";
546
- function requestCallsEvent(req, res, host, port, loadingTime) {
547
- const logger = new LoggerCore2();
548
- const currentDatePath = `Request called`;
549
- if (req.originalUrl === "undefined") {
550
- console.log(`[ ${colors3.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgRed(`${colors3.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] The route do not exist. - [ Status ] ${colors3.red(`${colors3.white(` 404 `)}`)}`);
551
- logger.error("The route do not exist.");
552
- } else {
553
- switch (res.statusCode) {
554
- case 200:
555
- switch (req.method) {
556
- case "POST":
557
- logger.info(`[ ${colors3.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgGreen(`${colors3.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors3.bgCyan(`${colors3.white(` 200 `)}`)}`);
558
- break;
559
- case "GET":
560
- case "PUT":
561
- logger.info(`[ ${colors3.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgGreen(`${colors3.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors3.bgCyan(`${colors3.white(` 200 `)}`)}`);
562
- break;
563
- case "DELETE":
564
- logger.info(`[ ${colors3.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgGreen(`${colors3.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors3.bgCyan(`${colors3.white(` 200 `)}`)}`);
565
- break;
566
- }
567
- break;
568
- case 404:
569
- switch (req.method) {
570
- case "POST":
571
- console.log(`[ ${colors3.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgRed(`${colors3.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors3.red(`${colors3.white(` 404 `)}`)}`);
572
- break;
573
- case "GET":
574
- console.log(`[ ${colors3.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgRed(`${colors3.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors3.red(`${colors3.bold(` 404 `)}`)}`);
575
- break;
576
- case "PUT":
577
- console.log(`[ ${colors3.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgRed(`${colors3.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors3.red(`${colors3.bold(` 404 `)}`)}`);
578
- break;
579
- case "DELETE":
580
- console.log(`[ ${colors3.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgRed(`${colors3.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors3.red(`${colors3.bold(` 404 `)}`)}`);
581
- break;
582
- }
583
- break;
584
- case 401:
585
- switch (req.method) {
586
- case "POST":
587
- console.log(`[ ${colors3.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgYellowBright(`${colors3.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors3.bgYellow(`${colors3.bold(` 401 `)}`)}`);
588
- break;
589
- case "GET":
590
- console.log(`[ ${colors3.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgYellowBright(`${colors3.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors3.bgYellow(`${colors3.bold(` 401 `)}`)}`);
591
- break;
592
- case "PUT":
593
- console.log(`[ ${colors3.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgYellowBright(`${colors3.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors3.bgYellow(`${colors3.bold(` 401 `)}`)}`);
594
- break;
595
- case "DELETE":
596
- console.log(`[ ${colors3.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgYellowBright(`${colors3.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors3.bgYellow(`${colors3.bold(` 401 `)}`)}`);
597
- break;
598
- }
599
- break;
600
- case 500:
601
- switch (req.method) {
602
- case "POST":
603
- console.log(`[ ${colors3.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgRed(`${colors3.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors3.red(`${colors3.bold(` 500 `)}`)}`);
604
- break;
605
- case "GET":
606
- console.log(`[ ${colors3.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgRed(`${colors3.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors3.red(`${colors3.bold(` 500 `)}`)}`);
607
- break;
608
- case "PUT":
609
- console.log(`[ ${colors3.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgRed(`${colors3.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors3.red(`${colors3.bold(` 500 `)}`)}`);
610
- break;
611
- case "DELETE":
612
- console.log(`[ ${colors3.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgRed(`${colors3.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors3.red(`${colors3.bold(` 500 `)}`)}`);
613
- break;
614
- }
615
- break;
616
- default:
617
- console.log(`[ ${colors3.blueBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.blueBright(` ${res.statusMessage} `)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors3.blueBright(` ${res.req.socket._httpMessage.statusCode} `)}`);
618
- break;
619
- }
620
- }
621
- }
622
-
623
- // src/application/service/core.service.ts
624
- import process3 from "node:process";
625
- import chalk2 from "chalk";
626
- import * as path from "path";
627
- import * as fs from "fs";
628
- import colors6 from "ansi-colors";
629
-
630
- // src/core/utils/modulesLoaded.utils.ts
631
- import colors5 from "ansi-colors";
632
-
633
- // src/core/utils/logMessage.utils.ts
634
- import colors4 from "ansi-colors";
635
- var LogMessageUtils = class {
636
- static success(title, action, contentAction) {
637
- console.log(`${colors4.green(`\u2714`)} ${colors4.bgGreen(` ${colors4.bold(`${colors4.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${colors4.bgGreen(`${colors4.white(` Success `)}`)} [ ${action} ] ${contentAction} - [ Status ] ${colors4.bgGreen(`${colors4.white(` 200 `)}`)}`);
638
- }
639
- static warning(title, action, contentAction) {
640
- console.warn(`${colors4.yellow(`\u26A0\uFE0F`)} ${colors4.bgYellow(` ${colors4.bold(`${colors4.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${colors4.bgYellow(`${colors4.white(` Warning `)}`)} ${contentAction}`);
641
- }
642
- static info(title, action, contentAction) {
643
- console.info(`${colors4.cyan(`\u24D8`)} ${colors4.bgCyan(` ${colors4.bold(`${colors4.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${colors4.bgCyan(`${colors4.white(` Info `)}`)} ${contentAction}`);
644
- }
645
- static error(title, errorType, stackTrace, messageContent, httpCodeValue) {
646
- console.error(`${colors4.red(`\u2718`)} ${colors4.bgRed(` ${colors4.bold(`${colors4.white(`${title}`)}`)} `)} | ${dateTimeFormattedUtils} | [ ${colors4.red(`${colors4.bold(` ${errorType} `)}`)} ] | [ ${colors4.bold(`stack trace`)} ] ${colors4.red(`${stackTrace}`)} - ${colors4.red(`${messageContent}`)} - [ ${colors4.red(`${colors4.bold(` HttpCode `)}`)} ] ${colors4.red(`${colors4.bold(` ${httpCodeValue} `)}`)} `);
647
- }
648
- static requestError(title, errorName, errorMessage, errorCode) {
649
- console.error(`[ ${colors4.red(`${title}`)} ] ${dateTimeFormattedUtils} | ${colors4.bgRed(`${colors4.white(` ERROR `)}`)} ${colors4.red(`[ ${errorName} ]`)} ${colors4.red(`${errorMessage}`)} - [ Status ] ${colors4.bgRed(`${colors4.white(` ${errorCode} `)}`)}`);
650
- }
651
- };
652
-
653
- // src/core/utils/modulesLoaded.utils.ts
654
- function modulesLoadedUtils(allAppRoutes, dbConChecker) {
655
- LogMessageUtils.success("Kernel", "load kernel", "Modules app have been successfully loaded");
656
- console.log(`${colors5.whiteBright(` content`)} ${colors5.green("Kernel :")} ${colors5.cyan(`${colors5.bold(`server side`)}`)} has been loaded successfully ${colors5.green(`\u2714`)}`);
657
- allAppRoutes ? console.log(`${colors5.whiteBright(` content`)} ${colors5.green("Kernel :")} ${colors5.cyan(`${colors5.bold(`Routers service`)} `)} has been loaded successfully ${colors5.green(`\u2714`)}`) : console.log(`${colors5.red(`\u2718`)} ${colors5.bgRed(` ${colors5.bold(`${colors5.white(` Register routes `)}`)} `)} | ${dateTimeFormattedUtils} | [ ${colors5.red(`${colors5.bold(` fail `)}`)} ] | [ ${colors5.bold(` loading `)} ] - ${colors5.red(` routers `)} - The route register failed to load `);
658
- typeof dbConChecker == "function" ? console.log(`${colors5.whiteBright(` content`)} ${colors5.green("Kernel :")} ${colors5.cyan(`${colors5.bold(`database checker connection`)}`)} has been loaded successfully ${colors5.green(`\u2714`)}`) : "";
659
- }
660
-
661
182
  // src/application/service/core.service.ts
662
183
  var CoreService = class {
663
184
  /**
@@ -673,7 +194,7 @@ var CoreService = class {
673
194
  * Returns an Object containing a node version, openssl, and v0
674
195
  */
675
196
  getVersions() {
676
- const { node, openssl, v8 } = process3.versions;
197
+ const { node, openssl, v8 } = process2.versions;
677
198
  const data = {
678
199
  "node version": node,
679
200
  "openssl": openssl,
@@ -693,14 +214,14 @@ var CoreService = class {
693
214
  * and Memory usage system
694
215
  */
695
216
  getUsageMemory() {
696
- const memoryData = process3.memoryUsage();
217
+ const memoryData = process2.memoryUsage();
697
218
  const data = {
698
219
  "Resident Set Size - total memory allocated for the process execution": this.formatMemoryUsage(memoryData.rss),
699
220
  "Total size of the allocated heap": this.formatMemoryUsage(memoryData.heapTotal),
700
221
  "Actual memory used during the execution": this.formatMemoryUsage(memoryData.heapUsed),
701
222
  "V8 external memory": this.formatMemoryUsage(memoryData.external),
702
- "Memory usage user": this.formatMemoryUsage(process3.cpuUsage().user),
703
- "Memory usage system": this.formatMemoryUsage(process3.cpuUsage().system)
223
+ "Memory usage user": this.formatMemoryUsage(process2.cpuUsage().user),
224
+ "Memory usage system": this.formatMemoryUsage(process2.cpuUsage().system)
704
225
  };
705
226
  return {
706
227
  "rss": data["Resident Set Size - total memory allocated for the process execution"],
@@ -715,11 +236,11 @@ var CoreService = class {
715
236
  * Return an Object containing a project path and running server time
716
237
  */
717
238
  getProjectInfo() {
718
- const startTime = process3.hrtime();
719
- const endTime = process3.hrtime(startTime);
239
+ const startTime = process2.hrtime();
240
+ const endTime = process2.hrtime(startTime);
720
241
  const executionTime = (endTime[0] * 1e9 + endTime[1]) / 1e6;
721
242
  return {
722
- "projectPath": path.join(process3.cwd()),
243
+ "projectPath": path.join(process2.cwd()),
723
244
  "startingTime": `${executionTime.toFixed(5)} ms`
724
245
  };
725
246
  }
@@ -729,7 +250,7 @@ var CoreService = class {
729
250
  * @private
730
251
  */
731
252
  getEnvFileLoading(filePath) {
732
- const fullPath = path.resolve(process3.cwd(), filePath);
253
+ const fullPath = path.resolve(process2.cwd(), filePath);
733
254
  if (fs.existsSync(fullPath)) {
734
255
  const env = fs.readFileSync(fullPath, "utf-8");
735
256
  const lines = env.split("\n");
@@ -737,7 +258,7 @@ var CoreService = class {
737
258
  const match = line.match(/^([^#=]+)=([^#]+)$/);
738
259
  if (match) {
739
260
  const key = match[1].trim();
740
- process3.env[key] = match[2].trim();
261
+ process2.env[key] = match[2].trim();
741
262
  }
742
263
  });
743
264
  }
@@ -749,35 +270,35 @@ var CoreService = class {
749
270
  */
750
271
  getServerRunningMode(development, production) {
751
272
  this.getEnvFileLoading(".env");
752
- const isDevelopment = process3.env.NODE_ENV === "development";
273
+ const isDevelopment = process2.env.NODE_ENV === "development";
753
274
  if (isDevelopment) {
754
- return `The server is running in ${colors6.bgBlue(`${colors6.bold(`${development}`)}`)} mode`;
275
+ return `The server is running in ${colors4.bgBlue(`${colors4.bold(`${development}`)}`)} mode`;
755
276
  } else {
756
- return `The server is running in ${colors6.bgBlue(`${colors6.bold(`${production}`)}`)} mode`;
277
+ return `The server is running in ${colors4.bgBlue(`${colors4.bold(`${production}`)}`)} mode`;
757
278
  }
758
279
  }
759
280
  infoServer(nodeVersion, startingTime, host, port, rss, heapUsed, user, system) {
760
281
  const paddingLength = 52;
761
282
  const msg0 = " ".padEnd(paddingLength, " ");
762
283
  const msg1 = " [OK] Web server listening";
763
- const msg2Value = `${colors6.bgBlue(`${colors6.bold(`${nodeVersion}`)}`)}`;
284
+ const msg2Value = `${colors4.bgBlue(`${colors4.bold(`${nodeVersion}`)}`)}`;
764
285
  const msg2 = ` The Web server is using Node.js version`;
765
- const msg3Value = `${colors6.bgBlue(`${colors6.bold(`${startingTime}`)}`)}`;
286
+ const msg3Value = `${colors4.bgBlue(`${colors4.bold(`${startingTime}`)}`)}`;
766
287
  const msg3 = ` Startup time:`;
767
288
  const msg4 = ` ${this.getServerRunningMode("development", "production")}`;
768
- const msg5 = ` ${colors6.underline(`http://${host}:${port}`)}`;
769
- console.log(chalk2.bgGreen.white(msg0.padEnd(paddingLength, " ")));
770
- console.log(chalk2.bgGreen.white(msg1.padEnd(paddingLength, " ")));
771
- console.log(chalk2.bgGreen.white(msg2, msg2Value.padEnd(30.5, " ")));
772
- console.log(chalk2.bgGreen.white(msg3, msg3Value.padEnd(56, " ")));
773
- console.log(chalk2.bgGreen.white(msg4.padEnd(71, " ")));
774
- console.log(chalk2.bgGreen.white(msg5.padEnd(61, " ")));
775
- console.log(chalk2.bgGreen.white(msg0.padEnd(paddingLength, " ")));
289
+ const msg5 = ` ${colors4.underline(`http://${host}:${port}`)}`;
290
+ console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, " ")));
291
+ console.log(chalk.bgGreen.white(msg1.padEnd(paddingLength, " ")));
292
+ console.log(chalk.bgGreen.white(msg2, msg2Value.padEnd(30.5, " ")));
293
+ console.log(chalk.bgGreen.white(msg3, msg3Value.padEnd(56, " ")));
294
+ console.log(chalk.bgGreen.white(msg4.padEnd(71, " ")));
295
+ console.log(chalk.bgGreen.white(msg5.padEnd(61, " ")));
296
+ console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, " ")));
776
297
  console.log(``);
777
- console.log(`${`Resident Set Size - total memory allocated for the process execution :`} ${colors6.cyan(`${colors6.bold(`${rss}`)}`)}`);
778
- console.log(`${`Actual memory used during the execution :`} ${colors6.cyan(`${colors6.bold(`${heapUsed}`)}`)}`);
779
- console.log(`${`Memory usage by user :`} ${colors6.cyan(`${colors6.bold(`${user}`)}`)}`);
780
- console.log(`${`Memory usage by system :`} ${colors6.cyan(`${colors6.bold(`${system}`)}`)}`);
298
+ console.log(`${`Resident Set Size - total memory allocated for the process execution :`} ${colors4.cyan(`${colors4.bold(`${rss}`)}`)}`);
299
+ console.log(`${`Actual memory used during the execution :`} ${colors4.cyan(`${colors4.bold(`${heapUsed}`)}`)}`);
300
+ console.log(`${`Memory usage by user :`} ${colors4.cyan(`${colors4.bold(`${user}`)}`)}`);
301
+ console.log(`${`Memory usage by system :`} ${colors4.cyan(`${colors4.bold(`${system}`)}`)}`);
781
302
  console.log(``);
782
303
  }
783
304
  coreListenerEventLoaderModuleService(kernelModule) {
@@ -799,7 +320,7 @@ var CoreService = class {
799
320
  const stackTrace = new StackTraceError(
800
321
  messageException.loadedModulesError,
801
322
  messageException.loadedModules,
802
- 406 /* NOT_ACCEPTABLE */,
323
+ status.NOT_ACCEPTABLE,
803
324
  true
804
325
  );
805
326
  throw new Error(stackTrace.message);
@@ -829,34 +350,34 @@ var WebServerCore = class {
829
350
  () => {
830
351
  try {
831
352
  if (this.host === "" && this.port === 0) {
832
- ServerListenEventError.hostPortUndefined();
353
+ eventErrorOnListeningServer.hostPortUndefined();
833
354
  } else if (this.host === "") {
834
- ServerListenEventError.hostUndefined();
355
+ eventErrorOnListeningServer.hostUndefined();
835
356
  } else if (this.port === 0) {
836
- ServerListenEventError.portUndefined();
357
+ eventErrorOnListeningServer.portUndefined();
837
358
  } else {
838
359
  this.registerRoutes(routers);
839
360
  }
840
361
  } catch (err) {
841
- this.traceError(err.message, "Error", 406 /* NOT_ACCEPTABLE */);
362
+ this.traceError(err.message, "Error", HttpStatusCode.NOT_ACCEPTABLE);
842
363
  }
843
364
  }
844
365
  );
845
366
  }
846
367
  onListeningOnServerEvent(serverWeb, kernelModule) {
847
- serverWeb.on(CEventNameError.error, (err) => {
848
- ServerListenEventError.onEventError(err);
849
- }).on(CEventNameError.close, () => {
850
- ServerListenEventError.serverClosing();
851
- }).on(CEventNameError.drop, () => {
852
- ServerListenEventError.dropNewConnection();
853
- }).on(CEventNameError.listening, () => {
368
+ serverWeb.on(eventName2.error, (err) => {
369
+ eventErrorOnListeningServer.onEventError(err);
370
+ }).on(eventName2.close, () => {
371
+ eventErrorOnListeningServer.serverClosing();
372
+ }).on(eventName2.drop, () => {
373
+ eventErrorOnListeningServer.dropNewConnection();
374
+ }).on(eventName2.listening, () => {
854
375
  this.infoWebApp();
855
376
  this.serverUtility.coreListenerEventLoaderModuleService(kernelModule);
856
377
  });
857
378
  }
858
379
  onRequestOnServerEvent(serverWeb) {
859
- serverWeb.on(CEventNameError.request, (req, res) => {
380
+ serverWeb.on(eventName2.request, (req, res) => {
860
381
  requestCallsEvent(req, res, this.host, this.port, dateTimeFormattedUtils);
861
382
  });
862
383
  }
@@ -885,46 +406,10 @@ var WebServerCore = class {
885
406
  this.serverUtility.getUsageMemory().system
886
407
  );
887
408
  }
888
- traceError(props, name, status) {
889
- return new StackTraceError(props, name, status, true);
409
+ traceError(props, name, status2) {
410
+ return new StackTraceError2(props, name, status2, true);
890
411
  }
891
412
  };
892
-
893
- // src/domains/constants/errorName.constant.ts
894
- var CErrorName = {
895
- evalError: "EvalError",
896
- syntaxError: "SyntaxError",
897
- rangeError: "RangeError",
898
- referenceError: "ReferenceError",
899
- typeError: "TypeError",
900
- uriError: "URIError",
901
- systemError: "SystemError",
902
- assertionError: "AssertionError",
903
- openSSLError: "OpenSSLError",
904
- generalError: "GeneralError"
905
- };
906
-
907
- // src/domains/constants/event.constant.ts
908
- var CEvent = {
909
- beforeExit: "beforeExit",
910
- disconnect: "disconnect",
911
- exit: "exit",
912
- rejectionHandled: "rejectionHandled",
913
- uncaughtException: "uncaughtException",
914
- uncaughtExceptionMonitor: "uncaughtExceptionMonitor",
915
- unhandledRejection: "unhandledRejection",
916
- warning: "warning",
917
- message: "message",
918
- multipleResolves: "multipleResolves",
919
- worker: "worker",
920
- sigint: "SIGINT",
921
- sigterm: "SIGTERM"
922
- };
923
413
  export {
924
- HttpStatusCodesConstant as HttpStatusCode,
925
- WebServerCore as WebServer,
926
- CErrorName as errorName,
927
- CEvent as event,
928
- CEventNameError as eventName,
929
- getEnvVariable
414
+ WebServerCore as WebServer
930
415
  };