@xrystal/core 3.4.8 → 3.4.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.4.8",
4
+ "version": "3.4.9",
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",
@@ -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: 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
- private statusCode;
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
- statusCode = 200;
21
- constructor({ protocol, socket, req, res }) {
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, }) {
@@ -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: 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
- private statusCode;
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
- statusCode = 200;
21
- constructor({ protocol, socket, req, res }) {
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, }) {