@arkyn/server 3.0.1-beta.159 → 3.0.1-beta.166

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.
Files changed (47) hide show
  1. package/dist/index.js +1026 -1262
  2. package/dist/modules/http/api/_logRequest.js +55 -68
  3. package/dist/modules/http/api/_makeRequest.js +69 -68
  4. package/dist/modules/http/api/deleteRequest.js +12 -12
  5. package/dist/modules/http/api/getRequest.js +11 -11
  6. package/dist/modules/http/api/patchRequest.js +11 -11
  7. package/dist/modules/http/api/postRequest.js +11 -11
  8. package/dist/modules/http/api/putRequest.js +11 -11
  9. package/dist/modules/http/badResponses/_badResponse.js +62 -58
  10. package/dist/modules/http/badResponses/badGateway.js +22 -28
  11. package/dist/modules/http/badResponses/badRequest.js +22 -28
  12. package/dist/modules/http/badResponses/conflict.js +22 -28
  13. package/dist/modules/http/badResponses/forbidden.js +22 -28
  14. package/dist/modules/http/badResponses/notFound.js +22 -28
  15. package/dist/modules/http/badResponses/notImplemented.js +22 -28
  16. package/dist/modules/http/badResponses/serverError.js +22 -28
  17. package/dist/modules/http/badResponses/unauthorized.js +22 -28
  18. package/dist/modules/http/badResponses/unprocessableEntity.js +27 -35
  19. package/dist/modules/http/successResponses/_successResponse.js +61 -68
  20. package/dist/modules/http/successResponses/created.js +22 -28
  21. package/dist/modules/http/successResponses/found.js +22 -28
  22. package/dist/modules/http/successResponses/noContent.js +16 -20
  23. package/dist/modules/http/successResponses/success.js +22 -28
  24. package/dist/modules/http/successResponses/updated.js +22 -28
  25. package/dist/modules/index.js +33 -67
  26. package/dist/modules/services/apiService.js +108 -128
  27. package/dist/modules/services/debugService.js +35 -65
  28. package/dist/modules/services/logMapperService.js +28 -51
  29. package/dist/modules/services/logService.js +20 -30
  30. package/dist/modules/utilities/decodeRequestBody.js +19 -21
  31. package/dist/modules/utilities/decodeRequestErrorMessage.js +5 -6
  32. package/dist/modules/utilities/errorHandler.js +36 -51
  33. package/dist/modules/utilities/flushDebugLogs.js +15 -19
  34. package/dist/modules/utilities/formAsyncParse.js +13 -18
  35. package/dist/modules/utilities/formParse.js +13 -18
  36. package/dist/modules/utilities/getScopedParams.js +8 -10
  37. package/dist/modules/utilities/schemaValidator.js +53 -104
  38. package/dist/modules/validations/validateCep.js +8 -8
  39. package/dist/modules/validations/validateCnpj.js +49 -26
  40. package/dist/modules/validations/validateCpf.js +22 -23
  41. package/dist/modules/validations/validateDate.js +25 -26
  42. package/dist/modules/validations/validateEmail.js +54 -53
  43. package/dist/modules/validations/validatePassword.js +11 -15
  44. package/dist/modules/validations/validatePhone.js +8 -8
  45. package/dist/modules/validations/validateRg.js +7 -7
  46. package/generate-version.ts +74 -0
  47. package/package.json +17 -9
