@xrystal/core 3.15.9 → 3.16.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.15.9",
4
+ "version": "3.16.2",
5
5
  "description": "Project core for xrystal",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -22,39 +22,32 @@ class Controller {
22
22
  const identityT = (k) => k;
23
23
  if (!store)
24
24
  return { url: '', method: '', headers: {}, params: {}, query: {}, t: identityT };
25
- const ctx = store.ctx;
26
- if (ctx) {
27
- const request = ctx.request || ctx.data?.request;
28
- return {
29
- url: request?.url || '',
30
- method: request?.method || '',
31
- headers: ctx.headers || {},
32
- body: ctx.body,
33
- params: ctx.params || {},
34
- query: ctx.query || {},
35
- accounts: ctx.user || ctx.data?.user || ctx.accounts,
36
- t: ctx.t || ctx.data?.t || identityT
37
- };
38
- }
39
- const req = store.req;
25
+ const { ctx, req: nativeReq } = store;
26
+ const reqSource = nativeReq?.url ? nativeReq : (ctx?.request?.url ? ctx.request : nativeReq);
40
27
  return {
41
- url: req?.originalUrl || req?.url || '',
42
- method: req?.method || 'GET',
43
- headers: req?.headers || {},
44
- body: req?.body,
45
- params: req?.params || {},
46
- query: req?.query || {},
47
- accounts: req?.accounts,
48
- t: req?.t || identityT
28
+ url: reqSource?.url || '',
29
+ method: reqSource?.method || 'GET',
30
+ headers: reqSource?.headers && typeof reqSource.headers.entries === 'function'
31
+ ? Object.fromEntries(reqSource.headers.entries())
32
+ : (ctx?.headers || nativeReq?.headers || {}),
33
+ body: ctx?.body || nativeReq?.body,
34
+ params: ctx?.params || nativeReq?.params || {},
35
+ query: ctx?.query || nativeReq?.query || {},
36
+ accounts: ctx?.user || ctx?.data?.user || nativeReq?.accounts,
37
+ t: ctx?.t || nativeReq?.t || identityT
49
38
  };
50
39
  }
51
40
  get res() {
52
41
  const store = this.currentStore;
53
42
  if (!store)
54
- return { status: () => { }, send: () => { }, json: () => { }, locals: {} };
43
+ return {
44
+ status: function () { return this; },
45
+ send: (data) => new Response(JSON.stringify(data), { status: 500, headers: { 'content-type': 'application/json' } }),
46
+ json: function (data) { return this.send(data); },
47
+ locals: {}
48
+ };
55
49
  const currentProtocol = this.protocol;
56
- if (store.ctx) {
57
- // Metadata'yı ALS üzerinden yönetiyoruz (Thread-safe)
50
+ if (store.ctx || store.req) {
58
51
  if (!store.metadata)
59
52
  store.metadata = { locals: {} };
60
53
  return {
@@ -84,8 +77,13 @@ class Controller {
84
77
  return res.status(resStatus).send(responseData);
85
78
  };
86
79
  parsedQuerys = (url) => {
87
- const queryString = url.includes('?') ? url.split('?')[1] : '';
88
- return queryString ? qs.parse(queryString, { decoder: decodeURIComponent }) : {};
80
+ try {
81
+ const queryString = url.includes('?') ? url.split('?')[1] : '';
82
+ return queryString ? qs.parse(queryString, { decoder: decodeURIComponent }) : {};
83
+ }
84
+ catch {
85
+ return {};
86
+ }
89
87
  };
90
88
  }
91
89
  export class ControllerService extends Controller {
@@ -97,6 +95,8 @@ export class ControllerService extends Controller {
97
95
  try {
98
96
  const currentReq = this.req;
99
97
  const currentRes = this.res;
98
+ if (!currentReq.url)
99
+ throw new Error("Request URL is missing from context");
100
100
  const payload = { req: currentReq, res: currentRes };
101
101
  const convertedPayload = { ...payload, parsedQuerys: this.parsedQuerys(currentReq.url) };
102
102
  if (checks) {