@expressots/core 1.9.0 → 2.0.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.
Files changed (93) hide show
  1. package/lib/CHANGELOG.md +54 -26
  2. package/lib/cjs/application/application-factory.js +83 -0
  3. package/lib/cjs/application/index.js +3 -5
  4. package/lib/cjs/controller/base-controller.js +1 -12
  5. package/lib/cjs/decorator/scope-binding.js +30 -0
  6. package/lib/cjs/index.js +1 -0
  7. package/lib/cjs/middleware/index.js +5 -0
  8. package/lib/cjs/middleware/interfaces/body-parser.interface.js +2 -0
  9. package/lib/cjs/middleware/interfaces/compression.interface.js +2 -0
  10. package/lib/cjs/middleware/interfaces/cors.interface.js +2 -0
  11. package/lib/cjs/middleware/interfaces/serve-static.interface.js +2 -0
  12. package/lib/cjs/middleware/middleware-resolver.js +64 -0
  13. package/lib/cjs/middleware/middleware-service.js +145 -0
  14. package/lib/cjs/provider/index.js +2 -2
  15. package/lib/cjs/types/application/application-factory.d.ts +34 -0
  16. package/lib/cjs/types/application/application-factory.d.ts.map +1 -0
  17. package/lib/cjs/types/application/index.d.ts +1 -1
  18. package/lib/cjs/types/application/index.d.ts.map +1 -1
  19. package/lib/cjs/types/controller/base-controller.d.ts +4 -10
  20. package/lib/cjs/types/controller/base-controller.d.ts.map +1 -1
  21. package/lib/cjs/types/decorator/scope-binding.d.ts +30 -0
  22. package/lib/cjs/types/decorator/scope-binding.d.ts.map +1 -1
  23. package/lib/cjs/types/index.d.ts +1 -0
  24. package/lib/cjs/types/index.d.ts.map +1 -1
  25. package/lib/cjs/types/middleware/index.d.ts +5 -0
  26. package/lib/cjs/types/middleware/index.d.ts.map +1 -0
  27. package/lib/cjs/types/middleware/interfaces/body-parser.interface.d.ts +34 -0
  28. package/lib/cjs/types/middleware/interfaces/body-parser.interface.d.ts.map +1 -0
  29. package/lib/cjs/types/middleware/interfaces/compression.interface.d.ts +99 -0
  30. package/lib/cjs/types/middleware/interfaces/compression.interface.d.ts.map +1 -0
  31. package/lib/cjs/types/middleware/interfaces/cors.interface.d.ts +58 -0
  32. package/lib/cjs/types/middleware/interfaces/cors.interface.d.ts.map +1 -0
  33. package/lib/cjs/types/middleware/interfaces/serve-static.interface.d.ts +71 -0
  34. package/lib/cjs/types/middleware/interfaces/serve-static.interface.d.ts.map +1 -0
  35. package/lib/cjs/types/middleware/middleware-resolver.d.ts +12 -0
  36. package/lib/cjs/types/middleware/middleware-resolver.d.ts.map +1 -0
  37. package/lib/cjs/types/middleware/middleware-service.d.ts +137 -0
  38. package/lib/cjs/types/middleware/middleware-service.d.ts.map +1 -0
  39. package/lib/cjs/types/provider/index.d.ts +1 -1
  40. package/lib/cjs/types/provider/index.d.ts.map +1 -1
  41. package/lib/esm/application/application-factory.js +72 -0
  42. package/lib/esm/application/index.js +3 -5
  43. package/lib/esm/controller/base-controller.js +1 -13
  44. package/lib/esm/decorator/scope-binding.js +30 -0
  45. package/lib/esm/index.mjs +1 -0
  46. package/lib/esm/middleware/index.js +5 -0
  47. package/lib/esm/middleware/interfaces/body-parser.interface.js +2 -0
  48. package/lib/esm/middleware/interfaces/compression.interface.js +2 -0
  49. package/lib/esm/middleware/interfaces/cors.interface.js +2 -0
  50. package/lib/esm/middleware/interfaces/serve-static.interface.js +2 -0
  51. package/lib/esm/middleware/middleware-resolver.js +65 -0
  52. package/lib/esm/middleware/middleware-service.js +144 -0
  53. package/lib/esm/provider/index.js +2 -2
  54. package/lib/esm/types/application/application-factory.d.ts +34 -0
  55. package/lib/esm/types/application/application-factory.d.ts.map +1 -0
  56. package/lib/esm/types/application/index.d.ts +1 -1
  57. package/lib/esm/types/application/index.d.ts.map +1 -1
  58. package/lib/esm/types/controller/base-controller.d.ts +4 -10
  59. package/lib/esm/types/controller/base-controller.d.ts.map +1 -1
  60. package/lib/esm/types/decorator/scope-binding.d.ts +30 -0
  61. package/lib/esm/types/decorator/scope-binding.d.ts.map +1 -1
  62. package/lib/esm/types/index.d.ts +1 -0
  63. package/lib/esm/types/index.d.ts.map +1 -1
  64. package/lib/esm/types/middleware/index.d.ts +5 -0
  65. package/lib/esm/types/middleware/index.d.ts.map +1 -0
  66. package/lib/esm/types/middleware/interfaces/body-parser.interface.d.ts +34 -0
  67. package/lib/esm/types/middleware/interfaces/body-parser.interface.d.ts.map +1 -0
  68. package/lib/esm/types/middleware/interfaces/compression.interface.d.ts +99 -0
  69. package/lib/esm/types/middleware/interfaces/compression.interface.d.ts.map +1 -0
  70. package/lib/esm/types/middleware/interfaces/cors.interface.d.ts +58 -0
  71. package/lib/esm/types/middleware/interfaces/cors.interface.d.ts.map +1 -0
  72. package/lib/esm/types/middleware/interfaces/serve-static.interface.d.ts +71 -0
  73. package/lib/esm/types/middleware/interfaces/serve-static.interface.d.ts.map +1 -0
  74. package/lib/esm/types/middleware/middleware-resolver.d.ts +12 -0
  75. package/lib/esm/types/middleware/middleware-resolver.d.ts.map +1 -0
  76. package/lib/esm/types/middleware/middleware-service.d.ts +137 -0
  77. package/lib/esm/types/middleware/middleware-service.d.ts.map +1 -0
  78. package/lib/esm/types/provider/index.d.ts +1 -1
  79. package/lib/esm/types/provider/index.d.ts.map +1 -1
  80. package/lib/package.json +7 -8
  81. package/package.json +7 -8
  82. package/lib/cjs/application/application.js +0 -141
  83. package/lib/cjs/provider/logger/winston-logger.js +0 -131
  84. package/lib/cjs/types/application/application.d.ts +0 -70
  85. package/lib/cjs/types/application/application.d.ts.map +0 -1
  86. package/lib/cjs/types/provider/logger/winston-logger.d.ts +0 -46
  87. package/lib/cjs/types/provider/logger/winston-logger.d.ts.map +0 -1
  88. package/lib/esm/application/application.js +0 -144
  89. package/lib/esm/provider/logger/winston-logger.js +0 -132
  90. package/lib/esm/types/application/application.d.ts +0 -70
  91. package/lib/esm/types/application/application.d.ts.map +0 -1
  92. package/lib/esm/types/provider/logger/winston-logger.d.ts +0 -46
  93. package/lib/esm/types/provider/logger/winston-logger.d.ts.map +0 -1
