@xrystal/core 3.16.8 → 3.17.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.16.8",
4
+ "version": "3.17.0",
5
5
  "description": "Project core for xrystal",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -1,5 +1,6 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks';
2
2
  import { ProtocolEnum } from '../../utils/index';
3
+ import LoggerService from '../logger';
3
4
  export declare const controllerContextStorage: AsyncLocalStorage<{
4
5
  protocol?: ProtocolEnum;
5
6
  ctx?: any;
@@ -42,9 +43,9 @@ export interface CustomResponse {
42
43
  locals: Record<string, any>;
43
44
  }
44
45
  declare abstract class Controller {
45
- protected loggerService: any;
46
+ protected logger: LoggerService;
46
47
  protected supportedProtocols: ProtocolEnum[];
47
- constructor({ loggerService }: any);
48
+ constructor();
48
49
  protected get protocol(): ProtocolEnum;
49
50
  protected get currentStore(): {
50
51
  protocol?: ProtocolEnum;
@@ -63,7 +64,6 @@ declare abstract class Controller {
63
64
  protected parsedQuerys: (url: string) => Record<string, any>;
64
65
  }
65
66
  export declare abstract class ControllerService extends Controller {
66
- constructor({ loggerService }: any);
67
67
  load(props?: {
68
68
  type?: ProtocolEnum | ProtocolEnum[];
69
69
  }): Promise<void>;
@@ -1,13 +1,13 @@
1
1
  import qs from 'qs';
2
2
  import { AsyncLocalStorage } from 'node:async_hooks';
3
- import { ProtocolEnum, responseMessageHelper, ResponseSchema } from '../../utils/index';
3
+ import { LoggerLayerEnum, ProtocolEnum, responseMessageHelper, ResponseSchema, x } from '../../utils/index';
4
+ import LoggerService from '../logger';
4
5
  export const controllerContextStorage = new AsyncLocalStorage();
5
6
  export const getControllerCtx = () => controllerContextStorage.getStore();
6
7
  class Controller {
7
- loggerService;
8
+ logger = x.get(LoggerService);
8
9
  supportedProtocols = [ProtocolEnum.HTTP, ProtocolEnum.WEBSOCKET];
9
- constructor({ loggerService }) {
10
- this.loggerService = loggerService;
10
+ constructor() {
11
11
  }
12
12
  get protocol() {
13
13
  return this.currentStore?.protocol || ProtocolEnum.HTTP;
@@ -89,9 +89,6 @@ class Controller {
89
89
  };
90
90
  }
91
91
  export class ControllerService extends Controller {
92
- constructor({ loggerService }) {
93
- super({ loggerService });
94
- }
95
92
  async load(props = {}) {
96
93
  if (props.type)
97
94
  this.supportedProtocols = Array.isArray(props.type) ? props.type : [props.type];
@@ -127,10 +124,13 @@ export class ControllerService extends Controller {
127
124
  return res.send(logicResult?.payload !== undefined ? logicResult.payload : logicResult);
128
125
  }
129
126
  catch (error) {
130
- this.loggerService.error(`Controller Error: ${error.message}`, { stack: error.stack });
127
+ this.logger.winston.log({
128
+ level: LoggerLayerEnum[LoggerLayerEnum.CRITICAL].toLowerCase(),
129
+ message: `Controller Error: ${error}`,
130
+ });
131
131
  return this.res.status(500).send({
132
132
  status: false,
133
- message: error.message || "Internal Server Error"
133
+ message: error.message
134
134
  });
135
135
  }
136
136
  }
@@ -8,16 +8,20 @@ export default class EventsService {
8
8
  this._globalLoader();
9
9
  };
10
10
  _globalLoader = () => {
11
- process.on("uncaughtException", (exception) => {
11
+ process.on("uncaughtException", (error, origin) => {
12
12
  this.#loggerService.winston.log({
13
13
  level: LoggerLayerEnum[LoggerLayerEnum.CRITICAL].toLowerCase(),
14
- message: `UncaughtException: ${exception}`,
14
+ message: `UncaughtException: ${error.message}`,
15
+ stack: error.stack,
16
+ origin: origin
15
17
  });
16
18
  });
17
- process.on("unhandledRejection", (exception) => {
19
+ process.on("unhandledRejection", (reason, promise) => {
20
+ const error = reason instanceof Error ? reason : new Error(String(reason));
18
21
  this.#loggerService.winston.log({
19
22
  level: LoggerLayerEnum[LoggerLayerEnum.CRITICAL].toLowerCase(),
20
- message: `UnhandledRejection: ${exception}`,
23
+ message: `UnhandledRejection: ${error.message}`,
24
+ stack: error.stack
21
25
  });
22
26
  });
23
27
  };