@leofcoin/chain 1.6.8 → 1.6.10

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.
@@ -19,8 +19,9 @@ const debug$5 = (target, text) => {
19
19
  globalThis.DEBUG?.indexOf('*') !== -1 ||
20
20
  globalThis.DEBUG?.indexOf(target.split('/')[0]) !== -1
21
21
  )
22
- if (text) console.log('\x1b[34m\x1b[1m%s', `${target}: ${text}`, '\x1b[0m');
23
- else console.log('\x1b[34m\x1b[1m%s', `${target}`, '\x1b[0m');
22
+ if (text)
23
+ console.trace('\x1b[34m\x1b[1m%s', `${target}: ${text}`, '\x1b[0m');
24
+ else console.trace('\x1b[34m\x1b[1m%s', `${target}`, '\x1b[0m');
24
25
  };
25
26
 
26
27
  const createDebugger = (target) => (text) => debug$5(target, text);
@@ -1432,781 +1433,764 @@ function requireIterator () {
1432
1433
  return iterator;
1433
1434
  }
1434
1435
 
1435
- var yallist;
1436
- var hasRequiredYallist;
1436
+ var yallist = Yallist$1;
1437
1437
 
1438
- function requireYallist () {
1439
- if (hasRequiredYallist) return yallist;
1440
- hasRequiredYallist = 1;
1441
- yallist = Yallist;
1438
+ Yallist$1.Node = Node;
1439
+ Yallist$1.create = Yallist$1;
1442
1440
 
1443
- Yallist.Node = Node;
1444
- Yallist.create = Yallist;
1445
-
1446
- function Yallist (list) {
1447
- var self = this;
1448
- if (!(self instanceof Yallist)) {
1449
- self = new Yallist();
1450
- }
1441
+ function Yallist$1 (list) {
1442
+ var self = this;
1443
+ if (!(self instanceof Yallist$1)) {
1444
+ self = new Yallist$1();
1445
+ }
1451
1446
 
1452
- self.tail = null;
1453
- self.head = null;
1454
- self.length = 0;
1447
+ self.tail = null;
1448
+ self.head = null;
1449
+ self.length = 0;
1455
1450
 
1456
- if (list && typeof list.forEach === 'function') {
1457
- list.forEach(function (item) {
1458
- self.push(item);
1459
- });
1460
- } else if (arguments.length > 0) {
1461
- for (var i = 0, l = arguments.length; i < l; i++) {
1462
- self.push(arguments[i]);
1463
- }
1464
- }
1465
-
1466
- return self
1467
- }
1451
+ if (list && typeof list.forEach === 'function') {
1452
+ list.forEach(function (item) {
1453
+ self.push(item);
1454
+ });
1455
+ } else if (arguments.length > 0) {
1456
+ for (var i = 0, l = arguments.length; i < l; i++) {
1457
+ self.push(arguments[i]);
1458
+ }
1459
+ }
1468
1460
 
1469
- Yallist.prototype.removeNode = function (node) {
1470
- if (node.list !== this) {
1471
- throw new Error('removing node which does not belong to this list')
1472
- }
1461
+ return self
1462
+ }
1473
1463
 
1474
- var next = node.next;
1475
- var prev = node.prev;
1464
+ Yallist$1.prototype.removeNode = function (node) {
1465
+ if (node.list !== this) {
1466
+ throw new Error('removing node which does not belong to this list')
1467
+ }
1476
1468
 
1477
- if (next) {
1478
- next.prev = prev;
1479
- }
1469
+ var next = node.next;
1470
+ var prev = node.prev;
1480
1471
 
1481
- if (prev) {
1482
- prev.next = next;
1483
- }
1472
+ if (next) {
1473
+ next.prev = prev;
1474
+ }
1484
1475
 
1485
- if (node === this.head) {
1486
- this.head = next;
1487
- }
1488
- if (node === this.tail) {
1489
- this.tail = prev;
1490
- }
1476
+ if (prev) {
1477
+ prev.next = next;
1478
+ }
1491
1479
 
1492
- node.list.length--;
1493
- node.next = null;
1494
- node.prev = null;
1495
- node.list = null;
1480
+ if (node === this.head) {
1481
+ this.head = next;
1482
+ }
1483
+ if (node === this.tail) {
1484
+ this.tail = prev;
1485
+ }
1496
1486
 
1497
- return next
1498
- };
1487
+ node.list.length--;
1488
+ node.next = null;
1489
+ node.prev = null;
1490
+ node.list = null;
1499
1491
 
1500
- Yallist.prototype.unshiftNode = function (node) {
1501
- if (node === this.head) {
1502
- return
1503
- }
1492
+ return next
1493
+ };
1504
1494
 
1505
- if (node.list) {
1506
- node.list.removeNode(node);
1507
- }
1495
+ Yallist$1.prototype.unshiftNode = function (node) {
1496
+ if (node === this.head) {
1497
+ return
1498
+ }
1508
1499
 
1509
- var head = this.head;
1510
- node.list = this;
1511
- node.next = head;
1512
- if (head) {
1513
- head.prev = node;
1514
- }
1500
+ if (node.list) {
1501
+ node.list.removeNode(node);
1502
+ }
1515
1503
 
1516
- this.head = node;
1517
- if (!this.tail) {
1518
- this.tail = node;
1519
- }
1520
- this.length++;
1521
- };
1504
+ var head = this.head;
1505
+ node.list = this;
1506
+ node.next = head;
1507
+ if (head) {
1508
+ head.prev = node;
1509
+ }
1522
1510
 
1523
- Yallist.prototype.pushNode = function (node) {
1524
- if (node === this.tail) {
1525
- return
1526
- }
1511
+ this.head = node;
1512
+ if (!this.tail) {
1513
+ this.tail = node;
1514
+ }
1515
+ this.length++;
1516
+ };
1527
1517
 
1528
- if (node.list) {
1529
- node.list.removeNode(node);
1530
- }
1518
+ Yallist$1.prototype.pushNode = function (node) {
1519
+ if (node === this.tail) {
1520
+ return
1521
+ }
1531
1522
 
1532
- var tail = this.tail;
1533
- node.list = this;
1534
- node.prev = tail;
1535
- if (tail) {
1536
- tail.next = node;
1537
- }
1523
+ if (node.list) {
1524
+ node.list.removeNode(node);
1525
+ }
1538
1526
 
1539
- this.tail = node;
1540
- if (!this.head) {
1541
- this.head = node;
1542
- }
1543
- this.length++;
1544
- };
1527
+ var tail = this.tail;
1528
+ node.list = this;
1529
+ node.prev = tail;
1530
+ if (tail) {
1531
+ tail.next = node;
1532
+ }
1545
1533
 
1546
- Yallist.prototype.push = function () {
1547
- for (var i = 0, l = arguments.length; i < l; i++) {
1548
- push(this, arguments[i]);
1549
- }
1550
- return this.length
1551
- };
1534
+ this.tail = node;
1535
+ if (!this.head) {
1536
+ this.head = node;
1537
+ }
1538
+ this.length++;
1539
+ };
1552
1540
 
1553
- Yallist.prototype.unshift = function () {
1554
- for (var i = 0, l = arguments.length; i < l; i++) {
1555
- unshift(this, arguments[i]);
1556
- }
1557
- return this.length
1558
- };
1541
+ Yallist$1.prototype.push = function () {
1542
+ for (var i = 0, l = arguments.length; i < l; i++) {
1543
+ push(this, arguments[i]);
1544
+ }
1545
+ return this.length
1546
+ };
1559
1547
 
1560
- Yallist.prototype.pop = function () {
1561
- if (!this.tail) {
1562
- return undefined
1563
- }
1548
+ Yallist$1.prototype.unshift = function () {
1549
+ for (var i = 0, l = arguments.length; i < l; i++) {
1550
+ unshift(this, arguments[i]);
1551
+ }
1552
+ return this.length
1553
+ };
1564
1554
 
1565
- var res = this.tail.value;
1566
- this.tail = this.tail.prev;
1567
- if (this.tail) {
1568
- this.tail.next = null;
1569
- } else {
1570
- this.head = null;
1571
- }
1572
- this.length--;
1573
- return res
1574
- };
1555
+ Yallist$1.prototype.pop = function () {
1556
+ if (!this.tail) {
1557
+ return undefined
1558
+ }
1575
1559
 
1576
- Yallist.prototype.shift = function () {
1577
- if (!this.head) {
1578
- return undefined
1579
- }
1560
+ var res = this.tail.value;
1561
+ this.tail = this.tail.prev;
1562
+ if (this.tail) {
1563
+ this.tail.next = null;
1564
+ } else {
1565
+ this.head = null;
1566
+ }
1567
+ this.length--;
1568
+ return res
1569
+ };
1580
1570
 
1581
- var res = this.head.value;
1582
- this.head = this.head.next;
1583
- if (this.head) {
1584
- this.head.prev = null;
1585
- } else {
1586
- this.tail = null;
1587
- }
1588
- this.length--;
1589
- return res
1590
- };
1571
+ Yallist$1.prototype.shift = function () {
1572
+ if (!this.head) {
1573
+ return undefined
1574
+ }
1591
1575
 
1592
- Yallist.prototype.forEach = function (fn, thisp) {
1593
- thisp = thisp || this;
1594
- for (var walker = this.head, i = 0; walker !== null; i++) {
1595
- fn.call(thisp, walker.value, i, this);
1596
- walker = walker.next;
1597
- }
1598
- };
1576
+ var res = this.head.value;
1577
+ this.head = this.head.next;
1578
+ if (this.head) {
1579
+ this.head.prev = null;
1580
+ } else {
1581
+ this.tail = null;
1582
+ }
1583
+ this.length--;
1584
+ return res
1585
+ };
1599
1586
 
1600
- Yallist.prototype.forEachReverse = function (fn, thisp) {
1601
- thisp = thisp || this;
1602
- for (var walker = this.tail, i = this.length - 1; walker !== null; i--) {
1603
- fn.call(thisp, walker.value, i, this);
1604
- walker = walker.prev;
1605
- }
1606
- };
1587
+ Yallist$1.prototype.forEach = function (fn, thisp) {
1588
+ thisp = thisp || this;
1589
+ for (var walker = this.head, i = 0; walker !== null; i++) {
1590
+ fn.call(thisp, walker.value, i, this);
1591
+ walker = walker.next;
1592
+ }
1593
+ };
1607
1594
 
1608
- Yallist.prototype.get = function (n) {
1609
- for (var i = 0, walker = this.head; walker !== null && i < n; i++) {
1610
- // abort out of the list early if we hit a cycle
1611
- walker = walker.next;
1612
- }
1613
- if (i === n && walker !== null) {
1614
- return walker.value
1615
- }
1616
- };
1595
+ Yallist$1.prototype.forEachReverse = function (fn, thisp) {
1596
+ thisp = thisp || this;
1597
+ for (var walker = this.tail, i = this.length - 1; walker !== null; i--) {
1598
+ fn.call(thisp, walker.value, i, this);
1599
+ walker = walker.prev;
1600
+ }
1601
+ };
1617
1602
 
1618
- Yallist.prototype.getReverse = function (n) {
1619
- for (var i = 0, walker = this.tail; walker !== null && i < n; i++) {
1620
- // abort out of the list early if we hit a cycle
1621
- walker = walker.prev;
1622
- }
1623
- if (i === n && walker !== null) {
1624
- return walker.value
1625
- }
1626
- };
1603
+ Yallist$1.prototype.get = function (n) {
1604
+ for (var i = 0, walker = this.head; walker !== null && i < n; i++) {
1605
+ // abort out of the list early if we hit a cycle
1606
+ walker = walker.next;
1607
+ }
1608
+ if (i === n && walker !== null) {
1609
+ return walker.value
1610
+ }
1611
+ };
1627
1612
 
1628
- Yallist.prototype.map = function (fn, thisp) {
1629
- thisp = thisp || this;
1630
- var res = new Yallist();
1631
- for (var walker = this.head; walker !== null;) {
1632
- res.push(fn.call(thisp, walker.value, this));
1633
- walker = walker.next;
1634
- }
1635
- return res
1636
- };
1613
+ Yallist$1.prototype.getReverse = function (n) {
1614
+ for (var i = 0, walker = this.tail; walker !== null && i < n; i++) {
1615
+ // abort out of the list early if we hit a cycle
1616
+ walker = walker.prev;
1617
+ }
1618
+ if (i === n && walker !== null) {
1619
+ return walker.value
1620
+ }
1621
+ };
1637
1622
 
1638
- Yallist.prototype.mapReverse = function (fn, thisp) {
1639
- thisp = thisp || this;
1640
- var res = new Yallist();
1641
- for (var walker = this.tail; walker !== null;) {
1642
- res.push(fn.call(thisp, walker.value, this));
1643
- walker = walker.prev;
1644
- }
1645
- return res
1646
- };
1623
+ Yallist$1.prototype.map = function (fn, thisp) {
1624
+ thisp = thisp || this;
1625
+ var res = new Yallist$1();
1626
+ for (var walker = this.head; walker !== null;) {
1627
+ res.push(fn.call(thisp, walker.value, this));
1628
+ walker = walker.next;
1629
+ }
1630
+ return res
1631
+ };
1647
1632
 
1648
- Yallist.prototype.reduce = function (fn, initial) {
1649
- var acc;
1650
- var walker = this.head;
1651
- if (arguments.length > 1) {
1652
- acc = initial;
1653
- } else if (this.head) {
1654
- walker = this.head.next;
1655
- acc = this.head.value;
1656
- } else {
1657
- throw new TypeError('Reduce of empty list with no initial value')
1658
- }
1633
+ Yallist$1.prototype.mapReverse = function (fn, thisp) {
1634
+ thisp = thisp || this;
1635
+ var res = new Yallist$1();
1636
+ for (var walker = this.tail; walker !== null;) {
1637
+ res.push(fn.call(thisp, walker.value, this));
1638
+ walker = walker.prev;
1639
+ }
1640
+ return res
1641
+ };
1659
1642
 
1660
- for (var i = 0; walker !== null; i++) {
1661
- acc = fn(acc, walker.value, i);
1662
- walker = walker.next;
1663
- }
1643
+ Yallist$1.prototype.reduce = function (fn, initial) {
1644
+ var acc;
1645
+ var walker = this.head;
1646
+ if (arguments.length > 1) {
1647
+ acc = initial;
1648
+ } else if (this.head) {
1649
+ walker = this.head.next;
1650
+ acc = this.head.value;
1651
+ } else {
1652
+ throw new TypeError('Reduce of empty list with no initial value')
1653
+ }
1664
1654
 
1665
- return acc
1666
- };
1655
+ for (var i = 0; walker !== null; i++) {
1656
+ acc = fn(acc, walker.value, i);
1657
+ walker = walker.next;
1658
+ }
1667
1659
 
1668
- Yallist.prototype.reduceReverse = function (fn, initial) {
1669
- var acc;
1670
- var walker = this.tail;
1671
- if (arguments.length > 1) {
1672
- acc = initial;
1673
- } else if (this.tail) {
1674
- walker = this.tail.prev;
1675
- acc = this.tail.value;
1676
- } else {
1677
- throw new TypeError('Reduce of empty list with no initial value')
1678
- }
1660
+ return acc
1661
+ };
1679
1662
 
1680
- for (var i = this.length - 1; walker !== null; i--) {
1681
- acc = fn(acc, walker.value, i);
1682
- walker = walker.prev;
1683
- }
1663
+ Yallist$1.prototype.reduceReverse = function (fn, initial) {
1664
+ var acc;
1665
+ var walker = this.tail;
1666
+ if (arguments.length > 1) {
1667
+ acc = initial;
1668
+ } else if (this.tail) {
1669
+ walker = this.tail.prev;
1670
+ acc = this.tail.value;
1671
+ } else {
1672
+ throw new TypeError('Reduce of empty list with no initial value')
1673
+ }
1684
1674
 
1685
- return acc
1686
- };
1675
+ for (var i = this.length - 1; walker !== null; i--) {
1676
+ acc = fn(acc, walker.value, i);
1677
+ walker = walker.prev;
1678
+ }
1687
1679
 
1688
- Yallist.prototype.toArray = function () {
1689
- var arr = new Array(this.length);
1690
- for (var i = 0, walker = this.head; walker !== null; i++) {
1691
- arr[i] = walker.value;
1692
- walker = walker.next;
1693
- }
1694
- return arr
1695
- };
1680
+ return acc
1681
+ };
1696
1682
 
1697
- Yallist.prototype.toArrayReverse = function () {
1698
- var arr = new Array(this.length);
1699
- for (var i = 0, walker = this.tail; walker !== null; i++) {
1700
- arr[i] = walker.value;
1701
- walker = walker.prev;
1702
- }
1703
- return arr
1704
- };
1683
+ Yallist$1.prototype.toArray = function () {
1684
+ var arr = new Array(this.length);
1685
+ for (var i = 0, walker = this.head; walker !== null; i++) {
1686
+ arr[i] = walker.value;
1687
+ walker = walker.next;
1688
+ }
1689
+ return arr
1690
+ };
1705
1691
 
1706
- Yallist.prototype.slice = function (from, to) {
1707
- to = to || this.length;
1708
- if (to < 0) {
1709
- to += this.length;
1710
- }
1711
- from = from || 0;
1712
- if (from < 0) {
1713
- from += this.length;
1714
- }
1715
- var ret = new Yallist();
1716
- if (to < from || to < 0) {
1717
- return ret
1718
- }
1719
- if (from < 0) {
1720
- from = 0;
1721
- }
1722
- if (to > this.length) {
1723
- to = this.length;
1724
- }
1725
- for (var i = 0, walker = this.head; walker !== null && i < from; i++) {
1726
- walker = walker.next;
1727
- }
1728
- for (; walker !== null && i < to; i++, walker = walker.next) {
1729
- ret.push(walker.value);
1730
- }
1731
- return ret
1732
- };
1692
+ Yallist$1.prototype.toArrayReverse = function () {
1693
+ var arr = new Array(this.length);
1694
+ for (var i = 0, walker = this.tail; walker !== null; i++) {
1695
+ arr[i] = walker.value;
1696
+ walker = walker.prev;
1697
+ }
1698
+ return arr
1699
+ };
1733
1700
 
1734
- Yallist.prototype.sliceReverse = function (from, to) {
1735
- to = to || this.length;
1736
- if (to < 0) {
1737
- to += this.length;
1738
- }
1739
- from = from || 0;
1740
- if (from < 0) {
1741
- from += this.length;
1742
- }
1743
- var ret = new Yallist();
1744
- if (to < from || to < 0) {
1745
- return ret
1746
- }
1747
- if (from < 0) {
1748
- from = 0;
1749
- }
1750
- if (to > this.length) {
1751
- to = this.length;
1752
- }
1753
- for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) {
1754
- walker = walker.prev;
1755
- }
1756
- for (; walker !== null && i > from; i--, walker = walker.prev) {
1757
- ret.push(walker.value);
1758
- }
1759
- return ret
1760
- };
1701
+ Yallist$1.prototype.slice = function (from, to) {
1702
+ to = to || this.length;
1703
+ if (to < 0) {
1704
+ to += this.length;
1705
+ }
1706
+ from = from || 0;
1707
+ if (from < 0) {
1708
+ from += this.length;
1709
+ }
1710
+ var ret = new Yallist$1();
1711
+ if (to < from || to < 0) {
1712
+ return ret
1713
+ }
1714
+ if (from < 0) {
1715
+ from = 0;
1716
+ }
1717
+ if (to > this.length) {
1718
+ to = this.length;
1719
+ }
1720
+ for (var i = 0, walker = this.head; walker !== null && i < from; i++) {
1721
+ walker = walker.next;
1722
+ }
1723
+ for (; walker !== null && i < to; i++, walker = walker.next) {
1724
+ ret.push(walker.value);
1725
+ }
1726
+ return ret
1727
+ };
1761
1728
 
