@xrystal/core 3.4.8 → 3.5.1
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 +3 -1
- package/source/loader/logger/index.d.ts +1 -1
- package/source/loader/logger/index.js +24 -15
- package/source/utils/models/classes/class.controller.d.ts +15 -4
- package/source/utils/models/classes/class.controller.js +23 -5
- package/x/dist/loader/logger/index.d.ts +1 -1
- package/x/dist/loader/logger/index.js +24 -15
- package/x/dist/utils/models/classes/class.controller.d.ts +15 -4
- package/x/dist/utils/models/classes/class.controller.js +23 -5
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Yusuf Yasir KAYGUSUZ",
|
|
3
3
|
"name": "@xrystal/core",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.5.1",
|
|
5
5
|
"description": "Project core for xrystal",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public",
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"chalk": "^5.6.2",
|
|
44
44
|
"commander": "^13.0.0",
|
|
45
45
|
"ejs": "^3.1.9",
|
|
46
|
+
"elysia": "^1.4.21",
|
|
46
47
|
"handlebars": "^4.7.8",
|
|
47
48
|
"i18next": "^25.6.3",
|
|
48
49
|
"i18next-fs-backend": "^2.6.1",
|
|
@@ -67,6 +68,7 @@
|
|
|
67
68
|
"yaml": "^2.5.0"
|
|
68
69
|
},
|
|
69
70
|
"devDependencies": {
|
|
71
|
+
"@types/bun": "^1.3.5",
|
|
70
72
|
"@types/express": "^5.0.6",
|
|
71
73
|
"@types/minimist": "^1.2.5",
|
|
72
74
|
"@types/node": "^25.0.6",
|
|
@@ -13,7 +13,7 @@ export default class LoggerService {
|
|
|
13
13
|
private getConsoleFormat;
|
|
14
14
|
winston: CustomLogger;
|
|
15
15
|
constructor();
|
|
16
|
-
load: (config: any) => Promise<void>;
|
|
16
|
+
load: (config: Record<string, any>) => Promise<void>;
|
|
17
17
|
winstonLoader: ({ loadPath, loggerLevel }: {
|
|
18
18
|
loadPath: string;
|
|
19
19
|
loggerLevel: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import winston, { format } from 'winston';
|
|
2
2
|
import 'winston-daily-rotate-file';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import { Kafka, Partitioners } from 'kafkajs';
|
|
4
|
+
import { Kafka, Partitioners, logLevel } from 'kafkajs';
|
|
5
5
|
import { LoggerLayerEnum } from '../../utils';
|
|
6
6
|
const customLevels = {
|
|
7
7
|
critical: LoggerLayerEnum.CRITICAL, // 0
|
|
@@ -53,20 +53,29 @@ export default class LoggerService {
|
|
|
53
53
|
const rawBrokers = config?.kafkaBrokers;
|
|
54
54
|
const brokers = rawBrokers ? String(rawBrokers).split(',').map((b) => b.trim()) : [];
|
|
55
55
|
if (brokers.length > 0) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
56
|
+
const kafka = new Kafka({
|
|
57
|
+
clientId: this.serviceName,
|
|
58
|
+
brokers: brokers,
|
|
59
|
+
logLevel: logLevel.ERROR,
|
|
60
|
+
retry: {
|
|
61
|
+
initialRetryTime: 1000,
|
|
62
|
+
retries: 10,
|
|
63
|
+
maxRetryTime: 30000,
|
|
64
|
+
factor: 2
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
this.kafkaProducer = kafka.producer({ createPartitioner: Partitioners.LegacyPartitioner });
|
|
68
|
+
const connectWithRetry = async () => {
|
|
69
|
+
try {
|
|
70
|
+
await this.kafkaProducer.connect();
|
|
71
|
+
this.isKafkaReady = true;
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
this.isKafkaReady = false;
|
|
75
|
+
setTimeout(connectWithRetry, 5000);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
connectWithRetry();
|
|
70
79
|
}
|
|
71
80
|
};
|
|
72
81
|
winstonLoader = ({ loadPath, loggerLevel }) => {
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { ParsedQs } from 'qs';
|
|
2
2
|
import { ProtocolEnum, ResponseSchema } from '../../index';
|
|
3
|
+
export interface ElysiaContext {
|
|
4
|
+
request: Request;
|
|
5
|
+
body?: any;
|
|
6
|
+
params?: Record<string, string>;
|
|
7
|
+
query?: Record<string, any>;
|
|
8
|
+
headers?: Headers;
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}
|
|
3
11
|
export interface CustomRequest {
|
|
4
12
|
accounts?: any;
|
|
5
13
|
query: {
|
|
@@ -12,8 +20,10 @@ export interface CustomRequest {
|
|
|
12
20
|
} & ParsedQs;
|
|
13
21
|
url: string;
|
|
14
22
|
method: string;
|
|
15
|
-
headers:
|
|
23
|
+
headers: Record<string, string>;
|
|
16
24
|
body?: any;
|
|
25
|
+
params?: Record<string, string>;
|
|
26
|
+
t?: Function;
|
|
17
27
|
}
|
|
18
28
|
export interface CustomResponse {
|
|
19
29
|
status: (code: number) => CustomResponse;
|
|
@@ -63,12 +73,12 @@ declare abstract class Controller {
|
|
|
63
73
|
protected limit: string | null;
|
|
64
74
|
defaultLimitSize: number;
|
|
65
75
|
maxLimitSize: number;
|
|
66
|
-
|
|
67
|
-
constructor({ protocol, socket, req, res }: {
|
|
76
|
+
constructor({ protocol, socket, req, res, ctx }: {
|
|
68
77
|
protocol: ProtocolEnum;
|
|
69
78
|
socket?: any;
|
|
70
79
|
req?: CustomRequest;
|
|
71
80
|
res?: CustomResponse;
|
|
81
|
+
ctx?: any;
|
|
72
82
|
});
|
|
73
83
|
protected createResponse(data: any, statusCode?: number): Response;
|
|
74
84
|
protected payloadProtocolSwitch: ({ protocol, socket, req, res }: {
|
|
@@ -105,11 +115,12 @@ declare abstract class Controller {
|
|
|
105
115
|
protected getErrorMessage(error: unknown): string;
|
|
106
116
|
}
|
|
107
117
|
declare class ControllerSchema extends Controller {
|
|
108
|
-
constructor({ protocol, socket, req, res }: {
|
|
118
|
+
constructor({ protocol, socket, req, res, ctx }: {
|
|
109
119
|
protocol: ProtocolEnum;
|
|
110
120
|
socket?: any;
|
|
111
121
|
req?: CustomRequest;
|
|
112
122
|
res?: CustomResponse;
|
|
123
|
+
ctx?: any;
|
|
113
124
|
});
|
|
114
125
|
schema({ checks, logic, response, }: {
|
|
115
126
|
checks?: ({ payload, convertedPayload }: {
|
|
@@ -17,8 +17,26 @@ class Controller {
|
|
|
17
17
|
limit = null;
|
|
18
18
|
defaultLimitSize = 20;
|
|
19
19
|
maxLimitSize = 100;
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
constructor({ protocol, socket, req, res, ctx }) {
|
|
21
|
+
// Eğer ctx varsa, otomatik req/res'e çevir
|
|
22
|
+
if (ctx) {
|
|
23
|
+
req = {
|
|
24
|
+
url: ctx.request.url,
|
|
25
|
+
method: ctx.request.method,
|
|
26
|
+
headers: Object.fromEntries(ctx.request.headers),
|
|
27
|
+
body: ctx.body,
|
|
28
|
+
params: ctx.params,
|
|
29
|
+
query: ctx.query,
|
|
30
|
+
accounts: ctx.accounts || ctx.user,
|
|
31
|
+
t: ctx.t
|
|
32
|
+
};
|
|
33
|
+
res = {
|
|
34
|
+
status: (code) => res,
|
|
35
|
+
send: (data) => data,
|
|
36
|
+
json: (data) => data,
|
|
37
|
+
locals: {}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
22
40
|
this.protocol = protocol;
|
|
23
41
|
this.socket = socket;
|
|
24
42
|
this.req = req;
|
|
@@ -118,7 +136,6 @@ class Controller {
|
|
|
118
136
|
if (!req || !res) {
|
|
119
137
|
throw new Error(`req or res not found`);
|
|
120
138
|
}
|
|
121
|
-
// Bun native Response döndür
|
|
122
139
|
const responseData = context({
|
|
123
140
|
localeLanguageConverter: req.t
|
|
124
141
|
});
|
|
@@ -207,12 +224,13 @@ class Controller {
|
|
|
207
224
|
}
|
|
208
225
|
}
|
|
209
226
|
class ControllerSchema extends Controller {
|
|
210
|
-
constructor({ protocol, socket, req, res }) {
|
|
227
|
+
constructor({ protocol, socket, req, res, ctx }) {
|
|
211
228
|
super({
|
|
212
229
|
protocol,
|
|
213
230
|
socket,
|
|
214
231
|
req,
|
|
215
|
-
res
|
|
232
|
+
res,
|
|
233
|
+
ctx
|
|
216
234
|
});
|
|
217
235
|
}
|
|
218
236
|
async schema({ checks, logic, response, }) {
|
|
@@ -13,7 +13,7 @@ export default class LoggerService {
|
|
|
13
13
|
private getConsoleFormat;
|
|
14
14
|
winston: CustomLogger;
|
|
15
15
|
constructor();
|
|
16
|
-
load: (config: any) => Promise<void>;
|
|
16
|
+
load: (config: Record<string, any>) => Promise<void>;
|
|
17
17
|
winstonLoader: ({ loadPath, loggerLevel }: {
|
|
18
18
|
loadPath: string;
|
|
19
19
|
loggerLevel: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import winston, { format } from 'winston';
|
|
2
2
|
import 'winston-daily-rotate-file';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import { Kafka, Partitioners } from 'kafkajs';
|
|
4
|
+
import { Kafka, Partitioners, logLevel } from 'kafkajs';
|
|
5
5
|
import { LoggerLayerEnum } from '../../utils';
|
|
6
6
|
const customLevels = {
|
|
7
7
|
critical: LoggerLayerEnum.CRITICAL, // 0
|
|
@@ -53,20 +53,29 @@ export default class LoggerService {
|
|
|
53
53
|
const rawBrokers = config?.kafkaBrokers;
|
|
54
54
|
const brokers = rawBrokers ? String(rawBrokers).split(',').map((b) => b.trim()) : [];
|
|
55
55
|
if (brokers.length > 0) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
56
|
+
const kafka = new Kafka({
|
|
57
|
+
clientId: this.serviceName,
|
|
58
|
+
brokers: brokers,
|
|
59
|
+
logLevel: logLevel.ERROR,
|
|
60
|
+
retry: {
|
|
61
|
+
initialRetryTime: 1000,
|
|
62
|
+
retries: 10,
|
|
63
|
+
maxRetryTime: 30000,
|
|
64
|
+
factor: 2
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
this.kafkaProducer = kafka.producer({ createPartitioner: Partitioners.LegacyPartitioner });
|
|
68
|
+
const connectWithRetry = async () => {
|
|
69
|
+
try {
|
|
70
|
+
await this.kafkaProducer.connect();
|
|
71
|
+
this.isKafkaReady = true;
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
this.isKafkaReady = false;
|
|
75
|
+
setTimeout(connectWithRetry, 5000);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
connectWithRetry();
|
|
70
79
|
}
|
|
71
80
|
};
|
|
72
81
|
winstonLoader = ({ loadPath, loggerLevel }) => {
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { ParsedQs } from 'qs';
|
|
2
2
|
import { ProtocolEnum, ResponseSchema } from '../../index';
|
|
3
|
+
export interface ElysiaContext {
|
|
4
|
+
request: Request;
|
|
5
|
+
body?: any;
|
|
6
|
+
params?: Record<string, string>;
|
|
7
|
+
query?: Record<string, any>;
|
|
8
|
+
headers?: Headers;
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}
|
|
3
11
|
export interface CustomRequest {
|
|
4
12
|
accounts?: any;
|
|
5
13
|
query: {
|
|
@@ -12,8 +20,10 @@ export interface CustomRequest {
|
|
|
12
20
|
} & ParsedQs;
|
|
13
21
|
url: string;
|
|
14
22
|
method: string;
|
|
15
|
-
headers:
|
|
23
|
+
headers: Record<string, string>;
|
|
16
24
|
body?: any;
|
|
25
|
+
params?: Record<string, string>;
|
|
26
|
+
t?: Function;
|
|
17
27
|
}
|
|
18
28
|
export interface CustomResponse {
|
|
19
29
|
status: (code: number) => CustomResponse;
|
|
@@ -63,12 +73,12 @@ declare abstract class Controller {
|
|
|
63
73
|
protected limit: string | null;
|
|
64
74
|
defaultLimitSize: number;
|
|
65
75
|
maxLimitSize: number;
|
|
66
|
-
|
|
67
|
-
constructor({ protocol, socket, req, res }: {
|
|
76
|
+
constructor({ protocol, socket, req, res, ctx }: {
|
|
68
77
|
protocol: ProtocolEnum;
|
|
69
78
|
socket?: any;
|
|
70
79
|
req?: CustomRequest;
|
|
71
80
|
res?: CustomResponse;
|
|
81
|
+
ctx?: any;
|
|
72
82
|
});
|
|
73
83
|
protected createResponse(data: any, statusCode?: number): Response;
|
|
74
84
|
protected payloadProtocolSwitch: ({ protocol, socket, req, res }: {
|
|
@@ -105,11 +115,12 @@ declare abstract class Controller {
|
|
|
105
115
|
protected getErrorMessage(error: unknown): string;
|
|
106
116
|
}
|
|
107
117
|
declare class ControllerSchema extends Controller {
|
|
108
|
-
constructor({ protocol, socket, req, res }: {
|
|
118
|
+
constructor({ protocol, socket, req, res, ctx }: {
|
|
109
119
|
protocol: ProtocolEnum;
|
|
110
120
|
socket?: any;
|
|
111
121
|
req?: CustomRequest;
|
|
112
122
|
res?: CustomResponse;
|
|
123
|
+
ctx?: any;
|
|
113
124
|
});
|
|
114
125
|
schema({ checks, logic, response, }: {
|
|
115
126
|
checks?: ({ payload, convertedPayload }: {
|
|
@@ -17,8 +17,26 @@ class Controller {
|
|
|
17
17
|
limit = null;
|
|
18
18
|
defaultLimitSize = 20;
|
|
19
19
|
maxLimitSize = 100;
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
constructor({ protocol, socket, req, res, ctx }) {
|
|
21
|
+
// Eğer ctx varsa, otomatik req/res'e çevir
|
|
22
|
+
if (ctx) {
|
|
23
|
+
req = {
|
|
24
|
+
url: ctx.request.url,
|
|
25
|
+
method: ctx.request.method,
|
|
26
|
+
headers: Object.fromEntries(ctx.request.headers),
|
|
27
|
+
body: ctx.body,
|
|
28
|
+
params: ctx.params,
|
|
29
|
+
query: ctx.query,
|
|
30
|
+
accounts: ctx.accounts || ctx.user,
|
|
31
|
+
t: ctx.t
|
|
32
|
+
};
|
|
33
|
+
res = {
|
|
34
|
+
status: (code) => res,
|
|
35
|
+
send: (data) => data,
|
|
36
|
+
json: (data) => data,
|
|
37
|
+
locals: {}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
22
40
|
this.protocol = protocol;
|
|
23
41
|
this.socket = socket;
|
|
24
42
|
this.req = req;
|
|
@@ -118,7 +136,6 @@ class Controller {
|
|
|
118
136
|
if (!req || !res) {
|
|
119
137
|
throw new Error(`req or res not found`);
|
|
120
138
|
}
|
|
121
|
-
// Bun native Response döndür
|
|
122
139
|
const responseData = context({
|
|
123
140
|
localeLanguageConverter: req.t
|
|
124
141
|
});
|
|
@@ -207,12 +224,13 @@ class Controller {
|
|
|
207
224
|
}
|
|
208
225
|
}
|
|
209
226
|
class ControllerSchema extends Controller {
|
|
210
|
-
constructor({ protocol, socket, req, res }) {
|
|
227
|
+
constructor({ protocol, socket, req, res, ctx }) {
|
|
211
228
|
super({
|
|
212
229
|
protocol,
|
|
213
230
|
socket,
|
|
214
231
|
req,
|
|
215
|
-
res
|
|
232
|
+
res,
|
|
233
|
+
ctx
|
|
216
234
|
});
|
|
217
235
|
}
|
|
218
236
|
async schema({ checks, logic, response, }) {
|