@expressots/core 2.16.2 → 3.0.0-beta.3
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/README.md +2 -2
- package/lib/CHANGELOG.md +321 -321
- package/lib/README.md +2 -2
- package/lib/cjs/application/application-container.js +18 -21
- package/lib/cjs/application/application-factory.js +4 -5
- package/lib/cjs/{common/server-env.types.js → application/application.types.js} +1 -0
- package/lib/cjs/application/index.js +3 -1
- package/lib/cjs/console/console.js +8 -20
- package/lib/cjs/container-module/container-module.js +10 -18
- package/lib/cjs/decorator/scope-binding.js +12 -11
- package/lib/cjs/di/annotation/decorator_utils.js +121 -0
- package/lib/cjs/di/annotation/inject.js +44 -0
- package/lib/cjs/di/annotation/inject_base.js +17 -0
- package/lib/cjs/di/annotation/injectable.js +44 -0
- package/lib/cjs/di/annotation/lazy_service_identifier.js +12 -0
- package/lib/cjs/di/annotation/multi_inject.js +30 -0
- package/lib/cjs/di/annotation/named.js +34 -0
- package/lib/cjs/di/annotation/optional.js +32 -0
- package/lib/cjs/di/annotation/post_construct.js +31 -0
- package/lib/cjs/di/annotation/pre_destroy.js +31 -0
- package/lib/cjs/di/annotation/property_event_decorator.js +15 -0
- package/lib/cjs/di/annotation/tagged.js +9 -0
- package/lib/cjs/di/annotation/target_name.js +35 -0
- package/lib/cjs/di/annotation/unmanaged.js +35 -0
- package/lib/cjs/di/binding-decorator/constants.js +7 -0
- package/lib/cjs/di/binding-decorator/decorator/fluent_provide.js +20 -0
- package/lib/cjs/di/binding-decorator/decorator/provide.js +37 -0
- package/lib/cjs/di/binding-decorator/factory/module_factory.js +17 -0
- package/lib/cjs/di/binding-decorator/index.js +14 -0
- package/lib/cjs/di/binding-decorator/syntax/provide_done_syntax.js +42 -0
- package/lib/cjs/di/binding-decorator/syntax/provide_in_syntax.js +33 -0
- package/lib/cjs/di/binding-decorator/syntax/provide_in_when_on_syntax.js +64 -0
- package/lib/cjs/di/binding-decorator/syntax/provide_on_syntax.js +22 -0
- package/lib/cjs/di/binding-decorator/syntax/provide_when_on_syntax.js +57 -0
- package/lib/cjs/di/binding-decorator/syntax/provide_when_syntax.js +89 -0
- package/lib/cjs/di/binding-decorator/utils/auto_wire.js +18 -0
- package/lib/cjs/di/bindings/binding.js +40 -0
- package/lib/cjs/di/bindings/binding_count.js +8 -0
- package/lib/cjs/di/constants/error_msgs.js +60 -0
- package/lib/cjs/di/constants/literal_types.js +26 -0
- package/lib/cjs/di/constants/metadata_keys.js +38 -0
- package/lib/cjs/di/container/container.js +521 -0
- package/lib/cjs/di/container/container_module.js +18 -0
- package/lib/cjs/di/container/container_snapshot.js +15 -0
- package/lib/cjs/di/container/lookup.js +132 -0
- package/lib/cjs/di/container/module_activation_store.js +49 -0
- package/lib/cjs/di/interfaces/interfaces.js +2 -0
- package/lib/cjs/di/inversify.js +78 -0
- package/lib/cjs/di/planning/context.js +17 -0
- package/lib/cjs/di/planning/metadata.js +42 -0
- package/lib/cjs/di/planning/metadata_reader.js +45 -0
- package/lib/cjs/di/planning/plan.js +10 -0
- package/lib/cjs/di/planning/planner.js +186 -0
- package/lib/cjs/di/planning/queryable_string.js +27 -0
- package/lib/cjs/di/planning/reflection_utils.js +178 -0
- package/lib/cjs/di/planning/request.js +23 -0
- package/lib/cjs/di/planning/target.js +108 -0
- package/lib/cjs/di/resolution/instantiation.js +150 -0
- package/lib/cjs/di/resolution/resolver.js +188 -0
- package/lib/cjs/di/scope/scope.js +50 -0
- package/lib/cjs/di/syntax/binding_in_syntax.js +23 -0
- package/lib/cjs/di/syntax/binding_in_when_on_syntax.js +75 -0
- package/lib/cjs/di/syntax/binding_on_syntax.js +18 -0
- package/lib/cjs/di/syntax/binding_to_syntax.js +111 -0
- package/lib/cjs/di/syntax/binding_when_on_syntax.js +64 -0
- package/lib/cjs/di/syntax/binding_when_syntax.js +84 -0
- package/lib/cjs/di/syntax/constraint_helpers.js +68 -0
- package/lib/cjs/di/utils/async.js +15 -0
- package/lib/cjs/di/utils/binding_utils.js +77 -0
- package/lib/cjs/di/utils/clonable.js +9 -0
- package/lib/cjs/di/utils/exceptions.js +46 -0
- package/lib/cjs/di/utils/factory_type.js +9 -0
- package/lib/cjs/di/utils/id.js +7 -0
- package/lib/cjs/di/utils/js.js +15 -0
- package/lib/cjs/di/utils/serialization.js +132 -0
- package/lib/cjs/error/app-error.js +5 -2
- package/lib/cjs/error/report.js +24 -15
- package/lib/cjs/index.js +1 -2
- package/lib/cjs/middleware/middleware-interface.js +2 -0
- package/lib/cjs/middleware/middleware-service.js +9 -24
- package/lib/cjs/provider/db-in-memory/base-repo.repository.js +29 -88
- package/lib/cjs/provider/db-in-memory/db-in-memory.interface.js +2 -0
- package/lib/cjs/provider/db-in-memory/db-in-memory.provider.js +92 -60
- package/lib/cjs/provider/db-in-memory/db-in-memory.types.js +25 -0
- package/lib/cjs/provider/db-in-memory/index.js +11 -0
- package/lib/cjs/provider/dto-validator/dto-validator.provider.js +4 -4
- package/lib/cjs/provider/dto-validator/package-resolver.js +56 -0
- package/lib/cjs/provider/environment/env-validator.provider.js +14 -12
- package/lib/cjs/provider/index.js +16 -5
- package/lib/cjs/provider/logger/logger.provider.js +10 -5
- package/lib/cjs/provider/provider-manager.js +72 -29
- package/lib/cjs/types/application/application-container.d.ts +12 -25
- package/lib/cjs/types/application/application-factory.d.ts +10 -7
- package/lib/cjs/types/{common/server-env.types.d.ts → application/application.types.d.ts} +1 -0
- package/lib/cjs/types/application/index.d.ts +1 -0
- package/lib/cjs/types/console/console.d.ts +3 -10
- package/lib/cjs/types/console/index.d.ts +2 -1
- package/lib/cjs/types/container-module/container-module.d.ts +3 -1
- package/lib/cjs/types/decorator/scope-binding.d.ts +9 -9
- package/lib/cjs/types/di/annotation/decorator_utils.d.ts +16 -0
- package/lib/cjs/types/di/annotation/inject.d.ts +16 -0
- package/lib/cjs/types/di/annotation/inject_base.d.ts +3 -0
- package/lib/cjs/types/di/annotation/injectable.d.ts +7 -0
- package/lib/cjs/types/di/annotation/lazy_service_identifier.d.ts +7 -0
- package/lib/cjs/types/di/annotation/multi_inject.d.ts +2 -0
- package/lib/cjs/types/di/annotation/named.d.ts +2 -0
- package/lib/cjs/types/di/annotation/optional.d.ts +2 -0
- package/lib/cjs/types/di/annotation/post_construct.d.ts +4 -0
- package/lib/cjs/types/di/annotation/pre_destroy.d.ts +4 -0
- package/lib/cjs/types/di/annotation/property_event_decorator.d.ts +4 -0
- package/lib/cjs/types/di/annotation/tagged.d.ts +2 -0
- package/lib/cjs/types/di/annotation/target_name.d.ts +3 -0
- package/lib/cjs/types/di/annotation/unmanaged.d.ts +3 -0
- package/lib/cjs/types/di/binding-decorator/constants.d.ts +4 -0
- package/lib/cjs/types/di/binding-decorator/decorator/fluent_provide.d.ts +4 -0
- package/lib/cjs/types/di/binding-decorator/decorator/provide.d.ts +4 -0
- package/lib/cjs/types/di/binding-decorator/factory/module_factory.d.ts +4 -0
- package/lib/cjs/types/di/binding-decorator/index.d.ts +8 -0
- package/lib/cjs/types/di/binding-decorator/interfaces/interfaces.d.ts +39 -0
- package/lib/cjs/types/di/binding-decorator/syntax/provide_done_syntax.d.ts +7 -0
- package/lib/cjs/types/di/binding-decorator/syntax/provide_in_syntax.d.ts +11 -0
- package/lib/cjs/types/di/binding-decorator/syntax/provide_in_when_on_syntax.d.ts +27 -0
- package/lib/cjs/types/di/binding-decorator/syntax/provide_on_syntax.d.ts +10 -0
- package/lib/cjs/types/di/binding-decorator/syntax/provide_when_on_syntax.d.ts +24 -0
- package/lib/cjs/types/di/binding-decorator/syntax/provide_when_syntax.d.ts +23 -0
- package/lib/cjs/types/di/binding-decorator/utils/auto_wire.d.ts +3 -0
- package/lib/cjs/types/di/bindings/binding.d.ts +20 -0
- package/lib/cjs/types/di/bindings/binding_count.d.ts +5 -0
- package/lib/cjs/types/di/constants/error_msgs.d.ts +32 -0
- package/lib/cjs/types/di/constants/literal_types.d.ts +5 -0
- package/lib/cjs/types/di/constants/metadata_keys.d.ts +13 -0
- package/lib/cjs/types/di/container/container.d.ts +73 -0
- package/lib/cjs/types/di/container/container_module.d.ts +11 -0
- package/lib/cjs/types/di/container/container_snapshot.d.ts +10 -0
- package/lib/cjs/types/di/container/lookup.d.ts +16 -0
- package/lib/cjs/types/di/container/module_activation_store.d.ts +10 -0
- package/lib/cjs/types/di/interfaces/interfaces.d.ts +299 -0
- package/lib/cjs/types/di/inversify.d.ts +25 -0
- package/lib/cjs/types/di/planning/context.d.ts +11 -0
- package/lib/cjs/types/di/planning/metadata.d.ts +8 -0
- package/lib/cjs/types/di/planning/metadata_reader.d.ts +6 -0
- package/lib/cjs/types/di/planning/plan.d.ts +7 -0
- package/lib/cjs/types/di/planning/planner.d.ts +5 -0
- package/lib/cjs/types/di/planning/queryable_string.d.ts +11 -0
- package/lib/cjs/types/di/planning/reflection_utils.d.ts +5 -0
- package/lib/cjs/types/di/planning/request.d.ts +14 -0
- package/lib/cjs/types/di/planning/target.d.ts +23 -0
- package/lib/cjs/types/di/resolution/instantiation.d.ts +3 -0
- package/lib/cjs/types/di/resolution/resolver.d.ts +3 -0
- package/lib/cjs/types/di/scope/scope.d.ts +3 -0
- package/lib/cjs/types/di/syntax/binding_in_syntax.d.ts +9 -0
- package/lib/cjs/types/di/syntax/binding_in_when_on_syntax.d.ts +29 -0
- package/lib/cjs/types/di/syntax/binding_on_syntax.d.ts +8 -0
- package/lib/cjs/types/di/syntax/binding_to_syntax.d.ts +18 -0
- package/lib/cjs/types/di/syntax/binding_when_on_syntax.d.ts +25 -0
- package/lib/cjs/types/di/syntax/binding_when_syntax.d.ts +21 -0
- package/lib/cjs/types/di/syntax/constraint_helpers.d.ts +6 -0
- package/lib/cjs/types/di/utils/async.d.ts +3 -0
- package/lib/cjs/types/di/utils/binding_utils.d.ts +4 -0
- package/lib/cjs/types/di/utils/clonable.d.ts +3 -0
- package/lib/cjs/types/di/utils/exceptions.d.ts +2 -0
- package/lib/cjs/types/di/utils/factory_type.d.ts +5 -0
- package/lib/cjs/types/di/utils/id.d.ts +2 -0
- package/lib/cjs/types/di/utils/js.d.ts +1 -0
- package/lib/cjs/types/di/utils/serialization.d.ts +10 -0
- package/lib/cjs/types/error/report.d.ts +7 -5
- package/lib/cjs/types/index.d.ts +1 -2
- package/lib/cjs/types/middleware/index.d.ts +2 -1
- package/lib/cjs/types/middleware/middleware-interface.d.ts +185 -0
- package/lib/cjs/types/middleware/middleware-service.d.ts +11 -163
- package/lib/cjs/types/provider/db-in-memory/base-repo.repository.d.ts +15 -60
- package/lib/cjs/types/provider/db-in-memory/db-in-memory.interface.d.ts +43 -0
- package/lib/cjs/types/provider/db-in-memory/db-in-memory.provider.d.ts +25 -35
- package/lib/cjs/types/provider/db-in-memory/db-in-memory.types.d.ts +14 -0
- package/lib/cjs/types/provider/db-in-memory/index.d.ts +4 -0
- package/lib/cjs/types/provider/dto-validator/dto-validator.provider.d.ts +2 -3
- package/lib/cjs/types/{common → provider/dto-validator}/package-resolver.d.ts +1 -2
- package/lib/cjs/types/provider/environment/env-validator.provider.d.ts +7 -3
- package/lib/cjs/types/provider/index.d.ts +1 -2
- package/lib/cjs/types/provider/logger/logger.provider.d.ts +5 -0
- package/lib/cjs/types/provider/provider-manager.d.ts +46 -6
- package/lib/package.json +9 -15
- package/package.json +9 -15
- package/lib/cjs/common/index.js +0 -5
- package/lib/cjs/common/package-resolver.js +0 -34
- package/lib/cjs/controller/base-controller.js +0 -63
- package/lib/cjs/controller/index.js +0 -5
- package/lib/cjs/types/common/index.d.ts +0 -2
- package/lib/cjs/types/common/project-config.d.ts +0 -56
- package/lib/cjs/types/controller/base-controller.d.ts +0 -32
- package/lib/cjs/types/controller/index.d.ts +0 -1
- /package/lib/cjs/{common → console}/color-codes.js +0 -0
- /package/lib/cjs/{common/project-config.js → di/binding-decorator/interfaces/interfaces.js} +0 -0
- /package/lib/cjs/types/{common → console}/color-codes.d.ts +0 -0
package/lib/cjs/error/report.js
CHANGED
|
@@ -5,13 +5,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
9
|
exports.Report = void 0;
|
|
13
|
-
const
|
|
14
|
-
const logger_provider_1 = require("../provider/logger/logger.provider");
|
|
10
|
+
const inversify_1 = require("../di/inversify");
|
|
15
11
|
const app_error_1 = require("./app-error");
|
|
16
12
|
/**
|
|
17
13
|
* Report class is a utility class to manage and log errors within the application.
|
|
@@ -20,7 +16,10 @@ const app_error_1 = require("./app-error");
|
|
|
20
16
|
*/
|
|
21
17
|
let Report = class Report {
|
|
22
18
|
constructor() {
|
|
23
|
-
this.
|
|
19
|
+
this.name = "Report Provider";
|
|
20
|
+
this.version = "3.0.0";
|
|
21
|
+
this.author = "Richard Zampieri";
|
|
22
|
+
this.repo = "https://github.com/expressots/expressots";
|
|
24
23
|
}
|
|
25
24
|
/**
|
|
26
25
|
* The Error method is responsible for generating a standardized error object,
|
|
@@ -34,20 +33,30 @@ let Report = class Report {
|
|
|
34
33
|
*
|
|
35
34
|
* @throws An object of the custom type AppError, which includes details about the error.
|
|
36
35
|
*/
|
|
37
|
-
error(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
error(
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
error, statusCode, service) {
|
|
39
|
+
let message = "";
|
|
40
|
+
if (error == null) {
|
|
41
|
+
// error is null or undefined
|
|
42
|
+
message = "";
|
|
43
|
+
}
|
|
44
|
+
else if (typeof error === "string") {
|
|
45
|
+
message = error;
|
|
46
|
+
}
|
|
47
|
+
else if (error instanceof Error) {
|
|
48
|
+
message = error.message;
|
|
49
|
+
}
|
|
50
|
+
else if (typeof error === "object" && "message" in error) {
|
|
51
|
+
message = error.message;
|
|
41
52
|
}
|
|
42
53
|
else {
|
|
43
|
-
|
|
54
|
+
message = String(error);
|
|
44
55
|
}
|
|
45
|
-
|
|
46
|
-
return appError;
|
|
56
|
+
return new app_error_1.AppError(message, statusCode, service);
|
|
47
57
|
}
|
|
48
58
|
};
|
|
49
59
|
exports.Report = Report;
|
|
50
60
|
exports.Report = Report = __decorate([
|
|
51
|
-
(0,
|
|
52
|
-
__metadata("design:paramtypes", [])
|
|
61
|
+
(0, inversify_1.injectable)()
|
|
53
62
|
], Report);
|
package/lib/cjs/index.js
CHANGED
|
@@ -15,11 +15,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./application"), exports);
|
|
18
|
-
__exportStar(require("./common"), exports);
|
|
19
18
|
__exportStar(require("./console"), exports);
|
|
20
19
|
__exportStar(require("./container-module"), exports);
|
|
21
|
-
__exportStar(require("./controller"), exports);
|
|
22
20
|
__exportStar(require("./decorator"), exports);
|
|
23
21
|
__exportStar(require("./error"), exports);
|
|
24
22
|
__exportStar(require("./middleware"), exports);
|
|
25
23
|
__exportStar(require("./provider"), exports);
|
|
24
|
+
__exportStar(require("./di/inversify"), exports);
|
|
@@ -1,35 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
4
|
};
|
|
11
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
6
|
exports.Middleware = exports.ExpressoMiddleware = void 0;
|
|
13
|
-
const express_1 =
|
|
14
|
-
const index_1 = require("../decorator/index");
|
|
7
|
+
const express_1 = require("express");
|
|
15
8
|
const error_handler_middleware_1 = __importDefault(require("../error/error-handler-middleware"));
|
|
16
9
|
const logger_provider_1 = require("../provider/logger/logger.provider");
|
|
17
10
|
const middleware_resolver_1 = require("./middleware-resolver");
|
|
18
|
-
const inversify_binding_decorators_1 = require("inversify-binding-decorators");
|
|
19
11
|
/**
|
|
20
12
|
* Abstract class for creating custom Expresso middleware.
|
|
21
13
|
* Custom middleware classes should extend this class and implement the use method.
|
|
22
14
|
*
|
|
23
15
|
*/
|
|
24
|
-
|
|
16
|
+
class ExpressoMiddleware {
|
|
25
17
|
get name() {
|
|
26
18
|
return this.constructor.name;
|
|
27
19
|
}
|
|
28
|
-
}
|
|
20
|
+
}
|
|
29
21
|
exports.ExpressoMiddleware = ExpressoMiddleware;
|
|
30
|
-
exports.ExpressoMiddleware = ExpressoMiddleware = __decorate([
|
|
31
|
-
(0, inversify_binding_decorators_1.provide)(ExpressoMiddleware)
|
|
32
|
-
], ExpressoMiddleware);
|
|
33
22
|
/**
|
|
34
23
|
* MiddlewareType Enum
|
|
35
24
|
*
|
|
@@ -50,8 +39,9 @@ var MiddlewareType;
|
|
|
50
39
|
* including adding Body Parser and retrieving all configured middlewares.
|
|
51
40
|
*
|
|
52
41
|
* @see IConfigure
|
|
42
|
+
* @public API
|
|
53
43
|
*/
|
|
54
|
-
|
|
44
|
+
class Middleware {
|
|
55
45
|
constructor() {
|
|
56
46
|
this.middlewarePipeline = [];
|
|
57
47
|
this.logger = new logger_provider_1.Logger();
|
|
@@ -60,7 +50,6 @@ let Middleware = class Middleware {
|
|
|
60
50
|
* Retrieves the type of the middleware.
|
|
61
51
|
*
|
|
62
52
|
* @param middleware - The middleware to be checked.
|
|
63
|
-
*
|
|
64
53
|
* @returns The type of the middleware.
|
|
65
54
|
*/
|
|
66
55
|
getMiddlewareType(middleware) {
|
|
@@ -79,7 +68,6 @@ let Middleware = class Middleware {
|
|
|
79
68
|
* Checks if a middleware with the given name exists in the middleware collection.
|
|
80
69
|
*
|
|
81
70
|
* @param middlewareName - The name of the middleware to be checked.
|
|
82
|
-
*
|
|
83
71
|
* @returns A boolean value indicating whether the middleware exists or not.
|
|
84
72
|
*/
|
|
85
73
|
middlewareExists(middlewareName) {
|
|
@@ -107,7 +95,7 @@ let Middleware = class Middleware {
|
|
|
107
95
|
else {
|
|
108
96
|
this.middlewarePipeline.push({
|
|
109
97
|
timestamp: new Date(),
|
|
110
|
-
middleware: express_1.
|
|
98
|
+
middleware: (0, express_1.urlencoded)(options),
|
|
111
99
|
});
|
|
112
100
|
}
|
|
113
101
|
}
|
|
@@ -134,7 +122,7 @@ let Middleware = class Middleware {
|
|
|
134
122
|
else {
|
|
135
123
|
this.middlewarePipeline.push({
|
|
136
124
|
timestamp: new Date(),
|
|
137
|
-
middleware: express_1.
|
|
125
|
+
middleware: (0, express_1.json)(options),
|
|
138
126
|
});
|
|
139
127
|
}
|
|
140
128
|
}
|
|
@@ -305,7 +293,7 @@ let Middleware = class Middleware {
|
|
|
305
293
|
else {
|
|
306
294
|
this.middlewarePipeline.push({
|
|
307
295
|
timestamp: new Date(),
|
|
308
|
-
middleware: express_1.
|
|
296
|
+
middleware: (0, express_1.static)(root, options),
|
|
309
297
|
});
|
|
310
298
|
}
|
|
311
299
|
}
|
|
@@ -496,8 +484,5 @@ let Middleware = class Middleware {
|
|
|
496
484
|
getErrorHandler() {
|
|
497
485
|
return this.errorHandler;
|
|
498
486
|
}
|
|
499
|
-
}
|
|
487
|
+
}
|
|
500
488
|
exports.Middleware = Middleware;
|
|
501
|
-
exports.Middleware = Middleware = __decorate([
|
|
502
|
-
(0, index_1.provideSingleton)(Middleware)
|
|
503
|
-
], Middleware);
|
|
@@ -8,107 +8,48 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.BaseRepository = void 0;
|
|
13
|
-
const
|
|
14
|
-
const db_in_memory_provider_1 = require("./db-in-memory.provider");
|
|
15
|
-
const inversify_1 = require("inversify");
|
|
16
|
+
const inversify_1 = require("../../di/inversify");
|
|
16
17
|
/**
|
|
17
|
-
* Base
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @decorator @provide(BaseRepository)
|
|
18
|
+
* Base repository class using the repository pattern.
|
|
19
|
+
* @template T - The type of entity to be stored in the repository.
|
|
20
|
+
* @public API
|
|
22
21
|
*/
|
|
23
22
|
let BaseRepository = class BaseRepository {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
this.tableName = tableName;
|
|
23
|
+
constructor(dataProvider, tableName) {
|
|
24
|
+
this.dataTable = dataProvider.getTable(tableName);
|
|
25
|
+
this.entityName = tableName;
|
|
26
|
+
}
|
|
27
|
+
async create(item) {
|
|
28
|
+
return this.dataTable.insert(item);
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* @returns {T[]} - An array of entities.
|
|
35
|
-
*/
|
|
36
|
-
get table() {
|
|
37
|
-
return [...this.inMemoryDB.getTable(this.tableName)];
|
|
30
|
+
async update(item) {
|
|
31
|
+
return this.dataTable.update(item);
|
|
38
32
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
* @param item - The entity to be created.
|
|
42
|
-
* @returns {T | null} - The created entity or null if the entity already exists.
|
|
43
|
-
* @throws {Error} - If the entity already exists.
|
|
44
|
-
*/
|
|
45
|
-
create(item) {
|
|
46
|
-
const existingItem = this.table.find((i) => i.id === item.id);
|
|
47
|
-
if (existingItem) {
|
|
48
|
-
throw new Error(`Object with id ${item.id} already exists`);
|
|
49
|
-
}
|
|
50
|
-
this.inMemoryDB.getTable(this.tableName).push(item);
|
|
51
|
-
this.inMemoryDB.printTable(this.tableName);
|
|
52
|
-
return item;
|
|
33
|
+
async delete(id) {
|
|
34
|
+
return this.dataTable.delete(id);
|
|
53
35
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
* @param id - The id of the entity to be deleted.
|
|
57
|
-
* @returns {boolean} - True if the entity was deleted, false otherwise.
|
|
58
|
-
* @throws {Error} - If the entity does not exist.
|
|
59
|
-
*/
|
|
60
|
-
delete(id) {
|
|
61
|
-
const db = this.inMemoryDB.getTable(this.tableName);
|
|
62
|
-
const index = db.findIndex((item) => item.id === id);
|
|
63
|
-
if (index !== -1) {
|
|
64
|
-
db.splice(index, 1);
|
|
65
|
-
this.inMemoryDB.printTable(this.tableName);
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
return false;
|
|
36
|
+
async find(id) {
|
|
37
|
+
return this.dataTable.find(id);
|
|
69
38
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
* @param item - The entity to be updated.
|
|
73
|
-
* @returns {T | null} - The updated entity or null if the entity does not exist
|
|
74
|
-
* @throws {Error} - If the entity does not exist.
|
|
75
|
-
*/
|
|
76
|
-
update(item) {
|
|
77
|
-
const db = this.inMemoryDB.getTable(this.tableName);
|
|
78
|
-
const index = db.findIndex((i) => i.id === item.id);
|
|
79
|
-
if (index !== -1) {
|
|
80
|
-
db[index] = item;
|
|
81
|
-
this.inMemoryDB.printTable(this.tableName);
|
|
82
|
-
return item;
|
|
83
|
-
}
|
|
84
|
-
return null;
|
|
39
|
+
async findAll() {
|
|
40
|
+
return this.dataTable.findAll();
|
|
85
41
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
* @param id - The id of the entity to find.
|
|
89
|
-
* @returns {T | null} - The entity if it exists, null otherwise
|
|
90
|
-
* @throws {Error} - If the entity does not exist.
|
|
91
|
-
*/
|
|
92
|
-
find(id) {
|
|
93
|
-
const item = this.table.find((item) => item.id === id);
|
|
94
|
-
this.inMemoryDB.printTable(this.tableName);
|
|
95
|
-
return item || null;
|
|
42
|
+
async query(predicate) {
|
|
43
|
+
return this.dataTable.query(predicate);
|
|
96
44
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
* @returns {T[] | null} - An array of entities or null if the table is empty.
|
|
100
|
-
*/
|
|
101
|
-
findAll() {
|
|
102
|
-
this.inMemoryDB.printTable(this.tableName);
|
|
103
|
-
return this.table;
|
|
45
|
+
async transaction(actions) {
|
|
46
|
+
await this.dataTable.transaction(actions);
|
|
104
47
|
}
|
|
105
48
|
};
|
|
106
49
|
exports.BaseRepository = BaseRepository;
|
|
107
|
-
__decorate([
|
|
108
|
-
(0, inversify_1.inject)(db_in_memory_provider_1.InMemoryDB),
|
|
109
|
-
__metadata("design:type", db_in_memory_provider_1.InMemoryDB)
|
|
110
|
-
], BaseRepository.prototype, "inMemoryDB", void 0);
|
|
111
50
|
exports.BaseRepository = BaseRepository = __decorate([
|
|
112
|
-
(0,
|
|
113
|
-
|
|
51
|
+
(0, inversify_1.injectable)(),
|
|
52
|
+
__param(0, (0, inversify_1.inject)("IDataProvider")),
|
|
53
|
+
__param(1, (0, inversify_1.unmanaged)()),
|
|
54
|
+
__metadata("design:paramtypes", [Object, String])
|
|
114
55
|
], BaseRepository);
|
|
@@ -6,77 +6,109 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
10
|
-
const inversify_1 = require("inversify");
|
|
9
|
+
exports.InMemoryDataTable = exports.InMemoryDataProvider = void 0;
|
|
10
|
+
const inversify_1 = require("../../di/inversify");
|
|
11
|
+
const db_in_memory_types_1 = require("./db-in-memory.types");
|
|
11
12
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* This class and its methods offer functionalities to simulate an in-memory database.
|
|
15
|
-
* It is particularly useful for developers starting with ExpressoTS without any database connection.
|
|
16
|
-
*
|
|
17
|
-
* @decorator @provideSingleton(InMemoryDB)
|
|
13
|
+
* In-memory data provider implementation.
|
|
14
|
+
* @public API
|
|
18
15
|
*/
|
|
19
|
-
|
|
20
|
-
let InMemoryDB = class InMemoryDB {
|
|
16
|
+
let InMemoryDataProvider = class InMemoryDataProvider {
|
|
21
17
|
constructor() {
|
|
22
|
-
this.name = "
|
|
23
|
-
this.version = "0.0
|
|
18
|
+
this.name = "In Memory DB Provider";
|
|
19
|
+
this.version = "3.0.0";
|
|
24
20
|
this.author = "Richard Zampieri";
|
|
25
|
-
this.repo = "
|
|
26
|
-
|
|
21
|
+
this.repo = "https://github.com/expressots/expressots";
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
this.tables = new Map();
|
|
27
24
|
}
|
|
28
|
-
/**
|
|
29
|
-
* getTable Method
|
|
30
|
-
*
|
|
31
|
-
* Retrieves a table by its name from the in-memory database.
|
|
32
|
-
*
|
|
33
|
-
* @param tableName - The name of the table to retrieve.
|
|
34
|
-
* @returns {IEntity[]} - An array of entities.
|
|
35
|
-
*/
|
|
36
25
|
getTable(tableName) {
|
|
37
|
-
if (!this.tables
|
|
38
|
-
this.tables
|
|
26
|
+
if (!this.tables.has(tableName)) {
|
|
27
|
+
this.tables.set(tableName, new InMemoryDataTable(tableName));
|
|
39
28
|
}
|
|
40
|
-
return this.tables
|
|
29
|
+
return this.tables.get(tableName);
|
|
41
30
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
31
|
+
};
|
|
32
|
+
exports.InMemoryDataProvider = InMemoryDataProvider;
|
|
33
|
+
exports.InMemoryDataProvider = InMemoryDataProvider = __decorate([
|
|
34
|
+
(0, inversify_1.injectable)()
|
|
35
|
+
], InMemoryDataProvider);
|
|
36
|
+
/**
|
|
37
|
+
* In-memory data table implementation.
|
|
38
|
+
*/
|
|
39
|
+
class InMemoryDataTable {
|
|
40
|
+
constructor(tableName) {
|
|
41
|
+
this.items = new Map();
|
|
42
|
+
this.transactionStack = [];
|
|
43
|
+
this.tableName = tableName;
|
|
44
|
+
}
|
|
45
|
+
async insert(item) {
|
|
46
|
+
if (this.items.has(item.id)) {
|
|
47
|
+
throw new db_in_memory_types_1.EntityAlreadyExistsError(this.tableName, item.id);
|
|
51
48
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
this.items.set(item.id, item);
|
|
50
|
+
return item;
|
|
51
|
+
}
|
|
52
|
+
async insertMany(items) {
|
|
53
|
+
const insertedItems = [];
|
|
54
|
+
for (const item of items) {
|
|
55
|
+
const insertedItem = await this.insert(item);
|
|
56
|
+
insertedItems.push(insertedItem);
|
|
55
57
|
}
|
|
58
|
+
return insertedItems;
|
|
56
59
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
* Prints all records in a specific table to the console.
|
|
61
|
-
* If the table doesn't exist or is empty, it notifies the user.
|
|
62
|
-
*
|
|
63
|
-
* @param tableName - The name of the table to print.
|
|
64
|
-
*/
|
|
65
|
-
printTable(tableName) {
|
|
66
|
-
if (!this.tables) {
|
|
67
|
-
process.stdout.write("No tables exist.");
|
|
68
|
-
return;
|
|
60
|
+
async update(item) {
|
|
61
|
+
if (!this.items.has(item.id)) {
|
|
62
|
+
throw new db_in_memory_types_1.EntityNotFoundError(this.tableName, item.id);
|
|
69
63
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
64
|
+
this.items.set(item.id, item);
|
|
65
|
+
return item;
|
|
66
|
+
}
|
|
67
|
+
async delete(id) {
|
|
68
|
+
if (!this.items.has(id)) {
|
|
69
|
+
throw new db_in_memory_types_1.EntityNotFoundError(this.tableName, id);
|
|
74
70
|
}
|
|
75
|
-
|
|
76
|
-
console.table(table);
|
|
71
|
+
return this.items.delete(id);
|
|
77
72
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
73
|
+
async find(id) {
|
|
74
|
+
const item = this.items.get(id);
|
|
75
|
+
if (!item) {
|
|
76
|
+
throw new db_in_memory_types_1.EntityNotFoundError(this.tableName, id);
|
|
77
|
+
}
|
|
78
|
+
return item;
|
|
79
|
+
}
|
|
80
|
+
async findAll() {
|
|
81
|
+
return Array.from(this.items.values());
|
|
82
|
+
}
|
|
83
|
+
async query(predicate) {
|
|
84
|
+
return Array.from(this.items.values()).filter(predicate);
|
|
85
|
+
}
|
|
86
|
+
async transaction(actions) {
|
|
87
|
+
this.beginTransaction();
|
|
88
|
+
try {
|
|
89
|
+
await actions();
|
|
90
|
+
this.commitTransaction();
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
this.rollbackTransaction();
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
beginTransaction() {
|
|
98
|
+
const snapshot = new Map(this.items);
|
|
99
|
+
this.transactionStack.push(snapshot);
|
|
100
|
+
}
|
|
101
|
+
commitTransaction() {
|
|
102
|
+
this.transactionStack.pop();
|
|
103
|
+
}
|
|
104
|
+
rollbackTransaction() {
|
|
105
|
+
const snapshot = this.transactionStack.pop();
|
|
106
|
+
if (snapshot) {
|
|
107
|
+
this.items = snapshot;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
throw new Error("No transaction to rollback.");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.InMemoryDataTable = InMemoryDataTable;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityAlreadyExistsError = exports.EntityNotFoundError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when an entity is not found.
|
|
6
|
+
* @public API
|
|
7
|
+
*/
|
|
8
|
+
class EntityNotFoundError extends Error {
|
|
9
|
+
constructor(entityName, id) {
|
|
10
|
+
super(`${entityName} with ID ${id} not found.`);
|
|
11
|
+
this.name = "EntityNotFoundError";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.EntityNotFoundError = EntityNotFoundError;
|
|
15
|
+
/**
|
|
16
|
+
* Error thrown when an entity already exists.
|
|
17
|
+
* @public API
|
|
18
|
+
*/
|
|
19
|
+
class EntityAlreadyExistsError extends Error {
|
|
20
|
+
constructor(entityName, id) {
|
|
21
|
+
super(`${entityName} with ID ${id} already exists.`);
|
|
22
|
+
this.name = "EntityAlreadyExistsError";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.EntityAlreadyExistsError = EntityAlreadyExistsError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseRepository = exports.EntityAlreadyExistsError = exports.EntityNotFoundError = exports.InMemoryDataTable = exports.InMemoryDataProvider = void 0;
|
|
4
|
+
var db_in_memory_provider_1 = require("./db-in-memory.provider");
|
|
5
|
+
Object.defineProperty(exports, "InMemoryDataProvider", { enumerable: true, get: function () { return db_in_memory_provider_1.InMemoryDataProvider; } });
|
|
6
|
+
Object.defineProperty(exports, "InMemoryDataTable", { enumerable: true, get: function () { return db_in_memory_provider_1.InMemoryDataTable; } });
|
|
7
|
+
var db_in_memory_types_1 = require("./db-in-memory.types");
|
|
8
|
+
Object.defineProperty(exports, "EntityNotFoundError", { enumerable: true, get: function () { return db_in_memory_types_1.EntityNotFoundError; } });
|
|
9
|
+
Object.defineProperty(exports, "EntityAlreadyExistsError", { enumerable: true, get: function () { return db_in_memory_types_1.EntityAlreadyExistsError; } });
|
|
10
|
+
var base_repo_repository_1 = require("./base-repo.repository");
|
|
11
|
+
Object.defineProperty(exports, "BaseRepository", { enumerable: true, get: function () { return base_repo_repository_1.BaseRepository; } });
|
|
@@ -3,20 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ValidateDTO = ValidateDTO;
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
const status_code_1 = require("../../error/status-code");
|
|
6
|
-
const package_resolver_1 = require("
|
|
6
|
+
const package_resolver_1 = require("./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.
|
|
10
10
|
* @param type - The type of the DTO to validate.
|
|
11
11
|
* @returns A RequestHandler function.
|
|
12
12
|
* @throws An exception if the DTO is invalid.
|
|
13
|
-
*
|
|
13
|
+
* @public API
|
|
14
14
|
*/
|
|
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, package_resolver_1.packageResolver)("class-validator");
|
|
19
|
-
const classTransformer = (0, package_resolver_1.packageResolver)("class-transformer");
|
|
18
|
+
const classValidator = await (0, package_resolver_1.packageResolver)("class-validator");
|
|
19
|
+
const classTransformer = await (0, package_resolver_1.packageResolver)("class-transformer");
|
|
20
20
|
if (!classValidator || !classTransformer) {
|
|
21
21
|
return next();
|
|
22
22
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.packageResolver = packageResolver;
|
|
27
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
28
|
+
const logger_provider_1 = require("../logger/logger.provider");
|
|
29
|
+
/**
|
|
30
|
+
* Resolve package from the current working directory.
|
|
31
|
+
* @param packageName
|
|
32
|
+
* @param options
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
async function packageResolver(packageName, ...options) {
|
|
36
|
+
const logger = new logger_provider_1.Logger();
|
|
37
|
+
try {
|
|
38
|
+
const hasPackage = require.resolve(packageName, {
|
|
39
|
+
paths: [process.cwd()],
|
|
40
|
+
});
|
|
41
|
+
if (hasPackage) {
|
|
42
|
+
const packageResolved = await Promise.resolve(`${hasPackage}`).then(s => __importStar(require(s)));
|
|
43
|
+
if (typeof packageResolved === "function") {
|
|
44
|
+
return packageResolved(...options);
|
|
45
|
+
}
|
|
46
|
+
if (packageResolved.default &&
|
|
47
|
+
typeof packageResolved.default === "function") {
|
|
48
|
+
return packageResolved.default(...options);
|
|
49
|
+
}
|
|
50
|
+
return packageResolved;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
logger.warn(`Package [${packageName}] not installed. Please install it using your package manager.`, "package-resolver");
|
|
55
|
+
}
|
|
56
|
+
}
|