@naturalcycles/js-lib 14.129.0 → 14.130.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.
Files changed (65) hide show
  1. package/dist/decorators/asyncMemo.decorator.d.ts +2 -2
  2. package/dist/decorators/createPromiseDecorator.d.ts +6 -6
  3. package/dist/decorators/debounce.d.ts +2 -2
  4. package/dist/decorators/memo.decorator.d.ts +2 -2
  5. package/dist/decorators/memo.util.d.ts +7 -7
  6. package/dist/error/app.error.d.ts +5 -1
  7. package/dist/error/app.error.js +10 -1
  8. package/dist/error/assert.d.ts +0 -1
  9. package/dist/error/assert.js +0 -3
  10. package/dist/error/error.model.d.ts +1 -0
  11. package/dist/error/error.util.d.ts +4 -5
  12. package/dist/error/error.util.js +27 -18
  13. package/dist/error/errorMode.d.ts +1 -1
  14. package/dist/error/errorMode.js +1 -1
  15. package/dist/error/http.error.d.ts +1 -1
  16. package/dist/error/http.error.js +2 -2
  17. package/dist/error/tryCatch.d.ts +1 -1
  18. package/dist/http/fetcher.js +4 -3
  19. package/dist/index.d.ts +0 -1
  20. package/dist/index.js +0 -1
  21. package/dist/json-schema/jsonSchemaBuilder.d.ts +1 -1
  22. package/dist/promise/pDefer.d.ts +2 -2
  23. package/dist/promise/pMap.js +3 -4
  24. package/dist/promise/pRetry.d.ts +1 -1
  25. package/dist/promise/pTimeout.d.ts +1 -1
  26. package/dist/string/pupa.d.ts +2 -2
  27. package/dist/string/readingTime.d.ts +1 -1
  28. package/dist/string/stringifyAny.d.ts +6 -0
  29. package/dist/string/stringifyAny.js +13 -1
  30. package/dist-esm/error/app.error.js +10 -1
  31. package/dist-esm/error/assert.js +0 -3
  32. package/dist-esm/error/error.util.js +27 -15
  33. package/dist-esm/error/errorMode.js +1 -1
  34. package/dist-esm/error/http.error.js +2 -2
  35. package/dist-esm/http/fetcher.js +4 -3
  36. package/dist-esm/index.js +0 -1
  37. package/dist-esm/promise/pMap.js +3 -4
  38. package/dist-esm/string/stringifyAny.js +13 -1
  39. package/package.json +1 -1
  40. package/src/decorators/asyncMemo.decorator.ts +2 -2
  41. package/src/decorators/createPromiseDecorator.ts +4 -4
  42. package/src/decorators/debounce.ts +2 -2
  43. package/src/decorators/memo.decorator.ts +2 -2
  44. package/src/decorators/memo.util.ts +7 -7
  45. package/src/error/app.error.ts +16 -1
  46. package/src/error/assert.ts +1 -5
  47. package/src/error/error.model.ts +10 -0
  48. package/src/error/error.util.ts +27 -28
  49. package/src/error/errorMode.ts +1 -1
  50. package/src/error/http.error.ts +2 -2
  51. package/src/error/tryCatch.ts +1 -1
  52. package/src/http/fetcher.ts +5 -8
  53. package/src/index.ts +0 -1
  54. package/src/json-schema/jsonSchemaBuilder.ts +1 -1
  55. package/src/promise/pDefer.ts +2 -2
  56. package/src/promise/pMap.ts +3 -4
  57. package/src/promise/pRetry.ts +1 -1
  58. package/src/promise/pTimeout.ts +1 -1
  59. package/src/string/pupa.ts +1 -1
  60. package/src/string/readingTime.ts +1 -1
  61. package/src/string/stringifyAny.ts +23 -1
  62. package/dist/promise/AggregatedError.d.ts +0 -10
  63. package/dist/promise/AggregatedError.js +0 -34
  64. package/dist-esm/promise/AggregatedError.js +0 -30
  65. package/src/promise/AggregatedError.ts +0 -36