1762
- Yallist.prototype.splice = function (start, deleteCount, ...nodes) {
1763
- if (start > this.length) {
1764
- start = this.length - 1;
1765
- }
1766
- if (start < 0) {
1767
- start = this.length + start;
1768
- }
1729
+ Yallist$1.prototype.sliceReverse = function (from, to) {
1730
+ to = to || this.length;
1731
+ if (to < 0) {
1732
+ to += this.length;
1733
+ }
1734
+ from = from || 0;
1735
+ if (from < 0) {
1736
+ from += this.length;
1737
+ }
1738
+ var ret = new Yallist$1();
1739
+ if (to < from || to < 0) {
1740
+ return ret
1741
+ }
1742
+ if (from < 0) {
1743
+ from = 0;
1744
+ }
1745
+ if (to > this.length) {
1746
+ to = this.length;
1747
+ }
1748
+ for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) {
1749
+ walker = walker.prev;
1750
+ }
1751
+ for (; walker !== null && i > from; i--, walker = walker.prev) {
1752
+ ret.push(walker.value);
1753
+ }
1754
+ return ret
1755
+ };
1769
1756
 
1770
- for (var i = 0, walker = this.head; walker !== null && i < start; i++) {
1771
- walker = walker.next;
1772
- }
1757
+ Yallist$1.prototype.splice = function (start, deleteCount, ...nodes) {
1758
+ if (start > this.length) {
1759
+ start = this.length - 1;
1760
+ }
1761
+ if (start < 0) {
1762
+ start = this.length + start;
1763
+ }
1773
1764
 
1774
- var ret = [];
1775
- for (var i = 0; walker && i < deleteCount; i++) {
1776
- ret.push(walker.value);
1777
- walker = this.removeNode(walker);
1778
- }
1779
- if (walker === null) {
1780
- walker = this.tail;
1781
- }
1765
+ for (var i = 0, walker = this.head; walker !== null && i < start; i++) {
1766
+ walker = walker.next;
1767
+ }
1782
1768
 
1783
- if (walker !== this.head && walker !== this.tail) {
1784
- walker = walker.prev;
1785
- }
1769
+ var ret = [];
1770
+ for (var i = 0; walker && i < deleteCount; i++) {
1771
+ ret.push(walker.value);
1772
+ walker = this.removeNode(walker);
1773
+ }
1774
+ if (walker === null) {
1775
+ walker = this.tail;
1776
+ }
1786
1777
 
1787
- for (var i = 0; i < nodes.length; i++) {
1788
- walker = insert(this, walker, nodes[i]);
1789
- }
1790
- return ret;
1791
- };
1778
+ if (walker !== this.head && walker !== this.tail) {
1779
+ walker = walker.prev;
1780
+ }
1792
1781
 
