@expressots/core 1.3.0 → 1.4.1
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 +10 -14
- package/lib/CHANGELOG.md +23 -13
- package/lib/README.md +10 -14
- package/lib/cjs/application/app-container.js +28 -11
- package/lib/cjs/container-module/container-module.js +69 -16
- package/lib/cjs/container-module/index.js +2 -1
- package/lib/cjs/controller/base-controller.js +2 -2
- package/lib/cjs/decorator/index.js +17 -0
- package/lib/cjs/decorator/scope-binding.js +12 -0
- package/lib/cjs/error/error-handler-middleware.js +1 -3
- package/lib/cjs/error/index.js +1 -3
- package/lib/cjs/error/report.js +26 -2
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/logger/general-logger.js +2 -2
- package/lib/cjs/types/application/app-container.d.ts +18 -6
- package/lib/cjs/types/application/app-container.d.ts.map +1 -1
- package/lib/cjs/types/container-module/container-module.d.ts +14 -8
- package/lib/cjs/types/container-module/container-module.d.ts.map +1 -1
- package/lib/cjs/types/container-module/index.d.ts +1 -1
- package/lib/cjs/types/container-module/index.d.ts.map +1 -1
- package/lib/cjs/types/decorator/index.d.ts +2 -0
- package/lib/cjs/types/decorator/index.d.ts.map +1 -0
- package/lib/cjs/types/decorator/scope-binding.d.ts +4 -0
- package/lib/cjs/types/decorator/scope-binding.d.ts.map +1 -0
- package/lib/cjs/types/error/error-handler-middleware.d.ts +3 -3
- package/lib/cjs/types/error/error-handler-middleware.d.ts.map +1 -1
- package/lib/cjs/types/error/index.d.ts +0 -1
- package/lib/cjs/types/error/index.d.ts.map +1 -1
- package/lib/cjs/types/error/report.d.ts +10 -3
- package/lib/cjs/types/error/report.d.ts.map +1 -1
- package/lib/cjs/types/index.d.ts +1 -0
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/esm/application/app-container.js +29 -12
- package/lib/esm/container-module/container-module.js +69 -17
- package/lib/esm/container-module/index.js +1 -1
- package/lib/esm/controller/base-controller.js +2 -2
- package/lib/esm/decorator/index.js +1 -0
- package/lib/esm/decorator/scope-binding.js +8 -0
- package/lib/esm/error/error-handler-middleware.js +1 -3
- package/lib/esm/error/index.js +0 -1
- package/lib/esm/error/report.js +26 -2
- package/lib/esm/index.mjs +1 -0
- package/lib/esm/logger/general-logger.js +2 -2
- package/lib/esm/types/application/app-container.d.ts +18 -6
- package/lib/esm/types/application/app-container.d.ts.map +1 -1
- package/lib/esm/types/container-module/container-module.d.ts +14 -8
- package/lib/esm/types/container-module/container-module.d.ts.map +1 -1
- package/lib/esm/types/container-module/index.d.ts +1 -1
- package/lib/esm/types/container-module/index.d.ts.map +1 -1
- package/lib/esm/types/decorator/index.d.ts +2 -0
- package/lib/esm/types/decorator/index.d.ts.map +1 -0
- package/lib/esm/types/decorator/scope-binding.d.ts +4 -0
- package/lib/esm/types/decorator/scope-binding.d.ts.map +1 -0
- package/lib/esm/types/error/error-handler-middleware.d.ts +3 -3
- package/lib/esm/types/error/error-handler-middleware.d.ts.map +1 -1
- package/lib/esm/types/error/index.d.ts +0 -1
- package/lib/esm/types/error/index.d.ts.map +1 -1
- package/lib/esm/types/error/report.d.ts +10 -3
- package/lib/esm/types/error/report.d.ts.map +1 -1
- package/lib/esm/types/index.d.ts +1 -0
- package/lib/esm/types/index.d.ts.map +1 -1
- package/lib/package.json +3 -3
- package/package.json +3 -3
- package/lib/cjs/error/application-error.js +0 -37
- package/lib/cjs/types/error/application-error.d.ts +0 -18
- package/lib/cjs/types/error/application-error.d.ts.map +0 -1
- package/lib/esm/error/application-error.js +0 -36
- package/lib/esm/types/error/application-error.d.ts +0 -18
- package/lib/esm/types/error/application-error.d.ts.map +0 -1
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
interface IAppError {
|
|
2
|
+
statusCode: number;
|
|
3
|
+
message: string;
|
|
4
|
+
service?: string;
|
|
5
|
+
name: string;
|
|
6
|
+
stack?: string;
|
|
7
|
+
}
|
|
2
8
|
/**
|
|
3
9
|
* Report class is a utility class to manage and throw application-specific errors.
|
|
4
10
|
*/
|
|
5
11
|
declare class Report {
|
|
12
|
+
static stack: string;
|
|
6
13
|
/**
|
|
7
14
|
* Error method takes an instance of AppError and throws it.
|
|
8
15
|
* @param error - An instance of AppError containing error details.
|
|
9
16
|
*/
|
|
10
|
-
static Error(error:
|
|
17
|
+
static Error(error: Error | string, statusCode?: number, service?: string): void;
|
|
11
18
|
}
|
|
12
|
-
export { Report };
|
|
19
|
+
export { Report, IAppError };
|
|
13
20
|
//# sourceMappingURL=report.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/report.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/report.ts"],"names":[],"mappings":"AAGA,UAAU,SAAS;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAGD;;GAEG;AACH,cACM,MAAM;IACR,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC;IAErB;;;OAGG;WACW,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;CA6B1F;AAED,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC"}
|
package/lib/cjs/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/core/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/core/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
|
|
@@ -4,11 +4,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
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;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
7
|
var AppContainer_1;
|
|
11
|
-
import { Container } from "inversify";
|
|
8
|
+
import { BindingScopeEnum, Container } from "inversify";
|
|
12
9
|
import { buildProviderModule, provide } from "inversify-binding-decorators";
|
|
13
10
|
/**
|
|
14
11
|
* The AppContainer class provides a container for managing dependency injection.
|
|
@@ -16,23 +13,43 @@ import { buildProviderModule, provide } from "inversify-binding-decorators";
|
|
|
16
13
|
*/
|
|
17
14
|
let AppContainer = AppContainer_1 = class AppContainer {
|
|
18
15
|
container;
|
|
19
|
-
/**
|
|
20
|
-
* Constructs a new instance of the AppContainer class.
|
|
21
|
-
*/
|
|
22
|
-
constructor() { }
|
|
23
16
|
/**
|
|
24
17
|
* Creates and configures a new dependency injection container.
|
|
25
18
|
* @param modules - An array of ContainerModule instances to load into the container.
|
|
19
|
+
* @param defaultScope - The default scope to use for bindings. Scoped (Request) by default, but offers Singleton and Transient as well.
|
|
26
20
|
* @returns The configured dependency injection container.
|
|
27
21
|
*/
|
|
28
|
-
create(modules) {
|
|
29
|
-
this.container = new Container(
|
|
22
|
+
create(modules, defaultScope = BindingScopeEnum.Request) {
|
|
23
|
+
this.container = new Container({
|
|
24
|
+
autoBindInjectable: true,
|
|
25
|
+
defaultScope,
|
|
26
|
+
});
|
|
30
27
|
this.container.load(buildProviderModule(), ...modules);
|
|
31
28
|
return this.container;
|
|
32
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Retrieves the binding dictionary of the container.
|
|
32
|
+
* @returns The binding dictionary of the container.
|
|
33
|
+
*/
|
|
34
|
+
getBindingDictionary() {
|
|
35
|
+
return this.container["_bindingDictionary"]._map;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves the container options.
|
|
39
|
+
* @returns The container options.
|
|
40
|
+
*/
|
|
41
|
+
getContainerOptions() {
|
|
42
|
+
return this.container["options"];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Retrieves the container.
|
|
46
|
+
* @returns The container.
|
|
47
|
+
*/
|
|
48
|
+
get Container() {
|
|
49
|
+
return this.container;
|
|
50
|
+
}
|
|
33
51
|
};
|
|
34
52
|
AppContainer = AppContainer_1 = __decorate([
|
|
35
|
-
provide(AppContainer_1)
|
|
36
|
-
__metadata("design:paramtypes", [])
|
|
53
|
+
provide(AppContainer_1)
|
|
37
54
|
], AppContainer);
|
|
38
55
|
export { AppContainer };
|
|
@@ -4,18 +4,42 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
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;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
7
|
var BaseModule_1;
|
|
11
|
-
import { ContainerModule } from "inversify";
|
|
8
|
+
import { BindingScopeEnum, ContainerModule } from "inversify";
|
|
12
9
|
import { provide } from "inversify-binding-decorators";
|
|
10
|
+
import { provideSingleton, provideTransient } from "../decorator";
|
|
11
|
+
/**
|
|
12
|
+
* Key to be used for storing and retrieving binding type metadata.
|
|
13
|
+
*/
|
|
14
|
+
const BINDING_TYPE_METADATA_KEY = "binding-type";
|
|
15
|
+
/**
|
|
16
|
+
* The scope decorator is a higher order function that can be used to decorate a class with a binding type.
|
|
17
|
+
* @param binding An instance of interfaces.BindingScope which represents the binding type.
|
|
18
|
+
* @returns A decorator function that can be used to decorate a class with a binding type.
|
|
19
|
+
*/
|
|
20
|
+
const scope = (binding) => {
|
|
21
|
+
return function (target) {
|
|
22
|
+
if (!Reflect.hasMetadata(BINDING_TYPE_METADATA_KEY, target)) {
|
|
23
|
+
Reflect.defineMetadata(BINDING_TYPE_METADATA_KEY, binding, target);
|
|
24
|
+
switch (binding) {
|
|
25
|
+
case BindingScopeEnum.Singleton:
|
|
26
|
+
provideSingleton(target);
|
|
27
|
+
break;
|
|
28
|
+
case BindingScopeEnum.Transient:
|
|
29
|
+
provideTransient(target);
|
|
30
|
+
break;
|
|
31
|
+
default:
|
|
32
|
+
provide(target);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
};
|
|
13
38
|
/**
|
|
14
39
|
* The BaseModule class provides methods for creating InversifyJS container modules.
|
|
15
40
|
* @provide BaseModule
|
|
16
41
|
*/
|
|
17
42
|
let BaseModule = BaseModule_1 = class BaseModule {
|
|
18
|
-
constructor() { }
|
|
19
43
|
/**
|
|
20
44
|
* Create a map of symbols for the provided controllers.
|
|
21
45
|
* @param controllers - An array of controller classes.
|
|
@@ -31,23 +55,51 @@ let BaseModule = BaseModule_1 = class BaseModule {
|
|
|
31
55
|
return symbols;
|
|
32
56
|
}
|
|
33
57
|
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
58
|
+
* Create an InversifyJS ContainerModule for the provided controllers.
|
|
59
|
+
* @param controllers - An array of controller classes.
|
|
60
|
+
* @param scope - An optional binding scope to be used for all controllers.
|
|
61
|
+
* @returns A ContainerModule with the controller bindings.
|
|
62
|
+
*/
|
|
63
|
+
static createContainerModule(controllers, scope) {
|
|
39
64
|
const symbols = BaseModule_1.createSymbols(controllers);
|
|
40
|
-
return new ContainerModule(bind => {
|
|
41
|
-
for (const symbol of symbols) {
|
|
42
|
-
|
|
43
|
-
|
|
65
|
+
return new ContainerModule((bind) => {
|
|
66
|
+
for (const [symbol, target] of symbols) {
|
|
67
|
+
if (scope) {
|
|
68
|
+
switch (scope) {
|
|
69
|
+
case BindingScopeEnum.Singleton:
|
|
70
|
+
bind(symbol).to(target).inSingletonScope();
|
|
71
|
+
break;
|
|
72
|
+
case BindingScopeEnum.Transient:
|
|
73
|
+
bind(symbol).to(target).inTransientScope();
|
|
74
|
+
break;
|
|
75
|
+
case BindingScopeEnum.Request:
|
|
76
|
+
bind(symbol).to(target).inRequestScope();
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const bindingType = Reflect.getMetadata(BINDING_TYPE_METADATA_KEY, target);
|
|
82
|
+
switch (bindingType) {
|
|
83
|
+
case BindingScopeEnum.Singleton:
|
|
84
|
+
bind(symbol).to(target).inSingletonScope();
|
|
85
|
+
break;
|
|
86
|
+
case BindingScopeEnum.Transient:
|
|
87
|
+
bind(symbol).to(target).inTransientScope();
|
|
88
|
+
break;
|
|
89
|
+
case BindingScopeEnum.Request:
|
|
90
|
+
bind(symbol).to(target).inRequestScope();
|
|
91
|
+
break;
|
|
92
|
+
default:
|
|
93
|
+
bind(symbol).to(target).inRequestScope();
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
44
97
|
}
|
|
45
98
|
});
|
|
46
99
|
}
|
|
47
100
|
};
|
|
48
101
|
BaseModule = BaseModule_1 = __decorate([
|
|
49
|
-
provide(BaseModule_1)
|
|
50
|
-
__metadata("design:paramtypes", [])
|
|
102
|
+
provide(BaseModule_1)
|
|
51
103
|
], BaseModule);
|
|
52
104
|
const CreateModule = BaseModule.createContainerModule;
|
|
53
|
-
export { CreateModule };
|
|
105
|
+
export { CreateModule, scope };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { CreateModule } from "./container-module";
|
|
1
|
+
export { CreateModule, scope } from "./container-module";
|
|
@@ -37,7 +37,7 @@ let BaseController = BaseController_1 = class BaseController {
|
|
|
37
37
|
return res.status(successStatusCode).json(dataReturn);
|
|
38
38
|
}
|
|
39
39
|
catch (error) {
|
|
40
|
-
Report.Error(error);
|
|
40
|
+
Report.Error(error, undefined, this.serviceName);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
@@ -53,7 +53,7 @@ let BaseController = BaseController_1 = class BaseController {
|
|
|
53
53
|
return res.status(successStatusCode).json(dataReturn);
|
|
54
54
|
}
|
|
55
55
|
catch (error) {
|
|
56
|
-
Report.Error(error);
|
|
56
|
+
Report.Error(error, undefined, this.serviceName);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./scope-binding";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { fluentProvide } from "inversify-binding-decorators";
|
|
2
|
+
const provideSingleton = (identifier) => {
|
|
3
|
+
return fluentProvide(identifier).inSingletonScope().done();
|
|
4
|
+
};
|
|
5
|
+
const provideTransient = (identifier) => {
|
|
6
|
+
return fluentProvide(identifier).inTransientScope().done();
|
|
7
|
+
};
|
|
8
|
+
export { provideSingleton, provideTransient };
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { StatusCode } from "./status-code";
|
|
2
|
-
import { LogLevel, log } from "../logger";
|
|
3
2
|
/**
|
|
4
3
|
* errorHandler is a custom Express error-handling middleware function.
|
|
5
4
|
* It logs the error, sets the status code, and sends a JSON response containing the status code and error message.
|
|
6
|
-
* @param error - An instance of
|
|
5
|
+
* @param error - An instance of IAppError containing error details.
|
|
7
6
|
* @param req - The Express request object.
|
|
8
7
|
* @param res - The Express response object.
|
|
9
8
|
* @param next - The Express next function for passing control to the next middleware function.
|
|
10
9
|
*/
|
|
11
10
|
function errorHandler(error, req, res, next) {
|
|
12
|
-
log(LogLevel.Error, error, error.service || "service-undefined");
|
|
13
11
|
res.status(error.statusCode || StatusCode.InternalServerError).json({ statusCode: error.statusCode, error: error.message });
|
|
14
12
|
}
|
|
15
13
|
export default errorHandler;
|
package/lib/esm/error/index.js
CHANGED
package/lib/esm/error/report.js
CHANGED
|
@@ -6,16 +6,40 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
var Report_1;
|
|
8
8
|
import { provide } from "inversify-binding-decorators";
|
|
9
|
+
import { LogLevel, log } from '../logger';
|
|
9
10
|
/**
|
|
10
11
|
* Report class is a utility class to manage and throw application-specific errors.
|
|
11
12
|
*/
|
|
12
13
|
let Report = Report_1 = class Report {
|
|
14
|
+
static stack;
|
|
13
15
|
/**
|
|
14
16
|
* Error method takes an instance of AppError and throws it.
|
|
15
17
|
* @param error - An instance of AppError containing error details.
|
|
16
18
|
*/
|
|
17
|
-
static Error(error) {
|
|
18
|
-
|
|
19
|
+
static Error(error, statusCode, service) {
|
|
20
|
+
let appError = {};
|
|
21
|
+
Error.captureStackTrace(this, this.Error);
|
|
22
|
+
const callerName = this.stack.split("\n")[1]?.trim()?.split(" ")[1];
|
|
23
|
+
if (error instanceof Error) {
|
|
24
|
+
appError = {
|
|
25
|
+
statusCode: statusCode ?? 500,
|
|
26
|
+
message: error.message,
|
|
27
|
+
service: service ?? callerName,
|
|
28
|
+
name: error.name,
|
|
29
|
+
stack: error.stack
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
appError = {
|
|
34
|
+
statusCode: statusCode ?? 500,
|
|
35
|
+
message: error,
|
|
36
|
+
service: service ?? callerName,
|
|
37
|
+
name: this.Error.name,
|
|
38
|
+
stack: this.stack
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
log(LogLevel.Error, appError, appError.service || "service-undefined");
|
|
42
|
+
throw appError;
|
|
19
43
|
}
|
|
20
44
|
};
|
|
21
45
|
Report = Report_1 = __decorate([
|
package/lib/esm/index.mjs
CHANGED
|
@@ -34,8 +34,8 @@ let GeneralLogger = GeneralLogger_1 = class GeneralLogger {
|
|
|
34
34
|
*/
|
|
35
35
|
createConsoleTransport() {
|
|
36
36
|
const consoleTransport = new transports.Console({
|
|
37
|
-
level: "debug",
|
|
38
|
-
handleExceptions:
|
|
37
|
+
level: (process.env.ENVIRONMENT !== "Development" && "debug") || "debug",
|
|
38
|
+
handleExceptions: false,
|
|
39
39
|
handleRejections: true
|
|
40
40
|
});
|
|
41
41
|
return consoleTransport;
|
|
@@ -1,20 +1,32 @@
|
|
|
1
|
-
import { Container, ContainerModule } from "inversify";
|
|
1
|
+
import { Container, ContainerModule, interfaces } from "inversify";
|
|
2
2
|
/**
|
|
3
3
|
* The AppContainer class provides a container for managing dependency injection.
|
|
4
4
|
* @provide AppContainer
|
|
5
5
|
*/
|
|
6
6
|
declare class AppContainer {
|
|
7
7
|
private container;
|
|
8
|
-
/**
|
|
9
|
-
* Constructs a new instance of the AppContainer class.
|
|
10
|
-
*/
|
|
11
|
-
constructor();
|
|
12
8
|
/**
|
|
13
9
|
* Creates and configures a new dependency injection container.
|
|
14
10
|
* @param modules - An array of ContainerModule instances to load into the container.
|
|
11
|
+
* @param defaultScope - The default scope to use for bindings. Scoped (Request) by default, but offers Singleton and Transient as well.
|
|
15
12
|
* @returns The configured dependency injection container.
|
|
16
13
|
*/
|
|
17
|
-
create(modules: ContainerModule[]): Container;
|
|
14
|
+
create(modules: ContainerModule[], defaultScope?: interfaces.BindingScope): Container;
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves the binding dictionary of the container.
|
|
17
|
+
* @returns The binding dictionary of the container.
|
|
18
|
+
*/
|
|
19
|
+
getBindingDictionary(): Map<any, any>;
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves the container options.
|
|
22
|
+
* @returns The container options.
|
|
23
|
+
*/
|
|
24
|
+
getContainerOptions(): interfaces.ContainerOptions;
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves the container.
|
|
27
|
+
* @returns The container.
|
|
28
|
+
*/
|
|
29
|
+
get Container(): Container;
|
|
18
30
|
}
|
|
19
31
|
export { AppContainer };
|
|
20
32
|
//# sourceMappingURL=app-container.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-container.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/application/app-container.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"app-container.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/application/app-container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGrF;;;GAGG;AACH,cACM,YAAY;IAEd,OAAO,CAAC,SAAS,CAAa;IAC9B;;;;;OAKG;IACI,MAAM,CACT,OAAO,EAAE,eAAe,EAAE,EAC1B,YAAY,GAAE,UAAU,CAAC,YAAuC,GACjE,SAAS;IAWZ;;;OAGG;IACI,oBAAoB,IAAI,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC;IAI5C;;;OAGG;IACI,mBAAmB,IAAI,UAAU,CAAC,gBAAgB;IAIzD;;;OAGG;IACH,IAAW,SAAS,IAAI,SAAS,CAEhC;CACJ;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { ContainerModule } from "inversify";
|
|
1
|
+
import { ContainerModule, interfaces } from "inversify";
|
|
2
|
+
/**
|
|
3
|
+
* The scope decorator is a higher order function that can be used to decorate a class with a binding type.
|
|
4
|
+
* @param binding An instance of interfaces.BindingScope which represents the binding type.
|
|
5
|
+
* @returns A decorator function that can be used to decorate a class with a binding type.
|
|
6
|
+
*/
|
|
7
|
+
declare const scope: (binding: interfaces.BindingScope) => (target: any) => void;
|
|
2
8
|
/**
|
|
3
9
|
* The BaseModule class provides methods for creating InversifyJS container modules.
|
|
4
10
|
* @provide BaseModule
|
|
5
11
|
*/
|
|
6
12
|
declare class BaseModule {
|
|
7
|
-
constructor();
|
|
8
13
|
/**
|
|
9
14
|
* Create a map of symbols for the provided controllers.
|
|
10
15
|
* @param controllers - An array of controller classes.
|
|
@@ -12,12 +17,13 @@ declare class BaseModule {
|
|
|
12
17
|
*/
|
|
13
18
|
private static createSymbols;
|
|
14
19
|
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
* Create an InversifyJS ContainerModule for the provided controllers.
|
|
21
|
+
* @param controllers - An array of controller classes.
|
|
22
|
+
* @param scope - An optional binding scope to be used for all controllers.
|
|
23
|
+
* @returns A ContainerModule with the controller bindings.
|
|
24
|
+
*/
|
|
25
|
+
static createContainerModule(controllers: any[], scope?: interfaces.BindingScope): ContainerModule;
|
|
20
26
|
}
|
|
21
27
|
declare const CreateModule: typeof BaseModule.createContainerModule;
|
|
22
|
-
export { CreateModule };
|
|
28
|
+
export { CreateModule, scope };
|
|
23
29
|
//# sourceMappingURL=container-module.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container-module.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/container-module/container-module.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"container-module.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/container-module/container-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,eAAe,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAS1E;;;;GAIG;AACH,QAAA,MAAM,KAAK,YAAa,WAAW,YAAY,cAClB,GAAG,SAiB/B,CAAC;AAOF;;;GAGG;AACH,cACM,UAAU;IACZ;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;IAY5B;;;;;OAKG;WACW,qBAAqB,CAC/B,WAAW,EAAE,GAAG,EAAE,EAClB,KAAK,CAAC,EAAE,UAAU,CAAC,YAAY,GAChC,eAAe;CAyCrB;AAED,QAAA,MAAM,YAAY,yCAAmC,CAAC;AAEtD,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { CreateModule } from "./container-module";
|
|
1
|
+
export { CreateModule, scope } from "./container-module";
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/container-module/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/container-module/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/decorator/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-binding.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/decorator/scope-binding.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,gBAAgB,eAAgB,GAAG,yBAExC,CAAC;AAEF,QAAA,MAAM,gBAAgB,eAAgB,GAAG,yBAExC,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { NextFunction, Request, Response } from "express";
|
|
2
|
-
import {
|
|
2
|
+
import { IAppError } from "./report";
|
|
3
3
|
/**
|
|
4
4
|
* errorHandler is a custom Express error-handling middleware function.
|
|
5
5
|
* It logs the error, sets the status code, and sends a JSON response containing the status code and error message.
|
|
6
|
-
* @param error - An instance of
|
|
6
|
+
* @param error - An instance of IAppError containing error details.
|
|
7
7
|
* @param req - The Express request object.
|
|
8
8
|
* @param res - The Express response object.
|
|
9
9
|
* @param next - The Express next function for passing control to the next middleware function.
|
|
10
10
|
*/
|
|
11
|
-
declare function errorHandler(error:
|
|
11
|
+
declare function errorHandler(error: IAppError, req: Request, res: Response, next: NextFunction): void;
|
|
12
12
|
export default errorHandler;
|
|
13
13
|
//# sourceMappingURL=error-handler-middleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-handler-middleware.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/error-handler-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"error-handler-middleware.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/error-handler-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAIrC;;;;;;;GAOG;AACH,iBAAS,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAE7F;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
interface IAppError {
|
|
2
|
+
statusCode: number;
|
|
3
|
+
message: string;
|
|
4
|
+
service?: string;
|
|
5
|
+
name: string;
|
|
6
|
+
stack?: string;
|
|
7
|
+
}
|
|
2
8
|
/**
|
|
3
9
|
* Report class is a utility class to manage and throw application-specific errors.
|
|
4
10
|
*/
|
|
5
11
|
declare class Report {
|
|
12
|
+
static stack: string;
|
|
6
13
|
/**
|
|
7
14
|
* Error method takes an instance of AppError and throws it.
|
|
8
15
|
* @param error - An instance of AppError containing error details.
|
|
9
16
|
*/
|
|
10
|
-
static Error(error:
|
|
17
|
+
static Error(error: Error | string, statusCode?: number, service?: string): void;
|
|
11
18
|
}
|
|
12
|
-
export { Report };
|
|
19
|
+
export { Report, IAppError };
|
|
13
20
|
//# sourceMappingURL=report.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/report.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/report.ts"],"names":[],"mappings":"AAGA,UAAU,SAAS;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAGD;;GAEG;AACH,cACM,MAAM;IACR,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC;IAErB;;;OAGG;WACW,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;CA6B1F;AAED,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC"}
|
package/lib/esm/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/core/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/core/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
|
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
|
|
5
5
|
"author": "Richard Zampieri",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"homepage": "https://expresso-ts.com",
|
|
25
25
|
"funding": {
|
|
26
|
-
"type": "",
|
|
27
|
-
"url": ""
|
|
26
|
+
"type": "github",
|
|
27
|
+
"url": "https://github.com/sponsors/expressots"
|
|
28
28
|
},
|
|
29
29
|
"repository": {
|
|
30
30
|
"type": "git",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
|
|
5
5
|
"author": "Richard Zampieri",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"homepage": "https://expresso-ts.com",
|
|
25
25
|
"funding": {
|
|
26
|
-
"type": "",
|
|
27
|
-
"url": ""
|
|
26
|
+
"type": "github",
|
|
27
|
+
"url": "https://github.com/sponsors/expressots"
|
|
28
28
|
},
|
|
29
29
|
"repository": {
|
|
30
30
|
"type": "git",
|
|
@@ -1,37 +0,0 @@
|
|
|
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
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var AppError_1;
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.AppError = void 0;
|
|
14
|
-
const inversify_binding_decorators_1 = require("inversify-binding-decorators");
|
|
15
|
-
/**
|
|
16
|
-
* The AppError class extends the built-in Error class, adding a status code and service property.
|
|
17
|
-
* It is designed for handling application-specific errors with more detailed information.
|
|
18
|
-
* @provide AppError
|
|
19
|
-
*/
|
|
20
|
-
let AppError = AppError_1 = class AppError extends Error {
|
|
21
|
-
/**
|
|
22
|
-
* Constructs a new AppError instance.
|
|
23
|
-
* @param statusCode - The status code associated with the error.
|
|
24
|
-
* @param message - The error message.
|
|
25
|
-
* @param service - An optional service name related to the error.
|
|
26
|
-
*/
|
|
27
|
-
constructor(statusCode, message, service) {
|
|
28
|
-
super(message);
|
|
29
|
-
this.statusCode = statusCode;
|
|
30
|
-
this.service = service;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
AppError = AppError_1 = __decorate([
|
|
34
|
-
(0, inversify_binding_decorators_1.provide)(AppError_1),
|
|
35
|
-
__metadata("design:paramtypes", [Number, String, String])
|
|
36
|
-
], AppError);
|
|
37
|
-
exports.AppError = AppError;
|