@@ -43,7 +43,7 @@ export interface PRetryOptions {
43
43
  *
44
44
  * @default () => true
45
45
  */
46
- predicate?(err: Error, attempt: number, maxAttempts: number): boolean
46
+ predicate?: (err: Error, attempt: number, maxAttempts: number) => boolean
47
47
 
48
48
  /**
49
49
  * Log the first attempt (which is not a "retry" yet).
@@ -23,7 +23,7 @@ export interface PTimeoutOptions {
23
23
  * err (which is TimeoutError) is passed as an argument for convenience, so it can
24
24
  * be logged or such. You don't have to consume it in any way though.
25
25
  */
26
- onTimeout?(err: TimeoutError): any
26
+ onTimeout?: (err: TimeoutError) => any
27
27
 
28
28
  /**
29
29
  * Defaults to true.
@@ -31,7 +31,7 @@ export interface PupaOptions {
31
31
  /**
32
32
  * Performs arbitrary operation for each interpolation. If the returned value was `undefined`, it behaves differently depending on the `ignoreMissing` option. Otherwise, the returned value will be interpolated into a string (and escaped when double-braced) and embedded into the template.
33
33
  */
34
- transform?(data: { value: any; key: string }): unknown
34
+ transform?: (data: { value: any; key: string }) => unknown
35
35
  }
36
36
 
37
37
  /**
@@ -16,7 +16,7 @@ export interface ReadingTimeOptions {
16
16
  * A function that returns a boolean value depending on if a character is considered as a word bound.
17
17
  * Default: spaces, new lines and tabs
18
18
  */
19
- wordBound?(char: string): boolean
19
+ wordBound?: (char: string) => boolean
20
20
  /**
21
21
  * Default 200
22
22
  */
@@ -3,6 +3,8 @@ import type { Reviver } from '../types'
3
3
  import { _jsonParseIfPossible } from './json.util'
4
4
  import { _safeJsonStringify } from './safeJsonStringify'
5
5
 
6
+ const supportsAggregateError = typeof globalThis.AggregateError === 'function'
7
+
6
8
  let globalStringifyFunction: JsonStringifyFunction = _safeJsonStringify
7
9
 
8
10
  /**
@@ -45,6 +47,13 @@ export interface StringifyAnyOptions {
45
47
  */
46
48
  includeErrorStack?: boolean
47
49
 
