@dxos/util 0.5.9-main.ea1d25b → 0.5.9-main.eacfffa

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.
@@ -1531,6 +1531,43 @@ var DeepMapper = class {
1531
1531
  return this._fn(value, this._recurse);
1532
1532
  }
1533
1533
  };
1534
+ var deepMapValuesAsync = (value, fn) => {
1535
+ return new DeepMapperAsync(fn).map(value);
1536
+ };
1537
+ var DeepMapperAsync = class {
1538
+ constructor(_fn) {
1539
+ this._fn = _fn;
1540
+ this._cyclic = /* @__PURE__ */ new Map();
1541
+ this._recurse = async (value) => {
1542
+ if (this._cyclic.has(value)) {
1543
+ return this._cyclic.get(value);
1544
+ }
1545
+ if (Array.isArray(value)) {
1546
+ const res = new Array(value.length);
1547
+ this._cyclic.set(value, res);
1548
+ for (let i = 0; i < value.length; i++) {
1549
+ res[i] = await this.map(value[i]);
1550
+ }
1551
+ return res;
1552
+ } else if (value !== null && typeof value === "object") {
1553
+ const res = {};
1554
+ this._cyclic.set(value, res);
1555
+ for (const key in value) {
1556
+ res[key] = await this.map(value[key]);
1557
+ }
1558
+ return res;
1559
+ } else {
1560
+ return value;
1561
+ }
1562
+ };
1563
+ }
1564
+ map(value) {
1565
+ if (this._cyclic.has(value)) {
1566
+ return this._cyclic.get(value);
1567
+ }
1568
+ return this._fn(value, this._recurse);
1569
+ }
1570
+ };
1534
1571
 
1535
1572
  // packages/common/util/src/explicit-resource-management-polyfill.ts
1536
1573
  Symbol.dispose ??= Symbol("Symbol.dispose");
@@ -1646,6 +1683,24 @@ var throwUnhandledError = (error) => {
1646
1683
  throw error;
1647
1684
  });
1648
1685
  };
1686
+
1687
+ // packages/common/util/src/safe-await.ts
1688
+ var safeAwaitAll = async (source, taskFactory, onError) => {
1689
+ const failedItems = [];
1690
+ await Promise.all([
1691
+ ...source
1692
+ ].map(async (item, idx) => {
1693
+ try {
1694
+ await taskFactory(item);
1695
+ } catch (err) {
1696
+ if (onError) {
1697
+ onError(err, item, idx);
1698
+ }
1699
+ failedItems.push(item);
1700
+ }
1701
+ }));
1702
+ return failedItems;
1703
+ };
1649
1704
  export {
1650
1705
  BitField,
1651
1706
  Callback,
@@ -1673,6 +1728,7 @@ export {
1673
1728
  createGroupReducer,
1674
1729
  createSetDispatch,
1675
1730
  deepMapValues,
1731
+ deepMapValuesAsync,
1676
1732
  defaultMap,
1677
1733
  defer,
1678
1734
  deferAsync,
@@ -1723,6 +1779,7 @@ export {
1723
1779
  reduceSeries,
1724
1780
  reduceSet,
1725
1781
  safariCheck,
1782
+ safeAwaitAll,
1726
1783
  safeInstanceof,
1727
1784
  safeParseInt,
1728
1785
  safeParseJson,