radashi 12.2.2 → 12.2.3

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/radashi.cjs CHANGED
@@ -371,27 +371,28 @@ var AggregateErrorOrPolyfill = /* @__PURE__ */ (() => globalThis.AggregateError
371
371
  })();
372
372
 
373
373
  // src/async/all.ts
374
- async function all(promises) {
375
- const entries = isArray(promises) ? promises.map((p) => [null, p]) : Object.entries(promises);
376
- const results = await Promise.all(
377
- entries.map(
378
- ([key, value]) => value.then((result) => ({ result, exc: null, key })).catch((exc) => ({ result: null, exc, key }))
379
- )
380
- );
381
- const exceptions = results.filter((r) => r.exc);
382
- if (exceptions.length > 0) {
383
- throw new AggregateErrorOrPolyfill(exceptions.map((e) => e.exc));
374
+ async function all(input) {
375
+ const errors = [];
376
+ const onError = (err) => {
377
+ errors.push(err);
378
+ };
379
+ let output;
380
+ if (isArray(input)) {
381
+ output = await Promise.all(
382
+ input.map((value) => Promise.resolve(value).catch(onError))
383
+ );
384
+ } else {
385
+ output = { ...input };
386
+ await Promise.all(
387
+ Object.keys(output).map(async (key) => {
388
+ output[key] = await Promise.resolve(output[key]).catch(onError);
389
+ })
390
+ );
384
391
  }
385
- if (isArray(promises)) {
386
- return results.map((r) => r.result);
392
+ if (errors.length > 0) {
393
+ throw new AggregateErrorOrPolyfill(errors);
387
394
  }
388
- return results.reduce(
389
- (acc, item) => {
390
- acc[item.key] = item.result;
391
- return acc;
392
- },
393
- {}
394
- );
395
+ return output;
395
396
  }
396
397
 
397
398
  // src/async/defer.ts
@@ -551,13 +551,9 @@ interface AggregateErrorConstructor {
551
551
  */
552
552
  declare const AggregateErrorOrPolyfill: AggregateErrorConstructor;
553
553
 
554
- type PromiseValues<T extends Promise<any>[]> = {
555
- [K in keyof T]: T[K] extends Promise<infer U> ? U : never;
556
- };
557
554
  /**
558
- * Functionally similar to `Promise.all` or `Promise.allSettled`. If
559
- * any errors are thrown, all errors are gathered and thrown in an
560
- * `AggregateError`.
555
+ * Wait for all promises to resolve. Errors from rejected promises are
556
+ * collected into an `AggregateError`.
561
557
  *
562
558
  * @see https://radashi.js.org/reference/async/all
563
559
  * @example
@@ -570,12 +566,20 @@ type PromiseValues<T extends Promise<any>[]> = {
570
566
  * ```
571
567
  * @version 12.1.0
572
568
  */
573
- declare function all<T extends [Promise<any>, ...Promise<any>[]]>(promises: T): Promise<PromiseValues<T>>;
574
- declare function all<T extends Promise<any>[]>(promises: T): Promise<PromiseValues<T>>;
569
+ declare function all<T extends readonly [unknown, ...unknown[]]>(input: T): Promise<{
570
+ -readonly [I in keyof T]: Awaited<T[I]>;
571
+ }>;
572
+ declare function all<T extends readonly unknown[]>(input: T): Promise<{
573
+ -readonly [I in keyof T]: Awaited<T[I]>;
574
+ }>;
575
575
  /**
576
- * Functionally similar to `Promise.all` or `Promise.allSettled`. If
577
- * any errors are thrown, all errors are gathered and thrown in an
578
- * `AggregateError`.
576
+ * Check each property in the given object for a promise value. Wait
577
+ * for all promises to resolve. Errors from rejected promises are
578
+ * collected into an `AggregateError`.
579
+ *
580
+ * The returned promise will resolve with an object whose keys are
581
+ * identical to the keys of the input object. The values are the
582
+ * resolved values of the promises.
579
583
  *
580
584
  * @see https://radashi.js.org/reference/async/all
581
585
  * @example
@@ -587,8 +591,8 @@ declare function all<T extends Promise<any>[]>(promises: T): Promise<PromiseValu
587
591
  * })
588
592
  * ```
589
593
  */
590
- declare function all<T extends Record<string, Promise<any>>>(promises: T): Promise<{
591
- [K in keyof T]: Awaited<T[K]>;
594
+ declare function all<T extends Record<string, unknown>>(input: T): Promise<{
595
+ -readonly [K in keyof T]: Awaited<T[K]>;
592
596
  }>;
593
597
 
594
598
  /**
package/dist/radashi.d.ts CHANGED
@@ -551,13 +551,9 @@ interface AggregateErrorConstructor {
551
551
  */
552
552
  declare const AggregateErrorOrPolyfill: AggregateErrorConstructor;
553
553
 
554
- type PromiseValues<T extends Promise<any>[]> = {
555
- [K in keyof T]: T[K] extends Promise<infer U> ? U : never;
556
- };
557
554
  /**
558
- * Functionally similar to `Promise.all` or `Promise.allSettled`. If
559
- * any errors are thrown, all errors are gathered and thrown in an
560
- * `AggregateError`.
555
+ * Wait for all promises to resolve. Errors from rejected promises are
556
+ * collected into an `AggregateError`.
561
557
  *
562
558
  * @see https://radashi.js.org/reference/async/all
563
559
  * @example
@@ -570,12 +566,20 @@ type PromiseValues<T extends Promise<any>[]> = {
570
566
  * ```
571
567
  * @version 12.1.0
572
568
  */
573
- declare function all<T extends [Promise<any>, ...Promise<any>[]]>(promises: T): Promise<PromiseValues<T>>;
574
- declare function all<T extends Promise<any>[]>(promises: T): Promise<PromiseValues<T>>;
569
+ declare function all<T extends readonly [unknown, ...unknown[]]>(input: T): Promise<{
570
+ -readonly [I in keyof T]: Awaited<T[I]>;
571
+ }>;
572
+ declare function all<T extends readonly unknown[]>(input: T): Promise<{
573
+ -readonly [I in keyof T]: Awaited<T[I]>;
574
+ }>;
575
575
  /**
576
- * Functionally similar to `Promise.all` or `Promise.allSettled`. If
577
- * any errors are thrown, all errors are gathered and thrown in an
578
- * `AggregateError`.
576
+ * Check each property in the given object for a promise value. Wait
577
+ * for all promises to resolve. Errors from rejected promises are
578
+ * collected into an `AggregateError`.
579
+ *
580
+ * The returned promise will resolve with an object whose keys are
581
+ * identical to the keys of the input object. The values are the
582
+ * resolved values of the promises.
579
583
  *
580
584
  * @see https://radashi.js.org/reference/async/all
581
585
  * @example
@@ -587,8 +591,8 @@ declare function all<T extends Promise<any>[]>(promises: T): Promise<PromiseValu
587
591
  * })
588
592
  * ```
589
593
  */
590
- declare function all<T extends Record<string, Promise<any>>>(promises: T): Promise<{
591
- [K in keyof T]: Awaited<T[K]>;
594
+ declare function all<T extends Record<string, unknown>>(input: T): Promise<{
595
+ -readonly [K in keyof T]: Awaited<T[K]>;
592
596
  }>;
593
597
 
594
598
  /**
package/dist/radashi.js CHANGED
@@ -369,27 +369,28 @@ var AggregateErrorOrPolyfill = /* @__PURE__ */ (() => globalThis.AggregateError
369
369
  })();
370
370
 
371
371
  // src/async/all.ts
372
- async function all(promises) {
373
- const entries = isArray(promises) ? promises.map((p) => [null, p]) : Object.entries(promises);
374
- const results = await Promise.all(
375
- entries.map(
376
- ([key, value]) => value.then((result) => ({ result, exc: null, key })).catch((exc) => ({ result: null, exc, key }))
377
- )
378
- );
379
- const exceptions = results.filter((r) => r.exc);
380
- if (exceptions.length > 0) {
381
- throw new AggregateErrorOrPolyfill(exceptions.map((e) => e.exc));
372
+ async function all(input) {
373
+ const errors = [];
374
+ const onError = (err) => {
375
+ errors.push(err);
376
+ };
377
+ let output;
378
+ if (isArray(input)) {
379
+ output = await Promise.all(
380
+ input.map((value) => Promise.resolve(value).catch(onError))
381
+ );
382
+ } else {
383
+ output = { ...input };
384
+ await Promise.all(
385
+ Object.keys(output).map(async (key) => {
386
+ output[key] = await Promise.resolve(output[key]).catch(onError);
387
+ })
388
+ );
382
389
  }
383
- if (isArray(promises)) {
384
- return results.map((r) => r.result);
390
+ if (errors.length > 0) {
391
+ throw new AggregateErrorOrPolyfill(errors);
385
392
  }
386
- return results.reduce(
387
- (acc, item) => {
388
- acc[item.key] = item.result;
389
- return acc;
390
- },
391
- {}
392
- );
393
+ return output;
393
394
  }
394
395
 
395
396
  // src/async/defer.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "radashi",
3
- "version": "12.2.2",
3
+ "version": "12.2.3",
4
4
  "type": "module",
5
5
  "description": "The modern, community-first TypeScript toolkit with all of the fast, readable, and minimal utility functions you need. Type-safe, dependency-free, tree-shakeable, fully tested.",
6
6
  "repository": {
@@ -50,6 +50,7 @@
50
50
  "@types/node": "^22.7.5",
51
51
  "@vitest/coverage-v8": "2.0.5",
52
52
  "cspell": "^8.13.3",
53
+ "execa": "^9.5.1",
53
54
  "prettier": "^3.3.2",
54
55
  "prettier-plugin-pkg": "^0.18.1",
55
56
  "prettier-plugin-sh": "^0.14.0",