50
+ /**
51
+ * Set to false to skip including Error.cause.
52
+ *
53
+ * @default true
54
+ */
55
+ includeErrorCause?: boolean
56
+
48
57
  /**
49
58
  * Allows to pass custom "stringify function".
50
59
  * E.g in Node.js you can pass `util.inspect` instead.
@@ -91,6 +100,7 @@ export function _stringifyAny(obj: any, opt: StringifyAnyOptions = {}): string {
91
100
  }
92
101
 
93
102
  if (obj instanceof Error || _isErrorObject(obj)) {
103
+ const { includeErrorCause = true } = opt
94
104
  //
95
105
  // Error or ErrorObject
96
106
  //
@@ -100,7 +110,7 @@ export function _stringifyAny(obj: any, opt: StringifyAnyOptions = {}): string {
100
110
  // if (obj?.name === 'Error') {
101
111
  // s = obj.message
102
112
  // }
103
- s = [obj.name, obj.message].join(': ')
113
+ s = [obj.name, obj.message].filter(Boolean).join(': ')
104
114
 
105
115
  if (opt.includeErrorStack && obj.stack) {
106
116
  // Here we're using the previously-generated "title line" (e.g "Error: some_message"),
@@ -128,6 +138,18 @@ export function _stringifyAny(obj: any, opt: StringifyAnyOptions = {}): string {
128
138
  // Error that has no `data`, but has `code` property
129
139
  s = [s, `code: ${(obj as any).code}`].join('\n')
130
140
  }
141
+
142
+ if (supportsAggregateError && obj instanceof AggregateError && obj.errors.length) {
143
+ s = [
144
+ s,
145
+ `${obj.errors.length} error(s):`,
146
+ ...obj.errors.map((err, i) => `${i + 1}. ${_stringifyAny(err, opt)}`),
147
+ ].join('\n')
148
+ }
149
+
150
+ if (obj.cause && includeErrorCause) {
151
+ s = s + '\ncaused by: ' + _stringifyAny(obj.cause, opt)
152
+ }
131
153
  } else if (typeof obj === 'string') {
132
154
  //
133
155
  // String
@@ -1,10 +0,0 @@
1
- /**
2
- * Error that aggregates a number of other errors.
3
- * .errors contain raw original errors to be accessed if needed.
4
- * .results contain the results of some batch operation (if needed).
5
- */
6
- export declare class AggregatedError<RESULT = any> extends Error {
7
- errors: Error[];
8
- results: RESULT[];
9
- constructor(errors: Error[], results?: RESULT[]);
10
- }
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AggregatedError = void 0;
4
- /**
5
- * Error that aggregates a number of other errors.
6
- * .errors contain raw original errors to be accessed if needed.
7
- * .results contain the results of some batch operation (if needed).
8
- */
9
- class AggregatedError extends Error {
10
- constructor(errors, results = []) {
11
- const message = [
12
- `${errors.length} errors:`,
13
- ...errors.map((e, i) => `${i + 1}. ${e.message}`),
14
- ].join('\n');
15
- super(message);
16
- this.errors = errors;
17
- this.results = results;
18
- Object.defineProperty(this, 'name', {
19
- value: this.constructor.name,
20
- configurable: true,
21
- });
22
- if (Error.captureStackTrace) {
23
- Error.captureStackTrace(this, this.constructor);
24
- }
25
- else {
26
- Object.defineProperty(this, 'stack', {
27
- value: new Error().stack,
28
- writable: true,
29
- configurable: true,
30
- });
31
- }
32
- }
33
- }
34
- exports.AggregatedError = AggregatedError;
@@ -1,30 +0,0 @@
1
- /**
2
- * Error that aggregates a number of other errors.
3
- * .errors contain raw original errors to be accessed if needed.
4
- * .results contain the results of some batch operation (if needed).
5
- */
6
- export class AggregatedError extends Error {
7
- constructor(errors, results = []) {
8
- const message = [
9
- `${errors.length} errors:`,
10
- ...errors.map((e, i) => `${i + 1}. ${e.message}`),
11
- ].join('\n');
12
- super(message);
13
- this.errors = errors;
14
- this.results = results;
15
- Object.defineProperty(this, 'name', {
16
- value: this.constructor.name,
17
- configurable: true,
18
- });
19
- if (Error.captureStackTrace) {
20
- Error.captureStackTrace(this, this.constructor);
21
- }
22
- else {
23
- Object.defineProperty(this, 'stack', {
24
- value: new Error().stack,
25
- writable: true,
26
- configurable: true,
27
- });
28
- }
29
- }
30
- }
@@ -1,36 +0,0 @@
1
- /**
2
- * Error that aggregates a number of other errors.
3
- * .errors contain raw original errors to be accessed if needed.
4
- * .results contain the results of some batch operation (if needed).
5
- */
6
- export class AggregatedError<RESULT = any> extends Error {
7
- errors!: Error[]
8
- results!: RESULT[]
9
-
10
- constructor(errors: Error[], results: RESULT[] = []) {
11
- const message = [
12
- `${errors.length} errors:`,
13
- ...errors.map((e, i) => `${i + 1}. ${e.message}`),
14
- ].join('\n')
15
-
16
- super(message)
17
-
18
- this.errors = errors
19
- this.results = results
20
-
21
- Object.defineProperty(this, 'name', {
22
- value: this.constructor.name,
23
- configurable: true,
24
- })
25
-
26
- if (Error.captureStackTrace) {
27
- Error.captureStackTrace(this, this.constructor)
28
- } else {
29
- Object.defineProperty(this, 'stack', {
30
- value: new Error().stack, // eslint-disable-line unicorn/error-message
31
- writable: true,
32
- configurable: true,
33
- })
34
- }
35
- }
36
- }