@xrystal/core 3.26.0 → 3.26.2

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.26.0",
4
+ "version": "3.26.2",
5
5
  "description": "Project core for xrystal",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -30,6 +30,8 @@ export declare const controllerContextStorage: AsyncLocalStorage<{
30
30
  _statusCode?: number;
31
31
  _contentType?: string;
32
32
  _isRaw?: boolean;
33
+ _parsedBody?: any;
34
+ _parsedQuery?: any;
33
35
  };
34
36
  }>;
35
37
  export declare const getControllerCtx: () => {
@@ -43,6 +45,8 @@ export declare const getControllerCtx: () => {
43
45
  _statusCode?: number;
44
46
  _contentType?: string;
45
47
  _isRaw?: boolean;
48
+ _parsedBody?: any;
49
+ _parsedQuery?: any;
46
50
  };
47
51
  };
48
52
  export declare abstract class BaseController {
@@ -61,6 +65,8 @@ export declare abstract class BaseController {
61
65
  _statusCode?: number;
62
66
  _contentType?: string;
63
67
  _isRaw?: boolean;
68
+ _parsedBody?: any;
69
+ _parsedQuery?: any;
64
70
  };
65
71
  };
66
72
  protected get req(): CustomRequest;
@@ -20,13 +20,15 @@ export class BaseController {
20
20
  const ctx = store?.ctx || {};
21
21
  const req = store?.req || {};
22
22
  const identityT = (k) => k;
23
- const body = ctx.body || req.body || ctx.request?.body || {};
24
- let query = ctx.query || req.query || ctx.request?.query || {};
25
- const urlStr = ctx.url || req.url || ctx.request?.url || '';
26
- if ((!query || Object.keys(query).length === 0) && typeof urlStr === 'string' && urlStr.includes('?')) {
27
- const parts = urlStr.split('?');
28
- if (parts[1])
29
- query = qs.parse(parts[1]);
23
+ const body = store?.metadata?._parsedBody || ctx.body || req.body || ctx.request?.body || {};
24
+ let query = store?.metadata?._parsedQuery || ctx.query || req.query || ctx.request?.query || {};
25
+ const urlStr = ctx.request?.url || req.url || ctx.url || '';
26
+ if ((!query || Object.keys(query).length === 0) && urlStr && typeof urlStr === 'string') {
27
+ if (urlStr.includes('?')) {
28
+ const queryString = urlStr.split('?')[1];
29
+ if (queryString)
30
+ query = qs.parse(queryString);
31
+ }
30
32
  }
31
33
  const params = {
32
34
  ...(req.params || {}),
@@ -188,21 +190,11 @@ export default class Controller extends BaseController {
188
190
  if (parsedBody && typeof parsedBody === 'object' && parsedBody.constructor?.name === 'FormData') {
189
191
  parsedBody = Object.fromEntries(parsedBody.entries());
190
192
  }
191
- const finalBody = parsedBody || {};
192
- const finalQuery = parsedQuery || {};
193
193
  if (store) {
194
- if (store.ctx) {
195
- store.ctx.body = finalBody;
196
- store.ctx.query = finalQuery;
197
- }
198
- if (store.req) {
199
- store.req.body = finalBody;
200
- store.req.query = finalQuery;
201
- }
202
- if (store.ctx?.request) {
203
- store.ctx.request.body = finalBody;
204
- store.ctx.request.query = finalQuery;
205
- }
194
+ if (!store.metadata)
195
+ store.metadata = { locals: {} };
196
+ store.metadata._parsedBody = parsedBody || {};
197
+ store.metadata._parsedQuery = parsedQuery || {};
206
198
  }
207
199
  const currentReq = this.req;
208
200
  const p = { req: currentReq, res: currentRes, body: currentReq.body, query: currentReq.query, params: currentReq.params, t: currentReq.t, accounts: currentReq.accounts };