@@ -1,21 +1,17 @@
1
- import { SuccessResponse as s } from "./_successResponse.js";
2
- class o extends s {
3
- /**
4
- * @param message - Description included in the response status text.
5
- */
6
- constructor(t) {
7
- super(), this.name = "NoContent", this.status = 204, this.statusText = t, this.onDebug();
8
- }
9
- /** Converts to a `Response` with `Content-Type: application/json` header and no body. */
10
- toResponse() {
11
- const t = {
12
- headers: { "Content-Type": "application/json" },
13
- status: this.status,
14
- statusText: this.statusText
15
- };
16
- return new Response(null, t);
17
- }
18
- }
19
- export {
20
- o as NoContent
1
+ import { SuccessResponse as e } from "./_successResponse.js";
2
+ //#region src/http/successResponses/noContent.ts
3
+ var t = class extends e {
4
+ constructor(e) {
5
+ super(), this.name = "NoContent", this.status = 204, this.statusText = e, this.onDebug();
6
+ }
7
+ toResponse() {
8
+ let e = {
9
+ headers: { "Content-Type": "application/json" },
10
+ status: this.status,
11
+ statusText: this.statusText
12
+ };
13
+ return new Response(null, e);
14
+ }
21
15
  };
16
+ //#endregion
17
+ export { t as NoContent };
@@ -1,30 +1,24 @@
1
1
  import { SuccessResponse as e } from "./_successResponse.js";
2
- class i extends e {
3
- /**
4
- * @param message - Description included in the response status text.
5
- * @param body - Data to include in the response body.
6
- */
7
- constructor(s, t) {
8
- super(), this.name = "Success", this.status = 200, this.statusText = s, this.body = t || void 0, this.onDebug();
9
- }
10
- /** Converts to a `Response` with `Content-Type: application/json` header. */
11
- toResponse() {
12
- const s = {
13
- headers: { "Content-Type": "application/json" },
14
- status: this.status,
15
- statusText: this.statusText
16
- };
17
- return new Response(JSON.stringify(this.body), s);
18
- }
19
- /** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
20
- toJson() {
21
- const s = {
22
- status: this.status,
23
- statusText: this.statusText
24
- };
25
- return Response.json(this.body, s);
26
- }
27
- }
28
- export {
29
- i as Success
2
+ //#region src/http/successResponses/success.ts
3
+ var t = class extends e {
4
+ constructor(e, t) {
5
+ super(), this.name = "Success", this.status = 200, this.statusText = e, this.body = t || void 0, this.onDebug();
6
+ }
7
+ toResponse() {
8
+ let e = {
9
+ headers: { "Content-Type": "application/json" },
10
+ status: this.status,
11
+ statusText: this.statusText
12
+ };
13
+ return new Response(JSON.stringify(this.body), e);
14
+ }
15
+ toJson() {
16
+ let e = {
17
+ status: this.status,
18
+ statusText: this.statusText
19
+ };
20
+ return Response.json(this.body, e);
21
+ }
30
22
  };
23
+ //#endregion
24
+ export { t as Success };
@@ -1,30 +1,24 @@
1
1
  import { SuccessResponse as e } from "./_successResponse.js";
2
- class i extends e {
3
- /**
4
- * @param message - Description included in the response status text.
5
- * @param body - Data to include in the response body.
6
- */
7
- constructor(s, t) {
8
- super(), this.name = "Updated", this.status = 200, this.statusText = s, this.body = t || void 0, this.onDebug();
9
- }
10
- /** Converts to a `Response` with `Content-Type: application/json` header. */
11
- toResponse() {
12
- const s = {
13
- headers: { "Content-Type": "application/json" },
14
- status: this.status,
15
- statusText: this.statusText
16
- };
17
- return new Response(JSON.stringify(this.body), s);
18
- }
19
- /** Converts to a `Response` using `Response.json()`. Alternative to `toResponse()`. */
20
- toJson() {
21
- const s = {
22
- status: this.status,
23
- statusText: this.statusText
24
- };
25
- return Response.json(this.body, s);
26
- }
27
- }
28
- export {
29
- i as Updated
2
+ //#region src/http/successResponses/updated.ts
3
+ var t = class extends e {
4
+ constructor(e, t) {
5
+ super(), this.name = "Updated", this.status = 200, this.statusText = e, this.body = t || void 0, this.onDebug();
6
+ }
7
+ toResponse() {
8
+ let e = {
9
+ headers: { "Content-Type": "application/json" },
10
+ status: this.status,
11
+ statusText: this.statusText
12
+ };
13
+ return new Response(JSON.stringify(this.body), e);
14
+ }
15
+ toJson() {
16
+ let e = {
17
+ status: this.status,
18
+ statusText: this.statusText
19
+ };
20
+ return Response.json(this.body, e);
21
+ }
30
22
  };
23
+ //#endregion
24
+ export { t as Updated };
@@ -1,68 +1,34 @@
1
- import { BadGateway as e } from "./http/badResponses/badGateway.js";
2
- import { BadRequest as p } from "./http/badResponses/badRequest.js";
3
- import { Conflict as f } from "./http/badResponses/conflict.js";
4
- import { Forbidden as x } from "./http/badResponses/forbidden.js";
5
- import { NotFound as i } from "./http/badResponses/notFound.js";
6
- import { NotImplemented as l } from "./http/badResponses/notImplemented.js";
1
+ import { DebugService as e } from "./services/debugService.js";
2
+ import { flushDebugLogs as t } from "./utilities/flushDebugLogs.js";
3
+ import { BadGateway as n } from "./http/badResponses/badGateway.js";
4
+ import { BadRequest as r } from "./http/badResponses/badRequest.js";
5
+ import { Conflict as i } from "./http/badResponses/conflict.js";
6
+ import { Forbidden as a } from "./http/badResponses/forbidden.js";
7
+ import { NotFound as o } from "./http/badResponses/notFound.js";
8
+ import { NotImplemented as s } from "./http/badResponses/notImplemented.js";
7
9
  import { ServerError as c } from "./http/badResponses/serverError.js";
8
- import { Unauthorized as u } from "./http/badResponses/unauthorized.js";
9
- import { UnprocessableEntity as S } from "./http/badResponses/unprocessableEntity.js";
10
- import { Created as P } from "./http/successResponses/created.js";
11
- import { Found as h } from "./http/successResponses/found.js";
12
- import { NoContent as E } from "./http/successResponses/noContent.js";
13
- import { Success as q } from "./http/successResponses/success.js";
14
- import { Updated as D } from "./http/successResponses/updated.js";
15
- import { ApiService as N } from "./services/apiService.js";
16
- import { DebugService as w } from "./services/debugService.js";
17
- import { LogService as L } from "./services/logService.js";
18
- import { decodeRequestBody as z } from "./utilities/decodeRequestBody.js";
19
- import { decodeRequestErrorMessage as H } from "./utilities/decodeRequestErrorMessage.js";
20
- import { errorHandler as M } from "./utilities/errorHandler.js";
21
- import { flushDebugLogs as k } from "./utilities/flushDebugLogs.js";
22
- import { formAsyncParse as K } from "./utilities/formAsyncParse.js";
23
- import { formParse as Q } from "./utilities/formParse.js";
24
- import { getScopedParams as W } from "./utilities/getScopedParams.js";
25
- import { SchemaValidator as Y } from "./utilities/schemaValidator.js";
26
- import { validateCep as _ } from "./validations/validateCep.js";
27
- import { validateCnpj as rr } from "./validations/validateCnpj.js";
28
- import { validateCpf as er } from "./validations/validateCpf.js";
29
- import { validateDate as pr } from "./validations/validateDate.js";
30
- import { validateEmail as fr } from "./validations/validateEmail.js";
31
- import { validatePassword as xr } from "./validations/validatePassword.js";
32
- import { validatePhone as ir } from "./validations/validatePhone.js";
33
- import { validateRg as lr } from "./validations/validateRg.js";
34
- export {
35
- N as ApiService,
36
- e as BadGateway,
37
- p as BadRequest,
38
- f as Conflict,
39
- P as Created,
40
- w as DebugService,
41
- x as Forbidden,
42
- h as Found,
43
- L as LogService,
44
- E as NoContent,
45
- i as NotFound,
46
- l as NotImplemented,
47
- Y as SchemaValidator,
48
- c as ServerError,
49
- q as Success,
50
- u as Unauthorized,
51
- S as UnprocessableEntity,
52
- D as Updated,
53
- z as decodeRequestBody,
54
- H as decodeRequestErrorMessage,
55
- M as errorHandler,
56
- k as flushDebugLogs,
57
- K as formAsyncParse,
58
- Q as formParse,
59
- W as getScopedParams,
60
- _ as validateCep,
61
- rr as validateCnpj,
62
- er as validateCpf,
63
- pr as validateDate,
64
- fr as validateEmail,
65
- xr as validatePassword,
66
- ir as validatePhone,
67
- lr as validateRg
68
- };
10
+ import { Unauthorized as l } from "./http/badResponses/unauthorized.js";
11
+ import { UnprocessableEntity as u } from "./http/badResponses/unprocessableEntity.js";
12
+ import { Created as d } from "./http/successResponses/created.js";
13
+ import { Found as f } from "./http/successResponses/found.js";
14
+ import { NoContent as p } from "./http/successResponses/noContent.js";
15
+ import { Success as m } from "./http/successResponses/success.js";
16
+ import { Updated as h } from "./http/successResponses/updated.js";
17
+ import { LogService as g } from "./services/logService.js";
18
+ import { ApiService as _ } from "./services/apiService.js";
19
+ import { decodeRequestBody as v } from "./utilities/decodeRequestBody.js";
20
+ import { decodeRequestErrorMessage as y } from "./utilities/decodeRequestErrorMessage.js";
21
+ import { errorHandler as b } from "./utilities/errorHandler.js";
22
+ import { formAsyncParse as x } from "./utilities/formAsyncParse.js";
23
+ import { formParse as S } from "./utilities/formParse.js";
24
+ import { getScopedParams as C } from "./utilities/getScopedParams.js";
25
+ import { SchemaValidator as w } from "./utilities/schemaValidator.js";
26
+ import { validateCep as T } from "./validations/validateCep.js";
27
+ import { validateCnpj as E } from "./validations/validateCnpj.js";
28
+ import { validateCpf as D } from "./validations/validateCpf.js";
29
+ import { validateDate as O } from "./validations/validateDate.js";
30
+ import { validateEmail as k } from "./validations/validateEmail.js";
31
+ import { validatePassword as A } from "./validations/validatePassword.js";
32
+ import { validatePhone as j } from "./validations/validatePhone.js";
33
+ import { validateRg as M } from "./validations/validateRg.js";
34
+ export { _ as ApiService, n as BadGateway, r as BadRequest, i as Conflict, d as Created, e as DebugService, a as Forbidden, f as Found, g as LogService, p as NoContent, o as NotFound, s as NotImplemented, w as SchemaValidator, c as ServerError, m as Success, l as Unauthorized, u as UnprocessableEntity, h as Updated, v as decodeRequestBody, y as decodeRequestErrorMessage, b as errorHandler, t as flushDebugLogs, x as formAsyncParse, S as formParse, C as getScopedParams, T as validateCep, E as validateCnpj, D as validateCpf, O as validateDate, k as validateEmail, A as validatePassword, j as validatePhone, M as validateRg };
@@ -1,129 +1,109 @@
1
- var b = Object.defineProperty;
2
- var l = (n, s, e) => s in n ? b(n, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[s] = e;
3
- var h = (n, s, e) => l(n, typeof s != "symbol" ? s + "" : s, e);
4
- import { deleteRequest as g } from "../http/api/deleteRequest.js";
5
- import { getRequest as m } from "../http/api/getRequest.js";
6
- import { patchRequest as c } from "../http/api/patchRequest.js";
7
- import { postRequest as t } from "../http/api/postRequest.js";
8
- import { putRequest as p } from "../http/api/putRequest.js";
9
- import { flushDebugLogs as y } from "../utilities/flushDebugLogs.js";
10
- class w {
11
- constructor(s) {
12
- h(this, "baseUrl");
13
- h(this, "baseHeaders");
14
- h(this, "baseToken");
15
- h(this, "enableDebug");
16
- this.baseUrl = s.baseUrl, this.baseHeaders = s.baseHeaders || void 0, this.baseToken = s.baseToken || void 0, this.enableDebug = s.enableDebug || !1;
17
- }
18
- onDebug(s, e, r) {
19
- if (this.enableDebug) {
20
- const o = [], u = (i) => JSON.stringify(i, null, 2);
21
- o.push(`Base URL: ${this.baseUrl}`), o.push(`Endpoint: ${s}`), o.push(`Status/Method: ${e} => ${r.status}`), o.push(`Message: ${r.message}`), r.headers && o.push(`Headers: ${u(r.headers)}`), r.body && o.push(`Body: ${u(r.body)}`), y({ debugs: o, name: "ApiDebug", scheme: "yellow" });
22
- }
23
- }
24
- generateHeaders(s, e) {
25
- let r = {};
26
- return this.baseToken && (r = { Authorization: `Bearer ${this.baseToken}` }), this.baseHeaders && (r = { ...r, ...this.baseHeaders }), s && (r = { ...r, ...s }), e && (r = { ...r, Authorization: `Bearer ${e}` }), r;
27
- }
28
- /**
29
- * Sends a get request to the specified endpoint.
30
- * @param endpoint - The API endpoint to send the get request to.
31
- * @param data - The request data, including optional headers and token.
32
- * @returns The API response data.
33
- */
34
- async get(s, e) {
35
- const r = this.generateHeaders((e == null ? void 0 : e.headers) || {}, e == null ? void 0 : e.token), o = await m({
36
- url: this.baseUrl + s,
37
- urlParams: (e == null ? void 0 : e.urlParams) || {},
38
- headers: r
39
- });
40
- return this.onDebug(s, "get", {
41
- headers: r,
42
- message: o.message,
43
- status: o.status
44
- }), o;
45
- }
46
- /**
47
- * Sends a post request to the specified endpoint.
48
- * @param endpoint - The API endpoint to send the post request to.
49
- * @param data - The request data, including body, optional headers, and token.
50
- * @returns The API response data.
51
- */
52
- async post(s, e) {
53
- const r = this.generateHeaders((e == null ? void 0 : e.headers) || {}, e == null ? void 0 : e.token), o = e == null ? void 0 : e.body, u = await t({
54
- url: this.baseUrl + s,
55
- urlParams: (e == null ? void 0 : e.urlParams) || {},
56
- headers: r,
57
- body: o
58
- });
59
- return this.onDebug(s, "post", {
60
- headers: r,
61
- body: o,
62
- message: u.message,
63
- status: u.status
64
- }), u;
65
- }
66
- /**
67
- * Sends a put request to the specified endpoint.
68
- * @param endpoint - The API endpoint to send the put request to.
69
- * @param data - The request data, including body, optional headers, and token.
70
- * @returns The API response data.
71
- */
72
- async put(s, e) {
73
- const r = this.generateHeaders((e == null ? void 0 : e.headers) || {}, e == null ? void 0 : e.token), o = e == null ? void 0 : e.body, u = await p({
74
- url: this.baseUrl + s,
75
- urlParams: (e == null ? void 0 : e.urlParams) || {},
76
- headers: r,
77
- body: o
78
- });
79
- return this.onDebug(s, "put", {
80
- headers: r,
81
- body: o,
82
- message: u.message,
83
- status: u.status
84
- }), u;
85
- }
86
- /**
87
- * Sends a patch request to the specified endpoint.
88
- * @param endpoint - The API endpoint to send the patch request to.
89
- * @param data - The request data, including body, optional headers, and token.
90
- * @returns The API response data.
91
- */
92
- async patch(s, e) {
93
- const r = this.generateHeaders((e == null ? void 0 : e.headers) || {}, e == null ? void 0 : e.token), o = e == null ? void 0 : e.body, u = await c({
94
- url: this.baseUrl + s,
95
- urlParams: (e == null ? void 0 : e.urlParams) || {},
96
- headers: r,
97
- body: o
98
- });
99
- return this.onDebug(s, "patch", {
100
- headers: r,
101
- body: o,
102
- message: u.message,
103
- status: u.status
104
- }), u;
105
- }
106
- /**
107
- * Sends a delete request to the specified endpoint.
108
- * @param endpoint - The API endpoint to send the delete request to.
109
- * @param data - The request data, including body, optional headers, and token.
110
- * @returns The API response data.
111
- */
112
- async delete(s, e) {
113
- const r = this.generateHeaders((e == null ? void 0 : e.headers) || {}, e == null ? void 0 : e.token), o = e == null ? void 0 : e.body, u = await g({
114
- url: this.baseUrl + s,
115
- urlParams: (e == null ? void 0 : e.urlParams) || {},
116
- headers: r,
117
- body: o
118
- });
119
- return this.onDebug(s, "delete", {
120
- headers: r,
121
- body: o,
122
- message: u.message,
123
- status: u.status
124
- }), u;
125
- }
126
- }
127
- export {
128
- w as ApiService
1
+ import { flushDebugLogs as e } from "../utilities/flushDebugLogs.js";
2
+ import { deleteRequest as t } from "../http/api/deleteRequest.js";
3
+ import { getRequest as n } from "../http/api/getRequest.js";
4
+ import { patchRequest as r } from "../http/api/patchRequest.js";
5
+ import { postRequest as i } from "../http/api/postRequest.js";
6
+ import { putRequest as a } from "../http/api/putRequest.js";
7
+ //#region src/services/apiService.ts
8
+ var o = class {
9
+ baseUrl;
10
+ baseHeaders;
11
+ baseToken;
12
+ enableDebug;
13
+ constructor(e) {
14
+ this.baseUrl = e.baseUrl, this.baseHeaders = e.baseHeaders || void 0, this.baseToken = e.baseToken || void 0, this.enableDebug = e.enableDebug || !1;
15
+ }
16
+ onDebug(t, n, r) {
17
+ if (this.enableDebug) {
18
+ let i = [], a = (e) => JSON.stringify(e, null, 2);
19
+ i.push(`Base URL: ${this.baseUrl}`), i.push(`Endpoint: ${t}`), i.push(`Status/Method: ${n} => ${r.status}`), i.push(`Message: ${r.message}`), r.headers && i.push(`Headers: ${a(r.headers)}`), r.body && i.push(`Body: ${a(r.body)}`), e({
20
+ debugs: i,
21
+ name: "ApiDebug",
22
+ scheme: "yellow"
23
+ });
24
+ }
25
+ }
26
+ generateHeaders(e, t) {
27
+ let n = {};
28
+ return this.baseToken && (n = { Authorization: `Bearer ${this.baseToken}` }), this.baseHeaders && (n = {
29
+ ...n,
30
+ ...this.baseHeaders
31
+ }), e && (n = {
32
+ ...n,
33
+ ...e
34
+ }), t && (n = {
35
+ ...n,
36
+ Authorization: `Bearer ${t}`
37
+ }), n;
38
+ }
39
+ async get(e, t) {
40
+ let r = this.generateHeaders(t?.headers || {}, t?.token), i = await n({
41
+ url: this.baseUrl + e,
42
+ urlParams: t?.urlParams || {},
43
+ headers: r
44
+ });
45
+ return this.onDebug(e, "get", {
46
+ headers: r,
47
+ message: i.message,
48
+ status: i.status
49
+ }), i;
50
+ }
51
+ async post(e, t) {
52
+ let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, a = await i({
53
+ url: this.baseUrl + e,
54
+ urlParams: t?.urlParams || {},
55
+ headers: n,
56
+ body: r
57
+ });
58
+ return this.onDebug(e, "post", {
59
+ headers: n,
60
+ body: r,
61
+ message: a.message,
62
+ status: a.status
63
+ }), a;
64
+ }
65
+ async put(e, t) {
66
+ let n = this.generateHeaders(t?.headers || {}, t?.token), r = t?.body, i = await a({
67
+ url: this.baseUrl + e,
68
+ urlParams: t?.urlParams || {},
69
+ headers: n,
70
+ body: r
71
+ });
72
+ return this.onDebug(e, "put", {
73
+ headers: n,
74
+ body: r,
75
+ message: i.message,
76
+ status: i.status
77
+ }), i;
78
+ }
79
+ async patch(e, t) {
80
+ let n = this.generateHeaders(t?.headers || {}, t?.token), i = t?.body, a = await r({
81
+ url: this.baseUrl + e,
82
+ urlParams: t?.urlParams || {},
83
+ headers: n,
84
+ body: i
85
+ });
86
+ return this.onDebug(e, "patch", {
87
+ headers: n,
88
+ body: i,
89
+ message: a.message,
90
+ status: a.status
91
+ }), a;
92
+ }
93
+ async delete(e, n) {
94
+ let r = this.generateHeaders(n?.headers || {}, n?.token), i = n?.body, a = await t({
95
+ url: this.baseUrl + e,
96
+ urlParams: n?.urlParams || {},
97
+ headers: r,
98
+ body: i
99
+ });
100
+ return this.onDebug(e, "delete", {
101
+ headers: r,
102
+ body: i,
103
+ message: a.message,
104
+ status: a.status
105
+ }), a;
106
+ }
129
107
  };
108
+ //#endregion
109
+ export { o as ApiService };
@@ -1,66 +1,36 @@
1
- var u = Object.defineProperty;
2
- var g = (i, t, l) => t in i ? u(i, t, { enumerable: !0, configurable: !0, writable: !0, value: l }) : i[t] = l;
3
- var d = (i, t, l) => g(i, typeof t != "symbol" ? t + "" : t, l);
4
- import m from "node:path";
5
- class f {
6
- /**
7
- * Adds a file name to the ignore list so it is skipped when resolving the caller in stack traces.
8
- *
9
- * @param file - File name to ignore (e.g. `"httpAdapter.ts"`).
10
- */
11
- static setIgnoreFile(t) {
12
- this.ignoreFiles.push(t);
13
- }
14
- /** Resets the ignore list, restoring full stack trace analysis. */
15
- static clearIgnoreFiles() {
16
- this.ignoreFiles = [];
17
- }
18
- /**
19
- * Resolves the file path and function name of the code that triggered the current debug call,
20
- * skipping internal node modules and any files registered with `setIgnoreFile`.
21
- *
22
- * @returns `{ functionName, callerInfo }` caller function name and file path relative to `process.cwd()`.
23
- */
24
- static getCaller() {
25
- const t = process.cwd(), c = (new Error().stack || "").split(`
26
- `).map((s) => s.trim());
27
- let n = 2;
28
- for (; n < c.length && (c[n].includes("node:internal") || c[n].includes("/node_modules/")); )
29
- n++;
30
- if (this.ignoreFiles.length > 0)
31
- for (; n < c.length && this.ignoreFiles.some(
32
- (s) => c[n].includes(s)
33
- ); )
34
- n++;
35
- const h = c[n] || "";
36
- let o = "Unknown function", e = "Unknown caller";
37
- const a = h.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);
38
- if (a)
39
- o = a[1], e = a[2];
40
- else {
41
- const s = h.match(/at\s+(.+)/);
42
- if (s) {
43
- e = s[1];
44
- const r = e.match(/at\s+([^(\s]+)\s+/);
45
- r && r[1] !== "new" && (o = r[1]);
46
- }
47
- }
48
- e.includes("(") && (e = e.substring(
49
- e.indexOf("(") + 1,
50
- e.lastIndexOf(")")
51
- )), e = e.split(":").slice(0, -2).join(":");
52
- try {
53
- e = m.relative(t, e);
54
- } catch {
55
- }
56
- return { functionName: o, callerInfo: e };
57
- }
58
- }
59
- /**
60
- * The name of the file to ignore when analyzing the stack trace.
61
- * When set, the `getCaller` function will skip stack frames containing this file name.
62
- */
63
- d(f, "ignoreFiles", []);
64
- export {
65
- f as DebugService
1
+ import e from "node:path";
2
+ //#region src/services/debugService.ts
3
+ var t = class {
4
+ static ignoreFiles = [];
5
+ static setIgnoreFile(e) {
6
+ this.ignoreFiles.push(e);
7
+ }
8
+ static clearIgnoreFiles() {
9
+ this.ignoreFiles = [];
10
+ }
11
+ static getCaller() {
12
+ let t = process.cwd(), n = ((/* @__PURE__ */ Error()).stack || "").split("\n").map((e) => e.trim()), r = 2;
13
+ for (; r < n.length && (n[r].includes("node:internal") || n[r].includes("/node_modules/"));) r++;
14
+ if (this.ignoreFiles.length > 0) for (; r < n.length && this.ignoreFiles.some((e) => n[r].includes(e));) r++;
15
+ let i = n[r] || "", a = "Unknown function", o = "Unknown caller", s = i.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);
16
+ if (s) a = s[1], o = s[2];
17
+ else {
18
+ let e = i.match(/at\s+(.+)/);
19
+ if (e) {
20
+ o = e[1];
21
+ let t = o.match(/at\s+([^(\s]+)\s+/);
22
+ t && t[1] !== "new" && (a = t[1]);
23
+ }
24
+ }
25
+ o.includes("(") && (o = o.substring(o.indexOf("(") + 1, o.lastIndexOf(")"))), o = o.split(":").slice(0, -2).join(":");
26
+ try {
27
+ o = e.relative(t, o);
28
+ } catch {}
29
+ return {
30
+ functionName: a,
31
+ callerInfo: o
32
+ };
33
+ }
66
34
  };
35
+ //#endregion
36
+ export { t as DebugService };