@drunkcod/express-kit 0.0.14 → 0.0.16
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 +7 -1
- package/lib/cjs/loggable.js +26 -12
- package/lib/loggable.d.ts +7 -1
- package/lib/loggable.js +26 -12
- package/package.json +2 -2
package/lib/cjs/loggable.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
export declare function at(message?: string): string;
|
|
2
|
-
|
|
2
|
+
type LoggableCause = {
|
|
3
|
+
message: unknown;
|
|
4
|
+
cause?: unknown;
|
|
5
|
+
stack?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function asLoggableError(error: unknown): LoggableCause;
|
|
3
8
|
export declare function hasOwnJSON(x: object): x is {
|
|
4
9
|
toJSON(): unknown;
|
|
5
10
|
};
|
|
11
|
+
export {};
|
package/lib/cjs/loggable.js
CHANGED
|
@@ -17,27 +17,41 @@ function at(message) {
|
|
|
17
17
|
Error.stackTraceLimit = old;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
+
function loggableStack(message, stopAt) {
|
|
21
|
+
const s = {};
|
|
22
|
+
Error.captureStackTrace(s, asLoggableError);
|
|
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
|
-
if (cause == null
|
|
22
|
-
return
|
|
30
|
+
if (cause == null)
|
|
31
|
+
return null;
|
|
32
|
+
if (typeof cause !== 'object')
|
|
33
|
+
return { message: cause };
|
|
23
34
|
if (hasOwnJSON(cause))
|
|
24
35
|
return asLoggableCause(cause.toJSON());
|
|
25
|
-
if (cause instanceof Error) {
|
|
36
|
+
if (cause instanceof Error || (0, argis_1.hasOwn)(cause, 'cause')) {
|
|
26
37
|
const { message, stack, cause: innerCause, ...rest } = cause;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
const r = { message };
|
|
39
|
+
if (innerCause) {
|
|
40
|
+
const loggableInner = asLoggableCause(innerCause);
|
|
41
|
+
r.cause = loggableInner;
|
|
42
|
+
r.message ??= loggableInner.message;
|
|
43
|
+
}
|
|
44
|
+
if (stack)
|
|
45
|
+
r.stack = stack;
|
|
46
|
+
return Object.assign(r, rest);
|
|
32
47
|
}
|
|
33
|
-
return { ...cause };
|
|
48
|
+
return { message: cause.toString(), ...cause };
|
|
34
49
|
}
|
|
35
50
|
function asLoggableError(error) {
|
|
36
51
|
if (error instanceof Error)
|
|
37
52
|
return asLoggableCause(error);
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
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 };
|
|
41
55
|
}
|
|
42
56
|
function hasOwnJSON(x) {
|
|
43
57
|
return 'toJSON' in x && typeof x.toJSON === 'function';
|
package/lib/loggable.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
export declare function at(message?: string): string;
|
|
2
|
-
|
|
2
|
+
type LoggableCause = {
|
|
3
|
+
message: unknown;
|
|
4
|
+
cause?: unknown;
|
|
5
|
+
stack?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function asLoggableError(error: unknown): LoggableCause;
|
|
3
8
|
export declare function hasOwnJSON(x: object): x is {
|
|
4
9
|
toJSON(): unknown;
|
|
5
10
|
};
|
|
11
|
+
export {};
|
package/lib/loggable.js
CHANGED
|
@@ -12,27 +12,41 @@ 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, asLoggableError);
|
|
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
|
-
if (cause == null
|
|
17
|
-
return
|
|
25
|
+
if (cause == null)
|
|
26
|
+
return null;
|
|
27
|
+
if (typeof cause !== 'object')
|
|
28
|
+
return { message: cause };
|
|
18
29
|
if (hasOwnJSON(cause))
|
|
19
30
|
return asLoggableCause(cause.toJSON());
|
|
20
|
-
if (cause instanceof Error) {
|
|
31
|
+
if (cause instanceof Error || hasOwn(cause, 'cause')) {
|
|
21
32
|
const { message, stack, cause: innerCause, ...rest } = cause;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
33
|
+
const r = { message };
|
|
34
|
+
if (innerCause) {
|
|
35
|
+
const loggableInner = asLoggableCause(innerCause);
|
|
36
|
+
r.cause = loggableInner;
|
|
37
|
+
r.message ??= loggableInner.message;
|
|
38
|
+
}
|
|
39
|
+
if (stack)
|
|
40
|
+
r.stack = stack;
|
|
41
|
+
return Object.assign(r, rest);
|
|
27
42
|
}
|
|
28
|
-
return { ...cause };
|
|
43
|
+
return { message: cause.toString(), ...cause };
|
|
29
44
|
}
|
|
30
45
|
export function asLoggableError(error) {
|
|
31
46
|
if (error instanceof Error)
|
|
32
47
|
return asLoggableCause(error);
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
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 };
|
|
36
50
|
}
|
|
37
51
|
export function hasOwnJSON(x) {
|
|
38
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.16",
|
|
5
5
|
"description": "Express4 utility things",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/index.d.ts",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"express-async"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@drunkcod/argis": "^0.0.
|
|
42
|
+
"@drunkcod/argis": "^0.0.11",
|
|
43
43
|
"@drunkcod/express-async": "^0.0.13"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|