1793
- Yallist.prototype.reverse = function () {
1794
- var head = this.head;
1795
- var tail = this.tail;
1796
- for (var walker = head; walker !== null; walker = walker.prev) {
1797
- var p = walker.prev;
1798
- walker.prev = walker.next;
1799
- walker.next = p;
1800
- }
1801
- this.head = tail;
1802
- this.tail = head;
1803
- return this
1804
- };
1782
+ for (var i = 0; i < nodes.length; i++) {
1783
+ walker = insert(this, walker, nodes[i]);
1784
+ }
1785
+ return ret;
1786
+ };
1805
1787
 
1806
- function insert (self, node, value) {
1807
- var inserted = node === self.head ?
1808
- new Node(value, null, node, self) :
1809
- new Node(value, node, node.next, self);
1788
+ Yallist$1.prototype.reverse = function () {
1789
+ var head = this.head;
1790
+ var tail = this.tail;
1791
+ for (var walker = head; walker !== null; walker = walker.prev) {
1792
+ var p = walker.prev;
1793
+ walker.prev = walker.next;
1794
+ walker.next = p;
1795
+ }
1796
+ this.head = tail;
1797
+ this.tail = head;
1798
+ return this
1799
+ };
1810
1800
 
1811
- if (inserted.next === null) {
1812
- self.tail = inserted;
1813
- }
1814
- if (inserted.prev === null) {
1815
- self.head = inserted;
1816
- }
1801
+ function insert (self, node, value) {
1802
+ var inserted = node === self.head ?
1803
+ new Node(value, null, node, self) :
1804
+ new Node(value, node, node.next, self);
1817
1805
 
1818
- self.length++;
1806
+ if (inserted.next === null) {
1807
+ self.tail = inserted;
1808
+ }
1809
+ if (inserted.prev === null) {
1810
+ self.head = inserted;
1811
+ }
1819
1812
 
1820
- return inserted
1821
- }
1813
+ self.length++;
1822
1814
 
1823
- function push (self, item) {
1824
- self.tail = new Node(item, self.tail, null, self);
1825
- if (!self.head) {
1826
- self.head = self.tail;
1827
- }
1828
- self.length++;
1829
- }
1815
+ return inserted
1816
+ }
1830
1817
 
