@naturalcycles/js-lib 14.55.0 → 14.56.0

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.
@@ -13,13 +13,15 @@ exports.AppError = void 0;
13
13
  class AppError extends Error {
14
14
  constructor(message, data = {}) {
15
15
  super(message);
16
- this.data = data;
17
- this.constructor = AppError;
18
- this.__proto__ = AppError.prototype;
19
16
  Object.defineProperty(this, 'name', {
20
17
  value: this.constructor.name,
21
18
  configurable: true,
22
19
  });
20
+ Object.defineProperty(this, 'data', {
21
+ value: data,
22
+ configurable: true,
23
+ enumerable: false,
24
+ });
23
25
  if (Error.captureStackTrace) {
24
26
  Error.captureStackTrace(this, this.constructor);
25
27
  }
@@ -36,5 +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: ErrorData);
39
+ constructor(message: string, data?: ErrorData);
40
40
  }
@@ -103,23 +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) {
106
+ constructor(message, data = {}) {
107
107
  super(message, data);
108
- this.constructor = AssertionError;
109
- this.__proto__ = AssertionError.prototype;
110
- Object.defineProperty(this, 'name', {
111
- value: this.constructor.name,
112
- configurable: true, // otherwise throws with "TypeError: Cannot redefine property: name"
113
- });
114
- if (Error.captureStackTrace) {
115
- Error.captureStackTrace(this, this.constructor);
116
- }
117
- else {
118
- Object.defineProperty(this, 'stack', {
119
- value: new Error().stack,
120
- configurable: true,
121
- });
122
- }
123
108
  }
124
109
  }
125
110
  exports.AssertionError = AssertionError;
@@ -8,21 +8,6 @@ const app_error_1 = require("./app.error");
8
8
  class HttpError extends app_error_1.AppError {
9
9
  constructor(message, data) {
10
10
  super(message, data);
11
- this.constructor = HttpError;
12
- this.__proto__ = HttpError.prototype;
13
- Object.defineProperty(this, 'name', {
14
- value: this.constructor.name,
15
- configurable: true, // otherwise throws with "TypeError: Cannot redefine property: name"
16
- });
17
- if (Error.captureStackTrace) {
18
- Error.captureStackTrace(this, this.constructor);
19
- }
20
- else {
21
- Object.defineProperty(this, 'stack', {
22
- value: new Error().stack,
23
- configurable: true,
24
- });
25
- }
26
11
  }
27
12
  }
28
13
  exports.HttpError = HttpError;
