@drunkcod/express-kit 0.0.15 → 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.
@@ -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, 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
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, ...rest };
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
48
  return { message: cause.toString(), ...cause };
40
49
  }
41
50
  function asLoggableError(error) {
42
51
  if (error instanceof Error)
43
52
  return asLoggableCause(error);
44
- const r = error && typeof error === 'object' ? asLoggableCause(error) : { message: error };
45
- Error.captureStackTrace(r, asLoggableError);
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.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, 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
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, ...rest };
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
43
  return { message: cause.toString(), ...cause };
35
44
  }
36
45
  export function asLoggableError(error) {
37
46
  if (error instanceof Error)
38
47
  return asLoggableCause(error);
39
- const r = error && typeof error === 'object' ? asLoggableCause(error) : { message: error };
40
- Error.captureStackTrace(r, asLoggableError);
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.15",
4
+ "version": "0.0.16",
5
5
  "description": "Express4 utility things",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/index.d.ts",