1831
- function unshift (self, item) {
1832
- self.head = new Node(item, null, self.head, self);
1833
- if (!self.tail) {
1834
- self.tail = self.head;
1835
- }
1836
- self.length++;
1837
- }
1818
+ function push (self, item) {
1819
+ self.tail = new Node(item, self.tail, null, self);
1820
+ if (!self.head) {
1821
+ self.head = self.tail;
1822
+ }
1823
+ self.length++;
1824
+ }
1838
1825
 
1839
- function Node (value, prev, next, list) {
1840
- if (!(this instanceof Node)) {
1841
- return new Node(value, prev, next, list)
1842
- }
1826
+ function unshift (self, item) {
1827
+ self.head = new Node(item, null, self.head, self);
1828
+ if (!self.tail) {
1829
+ self.tail = self.head;
1830
+ }
1831
+ self.length++;
1832
+ }
1843
1833
 
1844
- this.list = list;
1845
- this.value = value;
1834
+ function Node (value, prev, next, list) {
1835
+ if (!(this instanceof Node)) {
1836
+ return new Node(value, prev, next, list)
1837
+ }
1846
1838
 
1847
- if (prev) {
1848
- prev.next = this;
1849
- this.prev = prev;
1850
- } else {
1851
- this.prev = null;
1852
- }
1839
+ this.list = list;
1840
+ this.value = value;
1853
1841
 
1854
- if (next) {
1855
- next.prev = this;
1856
- this.next = next;
1857
- } else {
1858
- this.next = null;
1859
- }
1860
- }
1842
+ if (prev) {
1843
+ prev.next = this;
1844
+ this.prev = prev;
1845
+ } else {
1846
+ this.prev = null;
1847
+ }
1861
1848
 
1862
- try {
1863
- // add if support for Symbol.iterator is present
1864
- requireIterator()(Yallist);
1865
- } catch (er) {}
1866
- return yallist;
1849
+ if (next) {
1850
+ next.prev = this;
1851
+ this.next = next;
1852
+ } else {
1853
+ this.next = null;
1854
+ }
1867
1855
  }
1868
1856
 
