@zelgadis87/utils-core 5.4.3 → 5.4.4

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/.rollup/index.cjs CHANGED
@@ -1276,6 +1276,7 @@ function wrapWithString(str, start, end = start) {
1276
1276
  }
1277
1277
 
1278
1278
  /**
1279
+
1279
1280
  * An error class that aggregates multiple errors from a combined operation.
1280
1281
  * Used by `Operation.combine` to represent failures from multiple operations.
1281
1282
  *
@@ -1295,6 +1296,31 @@ class OperationAggregateError extends Error {
1295
1296
  return this.errors.length;
1296
1297
  }
1297
1298
  }
1299
+ /**
1300
+ * Combines multiple operation results into a single result.
1301
+ * - If all operations succeed, returns success with an array of all data values.
1302
+ * - If any operation fails, returns failure with an `OperationAggregateError` containing all errors.
1303
+ *
1304
+ * When combining operations whose error type is already `OperationAggregateError<E>`,
1305
+ * the errors are automatically flattened to avoid nesting (e.g., combining results from
1306
+ * previous `combine` calls).
1307
+ *
1308
+ * @template T - The success data type of individual operations
1309
+ * @template E - The error type of individual operations (defaults to Error)
1310
+ * @param results - Array of operation results to combine
1311
+ * @returns A single operation with either all data or all aggregated errors (flattened)
1312
+ */
1313
+ function combine$1(results) {
1314
+ const [successes, failures] = partition(results, r => r.success);
1315
+ if (failures.length === 0) {
1316
+ return { success: true, data: successes.map(r => r.data) };
1317
+ }
1318
+ const allErrors = failures.flatMap(r => {
1319
+ const error = r.error;
1320
+ return error instanceof OperationAggregateError ? error.errors : [error];
1321
+ });
1322
+ return { success: false, error: new OperationAggregateError(allErrors) };
1323
+ }
1298
1324
  const Operation = {
1299
1325
  ok: (data) => {
1300
1326
  return { success: true, data };
@@ -1335,20 +1361,7 @@ const Operation = {
1335
1361
  partition: (results) => {
1336
1362
  return partition(results, r => r.success);
1337
1363
  },
1338
- /**
1339
- * Combines multiple operation results into a single result.
1340
- * - If all operations succeed, returns success with an array of all data values.
1341
- * - If any operation fails, returns failure with an `OperationAggregateError` containing all errors.
1342
- *
1343
- * @template T - The success data type of individual operations
1344
- * @template E - The error type of individual operations (defaults to Error)
1345
- * @param results - Array of operation results to combine
1346
- * @returns A single operation with either all data or all aggregated errors
1347
- */
1348
- combine: (results) => {
1349
- const [successes, failures] = Operation.partition(results);
1350
- return failures.length === 0 ? Operation.ok(successes.map(r => r.data)) : Operation.ko(new OperationAggregateError(failures.map(r => r.error)));
1351
- },
1364
+ combine: combine$1,
1352
1365
  };
1353
1366
 
1354
1367
  function asPromise(promisable) {