@@ -20,8 +20,6 @@ class AggregatedError extends Error {
20
20
  super(message);
21
21
  this.errors = mappedErrors;
22
22
  this.results = results;
23
- this.constructor = AggregatedError;
24
- this.__proto__ = AggregatedError.prototype;
25
23
  Object.defineProperty(this, 'name', {
26
24
  value: this.constructor.name,
27
25
  configurable: true,
@@ -10,13 +10,15 @@
10
10
  export class AppError extends Error {
11
11
  constructor(message, data = {}) {
12
12
  super(message);
13
- this.data = data;
14
- this.constructor = AppError;
15
- this.__proto__ = AppError.prototype;
16
13
  Object.defineProperty(this, 'name', {
17
14
  value: this.constructor.name,
18
15
  configurable: true,
19
16
  });
17
+ Object.defineProperty(this, 'data', {
18
+ value: data,
19
+ configurable: true,
20
+ enumerable: false,
21
+ });
20
22
  if (Error.captureStackTrace) {
21
23
  Error.captureStackTrace(this, this.constructor);
22
24
  }
@@ -84,22 +84,7 @@ export function _assertTypeOf(v, expectedType, message) {
84
84
  }
85
85
  }
86
86
  export class AssertionError extends AppError {
87
- constructor(message, data) {
87
+ constructor(message, data = {}) {
88
88
  super(message, data);
89
- this.constructor = AssertionError;
90
- this.__proto__ = AssertionError.prototype;
91
- Object.defineProperty(this, 'name', {
92
- value: this.constructor.name,
93
- configurable: true, // otherwise throws with "TypeError: Cannot redefine property: name"
94
- });
95
- if (Error.captureStackTrace) {
96
- Error.captureStackTrace(this, this.constructor);
97
- }
98
- else {
99
- Object.defineProperty(this, 'stack', {
100
- value: new Error().stack,
101
- configurable: true,
102
- });
103
- }
104
89
  }
105
90
  }
@@ -5,20 +5,5 @@ import { AppError } from './app.error';
5
5
  export class HttpError extends AppError {
6
6
  constructor(message, data) {
7
7
  super(message, data);
8
- this.constructor = HttpError;
9
- this.__proto__ = HttpError.prototype;
10
- Object.defineProperty(this, 'name', {
11
- value: this.constructor.name,
12
- configurable: true, // otherwise throws with "TypeError: Cannot redefine property: name"
13
- });
14
- if (Error.captureStackTrace) {
15
- Error.captureStackTrace(this, this.constructor);
16
- }
17
- else {
18
- Object.defineProperty(this, 'stack', {
19
- value: new Error().stack,
20
- configurable: true,
21
- });
22
- }
23
8
  }
24
9
  }
@@ -17,8 +17,6 @@ export class AggregatedError extends Error {
17
17
  super(message);
18
18
  this.errors = mappedErrors;
19
19
  this.results = results;
20
- this.constructor = AggregatedError;
21
- this.__proto__ = AggregatedError.prototype;
22
20
  Object.defineProperty(this, 'name', {
23
21
  value: this.constructor.name,
24
22
  configurable: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.55.0",
3
+ "version": "14.56.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -10,16 +10,22 @@ import { ErrorData } from './error.model'
10
10
  * Based on: https://medium.com/@xpl/javascript-deriving-from-error-properly-8d2f8f315801
11
11
  */
12
12
  export class AppError<DATA_TYPE extends ErrorData = ErrorData> extends Error {
13
- constructor(message: string, public data = {} as DATA_TYPE) {
13
+ data!: DATA_TYPE
14
+
15
+ constructor(message: string, data = {} as DATA_TYPE) {
14
16
  super(message)
15
17
 
16
- this.constructor = AppError
17
- ;(this as any).__proto__ = AppError.prototype
18
18
  Object.defineProperty(this, 'name', {
19
19
  value: this.constructor.name,
20
20
  configurable: true,
21
21
  })
22
22
 
23
+ Object.defineProperty(this, 'data', {
24
+ value: data,
25
+ configurable: true,
26
+ enumerable: false,
27
+ })
28
+
23
29
  if (Error.captureStackTrace) {
24
30
  Error.captureStackTrace(this, this.constructor)
25
31
  } else {
@@ -123,23 +123,7 @@ export function _assertTypeOf<T>(v: any, expectedType: string, message?: string)
123
123
  }
124
124
 
125
125
  export class AssertionError extends AppError {
126
- constructor(message: string, data: ErrorData) {
126
+ constructor(message: string, data = {} as ErrorData) {
127
127
  super(message, data)
128
-
129
- this.constructor = AssertionError
130
- ;(this as any).__proto__ = AssertionError.prototype
131
- Object.defineProperty(this, 'name', {
132
- value: this.constructor.name,
133
- configurable: true, // otherwise throws with "TypeError: Cannot redefine property: name"
134
- })
135
-
136
- if (Error.captureStackTrace) {
137
- Error.captureStackTrace(this, this.constructor)
138
- } else {
139
- Object.defineProperty(this, 'stack', {
140
- value: new Error().stack, // eslint-disable-line unicorn/error-message
141
- configurable: true,
142
- })
143
- }
144
128
  }
145
129
  }
@@ -9,21 +9,5 @@ export class HttpError<
9
9
  > extends AppError<DATA_TYPE> {
10
10
  constructor(message: string, data: DATA_TYPE) {
11
11
  super(message, data)
12
-
13
- this.constructor = HttpError
14
- ;(this as any).__proto__ = HttpError.prototype
15
- Object.defineProperty(this, 'name', {
16
- value: this.constructor.name,
17
- configurable: true, // otherwise throws with "TypeError: Cannot redefine property: name"
18
- })
19
-
20
- if (Error.captureStackTrace) {
21
- Error.captureStackTrace(this, this.constructor)
22
- } else {
23
- Object.defineProperty(this, 'stack', {
24
- value: new Error().stack, // eslint-disable-line unicorn/error-message
25
- configurable: true,
26
- })
27
- }
28
12
  }
29
13
  }
@@ -23,8 +23,6 @@ export class AggregatedError<RESULT = any> extends Error {
23
23
  this.errors = mappedErrors
24
24
  this.results = results
25
25
 
26
- this.constructor = AggregatedError
27
- ;(this as any).__proto__ = AggregatedError.prototype
28
26
  Object.defineProperty(this, 'name', {
29
27
  value: this.constructor.name,
30
28
  configurable: true,