1869
- var lruCache;
1870
- var hasRequiredLruCache;
1871
-
1872
- function requireLruCache () {
1873
- if (hasRequiredLruCache) return lruCache;
1874
- hasRequiredLruCache = 1;
1875
-
1876
- // A linked list to keep track of recently-used-ness
1877
- const Yallist = requireYallist();
1878
-
1879
- const MAX = Symbol('max');
1880
- const LENGTH = Symbol('length');
1881
- const LENGTH_CALCULATOR = Symbol('lengthCalculator');
1882
- const ALLOW_STALE = Symbol('allowStale');
1883
- const MAX_AGE = Symbol('maxAge');
1884
- const DISPOSE = Symbol('dispose');
1885
- const NO_DISPOSE_ON_SET = Symbol('noDisposeOnSet');
1886
- const LRU_LIST = Symbol('lruList');
1887
- const CACHE = Symbol('cache');
1888
- const UPDATE_AGE_ON_GET = Symbol('updateAgeOnGet');
1889
-
1890
- const naiveLength = () => 1;
1891
-
1892
- // lruList is a yallist where the head is the youngest
1893
- // item, and the tail is the oldest. the list contains the Hit
1894
- // objects as the entries.
1895
- // Each Hit object has a reference to its Yallist.Node. This
1896
- // never changes.
1897
- //
1898
- // cache is a Map (or PseudoMap) that matches the keys to
1899
- // the Yallist.Node object.
1900
- class LRUCache {
1901
- constructor (options) {
1902
- if (typeof options === 'number')
1903
- options = { max: options };
1904
-
1905
- if (!options)
1906
- options = {};
1907
-
1908
- if (options.max && (typeof options.max !== 'number' || options.max < 0))
1909
- throw new TypeError('max must be a non-negative number')
1910
- // Kind of weird to have a default max of Infinity, but oh well.
1911
- this[MAX] = options.max || Infinity;
1912
-
1913
- const lc = options.length || naiveLength;
1914
- this[LENGTH_CALCULATOR] = (typeof lc !== 'function') ? naiveLength : lc;
1915
- this[ALLOW_STALE] = options.stale || false;
1916
- if (options.maxAge && typeof options.maxAge !== 'number')
1917
- throw new TypeError('maxAge must be a number')
1918
- this[MAX_AGE] = options.maxAge || 0;
1919
- this[DISPOSE] = options.dispose;
1920
- this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false;
1921
- this[UPDATE_AGE_ON_GET] = options.updateAgeOnGet || false;
1922
- this.reset();
1923
- }
1857
+ try {
1858
+ // add if support for Symbol.iterator is present
1859
+ requireIterator()(Yallist$1);
1860
+ } catch (er) {}
1861
+
1862
+ // A linked list to keep track of recently-used-ness
1863
+ const Yallist = yallist;
1864
+
1865
+ const MAX = Symbol('max');
1866
+ const LENGTH = Symbol('length');
1867
+ const LENGTH_CALCULATOR = Symbol('lengthCalculator');
1868
+ const ALLOW_STALE = Symbol('allowStale');
1869
+ const MAX_AGE = Symbol('maxAge');
1870
+ const DISPOSE = Symbol('dispose');
1871
+ const NO_DISPOSE_ON_SET = Symbol('noDisposeOnSet');
1872
+ const LRU_LIST = Symbol('lruList');
1873
+ const CACHE = Symbol('cache');
1874
+ const UPDATE_AGE_ON_GET = Symbol('updateAgeOnGet');
1875
+
1876
+ const naiveLength = () => 1;
1877
+
1878
+ // lruList is a yallist where the head is the youngest
1879
+ // item, and the tail is the oldest. the list contains the Hit
1880
+ // objects as the entries.
1881
+ // Each Hit object has a reference to its Yallist.Node. This
1882
+ // never changes.
1883
+ //
1884
+ // cache is a Map (or PseudoMap) that matches the keys to
1885
+ // the Yallist.Node object.
1886
+ class LRUCache {
1887
+ constructor (options) {
1888
+ if (typeof options === 'number')
1889
+ options = { max: options };
1890
+
1891
+ if (!options)
1892
+ options = {};
1893
+
1894
+ if (options.max && (typeof options.max !== 'number' || options.max < 0))
1895
+ throw new TypeError('max must be a non-negative number')
1896
+ // Kind of weird to have a default max of Infinity, but oh well.
1897
+ this[MAX] = options.max || Infinity;
1898
+
1899
+ const lc = options.length || naiveLength;
1900
+ this[LENGTH_CALCULATOR] = (typeof lc !== 'function') ? naiveLength : lc;
1901
+ this[ALLOW_STALE] = options.stale || false;
1902
+ if (options.maxAge && typeof options.maxAge !== 'number')
1903
+ throw new TypeError('maxAge must be a number')
1904
+ this[MAX_AGE] = options.maxAge || 0;
1905
+ this[DISPOSE] = options.dispose;
1906
+ this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false;
1907
+ this[UPDATE_AGE_ON_GET] = options.updateAgeOnGet || false;
1908
+ this.reset();
1909
+ }
1924
1910
 
1925
- // resize the cache when the max changes.
1926
- set max (mL) {
1927
- if (typeof mL !== 'number' || mL < 0)
1928
- throw new TypeError('max must be a non-negative number')
1911
+ // resize the cache when the max changes.
1912
+ set max (mL) {
1913
+ if (typeof mL !== 'number' || mL < 0)
1914
+ throw new TypeError('max must be a non-negative number')
1929
1915
 
1930
- this[MAX] = mL || Infinity;
1931
- trim(this);
1932
- }
1933
- get max () {
1934
- return this[MAX]
1935
- }
1916
+ this[MAX] = mL || Infinity;
1917
+ trim(this);
1918
+ }
1919
+ get max () {
1920
+ return this[MAX]
1921
+ }
1936
1922
 
1937
- set allowStale (allowStale) {
1938
- this[ALLOW_STALE] = !!allowStale;
1939
- }
1940
- get allowStale () {
1941
- return this[ALLOW_STALE]
1942
- }
1923
+ set allowStale (allowStale) {
1924
+ this[ALLOW_STALE] = !!allowStale;
1925
+ }
1926
+ get allowStale () {
1927
+ return this[ALLOW_STALE]
1928
+ }
1943
1929
 
1944
- set maxAge (mA) {
1945
- if (typeof mA !== 'number')
1946
- throw new TypeError('maxAge must be a non-negative number')
1930
+ set maxAge (mA) {
1931
+ if (typeof mA !== 'number')
1932
+ throw new TypeError('maxAge must be a non-negative number')
1947
1933
 
1948
- this[MAX_AGE] = mA;
1949
- trim(this);
1950
- }
1951
- get maxAge () {
1952
- return this[MAX_AGE]
1953
- }
1934
+ this[MAX_AGE] = mA;
1935
+ trim(this);
1936
+ }
1937
+ get maxAge () {
1938
+ return this[MAX_AGE]
1939
+ }
1954
1940
 
1955
- // resize the cache when the lengthCalculator changes.
1956
- set lengthCalculator (lC) {
1957
- if (typeof lC !== 'function')
1958
- lC = naiveLength;
1959
-
1960
- if (lC !== this[LENGTH_CALCULATOR]) {
1961
- this[LENGTH_CALCULATOR] = lC;
1962
- this[LENGTH] = 0;
1963
- this[LRU_LIST].forEach(hit => {
1964
- hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key);
1965
- this[LENGTH] += hit.length;
1966
- });
1967
- }
1968
- trim(this);
1969
- }
1970
- get lengthCalculator () { return this[LENGTH_CALCULATOR] }
1941
+ // resize the cache when the lengthCalculator changes.
1942
+ set lengthCalculator (lC) {
1943
+ if (typeof lC !== 'function')
1944
+ lC = naiveLength;
1945
+
1946
+ if (lC !== this[LENGTH_CALCULATOR]) {
1947
+ this[LENGTH_CALCULATOR] = lC;
1948
+ this[LENGTH] = 0;
1949
+ this[LRU_LIST].forEach(hit => {
1950
+ hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key);
1951
+ this[LENGTH] += hit.length;
1952
+ });
1953
+ }
1954
+ trim(this);
1955
+ }
1956
+ get lengthCalculator () { return this[LENGTH_CALCULATOR] }
1971
1957
 
1972
- get length () { return this[LENGTH] }
1973
- get itemCount () { return this[LRU_LIST].length }
1958
+ get length () { return this[LENGTH] }
1959
+ get itemCount () { return this[LRU_LIST].length }
1974
1960
 
1975
- rforEach (fn, thisp) {
1976
- thisp = thisp || this;
1977
- for (let walker = this[LRU_LIST].tail; walker !== null;) {
1978
- const prev = walker.prev;
1979
- forEachStep(this, fn, walker, thisp);
1980
- walker = prev;
1981
- }
1982
- }
1961
+ rforEach (fn, thisp) {
1962
+ thisp = thisp || this;
1963
+ for (let walker = this[LRU_LIST].tail; walker !== null;) {
1964
+ const prev = walker.prev;
1965
+ forEachStep(this, fn, walker, thisp);
1966
+ walker = prev;
1967
+ }
1968
+ }
1983
1969
 
1984
- forEach (fn, thisp) {
1985
- thisp = thisp || this;
1986
- for (let walker = this[LRU_LIST].head; walker !== null;) {
1987
- const next = walker.next;
1988
- forEachStep(this, fn, walker, thisp);
1989
- walker = next;
1990
- }
1991
- }
1970
+ forEach (fn, thisp) {
1971
+ thisp = thisp || this;
1972
+ for (let walker = this[LRU_LIST].head; walker !== null;) {
1973
+ const next = walker.next;
1974
+ forEachStep(this, fn, walker, thisp);
1975
+ walker = next;
1976
+ }
1977
+ }
1992
1978
 
1993
- keys () {
1994
- return this[LRU_LIST].toArray().map(k => k.key)
1995
- }
1979
+ keys () {
1980
+ return this[LRU_LIST].toArray().map(k => k.key)
1981
+ }
1996
1982
 
1997
- values () {
1998
- return this[LRU_LIST].toArray().map(k => k.value)
1999
- }
1983
+ values () {
1984
+ return this[LRU_LIST].toArray().map(k => k.value)
1985
+ }
2000
1986
 
2001
- reset () {
2002
- if (this[DISPOSE] &&
2003
- this[LRU_LIST] &&
2004
- this[LRU_LIST].length) {
2005
- this[LRU_LIST].forEach(hit => this[DISPOSE](hit.key, hit.value));
2006
- }
1987
+ reset () {
1988
+ if (this[DISPOSE] &&
1989
+ this[LRU_LIST] &&
1990
+ this[LRU_LIST].length) {
1991
+ this[LRU_LIST].forEach(hit => this[DISPOSE](hit.key, hit.value));
1992
+ }
2007
1993
 
2008
- this[CACHE] = new Map(); // hash of items by key
2009
- this[LRU_LIST] = new Yallist(); // list of items in order of use recency
2010
- this[LENGTH] = 0; // length of items in the list
2011
- }
1994
+ this[CACHE] = new Map(); // hash of items by key
1995
+ this[LRU_LIST] = new Yallist(); // list of items in order of use recency
1996
+ this[LENGTH] = 0; // length of items in the list
1997
+ }
2012
1998
 
2013
- dump () {
2014
- return this[LRU_LIST].map(hit =>
2015
- isStale(this, hit) ? false : {
2016
- k: hit.key,
2017
- v: hit.value,
2018
- e: hit.now + (hit.maxAge || 0)
2019
- }).toArray().filter(h => h)
2020
- }
1999
+ dump () {
2000
+ return this[LRU_LIST].map(hit =>
2001
+ isStale(this, hit) ? false : {
2002
+ k: hit.key,
2003
+ v: hit.value,
2004
+ e: hit.now + (hit.maxAge || 0)
2005
+ }).toArray().filter(h => h)
2006
+ }
2021
2007
 
2022
- dumpLru () {
2023
- return this[LRU_LIST]
2024
- }
2008
+ dumpLru () {
2009
+ return this[LRU_LIST]
2010
+ }
2025
2011
 
2026
- set (key, value, maxAge) {
2027
- maxAge = maxAge || this[MAX_AGE];
2012
+ set (key, value, maxAge) {
2013
+ maxAge = maxAge || this[MAX_AGE];
2028
2014
 
2029
- if (maxAge && typeof maxAge !== 'number')
2030
- throw new TypeError('maxAge must be a number')
2015
+ if (maxAge && typeof maxAge !== 'number')
2016
+ throw new TypeError('maxAge must be a number')
2031
2017
 
2032
- const now = maxAge ? Date.now() : 0;
2033
- const len = this[LENGTH_CALCULATOR](value, key);
2018
+ const now = maxAge ? Date.now() : 0;
2019
+ const len = this[LENGTH_CALCULATOR](value, key);
2034
2020
 
2035
- if (this[CACHE].has(key)) {
2036
- if (len > this[MAX]) {
2037
- del(this, this[CACHE].get(key));
2038
- return false
2039
- }
2021
+ if (this[CACHE].has(key)) {
2022
+ if (len > this[MAX]) {
2023
+ del(this, this[CACHE].get(key));
2024
+ return false
2025
+ }
2040
2026
 
2041
- const node = this[CACHE].get(key);
2042
- const item = node.value;
2027
+ const node = this[CACHE].get(key);
2028
+ const item = node.value;
2043
2029
 
2044
- // dispose of the old one before overwriting
2045
- // split out into 2 ifs for better coverage tracking
2046
- if (this[DISPOSE]) {
2047
- if (!this[NO_DISPOSE_ON_SET])
2048
- this[DISPOSE](key, item.value);
2049
- }
2030
+ // dispose of the old one before overwriting
2031
+ // split out into 2 ifs for better coverage tracking
2032
+ if (this[DISPOSE]) {
2033
+ if (!this[NO_DISPOSE_ON_SET])
2034
+ this[DISPOSE](key, item.value);
2035
+ }
2050
2036
 
2051
- item.now = now;
2052
- item.maxAge = maxAge;
2053
- item.value = value;
2054
- this[LENGTH] += len - item.length;
2055
- item.length = len;
2056
- this.get(key);
2057
- trim(this);
2058
- return true
2059
- }
2037
+ item.now = now;
2038
+ item.maxAge = maxAge;
2039
+ item.value = value;
2040
+ this[LENGTH] += len - item.length;
2041
+ item.length = len;
2042
+ this.get(key);
2043
+ trim(this);
2044
+ return true
2045
+ }
2060
2046
 
2061
- const hit = new Entry(key, value, len, now, maxAge);
2047
+ const hit = new Entry(key, value, len, now, maxAge);
2062
2048
 
2063
- // oversized objects fall out of cache automatically.
2064
- if (hit.length > this[MAX]) {
2065
- if (this[DISPOSE])
2066
- this[DISPOSE](key, value);
2049
+ // oversized objects fall out of cache automatically.
2050
+ if (hit.length > this[MAX]) {
2051
+ if (this[DISPOSE])
2052
+ this[DISPOSE](key, value);
2067
2053
 
2068
- return false
2069
- }
2054
+ return false
2055
+ }
2070
2056
 
2071
- this[LENGTH] += hit.length;
2072
- this[LRU_LIST].unshift(hit);
2073
- this[CACHE].set(key, this[LRU_LIST].head);
2074
- trim(this);
2075
- return true
2076
- }
2057
+ this[LENGTH] += hit.length;
2058
+ this[LRU_LIST].unshift(hit);
2059
+ this[CACHE].set(key, this[LRU_LIST].head);
2060
+ trim(this);
2061
+ return true
2062
+ }
2077
2063
 
2078
- has (key) {
2079
- if (!this[CACHE].has(key)) return false
2080
- const hit = this[CACHE].get(key).value;
2081
- return !isStale(this, hit)
2082
- }
2064
+ has (key) {
2065
+ if (!this[CACHE].has(key)) return false
2066
+ const hit = this[CACHE].get(key).value;
2067
+ return !isStale(this, hit)
2068
+ }
2083
2069
 
2084
- get (key) {
2085
- return get(this, key, true)
2086
- }
2070
+ get (key) {
2071
+ return get(this, key, true)
2072
+ }
2087
2073
 
2088
- peek (key) {
2089
- return get(this, key, false)
2090
- }
2074
+ peek (key) {
2075
+ return get(this, key, false)
2076
+ }
2091
2077
 
2092
- pop () {
2093
- const node = this[LRU_LIST].tail;
2094
- if (!node)
2095
- return null
2078
+ pop () {
2079
+ const node = this[LRU_LIST].tail;
2080
+ if (!node)
2081
+ return null
2096
2082
 
2097
- del(this, node);
2098
- return node.value
2099
- }
2083
+ del(this, node);
2084
+ return node.value
2085
+ }
2100
2086
 
2101
- del (key) {
2102
- del(this, this[CACHE].get(key));
2103
- }
2087
+ del (key) {
2088
+ del(this, this[CACHE].get(key));
2089
+ }
2104
2090
 
2105
- load (arr) {
2106
- // reset the cache
2107
- this.reset();
2108
-
2109
- const now = Date.now();
2110
- // A previous serialized cache has the most recent items first
2111
- for (let l = arr.length - 1; l >= 0; l--) {
2112
- const hit = arr[l];
2113
- const expiresAt = hit.e || 0;
2114
- if (expiresAt === 0)
2115
- // the item was created without expiration in a non aged cache
2116
- this.set(hit.k, hit.v);
2117
- else {
2118
- const maxAge = expiresAt - now;
2119
- // dont add already expired items
2120
- if (maxAge > 0) {
2121
- this.set(hit.k, hit.v, maxAge);
2122
- }
2123
- }
2124
- }
2125
- }
2091
+ load (arr) {
2092
+ // reset the cache
2093
+ this.reset();
2094
+
2095
+ const now = Date.now();
2096
+ // A previous serialized cache has the most recent items first
2097
+ for (let l = arr.length - 1; l >= 0; l--) {
2098
+ const hit = arr[l];
2099
+ const expiresAt = hit.e || 0;
2100
+ if (expiresAt === 0)
2101
+ // the item was created without expiration in a non aged cache
2102
+ this.set(hit.k, hit.v);
2103
+ else {
2104
+ const maxAge = expiresAt - now;
2105
+ // dont add already expired items
2106
+ if (maxAge > 0) {
2107
+ this.set(hit.k, hit.v, maxAge);
2108
+ }
2109
+ }
2110
+ }
2111
+ }
2126
2112
 
2127
- prune () {
2128
- this[CACHE].forEach((value, key) => get(this, key, false));
2129
- }
2130
- }
2113
+ prune () {
2114
+ this[CACHE].forEach((value, key) => get(this, key, false));
2115
+ }
2116
+ }
2131
2117
 
