@naturalcycles/js-lib 14.133.0 → 14.133.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.
@@ -14,5 +14,5 @@ export declare class AppError<DATA_TYPE extends ErrorData = ErrorData> extends E
14
14
  * cause here is normalized to be instance of Error
15
15
  */
16
16
  cause?: Error;
17
- constructor(message: string, data?: DATA_TYPE, opt?: ErrorOptions);
17
+ constructor(message: string, data?: DATA_TYPE, opt?: ErrorOptions, name?: string);
18
18
  }
@@ -11,11 +11,18 @@ exports.AppError = void 0;
11
11
  * Based on: https://medium.com/@xpl/javascript-deriving-from-error-properly-8d2f8f315801
12
12
  */
13
13
  class AppError extends Error {
14
- constructor(message, data = {}, opt) {
14
+ constructor(message, data = {}, opt, name) {
15
15
  super(message);
16
16
  Object.defineProperty(this, 'name', {
17
- value: this.constructor.name,
17
+ value: name || this.constructor.name,
18
18
  configurable: true,
19
+ writable: true,
20
+ });
21
+ // this is to allow changing this.constuctor.name to a non-minified version
22
+ Object.defineProperty(this.constructor, 'name', {
23
+ value: name || this.constructor.name,
24
+ configurable: true,
25
+ writable: true,
19
26
  });
20
27
  Object.defineProperty(this, 'data', {
21
28
  value: data,
@@ -36,4 +36,5 @@ export declare function _assertIsString(v: any, message?: string): asserts v is
36
36
  export declare function _assertIsNumber(v: any, message?: string): asserts v is number;
37
37
  export declare function _assertTypeOf<T>(v: any, expectedType: string, message?: string): asserts v is T;
38
38
  export declare class AssertionError extends AppError {
39
+ constructor(message: string, data?: {}, opt?: ErrorOptions);
39
40
  }
@@ -103,5 +103,8 @@ function _assertTypeOf(v, expectedType, message) {
103
103
  }
104
104
  exports._assertTypeOf = _assertTypeOf;
105
105
  class AssertionError extends app_error_1.AppError {
106
+ constructor(message, data = {}, opt) {
107
+ super(message, data, opt, 'AssertionError');
108
+ }
106
109
  }
107
110
  exports.AssertionError = AssertionError;
@@ -88,6 +88,12 @@ function _errorObjectToError(o, errorClass = Error) {
88
88
  Object.defineProperty(err, 'name', {
89
89
  value: o.name,
90
90
  configurable: true,
91
+ writable: true,
92
+ });
93
+ Object.defineProperty(err.constructor, 'name', {
94
+ value: o.name,
95
+ configurable: true,
96
+ writable: true,
91
97
  });
92
98
  Object.defineProperty(err, 'data', {
93
99
  value: o.data,
@@ -7,7 +7,7 @@ const app_error_1 = require("./app.error");
7
7
  */
8
8
  class HttpError extends app_error_1.AppError {
9
9
  constructor(message, data, opt) {
10
- super(message, data, opt);
10
+ super(message, data, opt, 'HttpError');
11
11
  }
12
12
  }
13
13
  exports.HttpError = HttpError;
@@ -2,6 +2,7 @@ import { AppError } from '../error/app.error';
2
2
  import type { ErrorData } from '../error/error.model';
3
3
  import type { AnyAsyncFunction } from '../types';
4
4
  export declare class TimeoutError extends AppError {
5
+ constructor(message: string, data?: {}, opt?: ErrorOptions);
5
6
  }
6
7
  export interface PTimeoutOptions {
7
8
  /**
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pTimeout = exports.pTimeoutFn = exports.TimeoutError = void 0;
4
4
  const app_error_1 = require("../error/app.error");
5
5
  class TimeoutError extends app_error_1.AppError {
6
+ constructor(message, data = {}, opt) {
7
+ super(message, data, opt, 'TimeoutError');
8
+ }
6
9
  }
7
10
  exports.TimeoutError = TimeoutError;
8
11
  /**
@@ -8,11 +8,18 @@
8
8
  * Based on: https://medium.com/@xpl/javascript-deriving-from-error-properly-8d2f8f315801
9
9
  */
10
10
  export class AppError extends Error {
11
- constructor(message, data = {}, opt) {
11
+ constructor(message, data = {}, opt, name) {
12
12
  super(message);
13
13
  Object.defineProperty(this, 'name', {
14
- value: this.constructor.name,
14
+ value: name || this.constructor.name,
15
15
  configurable: true,
16
+ writable: true,
17
+ });
18
+ // this is to allow changing this.constuctor.name to a non-minified version
19
+ Object.defineProperty(this.constructor, 'name', {
20
+ value: name || this.constructor.name,
21
+ configurable: true,
22
+ writable: true,
16
23
  });
17
24
  Object.defineProperty(this, 'data', {
18
25
  value: data,
@@ -84,4 +84,7 @@ export function _assertTypeOf(v, expectedType, message) {
84
84
  }
85
85
  }
86
86
  export class AssertionError extends AppError {
87
+ constructor(message, data = {}, opt) {
88
+ super(message, data, opt, 'AssertionError');
89
+ }
87
90
  }
@@ -79,6 +79,12 @@ export function _errorObjectToError(o, errorClass = Error) {
79
79
  Object.defineProperty(err, 'name', {
80
80
  value: o.name,
81
81
  configurable: true,
82
+ writable: true,
83
+ });
84
+ Object.defineProperty(err.constructor, 'name', {
85
+ value: o.name,
86
+ configurable: true,
87
+ writable: true,
82
88
  });
83
89
  Object.defineProperty(err, 'data', {
84
90
  value: o.data,
@@ -4,6 +4,6 @@ import { AppError } from './app.error';
4
4
  */
5
5
  export class HttpError extends AppError {
6
6
  constructor(message, data, opt) {
7
- super(message, data, opt);
7
+ super(message, data, opt, 'HttpError');
8
8
  }
9
9
  }
@@ -1,5 +1,8 @@
1
1
  import { AppError } from '../error/app.error';
2
2
  export class TimeoutError extends AppError {
3
+ constructor(message, data = {}, opt) {
4
+ super(message, data, opt, 'TimeoutError');
5
+ }
3
6
  }
4
7
  /**
5
8
  * Decorates a Function with a timeout.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.133.0",
3
+ "version": "14.133.1",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -17,12 +17,20 @@ export class AppError<DATA_TYPE extends ErrorData = ErrorData> extends Error {
17
17
  */
18
18
  override cause?: Error
19
19
 
20
- constructor(message: string, data = {} as DATA_TYPE, opt?: ErrorOptions) {
20
+ constructor(message: string, data = {} as DATA_TYPE, opt?: ErrorOptions, name?: string) {
21
21
  super(message)
22
22
 
23
23
  Object.defineProperty(this, 'name', {
24
- value: this.constructor.name,
24
+ value: name || this.constructor.name,
25
25
  configurable: true,
26
+ writable: true,
27
+ })
28
+
29
+ // this is to allow changing this.constuctor.name to a non-minified version
30
+ Object.defineProperty(this.constructor, 'name', {
31
+ value: name || this.constructor.name,
32
+ configurable: true,
33
+ writable: true,
26
34
  })
27
35
 
28
36
  Object.defineProperty(this, 'data', {
@@ -123,4 +123,8 @@ export function _assertTypeOf<T>(v: any, expectedType: string, message?: string)
123
123
  }
124
124
  }
125
125
 
126
- export class AssertionError extends AppError {}
126
+ export class AssertionError extends AppError {
127
+ constructor(message: string, data = {}, opt?: ErrorOptions) {
128
+ super(message, data, opt, 'AssertionError')
129
+ }
130
+ }
@@ -105,6 +105,13 @@ export function _errorObjectToError<DATA_TYPE extends ErrorData, ERROR_TYPE exte
105
105
  Object.defineProperty(err, 'name', {
106
106
  value: o.name,
107
107
  configurable: true,
108
+ writable: true,
109
+ })
110
+
111
+ Object.defineProperty(err.constructor, 'name', {
112
+ value: o.name,
113
+ configurable: true,
114
+ writable: true,
108
115
  })
109
116
 
110
117
  Object.defineProperty(err, 'data', {
@@ -8,6 +8,6 @@ export class HttpError<
8
8
  DATA_TYPE extends HttpErrorData = HttpErrorData,
9
9
  > extends AppError<DATA_TYPE> {
10
10
  constructor(message: string, data: DATA_TYPE, opt?: ErrorOptions) {
11
- super(message, data, opt)
11
+ super(message, data, opt, 'HttpError')
12
12
  }
13
13
  }
@@ -2,7 +2,11 @@ import { AppError } from '../error/app.error'
2
2
  import type { ErrorData } from '../error/error.model'
3
3
  import type { AnyAsyncFunction } from '../types'
4
4
 
5
- export class TimeoutError extends AppError {}
5
+ export class TimeoutError extends AppError {
6
+ constructor(message: string, data = {}, opt?: ErrorOptions) {
7
+ super(message, data, opt, 'TimeoutError')
8
+ }
9
+ }
6
10
 
7
11
  export interface PTimeoutOptions {
8
12
  /**