@douglasneuroinformatics/libjs 2.7.0 → 2.8.1
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/exception.d.ts +6 -1
- package/dist/exception.d.ts.map +1 -1
- package/dist/exception.js +19 -3
- package/package.json +2 -1
package/dist/exception.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { serializeError } from 'serialize-error';
|
|
1
2
|
import type { IsNever, RequiredKeysOf } from 'type-fest';
|
|
2
3
|
import type { z } from 'zod';
|
|
3
4
|
import { Result, ResultAsync } from './vendor/neverthrow.js';
|
|
@@ -32,7 +33,11 @@ interface ExceptionLike extends Error, ExceptionOptions {
|
|
|
32
33
|
toErr(): Result<never, this>;
|
|
33
34
|
toString(): string;
|
|
34
35
|
}
|
|
36
|
+
declare function parseStack(stack: string | undefined): string[];
|
|
35
37
|
declare function parseStack(error: Error): string[];
|
|
38
|
+
declare function errorToJSON(error: Error, { includeStack }?: {
|
|
39
|
+
includeStack?: boolean;
|
|
40
|
+
}): string;
|
|
36
41
|
declare abstract class BaseException<TParams extends ExceptionParams, TOptions extends ExceptionOptions> extends Error implements ExceptionLike {
|
|
37
42
|
cause: TOptions['cause'];
|
|
38
43
|
details: TOptions['details'];
|
|
@@ -125,5 +130,5 @@ export declare const ValidationException: ExceptionType<{
|
|
|
125
130
|
[key: string]: unknown;
|
|
126
131
|
}>;
|
|
127
132
|
export type { ExceptionConstructor, ExceptionConstructorArgs, ExceptionLike, ExceptionName, ExceptionOptions, ExceptionParams, ExceptionStatic, ExceptionType };
|
|
128
|
-
export { BaseException, ExceptionBuilder, OutOfRangeException, parseStack, RuntimeException, ValueException };
|
|
133
|
+
export { BaseException, errorToJSON, ExceptionBuilder, OutOfRangeException, parseStack, RuntimeException, serializeError, ValueException };
|
|
129
134
|
//# sourceMappingURL=exception.d.ts.map
|
package/dist/exception.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exception.d.ts","sourceRoot":"","sources":["../src/exception.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"exception.d.ts","sourceRoot":"","sources":["../src/exception.ts"],"names":[],"mappings":"AAMA,OAAO,EAAe,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAI7B,OAAO,EAAiB,MAAM,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE5E,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEtE,KAAK,aAAa,GAAG,GAAG,MAAM,WAAW,CAAC;AAE1C,KAAK,gBAAgB,GAAG;IACtB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE;QACR,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;CACH,CAAC;AAEF,KAAK,eAAe,CAAC,QAAQ,GAAG,GAAG,IAAI;IACrC,OAAO,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,QAAQ,KAAK,MAAM,CAAC,GAAG,MAAM,CAAC;IACnD,IAAI,EAAE,aAAa,CAAC;CACrB,CAAC;AAEF,KAAK,wBAAwB,CAAC,OAAO,SAAS,eAAe,EAAE,QAAQ,SAAS,gBAAgB,IAC9F,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,SAAS,IAAI,GAC1C,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,GACtC,OAAO,SAAS;IAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,GAAG,KAAK,MAAM,CAAC,GAAG,MAAM,CAAA;CAAE,GAC9D,CAAC,QAAQ,CAAC,GACV,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAA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,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE;;EAQ9D,CAAC;AAEX,eAAO,MAAQ,mBAAmB;;;;aACL;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAA;KAAE;;;EAE1D,CAAC;AAEX,YAAY,EACV,oBAAoB,EACpB,wBAAwB,EACxB,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,aAAa,EACd,CAAC;AAEF,OAAO,EACL,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,cAAc,EACf,CAAC"}
|
package/dist/exception.js
CHANGED
|
@@ -3,12 +3,28 @@
|
|
|
3
3
|
/* eslint-disable no-dupe-class-members */
|
|
4
4
|
import cleanStack from 'clean-stack';
|
|
5
5
|
import extractStack from 'extract-stack';
|
|
6
|
+
import { isErrorLike, serializeError } from 'serialize-error';
|
|
6
7
|
import stringifyObject from 'stringify-object';
|
|
7
8
|
import { objectify } from './object.js';
|
|
8
9
|
import { indentLines } from './string.js';
|
|
9
10
|
import { err, errAsync, Result, ResultAsync } from './vendor/neverthrow.js';
|
|
10
|
-
function parseStack(
|
|
11
|
-
|
|
11
|
+
function parseStack(errorOrStack) {
|
|
12
|
+
const stack = typeof errorOrStack === 'string' ? errorOrStack : errorOrStack?.stack;
|
|
13
|
+
return extractStack.lines(cleanStack(stack, { pretty: true }));
|
|
14
|
+
}
|
|
15
|
+
function errorToJSON(error, { includeStack = true } = {}) {
|
|
16
|
+
const serialize = (error) => {
|
|
17
|
+
const { cause, stack, ...serialized } = serializeError(error);
|
|
18
|
+
const result = {
|
|
19
|
+
...serialized,
|
|
20
|
+
cause: isErrorLike(cause) ? serialize(cause) : cause
|
|
21
|
+
};
|
|
22
|
+
if (includeStack) {
|
|
23
|
+
result.stack = parseStack(stack);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
return JSON.stringify(serialize(error), null, 2);
|
|
12
28
|
}
|
|
13
29
|
class BaseException extends Error {
|
|
14
30
|
cause;
|
|
@@ -119,4 +135,4 @@ export const { ValidationException } = new ExceptionBuilder()
|
|
|
119
135
|
.setOptionsType()
|
|
120
136
|
.setParams({ message: 'Zod schema validation failed', name: 'ValidationException' })
|
|
121
137
|
.build();
|
|
122
|
-
export { BaseException, ExceptionBuilder, OutOfRangeException, parseStack, RuntimeException, ValueException };
|
|
138
|
+
export { BaseException, errorToJSON, ExceptionBuilder, OutOfRangeException, parseStack, RuntimeException, serializeError, ValueException };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@douglasneuroinformatics/libjs",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.8.1",
|
|
5
5
|
"packageManager": "pnpm@10.3.0",
|
|
6
6
|
"description": "A collection of utility functions and types for Node.js and the browser",
|
|
7
7
|
"author": "Joshua Unrau",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"clean-stack": "^5.2.0",
|
|
46
46
|
"extract-stack": "^3.0.0",
|
|
47
|
+
"serialize-error": "^12.0.0",
|
|
47
48
|
"stringify-object": "^5.0.0",
|
|
48
49
|
"type-fest": "^4.34.1"
|
|
49
50
|
},
|