2132
- const get = (self, key, doUse) => {
2133
- const node = self[CACHE].get(key);
2134
- if (node) {
2135
- const hit = node.value;
2136
- if (isStale(self, hit)) {
2137
- del(self, node);
2138
- if (!self[ALLOW_STALE])
2139
- return undefined
2140
- } else {
2141
- if (doUse) {
2142
- if (self[UPDATE_AGE_ON_GET])
2143
- node.value.now = Date.now();
2144
- self[LRU_LIST].unshiftNode(node);
2145
- }
2146
- }
2147
- return hit.value
2148
- }
2149
- };
2118
+ const get = (self, key, doUse) => {
2119
+ const node = self[CACHE].get(key);
2120
+ if (node) {
2121
+ const hit = node.value;
2122
+ if (isStale(self, hit)) {
2123
+ del(self, node);
2124
+ if (!self[ALLOW_STALE])
2125
+ return undefined
2126
+ } else {
2127
+ if (doUse) {
2128
+ if (self[UPDATE_AGE_ON_GET])
2129
+ node.value.now = Date.now();
2130
+ self[LRU_LIST].unshiftNode(node);
2131
+ }
2132
+ }
2133
+ return hit.value
2134
+ }
2135
+ };
2150
2136
 
2151
- const isStale = (self, hit) => {
2152
- if (!hit || (!hit.maxAge && !self[MAX_AGE]))
2153
- return false
2137
+ const isStale = (self, hit) => {
2138
+ if (!hit || (!hit.maxAge && !self[MAX_AGE]))
2139
+ return false
2154
2140
 
2155
- const diff = Date.now() - hit.now;
2156
- return hit.maxAge ? diff > hit.maxAge
2157
- : self[MAX_AGE] && (diff > self[MAX_AGE])
2158
- };
2141
+ const diff = Date.now() - hit.now;
2142
+ return hit.maxAge ? diff > hit.maxAge
2143
+ : self[MAX_AGE] && (diff > self[MAX_AGE])
2144
+ };
2159
2145
 
