@ls-stack/utils 3.31.0 → 3.33.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/docs/arrayUtils/-internal-.md +138 -0
- package/docs/arrayUtils/README.md +50 -14
- package/docs/concurrentCalls/-internal-.md +96 -28
- package/docs/concurrentCalls/README.md +68 -18
- package/lib/arrayUtils.cjs +9 -0
- package/lib/arrayUtils.d.cts +36 -4
- package/lib/arrayUtils.d.ts +36 -4
- package/lib/arrayUtils.js +3 -1
- package/lib/{chunk-SRVMMYSW.js → chunk-RYBJST64.js} +9 -1
- package/lib/{chunk-J3ILVKZC.js → chunk-XUNY3QUT.js} +1 -1
- package/lib/concurrentCalls.cjs +49 -6
- package/lib/concurrentCalls.d.cts +31 -15
- package/lib/concurrentCalls.d.ts +31 -15
- package/lib/concurrentCalls.js +46 -7
- package/lib/filterObjectOrArrayKeys.js +2 -2
- package/lib/serializeXML.cjs +1 -1
- package/lib/serializeXML.js +2 -2
- package/lib/testUtils.js +2 -2
- package/package.json +1 -1
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
### ConcurrentCallsAggregateError
|
|
16
16
|
|
|
17
|
-
Defined in: [packages/utils/src/concurrentCalls.ts:
|
|
17
|
+
Defined in: [packages/utils/src/concurrentCalls.ts:38](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L38)
|
|
18
18
|
|
|
19
19
|
#### Extends
|
|
20
20
|
|
|
@@ -31,13 +31,13 @@ new ConcurrentCallsAggregateError(
|
|
|
31
31
|
failed): ConcurrentCallsAggregateError;
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
Defined in: [packages/utils/src/concurrentCalls.ts:
|
|
34
|
+
Defined in: [packages/utils/src/concurrentCalls.ts:43](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L43)
|
|
35
35
|
|
|
36
36
|
###### Parameters
|
|
37
37
|
|
|
38
38
|
###### errors
|
|
39
39
|
|
|
40
|
-
`
|
|
40
|
+
`ResultValidErrors`[]
|
|
41
41
|
|
|
42
42
|
###### total
|
|
43
43
|
|
|
@@ -62,10 +62,10 @@ AggregateError.constructor
|
|
|
62
62
|
##### errors
|
|
63
63
|
|
|
64
64
|
```ts
|
|
65
|
-
errors:
|
|
65
|
+
errors: ResultValidErrors[] = [];
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
Defined in: [packages/utils/src/concurrentCalls.ts:
|
|
68
|
+
Defined in: [packages/utils/src/concurrentCalls.ts:39](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L39)
|
|
69
69
|
|
|
70
70
|
###### Overrides
|
|
71
71
|
|
|
@@ -79,7 +79,7 @@ AggregateError.errors
|
|
|
79
79
|
failed: number = 0;
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
Defined in: [packages/utils/src/concurrentCalls.ts:
|
|
82
|
+
Defined in: [packages/utils/src/concurrentCalls.ts:41](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L41)
|
|
83
83
|
|
|
84
84
|
##### total
|
|
85
85
|
|
|
@@ -87,13 +87,13 @@ Defined in: [packages/utils/src/concurrentCalls.ts:35](https://github.com/lucaso
|
|
|
87
87
|
total: number = 0;
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
Defined in: [packages/utils/src/concurrentCalls.ts:
|
|
90
|
+
Defined in: [packages/utils/src/concurrentCalls.ts:40](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L40)
|
|
91
91
|
|
|
92
92
|
***
|
|
93
93
|
|
|
94
94
|
### ConcurrentCallsWithMetadataAggregateError\<M\>
|
|
95
95
|
|
|
96
|
-
Defined in: [packages/utils/src/concurrentCalls.ts:
|
|
96
|
+
Defined in: [packages/utils/src/concurrentCalls.ts:62](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L62)
|
|
97
97
|
|
|
98
98
|
#### Extends
|
|
99
99
|
|
|
@@ -116,7 +116,7 @@ new ConcurrentCallsWithMetadataAggregateError<M>(
|
|
|
116
116
|
failed): ConcurrentCallsWithMetadataAggregateError<M>;
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
-
Defined in: [packages/utils/src/concurrentCalls.ts:
|
|
119
|
+
Defined in: [packages/utils/src/concurrentCalls.ts:70](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L70)
|
|
120
120
|
|
|
121
121
|
###### Parameters
|
|
122
122
|
|
|
@@ -147,10 +147,10 @@ AggregateError.constructor
|
|
|
147
147
|
##### errors
|
|
148
148
|
|
|
149
149
|
```ts
|
|
150
|
-
errors:
|
|
150
|
+
errors: ResultValidErrors[] = [];
|
|
151
151
|
```
|
|
152
152
|
|
|
153
|
-
Defined in: [packages/utils/src/concurrentCalls.ts:
|
|
153
|
+
Defined in: [packages/utils/src/concurrentCalls.ts:65](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L65)
|
|
154
154
|
|
|
155
155
|
###### Overrides
|
|
156
156
|
|
|
@@ -164,12 +164,12 @@ AggregateError.errors
|
|
|
164
164
|
errorsWithMetadata: object[] = [];
|
|
165
165
|
```
|
|
166
166
|
|
|
167
|
-
Defined in: [packages/utils/src/concurrentCalls.ts:
|
|
167
|
+
Defined in: [packages/utils/src/concurrentCalls.ts:66](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L66)
|
|
168
168
|
|
|
169
169
|
###### error
|
|
170
170
|
|
|
171
171
|
```ts
|
|
172
|
-
error:
|
|
172
|
+
error: ResultValidErrors;
|
|
173
173
|
```
|
|
174
174
|
|
|
175
175
|
###### metadata
|
|
@@ -184,7 +184,7 @@ metadata: M;
|
|
|
184
184
|
failed: number = 0;
|
|
185
185
|
```
|
|
186
186
|
|
|
187
|
-
Defined in: [packages/utils/src/concurrentCalls.ts:
|
|
187
|
+
Defined in: [packages/utils/src/concurrentCalls.ts:68](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L68)
|
|
188
188
|
|
|
189
189
|
##### total
|
|
190
190
|
|
|
@@ -192,7 +192,7 @@ Defined in: [packages/utils/src/concurrentCalls.ts:56](https://github.com/lucaso
|
|
|
192
192
|
total: number = 0;
|
|
193
193
|
```
|
|
194
194
|
|
|
195
|
-
Defined in: [packages/utils/src/concurrentCalls.ts:
|
|
195
|
+
Defined in: [packages/utils/src/concurrentCalls.ts:67](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L67)
|
|
196
196
|
|
|
197
197
|
## Functions
|
|
198
198
|
|
|
@@ -202,7 +202,7 @@ Defined in: [packages/utils/src/concurrentCalls.ts:55](https://github.com/lucaso
|
|
|
202
202
|
function concurrentCalls<R>(): ConcurrentCalls<R, Error>;
|
|
203
203
|
```
|
|
204
204
|
|
|
205
|
-
Defined in: [packages/utils/src/concurrentCalls.ts:
|
|
205
|
+
Defined in: [packages/utils/src/concurrentCalls.ts:273](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L273)
|
|
206
206
|
|
|
207
207
|
Executes multiple asynchronous calls concurrently and collects the results in a easier to use format.
|
|
208
208
|
|
|
@@ -226,9 +226,9 @@ The type of the result value.
|
|
|
226
226
|
function concurrentCallsWithMetadata<M, R>(): ConcurrentCallsWithMetadata<M, R, Error>;
|
|
227
227
|
```
|
|
228
228
|
|
|
229
|
-
Defined in: [packages/utils/src/concurrentCalls.ts:
|
|
229
|
+
Defined in: [packages/utils/src/concurrentCalls.ts:472](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L472)
|
|
230
230
|
|
|
231
|
-
Executes multiple asynchronous calls concurrently and collects the results in a easier to use format.
|
|
231
|
+
Executes multiple asynchronous calls concurrently with metadata for each call and collects the results in a easier to use format.
|
|
232
232
|
|
|
233
233
|
#### Type Parameters
|
|
234
234
|
|
|
@@ -247,3 +247,53 @@ The type of the result value.
|
|
|
247
247
|
#### Returns
|
|
248
248
|
|
|
249
249
|
[`ConcurrentCallsWithMetadata`](-internal-.md#concurrentcallswithmetadata)\<`M`, `R`, `Error`\>
|
|
250
|
+
|
|
251
|
+
***
|
|
252
|
+
|
|
253
|
+
### concurrentResultCalls()
|
|
254
|
+
|
|
255
|
+
```ts
|
|
256
|
+
function concurrentResultCalls<ResultFn>(): ConcurrentCalls<ValueFromResult<Awaited<ReturnType<ResultFn>>>, ErrorFromResult<Awaited<ReturnType<ResultFn>>>>;
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
Defined in: [packages/utils/src/concurrentCalls.ts:487](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L487)
|
|
260
|
+
|
|
261
|
+
Executes multiple asynchronous result calls concurrently and collects the results in a easier to use format.
|
|
262
|
+
|
|
263
|
+
#### Type Parameters
|
|
264
|
+
|
|
265
|
+
##### ResultFn
|
|
266
|
+
|
|
267
|
+
`ResultFn` *extends* (...`args`) => `Promise`\<`Result`\<`unknown`, `ResultValidErrors`\>\>
|
|
268
|
+
|
|
269
|
+
#### Returns
|
|
270
|
+
|
|
271
|
+
[`ConcurrentCalls`](-internal-.md#concurrentcalls)\<[`ValueFromResult`](-internal-.md#valuefromresult)\<`Awaited`\<`ReturnType`\<`ResultFn`\>\>\>, [`ErrorFromResult`](-internal-.md#errorfromresult)\<`Awaited`\<`ReturnType`\<`ResultFn`\>\>\>\>
|
|
272
|
+
|
|
273
|
+
***
|
|
274
|
+
|
|
275
|
+
### concurrentResultsWithMetadata()
|
|
276
|
+
|
|
277
|
+
```ts
|
|
278
|
+
function concurrentResultsWithMetadata<M, ResultFn>(): ConcurrentCallsWithMetadata<M, ValueFromResult<Awaited<ReturnType<ResultFn>>>, ErrorFromResult<Awaited<ReturnType<ResultFn>>>>;
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Defined in: [packages/utils/src/concurrentCalls.ts:504](https://github.com/lucasols/utils/blob/main/packages/utils/src/concurrentCalls.ts#L504)
|
|
282
|
+
|
|
283
|
+
Executes multiple asynchronous result calls concurrently with metadata for each call and collects the results in a easier to use format.
|
|
284
|
+
|
|
285
|
+
#### Type Parameters
|
|
286
|
+
|
|
287
|
+
##### M
|
|
288
|
+
|
|
289
|
+
`M` *extends* [`ValidMetadata`](-internal-.md#validmetadata)
|
|
290
|
+
|
|
291
|
+
##### ResultFn
|
|
292
|
+
|
|
293
|
+
`ResultFn` *extends* (...`args`) => `Promise`\<`Result`\<`unknown`, `ResultValidErrors`\>\>
|
|
294
|
+
|
|
295
|
+
The type of the result function that will be called.
|
|
296
|
+
|
|
297
|
+
#### Returns
|
|
298
|
+
|
|
299
|
+
[`ConcurrentCallsWithMetadata`](-internal-.md#concurrentcallswithmetadata)\<`M`, [`ValueFromResult`](-internal-.md#valuefromresult)\<`Awaited`\<`ReturnType`\<`ResultFn`\>\>\>, [`ErrorFromResult`](-internal-.md#errorfromresult)\<`Awaited`\<`ReturnType`\<`ResultFn`\>\>\>\>
|
package/lib/arrayUtils.cjs
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/arrayUtils.ts
|
|
21
21
|
var arrayUtils_exports = {};
|
|
22
22
|
__export(arrayUtils_exports, {
|
|
23
|
+
arrayOps: () => arrayOps,
|
|
23
24
|
arrayWithPrev: () => arrayWithPrev,
|
|
24
25
|
arrayWithPrevAndIndex: () => arrayWithPrevAndIndex,
|
|
25
26
|
filterAndMap: () => filterAndMap,
|
|
@@ -155,8 +156,16 @@ function truncateArray(array, maxLength, appendIfTruncated) {
|
|
|
155
156
|
}
|
|
156
157
|
return result;
|
|
157
158
|
}
|
|
159
|
+
function arrayOps(array) {
|
|
160
|
+
return {
|
|
161
|
+
filterAndMap: (mapFilter) => filterAndMap(array, mapFilter),
|
|
162
|
+
sortBy: (sortByValue, props) => sortBy(array, sortByValue, props),
|
|
163
|
+
rejectDuplicates: (getKey) => rejectDuplicates(array, getKey)
|
|
164
|
+
};
|
|
165
|
+
}
|
|
158
166
|
// Annotate the CommonJS export names for ESM import in node:
|
|
159
167
|
0 && (module.exports = {
|
|
168
|
+
arrayOps,
|
|
160
169
|
arrayWithPrev,
|
|
161
170
|
arrayWithPrevAndIndex,
|
|
162
171
|
filterAndMap,
|
package/lib/arrayUtils.d.cts
CHANGED
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
declare function filterAndMap<T, R>(array: IterableIterator<T> | readonly T[], mapFilter: (item: T, index: number) => false | R): R[];
|
|
22
22
|
type FilterAndMapReturn<T> = false | T;
|
|
23
23
|
type SortOrder = 'desc' | 'asc';
|
|
24
|
+
type SortByValue<T> = (item: T) => (number | string)[] | number | string;
|
|
25
|
+
type SortByProps = {
|
|
26
|
+
order?: SortOrder | SortOrder[];
|
|
27
|
+
} | SortOrder | SortOrder[];
|
|
24
28
|
/**
|
|
25
29
|
* Sort an array based on a value
|
|
26
30
|
*
|
|
@@ -42,9 +46,7 @@ type SortOrder = 'desc' | 'asc';
|
|
|
42
46
|
* // return a array to sort by multiple values
|
|
43
47
|
* const sortedItems = sortBy(items, (item) => [item.a, item.b]);
|
|
44
48
|
*/
|
|
45
|
-
declare function sortBy<T>(arr: T[], sortByValue:
|
|
46
|
-
order?: SortOrder | SortOrder[];
|
|
47
|
-
} | SortOrder | SortOrder[]): T[];
|
|
49
|
+
declare function sortBy<T>(arr: T[], sortByValue: SortByValue<T>, props?: SortByProps): T[];
|
|
48
50
|
declare function arrayWithPrev<T>(array: T[]): [current: T, prev: T | null][];
|
|
49
51
|
declare function arrayWithPrevAndIndex<T>(array: T[]): {
|
|
50
52
|
item: T;
|
|
@@ -58,5 +60,35 @@ declare function rejectArrayUndefinedValues<T extends unknown[]>(array: T): T;
|
|
|
58
60
|
declare function hasDuplicates<T>(array: T[], getKey?: (item: T) => unknown): boolean;
|
|
59
61
|
declare function rejectDuplicates<T>(array: T[], getKey?: (item: T) => unknown): T[];
|
|
60
62
|
declare function truncateArray<T>(array: T[], maxLength: number, appendIfTruncated?: T | ((truncatedCount: number) => T)): T[];
|
|
63
|
+
type ArrayOps<T> = {
|
|
64
|
+
/**
|
|
65
|
+
* Filter and map an array
|
|
66
|
+
*
|
|
67
|
+
* @param mapFilter - A function that takes an item and returns a value or `false`
|
|
68
|
+
* to reject the item.
|
|
69
|
+
* @example
|
|
70
|
+
* const items = [1, 2, 3];
|
|
71
|
+
*
|
|
72
|
+
* const enhancedItems = arrayOps(items);
|
|
73
|
+
*
|
|
74
|
+
* enhancedItems.filterAndMap((item) => item === 2 ? false : item);
|
|
75
|
+
*/
|
|
76
|
+
filterAndMap: <R>(mapFilter: (item: T, index: number) => false | R) => R[];
|
|
77
|
+
sortBy: (sortByValue: SortByValue<T>, props: SortByProps) => T[];
|
|
78
|
+
rejectDuplicates: (getKey: (item: T) => unknown) => T[];
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Enhance an array with extra methods
|
|
82
|
+
*
|
|
83
|
+
* @param array
|
|
84
|
+
* @example
|
|
85
|
+
*
|
|
86
|
+
* const enhancedItems = arrayOps(array);
|
|
87
|
+
*
|
|
88
|
+
* enhancedItems.filterAndMap((item) => item === 2 ? false : item);
|
|
89
|
+
* enhancedItems.sortBy((item) => item);
|
|
90
|
+
* enhancedItems.rejectDuplicates((item) => item);
|
|
91
|
+
*/
|
|
92
|
+
declare function arrayOps<T>(array: T[]): ArrayOps<T>;
|
|
61
93
|
|
|
62
|
-
export { type FilterAndMapReturn, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findBeforeIndex, hasDuplicates, isInArray, rejectArrayUndefinedValues, rejectDuplicates, sortBy, truncateArray };
|
|
94
|
+
export { type FilterAndMapReturn, arrayOps, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findBeforeIndex, hasDuplicates, isInArray, rejectArrayUndefinedValues, rejectDuplicates, sortBy, truncateArray };
|
package/lib/arrayUtils.d.ts
CHANGED
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
declare function filterAndMap<T, R>(array: IterableIterator<T> | readonly T[], mapFilter: (item: T, index: number) => false | R): R[];
|
|
22
22
|
type FilterAndMapReturn<T> = false | T;
|
|
23
23
|
type SortOrder = 'desc' | 'asc';
|
|
24
|
+
type SortByValue<T> = (item: T) => (number | string)[] | number | string;
|
|
25
|
+
type SortByProps = {
|
|
26
|
+
order?: SortOrder | SortOrder[];
|
|
27
|
+
} | SortOrder | SortOrder[];
|
|
24
28
|
/**
|
|
25
29
|
* Sort an array based on a value
|
|
26
30
|
*
|
|
@@ -42,9 +46,7 @@ type SortOrder = 'desc' | 'asc';
|
|
|
42
46
|
* // return a array to sort by multiple values
|
|
43
47
|
* const sortedItems = sortBy(items, (item) => [item.a, item.b]);
|
|
44
48
|
*/
|
|
45
|
-
declare function sortBy<T>(arr: T[], sortByValue:
|
|
46
|
-
order?: SortOrder | SortOrder[];
|
|
47
|
-
} | SortOrder | SortOrder[]): T[];
|
|
49
|
+
declare function sortBy<T>(arr: T[], sortByValue: SortByValue<T>, props?: SortByProps): T[];
|
|
48
50
|
declare function arrayWithPrev<T>(array: T[]): [current: T, prev: T | null][];
|
|
49
51
|
declare function arrayWithPrevAndIndex<T>(array: T[]): {
|
|
50
52
|
item: T;
|
|
@@ -58,5 +60,35 @@ declare function rejectArrayUndefinedValues<T extends unknown[]>(array: T): T;
|
|
|
58
60
|
declare function hasDuplicates<T>(array: T[], getKey?: (item: T) => unknown): boolean;
|
|
59
61
|
declare function rejectDuplicates<T>(array: T[], getKey?: (item: T) => unknown): T[];
|
|
60
62
|
declare function truncateArray<T>(array: T[], maxLength: number, appendIfTruncated?: T | ((truncatedCount: number) => T)): T[];
|
|
63
|
+
type ArrayOps<T> = {
|
|
64
|
+
/**
|
|
65
|
+
* Filter and map an array
|
|
66
|
+
*
|
|
67
|
+
* @param mapFilter - A function that takes an item and returns a value or `false`
|
|
68
|
+
* to reject the item.
|
|
69
|
+
* @example
|
|
70
|
+
* const items = [1, 2, 3];
|
|
71
|
+
*
|
|
72
|
+
* const enhancedItems = arrayOps(items);
|
|
73
|
+
*
|
|
74
|
+
* enhancedItems.filterAndMap((item) => item === 2 ? false : item);
|
|
75
|
+
*/
|
|
76
|
+
filterAndMap: <R>(mapFilter: (item: T, index: number) => false | R) => R[];
|
|
77
|
+
sortBy: (sortByValue: SortByValue<T>, props: SortByProps) => T[];
|
|
78
|
+
rejectDuplicates: (getKey: (item: T) => unknown) => T[];
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Enhance an array with extra methods
|
|
82
|
+
*
|
|
83
|
+
* @param array
|
|
84
|
+
* @example
|
|
85
|
+
*
|
|
86
|
+
* const enhancedItems = arrayOps(array);
|
|
87
|
+
*
|
|
88
|
+
* enhancedItems.filterAndMap((item) => item === 2 ? false : item);
|
|
89
|
+
* enhancedItems.sortBy((item) => item);
|
|
90
|
+
* enhancedItems.rejectDuplicates((item) => item);
|
|
91
|
+
*/
|
|
92
|
+
declare function arrayOps<T>(array: T[]): ArrayOps<T>;
|
|
61
93
|
|
|
62
|
-
export { type FilterAndMapReturn, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findBeforeIndex, hasDuplicates, isInArray, rejectArrayUndefinedValues, rejectDuplicates, sortBy, truncateArray };
|
|
94
|
+
export { type FilterAndMapReturn, arrayOps, arrayWithPrev, arrayWithPrevAndIndex, filterAndMap, findAfterIndex, findBeforeIndex, hasDuplicates, isInArray, rejectArrayUndefinedValues, rejectDuplicates, sortBy, truncateArray };
|
package/lib/arrayUtils.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
arrayOps,
|
|
2
3
|
arrayWithPrev,
|
|
3
4
|
arrayWithPrevAndIndex,
|
|
4
5
|
filterAndMap,
|
|
@@ -10,10 +11,11 @@ import {
|
|
|
10
11
|
rejectDuplicates,
|
|
11
12
|
sortBy,
|
|
12
13
|
truncateArray
|
|
13
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-RYBJST64.js";
|
|
14
15
|
import "./chunk-C2SVCIWE.js";
|
|
15
16
|
import "./chunk-JF2MDHOJ.js";
|
|
16
17
|
export {
|
|
18
|
+
arrayOps,
|
|
17
19
|
arrayWithPrev,
|
|
18
20
|
arrayWithPrevAndIndex,
|
|
19
21
|
filterAndMap,
|
|
@@ -115,6 +115,13 @@ function truncateArray(array, maxLength, appendIfTruncated) {
|
|
|
115
115
|
}
|
|
116
116
|
return result;
|
|
117
117
|
}
|
|
118
|
+
function arrayOps(array) {
|
|
119
|
+
return {
|
|
120
|
+
filterAndMap: (mapFilter) => filterAndMap(array, mapFilter),
|
|
121
|
+
sortBy: (sortByValue, props) => sortBy(array, sortByValue, props),
|
|
122
|
+
rejectDuplicates: (getKey) => rejectDuplicates(array, getKey)
|
|
123
|
+
};
|
|
124
|
+
}
|
|
118
125
|
|
|
119
126
|
export {
|
|
120
127
|
filterAndMap,
|
|
@@ -127,5 +134,6 @@ export {
|
|
|
127
134
|
rejectArrayUndefinedValues,
|
|
128
135
|
hasDuplicates,
|
|
129
136
|
rejectDuplicates,
|
|
130
|
-
truncateArray
|
|
137
|
+
truncateArray,
|
|
138
|
+
arrayOps
|
|
131
139
|
};
|
package/lib/concurrentCalls.cjs
CHANGED
|
@@ -23,7 +23,9 @@ __export(concurrentCalls_exports, {
|
|
|
23
23
|
ConcurrentCallsAggregateError: () => ConcurrentCallsAggregateError,
|
|
24
24
|
ConcurrentCallsWithMetadataAggregateError: () => ConcurrentCallsWithMetadataAggregateError,
|
|
25
25
|
concurrentCalls: () => concurrentCalls,
|
|
26
|
-
concurrentCallsWithMetadata: () => concurrentCallsWithMetadata
|
|
26
|
+
concurrentCallsWithMetadata: () => concurrentCallsWithMetadata,
|
|
27
|
+
concurrentResultCalls: () => concurrentResultCalls,
|
|
28
|
+
concurrentResultsWithMetadata: () => concurrentResultsWithMetadata
|
|
27
29
|
});
|
|
28
30
|
module.exports = __toCommonJS(concurrentCalls_exports);
|
|
29
31
|
var import_t_result = require("t-result");
|
|
@@ -60,6 +62,15 @@ function truncateArray(array, maxLength, appendIfTruncated) {
|
|
|
60
62
|
return result;
|
|
61
63
|
}
|
|
62
64
|
|
|
65
|
+
// src/safeJson.ts
|
|
66
|
+
function safeJsonStringify(value) {
|
|
67
|
+
try {
|
|
68
|
+
return JSON.stringify(value);
|
|
69
|
+
} catch (_) {
|
|
70
|
+
return void 0;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
63
74
|
// src/sleep.ts
|
|
64
75
|
function sleep(ms) {
|
|
65
76
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -93,7 +104,10 @@ var ConcurrentCallsAggregateError = class extends AggregateError {
|
|
|
93
104
|
failed = 0;
|
|
94
105
|
constructor(errors, total, failed) {
|
|
95
106
|
const messages = errors.map(
|
|
96
|
-
(error) => `- ${truncateString(
|
|
107
|
+
(error) => `- ${truncateString(
|
|
108
|
+
error instanceof Error ? error.message : safeJsonStringify(error) ?? "???",
|
|
109
|
+
100
|
|
110
|
+
)}`
|
|
97
111
|
);
|
|
98
112
|
const message = formatErrorMessagesWithCounts(messages, failed, total);
|
|
99
113
|
super(errors, message);
|
|
@@ -122,7 +136,10 @@ var ConcurrentCallsWithMetadataAggregateError = class extends AggregateError {
|
|
|
122
136
|
}
|
|
123
137
|
} catch (_) {
|
|
124
138
|
}
|
|
125
|
-
return `- ${metadataPrefix}${truncateString(
|
|
139
|
+
return `- ${metadataPrefix}${truncateString(
|
|
140
|
+
error instanceof Error ? error.message : safeJsonStringify(error) ?? "???",
|
|
141
|
+
100
|
|
142
|
+
)}`;
|
|
126
143
|
});
|
|
127
144
|
const message = formatErrorMessagesWithCounts(messages, failed, total);
|
|
128
145
|
const errorInstances = errors.map((e) => e.error);
|
|
@@ -136,11 +153,20 @@ var ConcurrentCallsWithMetadataAggregateError = class extends AggregateError {
|
|
|
136
153
|
var ConcurrentCalls = class {
|
|
137
154
|
#pendingCalls = [];
|
|
138
155
|
#alreadyRun = false;
|
|
156
|
+
allowResultify = true;
|
|
157
|
+
constructor(allowResultify) {
|
|
158
|
+
this.allowResultify = allowResultify;
|
|
159
|
+
}
|
|
139
160
|
add(...calls) {
|
|
140
161
|
this.#pendingCalls.push(...calls);
|
|
141
162
|
return this;
|
|
142
163
|
}
|
|
143
164
|
resultifyAdd(...calls) {
|
|
165
|
+
if (!this.allowResultify) {
|
|
166
|
+
throw new Error(
|
|
167
|
+
"resultifyAdd is not allowed when using concurrentResults"
|
|
168
|
+
);
|
|
169
|
+
}
|
|
144
170
|
const processedCalls = calls.map((call) => {
|
|
145
171
|
return async () => {
|
|
146
172
|
try {
|
|
@@ -221,11 +247,15 @@ var ConcurrentCalls = class {
|
|
|
221
247
|
}
|
|
222
248
|
};
|
|
223
249
|
function concurrentCalls() {
|
|
224
|
-
return new ConcurrentCalls();
|
|
250
|
+
return new ConcurrentCalls(true);
|
|
225
251
|
}
|
|
226
252
|
var ConcurrentCallsWithMetadata = class {
|
|
227
253
|
#pendingCalls = [];
|
|
228
254
|
#alreadyRun = false;
|
|
255
|
+
allowResultify = true;
|
|
256
|
+
constructor(allowResultify) {
|
|
257
|
+
this.allowResultify = allowResultify;
|
|
258
|
+
}
|
|
229
259
|
add(...calls) {
|
|
230
260
|
invariant(
|
|
231
261
|
!this.#alreadyRun,
|
|
@@ -235,6 +265,11 @@ var ConcurrentCallsWithMetadata = class {
|
|
|
235
265
|
return this;
|
|
236
266
|
}
|
|
237
267
|
resultifyAdd(...items) {
|
|
268
|
+
if (!this.allowResultify) {
|
|
269
|
+
throw new Error(
|
|
270
|
+
"resultifyAdd is not allowed when using concurrentResultsWithMetadata"
|
|
271
|
+
);
|
|
272
|
+
}
|
|
238
273
|
const processedItems = items.map(({ fn, metadata }) => {
|
|
239
274
|
const cb = () => (0, import_t_result.resultify)(async () => {
|
|
240
275
|
const valueOrPromise = fn();
|
|
@@ -352,12 +387,20 @@ var ConcurrentCallsWithMetadata = class {
|
|
|
352
387
|
}
|
|
353
388
|
};
|
|
354
389
|
function concurrentCallsWithMetadata() {
|
|
355
|
-
return new ConcurrentCallsWithMetadata();
|
|
390
|
+
return new ConcurrentCallsWithMetadata(true);
|
|
391
|
+
}
|
|
392
|
+
function concurrentResultCalls() {
|
|
393
|
+
return new ConcurrentCalls(false);
|
|
394
|
+
}
|
|
395
|
+
function concurrentResultsWithMetadata() {
|
|
396
|
+
return new ConcurrentCallsWithMetadata(false);
|
|
356
397
|
}
|
|
357
398
|
// Annotate the CommonJS export names for ESM import in node:
|
|
358
399
|
0 && (module.exports = {
|
|
359
400
|
ConcurrentCallsAggregateError,
|
|
360
401
|
ConcurrentCallsWithMetadataAggregateError,
|
|
361
402
|
concurrentCalls,
|
|
362
|
-
concurrentCallsWithMetadata
|
|
403
|
+
concurrentCallsWithMetadata,
|
|
404
|
+
concurrentResultCalls,
|
|
405
|
+
concurrentResultsWithMetadata
|
|
363
406
|
});
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { Result } from 't-result';
|
|
1
|
+
import { ResultValidErrors, Result } from 't-result';
|
|
2
2
|
|
|
3
3
|
declare class ConcurrentCallsAggregateError extends AggregateError {
|
|
4
|
-
errors:
|
|
4
|
+
errors: ResultValidErrors[];
|
|
5
5
|
total: number;
|
|
6
6
|
failed: number;
|
|
7
|
-
constructor(errors:
|
|
7
|
+
constructor(errors: ResultValidErrors[], total: number, failed: number);
|
|
8
8
|
}
|
|
9
9
|
declare class ConcurrentCallsWithMetadataAggregateError<M extends ValidMetadata> extends AggregateError {
|
|
10
|
-
errors:
|
|
10
|
+
errors: ResultValidErrors[];
|
|
11
11
|
errorsWithMetadata: {
|
|
12
|
-
error:
|
|
12
|
+
error: ResultValidErrors;
|
|
13
13
|
metadata: M;
|
|
14
14
|
}[];
|
|
15
15
|
total: number;
|
|
16
16
|
failed: number;
|
|
17
17
|
constructor(errors: {
|
|
18
|
-
error:
|
|
18
|
+
error: ResultValidErrors;
|
|
19
19
|
metadata: M;
|
|
20
20
|
}[], total: number, failed: number);
|
|
21
21
|
}
|
|
@@ -27,12 +27,12 @@ type SucceededCall<R, M> = {
|
|
|
27
27
|
value: R;
|
|
28
28
|
metadata: M;
|
|
29
29
|
};
|
|
30
|
-
type FailedCall<M, E extends
|
|
30
|
+
type FailedCall<M, E extends ResultValidErrors = Error> = {
|
|
31
31
|
metadata: M;
|
|
32
32
|
error: E;
|
|
33
33
|
};
|
|
34
|
-
type Action<R, E extends
|
|
35
|
-
type SettledResultWithMetadata<R, M, E extends
|
|
34
|
+
type Action<R, E extends ResultValidErrors> = () => Promise<Result<R, E>>;
|
|
35
|
+
type SettledResultWithMetadata<R, M, E extends ResultValidErrors = Error> = {
|
|
36
36
|
ok: true;
|
|
37
37
|
value: R;
|
|
38
38
|
metadata: M;
|
|
@@ -42,8 +42,10 @@ type SettledResultWithMetadata<R, M, E extends Error = Error> = {
|
|
|
42
42
|
error: E;
|
|
43
43
|
metadata: M;
|
|
44
44
|
};
|
|
45
|
-
declare class ConcurrentCalls<R = unknown, E extends
|
|
45
|
+
declare class ConcurrentCalls<R = unknown, E extends ResultValidErrors = Error> {
|
|
46
46
|
#private;
|
|
47
|
+
allowResultify: boolean;
|
|
48
|
+
constructor(allowResultify: boolean);
|
|
47
49
|
add(...calls: Action<R, E>[]): this;
|
|
48
50
|
resultifyAdd(...calls: ((() => R) | (() => Promise<R>))[]): this;
|
|
49
51
|
runAll({ delayStart }?: RunProps): Promise<Result<R[], E>>;
|
|
@@ -59,11 +61,12 @@ declare class ConcurrentCalls<R = unknown, E extends Error = Error> {
|
|
|
59
61
|
* Executes multiple asynchronous calls concurrently and collects the results in a easier to use format.
|
|
60
62
|
*
|
|
61
63
|
* @template R - The type of the result value.
|
|
62
|
-
* @template E - The type of the error.
|
|
63
64
|
*/
|
|
64
65
|
declare function concurrentCalls<R = unknown>(): ConcurrentCalls<R, Error>;
|
|
65
|
-
declare class ConcurrentCallsWithMetadata<M extends ValidMetadata, R = unknown, E extends
|
|
66
|
+
declare class ConcurrentCallsWithMetadata<M extends ValidMetadata, R = unknown, E extends ResultValidErrors = Error> {
|
|
66
67
|
#private;
|
|
68
|
+
allowResultify: boolean;
|
|
69
|
+
constructor(allowResultify: boolean);
|
|
67
70
|
add(...calls: {
|
|
68
71
|
fn: Action<R, E>;
|
|
69
72
|
metadata: M;
|
|
@@ -85,12 +88,25 @@ declare class ConcurrentCallsWithMetadata<M extends ValidMetadata, R = unknown,
|
|
|
85
88
|
}>;
|
|
86
89
|
}
|
|
87
90
|
/**
|
|
88
|
-
* Executes multiple asynchronous calls concurrently and collects the results in a easier to use format.
|
|
91
|
+
* Executes multiple asynchronous calls concurrently with metadata for each call and collects the results in a easier to use format.
|
|
89
92
|
*
|
|
90
93
|
* @template M - The type of the call metadata.
|
|
91
94
|
* @template R - The type of the result value.
|
|
92
|
-
* @template E - The type of the error from individual Result objects.
|
|
93
95
|
*/
|
|
94
96
|
declare function concurrentCallsWithMetadata<M extends ValidMetadata, R = unknown>(): ConcurrentCallsWithMetadata<M, R, Error>;
|
|
97
|
+
type ValueFromResult<R> = R extends Result<infer T, any> ? T : never;
|
|
98
|
+
type ErrorFromResult<R> = R extends Result<any, infer E> ? E : never;
|
|
99
|
+
/**
|
|
100
|
+
* Executes multiple asynchronous result calls concurrently and collects the results in a easier to use format.
|
|
101
|
+
*
|
|
102
|
+
* @template R - The type of the result function that will be called.
|
|
103
|
+
*/
|
|
104
|
+
declare function concurrentResultCalls<ResultFn extends (...args: any[]) => Promise<Result<unknown, ResultValidErrors>>>(): ConcurrentCalls<ValueFromResult<Awaited<ReturnType<ResultFn>>>, ErrorFromResult<Awaited<ReturnType<ResultFn>>>>;
|
|
105
|
+
/**
|
|
106
|
+
* Executes multiple asynchronous result calls concurrently with metadata for each call and collects the results in a easier to use format.
|
|
107
|
+
*
|
|
108
|
+
* @template ResultFn - The type of the result function that will be called.
|
|
109
|
+
*/
|
|
110
|
+
declare function concurrentResultsWithMetadata<M extends ValidMetadata, ResultFn extends (...args: any[]) => Promise<Result<unknown, ResultValidErrors>>>(): ConcurrentCallsWithMetadata<M, ValueFromResult<Awaited<ReturnType<ResultFn>>>, ErrorFromResult<Awaited<ReturnType<ResultFn>>>>;
|
|
95
111
|
|
|
96
|
-
export { ConcurrentCallsAggregateError, ConcurrentCallsWithMetadataAggregateError, concurrentCalls, concurrentCallsWithMetadata };
|
|
112
|
+
export { ConcurrentCallsAggregateError, ConcurrentCallsWithMetadataAggregateError, concurrentCalls, concurrentCallsWithMetadata, concurrentResultCalls, concurrentResultsWithMetadata };
|