@expressots/adapter-express 1.5.0 → 1.6.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 (27) hide show
  1. package/lib/CHANGELOG.md +23 -1
  2. package/lib/cjs/adapter-express/application-express.js +38 -10
  3. package/lib/cjs/adapter-express/express-utils/decorators.js +12 -12
  4. package/lib/cjs/adapter-express/express-utils/inversify-express-server.js +2 -3
  5. package/lib/cjs/adapter-express/express-utils/utils.js +7 -8
  6. package/lib/cjs/adapter-express/index.js +1 -0
  7. package/lib/cjs/adapter-express/render/ejs/ejs.config.js +35 -0
  8. package/lib/cjs/adapter-express/render/ejs/ejs.types.js +3 -0
  9. package/lib/cjs/adapter-express/render/engine.js +14 -0
  10. package/lib/cjs/adapter-express/render/handlebars/hbs.config.js +42 -0
  11. package/lib/cjs/adapter-express/render/index.js +5 -0
  12. package/lib/cjs/adapter-express/render/resolve-render.js +33 -0
  13. package/lib/cjs/types/adapter-express/application-express.d.ts +10 -5
  14. package/lib/cjs/types/adapter-express/application-express.interface.d.ts +1 -13
  15. package/lib/cjs/types/adapter-express/application-express.types.d.ts +3 -2
  16. package/lib/cjs/types/adapter-express/express-utils/content/httpContent.d.ts +0 -1
  17. package/lib/cjs/types/adapter-express/express-utils/decorators.d.ts +1 -1
  18. package/lib/cjs/types/adapter-express/express-utils/httpResponseMessage.d.ts +0 -1
  19. package/lib/cjs/types/adapter-express/index.d.ts +1 -0
  20. package/lib/cjs/types/adapter-express/render/ejs/ejs.config.d.ts +21 -0
  21. package/lib/cjs/types/adapter-express/render/ejs/ejs.types.d.ts +169 -0
  22. package/lib/cjs/types/adapter-express/render/engine.d.ts +27 -0
  23. package/lib/cjs/types/adapter-express/render/handlebars/hbs.config.d.ts +20 -0
  24. package/lib/cjs/types/adapter-express/render/index.d.ts +3 -0
  25. package/lib/cjs/types/adapter-express/render/resolve-render.d.ts +7 -0
  26. package/lib/package.json +17 -18
  27. package/package.json +17 -18
package/lib/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
 
2
2
 
