@arkyn/server 3.0.1-beta.33 → 3.0.1-beta.35
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/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/services/getCaller.d.ts.map +1 -1
- package/dist/services/getCaller.js +9 -14
- package/dist/services/httpDebug.d.ts +40 -1
- package/dist/services/httpDebug.d.ts.map +1 -1
- package/dist/services/httpDebug.js +42 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/services/getCaller.ts +15 -16
- package/src/services/httpDebug.ts +44 -1
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,6 @@ export { errorHandler } from "./services/errorHandler";
|
|
|
20
20
|
export { formParse } from "./services/formParse";
|
|
21
21
|
export { getCaller } from "./services/getCaller";
|
|
22
22
|
export { getScopedParams } from "./services/getScopedParams";
|
|
23
|
-
export { httpDebug } from "./services/httpDebug";
|
|
23
|
+
export { httpDebug, HttpDebugService } from "./services/httpDebug";
|
|
24
24
|
export { SchemaValidator } from "./services/schemaValidator";
|
|
25
25
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAG7D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAG9E,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAG1D,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAG7D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAG9E,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAG1D,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -24,5 +24,5 @@ export { errorHandler } from "./services/errorHandler";
|
|
|
24
24
|
export { formParse } from "./services/formParse";
|
|
25
25
|
export { getCaller } from "./services/getCaller";
|
|
26
26
|
export { getScopedParams } from "./services/getScopedParams";
|
|
27
|
-
export { httpDebug } from "./services/httpDebug";
|
|
27
|
+
export { httpDebug, HttpDebugService } from "./services/httpDebug";
|
|
28
28
|
export { SchemaValidator } from "./services/schemaValidator";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCaller.d.ts","sourceRoot":"","sources":["../../src/services/getCaller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getCaller.d.ts","sourceRoot":"","sources":["../../src/services/getCaller.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AAEH,iBAAS,SAAS;;;EA+DjB;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
+
import { HttpDebugService } from "./httpDebug";
|
|
2
3
|
/**
|
|
3
4
|
* Retrieves information about the caller of the current function.
|
|
4
5
|
*
|
|
@@ -15,51 +16,45 @@ function getCaller() {
|
|
|
15
16
|
const err = new Error();
|
|
16
17
|
const stack = err.stack || "";
|
|
17
18
|
const stackLines = stack.split("\n").map((line) => line.trim());
|
|
18
|
-
|
|
19
|
-
// The second line is this function (getCaller)
|
|
20
|
-
// The third line should be the direct caller
|
|
21
|
-
// We start from 2 because indexes are zero-based
|
|
19
|
+
const ignoreFile = HttpDebugService.ignoreFile;
|
|
22
20
|
let callerIndex = 2;
|
|
23
|
-
// Ignore internal or infrastructure lines if necessary
|
|
24
21
|
while (callerIndex < stackLines.length &&
|
|
25
22
|
(stackLines[callerIndex].includes("node:internal") ||
|
|
26
23
|
stackLines[callerIndex].includes("/node_modules/"))) {
|
|
27
24
|
callerIndex++;
|
|
28
25
|
}
|
|
26
|
+
if (ignoreFile) {
|
|
27
|
+
while (callerIndex < stackLines.length &&
|
|
28
|
+
stackLines[callerIndex].includes(ignoreFile)) {
|
|
29
|
+
callerIndex++;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
29
32
|
const callerLine = stackLines[callerIndex] || "";
|
|
30
33
|
let functionName = "Unknown function";
|
|
31
34
|
let callerInfo = "Unknown caller";
|
|
32
|
-
// Default for named functions: "at functionName (file:line:column)"
|
|
33
35
|
const namedFunctionMatch = callerLine.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);
|
|
34
36
|
if (namedFunctionMatch) {
|
|
35
37
|
functionName = namedFunctionMatch[1];
|
|
36
38
|
callerInfo = namedFunctionMatch[2];
|
|
37
39
|
}
|
|
38
|
-
// Default for anonymous functions or methods: "at file:line:column"
|
|
39
40
|
else {
|
|
40
41
|
const anonymousFunctionMatch = callerLine.match(/at\s+(.+)/);
|
|
41
42
|
if (anonymousFunctionMatch) {
|
|
42
43
|
callerInfo = anonymousFunctionMatch[1];
|
|
43
|
-
// Tenta extrair nome da função de padrões como Object.method ou Class.method
|
|
44
44
|
const objectMethodMatch = callerInfo.match(/at\s+([^(\s]+)\s+/);
|
|
45
45
|
if (objectMethodMatch && objectMethodMatch[1] !== "new") {
|
|
46
46
|
functionName = objectMethodMatch[1];
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
// Handles file paths
|
|
51
50
|
if (callerInfo.includes("(")) {
|
|
52
51
|
callerInfo = callerInfo.substring(callerInfo.indexOf("(") + 1, callerInfo.lastIndexOf(")"));
|
|
53
52
|
}
|
|
54
|
-
// Remove the line:column part of the file path
|
|
55
53
|
callerInfo = callerInfo.split(":").slice(0, -2).join(":");
|
|
56
|
-
// Make the path relative to the project
|
|
57
54
|
try {
|
|
58
55
|
callerInfo = path.relative(projectRoot, callerInfo);
|
|
59
56
|
}
|
|
60
|
-
catch (e) {
|
|
61
|
-
// If it fails to relativize, use the original path
|
|
62
|
-
}
|
|
57
|
+
catch (e) { }
|
|
63
58
|
return { functionName, callerInfo };
|
|
64
59
|
}
|
|
65
60
|
export { getCaller };
|
|
@@ -1,3 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service for managing HTTP debug configuration and behavior.
|
|
3
|
+
*
|
|
4
|
+
* This service provides functionality to configure how the `getCaller` function
|
|
5
|
+
* identifies the actual caller in the stack trace by allowing specific files
|
|
6
|
+
* to be ignored during stack trace analysis.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Configure to ignore httpAdapter.ts in stack traces
|
|
11
|
+
* HttpDebugService.setIgnoreFile("httpAdapter.ts");
|
|
12
|
+
*
|
|
13
|
+
* // Now when httpDebug is called from within httpAdapter.ts,
|
|
14
|
+
* // it will show the actual caller (e.g., cart.ts) instead
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare class HttpDebugService {
|
|
18
|
+
/**
|
|
19
|
+
* The name of the file to ignore when analyzing the stack trace.
|
|
20
|
+
* When set, the `getCaller` function will skip stack frames containing this file name.
|
|
21
|
+
*/
|
|
22
|
+
static ignoreFile?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Sets the file name to be ignored during stack trace analysis.
|
|
25
|
+
*
|
|
26
|
+
* This method configures the debug service to skip specific files when
|
|
27
|
+
* determining the actual caller of a function. This is useful when you have
|
|
28
|
+
* adapter or wrapper functions that you want to be transparent in the debug output.
|
|
29
|
+
*
|
|
30
|
+
* @param file - The name of the file to ignore in stack traces (e.g., "httpAdapter.ts")
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Ignore the HTTP adapter file so debug shows the actual business logic caller
|
|
35
|
+
* HttpDebugService.setIgnoreFile("httpAdapter.ts");
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
static setIgnoreFile(file: string): void;
|
|
39
|
+
}
|
|
1
40
|
/**
|
|
2
41
|
* Logs debug information to the console when in development mode or when the
|
|
3
42
|
* `SHOW_ERRORS_IN_CONSOLE` environment variable is set to "true".
|
|
@@ -31,5 +70,5 @@
|
|
|
31
70
|
* ```
|
|
32
71
|
*/
|
|
33
72
|
declare function httpDebug(name: string, body: any, cause?: any): void;
|
|
34
|
-
export { httpDebug };
|
|
73
|
+
export { httpDebug, HttpDebugService };
|
|
35
74
|
//# sourceMappingURL=httpDebug.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpDebug.d.ts","sourceRoot":"","sources":["../../src/services/httpDebug.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,iBAAS,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,GAAG,QAuBtD;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"httpDebug.d.ts","sourceRoot":"","sources":["../../src/services/httpDebug.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,cAAM,gBAAgB;IACpB;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE3B;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM;CAGlC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,iBAAS,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,GAAG,QAuBtD;AAED,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -1,4 +1,45 @@
|
|
|
1
1
|
import { getCaller } from "../services/getCaller";
|
|
2
|
+
/**
|
|
3
|
+
* Service for managing HTTP debug configuration and behavior.
|
|
4
|
+
*
|
|
5
|
+
* This service provides functionality to configure how the `getCaller` function
|
|
6
|
+
* identifies the actual caller in the stack trace by allowing specific files
|
|
7
|
+
* to be ignored during stack trace analysis.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Configure to ignore httpAdapter.ts in stack traces
|
|
12
|
+
* HttpDebugService.setIgnoreFile("httpAdapter.ts");
|
|
13
|
+
*
|
|
14
|
+
* // Now when httpDebug is called from within httpAdapter.ts,
|
|
15
|
+
* // it will show the actual caller (e.g., cart.ts) instead
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
class HttpDebugService {
|
|
19
|
+
/**
|
|
20
|
+
* The name of the file to ignore when analyzing the stack trace.
|
|
21
|
+
* When set, the `getCaller` function will skip stack frames containing this file name.
|
|
22
|
+
*/
|
|
23
|
+
static ignoreFile;
|
|
24
|
+
/**
|
|
25
|
+
* Sets the file name to be ignored during stack trace analysis.
|
|
26
|
+
*
|
|
27
|
+
* This method configures the debug service to skip specific files when
|
|
28
|
+
* determining the actual caller of a function. This is useful when you have
|
|
29
|
+
* adapter or wrapper functions that you want to be transparent in the debug output.
|
|
30
|
+
*
|
|
31
|
+
* @param file - The name of the file to ignore in stack traces (e.g., "httpAdapter.ts")
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // Ignore the HTTP adapter file so debug shows the actual business logic caller
|
|
36
|
+
* HttpDebugService.setIgnoreFile("httpAdapter.ts");
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
static setIgnoreFile(file) {
|
|
40
|
+
this.ignoreFile = file;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
2
43
|
/**
|
|
3
44
|
* Logs debug information to the console when in development mode or when the
|
|
4
45
|
* `SHOW_ERRORS_IN_CONSOLE` environment variable is set to "true".
|
|
@@ -49,4 +90,4 @@ function httpDebug(name, body, cause) {
|
|
|
49
90
|
console.log(consoleData);
|
|
50
91
|
}
|
|
51
92
|
}
|
|
52
|
-
export { httpDebug };
|
|
93
|
+
export { httpDebug, HttpDebugService };
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -27,5 +27,5 @@ export { errorHandler } from "./services/errorHandler";
|
|
|
27
27
|
export { formParse } from "./services/formParse";
|
|
28
28
|
export { getCaller } from "./services/getCaller";
|
|
29
29
|
export { getScopedParams } from "./services/getScopedParams";
|
|
30
|
-
export { httpDebug } from "./services/httpDebug";
|
|
30
|
+
export { httpDebug, HttpDebugService } from "./services/httpDebug";
|
|
31
31
|
export { SchemaValidator } from "./services/schemaValidator";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
+
import { HttpDebugService } from "./httpDebug";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Retrieves information about the caller of the current function.
|
|
@@ -11,6 +12,7 @@ import path from "path";
|
|
|
11
12
|
* - `functionName`: The name of the function that called the current function, or "Unknown function" if it cannot be determined.
|
|
12
13
|
* - `callerInfo`: The file path of the caller relative to the project root, or "Unknown caller" if it cannot be determined.
|
|
13
14
|
*/
|
|
15
|
+
|
|
14
16
|
function getCaller() {
|
|
15
17
|
const projectRoot = process.cwd();
|
|
16
18
|
|
|
@@ -18,13 +20,10 @@ function getCaller() {
|
|
|
18
20
|
const stack = err.stack || "";
|
|
19
21
|
const stackLines = stack.split("\n").map((line) => line.trim());
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// The third line should be the direct caller
|
|
24
|
-
// We start from 2 because indexes are zero-based
|
|
23
|
+
const ignoreFile = HttpDebugService.ignoreFile;
|
|
24
|
+
|
|
25
25
|
let callerIndex = 2;
|
|
26
26
|
|
|
27
|
-
// Ignore internal or infrastructure lines if necessary
|
|
28
27
|
while (
|
|
29
28
|
callerIndex < stackLines.length &&
|
|
30
29
|
(stackLines[callerIndex].includes("node:internal") ||
|
|
@@ -33,24 +32,29 @@ function getCaller() {
|
|
|
33
32
|
callerIndex++;
|
|
34
33
|
}
|
|
35
34
|
|
|
35
|
+
if (ignoreFile) {
|
|
36
|
+
while (
|
|
37
|
+
callerIndex < stackLines.length &&
|
|
38
|
+
stackLines[callerIndex].includes(ignoreFile)
|
|
39
|
+
) {
|
|
40
|
+
callerIndex++;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
36
44
|
const callerLine = stackLines[callerIndex] || "";
|
|
37
45
|
|
|
38
46
|
let functionName = "Unknown function";
|
|
39
47
|
let callerInfo = "Unknown caller";
|
|
40
48
|
|
|
41
|
-
// Default for named functions: "at functionName (file:line:column)"
|
|
42
49
|
const namedFunctionMatch = callerLine.match(/at\s+([^(\s]+)\s+\(([^)]+)\)/);
|
|
43
50
|
if (namedFunctionMatch) {
|
|
44
51
|
functionName = namedFunctionMatch[1];
|
|
45
52
|
callerInfo = namedFunctionMatch[2];
|
|
46
|
-
}
|
|
47
|
-
// Default for anonymous functions or methods: "at file:line:column"
|
|
48
|
-
else {
|
|
53
|
+
} else {
|
|
49
54
|
const anonymousFunctionMatch = callerLine.match(/at\s+(.+)/);
|
|
50
55
|
if (anonymousFunctionMatch) {
|
|
51
56
|
callerInfo = anonymousFunctionMatch[1];
|
|
52
57
|
|
|
53
|
-
// Tenta extrair nome da função de padrões como Object.method ou Class.method
|
|
54
58
|
const objectMethodMatch = callerInfo.match(/at\s+([^(\s]+)\s+/);
|
|
55
59
|
if (objectMethodMatch && objectMethodMatch[1] !== "new") {
|
|
56
60
|
functionName = objectMethodMatch[1];
|
|
@@ -58,7 +62,6 @@ function getCaller() {
|
|
|
58
62
|
}
|
|
59
63
|
}
|
|
60
64
|
|
|
61
|
-
// Handles file paths
|
|
62
65
|
if (callerInfo.includes("(")) {
|
|
63
66
|
callerInfo = callerInfo.substring(
|
|
64
67
|
callerInfo.indexOf("(") + 1,
|
|
@@ -66,15 +69,11 @@ function getCaller() {
|
|
|
66
69
|
);
|
|
67
70
|
}
|
|
68
71
|
|
|
69
|
-
// Remove the line:column part of the file path
|
|
70
72
|
callerInfo = callerInfo.split(":").slice(0, -2).join(":");
|
|
71
73
|
|
|
72
|
-
// Make the path relative to the project
|
|
73
74
|
try {
|
|
74
75
|
callerInfo = path.relative(projectRoot, callerInfo);
|
|
75
|
-
} catch (e) {
|
|
76
|
-
// If it fails to relativize, use the original path
|
|
77
|
-
}
|
|
76
|
+
} catch (e) {}
|
|
78
77
|
|
|
79
78
|
return { functionName, callerInfo };
|
|
80
79
|
}
|
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
import { getCaller } from "../services/getCaller";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Service for managing HTTP debug configuration and behavior.
|
|
5
|
+
*
|
|
6
|
+
* This service provides functionality to configure how the `getCaller` function
|
|
7
|
+
* identifies the actual caller in the stack trace by allowing specific files
|
|
8
|
+
* to be ignored during stack trace analysis.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Configure to ignore httpAdapter.ts in stack traces
|
|
13
|
+
* HttpDebugService.setIgnoreFile("httpAdapter.ts");
|
|
14
|
+
*
|
|
15
|
+
* // Now when httpDebug is called from within httpAdapter.ts,
|
|
16
|
+
* // it will show the actual caller (e.g., cart.ts) instead
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
class HttpDebugService {
|
|
20
|
+
/**
|
|
21
|
+
* The name of the file to ignore when analyzing the stack trace.
|
|
22
|
+
* When set, the `getCaller` function will skip stack frames containing this file name.
|
|
23
|
+
*/
|
|
24
|
+
static ignoreFile?: string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Sets the file name to be ignored during stack trace analysis.
|
|
28
|
+
*
|
|
29
|
+
* This method configures the debug service to skip specific files when
|
|
30
|
+
* determining the actual caller of a function. This is useful when you have
|
|
31
|
+
* adapter or wrapper functions that you want to be transparent in the debug output.
|
|
32
|
+
*
|
|
33
|
+
* @param file - The name of the file to ignore in stack traces (e.g., "httpAdapter.ts")
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* // Ignore the HTTP adapter file so debug shows the actual business logic caller
|
|
38
|
+
* HttpDebugService.setIgnoreFile("httpAdapter.ts");
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
static setIgnoreFile(file: string) {
|
|
42
|
+
this.ignoreFile = file;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
3
46
|
/**
|
|
4
47
|
* Logs debug information to the console when in development mode or when the
|
|
5
48
|
* `SHOW_ERRORS_IN_CONSOLE` environment variable is set to "true".
|
|
@@ -58,4 +101,4 @@ function httpDebug(name: string, body: any, cause?: any) {
|
|
|
58
101
|
}
|
|
59
102
|
}
|
|
60
103
|
|
|
61
|
-
export { httpDebug };
|
|
104
|
+
export { httpDebug, HttpDebugService };
|