@expressots/core 1.4.2 → 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 (39) hide show
  1. package/lib/CHANGELOG.md +12 -0
  2. package/lib/cjs/application/application.js +21 -2
  3. package/lib/cjs/controller/base-controller.js +37 -0
  4. package/lib/cjs/index.js +1 -0
  5. package/lib/cjs/render/handlebars.interface.js +2 -0
  6. package/lib/cjs/render/index.js +2 -0
  7. package/lib/cjs/render/render.type.js +2 -0
  8. package/lib/cjs/types/application/application.d.ts +13 -0
  9. package/lib/cjs/types/application/application.d.ts.map +1 -1
  10. package/lib/cjs/types/controller/base-controller.d.ts +27 -2
  11. package/lib/cjs/types/controller/base-controller.d.ts.map +1 -1
  12. package/lib/cjs/types/index.d.ts +1 -0
  13. package/lib/cjs/types/index.d.ts.map +1 -1
  14. package/lib/cjs/types/render/handlebars.interface.d.ts +47 -0
  15. package/lib/cjs/types/render/handlebars.interface.d.ts.map +1 -0
  16. package/lib/cjs/types/render/index.d.ts +3 -0
  17. package/lib/cjs/types/render/index.d.ts.map +1 -0
  18. package/lib/cjs/types/render/render.type.d.ts +13 -0
  19. package/lib/cjs/types/render/render.type.d.ts.map +1 -0
  20. package/lib/esm/application/application.js +21 -2
  21. package/lib/esm/controller/base-controller.js +37 -0
  22. package/lib/esm/index.mjs +1 -0
  23. package/lib/esm/render/handlebars.interface.js +1 -0
  24. package/lib/esm/render/index.js +1 -0
  25. package/lib/esm/render/render.type.js +1 -0
  26. package/lib/esm/types/application/application.d.ts +13 -0
  27. package/lib/esm/types/application/application.d.ts.map +1 -1
  28. package/lib/esm/types/controller/base-controller.d.ts +27 -2
  29. package/lib/esm/types/controller/base-controller.d.ts.map +1 -1
  30. package/lib/esm/types/index.d.ts +1 -0
  31. package/lib/esm/types/index.d.ts.map +1 -1
  32. package/lib/esm/types/render/handlebars.interface.d.ts +47 -0
  33. package/lib/esm/types/render/handlebars.interface.d.ts.map +1 -0
  34. package/lib/esm/types/render/index.d.ts +3 -0
  35. package/lib/esm/types/render/index.d.ts.map +1 -0
  36. package/lib/esm/types/render/render.type.d.ts +13 -0
  37. package/lib/esm/types/render/render.type.d.ts.map +1 -0
  38. package/lib/package.json +1 -1
  39. package/package.json +1 -1
package/lib/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
 
2
2
 
3
+ ## [1.5.0](https://github.com/expressots/expressots/compare/v1.4.2...v1.5.0) (2023-07-11)
4
+
5
+
6
+ ### Features
7
+
8
+ * add render engine mechanic and handlebars sup ([#37](https://github.com/expressots/expressots/issues/37)) ([c9f1c61](https://github.com/expressots/expressots/commit/c9f1c616c3480575c013e1e3e6b397e9b6870fb2))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * remove npm auto publish from ci ([#35](https://github.com/expressots/expressots/issues/35)) ([c7145aa](https://github.com/expressots/expressots/commit/c7145aa5b7e99ee774141824437c30df9e3f4882))
14
+
3
15
  ## [1.4.2](https://github.com/expressots/expressots/compare/v1.4.1...v1.4.2) (2023-06-19)
4
16
 
5
17
 
@@ -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,6 +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 logger_1 = require("../logger");
24
25
  /**
25
26
  * The BaseController class is an abstract base class for controllers.
26
27
  * It provides methods for handling use case calls and sending appropriate responses.
@@ -54,6 +55,42 @@ let BaseController = BaseController_1 = class BaseController {
54
55
  callUseCase(useCase, res, successStatusCode) {
55
56
  return res.status(successStatusCode).json(useCase);
56
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
+ });
93
+ }
57
94
  };
58
95
  BaseController = BaseController_1 = __decorate([
59
96
  (0, inversify_binding_decorators_1.provide)(BaseController_1),
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;AAErD;;;;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,GAAG,EAAE,iBAAiB,EAAE,MAAM;IAI3F;;;;;OAKG;IACH,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM;CAG1E;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"}
@@ -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,6 +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 { LogLevel, log } from '../logger';
12
13
  /**
13
14
  * The BaseController class is an abstract base class for controllers.
14
15
  * It provides methods for handling use case calls and sending appropriate responses.
@@ -41,6 +42,42 @@ let BaseController = BaseController_1 = class BaseController {
41
42
  callUseCase(useCase, res, successStatusCode) {
42
43
  return res.status(successStatusCode).json(useCase);
43
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
+ });
80
+ }
44
81
  };
45
82
  BaseController = BaseController_1 = __decorate([
46
83
  provide(BaseController_1),
package/lib/esm/index.mjs CHANGED
@@ -7,3 +7,4 @@ export * from "./decorator";
7
7
  export * from "./environment";
8
8
  export * from "./error";
9
9
  export * from "./logger";
10
+ export * from "./render";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -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;AAErD;;;;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,GAAG,EAAE,iBAAiB,EAAE,MAAM;IAI3F;;;;;OAKG;IACH,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM;CAG1E;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"}
@@ -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"}
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressots/core",
3
- "version": "1.4.2",
3
+ "version": "1.5.0-dev",
4
4
  "description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
5
5
  "author": "Richard Zampieri",
6
6
  "main": "./lib/cjs/index.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressots/core",
3
- "version": "1.4.2",
3
+ "version": "1.5.0-dev",
4
4
  "description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
5
5
  "author": "Richard Zampieri",
6
6
  "main": "./lib/cjs/index.js",