3
+ ## [1.6.0](https://github.com/expressots/adapter-express/compare/1.5.0...1.6.0) (2024-07-17)
4
+
5
+
6
+ ### Features
7
+
8
+ * add render support for EJS and HBS ([8618655](https://github.com/expressots/adapter-express/commit/861865564bcdb2d90d7a083bf19f76918e810744))
9
+ * adjust version of core package ([a699bd4](https://github.com/expressots/adapter-express/commit/a699bd4e24fd86474f2c678798abcdd311bce0f1))
10
+ * bump @types/node from 20.14.9 to 20.14.10 ([9a1291b](https://github.com/expressots/adapter-express/commit/9a1291b7c5174d68e079f2b46b0cd140cf4332c1))
11
+ * bump @typescript-eslint/eslint-plugin from 7.15.0 to 7.16.1 ([e7d3c9a](https://github.com/expressots/adapter-express/commit/e7d3c9aea3e260417af7a77694e0c0511e0307b7))
12
+ * bump @typescript-eslint/parser from 7.15.0 to 7.16.1 ([2a99945](https://github.com/expressots/adapter-express/commit/2a99945f749015301b7e53d9bbfa151aa9adb0f6))
13
+ * bump prettier from 3.3.2 to 3.3.3 ([d7de72a](https://github.com/expressots/adapter-express/commit/d7de72a87b8ca503ff37d6ce0974ceb53af51dfe))
14
+ * bump release-it from 17.4.1 to 17.6.0 ([c36aeb6](https://github.com/expressots/adapter-express/commit/c36aeb6a51e446bb3757421fe613fd3202dfaf16))
15
+ * bump typescript from 5.2.2 to 5.5.3 ([53f9f96](https://github.com/expressots/adapter-express/commit/53f9f96f65d2b4652126f7f42c2b9774f0db7328))
16
+ * bump vitest and @vitest/coverage-v8 ([b2dae7e](https://github.com/expressots/adapter-express/commit/b2dae7e4e247e288a5fe8fefe135e47925b2f122))
17
+ * bump vitest and @vitest/coverage-v8 ([b3221eb](https://github.com/expressots/adapter-express/commit/b3221eba32cc85e304fef1cb98389dcae0566c24))
18
+ * linter adjust ([e43d222](https://github.com/expressots/adapter-express/commit/e43d2221ec3f869d60dc2b967ab325e3aaecc97b))
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * bump node version 18.18 and removed deprecated install in husky ([778ed79](https://github.com/expressots/adapter-express/commit/778ed79c3595fd239656d8182623635a8fff16d0))
24
+
3
25
  ## [1.5.0](https://github.com/expressots/adapter-express/compare/1.4.0...1.5.0) (2024-06-11)
4
26
 
5
27
 
@@ -119,4 +141,4 @@
119
141
 
120
142
  ### Bug Fixes
121
143
 
122
- * testing commitlint ([0e78653](https://github.com/expressots/<<repo_name>>/commit/0e786539402f69fdca3fe5b684d850e523db7698))
144
+ * testing commitlint ([0e78653](https://github.com/expressots/<<repo_name>>/commit/0e786539402f69fdca3fe5b684d850e523db7698))
@@ -15,8 +15,12 @@ const inversify_binding_decorators_1 = require("inversify-binding-decorators");
15
15
  const process_1 = __importDefault(require("process"));
16
16
  const application_express_base_1 = require("./application-express.base");
17
17
  const application_express_types_1 = require("./application-express.types");
18
- const inversify_express_server_1 = require("./express-utils/inversify-express-server");
19
18
  const http_status_middleware_1 = require("./express-utils/http-status-middleware");
19
+ const inversify_express_server_1 = require("./express-utils/inversify-express-server");
20
+ const ejs_config_1 = require("./render/ejs/ejs.config");
21
+ const engine_1 = require("./render/engine");
22
+ const hbs_config_1 = require("./render/handlebars/hbs.config");
23
+ const resolve_render_1 = require("./render/resolve-render");
20
24
  /**
21
25
  * The AppExpress class provides methods for configuring and running an Express application.
22
26
  * @class AppExpress
@@ -34,6 +38,7 @@ let AppExpress = class AppExpress extends application_express_base_1.Application
34
38
  this.logger = new core_1.Logger();
35
39
  this.globalPrefix = "/";
36
40
  this.middlewares = [];
41
+ this.renderOptions = {};
37
42
  }
38
43
  configureServices() { }
39
44
  postServerInitialization() { }
@@ -122,6 +127,7 @@ let AppExpress = class AppExpress extends application_express_base_1.Application
122
127
  */
123
128
  async listen(port, environment, consoleMessage) {
124
129
  await this.init();
130
+ await this.configEngine();
125
131
  this.port = port || 3000;
126
132
  this.environment = environment;
127
133
  this.app.set("env", environment);
@@ -145,6 +151,23 @@ let AppExpress = class AppExpress extends application_express_base_1.Application
145
151
  setGlobalRoutePrefix(prefix) {
146
152
  this.globalPrefix = prefix;
147
153
  }
154
+ /**
155
+ * Configures the application's view engine based on the provided configuration options.
156
+ */
157
+ async configEngine() {
158
+ if (this.renderOptions.engine) {
159
+ switch (this.renderOptions.engine) {
160
+ case engine_1.Engine.HBS:
161
+ await (0, hbs_config_1.setEngineHandlebars)(this.app, this.renderOptions.options);
162
+ break;
163
+ case engine_1.Engine.EJS:
164
+ await (0, ejs_config_1.setEngineEjs)(this.app, this.renderOptions.options);
165
+ break;
166
+ default:
167
+ throw new Error("Unsupported engine type!");
168
+ }
169
+ }
170
+ }
148
171
  /**
149
172
  * Configures the application's view engine based on the provided configuration options.
150
173
  *
@@ -152,16 +175,21 @@ let AppExpress = class AppExpress extends application_express_base_1.Application
152
175
  * @method setEngine
153
176
  * @template T - A generic type extending from RenderTemplateOptions.
154
177
  *
155
- * @param {T} options - An object of type T (must be an object that extends RenderTemplateOptions)
156
- * that provides the configuration options for setting the view engine.
157
- * This includes the extension name, view path, and the engine function itself.
178
+ * @param {Engine} engine - The view engine to set
179
+ * @param {EngineOptions} [options] - The configuration options for the view engine
158
180
  */
159
- setEngine(options) {
160
- if ("extName" in options) {
161
- const { extName, viewPath, engine } = options;
162
- this.app.engine(extName, engine);
163
- this.app.set("view engine", extName);
164
- this.app.set("views", viewPath);
181
+ async setEngine(engine, options) {
182
+ (0, resolve_render_1.packageResolver)(engine, options);
183
+ try {
184
+ if (options) {
185
+ this.renderOptions = { engine, options };
186
+ }
187
+ else {
188
+ this.renderOptions = { engine };
189
+ }
190
+ }
191
+ catch (error) {
192
+ this.logger.error(error.message, "adapter-express");
165
193
  }
166
194
  }
167
195
  /**
@@ -1,6 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.params = exports.principal = exports.next = exports.cookies = exports.headers = exports.body = exports.query = exports.param = exports.response = exports.request = exports.httpMethod = exports.Delete = exports.Head = exports.Patch = exports.Put = exports.Post = exports.Get = exports.All = exports.Http = exports.controller = exports.injectHttpContext = void 0;
3
+ exports.principal = exports.next = exports.cookies = exports.headers = exports.body = exports.query = exports.param = exports.response = exports.request = exports.injectHttpContext = void 0;
4
+ exports.controller = controller;
5
+ exports.Http = Http;
6
+ exports.All = All;
7
+ exports.Get = Get;
8
+ exports.Post = Post;
9
+ exports.Put = Put;
10
+ exports.Patch = Patch;
11
+ exports.Head = Head;
12
+ exports.Delete = Delete;
13
+ exports.httpMethod = httpMethod;
14
+ exports.params = params;
4
15
  require("reflect-metadata");
5
16
  const inversify_1 = require("inversify");
6
17
  const constants_1 = require("./constants");
@@ -37,7 +48,6 @@ function controller(path, ...middleware) {
37
48
  Reflect.defineMetadata(constants_1.METADATA_KEY.controller, newMetadata, Reflect);
38
49
  };
39
50
  }
40
- exports.controller = controller;
41
51
  /**
42
52
  * Http decorator to define the status code for a route
43
53
  * @param code
@@ -65,7 +75,6 @@ function Http(code) {
65
75
  Reflect.defineMetadata(constants_1.HTTP_CODE_METADATA.statusCode, httpCodeMetadata, Reflect);
66
76
  };
67
77
  }
68
- exports.Http = Http;
69
78
  /**
70
79
  * Decorator to allow accept all HTTP methods
71
80
  * @param path route path, wildcard
@@ -74,7 +83,6 @@ exports.Http = Http;
74
83
  function All(path, ...middleware) {
75
84
  return httpMethod("all", path, ...middleware);
76
85
  }
77
- exports.All = All;
78
86
  /**
79
87
  * Decorator to allow GET HTTP method
80
88
  * @param path route path
@@ -83,7 +91,6 @@ exports.All = All;
83
91
  function Get(path, ...middleware) {
84
92
  return enhancedHttpMethod("get", path, ...middleware);
85
93
  }
86
- exports.Get = Get;
87
94
  /**
88
95
  * Decorator to allow POST HTTP method
89
96
  * @param path route path
@@ -92,7 +99,6 @@ exports.Get = Get;
92
99
  function Post(path, ...middleware) {
93
100
  return httpMethod("post", path, ...middleware);
94
101
  }
95
- exports.Post = Post;
96
102
  /**
97
103
  * Decorator to allow PUT HTTP method
98
104
  * @param path route path
@@ -101,7 +107,6 @@ exports.Post = Post;
101
107
  function Put(path, ...middleware) {
102
108
  return enhancedHttpMethod("put", path, ...middleware);
103
109
  }
104
- exports.Put = Put;
105
110
  /**
106
111
  * Decorator to allow PATCH HTTP method
107
112
  * @param path route path
@@ -110,7 +115,6 @@ exports.Put = Put;
110
115
  function Patch(path, ...middleware) {
111
116
  return enhancedHttpMethod("patch", path, ...middleware);
112
117
  }
113
- exports.Patch = Patch;
114
118
  /**
115
119
  * Decorator to allow HEAD HTTP method
116
120
  * @param path route path
@@ -119,7 +123,6 @@ exports.Patch = Patch;
119
123
  function Head(path, ...middleware) {
120
124
  return httpMethod("head", path, ...middleware);
121
125
  }
122
- exports.Head = Head;
123
126
  /**
124
127
  * Decorator to allow DELETE HTTP method
125
128
  * @param path route path
@@ -128,7 +131,6 @@ exports.Head = Head;
128
131
  function Delete(path, ...middleware) {
129
132
  return enhancedHttpMethod("delete", path, ...middleware);
130
133
  }
131
- exports.Delete = Delete;
132
134
  /**
133
135
  * Decorator to allow OPTIONS HTTP method
134
136
  * @param path route path
@@ -219,7 +221,6 @@ function httpMethod(method, path, ...middleware) {
219
221
  metadataList.push(metadata);
220
222
  };
221
223
  }
222
- exports.httpMethod = httpMethod;
223
224
  /**
224
225
  * Parameter decorator to inject the request object
225
226
  * @returns ParameterDecorator
@@ -300,7 +301,6 @@ function params(type, parameterName) {
300
301
  Reflect.defineMetadata(constants_1.METADATA_KEY.controllerParameter, metadataList, target.constructor);
301
302
  };
302
303
  }
303
- exports.params = params;
304
304
  /**
305
305
  * Converts a string value to the specified type.
306
306
  * @param value The value to convert.
@@ -194,10 +194,9 @@ class InversifyExpressServer {
194
194
  value();
195
195
  }
196
196
  else if (!res.headersSent) {
197
- if (value === undefined) {
198
- res.status(204);
197
+ if (value !== undefined) {
198
+ res.send(value);
199
199
  }
200
- res.send(value);
201
200
  }
202
201
  }
203
202
  catch (err) {
@@ -1,6 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.instanceOfIHttpActionResult = exports.cleanUpMetadata = exports.getControllerParameterMetadata = exports.getControllerMethodMetadata = exports.getControllerMetadata = exports.getControllersFromMetadata = exports.getControllersFromContainer = void 0;
3
+ exports.getControllersFromContainer = getControllersFromContainer;
4
+ exports.getControllersFromMetadata = getControllersFromMetadata;
5
+ exports.getControllerMetadata = getControllerMetadata;
6
+ exports.getControllerMethodMetadata = getControllerMethodMetadata;
7
+ exports.getControllerParameterMetadata = getControllerParameterMetadata;
8
+ exports.cleanUpMetadata = cleanUpMetadata;
9
+ exports.instanceOfIHttpActionResult = instanceOfIHttpActionResult;
4
10
  const constants_1 = require("./constants");
5
11
  function getControllersFromContainer(container, forceControllers) {
6
12
  if (container.isBound(constants_1.TYPE.Controller)) {
@@ -13,17 +19,14 @@ function getControllersFromContainer(container, forceControllers) {
13
19
  return [];
14
20
  }
15
21
  }
16
- exports.getControllersFromContainer = getControllersFromContainer;
17
22
  function getControllersFromMetadata() {
18
23
  const arrayOfControllerMetadata = Reflect.getMetadata(constants_1.METADATA_KEY.controller, Reflect) || [];
19
24
  return arrayOfControllerMetadata.map((metadata) => metadata.target);
20
25
  }
21
- exports.getControllersFromMetadata = getControllersFromMetadata;
22
26
  function getControllerMetadata(constructor) {
23
27
  const controllerMetadata = Reflect.getOwnMetadata(constants_1.METADATA_KEY.controller, constructor);
24
28
  return controllerMetadata;
25
29
  }
26
- exports.getControllerMetadata = getControllerMetadata;
27
30
  function getControllerMethodMetadata(constructor) {
28
31
  const methodMetadata = Reflect.getOwnMetadata(constants_1.METADATA_KEY.controllerMethod, constructor);
29
32
  const genericMetadata = Reflect.getMetadata(constants_1.METADATA_KEY.controllerMethod, Reflect.getPrototypeOf(constructor));
@@ -35,7 +38,6 @@ function getControllerMethodMetadata(constructor) {
35
38
  }
36
39
  return methodMetadata;
37
40
  }
38
- exports.getControllerMethodMetadata = getControllerMethodMetadata;
39
41
  function getControllerParameterMetadata(constructor) {
40
42
  const parameterMetadata = Reflect.getOwnMetadata(constants_1.METADATA_KEY.controllerParameter, constructor);
41
43
  const genericMetadata = Reflect.getMetadata(constants_1.METADATA_KEY.controllerParameter, Reflect.getPrototypeOf(constructor));
@@ -47,12 +49,9 @@ function getControllerParameterMetadata(constructor) {
47
49
  }
48
50
  return parameterMetadata;
49
51
  }
50
- exports.getControllerParameterMetadata = getControllerParameterMetadata;
51
52
  function cleanUpMetadata() {
52
53
  Reflect.defineMetadata(constants_1.METADATA_KEY.controller, [], Reflect);
53
54
  }
54
- exports.cleanUpMetadata = cleanUpMetadata;
55
55
  function instanceOfIHttpActionResult(value) {
56
56
  return value != null && typeof value.executeAsync === "function";
57
57
  }
58
- exports.instanceOfIHttpActionResult = instanceOfIHttpActionResult;
@@ -20,3 +20,4 @@ var application_express_1 = require("./application-express");
20
20
  Object.defineProperty(exports, "AppExpress", { enumerable: true, get: function () { return application_express_1.AppExpress; } });
21
21
  var application_express_types_1 = require("./application-express.types");
22
22
  Object.defineProperty(exports, "ServerEnvironment", { enumerable: true, get: function () { return application_express_types_1.ServerEnvironment; } });
23
+ __exportStar(require("./render"), exports);
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setEngineEjs = setEngineEjs;
4
+ const path_1 = require("path");
5
+ /**
6
+ * Ejs defaults
7
+ * @type {EjsOptions}
8
+ * @constant
9
+ * @default
10
+ */
11
+ const EJS_DEFAULTS = {
12
+ viewsDir: (0, path_1.join)(process.cwd(), "views"),
13
+ viewEngine: "ejs",
14
+ serverOptions: {},
15
+ };
16
+ /**
17
+ * Set Ejs as the view engine
18
+ * @param {Application} app - The express application
19
+ * @param {EjsOptions} [options=EJS_DEFAULTS] - The ejs options
20
+ */
21
+ async function setEngineEjs(app, options = EJS_DEFAULTS) {
22
+ app.set("view engine", options.viewEngine || EJS_DEFAULTS.viewEngine);
23
+ app.set("views", options.viewsDir || EJS_DEFAULTS.viewsDir);
24
+ if (Array.isArray(options.viewsDir)) {
25
+ options.viewsDir.forEach((dir) => {
26
+ app.set("views", dir);
27
+ });
28
+ }
29
+ if (options.serverOptions) {
30
+ app.locals = {
31
+ ...app.locals,
32
+ ...options.serverOptions,
33
+ };
34
+ }
35
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Engine = void 0;
4
+ /**
5
+ * The supported view engines.
6
+ * @enum {string}
7
+ * @readonly
8
+ * @public
9
+ */
10
+ var Engine;
11
+ (function (Engine) {
12
+ Engine["HBS"] = "hbs";
13
+ Engine["EJS"] = "ejs";
14
+ })(Engine || (exports.Engine = Engine = {}));
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setEngineHandlebars = setEngineHandlebars;
4
+ const path_1 = require("path");
5
+ const core_1 = require("@expressots/core");
6
+ /**
7
+ * Handlebars defaults
8
+ * @type {HandlebarsOptions}
9
+ * @constant
10
+ * @default
11
+ */
12
+ const HANDLEBARS_DEFAULTS = {
13
+ viewsDir: (0, path_1.join)(process.cwd(), "views"),
14
+ viewEngine: "hbs",
15
+ serverOptions: {},
16
+ };
17
+ /**
18
+ * Set Handlebars as the view engine
19
+ * @param {express.Application} app - The express application
20
+ * @param {HandlebarsOptions} [options=HANDLEBARS_DEFAULTS] - The handlebars options
21
+ */
22
+ async function setEngineHandlebars(app, options = HANDLEBARS_DEFAULTS) {
23
+ const logger = new core_1.Logger();
24
+ try {
25
+ app.set("view engine", options.viewEngine || HANDLEBARS_DEFAULTS.viewEngine);
26
+ app.set("views", options.viewsDir || HANDLEBARS_DEFAULTS.viewsDir);
27
+ if (Array.isArray(options.viewsDir)) {
28
+ options.viewsDir.forEach((dir) => {
29
+ app.set("views", dir);
30
+ });
31
+ }
32
+ if (options.serverOptions) {
33
+ app.locals = {
34
+ ...app.locals,
35
+ ...options.serverOptions,
36
+ };
37
+ }
38
+ }
39
+ catch (error) {
40
+ logger.error(error.message, "handlebars-config");
41
+ }
42
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Engine = void 0;
4
+ var engine_1 = require("./engine");
5
+ Object.defineProperty(exports, "Engine", { enumerable: true, get: function () { return engine_1.Engine; } });
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.packageResolver = packageResolver;
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
5
+ const core_1 = require("@expressots/core");
6
+ /**
7
+ * Resolve package from the current working directory.
8
+ * @param packageName
9
+ * @param options
10
+ * @returns
11
+ */
12
+ function packageResolver(packageName, ...options) {
13
+ const logger = new core_1.Logger();
14
+ try {
15
+ const hasPackage = require.resolve(packageName, {
16
+ paths: [process.cwd()],
17
+ });
18
+ if (hasPackage) {
19
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
20
+ const packageResolved = require(hasPackage);
21
+ if (typeof packageResolved === "function") {
22
+ return packageResolved(...options);
23
+ }
24
+ if (packageResolved.default && typeof packageResolved.default === "function") {
25
+ return packageResolved.default(...options);
26
+ }
27
+ return packageResolved;
28
+ }
29
+ }
30
+ catch (error) {
31
+ logger.warn(`Package [${packageName}] not installed. Please install it using your package manager.`, "package-resolver");
32
+ }
33
+ }
@@ -1,8 +1,9 @@
1
- import { IApplicationMessageToConsole, RenderTemplateOptions } from "@expressots/core";
1
+ import { IApplicationMessageToConsole } from "@expressots/core";
2
2
  import express from "express";
3
3
  import { Container } from "inversify";
4
4
  import { ApplicationBase } from "./application-express.base";
5
5
  import { IWebServer, ServerEnvironment } from "./application-express.types";
6
+ import { Engine, EngineOptions } from "./render/engine";
6
7
  /**
7
8
  * The AppExpress class provides methods for configuring and running an Express application.
8
9
  * @class AppExpress
@@ -23,6 +24,7 @@ declare class AppExpress extends ApplicationBase implements IWebServer {
23
24
  private globalPrefix;
24
25
  private middlewares;
25
26
  private console;
27
+ private renderOptions;
26
28
  protected configureServices(): void | Promise<void>;
27
29
  protected postServerInitialization(): void | Promise<void>;
28
30
  protected serverShutdown(): void | Promise<void>;
@@ -65,6 +67,10 @@ declare class AppExpress extends ApplicationBase implements IWebServer {
65
67
  *
66
68
  */
67
69
  setGlobalRoutePrefix(prefix: string): void;
70
+ /**
71
+ * Configures the application's view engine based on the provided configuration options.
72
+ */
73
+ private configEngine;
68
74
  /**
69
75
  * Configures the application's view engine based on the provided configuration options.
70
76
  *
@@ -72,11 +78,10 @@ declare class AppExpress extends ApplicationBase implements IWebServer {
72
78
  * @method setEngine
73
79
  * @template T - A generic type extending from RenderTemplateOptions.
74
80
  *
75
- * @param {T} options - An object of type T (must be an object that extends RenderTemplateOptions)
76
- * that provides the configuration options for setting the view engine.
77
- * This includes the extension name, view path, and the engine function itself.
81
+ * @param {Engine} engine - The view engine to set
82
+ * @param {EngineOptions} [options] - The configuration options for the view engine
78
83
  */
79
- setEngine<T extends RenderTemplateOptions>(options: T): void;
84
+ setEngine<T extends EngineOptions>(engine: Engine, options?: T): Promise<void>;
80
85
  /**
81
86
  * Verifies if the current environment is development.
82
87
  *
@@ -1,5 +1,5 @@
1
+ import { IApplicationMessageToConsole } from "@expressots/core";
1
2
  import express from "express";
2
- import { IApplicationMessageToConsole, RenderTemplateOptions } from "@expressots/core";
3
3
  import { ServerEnvironment } from "./application-express.types";
4
4
  /**
5
5
  * Public Interface for the WebServer application.
@@ -12,18 +12,6 @@ export interface IWebServerPublic {
12
12
  * @param consoleMessage - Optional message to display in the console.
13
13
  */
14
14
  listen(port: number, environment: ServerEnvironment, consoleMessage?: IApplicationMessageToConsole): Promise<void>;
15
- /**
16
- * Configures the application's view engine based on the provided configuration options.
17
- *
18
- * @public
19
- * @method setEngine
20
- * @template T - A generic type extending from RenderTemplateOptions.
21
- *
22
- * @param {T} options - An object of type T (must be an object that extends RenderTemplateOptions)
23
- * that provides the configuration options for setting the view engine.
24
- * This includes the extension name, view path, and the engine function itself.
25
- */
26
- setEngine<T extends RenderTemplateOptions>(options: T): void;
27
15
  /**
28
16
  * Get the underlying HTTP server. (default: Express.js)
29
17
  * @returns The underlying HTTP server after initialization.
@@ -1,13 +1,14 @@
1
1
  import express, { Request, Response, NextFunction } from "express";
2
- import { IApplicationMessageToConsole, RenderTemplateOptions } from "@expressots/core";
2
+ import { IApplicationMessageToConsole } from "@expressots/core";
3
3
  import { Container } from "inversify";
4
+ import { Engine, EngineOptions } from "./render/engine";
4
5
  /**
5
6
  * Interface for the WebServer application implementation.
6
7
  */
7
8
  export interface IWebServer {
8
9
  configure(container: Container): Promise<void>;
9
10
  listen(port: number, environment: ServerEnvironment, consoleMessage?: IApplicationMessageToConsole): Promise<void>;
10
- setEngine<T extends RenderTemplateOptions>(options: T): void;
11
+ setEngine<T extends EngineOptions>(engine: Engine, options?: T): Promise<void>;
11
12
  }
12
13
  /**
13
14
  * Constructor type for IWebServer.
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type { OutgoingHttpHeaders } from "node:http";
3
2
  export declare abstract class HttpContent {
4
3
  private _headers;
@@ -1,7 +1,7 @@
1
1
  import "reflect-metadata";
2
2
  import { PARAMETER_TYPE, HTTP_VERBS_ENUM } from "./constants";
3
3
  import type { HandlerDecorator, Middleware } from "./interfaces";
4
- export declare const injectHttpContext: (target: import("inversify/lib/annotation/decorator_utils").DecoratorTarget<unknown>, targetKey?: string | symbol, indexOrPropertyDescriptor?: number | TypedPropertyDescriptor<unknown>) => void;
4
+ export declare const injectHttpContext: (target: import("inversify/lib/annotation/decorator_utils").DecoratorTarget<unknown>, targetKey?: string | symbol | undefined, indexOrPropertyDescriptor?: number | TypedPropertyDescriptor<unknown>) => void;
5
5
  /**
6
6
  * Controller decorator to define a new controller
7
7
  * @param path route path
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type { OutgoingHttpHeaders } from "node:http";
3
2
  import { HttpContent } from "./content/httpContent";
4
3
  export declare class HttpResponseMessage {
@@ -2,3 +2,4 @@ export * from "./express-utils";
2
2
  export { AppExpress } from "./application-express";
3
3
  export { IWebServerPublic } from "./application-express.interface";
4
4
  export { IWebServer, IWebServerConstructor, ServerEnvironment } from "./application-express.types";
5
+ export * from "./render";
@@ -0,0 +1,21 @@
1
+ import { Application } from "express";
2
+ import { Options } from "./ejs.types";
3
+ /**
4
+ * Ejs options
5
+ * @typedef {Object} EjsOptions
6
+ * @property {string | Array<string>} viewsDir - The path to the views folder
7
+ * @property {string} viewEngine - The view engine
8
+ * @property {ejs.Options} [serverOptions] - The server options
9
+ *
10
+ */
11
+ export type EjsOptions = {
12
+ viewsDir?: string | Array<string>;
13
+ viewEngine?: string;
14
+ serverOptions?: Options;
15
+ };
16
+ /**
17
+ * Set Ejs as the view engine
18
+ * @param {Application} app - The express application
19
+ * @param {EjsOptions} [options=EJS_DEFAULTS] - The ejs options
20
+ */
21
+ export declare function setEngineEjs(app: Application, options?: EjsOptions): Promise<void>;
@@ -0,0 +1,169 @@
1
+ /**
2
+ * An object where {@link filename} is the final parsed path or {@link template} is the content of the included template
3
+ */
4
+ export type IncluderResult = {
5
+ filename: string;
6
+ template?: never;
7
+ } | {
8
+ template: string;
9
+ filename?: never;
10
+ };
11
+ /**
12
+ * @param originalPath the path as it appears in the include statement
13
+ * @param parsedPath the previously resolved path
14
+ *
15
+ * @return An {@link IncluderResult} object containing the filename or template data.
16
+ */
17
+ type IncluderCallback = (originalPath: string, parsedPath: string) => IncluderResult;
18
+ /**
19
+ * Escapes a string using HTML/XML escaping rules.
20
+ *
21
+ * Returns the empty string for `null` or `undefined`.
22
+ *
23
+ * @param markup Input string
24
+ * @return Escaped string
25
+ */
26
+ type EscapeCallback = (markup?: any) => string;
27
+ export interface Options {
28
+ /**
29
+ * Log the generated JavaScript source for the EJS template to the console.
30
+ *
31
+ * @default false
32
+ */
33
+ debug?: boolean | undefined;
34
+ /**
35
+ * Include additional runtime debugging information in generated template
36
+ * functions.
37
+ *
38
+ * @default true
39
+ */
40
+ compileDebug?: boolean | undefined;
41
+ /**
42
+ * Whether or not to use `with () {}` construct in the generated template
43
+ * functions. If set to `false`, data is still accessible through the object
44
+ * whose name is specified by `ejs.localsName` (defaults to `locals`).
45
+ *
46
+ * @default true
47
+ */
48
+ _with?: boolean | undefined;
49
+ /**
50
+ * Whether to run in strict mode or not.
51
+ * Enforces `_with=false`.
52
+ *
53
+ * @default false
54
+ */
55
+ strict?: boolean | undefined;
56
+ /**
57
+ * An array of local variables that are always destructured from `localsName`,
58
+ * available even in strict mode.
59
+ *
60
+ * @default []
61
+ */
62
+ destructuredLocals?: Array<string> | undefined;
63
+ /**
64
+ * Remove all safe-to-remove whitespace, including leading and trailing
65
+ * whitespace. It also enables a safer version of `-%>` line slurping for all
66
+ * scriptlet tags (it does not strip new lines of tags in the middle of a
67
+ * line).
68
+ *
69
+ * @default false
70
+ */
71
+ rmWhitespace?: boolean | undefined;
72
+ /**
73
+ * Whether or not to compile a `ClientFunction` that can be rendered
74
+ * in the browser without depending on ejs.js. Otherwise, a `TemplateFunction`
75
+ * will be compiled.
76
+ *
77
+ * @default false
78
+ */
79
+ client?: boolean | undefined;
80
+ /**
81
+ * The escaping function used with `<%=` construct. It is used in rendering
82
+ * and is `.toString()`ed in the generation of client functions.
83
+ *
84
+ * @default ejs.escapeXML
85
+ */
86
+ escape?: EscapeCallback | undefined;
87
+ /**
88
+ * The filename of the template. Required for inclusion and caching unless
89
+ * you are using `renderFile`. Also used for error reporting.
90
+ *
91
+ * @default undefined
92
+ */
93
+ filename?: string | undefined;
94
+ /**
95
+ * The path to templates root(s). When this is set, absolute paths for includes
96
+ * (/filename.ejs) will be relative to the templates root(s).
97
+ *
98
+ * @default undefined
99
+ */
100
+ root?: Array<string> | string | undefined;
101
+ /**
102
+ * The opening delimiter for all statements. This allows you to clearly delinate
103
+ * the difference between template code and existing delimiters. (It is recommended
104
+ * to synchronize this with the closeDelimiter property.)
105
+ *
106
+ * @default ejs.openDelimiter
107
+ */
108
+ openDelimiter?: string | undefined;
109
+ /**
110
+ * The closing delimiter for all statements. This allows to to clearly delinate
111
+ * the difference between template code and existing delimiters. (It is recommended
112
+ * to synchronize this with the openDelimiter property.)
113
+ *
114
+ * @default ejs.closeDelimiter
115
+ */
116
+ closeDelimiter?: string | undefined;
117
+ /**
118
+ * Character to use with angle brackets for open/close
119
+ * @default '%'
120
+ */
121
+ delimiter?: string | undefined;
122
+ /**
123
+ * Whether or not to enable caching of template functions. Beware that
124
+ * the options of compilation are not checked as being the same, so
125
+ * special handling is required if, for example, you want to cache client
126
+ * and regular functions of the same file.
127
+ *
128
+ * Requires `filename` to be set. Only works with rendering function.
129
+ *
130
+ * @default false
131
+ */
132
+ cache?: boolean | undefined;
133
+ /**
134
+ * The Object to which `this` is set during rendering.
135
+ *
136
+ * @default this
137
+ */
138
+ context?: any;
139
+ /**
140
+ * Whether or not to create an async function instead of a regular function.
141
+ * This requires language support.
142
+ *
143
+ * @default false
144
+ */
145
+ async?: boolean | undefined;
146
+ /**
147
+ * Make sure to set this to 'false' in order to skip UglifyJS parsing,
148
+ * when using ES6 features (`const`, etc) as UglifyJS doesn't understand them.
149
+ * @default true
150
+ */
151
+ beautify?: boolean | undefined;
152
+ /**
153
+ * Name to use for the object storing local variables when not using `with` or destructuring.
154
+ *
155
+ * @default ejs.localsName
156
+ */
157
+ localsName?: string | undefined;
158
+ /** Set to a string (e.g., 'echo' or 'print') for a function to print output inside scriptlet tags. */
159
+ outputFunctionName?: string | undefined;
160
+ /**
161
+ * An array of paths to use when resolving includes with relative paths
162
+ */
163
+ views?: Array<string> | undefined;
164
+ /**
165
+ * Custom function to handle EJS includes
166
+ */
167
+ includer?: IncluderCallback;
168
+ }
169
+ export {};
@@ -0,0 +1,27 @@
1
+ import { EjsOptions } from "./ejs/ejs.config";
2
+ import { HandlebarsOptions } from "./handlebars/hbs.config";
3
+ /**
4
+ * The configuration options for the view engine.
5
+ * @typedef {HandlebarsOptions | EjsOptions} EngineOptions
6
+ * @private
7
+ */
8
+ export type RenderOptions = {
9
+ engine: Engine;
10
+ options?: EngineOptions;
11
+ };
12
+ /**
13
+ * The supported view engines.
14
+ * @enum {string}
15
+ * @readonly
16
+ * @public
17
+ */
18
+ export declare enum Engine {
19
+ HBS = "hbs",
20
+ EJS = "ejs"
21
+ }
22
+ /**
23
+ * The configuration options for the view engine.
24
+ * @typedef {HandlebarsOptions | EjsOptions} EngineOptions
25
+ * @public
26
+ */
27
+ export type EngineOptions = HandlebarsOptions | EjsOptions;
@@ -0,0 +1,20 @@
1
+ import express from "express";
2
+ /**
3
+ * Handlebars options
4
+ * @typedef {Object} HandlebarsOptions
5
+ * @property {string} viewsDir - The path to the views folder
6
+ * @property {string} viewEngine - The view engine to be used
7
+ * @property {ConfigOptions} [serverOptions] - The server options
8
+ *
9
+ */
10
+ export type HandlebarsOptions = {
11
+ viewsDir?: string | Array<string>;
12
+ viewEngine?: string;
13
+ serverOptions?: unknown;
14
+ };
15
+ /**
16
+ * Set Handlebars as the view engine
17
+ * @param {express.Application} app - The express application
18
+ * @param {HandlebarsOptions} [options=HANDLEBARS_DEFAULTS] - The handlebars options
19
+ */
20
+ export declare function setEngineHandlebars(app: express.Application, options?: HandlebarsOptions): Promise<void>;
@@ -0,0 +1,3 @@
1
+ export { EjsOptions as EJS } from "./ejs/ejs.config";
2
+ export { HandlebarsOptions as HBS } from "./handlebars/hbs.config";
3
+ export { Engine } from "./engine";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Resolve package from the current working directory.
3
+ * @param packageName
4
+ * @param options
5
+ * @returns
6
+ */
7
+ export declare function packageResolver(packageName: string, ...options: Array<any>): any;
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressots/adapter-express",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "Expressots - modern, fast, lightweight nodejs web framework (@adapter-express)",
5
5
  "author": "",
6
6
  "main": "./lib/cjs/index.js",
@@ -47,10 +47,10 @@
47
47
  "server-side"
48
48
  ],
49
49
  "engines": {
50
- "node": ">=18.10.0"
50
+ "node": ">=18.18.0"
51
51
  },
52
52
  "scripts": {
53
- "prepare": "husky install",
53
+ "prepare": "husky",
54
54
  "clean": "node scripts/rm.js lib",
55
55
  "copy": "node scripts/copy.js package.json README.md CHANGELOG.md lib",
56
56
  "build": "npm run clean && npm run build:cjs && npm run copy",
@@ -73,25 +73,24 @@
73
73
  },
74
74
  "devDependencies": {
75
75
  "@codecov/vite-plugin": "^0.0.1-beta.6",
76
- "@commitlint/cli": "18.0.0",
76
+ "@commitlint/cli": "19.2.1",
77
77
  "@commitlint/config-conventional": "19.2.2",
78
- "@expressots/core": "latest",
79
- "@release-it/conventional-changelog": "7.0.2",
78
+ "@expressots/core": "2.15.0",
79
+ "@release-it/conventional-changelog": "8.0.1",
80
80
  "@types/express": "4.17.21",
81
- "@types/node": "20.4.9",
82
- "@typescript-eslint/eslint-plugin": "6.6.0",
83
- "@typescript-eslint/parser": "6.6.0",
84
- "@vitest/coverage-v8": "^1.4.0",
85
- "eslint": "8.48.0",
81
+ "@types/node": "20.14.10",
82
+ "@typescript-eslint/eslint-plugin": "7.16.1",
83
+ "@typescript-eslint/parser": "7.16.1",
84
+ "@vitest/coverage-v8": "2.0.3",
85
+ "eslint": "8.57.0",
86
86
  "eslint-config-prettier": "9.1.0",
87
87
  "husky": "9.0.11",
88
- "prettier": "3.3.2",
89
- "release-it": "16.3.0",
90
- "ts-jest": "29.0.5",
91
- "typescript": "5.2.2",
92
- "vite": "^5.2.8",
93
- "vite-tsconfig-paths": "^4.3.2",
94
- "vitest": "^1.4.0"
88
+ "prettier": "3.3.3",
89
+ "release-it": "17.6.0",
90
+ "typescript": "5.5.3",
91
+ "vite": "5.3.3",
92
+ "vite-tsconfig-paths": "4.3.2",
93
+ "vitest": "2.0.3"
95
94
  },
96
95
  "release-it": {
97
96
  "git": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressots/adapter-express",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "Expressots - modern, fast, lightweight nodejs web framework (@adapter-express)",
5
5
  "author": "",
6
6
  "main": "./lib/cjs/index.js",
@@ -47,10 +47,10 @@
47
47
  "server-side"
48
48
  ],
49
49
  "engines": {
50
- "node": ">=18.10.0"
50
+ "node": ">=18.18.0"
51
51
  },
52
52
  "scripts": {
53
- "prepare": "husky install",
53
+ "prepare": "husky",
54
54
  "clean": "node scripts/rm.js lib",
55
55
  "copy": "node scripts/copy.js package.json README.md CHANGELOG.md lib",
56
56
  "build": "npm run clean && npm run build:cjs && npm run copy",
@@ -73,25 +73,24 @@
73
73
  },
74
74
  "devDependencies": {
75
75
  "@codecov/vite-plugin": "^0.0.1-beta.6",
76
- "@commitlint/cli": "18.0.0",
76
+ "@commitlint/cli": "19.2.1",
77
77
  "@commitlint/config-conventional": "19.2.2",
78
- "@expressots/core": "latest",
79
- "@release-it/conventional-changelog": "7.0.2",
78
+ "@expressots/core": "2.15.0",
79
+ "@release-it/conventional-changelog": "8.0.1",
80
80
  "@types/express": "4.17.21",
81
- "@types/node": "20.4.9",
82
- "@typescript-eslint/eslint-plugin": "6.6.0",
83
- "@typescript-eslint/parser": "6.6.0",
84
- "@vitest/coverage-v8": "^1.4.0",
85
- "eslint": "8.48.0",
81
+ "@types/node": "20.14.10",
82
+ "@typescript-eslint/eslint-plugin": "7.16.1",
83
+ "@typescript-eslint/parser": "7.16.1",
84
+ "@vitest/coverage-v8": "2.0.3",
85
+ "eslint": "8.57.0",
86
86
  "eslint-config-prettier": "9.1.0",
87
87
  "husky": "9.0.11",
88
- "prettier": "3.3.2",
89
- "release-it": "16.3.0",
90
- "ts-jest": "29.0.5",
91
- "typescript": "5.2.2",
92
- "vite": "^5.2.8",
93
- "vite-tsconfig-paths": "^4.3.2",
94
- "vitest": "^1.4.0"
88
+ "prettier": "3.3.3",
89
+ "release-it": "17.6.0",
90
+ "typescript": "5.5.3",
91
+ "vite": "5.3.3",
92
+ "vite-tsconfig-paths": "4.3.2",
93
+ "vitest": "2.0.3"
95
94
  },
96
95
  "release-it": {
97
96
  "git": {