@xrystal/core 3.19.2 → 3.19.3
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.19.
|
|
4
|
+
"version": "3.19.3",
|
|
5
5
|
"description": "Project core for xrystal",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public",
|
|
@@ -37,17 +37,21 @@
|
|
|
37
37
|
"start": "bun --env-file=../infrastructer/x/environments/.global.env --env-file=../infrastructer/x/environments/.dev.env source/index.js"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
+
"@types/lodash": "^4.17.23",
|
|
40
41
|
"@types/yaml": "^1.9.7",
|
|
41
42
|
"awilix": "^12.0.5",
|
|
42
43
|
"chalk": "^5.6.2",
|
|
43
44
|
"commander": "^13.0.0",
|
|
44
45
|
"ejs": "^3.1.9",
|
|
45
46
|
"handlebars": "^4.7.8",
|
|
47
|
+
"i": "^0.3.7",
|
|
46
48
|
"i18next": "^25.6.3",
|
|
47
49
|
"i18next-fs-backend": "^2.6.1",
|
|
48
50
|
"i18next-http-middleware": "^3.8.2",
|
|
49
51
|
"kafkajs": "^2.2.4",
|
|
52
|
+
"lodash": "^4.17.23",
|
|
50
53
|
"moment-timezone": "^0.6.0",
|
|
54
|
+
"npm": "^11.7.0",
|
|
51
55
|
"ora": "^9.0.0",
|
|
52
56
|
"picocolors": "^1.1.1",
|
|
53
57
|
"qs": "^6.14.1",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { merge } from 'lodash';
|
|
2
3
|
import { Constants } from '../../utils';
|
|
3
4
|
import { pathToFileURL } from 'node:url';
|
|
4
5
|
export default class ConfigsService {
|
|
@@ -52,21 +53,16 @@ export default class ConfigsService {
|
|
|
52
53
|
try {
|
|
53
54
|
const moduleData = await modulePromise;
|
|
54
55
|
const importedConfigs = moduleData?.default || moduleData?.configs || moduleData || {};
|
|
55
|
-
this.#config
|
|
56
|
-
|
|
57
|
-
...(typeof importedConfigs === 'object' ? importedConfigs : {})
|
|
58
|
-
};
|
|
56
|
+
const merged = merge({}, this.#config, importedConfigs || {});
|
|
57
|
+
this.#config = Object.freeze(merged);
|
|
59
58
|
}
|
|
60
59
|
catch (e) {
|
|
61
60
|
// error
|
|
62
61
|
}
|
|
63
62
|
};
|
|
64
63
|
setConfig(newConfigs) {
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
...newConfigs
|
|
68
|
-
};
|
|
69
|
-
this.#config = Object.freeze(mergedData);
|
|
64
|
+
const mergedDObj = Object.assign(this.#config, newConfigs);
|
|
65
|
+
this.#config = Object.freeze(mergedDObj);
|
|
70
66
|
}
|
|
71
67
|
_(key) {
|
|
72
68
|
return this.#config[key];
|
|
@@ -60,7 +60,6 @@ declare abstract class Controller {
|
|
|
60
60
|
};
|
|
61
61
|
protected get req(): CustomRequest;
|
|
62
62
|
protected get res(): CustomResponse;
|
|
63
|
-
protected parsedQuerys: (url: string) => Record<string, any>;
|
|
64
63
|
}
|
|
65
64
|
export declare abstract class ControllerService extends Controller {
|
|
66
65
|
load(props?: {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import qs from 'qs';
|
|
2
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
2
|
import { LoggerLayerEnum, ProtocolEnum, responseMessageHelper, ResponseSchema, x } from '../../utils/index';
|
|
4
3
|
import LoggerService from '../logger';
|
|
@@ -16,22 +15,18 @@ class Controller {
|
|
|
16
15
|
get req() {
|
|
17
16
|
const store = this.currentStore;
|
|
18
17
|
const identityT = (k) => k;
|
|
19
|
-
if (!store)
|
|
18
|
+
if (!store?.ctx)
|
|
20
19
|
return { url: '', method: '', headers: {}, params: {}, query: {}, lang: 'en', t: identityT };
|
|
21
|
-
const { ctx, req: nativeReq } = store;
|
|
22
|
-
const source = nativeReq || ctx?.request || ctx;
|
|
23
20
|
return {
|
|
24
|
-
url:
|
|
25
|
-
method:
|
|
26
|
-
headers:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
accounts: ctx
|
|
33
|
-
lang: ctx?.lang || nativeReq?.lang || source?.lang || 'en',
|
|
34
|
-
t: ctx?.t || nativeReq?.t || source?.t || identityT
|
|
21
|
+
url: store.ctx.url,
|
|
22
|
+
method: store.ctx.method,
|
|
23
|
+
headers: store.ctx.headers,
|
|
24
|
+
body: store.ctx.body,
|
|
25
|
+
query: store.ctx.query,
|
|
26
|
+
params: store.ctx.params,
|
|
27
|
+
lang: store.ctx.lang,
|
|
28
|
+
t: store.ctx.t || identityT,
|
|
29
|
+
accounts: store.ctx.accounts || store.req?.accounts
|
|
35
30
|
};
|
|
36
31
|
}
|
|
37
32
|
get res() {
|
|
@@ -76,15 +71,6 @@ class Controller {
|
|
|
76
71
|
json(data) { return this.send(data); }
|
|
77
72
|
};
|
|
78
73
|
}
|
|
79
|
-
parsedQuerys = (url) => {
|
|
80
|
-
try {
|
|
81
|
-
const queryPart = url.split('?')[1];
|
|
82
|
-
return queryPart ? qs.parse(queryPart, { decoder: decodeURIComponent }) : {};
|
|
83
|
-
}
|
|
84
|
-
catch {
|
|
85
|
-
return {};
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
74
|
}
|
|
89
75
|
export class ControllerService extends Controller {
|
|
90
76
|
async load(props = {}) {
|
|
@@ -93,14 +79,19 @@ export class ControllerService extends Controller {
|
|
|
93
79
|
}
|
|
94
80
|
async schema({ checks, logic, response }) {
|
|
95
81
|
try {
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
const payload = { req, res };
|
|
99
|
-
const convertedPayload = {
|
|
82
|
+
const currentReq = this.req;
|
|
83
|
+
const currentRes = this.res;
|
|
84
|
+
const payload = { req: currentReq, res: currentRes };
|
|
85
|
+
const convertedPayload = {
|
|
86
|
+
...payload,
|
|
87
|
+
query: currentReq.query,
|
|
88
|
+
body: currentReq.body,
|
|
89
|
+
params: currentReq.params
|
|
90
|
+
};
|
|
100
91
|
if (checks) {
|
|
101
92
|
const checkResult = await checks({ payload, convertedPayload });
|
|
102
|
-
if (checkResult === false || (checkResult &&
|
|
103
|
-
return
|
|
93
|
+
if (checkResult === false || (checkResult && typeof checkResult === 'object' && !Array.isArray(checkResult))) {
|
|
94
|
+
return currentRes.status(checkResult?.code || 400).send(new ResponseSchema({
|
|
104
95
|
status: false,
|
|
105
96
|
message: checkResult?.message || '',
|
|
106
97
|
code: checkResult?.code || 400
|
|
@@ -109,34 +100,31 @@ export class ControllerService extends Controller {
|
|
|
109
100
|
}
|
|
110
101
|
const logicResult = await logic({ payload, convertedPayload });
|
|
111
102
|
if (logicResult?.status === false) {
|
|
112
|
-
return
|
|
103
|
+
return currentRes.status(logicResult.code || 400).send(new ResponseSchema({
|
|
113
104
|
status: false,
|
|
114
105
|
message: logicResult.message,
|
|
115
106
|
code: logicResult.code || 400
|
|
116
107
|
}).getResponse);
|
|
117
108
|
}
|
|
118
|
-
if (logicResult?.response instanceof Function)
|
|
119
|
-
return logicResult.response(logicResult.payload);
|
|
120
109
|
if (logicResult instanceof Response)
|
|
121
110
|
return logicResult;
|
|
122
111
|
if (response) {
|
|
123
112
|
const resResult = await response({ payload, convertedPayload, logicResult });
|
|
124
113
|
const messageData = Array.isArray(resResult) ? resResult : resResult?.message;
|
|
125
|
-
|
|
114
|
+
return currentRes.status(200).send(new ResponseSchema({
|
|
126
115
|
status: true,
|
|
127
116
|
message: Array.isArray(messageData)
|
|
128
|
-
? responseMessageHelper.successFully(messageData[0], messageData[1],
|
|
117
|
+
? responseMessageHelper.successFully(messageData[0], messageData[1], currentReq.t)
|
|
129
118
|
: (messageData || ''),
|
|
130
119
|
payload: logicResult?.payload !== undefined ? logicResult.payload : logicResult
|
|
131
|
-
};
|
|
132
|
-
return res.status(200).send(new ResponseSchema(successObj).getResponse);
|
|
120
|
+
}).getResponse);
|
|
133
121
|
}
|
|
134
|
-
return
|
|
122
|
+
return currentRes.send(logicResult?.payload !== undefined ? logicResult.payload : logicResult);
|
|
135
123
|
}
|
|
136
124
|
catch (error) {
|
|
137
125
|
this.logger.winston.log({
|
|
138
126
|
level: LoggerLayerEnum[LoggerLayerEnum.CRITICAL].toLowerCase(),
|
|
139
|
-
message: `Controller Error: ${error}
|
|
127
|
+
message: `Controller Error: ${error}`
|
|
140
128
|
});
|
|
141
129
|
return this.res.status(500).send(new ResponseSchema({
|
|
142
130
|
status: false,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
1
2
|
import x from './classes/class.x';
|
|
2
|
-
import locator
|
|
3
|
+
import locator from './classes/class.service-locator';
|
|
3
4
|
export * from './classes/class.tmp-file-loader';
|
|
4
5
|
export * from './classes/class.response';
|
|
5
6
|
export * from './classes/class.services';
|
|
6
7
|
export * from './classes/class.interfaces';
|
|
7
8
|
export * from './types';
|
|
8
9
|
export * from './enums';
|
|
9
|
-
export { x, locator,
|
|
10
|
+
export { x, locator, _ };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
1
2
|
import x from './classes/class.x';
|
|
2
|
-
import locator
|
|
3
|
+
import locator from './classes/class.service-locator';
|
|
3
4
|
export * from './classes/class.tmp-file-loader';
|
|
4
5
|
export * from './classes/class.response';
|
|
5
6
|
export * from './classes/class.services';
|
|
6
7
|
export * from './classes/class.interfaces';
|
|
7
8
|
export * from './types';
|
|
8
9
|
export * from './enums';
|
|
9
|
-
export { x, locator,
|
|
10
|
+
export { x, locator, _ };
|