@naturalcycles/js-lib 15.89.0 → 15.91.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.
- package/dist/asyncManager.js +3 -2
- package/dist/decorators/asyncMemo.decorator.d.ts +1 -1
- package/dist/decorators/asyncMemo.decorator.js +4 -3
- package/dist/decorators/logMethod.decorator.d.ts +1 -1
- package/dist/decorators/logMethod.decorator.js +8 -3
- package/dist/decorators/memo.decorator.d.ts +1 -1
- package/dist/decorators/memo.decorator.js +3 -2
- package/dist/decorators/memoSimple.decorator.js +8 -1
- package/dist/decorators/memoized.js +3 -2
- package/dist/decorators/memoizedAsync.js +4 -3
- package/dist/error/tryCatch.d.ts +1 -1
- package/dist/error/tryCatch.js +3 -2
- package/dist/http/fetcher.js +18 -17
- package/dist/http/fetcher.model.d.ts +1 -1
- package/dist/log/commonLogger.d.ts +35 -28
- package/dist/log/commonLogger.js +51 -86
- package/dist/promise/pGradualQueue.d.ts +1 -1
- package/dist/promise/pMap.d.ts +2 -2
- package/dist/promise/pMap.js +4 -3
- package/dist/promise/pQueue.d.ts +1 -1
- package/dist/promise/pRetry.d.ts +1 -1
- package/dist/promise/pRetry.js +3 -2
- package/package.json +2 -2
- package/src/asyncManager.ts +3 -2
- package/src/decorators/asyncMemo.decorator.ts +5 -4
- package/src/decorators/logMethod.decorator.ts +9 -4
- package/src/decorators/memo.decorator.ts +4 -3
- package/src/decorators/memoSimple.decorator.ts +2 -1
- package/src/decorators/memoized.ts +3 -2
- package/src/decorators/memoizedAsync.ts +4 -3
- package/src/error/tryCatch.ts +4 -3
- package/src/http/fetcher.model.ts +1 -1
- package/src/http/fetcher.ts +9 -10
- package/src/log/commonLogger.ts +78 -118
- package/src/promise/pGradualQueue.ts +1 -1
- package/src/promise/pMap.ts +10 -5
- package/src/promise/pQueue.ts +1 -1
- package/src/promise/pRetry.ts +4 -3
package/src/promise/pMap.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ErrorMode } from '../error/errorMode.js'
|
|
2
|
+
import { consoleLogger } from '../log/commonLogger.js'
|
|
2
3
|
import type { CommonLogger } from '../log/commonLogger.js'
|
|
3
4
|
import { END, SKIP } from '../types.js'
|
|
4
5
|
import type { AbortableAsyncMapper } from '../types.js'
|
|
@@ -17,12 +18,12 @@ export interface PMapOptions {
|
|
|
17
18
|
* When set to THROW_AGGREGATED, instead of stopping when a promise rejects, it will wait for all the promises to settle and then reject with an Aggregated error.
|
|
18
19
|
*
|
|
19
20
|
* When set to SUPPRESS - will ignore errors and return results from successful operations.
|
|
20
|
-
* When in SUPPRESS - errors are still logged via the `logger` (which defaults to
|
|
21
|
+
* When in SUPPRESS - errors are still logged via the `logger` (which defaults to consoleLogger).
|
|
21
22
|
*/
|
|
22
23
|
errorMode?: ErrorMode
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
|
-
* Default to `
|
|
26
|
+
* Default to `consoleLogger`.
|
|
26
27
|
* Pass `null` to skip logging completely.
|
|
27
28
|
*/
|
|
28
29
|
logger?: CommonLogger | null
|
|
@@ -71,7 +72,11 @@ export async function pMap<IN, OUT>(
|
|
|
71
72
|
const itemsLength = items.length
|
|
72
73
|
if (itemsLength === 0) return [] // short circuit
|
|
73
74
|
|
|
74
|
-
const {
|
|
75
|
+
const {
|
|
76
|
+
concurrency = Infinity,
|
|
77
|
+
errorMode = ErrorMode.THROW_IMMEDIATELY,
|
|
78
|
+
logger = consoleLogger,
|
|
79
|
+
} = opt
|
|
75
80
|
|
|
76
81
|
// Special cases that are able to preserve async stack traces
|
|
77
82
|
// Special case: serial execution
|
|
@@ -181,7 +186,7 @@ async function pMap1<IN, OUT>(
|
|
|
181
186
|
errors.push(err as Error)
|
|
182
187
|
} else {
|
|
183
188
|
// otherwise, suppress (but still log via logger)
|
|
184
|
-
logger?.error(err)
|
|
189
|
+
logger?.error({ err })
|
|
185
190
|
}
|
|
186
191
|
}
|
|
187
192
|
}
|
|
@@ -219,7 +224,7 @@ async function pMapAll<IN, OUT>(
|
|
|
219
224
|
errors.push(r.reason)
|
|
220
225
|
} else {
|
|
221
226
|
// otherwise, suppress (but still log via logger)
|
|
222
|
-
logger?.error(r.reason)
|
|
227
|
+
logger?.error({ err: r.reason })
|
|
223
228
|
}
|
|
224
229
|
}
|
|
225
230
|
|
package/src/promise/pQueue.ts
CHANGED
package/src/promise/pRetry.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { _since } from '../datetime/time.util.js'
|
|
2
2
|
import type { ErrorData } from '../error/error.model.js'
|
|
3
3
|
import { _errorDataAppend } from '../error/error.util.js'
|
|
4
|
+
import { consoleLogger } from '../log/commonLogger.js'
|
|
4
5
|
import type { CommonLogger } from '../log/commonLogger.js'
|
|
5
6
|
import type { AnyAsyncFunction, UnixTimestampMillis } from '../types.js'
|
|
6
7
|
import { pDelay } from './pDelay.js'
|
|
@@ -84,7 +85,7 @@ export interface PRetryOptions {
|
|
|
84
85
|
logNone?: boolean
|
|
85
86
|
|
|
86
87
|
/**
|
|
87
|
-
* Default to `
|
|
88
|
+
* Default to `consoleLogger`
|
|
88
89
|
*/
|
|
89
90
|
logger?: CommonLogger
|
|
90
91
|
|
|
@@ -113,7 +114,7 @@ export async function pRetry<T>(
|
|
|
113
114
|
delay: initialDelay = 1000,
|
|
114
115
|
delayMultiplier = 2,
|
|
115
116
|
predicate,
|
|
116
|
-
logger =
|
|
117
|
+
logger = consoleLogger,
|
|
117
118
|
name,
|
|
118
119
|
timeout,
|
|
119
120
|
} = opt
|
|
@@ -164,7 +165,7 @@ export async function pRetry<T>(
|
|
|
164
165
|
if (logFailures) {
|
|
165
166
|
// Logger at warn (not error) level, because it's not a fatal error, but a retriable one
|
|
166
167
|
// Fatal one is not logged either, because it's been thrown instead
|
|
167
|
-
logger.warn(`${fname} attempt #${attempt} error in ${_since(started)}
|
|
168
|
+
logger.warn({ msg: `${fname} attempt #${attempt} error in ${_since(started)}`, err })
|
|
168
169
|
}
|
|
169
170
|
|
|
170
171
|
if (attempt >= maxAttempts || (predicate && !predicate(err as Error, attempt, maxAttempts))) {
|