@xrystal/core 3.21.6 → 3.21.7
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/package.json
CHANGED
|
@@ -27,8 +27,8 @@ export declare const getControllerCtx: () => {
|
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
export declare abstract class Controller {
|
|
30
|
-
protected logger: LoggerService;
|
|
31
30
|
protected systemService: SystemService;
|
|
31
|
+
protected loggerService: LoggerService;
|
|
32
32
|
protected supportedProtocols: ProtocolEnum[];
|
|
33
33
|
protected get protocol(): ProtocolEnum;
|
|
34
34
|
protected get currentStore(): {
|
|
@@ -47,10 +47,7 @@ export declare abstract class Controller {
|
|
|
47
47
|
protected get res(): CustomResponse;
|
|
48
48
|
}
|
|
49
49
|
export declare abstract class ControllerService extends Controller implements IService<any> {
|
|
50
|
-
constructor({
|
|
51
|
-
systemService: SystemService;
|
|
52
|
-
loggerService: LoggerService;
|
|
53
|
-
});
|
|
50
|
+
constructor({}: {});
|
|
54
51
|
onInit(): Promise<void>;
|
|
55
52
|
schema({ checks, logic, response }: {
|
|
56
53
|
checks?: (args: any) => Promise<any>;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
import { LoggerLayerEnum, ProtocolEnum, responseMessageHelper, ResponseSchema } from '../../utils/index';
|
|
2
|
+
import { LoggerLayerEnum, ProtocolEnum, responseMessageHelper, ResponseSchema, x } from '../../utils/index';
|
|
3
|
+
import LoggerService from '../logger';
|
|
4
|
+
import SystemService from '../system';
|
|
3
5
|
export const controllerContextStorage = new AsyncLocalStorage();
|
|
4
6
|
export const getControllerCtx = () => controllerContextStorage.getStore();
|
|
5
7
|
export class Controller {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
systemService = x.get(SystemService);
|
|
9
|
+
loggerService = x.get(LoggerService);
|
|
8
10
|
supportedProtocols = [ProtocolEnum.HTTP, ProtocolEnum.WEBSOCKET];
|
|
9
11
|
get protocol() {
|
|
10
12
|
return this.currentStore?.protocol || ProtocolEnum.HTTP;
|
|
@@ -72,10 +74,8 @@ export class Controller {
|
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
export class ControllerService extends Controller {
|
|
75
|
-
constructor({
|
|
77
|
+
constructor({}) {
|
|
76
78
|
super();
|
|
77
|
-
this.systemService = systemService;
|
|
78
|
-
this.logger = loggerService;
|
|
79
79
|
}
|
|
80
80
|
async onInit() {
|
|
81
81
|
const protocols = this.systemService?.tmp?.configs?.loaders?.controller?.protocols;
|
|
@@ -146,7 +146,7 @@ export class ControllerService extends Controller {
|
|
|
146
146
|
}).getResponse);
|
|
147
147
|
}
|
|
148
148
|
catch (error) {
|
|
149
|
-
this.
|
|
149
|
+
this.loggerService?.log(LoggerLayerEnum.ERROR, `Controller Error: ${error.message}`);
|
|
150
150
|
return this.res.status(500).send(new ResponseSchema({
|
|
151
151
|
status: false,
|
|
152
152
|
message: error.message,
|