@drunkcod/express-kit 0.0.14 → 0.0.15

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.
@@ -1,5 +1,11 @@
1
1
  export declare function at(message?: string): string;
2
- export declare function asLoggableError(error: unknown): object;
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 {};
@@ -18,19 +18,25 @@ function at(message) {
18
18
  }
19
19
  }
20
20
  function asLoggableCause(cause) {
21
- if (cause == null || typeof cause !== 'object')
22
- return cause;
21
+ if (cause == null)
22
+ return null;
23
+ if (typeof cause !== 'object')
24
+ return { message: cause };
23
25
  if (hasOwnJSON(cause))
24
26
  return asLoggableCause(cause.toJSON());
25
- if (cause instanceof Error) {
27
+ if (cause instanceof Error || (0, argis_1.hasOwn)(cause, 'cause')) {
26
28
  const { message, stack, cause: innerCause, ...rest } = cause;
27
- return innerCause ? { message, stack, cause: asLoggableCause(innerCause), ...rest } : { message, stack, ...rest };
29
+ const r = { message, ...rest };
30
+ if (innerCause) {
31
+ const loggableInner = asLoggableCause(innerCause);
32
+ r.cause = loggableInner;
33
+ r.message ??= loggableInner.message;
34
+ }
35
+ if (stack)
36
+ r.stack = stack;
37
+ return r;
28
38
  }
29
- if ((0, argis_1.hasOwn)(cause, 'cause')) {
30
- const { cause: innerCause, ...rest } = cause;
31
- return { ...rest, cause: asLoggableCause(innerCause) };
32
- }
33
- return { ...cause };
39
+ return { message: cause.toString(), ...cause };
34
40
  }
35
41
  function asLoggableError(error) {
36
42
  if (error instanceof Error)
package/lib/loggable.d.ts CHANGED
@@ -1,5 +1,11 @@
1
1
  export declare function at(message?: string): string;
2
- export declare function asLoggableError(error: unknown): object;
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
@@ -13,19 +13,25 @@ export function at(message) {
13
13
  }
14
14
  }
15
15
  function asLoggableCause(cause) {
16
- if (cause == null || typeof cause !== 'object')
17
- return cause;
16
+ if (cause == null)
17
+ return null;
18
+ if (typeof cause !== 'object')
19
+ return { message: cause };
18
20
  if (hasOwnJSON(cause))
19
21
  return asLoggableCause(cause.toJSON());
20
- if (cause instanceof Error) {
22
+ if (cause instanceof Error || hasOwn(cause, 'cause')) {
21
23
  const { message, stack, cause: innerCause, ...rest } = cause;
22
- return innerCause ? { message, stack, cause: asLoggableCause(innerCause), ...rest } : { message, stack, ...rest };
24
+ const r = { message, ...rest };
25
+ if (innerCause) {
26
+ const loggableInner = asLoggableCause(innerCause);
27
+ r.cause = loggableInner;
28
+ r.message ??= loggableInner.message;
29
+ }
30
+ if (stack)
31
+ r.stack = stack;
32
+ return r;
23
33
  }
24
- if (hasOwn(cause, 'cause')) {
25
- const { cause: innerCause, ...rest } = cause;
26
- return { ...rest, cause: asLoggableCause(innerCause) };
27
- }
28
- return { ...cause };
34
+ return { message: cause.toString(), ...cause };
29
35
  }
30
36
  export function asLoggableError(error) {
31
37
  if (error instanceof Error)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@drunkcod/express-kit",
3
3
  "type": "module",
4
- "version": "0.0.14",
4
+ "version": "0.0.15",
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.7",
42
+ "@drunkcod/argis": "^0.0.11",
43
43
  "@drunkcod/express-async": "^0.0.13"
44
44
  },
45
45
  "devDependencies": {