@expressots/core 1.4.1 → 1.5.0-dev

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 (50) hide show
  1. package/LICENSE.md +21 -21
  2. package/README.md +61 -61
  3. package/lib/CHANGELOG.md +204 -167
  4. package/lib/README.md +61 -61
  5. package/lib/cjs/application/application.js +21 -2
  6. package/lib/cjs/controller/base-controller.js +39 -17
  7. package/lib/cjs/error/report.js +13 -3
  8. package/lib/cjs/index.js +1 -0
  9. package/lib/cjs/render/handlebars.interface.js +2 -0
  10. package/lib/cjs/render/index.js +2 -0
  11. package/lib/cjs/render/render.type.js +2 -0
  12. package/lib/cjs/types/application/application.d.ts +13 -0
  13. package/lib/cjs/types/application/application.d.ts.map +1 -1
  14. package/lib/cjs/types/controller/base-controller.d.ts +27 -2
  15. package/lib/cjs/types/controller/base-controller.d.ts.map +1 -1
  16. package/lib/cjs/types/error/error-handler-middleware.d.ts.map +1 -1
  17. package/lib/cjs/types/error/report.d.ts +13 -3
  18. package/lib/cjs/types/error/report.d.ts.map +1 -1
  19. package/lib/cjs/types/index.d.ts +1 -0
  20. package/lib/cjs/types/index.d.ts.map +1 -1
  21. package/lib/cjs/types/render/handlebars.interface.d.ts +47 -0
  22. package/lib/cjs/types/render/handlebars.interface.d.ts.map +1 -0
  23. package/lib/cjs/types/render/index.d.ts +3 -0
  24. package/lib/cjs/types/render/index.d.ts.map +1 -0
  25. package/lib/cjs/types/render/render.type.d.ts +13 -0
  26. package/lib/cjs/types/render/render.type.d.ts.map +1 -0
  27. package/lib/esm/application/application.js +21 -2
  28. package/lib/esm/controller/base-controller.js +39 -17
  29. package/lib/esm/error/report.js +13 -3
  30. package/lib/esm/index.mjs +1 -0
  31. package/lib/esm/render/handlebars.interface.js +1 -0
  32. package/lib/esm/render/index.js +1 -0
  33. package/lib/esm/render/render.type.js +1 -0
  34. package/lib/esm/types/application/application.d.ts +13 -0
  35. package/lib/esm/types/application/application.d.ts.map +1 -1
  36. package/lib/esm/types/controller/base-controller.d.ts +27 -2
  37. package/lib/esm/types/controller/base-controller.d.ts.map +1 -1
  38. package/lib/esm/types/error/error-handler-middleware.d.ts.map +1 -1
  39. package/lib/esm/types/error/report.d.ts +13 -3
  40. package/lib/esm/types/error/report.d.ts.map +1 -1
  41. package/lib/esm/types/index.d.ts +1 -0
  42. package/lib/esm/types/index.d.ts.map +1 -1
  43. package/lib/esm/types/render/handlebars.interface.d.ts +47 -0
  44. package/lib/esm/types/render/handlebars.interface.d.ts.map +1 -0
  45. package/lib/esm/types/render/index.d.ts +3 -0
  46. package/lib/esm/types/render/index.d.ts.map +1 -0
  47. package/lib/esm/types/render/render.type.d.ts +13 -0
  48. package/lib/esm/types/render/render.type.d.ts.map +1 -0
  49. package/lib/package.json +2 -2
  50. package/package.json +2 -2