2160
- const trim = self => {
2161
- if (self[LENGTH] > self[MAX]) {
2162
- for (let walker = self[LRU_LIST].tail;
2163
- self[LENGTH] > self[MAX] && walker !== null;) {
2164
- // We know that we're about to delete this one, and also
2165
- // what the next least recently used key will be, so just
2166
- // go ahead and set it now.
2167
- const prev = walker.prev;
2168
- del(self, walker);
2169
- walker = prev;
2170
- }
2171
- }
2172
- };
2146
+ const trim = self => {
2147
+ if (self[LENGTH] > self[MAX]) {
2148
+ for (let walker = self[LRU_LIST].tail;
2149
+ self[LENGTH] > self[MAX] && walker !== null;) {
2150
+ // We know that we're about to delete this one, and also
2151
+ // what the next least recently used key will be, so just
2152
+ // go ahead and set it now.
2153
+ const prev = walker.prev;
2154
+ del(self, walker);
2155
+ walker = prev;
2156
+ }
2157
+ }
2158
+ };
2173
2159
 
2174
- const del = (self, node) => {
2175
- if (node) {
2176
- const hit = node.value;
2177
- if (self[DISPOSE])
2178
- self[DISPOSE](hit.key, hit.value);
2160
+ const del = (self, node) => {
2161
+ if (node) {
2162
+ const hit = node.value;
2163
+ if (self[DISPOSE])
2164
+ self[DISPOSE](hit.key, hit.value);
2179
2165
 
2180
- self[LENGTH] -= hit.length;
2181
- self[CACHE].delete(hit.key);
2182
- self[LRU_LIST].removeNode(node);
2183
- }
2184
- };
2166
+ self[LENGTH] -= hit.length;
2167
+ self[CACHE].delete(hit.key);
2168
+ self[LRU_LIST].removeNode(node);
2169
+ }
2170
+ };
2185
2171
 
2186
- class Entry {
2187
- constructor (key, value, length, now, maxAge) {
2188
- this.key = key;
2189
- this.value = value;
2190
- this.length = length;
2191
- this.now = now;
2192
- this.maxAge = maxAge || 0;
2193
- }
2194
- }
2172
+ class Entry {
2173
+ constructor (key, value, length, now, maxAge) {
2174
+ this.key = key;
2175
+ this.value = value;
2176
+ this.length = length;
2177
+ this.now = now;
2178
+ this.maxAge = maxAge || 0;
2179
+ }
2180
+ }
2195
2181
 
