@expressots/core 2.10.0 → 2.11.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 +21 -0
- package/lib/cjs/application/{app-container.js → application-container.js} +8 -6
- package/lib/cjs/application/application-factory.js +19 -54
- package/lib/cjs/application/index.js +2 -2
- package/lib/cjs/console/console.js +7 -7
- package/lib/cjs/provider/dto-validator/dto-validator.provider.js +3 -3
- package/lib/cjs/provider/logger/logger.provider.js +2 -2
- package/lib/cjs/types/application/{app-container.d.ts → application-container.d.ts} +8 -6
- package/lib/cjs/types/application/application-factory.d.ts +6 -21
- package/lib/cjs/types/application/index.d.ts +1 -1
- package/lib/cjs/types/common/index.d.ts +1 -1
- package/lib/package.json +2 -2
- package/package.json +2 -2
- /package/lib/cjs/common/{color-service.provider.js → color-codes.js} +0 -0
- /package/lib/cjs/common/{package-resolver.provider.js → package-resolver.js} +0 -0
- /package/lib/cjs/common/{project-config.provider.js → project-config.js} +0 -0
- /package/lib/cjs/types/common/{color-service.provider.d.ts → color-codes.d.ts} +0 -0
- /package/lib/cjs/types/common/{package-resolver.provider.d.ts → package-resolver.d.ts} +0 -0
- /package/lib/cjs/types/common/{project-config.provider.d.ts → project-config.d.ts} +0 -0
package/lib/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## [2.11.0](https://github.com/expressots/expressots/compare/2.10.0...2.11.0) (2024-04-04)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* bump @types/node from 20.12.2 to 20.12.3 ([430ada9](https://github.com/expressots/expressots/commit/430ada937b04ad12ca26dad1decabffe0b5299ab))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* update adpater version to latest ([89c671d](https://github.com/expressots/expressots/commit/89c671d2905ceea8877ee5cc6c6fc8ddae262549))
|
|
14
|
+
* update console tests ([c639466](https://github.com/expressots/expressots/commit/c6394663749fe4ebda9ce0b54ccaa7e83593d0df))
|
|
15
|
+
* upgrade tsconfig-paths from 4.1.2 to 4.2.0 ([fc373a6](https://github.com/expressots/expressots/commit/fc373a64d41174351439a356afd3708aba0e8661))
|
|
16
|
+
* upgrade tsconfig-paths from 4.1.2 to 4.2.0 ([e8f0d68](https://github.com/expressots/expressots/commit/e8f0d68a02999d8bcf9936c1973b62a9c97119ac))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Code Refactoring
|
|
20
|
+
|
|
21
|
+
* appfactory class ([3fde40a](https://github.com/expressots/expressots/commit/3fde40a8754e22ad377e58d2c5a0b16fcf116dd0))
|
|
22
|
+
* rename items for standardization and improve doc ([d01f4d1](https://github.com/expressots/expressots/commit/d01f4d191a09716fde688404506ea7895efaf127))
|
|
23
|
+
|
|
3
24
|
## [2.10.0](https://github.com/expressots/expressots/compare/2.9.1...2.10.0) (2024-03-31)
|
|
4
25
|
|
|
5
26
|
|
|
@@ -18,16 +18,18 @@ const inversify_binding_decorators_1 = require("inversify-binding-decorators");
|
|
|
18
18
|
* and the ability to skip base class checks. The container can be loaded with multiple
|
|
19
19
|
* ContainerModule instances, facilitating modular and organized code.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* const container =
|
|
24
|
-
*
|
|
25
|
-
* @provide AppContainer
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const container = new AppContainer();
|
|
24
|
+
* container.create([new MyModule()]);
|
|
26
25
|
*/
|
|
27
26
|
let AppContainer = class AppContainer {
|
|
28
27
|
/**
|
|
29
28
|
* Constructs the AppContainer instance.
|
|
30
|
-
* @param options - The options for creating the container
|
|
29
|
+
* @param options - The options for creating the container with default request scope.
|
|
30
|
+
* @option options.defaultScope - The default scope for bindings in the container.
|
|
31
|
+
* @option options.skipBaseClassChecks - Allows skipping of base class checks when working with derived classes.
|
|
32
|
+
* @option options.autoBindInjectable - Allows auto-binding of injectable classes.
|
|
31
33
|
*/
|
|
32
34
|
constructor(options) {
|
|
33
35
|
this.options = {
|
|
@@ -2,73 +2,38 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AppFactory = void 0;
|
|
4
4
|
const logger_provider_1 = require("../provider/logger/logger.provider");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Type guard to check if input is a constructor type of IWebServer.
|
|
7
|
+
* @param input - Input to check.
|
|
8
|
+
* @returns True if input is a constructor type of IWebServer.
|
|
9
|
+
*/
|
|
10
|
+
function isWebServerConstructor(input) {
|
|
11
|
+
return input && typeof input === "function";
|
|
12
|
+
}
|
|
9
13
|
/**
|
|
10
14
|
* AppFactory Class
|
|
11
15
|
*
|
|
12
|
-
* Responsible for creating an instance of the
|
|
13
|
-
* either using a custom application type or with provided middlewares.
|
|
16
|
+
* Responsible for creating an instance of the IWebServer implementation using a custom application type.
|
|
14
17
|
*/
|
|
15
18
|
class AppFactory {
|
|
16
|
-
/* public static async create(
|
|
17
|
-
container: Container,
|
|
18
|
-
middlewares: Array<express.RequestHandler>,
|
|
19
|
-
httpServerFactory?: new () => AppFastify,
|
|
20
|
-
): Promise<AppFastify>; */
|
|
21
19
|
/**
|
|
22
|
-
*
|
|
20
|
+
* Create an instance of a web server.
|
|
23
21
|
* @param container - InversifyJS container to resolve dependencies.
|
|
24
|
-
* @param
|
|
25
|
-
* @returns
|
|
22
|
+
* @param webServerType - Constructor of a class that implements IWebServer, or array of middlewares.
|
|
23
|
+
* @returns A promise that resolves to an instance of IWebServer.
|
|
26
24
|
*/
|
|
27
|
-
static async create(container,
|
|
28
|
-
// Set the container for the application global access
|
|
25
|
+
static async create(container, webServerType) {
|
|
29
26
|
AppFactory.container = container;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
app = container.resolve(appTypeOrMiddlewares);
|
|
35
|
-
app.create(container);
|
|
36
|
-
return app;
|
|
37
|
-
/* case AppFastify:
|
|
38
|
-
app = container.resolve(appTypeOrMiddlewares as new () => AppFastify);
|
|
39
|
-
await app.create(container);
|
|
40
|
-
return app as IApplicationFastify; */
|
|
41
|
-
default:
|
|
42
|
-
app = container.resolve(appTypeOrMiddlewares);
|
|
43
|
-
app.create(container);
|
|
44
|
-
return app;
|
|
45
|
-
}
|
|
27
|
+
if (isWebServerConstructor(webServerType)) {
|
|
28
|
+
const webServerInstance = new webServerType();
|
|
29
|
+
await webServerInstance.configure(container);
|
|
30
|
+
return webServerInstance;
|
|
46
31
|
}
|
|
47
32
|
else {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
app = container.get(adapter_express_1.AppExpress);
|
|
51
|
-
app.create(container, appTypeOrMiddlewares);
|
|
52
|
-
return app;
|
|
53
|
-
/* case AppFastify:
|
|
54
|
-
app = container.get<AppFastify>(AppFastify);
|
|
55
|
-
await app.create(container, appTypeOrMiddlewares as Array<Handler>);
|
|
56
|
-
return app as AppFastify; */
|
|
57
|
-
default:
|
|
58
|
-
app = container.get(adapter_express_1.AppExpress);
|
|
59
|
-
app.create(container, appTypeOrMiddlewares);
|
|
60
|
-
return app;
|
|
61
|
-
}
|
|
33
|
+
this.logger.error("Invalid web server type.", "app-factory:create");
|
|
34
|
+
throw new Error("Invalid web server type.");
|
|
62
35
|
}
|
|
63
36
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Checks if the provided parameter is a custom application type.
|
|
66
|
-
* @param appTypeOrMiddlewares - Custom application class or array of middlewares.
|
|
67
|
-
* @returns True if the provided parameter is a custom application type.
|
|
68
|
-
*/
|
|
69
|
-
static isOpinionated(appTypeOrMiddlewares) {
|
|
70
|
-
return typeof appTypeOrMiddlewares === "function";
|
|
71
|
-
}
|
|
72
37
|
}
|
|
73
38
|
exports.AppFactory = AppFactory;
|
|
74
39
|
AppFactory.logger = new logger_provider_1.Logger();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AppFactory = exports.AppContainer = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "AppContainer", { enumerable: true, get: function () { return
|
|
4
|
+
var application_container_1 = require("./application-container");
|
|
5
|
+
Object.defineProperty(exports, "AppContainer", { enumerable: true, get: function () { return application_container_1.AppContainer; } });
|
|
6
6
|
var application_factory_1 = require("./application-factory");
|
|
7
7
|
Object.defineProperty(exports, "AppFactory", { enumerable: true, get: function () { return application_factory_1.AppFactory; } });
|
|
@@ -8,7 +8,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.Console = void 0;
|
|
10
10
|
const inversify_binding_decorators_1 = require("inversify-binding-decorators");
|
|
11
|
-
const
|
|
11
|
+
const color_codes_1 = require("../common/color-codes");
|
|
12
12
|
/**
|
|
13
13
|
* The Console class provides methods for displaying styled messages in the console.
|
|
14
14
|
* @provide Console
|
|
@@ -22,7 +22,7 @@ let Console = class Console {
|
|
|
22
22
|
async printColor(message, colorStyle) {
|
|
23
23
|
const textColor = "black";
|
|
24
24
|
const bgColor = colorStyle;
|
|
25
|
-
console.log(`${
|
|
25
|
+
console.log(`${color_codes_1.bgColorCodes[bgColor]}${color_codes_1.colorCodes[textColor]}${message}\x1b[0m`);
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Display a message in the console with details about the running server.
|
|
@@ -35,19 +35,19 @@ let Console = class Console {
|
|
|
35
35
|
appName: consoleMessage?.appName || "Application",
|
|
36
36
|
appVersion: consoleMessage?.appVersion || "not provided",
|
|
37
37
|
};
|
|
38
|
-
let terminalColor =
|
|
38
|
+
let terminalColor = color_codes_1.ColorStyle.None;
|
|
39
39
|
switch (environment.toLowerCase()) {
|
|
40
40
|
case "development":
|
|
41
|
-
terminalColor =
|
|
41
|
+
terminalColor = color_codes_1.ColorStyle.Yellow;
|
|
42
42
|
break;
|
|
43
43
|
case "staging":
|
|
44
|
-
terminalColor =
|
|
44
|
+
terminalColor = color_codes_1.ColorStyle.Blue;
|
|
45
45
|
break;
|
|
46
46
|
case "production":
|
|
47
|
-
terminalColor =
|
|
47
|
+
terminalColor = color_codes_1.ColorStyle.Green;
|
|
48
48
|
break;
|
|
49
49
|
default:
|
|
50
|
-
terminalColor =
|
|
50
|
+
terminalColor = color_codes_1.ColorStyle.Red;
|
|
51
51
|
break;
|
|
52
52
|
}
|
|
53
53
|
this.printColor(`${appConsoleMessage.appName} version ${appConsoleMessage.appVersion} is running on ` +
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ValidateDTO = void 0;
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
const status_code_1 = require("../../error/status-code");
|
|
6
|
-
const
|
|
6
|
+
const package_resolver_1 = require("../../common/package-resolver");
|
|
7
7
|
const logger_provider_1 = require("../logger/logger.provider");
|
|
8
8
|
/**
|
|
9
9
|
* Validate the DTO using class-validator and class-transformer.
|
|
@@ -15,8 +15,8 @@ const logger_provider_1 = require("../logger/logger.provider");
|
|
|
15
15
|
function ValidateDTO(type) {
|
|
16
16
|
return async (req, res, next) => {
|
|
17
17
|
const logger = new logger_provider_1.Logger();
|
|
18
|
-
const classValidator = (0,
|
|
19
|
-
const classTransformer = (0,
|
|
18
|
+
const classValidator = (0, package_resolver_1.packageResolver)("class-validator");
|
|
19
|
+
const classTransformer = (0, package_resolver_1.packageResolver)("class-transformer");
|
|
20
20
|
if (!classValidator || !classTransformer) {
|
|
21
21
|
return next();
|
|
22
22
|
}
|
|
@@ -11,7 +11,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.Logger = void 0;
|
|
13
13
|
const inversify_1 = require("inversify");
|
|
14
|
-
const
|
|
14
|
+
const color_codes_1 = require("../../common/color-codes");
|
|
15
15
|
/**
|
|
16
16
|
* Applies a specified color to a text string.
|
|
17
17
|
*
|
|
@@ -20,7 +20,7 @@ const color_service_provider_1 = require("../../common/color-service.provider");
|
|
|
20
20
|
* @returns The colored text.
|
|
21
21
|
*/
|
|
22
22
|
function colorText(text, color) {
|
|
23
|
-
return `${
|
|
23
|
+
return `${color_codes_1.colorCodes[color]}${text}\x1b[0m`;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Class that provides logging functionality with colorized text.
|
|
@@ -23,18 +23,20 @@ interface ContainerOptions {
|
|
|
23
23
|
* and the ability to skip base class checks. The container can be loaded with multiple
|
|
24
24
|
* ContainerModule instances, facilitating modular and organized code.
|
|
25
25
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* const container =
|
|
29
|
-
*
|
|
30
|
-
* @provide AppContainer
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const container = new AppContainer();
|
|
29
|
+
* container.create([new MyModule()]);
|
|
31
30
|
*/
|
|
32
31
|
declare class AppContainer {
|
|
33
32
|
private container;
|
|
34
33
|
private options;
|
|
35
34
|
/**
|
|
36
35
|
* Constructs the AppContainer instance.
|
|
37
|
-
* @param options - The options for creating the container
|
|
36
|
+
* @param options - The options for creating the container with default request scope.
|
|
37
|
+
* @option options.defaultScope - The default scope for bindings in the container.
|
|
38
|
+
* @option options.skipBaseClassChecks - Allows skipping of base class checks when working with derived classes.
|
|
39
|
+
* @option options.autoBindInjectable - Allows auto-binding of injectable classes.
|
|
38
40
|
*/
|
|
39
41
|
constructor(options?: ContainerOptions);
|
|
40
42
|
/**
|
|
@@ -1,34 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { IWebServer, IWebServerPublic, IWebServerConstructor } from "@expressots/adapter-express";
|
|
2
2
|
import { Container } from "inversify";
|
|
3
|
-
import { AppExpress, IApplicationExpress } from "@expressots/adapter-express";
|
|
4
3
|
/**
|
|
5
4
|
* AppFactory Class
|
|
6
5
|
*
|
|
7
|
-
* Responsible for creating an instance of the
|
|
8
|
-
* either using a custom application type or with provided middlewares.
|
|
6
|
+
* Responsible for creating an instance of the IWebServer implementation using a custom application type.
|
|
9
7
|
*/
|
|
10
8
|
declare class AppFactory {
|
|
11
9
|
static container: Container;
|
|
12
10
|
private static logger;
|
|
13
11
|
/**
|
|
14
|
-
*
|
|
12
|
+
* Create an instance of a web server.
|
|
15
13
|
* @param container - InversifyJS container to resolve dependencies.
|
|
16
|
-
* @param
|
|
17
|
-
* @returns
|
|
14
|
+
* @param webServerType - Constructor of a class that implements IWebServer, or array of middlewares.
|
|
15
|
+
* @returns A promise that resolves to an instance of IWebServer.
|
|
18
16
|
*/
|
|
19
|
-
static create(container: Container,
|
|
20
|
-
/**
|
|
21
|
-
* Creates an instance of the application with provided middlewares.
|
|
22
|
-
* @param container - InversifyJS container to resolve dependencies.
|
|
23
|
-
* @param middlewares - Array of Express middlewares to be applied.
|
|
24
|
-
* @returns Instance of the application.
|
|
25
|
-
*/
|
|
26
|
-
static create(container: Container, middlewares: Array<express.RequestHandler>, httpServerFactory?: new () => AppExpress): Promise<AppExpress>;
|
|
27
|
-
/**
|
|
28
|
-
* Checks if the provided parameter is a custom application type.
|
|
29
|
-
* @param appTypeOrMiddlewares - Custom application class or array of middlewares.
|
|
30
|
-
* @returns True if the provided parameter is a custom application type.
|
|
31
|
-
*/
|
|
32
|
-
private static isOpinionated;
|
|
17
|
+
static create<T extends IWebServer>(container: Container, webServerType: IWebServerConstructor<T>): Promise<IWebServerPublic>;
|
|
33
18
|
}
|
|
34
19
|
export { AppFactory };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { AppContainer } from "./
|
|
1
|
+
export { AppContainer } from "./application-container";
|
|
2
2
|
export { AppFactory } from "./application-factory";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Pattern, ExpressoConfig } from "./project-config
|
|
1
|
+
export { Pattern, ExpressoConfig } from "./project-config";
|
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.0",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
|
|
5
5
|
"author": "Richard Zampieri",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"@expressots/adapter-express": "latest",
|
|
79
79
|
"@release-it/conventional-changelog": "7.0.2",
|
|
80
80
|
"@types/express": "4.17.21",
|
|
81
|
-
"@types/node": "20.12.
|
|
81
|
+
"@types/node": "20.12.3",
|
|
82
82
|
"@typescript-eslint/eslint-plugin": "6.21.0",
|
|
83
83
|
"@typescript-eslint/parser": "6.6.0",
|
|
84
84
|
"@vitest/coverage-v8": "1.4.0",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.0",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
|
|
5
5
|
"author": "Richard Zampieri",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"@expressots/adapter-express": "latest",
|
|
79
79
|
"@release-it/conventional-changelog": "7.0.2",
|
|
80
80
|
"@types/express": "4.17.21",
|
|
81
|
-
"@types/node": "20.12.
|
|
81
|
+
"@types/node": "20.12.3",
|
|
82
82
|
"@typescript-eslint/eslint-plugin": "6.21.0",
|
|
83
83
|
"@typescript-eslint/parser": "6.6.0",
|
|
84
84
|
"@vitest/coverage-v8": "1.4.0",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|