package/lib/README.md CHANGED
@@ -1,61 +1,61 @@
1
- <p align="center">
2
- <a href="https://expresso-ts.com/" target="blank"><img src="https://github.com/expressots/expressots/blob/main/media/expressots.png" width="120" alt="Expresso TS Logo" /></a>
3
- </p>
4
-
5
- # Expresso TS
6
-
7
- A Typescript + [Node.js]("https://nodejs.org/en/") lightweight framework for quick building scalable, easy to read and maintain, server-side applications 🚀
8
-
9
- ## Philosophy
10
-
11
- ExpressoTS is a developer-friendly framework designed to streamline the process of building server-side applications. With a focus on readability, maintainability, and scalability, ExpressoTS aims to simplify the development process by providing a clear and concise structure.
12
-
13
- Gone are the days of tedious setup tasks such as configuring logging systems, handling authentication, and connecting to databases. With ExpressoTS, developers can focus on what really matters - writing code. The framework takes care of the repetitive and time-consuming aspects of development, allowing developers to work more efficiently.
14
-
15
- One of the key features of Expresso TS is its flexible and extensible architecture. The framework provides a simple but powerful dependency injection system that enables developers to quickly and easily extend its functionality by creating and adding providers. This allows developers to seamlessly integrate new features throughout the entire application without having to worry about the complexities of integration.
16
-
17
- Whether you're building a simple API or a complex enterprise application, Expresso TS can help you deliver your project on time and on budget. With a comprehensive set of tools and features, Expresso TS makes it easy to build high-quality, scalable, and maintainable server-side applications.
18
-
19
- ## Getting Started
20
-
21
- - Here is our [Official Documentation](https://expresso-ts.com/)
22
- - Checkout our [First Steps documentation](https://expresso-ts.com/docs/overview/first-steps)
23
- - Our [CLI Documentation](https://expresso-ts.com/docs/category/cli)
24
-
25
- ## Questions
26
-
27
- For questions and support please use the Official [Discord Channel](https://discord.com/invite/PyPJfGK). We have a very active community there, that will be happy to help you. Post your questions in the channel called **HELP EXPRESSO TS** and forum called **help**.
28
-
29
- ## Issues
30
-
31
- The [Issue Reporting Channel](https://github.com/expressots/expressots/issues) is for bug report and feature request **only**.
32
-
33
- Before you create an issue, please make sure you read the [Contribution Guidelines](CONTRIBUTING.md).
34
-
35
- ## Support the project
36
-
37
- Expresso TS is an MIT-licensed open source project. It's an independent project with ongoing development made possible thanks to your support. If you'd like to help, please consider:
38
-
39
- - Become a sponsor on **[Sponsor no GitHub](https://github.com/sponsors/expressots)**
40
- - Follow the **[organization](https://github.com/expressots)** on GitHub and Star ⭐ the project
41
- - Subscribe to the Twitch channel: **[Richard Zampieri](https://www.twitch.tv/richardzampieri)**
42
- - Join our **[Discord](https://discord.com/invite/PyPJfGK)**
43
- - Contribute submitting **[issues and pull requests](https://github.com/expressots/expressots/issues/new/choose)**
44
- - Share the project with your friends and colleagues
45
-
46
- ## Contributors
47
-
48
- - [Daniel Boll](https://github.com/daniel-boll)
49
- - [Felipe Fontana](https://github.com/f0ntana)
50
- - [Juliano Soares](https://github.com/juliano-soares)
51
- - [Vitor Caminha](https://github.com/VitorCaminha)
52
- - [Ariel Betti](https://github.com/ArielBetti)
53
- - [Rodrigo da Hora](https://github.com/dahorarodrigo)
54
-
55
- ## Backers
56
-
57
- - Work in progress
58
-
59
- ## License
60
-
61
- ExpressoTS is **[MIT licensed](LICENSE.md)**
1
+ <p align="center">
2
+ <a href="https://expresso-ts.com/" target="blank"><img src="https://github.com/expressots/expressots/blob/main/media/expressots.png" width="120" alt="Expresso TS Logo" /></a>
3
+ </p>
4
+
5
+ # Expresso TS
6
+
7
+ A Typescript + [Node.js]("https://nodejs.org/en/") lightweight framework for quick building scalable, easy to read and maintain, server-side applications 🚀
8
+
9
+ ## Philosophy
10
+
11
+ ExpressoTS is a developer-friendly framework designed to streamline the process of building server-side applications. With a focus on readability, maintainability, and scalability, ExpressoTS aims to simplify the development process by providing a clear and concise structure.
12
+
13
+ Gone are the days of tedious setup tasks such as configuring logging systems, handling authentication, and connecting to databases. With ExpressoTS, developers can focus on what really matters - writing code. The framework takes care of the repetitive and time-consuming aspects of development, allowing developers to work more efficiently.
14
+
15
+ One of the key features of Expresso TS is its flexible and extensible architecture. The framework provides a simple but powerful dependency injection system that enables developers to quickly and easily extend its functionality by creating and adding providers. This allows developers to seamlessly integrate new features throughout the entire application without having to worry about the complexities of integration.
16
+
17
+ Whether you're building a simple API or a complex enterprise application, Expresso TS can help you deliver your project on time and on budget. With a comprehensive set of tools and features, Expresso TS makes it easy to build high-quality, scalable, and maintainable server-side applications.
18
+
19
+ ## Getting Started
20
+
21
+ - Here is our [Official Documentation](https://expresso-ts.com/)
22
+ - Checkout our [First Steps documentation](https://expresso-ts.com/docs/overview/first-steps)
23
+ - Our [CLI Documentation](https://expresso-ts.com/docs/category/cli)
24
+
25
+ ## Questions
26
+
27
+ For questions and support please use the Official [Discord Channel](https://discord.com/invite/PyPJfGK). We have a very active community there, that will be happy to help you. Post your questions in the channel called **HELP EXPRESSO TS** and forum called **help**.
28
+
29
+ ## Issues
30
+
31
+ The [Issue Reporting Channel](https://github.com/expressots/expressots/issues) is for bug report and feature request **only**.
32
+
33
+ Before you create an issue, please make sure you read the [Contribution Guidelines](CONTRIBUTING.md).
34
+
35
+ ## Support the project
36
+
37
+ Expresso TS is an MIT-licensed open source project. It's an independent project with ongoing development made possible thanks to your support. If you'd like to help, please consider:
38
+
39
+ - Become a sponsor on **[Sponsor no GitHub](https://github.com/sponsors/expressots)**
40
+ - Follow the **[organization](https://github.com/expressots)** on GitHub and Star ⭐ the project
41
+ - Subscribe to the Twitch channel: **[Richard Zampieri](https://www.twitch.tv/richardzampieri)**
42
+ - Join our **[Discord](https://discord.com/invite/PyPJfGK)**
43
+ - Contribute submitting **[issues and pull requests](https://github.com/expressots/expressots/issues/new/choose)**
44
+ - Share the project with your friends and colleagues
45
+
46
+ ## Contributors
47
+
48
+ - [Daniel Boll](https://github.com/daniel-boll)
49
+ - [Felipe Fontana](https://github.com/f0ntana)
50
+ - [Juliano Soares](https://github.com/juliano-soares)
51
+ - [Vitor Caminha](https://github.com/VitorCaminha)
52
+ - [Ariel Betti](https://github.com/ArielBetti)
53
+ - [Rodrigo da Hora](https://github.com/dahorarodrigo)
54
+
55
+ ## Backers
56
+
57
+ - Work in progress
58
+
59
+ ## License
60
+
61
+ ExpressoTS is **[MIT licensed](LICENSE.md)**
@@ -15,11 +15,11 @@ var Application_1;
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.ServerEnvironment = exports.Application = exports.AppInstance = void 0;
17
17
  const express_1 = __importDefault(require("express"));
18
+ const process_1 = __importDefault(require("process"));
19
+ const error_handler_middleware_1 = __importDefault(require("../error/error-handler-middleware"));
18
20
  const inversify_binding_decorators_1 = require("inversify-binding-decorators");
19
21
  const inversify_express_utils_1 = require("inversify-express-utils");
20
- const process_1 = __importDefault(require("process"));
21
22
  const console_1 = require("../console/console");
22
- const error_handler_middleware_1 = __importDefault(require("../error/error-handler-middleware"));
23
23
  /**
24
24
  * Enum representing possible server environments.
25
25
  */
@@ -98,6 +98,25 @@ let Application = Application_1 = class Application {
98
98
  });
99
99
  this.postServerInitialization();
100
100
  }
101
+ /**
102
+ * Configures the application's view engine based on the provided configuration options.
103
+ *
104
+ * @public
105
+ * @method setEngine
106
+ * @template T - A generic type extending from RenderTemplateOptions.
107
+ *
108
+ * @param {T} options - An object of type T (must be an object that extends RenderTemplateOptions)
109
+ * that provides the configuration options for setting the view engine.
110
+ * This includes the extension name, view path, and the engine function itself.
111
+ */
112
+ setEngine(options) {
113
+ if ("extName" in options) {
114
+ const { extName, viewPath, engine } = options;
115
+ this.app.engine(extName, engine);
116
+ this.app.set("view engine", extName);
117
+ this.app.set("views", viewPath);
118
+ }
119
+ }
101
120
  };
102
121
  Application = Application_1 = __decorate([
103
122
  (0, inversify_binding_decorators_1.provide)(Application_1),
@@ -21,7 +21,7 @@ var BaseController_1;
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
22
  exports.BaseController = void 0;
23
23
  const inversify_binding_decorators_1 = require("inversify-binding-decorators");
24
- const error_1 = require("../error");
24
+ const logger_1 = require("../logger");
25
25
  /**
26
26
  * The BaseController class is an abstract base class for controllers.
27
27
  * It provides methods for handling use case calls and sending appropriate responses.
@@ -43,14 +43,7 @@ let BaseController = BaseController_1 = class BaseController {
43
43
  */
44
44
  callUseCaseAsync(useCase, res, successStatusCode) {
45
45
  return __awaiter(this, void 0, void 0, function* () {
46
- let dataReturn;
47
- try {
48
- dataReturn = yield useCase;
49
- return res.status(successStatusCode).json(dataReturn);
50
- }
51
- catch (error) {
52
- error_1.Report.Error(error, undefined, this.serviceName);
53
- }
46
+ return res.status(successStatusCode).json(yield useCase);
54
47
  });
55
48
  }
56
49
  /**
@@ -60,14 +53,43 @@ let BaseController = BaseController_1 = class BaseController {
60
53
  * @param successStatusCode - The HTTP status code to return upon successful execution.
61
54
  */
62
55
  callUseCase(useCase, res, successStatusCode) {
63
- let dataReturn;
64
- try {
65
- dataReturn = useCase;
66
- return res.status(successStatusCode).json(dataReturn);
67
- }
68
- catch (error) {
69
- error_1.Report.Error(error, undefined, this.serviceName);
70
- }
56
+ return res.status(successStatusCode).json(useCase);
57
+ }
58
+ /**
59
+ * Synchronously renders a template with the given options using the Express `Response` object's render method.
60
+ *
61
+ * @protected
62
+ * @method callUseRender
63
+ *
64
+ * @param {Response} res - The Express `Response` object.
65
+ * @param {string} template - The name of the template to render.
66
+ * @param {Object} [options={}] - An optional object containing data to be passed to the template.
67
+ *
68
+ */
69
+ callUseRender(res, template, options = {}) {
70
+ return res.render(template, options);
71
+ }
72
+ /**
73
+ * Asynchronously renders a template with the given options using the Express `Response` object's render method.
74
+ *
75
+ * @protected
76
+ * @method callUseRenderAsync
77
+ *
78
+ * @param {Response} res - The Express `Response` object.
79
+ * @param {string} template - The name of the template to render.
80
+ * @param {Object} [options={}] - An optional object containing data to be passed to the template.
81
+ *
82
+ */
83
+ callUseRenderAsync(res, template, options = {}) {
84
+ return new Promise((resolve, reject) => {
85
+ res.render(template, options, (err, compiled) => {
86
+ if (err) {
87
+ (0, logger_1.log)(logger_1.LogLevel.Error, err.message, "base-controller");
88
+ reject(err);
89
+ }
90
+ resolve(compiled);
91
+ });
92
+ });
71
93
  }
72
94
  };
73
95
  BaseController = BaseController_1 = __decorate([
@@ -11,12 +11,22 @@ exports.Report = void 0;
11
11
  const inversify_binding_decorators_1 = require("inversify-binding-decorators");
12
12
  const logger_1 = require("../logger");
13
13
  /**
14
- * Report class is a utility class to manage and throw application-specific errors.
14
+ * Report class is a utility class to manage and log errors within the application.
15
+ * It is responsible for creating a standardized error object, logging it,
16
+ * and then throwing the error for further handling.
15
17
  */
16
18
  let Report = Report_1 = class Report {
17
19
  /**
18
- * Error method takes an instance of AppError and throws it.
19
- * @param error - An instance of AppError containing error details.
20
+ * The Error method is responsible for generating a standardized error object,
21
+ * logging the error, and then throwing it for further handling.
22
+ * The error thrown is of the custom type IAppError, which extends the built-in Error class.
23
+ *
24
+ * @param error - An instance of Error or a string that describes the error.
25
+ * @param statusCode - The HTTP status code associated with the error (default is 500).
26
+ * @param service - The service name associated with the error. If not specified,
27
+ * it defaults to the name of the calling function.
28
+ *
29
+ * @throws An object of the custom type IAppError, which includes details about the error.
20
30
  */
21
31
  static Error(error, statusCode, service) {
22
32
  var _a, _b;
package/lib/cjs/index.js CHANGED
@@ -23,3 +23,4 @@ __exportStar(require("./decorator"), exports);
23
23
  __exportStar(require("./environment"), exports);
24
24
  __exportStar(require("./error"), exports);
25
25
  __exportStar(require("./logger"), exports);
26
+ __exportStar(require("./render"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +1,7 @@
1
1
  import express from "express";
2
2
  import { Container } from "inversify";
3
3
  import { IApplicationMessageToConsole } from "../console/console";
4
+ import { RenderTemplateOptions } from "../render";
4
5
  /**
5
6
  * Enum representing possible server environments.
6
7
  */
@@ -47,6 +48,18 @@ declare class Application {
47
48
  * @param consoleMessage - Optional message to display in the console.
48
49
  */
49
50
  listen(port: number, environment: ServerEnvironment, consoleMessage?: IApplicationMessageToConsole): void;
51
+ /**
52
+ * Configures the application's view engine based on the provided configuration options.
53
+ *
54
+ * @public
55
+ * @method setEngine
56
+ * @template T - A generic type extending from RenderTemplateOptions.
57
+ *
58
+ * @param {T} options - An object of type T (must be an object that extends RenderTemplateOptions)
59
+ * that provides the configuration options for setting the view engine.
60
+ * This includes the extension name, view path, and the engine function itself.
61
+ */
62
+ setEngine<T extends RenderTemplateOptions>(options: T): void;
50
63
  }
51
64
  declare const appServerInstance: Application;
52
65
  export { appServerInstance as AppInstance, Application, ServerEnvironment };
@@ -1 +1 @@
1
- {"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/application/application.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAItC,OAAO,EAAW,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAG3E;;GAEG;AACH,aAAK,iBAAiB;IAClB,WAAW,gBAAgB;IAC3B,OAAO,YAAY;IACnB,UAAU,eAAe;CAC5B;AAED;;;GAGG;AACH,cACM,WAAW;IAEb,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;IAIhC;;;;;OAKG;IACI,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,GAAE,OAAO,CAAC,cAAc,EAAO,GAAG,WAAW;IAoC5F;;;;;OAKG;IACI,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,iBAAiB,EAAE,cAAc,CAAC,EAAE,4BAA4B,GAAG,IAAI;CAanH;AAED,QAAA,MAAM,iBAAiB,EAAE,WAA+B,CAAC;AAEzD,OAAO,EAAE,iBAAiB,IAAI,WAAW,EAAE,WAAW,EAAE,iBAAiB,EAAE,CAAC"}
1
+ {"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/application/application.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAG9B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,OAAO,EAAW,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAe,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAE/D;;GAEG;AACH,aAAK,iBAAiB;IAClB,WAAW,gBAAgB;IAC3B,OAAO,YAAY;IACnB,UAAU,eAAe;CAC5B;AAED;;;GAGG;AACH,cACM,WAAW;IAEb,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;IAIhC;;;;;OAKG;IACI,MAAM,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,GAAE,OAAO,CAAC,cAAc,EAAO,GAAG,WAAW;IAoC5F;;;;;OAKG;IACI,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,iBAAiB,EAAE,cAAc,CAAC,EAAE,4BAA4B,GAAG,IAAI;IAchH;;;;;;;;;;OAUG;IACI,SAAS,CAAC,CAAC,SAAS,qBAAqB,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI;CAQtE;AAED,QAAA,MAAM,iBAAiB,EAAE,WAA+B,CAAC;AAEzD,OAAO,EAAE,iBAAiB,IAAI,WAAW,EAAE,WAAW,EAAE,iBAAiB,EAAE,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { Response } from 'express';
1
2
  import { interfaces } from 'inversify-express-utils';
2
3
  /**
3
4
  * The BaseController class is an abstract base class for controllers.
@@ -17,14 +18,38 @@ declare abstract class BaseController implements interfaces.Controller {
17
18
  * @param res - The Express response object.
18
19
  * @param successStatusCode - The HTTP status code to return upon successful execution.
19
20
  */
20
- protected callUseCaseAsync(useCase: Promise<any>, res: any, successStatusCode: number): Promise<any>;
21
+ protected callUseCaseAsync(useCase: Promise<any>, res: Response, successStatusCode: number): Promise<Response<any, Record<string, any>>>;
21
22
  /**
22
23
  * Calls a use case and sends an appropriate response based on the result.
23
24
  * @param useCase - The use case to call.
24
25
  * @param res - The Express response object.
25
26
  * @param successStatusCode - The HTTP status code to return upon successful execution.
26
27
  */
27
- protected callUseCase(useCase: any, res: any, successStatusCode: number): any;
28
+ protected callUseCase(useCase: any, res: Response, successStatusCode: number): Response<any, Record<string, any>>;
29
+ /**
30
+ * Synchronously renders a template with the given options using the Express `Response` object's render method.
31
+ *
32
+ * @protected
33
+ * @method callUseRender
34
+ *
35
+ * @param {Response} res - The Express `Response` object.
36
+ * @param {string} template - The name of the template to render.
37
+ * @param {Object} [options={}] - An optional object containing data to be passed to the template.
38
+ *
39
+ */
40
+ protected callUseRender(res: Response, template: string, options?: {}): void;
41
+ /**
42
+ * Asynchronously renders a template with the given options using the Express `Response` object's render method.
43
+ *
44
+ * @protected
45
+ * @method callUseRenderAsync
46
+ *
47
+ * @param {Response} res - The Express `Response` object.
48
+ * @param {string} template - The name of the template to render.
49
+ * @param {Object} [options={}] - An optional object containing data to be passed to the template.
50
+ *
51
+ */
52
+ protected callUseRenderAsync(res: Response, template: string, options?: {}): Promise<string>;
28
53
  }
29
54
  export { BaseController };
30
55
  //# sourceMappingURL=base-controller.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"base-controller.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/controller/base-controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD;;;;GAIG;AACH,uBACe,cAAe,YAAW,UAAU,CAAC,UAAU;IAE1D,OAAO,CAAC,WAAW,CAAS;IAE5B;;;OAGG;gBACS,WAAW,GAAE,MAAS;IAIlC;;;;;OAKG;cACa,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM;IAa3F;;;;;OAKG;IACH,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM;CAc1E;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
1
+ {"version":3,"file":"base-controller.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/controller/base-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD;;;;GAIG;AACH,uBACe,cAAe,YAAW,UAAU,CAAC,UAAU;IAE1D,OAAO,CAAC,WAAW,CAAS;IAE5B;;;OAGG;gBACS,WAAW,GAAE,MAAW;IAIpC;;;;;OAKG;cACa,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM;IAIhG;;;;;OAKG;IACH,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM;IAI3E;;;;;;;;;;MAUE;IACH,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,KAAK,GAAG,IAAI;IAI5E;;;;;;;;;;OAUG;IACH,SAAS,CAAC,kBAAkB,CAAC,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;CAW/F;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -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,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAIrC;;;;;;;GAOG;AACH,iBAAS,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAE7F;AAED,eAAe,YAAY,CAAC"}
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;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC;;;;;;;GAOG;AACH,iBAAS,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAE7F;AAED,eAAe,YAAY,CAAC"}
@@ -6,13 +6,23 @@ interface IAppError {
6
6
  stack?: string;
7
7
  }
8
8
  /**
9
- * Report class is a utility class to manage and throw application-specific errors.
9
+ * Report class is a utility class to manage and log errors within the application.
10
+ * It is responsible for creating a standardized error object, logging it,
11
+ * and then throwing the error for further handling.
10
12
  */
11
13
  declare class Report {
12
14
  static stack: string;
13
15
  /**
14
- * Error method takes an instance of AppError and throws it.
15
- * @param error - An instance of AppError containing error details.
16
+ * The Error method is responsible for generating a standardized error object,
17
+ * logging the error, and then throwing it for further handling.
18
+ * The error thrown is of the custom type IAppError, which extends the built-in Error class.
19
+ *
20
+ * @param error - An instance of Error or a string that describes the error.
21
+ * @param statusCode - The HTTP status code associated with the error (default is 500).
22
+ * @param service - The service name associated with the error. If not specified,
23
+ * it defaults to the name of the calling function.
24
+ *
25
+ * @throws An object of the custom type IAppError, which includes details about the error.
16
26
  */
17
27
  static Error(error: Error | string, statusCode?: number, service?: string): void;
18
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/report.ts"],"names":[],"mappings":"AAGA,UAAU,SAAS;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAGD;;GAEG;AACH,cACM,MAAM;IACR,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC;IAErB;;;OAGG;WACW,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;CA6B1F;AAED,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/report.ts"],"names":[],"mappings":"AAGA,UAAU,SAAS;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,cACM,MAAM;IACR,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC;IAErB;;;;;;;;;;;OAWG;WACW,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;CA6B1F;AAED,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC"}
@@ -7,4 +7,5 @@ export * from "./decorator";
7
7
  export * from "./environment";
8
8
  export * from "./error";
9
9
  export * from "./logger";
10
+ export * from "./render";
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/core/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/core/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Configuration options for Express Handlebars.
3
+ * @interface ConfigOptions
4
+ */
5
+ interface ConfigOptions {
6
+ extname?: string;
7
+ layoutDir?: string;
8
+ defaultLayout?: string | false;
9
+ }
10
+ /**
11
+ * Callback function for rendering templates.
12
+ * @callback RenderCallback
13
+ *
14
+ * @param {Error | null} err - The error object.
15
+ * @param {string} [content] - The rendered content.
16
+ */
17
+ interface RenderCallback {
18
+ (err: Error | null, content?: string): void;
19
+ }
20
+ /**
21
+ * Function for rendering templates.
22
+ * @typedef Engine
23
+ *
24
+ * @param {string} viewPath - The path to the directory containing the templates.
25
+ * @param {ConfigOptions} options - The configuration options for the template engine.
26
+ * @param {RenderCallback} [callback] - The callback function for rendering templates.
27
+ */
28
+ type Engine = (viewPath: string, options: ConfigOptions, callback?: RenderCallback) => void;
29
+ /**
30
+ * Interface representing the configuration options for Handlebars templates.
31
+ */
32
+ interface IHandlebars {
33
+ /**
34
+ * Specifies the extension name for the Handlebars templates.
35
+ */
36
+ extName: string;
37
+ /**
38
+ * Specifies the path to the directory containing the Handlebars templates.
39
+ */
40
+ viewPath: string;
41
+ /**
42
+ * Specifies the function for rendering Handlebars templates.
43
+ */
44
+ engine: Engine;
45
+ }
46
+ export { IHandlebars };
47
+ //# sourceMappingURL=handlebars.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlebars.interface.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/render/handlebars.interface.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,UAAU,aAAa;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CAClC;AAED;;;;;;GAMG;AACH,UAAU,cAAc;IACpB,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/C;AAED;;;;;;;GAOG;AACH,KAAK,MAAM,GAAG,CACV,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,aAAa,EACtB,QAAQ,CAAC,EAAE,cAAc,KACxB,IAAI,CAAC;AAEV;;GAEG;AACH,UAAU,WAAW;IACjB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { IHandlebars } from "./handlebars.interface";
2
+ export { RenderTemplateOptions } from "./render.type";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/render/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { IHandlebars } from "./handlebars.interface";
2
+ /**
3
+ * Type alias for the configuration options for rendering templates.
4
+ *
5
+ * Currently, this type alias is equivalent to the `IHandlebars` interface,
6
+ * and represents the configuration options for Handlebars templates.
7
+ *
8
+ * In the future, this type could be expanded to include configuration options
9
+ * for other template engines.
10
+ */
11
+ type RenderTemplateOptions = IHandlebars;
12
+ export { RenderTemplateOptions };
13
+ //# sourceMappingURL=render.type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.type.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/render/render.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD;;;;;;;;GAQG;AACH,KAAK,qBAAqB,GAAG,WAAW,CAAC;AAEzC,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
@@ -9,11 +9,11 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  };
10
10
  var Application_1;
11
11
  import express from "express";
12
+ import process from "process";
13
+ import errorHandler from "../error/error-handler-middleware";
12
14
  import { provide } from "inversify-binding-decorators";
13
15
  import { InversifyExpressServer } from "inversify-express-utils";
14
- import process from "process";
15
16
  import { Console } from "../console/console";
16
- import errorHandler from "../error/error-handler-middleware";
17
17
  /**
18
18
  * Enum representing possible server environments.
19
19
  */
@@ -94,6 +94,25 @@ let Application = Application_1 = class Application {
94
94
  });
95
95
  this.postServerInitialization();
96
96
  }
97
+ /**
98
+ * Configures the application's view engine based on the provided configuration options.
99
+ *
100
+ * @public
101
+ * @method setEngine
102
+ * @template T - A generic type extending from RenderTemplateOptions.
103
+ *
104
+ * @param {T} options - An object of type T (must be an object that extends RenderTemplateOptions)
105
+ * that provides the configuration options for setting the view engine.
106
+ * This includes the extension name, view path, and the engine function itself.
107
+ */
108
+ setEngine(options) {
109
+ if ("extName" in options) {
110
+ const { extName, viewPath, engine } = options;
111
+ this.app.engine(extName, engine);
112
+ this.app.set("view engine", extName);
113
+ this.app.set("views", viewPath);
114
+ }
115
+ }
97
116
  };
98
117
  Application = Application_1 = __decorate([
99
118
  provide(Application_1),
@@ -9,7 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  };
10
10
  var BaseController_1;
11
11
  import { provide } from 'inversify-binding-decorators';
12
- import { Report } from '../error';
12
+ import { LogLevel, log } from '../logger';
13
13
  /**
14
14
  * The BaseController class is an abstract base class for controllers.
15
15
  * It provides methods for handling use case calls and sending appropriate responses.
@@ -31,14 +31,7 @@ let BaseController = BaseController_1 = class BaseController {
31
31
  * @param successStatusCode - The HTTP status code to return upon successful execution.
32
32
  */
33
33
  async callUseCaseAsync(useCase, res, successStatusCode) {
34
- let dataReturn;
35
- try {
36
- dataReturn = await useCase;
37
- return res.status(successStatusCode).json(dataReturn);
38
- }
39
- catch (error) {
40
- Report.Error(error, undefined, this.serviceName);
41
- }
34
+ return res.status(successStatusCode).json(await useCase);
42
35
  }
43
36
  /**
44
37
  * Calls a use case and sends an appropriate response based on the result.
@@ -47,14 +40,43 @@ let BaseController = BaseController_1 = class BaseController {
47
40
  * @param successStatusCode - The HTTP status code to return upon successful execution.
48
41
  */
49
42
  callUseCase(useCase, res, successStatusCode) {
50
- let dataReturn;
51
- try {
52
- dataReturn = useCase;
53
- return res.status(successStatusCode).json(dataReturn);
54
- }
55
- catch (error) {
56
- Report.Error(error, undefined, this.serviceName);
57
- }
43
+ return res.status(successStatusCode).json(useCase);
44
+ }
45
+ /**
46
+ * Synchronously renders a template with the given options using the Express `Response` object's render method.
47
+ *
48
+ * @protected
49
+ * @method callUseRender
50
+ *
51
+ * @param {Response} res - The Express `Response` object.
52
+ * @param {string} template - The name of the template to render.
53
+ * @param {Object} [options={}] - An optional object containing data to be passed to the template.
54
+ *
55
+ */
56
+ callUseRender(res, template, options = {}) {
57
+ return res.render(template, options);
58
+ }
59
+ /**
60
+ * Asynchronously renders a template with the given options using the Express `Response` object's render method.
61
+ *
62
+ * @protected
63
+ * @method callUseRenderAsync
64
+ *
65
+ * @param {Response} res - The Express `Response` object.
66
+ * @param {string} template - The name of the template to render.
67
+ * @param {Object} [options={}] - An optional object containing data to be passed to the template.
68
+ *
69
+ */
70
+ callUseRenderAsync(res, template, options = {}) {
71
+ return new Promise((resolve, reject) => {
72
+ res.render(template, options, (err, compiled) => {
73
+ if (err) {
74
+ log(LogLevel.Error, err.message, "base-controller");
75
+ reject(err);
76
+ }
77
+ resolve(compiled);
78
+ });
79
+ });
58
80
  }
59
81
  };
60
82
  BaseController = BaseController_1 = __decorate([