@xrystal/core 3.24.6 → 3.24.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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.24.6",
4
+ "version": "3.24.7",
5
5
  "description": "Project core for xrystal",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -2,6 +2,23 @@ import { AsyncLocalStorage } from 'node:async_hooks';
2
2
  import Logger from '../logger';
3
3
  import System from '../system';
4
4
  import { IProvide, ProtocolEnum } from '../../utils/index';
5
+ export interface CustomRequest {
6
+ accounts?: any;
7
+ url: string;
8
+ method: string;
9
+ headers: Record<string, any>;
10
+ body?: any;
11
+ params: Record<string, any>;
12
+ query: Record<string, any>;
13
+ lang: string;
14
+ t: (k: string, args?: any) => string;
15
+ }
16
+ export interface CustomResponse {
17
+ status: (code: number) => CustomResponse;
18
+ send: (data: any) => any;
19
+ json: (data: any) => any;
20
+ locals: Record<string, any>;
21
+ }
5
22
  export declare const controllerContextStorage: AsyncLocalStorage<{
6
23
  protocol?: ProtocolEnum;
7
24
  ctx?: any;
@@ -59,20 +76,3 @@ export default abstract class Controller extends BaseController implements IProv
59
76
  response?: (args: any) => Promise<any>;
60
77
  }): Promise<any>;
61
78
  }
62
- export interface CustomRequest {
63
- accounts?: any;
64
- url: string;
65
- method: string;
66
- headers: Record<string, any>;
67
- body?: any;
68
- params: Record<string, any>;
69
- query: Record<string, any>;
70
- lang: string;
71
- t: (k: string, args?: any) => string;
72
- }
73
- export interface CustomResponse {
74
- status: (code: number) => CustomResponse;
75
- send: (data: any) => any;
76
- json: (data: any) => any;
77
- locals: Record<string, any>;
78
- }
@@ -93,9 +93,11 @@ export default class Controller extends BaseController {
93
93
  payloadString = '';
94
94
  }
95
95
  }
96
+ else if (content === 'unsuccessful' || content === 'success_process') {
97
+ payloadString = '';
98
+ }
96
99
  const params = payloadString.split('-').map(p => p.trim()).filter(p => p !== '');
97
- const p1Raw = params[0] || '';
98
- const p1 = (p1Raw === method || p1Raw === 'unsuccessful' || p1Raw === 'success_process') ? '' : t(p1Raw);
100
+ const p1 = params[0] ? t(params[0]) : '';
99
101
  const p2 = params.slice(1).map(v => t(v)).join(' ');
100
102
  if (responseMessageHelper[method])
101
103
  return responseMessageHelper[method](p1, p2, t);
@@ -119,7 +121,7 @@ export default class Controller extends BaseController {
119
121
  const checkResult = await checks(p);
120
122
  if (checkResult !== true) {
121
123
  extractMeta(checkResult);
122
- const bizCode = store?.metadata._code ?? 400;
124
+ const bizCode = store?.metadata?._code ?? 400;
123
125
  let errorPayload = undefined;
124
126
  if (checkResult?.payload) {
125
127
  const d = checkResult.payload.data ?? checkResult.payload;
@@ -139,7 +141,7 @@ export default class Controller extends BaseController {
139
141
  extractMeta(logicResult);
140
142
  }
141
143
  if (logicResult?.status === false) {
142
- const bizCode = store?.metadata._code ?? 400;
144
+ const bizCode = store?.metadata?._code ?? 400;
143
145
  return currentRes.status(bizCode).send(new ResponseSchema({ status: false, message: this.parseMessage(logicResult.message, currentReq.t, true), code: bizCode }).getResponse);
144
146
  }
145
147
  const resResult = response ? await response({ ...p, logicResult }) : logicResult;
@@ -175,7 +177,7 @@ export default class Controller extends BaseController {
175
177
  else {
176
178
  extractData(resResult !== undefined ? resResult : logicResult);
177
179
  }
178
- const bizSuccessCode = store?.metadata._code || 200;
180
+ let bizSuccessCode = store?.metadata?._code || 200;
179
181
  let payload = undefined;
180
182
  if (finalData !== undefined || finalExtraData !== undefined) {
181
183
  payload = {};
@@ -2,15 +2,15 @@ export interface PayloadSchemaInterface {
2
2
  status: boolean;
3
3
  message: string;
4
4
  payload?: any;
5
- [key: string]: any;
6
5
  code?: number;
6
+ [key: string]: any;
7
7
  }
8
8
  export declare class ResponseSchema {
9
- constructor({ status, message, payload, code }: PayloadSchemaInterface);
10
9
  status: boolean;
11
10
  message: string;
12
11
  payload: any;
13
12
  code: number;
13
+ constructor({ status, message, payload, code }: PayloadSchemaInterface);
14
14
  validData(): any;
15
15
  statusCodeGenerator(): number;
16
16
  get getResponse(): any;
@@ -1,14 +1,14 @@
1
1
  export class ResponseSchema {
2
+ status;
3
+ message;
4
+ payload;
5
+ code;
2
6
  constructor({ status = false, message = '', payload = null, code = 0 }) {
3
7
  this.status = status;
4
8
  this.message = message;
5
9
  this.payload = payload;
6
10
  this.code = code;
7
11
  }
8
- status;
9
- message;
10
- payload;
11
- code;
12
12
  validData() {
13
13
  return this.payload;
14
14
  }
@@ -24,7 +24,7 @@ export class ResponseSchema {
24
24
  }
25
25
  }
26
26
  get getResponse() {
27
- let response = {
27
+ const response = {
28
28
  status: this.status,
29
29
  message: this.message
30
30
  };
@@ -32,6 +32,6 @@ export class ResponseSchema {
32
32
  response.payload = this.validData();
33
33
  }
34
34
  response.code = this.statusCodeGenerator();
35
- return { ...response };
35
+ return response;
36
36
  }
37
37
  }