zeed 0.7.127 → 0.7.128

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.
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-VD7O2RRX.js";
7
7
  import {
8
8
  isBrowser
9
- } from "./chunk-46Z3QUGD.js";
9
+ } from "./chunk-EVTXRPQ2.js";
10
10
  import {
11
11
  Logger,
12
12
  __name,
@@ -330,4 +330,4 @@ export {
330
330
  LocalStorage,
331
331
  LoggerBrowserClassicHandler
332
332
  };
333
- //# sourceMappingURL=chunk-JQJFUSJT.js.map
333
+ //# sourceMappingURL=chunk-AQQCGESZ.js.map
@@ -1614,85 +1614,6 @@ function useAsyncMutex() {
1614
1614
  }
1615
1615
  __name(useAsyncMutex, "useAsyncMutex");
1616
1616
 
1617
- // src/common/uuid.ts
1618
- var { encode: encode62, decode: decode62 } = useBase(62);
1619
- var { encode: encode32, decode: decode32 } = useBase(32);
1620
- function uuidBytes() {
1621
- return randomUint8Array(16);
1622
- }
1623
- __name(uuidBytes, "uuidBytes");
1624
- var uuid32bit = /* @__PURE__ */ __name(() => new Uint32Array(randomUint8Array(4))[0], "uuid32bit");
1625
- function uuid() {
1626
- return encode62(uuidBytes(), 22);
1627
- }
1628
- __name(uuid, "uuid");
1629
- function uuidEncode(bytes) {
1630
- return encode62(bytes, 22);
1631
- }
1632
- __name(uuidEncode, "uuidEncode");
1633
- function uuidDecode(uuid2) {
1634
- return decode62(uuid2, 16);
1635
- }
1636
- __name(uuidDecode, "uuidDecode");
1637
- function uuidB32() {
1638
- return encode32(uuidBytes(), 26);
1639
- }
1640
- __name(uuidB32, "uuidB32");
1641
- function uuid32Encode(bytes) {
1642
- return encode32(bytes, 26);
1643
- }
1644
- __name(uuid32Encode, "uuid32Encode");
1645
- function uuid32Decode(uuid2) {
1646
- return decode32(uuid2, 16);
1647
- }
1648
- __name(uuid32Decode, "uuid32Decode");
1649
- var _unameCounters = {};
1650
- function uname(name = "id") {
1651
- if (_unameCounters[name] == null) {
1652
- _unameCounters[name] = 0;
1653
- }
1654
- return `${name}-${_unameCounters[name]++}`;
1655
- }
1656
- __name(uname, "uname");
1657
- var _qid = 0;
1658
- function qid() {
1659
- return `id-${_qid++}`;
1660
- }
1661
- __name(qid, "qid");
1662
- var pattern = "10000000-1000-4000-8000-100000000000";
1663
- var uuidv4 = /* @__PURE__ */ __name(() => pattern.replace(/[018]/g, (c) => (c ^ randomUint8Array(1)[0] & 15 >> c / 4).toString(16)), "uuidv4");
1664
- var ReferenceDateInMS = 16e11;
1665
- function longToByteArray(long) {
1666
- var byteArray = new Uint8Array([0, 0, 0, 0, 0, 0]);
1667
- const bytes = byteArray.length - 1;
1668
- for (var index = 0; index < byteArray.length; index++) {
1669
- var byte = long & 255;
1670
- byteArray[bytes - index] = byte;
1671
- long = (long - byte) / 256;
1672
- }
1673
- return byteArray;
1674
- }
1675
- __name(longToByteArray, "longToByteArray");
1676
- function suidBytes() {
1677
- const ms = getTimestamp() - ReferenceDateInMS;
1678
- return new Uint8Array([...longToByteArray(ms), ...randomUint8Array(10)]);
1679
- }
1680
- __name(suidBytes, "suidBytes");
1681
- function suid() {
1682
- return encode62(suidBytes(), 22);
1683
- }
1684
- __name(suid, "suid");
1685
- function suidDate(id) {
1686
- return suidBytesDate(decode62(id, 16));
1687
- }
1688
- __name(suidDate, "suidDate");
1689
- function suidBytesDate(id) {
1690
- return new Date(ReferenceDateInMS + id.slice(0, 6).reduce((acc, byte) => {
1691
- return acc * 256 + byte;
1692
- }, 0));
1693
- }
1694
- __name(suidBytesDate, "suidBytesDate");
1695
-
1696
1617
  // src/common/msg/emitter.ts
1697
1618
  var log5 = Logger("zeed:emitter");
1698
1619
  var Emitter = class {
@@ -1838,6 +1759,85 @@ function lazyListener(emitter, listenerKey) {
1838
1759
  }
1839
1760
  __name(lazyListener, "lazyListener");
1840
1761
 
1762
+ // src/common/uuid.ts
1763
+ var { encode: encode62, decode: decode62 } = useBase(62);
1764
+ var { encode: encode32, decode: decode32 } = useBase(32);
1765
+ function uuidBytes() {
1766
+ return randomUint8Array(16);
1767
+ }
1768
+ __name(uuidBytes, "uuidBytes");
1769
+ var uuid32bit = /* @__PURE__ */ __name(() => new Uint32Array(randomUint8Array(4))[0], "uuid32bit");
1770
+ function uuid() {
1771
+ return encode62(uuidBytes(), 22);
1772
+ }
1773
+ __name(uuid, "uuid");
1774
+ function uuidEncode(bytes) {
1775
+ return encode62(bytes, 22);
1776
+ }
1777
+ __name(uuidEncode, "uuidEncode");
1778
+ function uuidDecode(uuid2) {
1779
+ return decode62(uuid2, 16);
1780
+ }
1781
+ __name(uuidDecode, "uuidDecode");
1782
+ function uuidB32() {
1783
+ return encode32(uuidBytes(), 26);
1784
+ }
1785
+ __name(uuidB32, "uuidB32");
1786
+ function uuid32Encode(bytes) {
1787
+ return encode32(bytes, 26);
1788
+ }
1789
+ __name(uuid32Encode, "uuid32Encode");
1790
+ function uuid32Decode(uuid2) {
1791
+ return decode32(uuid2, 16);
1792
+ }
1793
+ __name(uuid32Decode, "uuid32Decode");
1794
+ var _unameCounters = {};
1795
+ function uname(name = "id") {
1796
+ if (_unameCounters[name] == null) {
1797
+ _unameCounters[name] = 0;
1798
+ }
1799
+ return `${name}-${_unameCounters[name]++}`;
1800
+ }
1801
+ __name(uname, "uname");
1802
+ var _qid = 0;
1803
+ function qid() {
1804
+ return `id-${_qid++}`;
1805
+ }
1806
+ __name(qid, "qid");
1807
+ var pattern = "10000000-1000-4000-8000-100000000000";
1808
+ var uuidv4 = /* @__PURE__ */ __name(() => pattern.replace(/[018]/g, (c) => (c ^ randomUint8Array(1)[0] & 15 >> c / 4).toString(16)), "uuidv4");
1809
+ var ReferenceDateInMS = 16e11;
1810
+ function longToByteArray(long) {
1811
+ var byteArray = new Uint8Array([0, 0, 0, 0, 0, 0]);
1812
+ const bytes = byteArray.length - 1;
1813
+ for (var index = 0; index < byteArray.length; index++) {
1814
+ var byte = long & 255;
1815
+ byteArray[bytes - index] = byte;
1816
+ long = (long - byte) / 256;
1817
+ }
1818
+ return byteArray;
1819
+ }
1820
+ __name(longToByteArray, "longToByteArray");
1821
+ function suidBytes() {
1822
+ const ms = getTimestamp() - ReferenceDateInMS;
1823
+ return new Uint8Array([...longToByteArray(ms), ...randomUint8Array(10)]);
1824
+ }
1825
+ __name(suidBytes, "suidBytes");
1826
+ function suid() {
1827
+ return encode62(suidBytes(), 22);
1828
+ }
1829
+ __name(suid, "suid");
1830
+ function suidDate(id) {
1831
+ return suidBytesDate(decode62(id, 16));
1832
+ }
1833
+ __name(suidDate, "suidDate");
1834
+ function suidBytesDate(id) {
1835
+ return new Date(ReferenceDateInMS + id.slice(0, 6).reduce((acc, byte) => {
1836
+ return acc * 256 + byte;
1837
+ }, 0));
1838
+ }
1839
+ __name(suidBytesDate, "suidBytesDate");
1840
+
1841
1841
  // src/common/exec/pool.ts
1842
1842
  function usePool(config = {}) {
1843
1843
  const { maxParallel = 3 } = config;
@@ -1853,13 +1853,23 @@ function usePool(config = {}) {
1853
1853
  countResolved = 0;
1854
1854
  }
1855
1855
  __name(didFinish, "didFinish");
1856
+ function didUpdate() {
1857
+ let presentMax = 0;
1858
+ let presentResolved = 0;
1859
+ for (const { max, resolved, state } of Object.values(tasks)) {
1860
+ presentMax += max;
1861
+ presentResolved += state === 2 /* finished */ ? max : Math.min(max, resolved);
1862
+ }
1863
+ events.emit("didUpdate", countMax, countResolved, presentMax, presentResolved);
1864
+ }
1865
+ __name(didUpdate, "didUpdate");
1856
1866
  function performNext() {
1857
- events.emit("didUpdate", countMax, countResolved);
1867
+ didUpdate();
1858
1868
  if (countMax > 0 && countMax === countResolved)
1859
1869
  didFinish();
1860
1870
  if (currentParallel >= maxParallel)
1861
1871
  return;
1862
- let waitingTasks = Object.values(tasks).filter((t) => !t.running);
1872
+ let waitingTasks = Object.values(tasks).filter((t) => t.state === 0 /* waiting */);
1863
1873
  if (waitingTasks.length > 0) {
1864
1874
  let taskInfo;
1865
1875
  for (let t of waitingTasks) {
@@ -1867,28 +1877,29 @@ function usePool(config = {}) {
1867
1877
  taskInfo = t;
1868
1878
  }
1869
1879
  }
1870
- if (taskInfo) {
1880
+ if (taskInfo != null) {
1871
1881
  const id = taskInfo.id;
1872
1882
  const done = taskInfo.done;
1873
- taskInfo.running = true;
1883
+ taskInfo.state = 1 /* running */;
1874
1884
  ++currentParallel;
1875
1885
  events.emit("didStart", id);
1876
- taskInfo.task().then((r) => {
1877
- delete tasks[id];
1878
- events.emit("didResolve", id, r);
1879
- if (done)
1880
- done(r);
1886
+ const taskFinished = /* @__PURE__ */ __name(() => {
1887
+ if (taskInfo) {
1888
+ taskInfo.state = 2 /* finished */;
1889
+ taskInfo.resolved = taskInfo.max;
1890
+ }
1881
1891
  --currentParallel;
1882
1892
  ++countResolved;
1883
1893
  performNext();
1894
+ }, "taskFinished");
1895
+ taskInfo.task(taskInfo).then((r) => {
1896
+ done(r);
1897
+ events.emit("didResolve", id, r);
1898
+ taskFinished();
1884
1899
  }).catch((err) => {
1885
- delete tasks[id];
1900
+ done();
1886
1901
  events.emit("didReject", id, err);
1887
- if (done)
1888
- done();
1889
- --currentParallel;
1890
- ++countResolved;
1891
- performNext();
1902
+ taskFinished();
1892
1903
  });
1893
1904
  }
1894
1905
  }
@@ -1896,11 +1907,11 @@ function usePool(config = {}) {
1896
1907
  __name(performNext, "performNext");
1897
1908
  function cancel(id) {
1898
1909
  let taskInfo = tasks[id];
1899
- if (taskInfo && taskInfo.running !== true) {
1900
- delete tasks[id];
1910
+ if (taskInfo && taskInfo.state === 0 /* waiting */) {
1911
+ tasks[id].state = 2 /* finished */;
1901
1912
  ++countResolved;
1902
1913
  events.emit("didCancel", id);
1903
- events.emit("didUpdate", countMax, countResolved);
1914
+ didUpdate();
1904
1915
  }
1905
1916
  }
1906
1917
  __name(cancel, "cancel");
@@ -1909,18 +1920,32 @@ function usePool(config = {}) {
1909
1920
  }
1910
1921
  __name(cancelAll, "cancelAll");
1911
1922
  function enqueue(task, config2 = {}) {
1912
- let promise;
1913
- let { id } = config2;
1914
- if (!id)
1915
- id = uuid();
1923
+ var _a, _b, _c;
1924
+ let done;
1925
+ let promise = new Promise((resolve) => done = resolve);
1926
+ let id = (_a = config2.id) != null ? _a : uuid();
1916
1927
  if (tasks[id] == null) {
1917
1928
  tasks[id] = {
1918
1929
  id,
1919
1930
  task,
1920
1931
  priority: ++priority,
1921
- running: false
1932
+ state: 0 /* waiting */,
1933
+ max: (_b = config2.max) != null ? _b : 1,
1934
+ resolved: (_c = config2.resolved) != null ? _c : 0,
1935
+ done,
1936
+ setMax(max) {
1937
+ tasks[id].max = max;
1938
+ didUpdate();
1939
+ },
1940
+ setResolved(max) {
1941
+ tasks[id].resolved = max;
1942
+ didUpdate();
1943
+ },
1944
+ incResolved(inc = 1) {
1945
+ tasks[id].resolved += inc;
1946
+ didUpdate();
1947
+ }
1922
1948
  };
1923
- promise = new Promise((resolve) => tasks[id].done = resolve);
1924
1949
  ++countMax;
1925
1950
  performNext();
1926
1951
  }
@@ -2821,6 +2846,10 @@ export {
2821
2846
  useEventListener,
2822
2847
  useMutex,
2823
2848
  useAsyncMutex,
2849
+ Emitter,
2850
+ getGlobalEmitter,
2851
+ messages,
2852
+ lazyListener,
2824
2853
  uuidBytes,
2825
2854
  uuid32bit,
2826
2855
  uuid,
@@ -2836,10 +2865,6 @@ export {
2836
2865
  suid,
2837
2866
  suidDate,
2838
2867
  suidBytesDate,
2839
- Emitter,
2840
- getGlobalEmitter,
2841
- messages,
2842
- lazyListener,
2843
2868
  usePool,
2844
2869
  SerialQueue,
2845
2870
  throttle,
@@ -2871,4 +2896,4 @@ export {
2871
2896
  useExitHandler,
2872
2897
  MemStorage
2873
2898
  };
2874
- //# sourceMappingURL=chunk-46Z3QUGD.js.map
2899
+ //# sourceMappingURL=chunk-EVTXRPQ2.js.map