@expressots/adapter-express 1.4.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.
- package/lib/CHANGELOG.md +50 -1
- package/lib/cjs/adapter-express/application-express.js +38 -10
- package/lib/cjs/adapter-express/express-utils/decorators.js +34 -24
- package/lib/cjs/adapter-express/express-utils/http-status-middleware.js +33 -1
- package/lib/cjs/adapter-express/express-utils/inversify-express-server.js +2 -3
- package/lib/cjs/adapter-express/express-utils/utils.js +7 -8
- package/lib/cjs/adapter-express/index.js +1 -0
- package/lib/cjs/adapter-express/render/ejs/ejs.config.js +35 -0
- package/lib/cjs/adapter-express/render/ejs/ejs.types.js +3 -0
- package/lib/cjs/adapter-express/render/engine.js +14 -0
- package/lib/cjs/adapter-express/render/handlebars/hbs.config.js +42 -0
- package/lib/cjs/adapter-express/render/index.js +5 -0
- package/lib/cjs/adapter-express/render/resolve-render.js +33 -0
- package/lib/cjs/types/adapter-express/application-express.d.ts +10 -5
- package/lib/cjs/types/adapter-express/application-express.interface.d.ts +1 -13
- package/lib/cjs/types/adapter-express/application-express.types.d.ts +3 -2
- package/lib/cjs/types/adapter-express/express-utils/content/httpContent.d.ts +0 -1
- package/lib/cjs/types/adapter-express/express-utils/decorators.d.ts +1 -1
- package/lib/cjs/types/adapter-express/express-utils/http-status-middleware.d.ts +13 -0
- package/lib/cjs/types/adapter-express/express-utils/httpResponseMessage.d.ts +0 -1
- package/lib/cjs/types/adapter-express/index.d.ts +1 -0
- package/lib/cjs/types/adapter-express/render/ejs/ejs.config.d.ts +21 -0
- package/lib/cjs/types/adapter-express/render/ejs/ejs.types.d.ts +169 -0
- package/lib/cjs/types/adapter-express/render/engine.d.ts +27 -0
- package/lib/cjs/types/adapter-express/render/handlebars/hbs.config.d.ts +20 -0
- package/lib/cjs/types/adapter-express/render/index.d.ts +3 -0
- package/lib/cjs/types/adapter-express/render/resolve-render.d.ts +7 -0
- package/lib/package.json +20 -21
- package/package.json +20 -21
package/lib/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
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
|
+
|
|
25
|
+
## [1.5.0](https://github.com/expressots/adapter-express/compare/1.4.0...1.5.0) (2024-06-11)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Features
|
|
29
|
+
|
|
30
|
+
* bump @commitlint/config-conventional from 17.7.0 to 19.2.2 ([c4db260](https://github.com/expressots/adapter-express/commit/c4db260694b492e5744dc7c59ce4edae23053ec8))
|
|
31
|
+
* bump @release-it/conventional-changelog from 7.0.1 to 7.0.2 ([d063fd9](https://github.com/expressots/adapter-express/commit/d063fd9ff2b405eb69197b70cad72334d814b6bf))
|
|
32
|
+
* bump eslint-config-prettier from 9.0.0 to 9.1.0 ([20ca753](https://github.com/expressots/adapter-express/commit/20ca753e4297889506af98e6caa5b1f374aded59))
|
|
33
|
+
* bump husky from 8.0.3 to 9.0.11 ([8cb065e](https://github.com/expressots/adapter-express/commit/8cb065e49e209b2a6ab56d07a712df30596350ca))
|
|
34
|
+
* bump prettier from 3.0.3 to 3.3.1 ([872c7ba](https://github.com/expressots/adapter-express/commit/872c7ba7072c1cfb36a7efe74be0b41f6aea541b))
|
|
35
|
+
* bump prettier from 3.3.1 to 3.3.2 ([5edd349](https://github.com/expressots/adapter-express/commit/5edd3490f1a6fa48a65694a9c146c2ec69a264d3))
|
|
36
|
+
* bump release-it from 16.1.5 to 16.3.0 ([5febf25](https://github.com/expressots/adapter-express/commit/5febf2517dec9857d59ec189829262dafcc63fbd))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Bug Fixes
|
|
40
|
+
|
|
41
|
+
* decorator method case confict fix ([cdf0fbd](https://github.com/expressots/adapter-express/commit/cdf0fbd6c864a0e538372dc102664538112f0e30))
|
|
42
|
+
* init commit ([55359bf](https://github.com/expressots/adapter-express/commit/55359bf31acfdf0186f6916cd0dc1897d1f24cd2))
|
|
43
|
+
* patch issue where not using http decorator shows incorrect code ([975e451](https://github.com/expressots/adapter-express/commit/975e45112181088bcb9d8f1487e8272deb49d3df))
|
|
44
|
+
* remove comments and logs for prod build ([cd0151b](https://github.com/expressots/adapter-express/commit/cd0151be92f1cb73b6040a72db6d4f1268ae6cfc))
|
|
45
|
+
* remove unused method param in find param pattern ([fd40872](https://github.com/expressots/adapter-express/commit/fd4087276672a6b3c34563736892e4065a497bfa))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Code Refactoring
|
|
49
|
+
|
|
50
|
+
* without and with decor in the same route conflict ([469f65e](https://github.com/expressots/adapter-express/commit/469f65e9248aefe5db084608684ca211204c2f5b))
|
|
51
|
+
|
|
3
52
|
## [1.4.0](https://github.com/expressots/adapter-express/compare/1.3.0...1.4.0) (2024-06-07)
|
|
4
53
|
|
|
5
54
|
|
|
@@ -92,4 +141,4 @@
|
|
|
92
141
|
|
|
93
142
|
### Bug Fixes
|
|
94
143
|
|
|
95
|
-
* 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 {
|
|
156
|
-
*
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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.
|
|
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");
|
|
@@ -17,16 +28,14 @@ function controller(path, ...middleware) {
|
|
|
17
28
|
path,
|
|
18
29
|
target,
|
|
19
30
|
};
|
|
20
|
-
const pathMetadata = Reflect.getOwnMetadata(constants_1.HTTP_CODE_METADATA.path, Reflect);
|
|
21
|
-
const statusCodeMetadata = Reflect.getOwnMetadata(constants_1.HTTP_CODE_METADATA.statusCode, Reflect);
|
|
22
|
-
|
|
23
|
-
if (!statusCodePathMapping) {
|
|
24
|
-
statusCodePathMapping = {};
|
|
25
|
-
}
|
|
31
|
+
const pathMetadata = Reflect.getOwnMetadata(constants_1.HTTP_CODE_METADATA.path, Reflect) || {};
|
|
32
|
+
const statusCodeMetadata = Reflect.getOwnMetadata(constants_1.HTTP_CODE_METADATA.statusCode, Reflect) || {};
|
|
33
|
+
const statusCodePathMapping = Reflect.getOwnMetadata(constants_1.HTTP_CODE_METADATA.httpCode, Reflect) || {};
|
|
26
34
|
for (const key in pathMetadata) {
|
|
27
35
|
if (statusCodeMetadata && statusCodeMetadata[key]) {
|
|
28
|
-
const realPath = pathMetadata[key] === "/" ? path : `${path}${pathMetadata[key]}`;
|
|
29
|
-
statusCodePathMapping[realPath] =
|
|
36
|
+
const realPath = pathMetadata[key]["path"] === "/" ? path : `${path}${pathMetadata[key]["path"]}`;
|
|
37
|
+
statusCodePathMapping[`${realPath}/-${pathMetadata[key]["method"].toLowerCase()}`] =
|
|
38
|
+
statusCodeMetadata[key];
|
|
30
39
|
}
|
|
31
40
|
}
|
|
32
41
|
Reflect.defineMetadata(constants_1.HTTP_CODE_METADATA.httpCode, statusCodePathMapping, Reflect);
|
|
@@ -39,7 +48,6 @@ function controller(path, ...middleware) {
|
|
|
39
48
|
Reflect.defineMetadata(constants_1.METADATA_KEY.controller, newMetadata, Reflect);
|
|
40
49
|
};
|
|
41
50
|
}
|
|
42
|
-
exports.controller = controller;
|
|
43
51
|
/**
|
|
44
52
|
* Http decorator to define the status code for a route
|
|
45
53
|
* @param code
|
|
@@ -67,7 +75,6 @@ function Http(code) {
|
|
|
67
75
|
Reflect.defineMetadata(constants_1.HTTP_CODE_METADATA.statusCode, httpCodeMetadata, Reflect);
|
|
68
76
|
};
|
|
69
77
|
}
|
|
70
|
-
exports.Http = Http;
|
|
71
78
|
/**
|
|
72
79
|
* Decorator to allow accept all HTTP methods
|
|
73
80
|
* @param path route path, wildcard
|
|
@@ -76,7 +83,6 @@ exports.Http = Http;
|
|
|
76
83
|
function All(path, ...middleware) {
|
|
77
84
|
return httpMethod("all", path, ...middleware);
|
|
78
85
|
}
|
|
79
|
-
exports.All = All;
|
|
80
86
|
/**
|
|
81
87
|
* Decorator to allow GET HTTP method
|
|
82
88
|
* @param path route path
|
|
@@ -85,7 +91,6 @@ exports.All = All;
|
|
|
85
91
|
function Get(path, ...middleware) {
|
|
86
92
|
return enhancedHttpMethod("get", path, ...middleware);
|
|
87
93
|
}
|
|
88
|
-
exports.Get = Get;
|
|
89
94
|
/**
|
|
90
95
|
* Decorator to allow POST HTTP method
|
|
91
96
|
* @param path route path
|
|
@@ -94,7 +99,6 @@ exports.Get = Get;
|
|
|
94
99
|
function Post(path, ...middleware) {
|
|
95
100
|
return httpMethod("post", path, ...middleware);
|
|
96
101
|
}
|
|
97
|
-
exports.Post = Post;
|
|
98
102
|
/**
|
|
99
103
|
* Decorator to allow PUT HTTP method
|
|
100
104
|
* @param path route path
|
|
@@ -103,7 +107,6 @@ exports.Post = Post;
|
|
|
103
107
|
function Put(path, ...middleware) {
|
|
104
108
|
return enhancedHttpMethod("put", path, ...middleware);
|
|
105
109
|
}
|
|
106
|
-
exports.Put = Put;
|
|
107
110
|
/**
|
|
108
111
|
* Decorator to allow PATCH HTTP method
|
|
109
112
|
* @param path route path
|
|
@@ -112,7 +115,6 @@ exports.Put = Put;
|
|
|
112
115
|
function Patch(path, ...middleware) {
|
|
113
116
|
return enhancedHttpMethod("patch", path, ...middleware);
|
|
114
117
|
}
|
|
115
|
-
exports.Patch = Patch;
|
|
116
118
|
/**
|
|
117
119
|
* Decorator to allow HEAD HTTP method
|
|
118
120
|
* @param path route path
|
|
@@ -121,7 +123,6 @@ exports.Patch = Patch;
|
|
|
121
123
|
function Head(path, ...middleware) {
|
|
122
124
|
return httpMethod("head", path, ...middleware);
|
|
123
125
|
}
|
|
124
|
-
exports.Head = Head;
|
|
125
126
|
/**
|
|
126
127
|
* Decorator to allow DELETE HTTP method
|
|
127
128
|
* @param path route path
|
|
@@ -130,7 +131,6 @@ exports.Head = Head;
|
|
|
130
131
|
function Delete(path, ...middleware) {
|
|
131
132
|
return enhancedHttpMethod("delete", path, ...middleware);
|
|
132
133
|
}
|
|
133
|
-
exports.Delete = Delete;
|
|
134
134
|
/**
|
|
135
135
|
* Decorator to allow OPTIONS HTTP method
|
|
136
136
|
* @param path route path
|
|
@@ -148,11 +148,17 @@ function enhancedHttpMethod(method, path, ...middleware) {
|
|
|
148
148
|
let metadataList = [];
|
|
149
149
|
let pathMetadata = Reflect.getOwnMetadata(constants_1.HTTP_CODE_METADATA.path, Reflect);
|
|
150
150
|
if (pathMetadata) {
|
|
151
|
-
pathMetadata[key] =
|
|
151
|
+
pathMetadata[key] = {
|
|
152
|
+
path,
|
|
153
|
+
method,
|
|
154
|
+
};
|
|
152
155
|
}
|
|
153
156
|
else {
|
|
154
157
|
pathMetadata = {};
|
|
155
|
-
pathMetadata[key] =
|
|
158
|
+
pathMetadata[key] = {
|
|
159
|
+
path,
|
|
160
|
+
method,
|
|
161
|
+
};
|
|
156
162
|
}
|
|
157
163
|
Reflect.defineMetadata(constants_1.HTTP_CODE_METADATA.path, pathMetadata, Reflect);
|
|
158
164
|
if (!Reflect.hasOwnMetadata(constants_1.METADATA_KEY.controllerMethod, target.constructor)) {
|
|
@@ -193,11 +199,17 @@ function httpMethod(method, path, ...middleware) {
|
|
|
193
199
|
let metadataList = [];
|
|
194
200
|
let pathMetadata = Reflect.getOwnMetadata(constants_1.HTTP_CODE_METADATA.path, Reflect);
|
|
195
201
|
if (pathMetadata) {
|
|
196
|
-
pathMetadata[key] =
|
|
202
|
+
pathMetadata[key] = {
|
|
203
|
+
path,
|
|
204
|
+
method,
|
|
205
|
+
};
|
|
197
206
|
}
|
|
198
207
|
else {
|
|
199
208
|
pathMetadata = {};
|
|
200
|
-
pathMetadata[key] =
|
|
209
|
+
pathMetadata[key] = {
|
|
210
|
+
path,
|
|
211
|
+
method,
|
|
212
|
+
};
|
|
201
213
|
}
|
|
202
214
|
Reflect.defineMetadata(constants_1.HTTP_CODE_METADATA.path, pathMetadata, Reflect);
|
|
203
215
|
if (!Reflect.hasOwnMetadata(constants_1.METADATA_KEY.controllerMethod, target.constructor)) {
|
|
@@ -209,7 +221,6 @@ function httpMethod(method, path, ...middleware) {
|
|
|
209
221
|
metadataList.push(metadata);
|
|
210
222
|
};
|
|
211
223
|
}
|
|
212
|
-
exports.httpMethod = httpMethod;
|
|
213
224
|
/**
|
|
214
225
|
* Parameter decorator to inject the request object
|
|
215
226
|
* @returns ParameterDecorator
|
|
@@ -290,7 +301,6 @@ function params(type, parameterName) {
|
|
|
290
301
|
Reflect.defineMetadata(constants_1.METADATA_KEY.controllerParameter, metadataList, target.constructor);
|
|
291
302
|
};
|
|
292
303
|
}
|
|
293
|
-
exports.params = params;
|
|
294
304
|
/**
|
|
295
305
|
* Converts a string value to the specified type.
|
|
296
306
|
* @param value The value to convert.
|
|
@@ -12,18 +12,47 @@ class HttpStatusCodeMiddleware extends core_1.ExpressoMiddleware {
|
|
|
12
12
|
use(req, res, next) {
|
|
13
13
|
const statusCodeMapping = Reflect.getMetadata(constants_1.HTTP_CODE_METADATA.httpCode, Reflect);
|
|
14
14
|
let path = req.path.endsWith("/") ? req.path.slice(0, -1) : req.path;
|
|
15
|
+
const formattedMethod = req.method.toLowerCase();
|
|
15
16
|
if (path === "/" || path === "") {
|
|
16
17
|
path = "/";
|
|
17
18
|
}
|
|
19
|
+
path = `${path}/-${formattedMethod}`;
|
|
18
20
|
const statusCode = statusCodeMapping[path];
|
|
19
21
|
if (statusCode) {
|
|
20
22
|
res.status(statusCode);
|
|
21
23
|
}
|
|
22
24
|
else {
|
|
23
|
-
this.
|
|
25
|
+
const patternMatchStatusCode = this.findMatchingParameterPath(path, statusCodeMapping);
|
|
26
|
+
if (patternMatchStatusCode) {
|
|
27
|
+
res.status(patternMatchStatusCode);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this.setDefaultStatusCode(req, res);
|
|
31
|
+
}
|
|
24
32
|
}
|
|
25
33
|
next();
|
|
26
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Find the matching parameter path.
|
|
37
|
+
* @param path - The path to match.
|
|
38
|
+
* @param mapping - The mapping to check.
|
|
39
|
+
* @param method - The method to check.
|
|
40
|
+
* @returns The status code if found, otherwise null.
|
|
41
|
+
**/
|
|
42
|
+
findMatchingParameterPath(path, mapping) {
|
|
43
|
+
for (const pathCode in mapping) {
|
|
44
|
+
const patternCheck = new RegExp("^" + pathCode.replace(/:[^\s/]+/g, "([^/]+)") + "$");
|
|
45
|
+
if (patternCheck.test(path)) {
|
|
46
|
+
return mapping[pathCode];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Set the default status code based on the request method.
|
|
53
|
+
* @param req - The request object.
|
|
54
|
+
* @param res - The response object.
|
|
55
|
+
**/
|
|
27
56
|
setDefaultStatusCode(req, res) {
|
|
28
57
|
switch (req.method.toLowerCase()) {
|
|
29
58
|
case "get":
|
|
@@ -35,6 +64,9 @@ class HttpStatusCodeMiddleware extends core_1.ExpressoMiddleware {
|
|
|
35
64
|
case "put":
|
|
36
65
|
res.statusCode = 204;
|
|
37
66
|
break;
|
|
67
|
+
case "patch":
|
|
68
|
+
res.statusCode = 204;
|
|
69
|
+
break;
|
|
38
70
|
case "delete":
|
|
39
71
|
res.statusCode = 204;
|
|
40
72
|
break;
|
|
@@ -194,10 +194,9 @@ class InversifyExpressServer {
|
|
|
194
194
|
value();
|
|
195
195
|
}
|
|
196
196
|
else if (!res.headersSent) {
|
|
197
|
-
if (value
|
|
198
|
-
res.
|
|
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.
|
|
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,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,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
|
|
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 {
|
|
76
|
-
*
|
|
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
|
|
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
|
|
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
|
|
11
|
+
setEngine<T extends EngineOptions>(engine: Engine, options?: T): Promise<void>;
|
|
11
12
|
}
|
|
12
13
|
/**
|
|
13
14
|
* Constructor type for IWebServer.
|
|
@@ -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
|
|
@@ -7,5 +7,18 @@ import { ExpressoMiddleware } from "@expressots/core";
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class HttpStatusCodeMiddleware extends ExpressoMiddleware {
|
|
9
9
|
use(req: Request, res: Response, next: NextFunction): void | Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Find the matching parameter path.
|
|
12
|
+
* @param path - The path to match.
|
|
13
|
+
* @param mapping - The mapping to check.
|
|
14
|
+
* @param method - The method to check.
|
|
15
|
+
* @returns The status code if found, otherwise null.
|
|
16
|
+
**/
|
|
17
|
+
private findMatchingParameterPath;
|
|
18
|
+
/**
|
|
19
|
+
* Set the default status code based on the request method.
|
|
20
|
+
* @param req - The request object.
|
|
21
|
+
* @param res - The response object.
|
|
22
|
+
**/
|
|
10
23
|
private setDefaultStatusCode;
|
|
11
24
|
}
|
|
@@ -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>;
|
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/adapter-express",
|
|
3
|
-
"version": "1.
|
|
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.
|
|
50
|
+
"node": ">=18.18.0"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
|
-
"prepare": "husky
|
|
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": "
|
|
77
|
-
"@commitlint/config-conventional": "
|
|
78
|
-
"@expressots/core": "
|
|
79
|
-
"@release-it/conventional-changelog": "
|
|
76
|
+
"@commitlint/cli": "19.2.1",
|
|
77
|
+
"@commitlint/config-conventional": "19.2.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.
|
|
82
|
-
"@typescript-eslint/eslint-plugin": "
|
|
83
|
-
"@typescript-eslint/parser": "
|
|
84
|
-
"@vitest/coverage-v8": "
|
|
85
|
-
"eslint": "8.
|
|
86
|
-
"eslint-config-prettier": "9.
|
|
87
|
-
"husky": "
|
|
88
|
-
"prettier": "3.
|
|
89
|
-
"release-it": "
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"vite": "
|
|
93
|
-
"
|
|
94
|
-
"vitest": "^1.4.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
|
+
"eslint-config-prettier": "9.1.0",
|
|
87
|
+
"husky": "9.0.11",
|
|
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.
|
|
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.
|
|
50
|
+
"node": ">=18.18.0"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
|
-
"prepare": "husky
|
|
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": "
|
|
77
|
-
"@commitlint/config-conventional": "
|
|
78
|
-
"@expressots/core": "
|
|
79
|
-
"@release-it/conventional-changelog": "
|
|
76
|
+
"@commitlint/cli": "19.2.1",
|
|
77
|
+
"@commitlint/config-conventional": "19.2.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.
|
|
82
|
-
"@typescript-eslint/eslint-plugin": "
|
|
83
|
-
"@typescript-eslint/parser": "
|
|
84
|
-
"@vitest/coverage-v8": "
|
|
85
|
-
"eslint": "8.
|
|
86
|
-
"eslint-config-prettier": "9.
|
|
87
|
-
"husky": "
|
|
88
|
-
"prettier": "3.
|
|
89
|
-
"release-it": "
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"vite": "
|
|
93
|
-
"
|
|
94
|
-
"vitest": "^1.4.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
|
+
"eslint-config-prettier": "9.1.0",
|
|
87
|
+
"husky": "9.0.11",
|
|
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": {
|