@ls-stack/utils 3.27.2 → 3.28.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.
@@ -10,7 +10,7 @@
10
10
 
11
11
  ### ConcurrentCalls\<R, E\>
12
12
 
13
- Defined in: [packages/utils/src/concurrentCalls.ts:31](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L31)
13
+ Defined in: [packages/utils/src/concurrentCalls.ts:124](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L124)
14
14
 
15
15
  #### Type Parameters
16
16
 
@@ -42,7 +42,7 @@ new ConcurrentCalls<R, E>(): ConcurrentCalls<R, E>;
42
42
  add(...calls): this;
43
43
  ```
44
44
 
45
- Defined in: [packages/utils/src/concurrentCalls.ts:35](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L35)
45
+ Defined in: [packages/utils/src/concurrentCalls.ts:128](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L128)
46
46
 
47
47
  ###### Parameters
48
48
 
@@ -60,7 +60,7 @@ Defined in: [packages/utils/src/concurrentCalls.ts:35](https://github.com/lucaso
60
60
  resultifyAdd(...calls): this;
61
61
  ```
62
62
 
63
- Defined in: [packages/utils/src/concurrentCalls.ts:41](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L41)
63
+ Defined in: [packages/utils/src/concurrentCalls.ts:134](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L134)
64
64
 
65
65
  ###### Parameters
66
66
 