2196
- const forEachStep = (self, fn, node, thisp) => {
2197
- let hit = node.value;
2198
- if (isStale(self, hit)) {
2199
- del(self, node);
2200
- if (!self[ALLOW_STALE])
2201
- hit = undefined;
2202
- }
2203
- if (hit)
2204
- fn.call(thisp, hit.value, hit.key, self);
2205
- };
2182
+ const forEachStep = (self, fn, node, thisp) => {
2183
+ let hit = node.value;
2184
+ if (isStale(self, hit)) {
2185
+ del(self, node);
2186
+ if (!self[ALLOW_STALE])
2187
+ hit = undefined;
2188
+ }
2189
+ if (hit)
2190
+ fn.call(thisp, hit.value, hit.key, self);
2191
+ };
2206
2192
 
2207
- lruCache = LRUCache;
2208
- return lruCache;
2209
- }
2193
+ var lruCache = LRUCache;
2210
2194
 
2211
2195
  var range;
2212
2196
  var hasRequiredRange;
@@ -2414,7 +2398,7 @@ function requireRange () {
2414
2398
 
2415
2399
  range = Range;
2416
2400
 
2417
- const LRU = requireLruCache();
2401
+ const LRU = lruCache;
2418
2402
  const cache = new LRU({ max: 1000 });
2419
2403
 
2420
2404
  const parseOptions = parseOptions_1;
@@ -3540,11 +3524,11 @@ var semver$1 = /*@__PURE__*/getDefaultExportFromCjs(semver);
3540
3524
 
3541
3525
  const limit = 1800;
3542
3526
  const transactionLimit = 1000;
3543
- const requestTimeout = 30000;
3544
- const syncTimeout = 30000;
3527
+ const requestTimeout = 30_000;
3528
+ const syncTimeout = 30_000;
3545
3529
  class Protocol {
3546
3530
  constructor(config) {
3547
- this.resolveTimeout = 10000;
3531
+ this.resolveTimeout = 10_000;
3548
3532
  if (config?.resolveTimeout)
3549
3533
  this.resolveTimeout = config.resolveTimeout;
3550
3534
  }
@@ -3644,7 +3628,13 @@ class Transaction extends Protocol {
3644
3628
  * @returns {Number} nonce
3645
3629
  */
3646
3630
  async getNonce(address) {
3647
- if (!(await globalThis.accountsStore.has(address))) {
3631
+ try {
3632
+ if (!(await globalThis.accountsStore.has(address))) {
3633
+ const nonce = await this.#getNonceFallback(address);
3634
+ await globalThis.accountsStore.put(address, new TextEncoder().encode(String(nonce)));
3635
+ }
3636
+ }
3637
+ catch (error) {
3648
3638
  const nonce = await this.#getNonceFallback(address);
3649
3639
  await globalThis.accountsStore.put(address, new TextEncoder().encode(String(nonce)));
3650
3640
  }
@@ -3662,8 +3652,7 @@ class Transaction extends Protocol {
3662
3652
  return Number(nonce);
3663
3653
  }
3664
3654
  async validateNonce(address, nonce) {
3665
- let previousNonce = await globalThis.accountsStore.get(address);
3666
- previousNonce = Number(new TextDecoder().decode(previousNonce));
3655
+ const previousNonce = await this.getNonce(address);
3667
3656
  if (previousNonce > nonce)
3668
3657
  throw new Error(`a transaction with a higher nonce already exists`);
3669
3658
  if (previousNonce === nonce)
@@ -3721,7 +3710,7 @@ class Transaction extends Protocol {
3721
3710
  result.status === 'fulfilled' ? resolve(result.hash) : reject({ hash: result.hash, error: result.error });
3722
3711
  setTimeout(async () => {
3723
3712
  pubsub.unsubscribe(`transaction.completed.${hash}`, completed);
3724
- }, 10000);
3713
+ }, 10_000);
3725
3714
  };
3726
3715
  pubsub.subscribe(`transaction.completed.${hash}`, completed);
3727
3716
  }
@@ -3908,7 +3897,8 @@ class Machine {
3908
3897
  lastBlock: {
3909
3898
  index: 0,
3910
3899
  hash: ''
3911
- }
3900
+ },
3901
+ accounts: {}
3912
3902
  };
3913
3903
  // @ts-ignore
3914
3904
  return this.#init(blocks);
@@ -3998,8 +3988,14 @@ class Machine {
3998
3988
  const value = await this.#askWorker('get', { contract, method: 'state', params: [] });
3999
3989
  state[contract] = value;
4000
3990
  }));
4001
- await stateStore.put('lastBlock', JSON.stringify(await this.lastBlock));
4002
- await stateStore.put('states', JSON.stringify(state));
3991
+ const accounts = await Promise.all((await accountsStore.keys()).map((address) => accountsStore.get(address)));
3992
+ const tasks = [
3993
+ stateStore.put('lastBlock', JSON.stringify(await this.lastBlock)),
3994
+ stateStore.put('states', JSON.stringify(state)),
3995
+ stateStore.put('accounts', JSON.stringify(accounts))
3996
+ // accountsStore.clear()
3997
+ ];
3998
+ await Promise.all(tasks);
4003
3999
  }
4004
4000
  }
4005
4001
  catch (error) {
@@ -4033,6 +4029,12 @@ class Machine {
4033
4029
  if (await stateStore.has('lastBlock')) {
4034
4030
  this.states.lastBlock = JSON.parse(new TextDecoder().decode(await stateStore.get('lastBlock')));
4035
4031
  this.states.states = JSON.parse(new TextDecoder().decode(await stateStore.get('states')));
4032
+ try {
4033
+ this.states.accounts = JSON.parse(new TextDecoder().decode(await stateStore.get('accounts')));
4034
+ }
4035
+ catch {
4036
+ this.states.accounts = {};
4037
+ }
4036
4038
  console.log({ balances: this.states.states[addresses.nativeToken].balances });
4037
4039
  }
4038
4040
  const message = {
@@ -5024,7 +5026,6 @@ class Chain extends VersionControl {
5024
5026
  const lastBlock = await this.#makeRequest(peer, 'lastBlock');
5025
5027
  const localBlock = await this.lastBlock;
5026
5028
  const higherThenCurrentLocal = !localBlock.index ? true : lastBlock.index > localBlock.index;
5027
- const peerTransactionPool = (higherThenCurrentLocal && (await this.getPeerTransactionPool(peer))) || [];
5028
5029
  if (Object.keys(lastBlock).length > 0) {
5029
5030
  if (!this.lastBlock || higherThenCurrentLocal) {
5030
5031
  this.knownBlocks = await this.#makeRequest(peer, 'knownBlocks');
@@ -5033,6 +5034,7 @@ class Chain extends VersionControl {
5033
5034
  else if (!this.knownBlocks)
5034
5035
  this.knownBlocks = await this.#makeRequest(peer, 'knownBlocks');
5035
5036
  }
5037
+ const peerTransactionPool = (higherThenCurrentLocal && (await this.getPeerTransactionPool(peer))) || [];
5036
5038
  if (this.#participating && peerTransactionPool.length > 0)
5037
5039
  return this.#runEpoch();
5038
5040
  }