@drunkcod/express-kit 0.0.15 → 0.0.17
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/lib/cjs/loggable.d.ts +1 -1
- package/lib/cjs/loggable.js +14 -6
- package/lib/loggable.d.ts +1 -1
- package/lib/loggable.js +14 -6
- package/package.json +5 -5
package/lib/cjs/loggable.d.ts
CHANGED
package/lib/cjs/loggable.js
CHANGED
|
@@ -17,6 +17,15 @@ function at(message) {
|
|
|
17
17
|
Error.stackTraceLimit = old;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
+
function loggableStack(message, stopAt) {
|
|
21
|
+
const s = {};
|
|
22
|
+
Error.captureStackTrace(s, stopAt);
|
|
23
|
+
if (message)
|
|
24
|
+
message = `: ${message}`;
|
|
25
|
+
else
|
|
26
|
+
message = '';
|
|
27
|
+
return `LoggableError${message}\n` + s.stack?.substring(6);
|
|
28
|
+
}
|
|
20
29
|
function asLoggableCause(cause) {
|
|
21
30
|
if (cause == null)
|
|
22
31
|
return null;
|
|
@@ -26,7 +35,7 @@ function asLoggableCause(cause) {
|
|
|
26
35
|
return asLoggableCause(cause.toJSON());
|
|
27
36
|
if (cause instanceof Error || (0, argis_1.hasOwn)(cause, 'cause')) {
|
|
28
37
|
const { message, stack, cause: innerCause, ...rest } = cause;
|
|
29
|
-
const r = { message
|
|
38
|
+
const r = { message };
|
|
30
39
|
if (innerCause) {
|
|
31
40
|
const loggableInner = asLoggableCause(innerCause);
|
|
32
41
|
r.cause = loggableInner;
|
|
@@ -34,16 +43,15 @@ function asLoggableCause(cause) {
|
|
|
34
43
|
}
|
|
35
44
|
if (stack)
|
|
36
45
|
r.stack = stack;
|
|
37
|
-
return r;
|
|
46
|
+
return Object.assign(r, rest);
|
|
38
47
|
}
|
|
39
|
-
return
|
|
48
|
+
return cause;
|
|
40
49
|
}
|
|
41
50
|
function asLoggableError(error) {
|
|
42
51
|
if (error instanceof Error)
|
|
43
52
|
return asLoggableCause(error);
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
return Object.defineProperty(r, 'stack', { enumerable: true });
|
|
53
|
+
const { message, ...rest } = error && typeof error === 'object' ? asLoggableCause(error) : { message: error };
|
|
54
|
+
return { message, stack: loggableStack(message?.toString(), asLoggableError), ...rest };
|
|
47
55
|
}
|
|
48
56
|
function hasOwnJSON(x) {
|
|
49
57
|
return 'toJSON' in x && typeof x.toJSON === 'function';
|
package/lib/loggable.d.ts
CHANGED
package/lib/loggable.js
CHANGED
|
@@ -12,6 +12,15 @@ export function at(message) {
|
|
|
12
12
|
Error.stackTraceLimit = old;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
+
function loggableStack(message, stopAt) {
|
|
16
|
+
const s = {};
|
|
17
|
+
Error.captureStackTrace(s, stopAt);
|
|
18
|
+
if (message)
|
|
19
|
+
message = `: ${message}`;
|
|
20
|
+
else
|
|
21
|
+
message = '';
|
|
22
|
+
return `LoggableError${message}\n` + s.stack?.substring(6);
|
|
23
|
+
}
|
|
15
24
|
function asLoggableCause(cause) {
|
|
16
25
|
if (cause == null)
|
|
17
26
|
return null;
|
|
@@ -21,7 +30,7 @@ function asLoggableCause(cause) {
|
|
|
21
30
|
return asLoggableCause(cause.toJSON());
|
|
22
31
|
if (cause instanceof Error || hasOwn(cause, 'cause')) {
|
|
23
32
|
const { message, stack, cause: innerCause, ...rest } = cause;
|
|
24
|
-
const r = { message
|
|
33
|
+
const r = { message };
|
|
25
34
|
if (innerCause) {
|
|
26
35
|
const loggableInner = asLoggableCause(innerCause);
|
|
27
36
|
r.cause = loggableInner;
|
|
@@ -29,16 +38,15 @@ function asLoggableCause(cause) {
|
|
|
29
38
|
}
|
|
30
39
|
if (stack)
|
|
31
40
|
r.stack = stack;
|
|
32
|
-
return r;
|
|
41
|
+
return Object.assign(r, rest);
|
|
33
42
|
}
|
|
34
|
-
return
|
|
43
|
+
return cause;
|
|
35
44
|
}
|
|
36
45
|
export function asLoggableError(error) {
|
|
37
46
|
if (error instanceof Error)
|
|
38
47
|
return asLoggableCause(error);
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
return Object.defineProperty(r, 'stack', { enumerable: true });
|
|
48
|
+
const { message, ...rest } = error && typeof error === 'object' ? asLoggableCause(error) : { message: error };
|
|
49
|
+
return { message, stack: loggableStack(message?.toString(), asLoggableError), ...rest };
|
|
42
50
|
}
|
|
43
51
|
export function hasOwnJSON(x) {
|
|
44
52
|
return 'toJSON' in x && typeof x.toJSON === 'function';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drunkcod/express-kit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.17",
|
|
5
5
|
"description": "Express4 utility things",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
@@ -40,16 +40,16 @@
|
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@drunkcod/argis": "^0.0.11",
|
|
43
|
-
"@drunkcod/express-async": "^0.0.
|
|
43
|
+
"@drunkcod/express-async": "^0.0.17"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@drunkcod/ts-jest-esm": "^0.0.1",
|
|
47
47
|
"@jest/globals": "^29.7.0",
|
|
48
|
-
"@types/node": "^22.
|
|
48
|
+
"@types/node": "^22.13.10",
|
|
49
49
|
"jest": "^29.7.0",
|
|
50
50
|
"npm-run-all": "^4.1.5",
|
|
51
51
|
"rimraf": "^6.0.1",
|
|
52
|
-
"ts-jest": "^29.2.
|
|
53
|
-
"typescript": "^5.
|
|
52
|
+
"ts-jest": "^29.2.6",
|
|
53
|
+
"typescript": "^5.8.2"
|
|
54
54
|
}
|
|
55
55
|
}
|