@arkyn/server 2.0.1-beta.4 → 2.0.1-beta.5

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkyn/server",
3
- "version": "2.0.1-beta.4",
3
+ "version": "2.0.1-beta.5",
4
4
  "main": "./dist/bundle.js",
5
5
  "module": "./src/index.ts",
6
6
  "type": "module",
@@ -1,3 +1,5 @@
1
+ import { getCaller } from "../services/getCaller";
2
+
1
3
  function httpDebug(name: string, body: any, cause?: any) {
2
4
  const isDebugMode =
3
5
  process.env.NODE_ENV === "development" ||
@@ -8,29 +10,7 @@ function httpDebug(name: string, body: any, cause?: any) {
8
10
  const cyan = "\x1b[36m";
9
11
 
10
12
  const debugName = `${cyan}[ARKYN-DEBUG]${reset}`;
11
-
12
- const error = new Error();
13
- const stackLines =
14
- error.stack?.split("\n").map((line) => line.trim()) || [];
15
-
16
- let callerInfo = "Unknown caller";
17
- let functionName = "Unknown function";
18
-
19
- for (const line of stackLines) {
20
- if (
21
- !line.includes("httpDebug") &&
22
- !line.includes("BadGateway") &&
23
- !line.includes("BadRequest")
24
- ) {
25
- // Captura formatos diferentes de stack trace
26
- const match = line.match(/at (.+?) \((.+?)\)/) || line.match(/at (.+)/);
27
- if (match) {
28
- functionName = match[1].split(" ")[0]; // Pega apenas o nome da função
29
- callerInfo = match[2] || match[1]; // Caminho do arquivo e linha
30
- break;
31
- }
32
- }
33
- }
13
+ const { callerInfo, functionName } = getCaller();
34
14
 
35
15
  console.log(`${debugName} ${name} initialized`);
36
16
  console.log(`${debugName} Caller Function: ${functionName}`);
@@ -0,0 +1,40 @@
1
+ import path from "path";
2
+
3
+ function getCaller() {
4
+ // Diretório raiz do projeto
5
+ const projectRoot = process.cwd();
6
+
7
+ // Captura a stack trace
8
+ const error = new Error();
9
+ const stackLines = error.stack?.split("\n").map((line) => line.trim()) || [];
10
+
11
+ let callerInfo = "Unknown caller";
12
+ let functionName = "Unknown function";
13
+
14
+ for (const line of stackLines) {
15
+ if (
16
+ !line.includes("httpDebug") &&
17
+ !line.includes("BadGateway") &&
18
+ !line.includes("BadRequest")
19
+ ) {
20
+ // Captura formatos diferentes de stack trace
21
+ const match = line.match(/at (.+?) \((.+?)\)/) || line.match(/at (.+)/);
22
+ if (match) {
23
+ functionName = match[1].split(" ")[0]; // Nome da função
24
+ let fullPath = match[2] || match[1]; // Caminho absoluto do arquivo
25
+
26
+ // Transforma caminho absoluto em relativo ao projeto
27
+ if (fullPath.startsWith(projectRoot)) {
28
+ fullPath = path.relative(projectRoot, fullPath);
29
+ }
30
+
31
+ callerInfo = fullPath;
32
+ break;
33
+ }
34
+ }
35
+ }
36
+
37
+ return { functionName, callerInfo };
38
+ }
39
+
40
+ export { getCaller };