@xrystal/core 3.21.7 → 3.21.9

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.21.7",
4
+ "version": "3.21.9",
5
5
  "description": "Project core for xrystal",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -1,7 +1,7 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks';
2
- import { IService, ProtocolEnum } from '../../utils/index';
3
2
  import LoggerService from '../logger';
4
3
  import SystemService from '../system';
4
+ import { IService, ProtocolEnum } from '../../utils/index';
5
5
  export declare const controllerContextStorage: AsyncLocalStorage<{
6
6
  protocol?: ProtocolEnum;
7
7
  ctx?: any;
@@ -1,7 +1,7 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks';
2
- import { LoggerLayerEnum, ProtocolEnum, responseMessageHelper, ResponseSchema, x } from '../../utils/index';
3
2
  import LoggerService from '../logger';
4
3
  import SystemService from '../system';
4
+ import { LoggerLayerEnum, ProtocolEnum, responseMessageHelper, ResponseSchema, x } from '../../utils/index';
5
5
  export const controllerContextStorage = new AsyncLocalStorage();
6
6
  export const getControllerCtx = () => controllerContextStorage.getStore();
7
7
  export class Controller {
@@ -103,7 +103,13 @@ export class ControllerService extends Controller {
103
103
  }).getResponse);
104
104
  }
105
105
  }
106
- const logicResult = logic ? await logic(p) : null;
106
+ let logicResult = logic ? await logic(p) : null;
107
+ if (logicResult && typeof logicResult === 'object' && typeof logicResult.response === 'function') {
108
+ logicResult = await logicResult.response();
109
+ }
110
+ if (logicResult instanceof Response || (logicResult?.constructor?.name === 'Response')) {
111
+ return logicResult;
112
+ }
107
113
  if (logicResult?.status === false) {
108
114
  return currentRes.status(logicResult.code || 400).send(new ResponseSchema({
109
115
  status: false,
@@ -111,9 +117,10 @@ export class ControllerService extends Controller {
111
117
  code: logicResult.code || 400
112
118
  }).getResponse);
113
119
  }
114
- if (logicResult instanceof Response)
115
- return logicResult;
116
120
  const resResult = response ? await response({ ...p, logicResult }) : logicResult;
121
+ if (resResult instanceof Response || (resResult?.constructor?.name === 'Response')) {
122
+ return resResult;
123
+ }
117
124
  let finalMessage = '';
118
125
  let rawMessageValue = '';
119
126
  const messageSource = resResult?.message || (typeof resResult === 'string' || Array.isArray(resResult) ? resResult : '');
@@ -1,9 +1,10 @@
1
1
  import winston from "winston";
2
2
  import "winston-daily-rotate-file";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
- import ConfigsService from "../configs";
5
- import { LoggerLayerEnum, IService } from "../../utils";
6
4
  import SystemService from "../system";
5
+ import ConfigsService from "../configs";
6
+ import { LoggerLayerEnum } from '../../utils/models/enums/index';
7
+ import { IService } from "../../utils";
7
8
  export interface ICustomLogger extends winston.Logger {
8
9
  critical: winston.LeveledLogMethod;
9
10
  http: winston.LeveledLogMethod;
@@ -4,7 +4,7 @@ import "winston-daily-rotate-file";
4
4
  import path from "node:path";
5
5
  import { AsyncLocalStorage } from "node:async_hooks";
6
6
  import { Kafka, Partitioners, logLevel } from "kafkajs";
7
- import { LoggerLayerEnum } from "../../utils";
7
+ import { LoggerLayerEnum } from '../../utils/models/enums/index';
8
8
  class KafkaTransport extends Transport {
9
9
  service;
10
10
  constructor(opts, service) {