@@ -78,7 +78,7 @@ Defined in: [packages/utils/src/concurrentCalls.ts:41](https://github.com/lucaso
78
78
  runAll(__namedParameters): Promise<Result<R[], E>>;
79
79
  ```
80
80
 
81
- Defined in: [packages/utils/src/concurrentCalls.ts:58](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L58)
81
+ Defined in: [packages/utils/src/concurrentCalls.ts:151](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L151)
82
82
 
83
83
  ###### Parameters
84
84
 
@@ -94,7 +94,8 @@ Defined in: [packages/utils/src/concurrentCalls.ts:58](https://github.com/lucaso
94
94
 
95
95
  ```ts
96
96
  runAllSettled(__namedParameters): Promise<{
97
- aggregatedError: null | AggregateError;
97
+ aggregatedError: | null
98
+ | ConcurrentCallsAggregateError;
98
99
  allFailed: boolean;
99
100
  failures: E[];
100
101
  succeeded: R[];
@@ -102,7 +103,7 @@ runAllSettled(__namedParameters): Promise<{
102
103
  }>;
103
104
  ```
104
105
 
105
- Defined in: [packages/utils/src/concurrentCalls.ts:90](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L90)
106
+ Defined in: [packages/utils/src/concurrentCalls.ts:183](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L183)
106
107
 
107
108
  ###### Parameters
108
109
 
@@ -113,7 +114,8 @@ Defined in: [packages/utils/src/concurrentCalls.ts:90](https://github.com/lucaso
113
114
  ###### Returns
114
115
 
115
116
  `Promise`\<\{
116
- `aggregatedError`: `null` \| `AggregateError`;
117
+ `aggregatedError`: \| `null`
118
+ \| [`ConcurrentCallsAggregateError`](README.md#concurrentcallsaggregateerror);
117
119
  `allFailed`: `boolean`;
118
120
  `failures`: `E`[];
119
121
  `succeeded`: `R`[];
@@ -124,7 +126,7 @@ Defined in: [packages/utils/src/concurrentCalls.ts:90](https://github.com/lucaso
124
126
 
125
127
  ### ConcurrentCallsWithMetadata\<M, R, E\>
126
128
 
127
- Defined in: [packages/utils/src/concurrentCalls.ts:157](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L157)
129
+ Defined in: [packages/utils/src/concurrentCalls.ts:250](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L250)
128
130
 
129
131
  #### Type Parameters
130
132
 
@@ -160,7 +162,7 @@ new ConcurrentCallsWithMetadata<M, R, E>(): ConcurrentCallsWithMetadata<M, R, E>
160
162
  add(...calls): this;
161
163
  ```
162
164
 
163
- Defined in: [packages/utils/src/concurrentCalls.ts:165](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L165)
165
+ Defined in: [packages/utils/src/concurrentCalls.ts:258](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L258)
164
166
 
165
167
  ###### Parameters
166
168
 
@@ -178,7 +180,7 @@ Defined in: [packages/utils/src/concurrentCalls.ts:165](https://github.com/lucas
178
180
  resultifyAdd(...items): this;
179
181
  ```
180
182
 
181
- Defined in: [packages/utils/src/concurrentCalls.ts:179](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L179)
183
+ Defined in: [packages/utils/src/concurrentCalls.ts:272](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L272)
182
184
 
183
185
  ###### Parameters
184
186
 
@@ -196,7 +198,7 @@ Defined in: [packages/utils/src/concurrentCalls.ts:179](https://github.com/lucas
196
198
  runAll(__namedParameters): Promise<Result<SucceededCall<R, M>[], FailedCall<M, E>>>;
197
199
  ```
198
200
 
199
- Defined in: [packages/utils/src/concurrentCalls.ts:199](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L199)
201
+ Defined in: [packages/utils/src/concurrentCalls.ts:292](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L292)
200
202
 
201
203
  ###### Parameters
202
204
 
@@ -212,7 +214,8 @@ Defined in: [packages/utils/src/concurrentCalls.ts:199](https://github.com/lucas
212
214
 
213
215
  ```ts
214
216
  runAllSettled(__namedParameters): Promise<{
215
- aggregatedError: null | AggregateError;
217
+ aggregatedError: | null
218
+ | ConcurrentCallsWithMetadataAggregateError<M>;
216
219
  allFailed: boolean;
217
220
  failed: FailedCall<M, E>[];
218
221
  failures: FailedCall<M, E>[];
@@ -222,7 +225,7 @@ runAllSettled(__namedParameters): Promise<{
222
225
  }>;
223
226
  ```
224
227
 
225
- Defined in: [packages/utils/src/concurrentCalls.ts:246](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L246)
228
+ Defined in: [packages/utils/src/concurrentCalls.ts:339](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L339)
226
229
 
227
230
  ###### Parameters
228
231
 
@@ -233,7 +236,8 @@ Defined in: [packages/utils/src/concurrentCalls.ts:246](https://github.com/lucas
233
236
  ###### Returns
234
237
 
235
238
  `Promise`\<\{
236
- `aggregatedError`: `null` \| `AggregateError`;
239
+ `aggregatedError`: \| `null`
240
+ \| [`ConcurrentCallsWithMetadataAggregateError`](README.md#concurrentcallswithmetadataaggregateerror)\<`M`\>;
237
241
  `allFailed`: `boolean`;
238
242
  `failed`: [`FailedCall`](#failedcall)\<`M`, `E`\>[];
239
243
  `failures`: [`FailedCall`](#failedcall)\<`M`, `E`\>[];
@@ -250,7 +254,7 @@ Defined in: [packages/utils/src/concurrentCalls.ts:246](https://github.com/lucas
250
254
  type Action<R, E> = () => Promise<Result<R, E>>;
251
255
  ```
252
256
 
253
- Defined in: [packages/utils/src/concurrentCalls.ts:24](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L24)
257
+ Defined in: [packages/utils/src/concurrentCalls.ts:117](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L117)
254
258
 
255
259
  #### Type Parameters
256
260
 
@@ -274,7 +278,7 @@ Defined in: [packages/utils/src/concurrentCalls.ts:24](https://github.com/lucaso
274
278
  type FailedCall<M, E> = object;
275
279
  ```
276
280
 
277
- Defined in: [packages/utils/src/concurrentCalls.ts:19](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L19)
281
+ Defined in: [packages/utils/src/concurrentCalls.ts:112](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L112)
278
282
 
279
283
  #### Type Parameters
280
284
 
@@ -294,7 +298,7 @@ Defined in: [packages/utils/src/concurrentCalls.ts:19](https://github.com/lucaso
294
298
  error: E;
295
299
  ```
296
300
 
297
- Defined in: [packages/utils/src/concurrentCalls.ts:21](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L21)
301
+ Defined in: [packages/utils/src/concurrentCalls.ts:114](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L114)
298
302
 
299
303
  ##### metadata
300
304
 
@@ -302,7 +306,7 @@ Defined in: [packages/utils/src/concurrentCalls.ts:21](https://github.com/lucaso
302
306
  metadata: M;
303
307
  ```
304
308
 
305
- Defined in: [packages/utils/src/concurrentCalls.ts:20](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L20)
309
+ Defined in: [packages/utils/src/concurrentCalls.ts:113](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L113)
306
310
 
307
311
  ***
308
312
 
@@ -312,7 +316,7 @@ Defined in: [packages/utils/src/concurrentCalls.ts:20](https://github.com/lucaso
312
316
  type RunProps = object;
313
317
  ```
314
318
 
315
- Defined in: [packages/utils/src/concurrentCalls.ts:10](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L10)
319
+ Defined in: [packages/utils/src/concurrentCalls.ts:103](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L103)
316
320
 
317
321
  #### Properties
318
322
 
@@ -322,7 +326,7 @@ Defined in: [packages/utils/src/concurrentCalls.ts:10](https://github.com/lucaso
322
326
  optional delayStart: (index) => number;
323
327
  ```
324
328
 
325
- Defined in: [packages/utils/src/concurrentCalls.ts:11](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L11)
329
+ Defined in: [packages/utils/src/concurrentCalls.ts:104](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L104)
326
330
 
327
331
  ###### Parameters
328
332
 
@@ -353,7 +357,7 @@ type SettledResultWithMetadata<R, M, E> =
353
357
  };
354
358
  ```
355
359
 
356
- Defined in: [packages/utils/src/concurrentCalls.ts:27](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L27)
360
+ Defined in: [packages/utils/src/concurrentCalls.ts:120](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L120)
357
361
 
358
362
  #### Type Parameters
359
363
 
@@ -377,7 +381,7 @@ Defined in: [packages/utils/src/concurrentCalls.ts:27](https://github.com/lucaso
377
381
  type SucceededCall<R, M> = object;
378
382
  ```
379
383
 
380
- Defined in: [packages/utils/src/concurrentCalls.ts:15](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L15)
384
+ Defined in: [packages/utils/src/concurrentCalls.ts:108](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L108)
381
385
 
382
386
  #### Type Parameters
383
387
 
@@ -397,7 +401,7 @@ Defined in: [packages/utils/src/concurrentCalls.ts:15](https://github.com/lucaso
397
401
  metadata: M;
398
402
  ```
399
403
 
400
- Defined in: [packages/utils/src/concurrentCalls.ts:17](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L17)
404
+ Defined in: [packages/utils/src/concurrentCalls.ts:110](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L110)
401
405
 
402
406
  ##### value
403
407
 
@@ -405,7 +409,7 @@ Defined in: [packages/utils/src/concurrentCalls.ts:17](https://github.com/lucaso
405
409
  value: R;
406
410
  ```
407
411
 
408
- Defined in: [packages/utils/src/concurrentCalls.ts:16](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L16)
412
+ Defined in: [packages/utils/src/concurrentCalls.ts:109](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L109)
409
413
 
410
414
  ***
411
415
 
@@ -415,4 +419,4 @@ Defined in: [packages/utils/src/concurrentCalls.ts:16](https://github.com/lucaso
415
419
  type ValidMetadata = string | number | boolean | Record<string, unknown>;
416
420
  ```
417
421
 
418
- Defined in: [packages/utils/src/concurrentCalls.ts:8](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L8)
422
+ Defined in: [packages/utils/src/concurrentCalls.ts:101](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L101)
@@ -10,6 +10,190 @@
10
10
 
11
11
  - [\<internal\>](-internal-.md)
12
12
 
13
+ ## Classes
14
+
15
+ ### ConcurrentCallsAggregateError
16
+
17
+ Defined in: [packages/utils/src/concurrentCalls.ts:32](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L32)
18
+
19
+ #### Extends
20
+
21
+ - `AggregateError`
22
+
23
+ #### Constructors
24
+
25
+ ##### Constructor
26
+
27
+ ```ts
28
+ new ConcurrentCallsAggregateError(
29
+ errors,
30
+ total,
31
+ failed): ConcurrentCallsAggregateError;
32
+ ```
33
+
34
+ Defined in: [packages/utils/src/concurrentCalls.ts:37](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L37)
35
+
36
+ ###### Parameters
37
+
38
+ ###### errors
39
+
40
+ `Error`[]
41
+
42
+ ###### total
43
+
44
+ `number`
45
+
46
+ ###### failed
47
+
48
+ `number`
49
+
50
+ ###### Returns
51
+
52
+ [`ConcurrentCallsAggregateError`](#concurrentcallsaggregateerror)
53
+
54
+ ###### Overrides
55
+
56
+ ```ts
57
+ AggregateError.constructor
58
+ ```
59
+
60
+ #### Properties
61
+
62
+ ##### errors
63
+
64
+ ```ts
65
+ errors: Error[] = [];
66
+ ```
67
+
68
+ Defined in: [packages/utils/src/concurrentCalls.ts:33](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L33)
69
+
70
+ ###### Overrides
71
+
72
+ ```ts
73
+ AggregateError.errors
74
+ ```
75
+
76
+ ##### failed
77
+
78
+ ```ts
79
+ failed: number = 0;
80
+ ```
81
+
82
+ Defined in: [packages/utils/src/concurrentCalls.ts:35](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L35)
83
+
84
+ ##### total
85
+
86
+ ```ts
87
+ total: number = 0;
88
+ ```
89
+
90
+ Defined in: [packages/utils/src/concurrentCalls.ts:34](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L34)
91
+
92
+ ***
93
+
94
+ ### ConcurrentCallsWithMetadataAggregateError\<M\>
95
+
96
+ Defined in: [packages/utils/src/concurrentCalls.ts:50](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L50)
97
+
98
+ #### Extends
99
+
100
+ - `AggregateError`
101
+
102
+ #### Type Parameters
103
+
104
+ ##### M
105
+
106
+ `M` *extends* [`ValidMetadata`](-internal-.md#validmetadata)
107
+
108
+ #### Constructors
109
+
110
+ ##### Constructor
111
+
112
+ ```ts
113
+ new ConcurrentCallsWithMetadataAggregateError<M>(
114
+ errors,
115
+ total,
116
+ failed): ConcurrentCallsWithMetadataAggregateError<M>;
117
+ ```
118
+
119
+ Defined in: [packages/utils/src/concurrentCalls.ts:58](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L58)
120
+
121
+ ###### Parameters
122
+
123
+ ###### errors
124
+
125
+ `object`[]
126
+
127
+ ###### total
128
+
129
+ `number`
130
+
131
+ ###### failed
132
+
133
+ `number`
134
+
135
+ ###### Returns
136
+
137
+ [`ConcurrentCallsWithMetadataAggregateError`](#concurrentcallswithmetadataaggregateerror)\<`M`\>
138
+
139
+ ###### Overrides
140
+
141
+ ```ts
142
+ AggregateError.constructor
143
+ ```
144
+
145
+ #### Properties
146
+
147
+ ##### errors
148
+
149
+ ```ts
150
+ errors: Error[] = [];
151
+ ```
152
+
153
+ Defined in: [packages/utils/src/concurrentCalls.ts:53](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L53)
154
+
155
+ ###### Overrides
156
+
157
+ ```ts
158
+ AggregateError.errors
159
+ ```
160
+
161
+ ##### errorsWithMetadata
162
+
163
+ ```ts
164
+ errorsWithMetadata: object[] = [];
165
+ ```
166
+
167
+ Defined in: [packages/utils/src/concurrentCalls.ts:54](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L54)
168
+
169
+ ###### error
170
+
171
+ ```ts
172
+ error: Error;
173
+ ```
174
+
175
+ ###### metadata
176
+
177
+ ```ts
178
+ metadata: M;
179
+ ```
180
+
181
+ ##### failed
182
+
183
+ ```ts
184
+ failed: number = 0;
185
+ ```
186
+
187
+ Defined in: [packages/utils/src/concurrentCalls.ts:56](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L56)
188
+
189
+ ##### total
190
+
191
+ ```ts
192
+ total: number = 0;
193
+ ```
194
+
195
+ Defined in: [packages/utils/src/concurrentCalls.ts:55](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L55)
196
+
13
197
  ## Functions
14
198
 
15
199
  ### concurrentCalls()
@@ -18,7 +202,7 @@
18
202
  function concurrentCalls<R>(): ConcurrentCalls<R, Error>;
19
203
  ```
20
204
 
21
- Defined in: [packages/utils/src/concurrentCalls.ts:153](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L153)
205
+ Defined in: [packages/utils/src/concurrentCalls.ts:246](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L246)
22
206
 
23
207
  Executes multiple asynchronous calls concurrently and collects the results in a easier to use format.
24
208
 
@@ -42,7 +226,7 @@ The type of the result value.
42
226
  function concurrentCallsWithMetadata<M, R>(): ConcurrentCallsWithMetadata<M, R, Error>;
43
227
  ```
44
228
 
45
- Defined in: [packages/utils/src/concurrentCalls.ts:345](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L345)
229
+ Defined in: [packages/utils/src/concurrentCalls.ts:435](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L435)
46
230
 
47
231
  Executes multiple asynchronous calls concurrently and collects the results in a easier to use format.
48
232
 
@@ -20,6 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/concurrentCalls.ts
21
21
  var concurrentCalls_exports = {};
22
22
  __export(concurrentCalls_exports, {
23
+ ConcurrentCallsAggregateError: () => ConcurrentCallsAggregateError,
24
+ ConcurrentCallsWithMetadataAggregateError: () => ConcurrentCallsWithMetadataAggregateError,
23
25
  concurrentCalls: () => concurrentCalls,
24
26
  concurrentCallsWithMetadata: () => concurrentCallsWithMetadata
25
27
  });
@@ -70,6 +72,67 @@ function truncateString(str, length, ellipsis = "\u2026") {
70
72
  }
71
73
 
72
74
  // src/concurrentCalls.ts
75
+ function formatErrorMessagesWithCounts(messages, failed, total) {
76
+ const errorMessageCounts = /* @__PURE__ */ new Map();
77
+ for (const message of messages) {
78
+ errorMessageCounts.set(message, (errorMessageCounts.get(message) || 0) + 1);
79
+ }
80
+ const formattedMessages = Array.from(errorMessageCounts.entries()).map(
81
+ ([message, count]) => count > 1 ? `${message} (${count}x)` : message
82
+ );
83
+ return `${failed}/${total} calls failed:
84
+ ${truncateArray(
85
+ formattedMessages,
86
+ 5,
87
+ "..."
88
+ ).join("\n")}`;
89
+ }
90
+ var ConcurrentCallsAggregateError = class extends AggregateError {
91
+ errors = [];
92
+ total = 0;
93
+ failed = 0;
94
+ constructor(errors, total, failed) {
95
+ const messages = errors.map(
96
+ (error) => `- ${truncateString(error.message, 100)}`
97
+ );
98
+ const message = formatErrorMessagesWithCounts(messages, failed, total);
99
+ super(errors, message);
100
+ this.errors = errors;
101
+ this.total = total;
102
+ this.failed = failed;
103
+ }
104
+ };
105
+ var ConcurrentCallsWithMetadataAggregateError = class extends AggregateError {
106
+ errors = [];
107
+ errorsWithMetadata = [];
108
+ total = 0;
109
+ failed = 0;
110
+ constructor(errors, total, failed) {
111
+ const messages = errors.map(({ error, metadata }) => {
112
+ let metadataPrefix = typeof metadata === "string" || typeof metadata === "number" || typeof metadata === "boolean" ? `${metadata}: ` : "";
113
+ try {
114
+ const isArray = Array.isArray(metadata);
115
+ if (isObject(metadata) || isArray) {
116
+ const stringifiedMetadata = JSON.stringify(metadata);
117
+ if (stringifiedMetadata.length < 30) {
118
+ metadataPrefix = `${stringifiedMetadata}: `;
119
+ } else {
120
+ metadataPrefix = `[${isArray ? "Array" : "Object"} metadata]: `;
121
+ }
122
+ }
123
+ } catch (_) {
124
+ }
125
+ return `- ${metadataPrefix}${truncateString(error.message, 100)}`;
126
+ });
127
+ const message = formatErrorMessagesWithCounts(messages, failed, total);
128
+ const errorInstances = errors.map((e) => e.error);
129
+ super(errorInstances, message);
130
+ this.errors = errorInstances;
131
+ this.errorsWithMetadata = errors;
132
+ this.total = total;
133
+ this.failed = failed;
134
+ }
135
+ };
73
136
  var ConcurrentCalls = class {
74
137
  #pendingCalls = [];
75
138
  #alreadyRun = false;
@@ -146,7 +209,7 @@ var ConcurrentCalls = class {
146
209
  }
147
210
  }
148
211
  const allFailed = failed.length === total;
149
- const aggregatedError = failed.length > 0 ? new AggregateError(failed, "One or more calls failed") : null;
212
+ const aggregatedError = failed.length > 0 ? new ConcurrentCallsAggregateError(failed, total, failed.length) : null;
150
213
  this.#pendingCalls = [];
151
214
  return {
152
215
  succeeded,
@@ -272,13 +335,10 @@ var ConcurrentCallsWithMetadata = class {
272
335
  }
273
336
  }
274
337
  const allFailed = failedProcessing.length === total;
275
- const aggregatedError = failedProcessing.length > 0 ? new AggregateError(
276
- failedProcessing.map((f) => f.error),
277
- `${failedProcessing.length}/${total} calls failed: ${truncateArray(
278
- failedProcessing.map((f) => truncateString(f.error.message, 20)),
279
- 5,
280
- "..."
281
- ).join("; ")}`
338
+ const aggregatedError = failedProcessing.length > 0 ? new ConcurrentCallsWithMetadataAggregateError(
339
+ failedProcessing,
340
+ total,
341
+ failedProcessing.length
282
342
  ) : null;
283
343
  return {
284
344
  succeeded: succeededProcessing,
@@ -296,6 +356,8 @@ function concurrentCallsWithMetadata() {
296
356
  }
297
357
  // Annotate the CommonJS export names for ESM import in node:
298
358
  0 && (module.exports = {
359
+ ConcurrentCallsAggregateError,
360
+ ConcurrentCallsWithMetadataAggregateError,
299
361
  concurrentCalls,
300
362
  concurrentCallsWithMetadata
301
363
  });
@@ -1,5 +1,24 @@
1
1
  import { Result } from 't-result';
2
2
 
3
+ declare class ConcurrentCallsAggregateError extends AggregateError {
4
+ errors: Error[];
5
+ total: number;
6
+ failed: number;
7
+ constructor(errors: Error[], total: number, failed: number);
8
+ }
9
+ declare class ConcurrentCallsWithMetadataAggregateError<M extends ValidMetadata> extends AggregateError {
10
+ errors: Error[];
11
+ errorsWithMetadata: {
12
+ error: Error;
13
+ metadata: M;
14
+ }[];
15
+ total: number;
16
+ failed: number;
17
+ constructor(errors: {
18
+ error: Error;
19
+ metadata: M;
20
+ }[], total: number, failed: number);
21
+ }
3
22
  type ValidMetadata = string | number | boolean | Record<string, unknown>;
4
23
  type RunProps = {
5
24
  delayStart?: (index: number) => number;
@@ -33,7 +52,7 @@ declare class ConcurrentCalls<R = unknown, E extends Error = Error> {
33
52
  failures: E[];
34
53
  succeeded: R[];
35
54
  total: number;
36
- aggregatedError: AggregateError | null;
55
+ aggregatedError: ConcurrentCallsAggregateError | null;
37
56
  }>;
38
57
  }
39
58
  /**
@@ -62,7 +81,7 @@ declare class ConcurrentCallsWithMetadata<M extends ValidMetadata, R = unknown,
62
81
  succeeded: SucceededCall<R, M>[];
63
82
  total: number;
64
83
  results: SettledResultWithMetadata<R, M, E>[];
65
- aggregatedError: AggregateError | null;
84
+ aggregatedError: ConcurrentCallsWithMetadataAggregateError<M> | null;
66
85
  }>;
67
86
  }
68
87
  /**
@@ -74,4 +93,4 @@ declare class ConcurrentCallsWithMetadata<M extends ValidMetadata, R = unknown,
74
93
  */
75
94
  declare function concurrentCallsWithMetadata<M extends ValidMetadata, R = unknown>(): ConcurrentCallsWithMetadata<M, R, Error>;
76
95
 
77
- export { concurrentCalls, concurrentCallsWithMetadata };
96
+ export { ConcurrentCallsAggregateError, ConcurrentCallsWithMetadataAggregateError, concurrentCalls, concurrentCallsWithMetadata };
@@ -1,5 +1,24 @@
1
1
  import { Result } from 't-result';
2
2
 
3
+ declare class ConcurrentCallsAggregateError extends AggregateError {
4
+ errors: Error[];
5
+ total: number;
6
+ failed: number;
7
+ constructor(errors: Error[], total: number, failed: number);
8
+ }
9
+ declare class ConcurrentCallsWithMetadataAggregateError<M extends ValidMetadata> extends AggregateError {
10
+ errors: Error[];
11
+ errorsWithMetadata: {
12
+ error: Error;
13
+ metadata: M;
14
+ }[];
15
+ total: number;
16
+ failed: number;
17
+ constructor(errors: {
18
+ error: Error;
19
+ metadata: M;
20
+ }[], total: number, failed: number);
21
+ }
3
22
  type ValidMetadata = string | number | boolean | Record<string, unknown>;
4
23
  type RunProps = {
5
24
  delayStart?: (index: number) => number;
@@ -33,7 +52,7 @@ declare class ConcurrentCalls<R = unknown, E extends Error = Error> {
33
52
  failures: E[];
34
53
  succeeded: R[];
35
54
  total: number;
36
- aggregatedError: AggregateError | null;
55
+ aggregatedError: ConcurrentCallsAggregateError | null;
37
56
  }>;
38
57
  }
39
58
  /**
@@ -62,7 +81,7 @@ declare class ConcurrentCallsWithMetadata<M extends ValidMetadata, R = unknown,
62
81
  succeeded: SucceededCall<R, M>[];
63
82
  total: number;
64
83
  results: SettledResultWithMetadata<R, M, E>[];
65
- aggregatedError: AggregateError | null;
84
+ aggregatedError: ConcurrentCallsWithMetadataAggregateError<M> | null;
66
85
  }>;
67
86
  }
68
87
  /**
@@ -74,4 +93,4 @@ declare class ConcurrentCallsWithMetadata<M extends ValidMetadata, R = unknown,
74
93
  */
75
94
  declare function concurrentCallsWithMetadata<M extends ValidMetadata, R = unknown>(): ConcurrentCallsWithMetadata<M, R, Error>;
76
95
 
77
- export { concurrentCalls, concurrentCallsWithMetadata };
96
+ export { ConcurrentCallsAggregateError, ConcurrentCallsWithMetadataAggregateError, concurrentCalls, concurrentCallsWithMetadata };
@@ -11,11 +11,73 @@ import {
11
11
  invariant
12
12
  } from "./chunk-C2SVCIWE.js";
13
13
  import {
14
+ isObject,
14
15
  isPromise
15
16
  } from "./chunk-JF2MDHOJ.js";
16
17
 
17
18
  // src/concurrentCalls.ts
18
19
  import { Result, resultify, unknownToError } from "t-result";
20
+ function formatErrorMessagesWithCounts(messages, failed, total) {
21
+ const errorMessageCounts = /* @__PURE__ */ new Map();
22
+ for (const message of messages) {
23
+ errorMessageCounts.set(message, (errorMessageCounts.get(message) || 0) + 1);
24
+ }
25
+ const formattedMessages = Array.from(errorMessageCounts.entries()).map(
26
+ ([message, count]) => count > 1 ? `${message} (${count}x)` : message
27
+ );
28
+ return `${failed}/${total} calls failed:
29
+ ${truncateArray(
30
+ formattedMessages,
31
+ 5,
32
+ "..."
33
+ ).join("\n")}`;
34
+ }
35
+ var ConcurrentCallsAggregateError = class extends AggregateError {
36
+ errors = [];
37
+ total = 0;
38
+ failed = 0;
39
+ constructor(errors, total, failed) {
40
+ const messages = errors.map(
41
+ (error) => `- ${truncateString(error.message, 100)}`
42
+ );
43
+ const message = formatErrorMessagesWithCounts(messages, failed, total);
44
+ super(errors, message);
45
+ this.errors = errors;
46
+ this.total = total;
47
+ this.failed = failed;
48
+ }
49
+ };
50
+ var ConcurrentCallsWithMetadataAggregateError = class extends AggregateError {
51
+ errors = [];
52
+ errorsWithMetadata = [];
53
+ total = 0;
54
+ failed = 0;
55
+ constructor(errors, total, failed) {
56
+ const messages = errors.map(({ error, metadata }) => {
57
+ let metadataPrefix = typeof metadata === "string" || typeof metadata === "number" || typeof metadata === "boolean" ? `${metadata}: ` : "";
58
+ try {
59
+ const isArray = Array.isArray(metadata);
60
+ if (isObject(metadata) || isArray) {
61
+ const stringifiedMetadata = JSON.stringify(metadata);
62
+ if (stringifiedMetadata.length < 30) {
63
+ metadataPrefix = `${stringifiedMetadata}: `;
64
+ } else {
65
+ metadataPrefix = `[${isArray ? "Array" : "Object"} metadata]: `;
66
+ }
67
+ }
68
+ } catch (_) {
69
+ }
70
+ return `- ${metadataPrefix}${truncateString(error.message, 100)}`;
71
+ });
72
+ const message = formatErrorMessagesWithCounts(messages, failed, total);
73
+ const errorInstances = errors.map((e) => e.error);
74
+ super(errorInstances, message);
75
+ this.errors = errorInstances;
76
+ this.errorsWithMetadata = errors;
77
+ this.total = total;
78
+ this.failed = failed;
79
+ }
80
+ };
19
81
  var ConcurrentCalls = class {
20
82
  #pendingCalls = [];
21
83
  #alreadyRun = false;
@@ -92,7 +154,7 @@ var ConcurrentCalls = class {
92
154
  }
93
155
  }
94
156
  const allFailed = failed.length === total;
95
- const aggregatedError = failed.length > 0 ? new AggregateError(failed, "One or more calls failed") : null;
157
+ const aggregatedError = failed.length > 0 ? new ConcurrentCallsAggregateError(failed, total, failed.length) : null;
96
158
  this.#pendingCalls = [];
97
159
  return {
98
160
  succeeded,
@@ -218,13 +280,10 @@ var ConcurrentCallsWithMetadata = class {
218
280
  }
219
281
  }
220
282
  const allFailed = failedProcessing.length === total;
221
- const aggregatedError = failedProcessing.length > 0 ? new AggregateError(
222
- failedProcessing.map((f) => f.error),
223
- `${failedProcessing.length}/${total} calls failed: ${truncateArray(
224
- failedProcessing.map((f) => truncateString(f.error.message, 20)),
225
- 5,
226
- "..."
227
- ).join("; ")}`
283
+ const aggregatedError = failedProcessing.length > 0 ? new ConcurrentCallsWithMetadataAggregateError(
284
+ failedProcessing,
285
+ total,
286
+ failedProcessing.length
228
287
  ) : null;
229
288
  return {
230
289
  succeeded: succeededProcessing,
@@ -241,6 +300,8 @@ function concurrentCallsWithMetadata() {
241
300
  return new ConcurrentCallsWithMetadata();
242
301
  }
243
302
  export {
303
+ ConcurrentCallsAggregateError,
304
+ ConcurrentCallsWithMetadataAggregateError,
244
305
  concurrentCalls,
245
306
  concurrentCallsWithMetadata
246
307
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ls-stack/utils",
3
3
  "description": "Universal TypeScript utilities for browser and Node.js",
4
- "version": "3.27.2",
4
+ "version": "3.28.0",
5
5
  "license": "MIT",
6
6
  "files": [
7
7
  "lib",