@@ -1,131 +0,0 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- var GeneralLogger_1;
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.log = exports.GeneralLogger = exports.LogLevel = void 0;
17
- const inversify_binding_decorators_1 = require("inversify-binding-decorators");
18
- const winston_1 = require("winston");
19
- const winston_daily_rotate_file_1 = __importDefault(require("winston-daily-rotate-file"));
20
- /**
21
- * LogLevel enumeration defines the available log levels.
22
- */
23
- var LogLevel;
24
- (function (LogLevel) {
25
- LogLevel[LogLevel["Debug"] = 0] = "Debug";
26
- LogLevel[LogLevel["Error"] = 1] = "Error";
27
- LogLevel[LogLevel["Info"] = 2] = "Info";
28
- })(LogLevel || (exports.LogLevel = LogLevel = {}));
29
- /**
30
- * GeneralLogger class is a utility class to manage logging within the application.
31
- */
32
- let GeneralLogger = GeneralLogger_1 = class GeneralLogger {
33
- constructor() {
34
- this.logger = (0, winston_1.createLogger)(this.createLoggerOptions());
35
- }
36
- /**
37
- * Creates a console transport for logging.
38
- * @returns {transports.ConsoleTransportInstance} A Winston console transport instance.
39
- */
40
- createConsoleTransport() {
41
- const consoleTransport = new winston_1.transports.Console({
42
- level: (process.env.ENVIRONMENT !== "Development" && "debug") || "debug",
43
- handleExceptions: false,
44
- handleRejections: true,
45
- });
46
- return consoleTransport;
47
- }
48
- /**
49
- * Creates a rotational file transport for logging.
50
- * @returns {DailyRotateFile} A Winston daily rotate file transport instance.
51
- */
52
- createRotationalFileTransport() {
53
- const rotationalFileTransport = new winston_daily_rotate_file_1.default({
54
- level: "error",
55
- filename: "logs/general-%DATE%.log",
56
- datePattern: "YYYY-MM-DD",
57
- zippedArchive: true,
58
- maxSize: "20m",
59
- maxFiles: "7d",
60
- silent: false,
61
- });
62
- return rotationalFileTransport;
63
- }
64
- /**
65
- * Creates a logger options object for Winston.
66
- * @returns {LoggerOptions} A Winston logger options object.
67
- */
68
- createLoggerOptions() {
69
- const loggerOptions = {
70
- transports: [
71
- this.createConsoleTransport(),
72
- this.createRotationalFileTransport(),
73
- ],
74
- defaultMeta: { service: "service-unknown" },
75
- format: winston_1.format.combine(winston_1.format.splat(), winston_1.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), winston_1.format.label({ label: "core-api" }), winston_1.format.printf(({ timestamp, level, message, service, label }) => {
76
- return `[${timestamp}] [${label}] [${service}] ${level}: ${message}`;
77
- })),
78
- };
79
- return loggerOptions;
80
- }
81
- /**
82
- * Retrieves the path and line number of the error.
83
- * @param error - An Error object containing error details.
84
- * @returns {string} A string containing the path and line number of the error.
85
- */
86
- getPathAndLine(error) {
87
- let pathLine = "";
88
- if (error.stack) {
89
- const callerLine = error.stack.split("\n")[1];
90
- const index = callerLine.indexOf("at ");
91
- pathLine = callerLine.substring(index + +2, callerLine.length);
92
- }
93
- return pathLine;
94
- }
95
- /**
96
- * Logs a message or error with the specified log level and service.
97
- * @param logLevel - The log level to use (Debug, Error, or Info).
98
- * @param content - The message or Error object to log.
99
- * @param service - The service name (optional) associated with the log.
100
- */
101
- log(logLevel, content, service) {
102
- let pathLine = "";
103
- let logMessageFormat = "";
104
- if (typeof content === "object") {
105
- pathLine = this.getPathAndLine(content);
106
- logMessageFormat = `${content.message} - (${content.name}) [file: %s]`;
107
- }
108
- else {
109
- logMessageFormat = content;
110
- }
111
- switch (logLevel) {
112
- case LogLevel.Debug:
113
- console.log(logMessageFormat, pathLine, { service });
114
- break;
115
- case LogLevel.Error:
116
- this.logger.error(logMessageFormat, pathLine, { service });
117
- break;
118
- case LogLevel.Info:
119
- this.logger.info(content, { service });
120
- break;
121
- }
122
- }
123
- };
124
- exports.GeneralLogger = GeneralLogger;
125
- exports.GeneralLogger = GeneralLogger = GeneralLogger_1 = __decorate([
126
- (0, inversify_binding_decorators_1.provide)(GeneralLogger_1),
127
- __metadata("design:paramtypes", [])
128
- ], GeneralLogger);
129
- const Log = new GeneralLogger();
130
- const log = Log.log.bind(Log);
131
- exports.log = log;
@@ -1,70 +0,0 @@
1
- import express from "express";
2
- import { Container } from "inversify";
3
- import { IApplicationMessageToConsole } from "../console/console";
4
- import { RenderTemplateOptions } from "../render";
5
- /**
6
- * Enum representing possible server environments.
7
- */
8
- declare enum ServerEnvironment {
9
- Development = "development",
10
- Staging = "staging",
11
- Production = "production"
12
- }
13
- /**
14
- * The Application class provides a way to configure and manage an Express application.
15
- * @provide Application
16
- */
17
- declare class Application {
18
- private app;
19
- private port;
20
- private environment;
21
- /**
22
- * Constructs a new instance of the Application class.
23
- */
24
- constructor();
25
- /**
26
- * Configure services that should be initialized before the server starts.
27
- */
28
- protected configureServices(): void;
29
- /**
30
- * Configure services that should be executed after the server starts.
31
- */
32
- protected postServerInitialization(): void;
33
- /**
34
- * Perform actions or cleanup after the server is shutdown.
35
- */
36
- protected serverShutdown(): void;
37
- /**
38
- * Handles process exit by calling serverShutdown and then exiting the process.
39
- */
40
- private handleExit;
41
- /**
42
- * Create and configure the Express application.
43
- * @param container - The InversifyJS container.
44
- * @param middlewares - An array of Express middlewares to be applied.
45
- * @returns The configured Application instance.
46
- */
47
- create(container: Container, middlewares?: Array<express.RequestHandler>): Application;
48
- /**
49
- * Start listening on the given port and environment.
50
- * @param port - The port number to listen on.
51
- * @param environment - The server environment.
52
- * @param consoleMessage - Optional message to display in the console.
53
- */
54
- listen(port: number, environment: ServerEnvironment, consoleMessage?: IApplicationMessageToConsole): void;
55
- /**
56
- * Configures the application's view engine based on the provided configuration options.
57
- *
58
- * @public
59
- * @method setEngine
60
- * @template T - A generic type extending from RenderTemplateOptions.
61
- *
62
- * @param {T} options - An object of type T (must be an object that extends RenderTemplateOptions)
63
- * that provides the configuration options for setting the view engine.
64
- * This includes the extension name, view path, and the engine function itself.
65
- */
66
- setEngine<T extends RenderTemplateOptions>(options: T): void;
67
- }
68
- declare const appServerInstance: Application;
69
- export { appServerInstance as AppInstance, Application, ServerEnvironment };
70
- //# sourceMappingURL=application.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,46 +0,0 @@
1
- /**
2
- * LogLevel enumeration defines the available log levels.
3
- */
4
- declare enum LogLevel {
5
- Debug = 0,
6
- Error = 1,
7
- Info = 2
8
- }
9
- /**
10
- * GeneralLogger class is a utility class to manage logging within the application.
11
- */
12
- declare class GeneralLogger {
13
- private logger;
14
- constructor();
15
- /**
16
- * Creates a console transport for logging.
17
- * @returns {transports.ConsoleTransportInstance} A Winston console transport instance.
18
- */
19
- private createConsoleTransport;
20
- /**
21
- * Creates a rotational file transport for logging.
22
- * @returns {DailyRotateFile} A Winston daily rotate file transport instance.
23
- */
24
- private createRotationalFileTransport;
25
- /**
26
- * Creates a logger options object for Winston.
27
- * @returns {LoggerOptions} A Winston logger options object.
28
- */
29
- private createLoggerOptions;
30
- /**
31
- * Retrieves the path and line number of the error.
32
- * @param error - An Error object containing error details.
33
- * @returns {string} A string containing the path and line number of the error.
34
- */
35
- private getPathAndLine;
36
- /**
37
- * Logs a message or error with the specified log level and service.
38
- * @param logLevel - The log level to use (Debug, Error, or Info).
39
- * @param content - The message or Error object to log.
40
- * @param service - The service name (optional) associated with the log.
41
- */
42
- log(logLevel: LogLevel, content: Error | string, service?: string): void;
43
- }
44
- declare const log: (logLevel: LogLevel, content: Error | string, service?: string) => void;
45
- export { LogLevel, GeneralLogger, log };
46
- //# sourceMappingURL=winston-logger.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"winston-logger.d.ts","sourceRoot":"","sources":["../../../../../packages/core/src/provider/logger/winston-logger.ts"],"names":[],"mappings":"AAUA;;GAEG;AACH,aAAK,QAAQ;IACX,KAAK,IAAA;IACL,KAAK,IAAA;IACL,IAAI,IAAA;CACL;AAED;;GAEG;AACH,cACM,aAAa;IACjB,OAAO,CAAC,MAAM,CAAS;;IAMvB;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAY9B;;;OAGG;IACH,OAAO,CAAC,6BAA6B;IAcrC;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAoB3B;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAYtB;;;;;OAKG;IACI,GAAG,CACR,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,KAAK,GAAG,MAAM,EACvB,OAAO,CAAC,EAAE,MAAM,GACf,IAAI;CAyBR;AAGD,QAAA,MAAM,GAAG,aA/BK,QAAQ,WACT,KAAK,GAAG,MAAM,YACb,MAAM,KACf,IA4BwB,CAAC;AAE9B,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC"}
@@ -1,144 +0,0 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- var Application_1;
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.ServerEnvironment = exports.Application = exports.AppInstance = void 0;
17
- const process_1 = __importDefault(require("process"));
18
- const express_1 = __importDefault(require("express"));
19
- const inversify_binding_decorators_1 = require("inversify-binding-decorators");
20
- const inversify_express_utils_1 = require("inversify-express-utils");
21
- const console_1 = require("../console/console");
22
- const error_handler_middleware_1 = __importDefault(require("../error/error-handler-middleware"));
23
- /**
24
- * Enum representing possible server environments.
25
- */
26
- var ServerEnvironment;
27
- (function (ServerEnvironment) {
28
- ServerEnvironment["Development"] = "development";
29
- ServerEnvironment["Staging"] = "staging";
30
- ServerEnvironment["Production"] = "production";
31
- })(ServerEnvironment || (exports.ServerEnvironment = ServerEnvironment = {}));
32
- /**
33
- * The Application class provides a way to configure and manage an Express application.
34
- * @provide Application
35
- */
36
- let Application = Application_1 = class Application {
37
- app;
38
- port;
39
- environment;
40
- /**
41
- * Constructs a new instance of the Application class.
42
- */
43
- constructor() { }
44
- /**
45
- * Configure services that should be initialized before the server starts.
46
- */
47
- configureServices() { }
48
- /**
49
- * Configure services that should be executed after the server starts.
50
- */
51
- postServerInitialization() { }
52
- /**
53
- * Perform actions or cleanup after the server is shutdown.
54
- */
55
- serverShutdown() { }
56
- /**
57
- * Handles process exit by calling serverShutdown and then exiting the process.
58
- */
59
- handleExit() {
60
- this.serverShutdown();
61
- process_1.default.exit(0);
62
- }
63
- /**
64
- * Create and configure the Express application.
65
- * @param container - The InversifyJS container.
66
- * @param middlewares - An array of Express middlewares to be applied.
67
- * @returns The configured Application instance.
68
- */
69
- create(container, middlewares = []) {
70
- this.configureServices();
71
- const expressServer = new inversify_express_utils_1.InversifyExpressServer(container);
72
- expressServer.setConfig((app) => {
73
- // Detect if a middleware in the array has a body parser. If so, replace the default body parser.
74
- const hasCustomBodyParser = middlewares.some((middleware) => {
75
- const middlewareName = middleware.name.toLowerCase();
76
- return (middlewareName.includes("json") ||
77
- middlewareName.includes("urlencoded"));
78
- });
79
- if (!hasCustomBodyParser) {
80
- /* Default body parser application/json */
81
- app.use(express_1.default.json());
82
- /* Default body parser application/x-www-form-urlencoded */
83
- app.use(express_1.default.urlencoded({ extended: true }));
84
- }
85
- middlewares.forEach((middleware) => {
86
- app.use(middleware);
87
- });
88
- });
89
- expressServer.setErrorConfig((app) => {
90
- app.use(error_handler_middleware_1.default);
91
- });
92
- this.app = expressServer.build();
93
- return this;
94
- }
95
- /**
96
- * Start listening on the given port and environment.
97
- * @param port - The port number to listen on.
98
- * @param environment - The server environment.
99
- * @param consoleMessage - Optional message to display in the console.
100
- */
101
- listen(port, environment, consoleMessage) {
102
- this.port = port;
103
- this.environment = environment;
104
- this.app.listen(this.port, () => {
105
- new console_1.Console().messageServer(this.port, this.environment, consoleMessage);
106
- [
107
- "SIGTERM",
108
- "SIGHUP",
109
- "SIGBREAK",
110
- "SIGQUIT",
111
- "SIGINT",
112
- ].forEach((signal) => {
113
- process_1.default.on(signal, this.handleExit.bind(this));
114
- });
115
- });
116
- this.postServerInitialization();
117
- }
118
- /**
119
- * Configures the application's view engine based on the provided configuration options.
120
- *
121
- * @public
122
- * @method setEngine
123
- * @template T - A generic type extending from RenderTemplateOptions.
124
- *
125
- * @param {T} options - An object of type T (must be an object that extends RenderTemplateOptions)
126
- * that provides the configuration options for setting the view engine.
127
- * This includes the extension name, view path, and the engine function itself.
128
- */
129
- setEngine(options) {
130
- if ("extName" in options) {
131
- const { extName, viewPath, engine } = options;
132
- this.app.engine(extName, engine);
133
- this.app.set("view engine", extName);
134
- this.app.set("views", viewPath);
135
- }
136
- }
137
- };
138
- exports.Application = Application;
139
- exports.Application = Application = Application_1 = __decorate([
140
- (0, inversify_binding_decorators_1.provide)(Application_1),
141
- __metadata("design:paramtypes", [])
142
- ], Application);
143
- const appServerInstance = new Application();
144
- exports.AppInstance = appServerInstance;
@@ -1,132 +0,0 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- var GeneralLogger_1;
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.log = exports.GeneralLogger = exports.LogLevel = void 0;
17
- const inversify_binding_decorators_1 = require("inversify-binding-decorators");
18
- const winston_1 = require("winston");
19
- const winston_daily_rotate_file_1 = __importDefault(require("winston-daily-rotate-file"));
20
- /**
21
- * LogLevel enumeration defines the available log levels.
22
- */
23
- var LogLevel;
24
- (function (LogLevel) {
25
- LogLevel[LogLevel["Debug"] = 0] = "Debug";
26
- LogLevel[LogLevel["Error"] = 1] = "Error";
27
- LogLevel[LogLevel["Info"] = 2] = "Info";
28
- })(LogLevel || (exports.LogLevel = LogLevel = {}));
29
- /**
30
- * GeneralLogger class is a utility class to manage logging within the application.
31
- */
32
- let GeneralLogger = GeneralLogger_1 = class GeneralLogger {
33
- logger;
34
- constructor() {
35
- this.logger = (0, winston_1.createLogger)(this.createLoggerOptions());
36
- }
37
- /**
38
- * Creates a console transport for logging.
39
- * @returns {transports.ConsoleTransportInstance} A Winston console transport instance.
40
- */
41
- createConsoleTransport() {
42
- const consoleTransport = new winston_1.transports.Console({
43
- level: (process.env.ENVIRONMENT !== "Development" && "debug") || "debug",
44
- handleExceptions: false,
45
- handleRejections: true,
46
- });
47
- return consoleTransport;
48
- }
49
- /**
50
- * Creates a rotational file transport for logging.
51
- * @returns {DailyRotateFile} A Winston daily rotate file transport instance.
52
- */
53
- createRotationalFileTransport() {
54
- const rotationalFileTransport = new winston_daily_rotate_file_1.default({
55
- level: "error",
56
- filename: "logs/general-%DATE%.log",
57
- datePattern: "YYYY-MM-DD",
58
- zippedArchive: true,
59
- maxSize: "20m",
60
- maxFiles: "7d",
61
- silent: false,
62
- });
63
- return rotationalFileTransport;
64
- }
65
- /**
66
- * Creates a logger options object for Winston.
67
- * @returns {LoggerOptions} A Winston logger options object.
68
- */
69
- createLoggerOptions() {
70
- const loggerOptions = {
71
- transports: [
72
- this.createConsoleTransport(),
73
- this.createRotationalFileTransport(),
74
- ],
75
- defaultMeta: { service: "service-unknown" },
76
- format: winston_1.format.combine(winston_1.format.splat(), winston_1.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), winston_1.format.label({ label: "core-api" }), winston_1.format.printf(({ timestamp, level, message, service, label }) => {
77
- return `[${timestamp}] [${label}] [${service}] ${level}: ${message}`;
78
- })),
79
- };
80
- return loggerOptions;
81
- }
82
- /**
83
- * Retrieves the path and line number of the error.
84
- * @param error - An Error object containing error details.
85
- * @returns {string} A string containing the path and line number of the error.
86
- */
87
- getPathAndLine(error) {
88
- let pathLine = "";
89
- if (error.stack) {
90
- const callerLine = error.stack.split("\n")[1];
91
- const index = callerLine.indexOf("at ");
92
- pathLine = callerLine.substring(index + +2, callerLine.length);
93
- }
94
- return pathLine;
95
- }
96
- /**
97
- * Logs a message or error with the specified log level and service.
98
- * @param logLevel - The log level to use (Debug, Error, or Info).
99
- * @param content - The message or Error object to log.
100
- * @param service - The service name (optional) associated with the log.
101
- */
102
- log(logLevel, content, service) {
103
- let pathLine = "";
104
- let logMessageFormat = "";
105
- if (typeof content === "object") {
106
- pathLine = this.getPathAndLine(content);
107
- logMessageFormat = `${content.message} - (${content.name}) [file: %s]`;
108
- }
109
- else {
110
- logMessageFormat = content;
111
- }
112
- switch (logLevel) {
113
- case LogLevel.Debug:
114
- console.log(logMessageFormat, pathLine, { service });
115
- break;
116
- case LogLevel.Error:
117
- this.logger.error(logMessageFormat, pathLine, { service });
118
- break;
119
- case LogLevel.Info:
120
- this.logger.info(content, { service });
121
- break;
122
- }
123
- }
124
- };
125
- exports.GeneralLogger = GeneralLogger;
126
- exports.GeneralLogger = GeneralLogger = GeneralLogger_1 = __decorate([
127
- (0, inversify_binding_decorators_1.provide)(GeneralLogger_1),
128
- __metadata("design:paramtypes", [])
129
- ], GeneralLogger);
130
- const Log = new GeneralLogger();
131
- const log = Log.log.bind(Log);
132
- exports.log = log;
@@ -1,70 +0,0 @@
1
- import express from "express";
2
- import { Container } from "inversify";
3
- import { IApplicationMessageToConsole } from "../console/console";
4
- import { RenderTemplateOptions } from "../render";
5
- /**
6
- * Enum representing possible server environments.
7
- */
8
- declare enum ServerEnvironment {
9
- Development = "development",
10
- Staging = "staging",
11
- Production = "production"
12
- }
13
- /**
14
- * The Application class provides a way to configure and manage an Express application.
15
- * @provide Application
16
- */
17
- declare class Application {
18
- private app;
19
- private port;
20
- private environment;
21
- /**
22
- * Constructs a new instance of the Application class.
23
- */
24
- constructor();
25
- /**
26
- * Configure services that should be initialized before the server starts.
27
- */
28
- protected configureServices(): void;
29
- /**
30
- * Configure services that should be executed after the server starts.
31
- */
32
- protected postServerInitialization(): void;
33
- /**
34
- * Perform actions or cleanup after the server is shutdown.
35
- */
36
- protected serverShutdown(): void;
37
- /**
38
- * Handles process exit by calling serverShutdown and then exiting the process.
39
- */
40
- private handleExit;
41
- /**
42
- * Create and configure the Express application.
43
- * @param container - The InversifyJS container.
44
- * @param middlewares - An array of Express middlewares to be applied.
45
- * @returns The configured Application instance.
46
- */
47
- create(container: Container, middlewares?: Array<express.RequestHandler>): Application;
48
- /**
49
- * Start listening on the given port and environment.
50
- * @param port - The port number to listen on.
51
- * @param environment - The server environment.
52
- * @param consoleMessage - Optional message to display in the console.
53
- */
54
- listen(port: number, environment: ServerEnvironment, consoleMessage?: IApplicationMessageToConsole): void;
55
- /**
56
- * Configures the application's view engine based on the provided configuration options.
57
- *
58
- * @public
59
- * @method setEngine
60
- * @template T - A generic type extending from RenderTemplateOptions.
61
- *
62
- * @param {T} options - An object of type T (must be an object that extends RenderTemplateOptions)
63
- * that provides the configuration options for setting the view engine.
64
- * This includes the extension name, view path, and the engine function itself.
65
- */
66
- setEngine<T extends RenderTemplateOptions>(options: T): void;
67
- }
68
- declare const appServerInstance: Application;
69
- export { appServerInstance as AppInstance, Application, ServerEnvironment };
70
- //# sourceMappingURL=application.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,46 +0,0 @@
1
- /**
2
- * LogLevel enumeration defines the available log levels.
3
- */
4
- declare enum LogLevel {
5
- Debug = 0,
6
- Error = 1,
7
- Info = 2
8
- }
9
- /**
10
- * GeneralLogger class is a utility class to manage logging within the application.
11
- */
12
- declare class GeneralLogger {
13
- private logger;
14
- constructor();
15
- /**
16
- * Creates a console transport for logging.
17
- * @returns {transports.ConsoleTransportInstance} A Winston console transport instance.
18
- */
19
- private createConsoleTransport;
20
- /**
21
- * Creates a rotational file transport for logging.
22
- * @returns {DailyRotateFile} A Winston daily rotate file transport instance.
23
- */
24
- private createRotationalFileTransport;
25
- /**
26
- * Creates a logger options object for Winston.
27
- * @returns {LoggerOptions} A Winston logger options object.
28
- */
29
- private createLoggerOptions;
30
- /**
31
- * Retrieves the path and line number of the error.
32
- * @param error - An Error object containing error details.
33
- * @returns {string} A string containing the path and line number of the error.
34
- */
35
- private getPathAndLine;
36
- /**
37
- * Logs a message or error with the specified log level and service.
38
- * @param logLevel - The log level to use (Debug, Error, or Info).
39
- * @param content - The message or Error object to log.
40
- * @param service - The service name (optional) associated with the log.
41
- */
42
- log(logLevel: LogLevel, content: Error | string, service?: string): void;
43
- }
44
- declare const log: (logLevel: LogLevel, content: Error | string, service?: string) => void;
45
- export { LogLevel, GeneralLogger, log };
46
- //# sourceMappingURL=winston-logger.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"winston-logger.d.ts","sourceRoot":"","sources":["../../../../../packages/core/src/provider/logger/winston-logger.ts"],"names":[],"mappings":"AAUA;;GAEG;AACH,aAAK,QAAQ;IACX,KAAK,IAAA;IACL,KAAK,IAAA;IACL,IAAI,IAAA;CACL;AAED;;GAEG;AACH,cACM,aAAa;IACjB,OAAO,CAAC,MAAM,CAAS;;IAMvB;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAY9B;;;OAGG;IACH,OAAO,CAAC,6BAA6B;IAcrC;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAoB3B;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAYtB;;;;;OAKG;IACI,GAAG,CACR,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,KAAK,GAAG,MAAM,EACvB,OAAO,CAAC,EAAE,MAAM,GACf,IAAI;CAyBR;AAGD,QAAA,MAAM,GAAG,aA/BK,QAAQ,WACT,KAAK,GAAG,MAAM,YACb,MAAM,KACf,IA4BwB,CAAC;AAE9B,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC"}