@leofcoin/chain 1.6.10 → 1.6.12
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/exports/browser/chain.js +719 -661
- package/exports/browser/workers/machine-worker.js +35 -4
- package/exports/chain.js +46 -5
- package/exports/machine.d.ts +11 -0
- package/exports/workers/machine-worker.js +35 -4
- package/package.json +13 -13
package/exports/browser/chain.js
CHANGED
|
@@ -1433,764 +1433,781 @@ function requireIterator () {
|
|
|
1433
1433
|
return iterator;
|
|
1434
1434
|
}
|
|
1435
1435
|
|
|
1436
|
-
var yallist
|
|
1436
|
+
var yallist;
|
|
1437
|
+
var hasRequiredYallist;
|
|
1437
1438
|
|
|
1438
|
-
|
|
1439
|
-
|
|
1439
|
+
function requireYallist () {
|
|
1440
|
+
if (hasRequiredYallist) return yallist;
|
|
1441
|
+
hasRequiredYallist = 1;
|
|
1442
|
+
yallist = Yallist;
|
|
1440
1443
|
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
if (!(self instanceof Yallist$1)) {
|
|
1444
|
-
self = new Yallist$1();
|
|
1445
|
-
}
|
|
1444
|
+
Yallist.Node = Node;
|
|
1445
|
+
Yallist.create = Yallist;
|
|
1446
1446
|
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1447
|
+
function Yallist (list) {
|
|
1448
|
+
var self = this;
|
|
1449
|
+
if (!(self instanceof Yallist)) {
|
|
1450
|
+
self = new Yallist();
|
|
1451
|
+
}
|
|
1450
1452
|
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
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
|
-
}
|
|
1453
|
+
self.tail = null;
|
|
1454
|
+
self.head = null;
|
|
1455
|
+
self.length = 0;
|
|
1460
1456
|
|
|
1461
|
-
|
|
1462
|
-
|
|
1457
|
+
if (list && typeof list.forEach === 'function') {
|
|
1458
|
+
list.forEach(function (item) {
|
|
1459
|
+
self.push(item);
|
|
1460
|
+
});
|
|
1461
|
+
} else if (arguments.length > 0) {
|
|
1462
|
+
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
1463
|
+
self.push(arguments[i]);
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1463
1466
|
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
throw new Error('removing node which does not belong to this list')
|
|
1467
|
-
}
|
|
1467
|
+
return self
|
|
1468
|
+
}
|
|
1468
1469
|
|
|
1469
|
-
|
|
1470
|
-
|
|
1470
|
+
Yallist.prototype.removeNode = function (node) {
|
|
1471
|
+
if (node.list !== this) {
|
|
1472
|
+
throw new Error('removing node which does not belong to this list')
|
|
1473
|
+
}
|
|
1471
1474
|
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
}
|
|
1475
|
+
var next = node.next;
|
|
1476
|
+
var prev = node.prev;
|
|
1475
1477
|
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1478
|
+
if (next) {
|
|
1479
|
+
next.prev = prev;
|
|
1480
|
+
}
|
|
1479
1481
|
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
if (node === this.tail) {
|
|
1484
|
-
this.tail = prev;
|
|
1485
|
-
}
|
|
1482
|
+
if (prev) {
|
|
1483
|
+
prev.next = next;
|
|
1484
|
+
}
|
|
1486
1485
|
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1486
|
+
if (node === this.head) {
|
|
1487
|
+
this.head = next;
|
|
1488
|
+
}
|
|
1489
|
+
if (node === this.tail) {
|
|
1490
|
+
this.tail = prev;
|
|
1491
|
+
}
|
|
1491
1492
|
|
|
1492
|
-
|
|
1493
|
-
|
|
1493
|
+
node.list.length--;
|
|
1494
|
+
node.next = null;
|
|
1495
|
+
node.prev = null;
|
|
1496
|
+
node.list = null;
|
|
1494
1497
|
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
return
|
|
1498
|
-
}
|
|
1498
|
+
return next
|
|
1499
|
+
};
|
|
1499
1500
|
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1501
|
+
Yallist.prototype.unshiftNode = function (node) {
|
|
1502
|
+
if (node === this.head) {
|
|
1503
|
+
return
|
|
1504
|
+
}
|
|
1503
1505
|
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
if (head) {
|
|
1508
|
-
head.prev = node;
|
|
1509
|
-
}
|
|
1506
|
+
if (node.list) {
|
|
1507
|
+
node.list.removeNode(node);
|
|
1508
|
+
}
|
|
1510
1509
|
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
}
|
|
1510
|
+
var head = this.head;
|
|
1511
|
+
node.list = this;
|
|
1512
|
+
node.next = head;
|
|
1513
|
+
if (head) {
|
|
1514
|
+
head.prev = node;
|
|
1515
|
+
}
|
|
1517
1516
|
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1517
|
+
this.head = node;
|
|
1518
|
+
if (!this.tail) {
|
|
1519
|
+
this.tail = node;
|
|
1520
|
+
}
|
|
1521
|
+
this.length++;
|
|
1522
|
+
};
|
|
1522
1523
|
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1524
|
+
Yallist.prototype.pushNode = function (node) {
|
|
1525
|
+
if (node === this.tail) {
|
|
1526
|
+
return
|
|
1527
|
+
}
|
|
1526
1528
|
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
if (tail) {
|
|
1531
|
-
tail.next = node;
|
|
1532
|
-
}
|
|
1529
|
+
if (node.list) {
|
|
1530
|
+
node.list.removeNode(node);
|
|
1531
|
+
}
|
|
1533
1532
|
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
}
|
|
1533
|
+
var tail = this.tail;
|
|
1534
|
+
node.list = this;
|
|
1535
|
+
node.prev = tail;
|
|
1536
|
+
if (tail) {
|
|
1537
|
+
tail.next = node;
|
|
1538
|
+
}
|
|
1540
1539
|
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
};
|
|
1540
|
+
this.tail = node;
|
|
1541
|
+
if (!this.head) {
|
|
1542
|
+
this.head = node;
|
|
1543
|
+
}
|
|
1544
|
+
this.length++;
|
|
1545
|
+
};
|
|
1547
1546
|
|
|
1548
|
-
Yallist
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
};
|
|
1547
|
+
Yallist.prototype.push = function () {
|
|
1548
|
+
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
1549
|
+
push(this, arguments[i]);
|
|
1550
|
+
}
|
|
1551
|
+
return this.length
|
|
1552
|
+
};
|
|
1554
1553
|
|
|
1555
|
-
Yallist
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1554
|
+
Yallist.prototype.unshift = function () {
|
|
1555
|
+
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
1556
|
+
unshift(this, arguments[i]);
|
|
1557
|
+
}
|
|
1558
|
+
return this.length
|
|
1559
|
+
};
|
|
1559
1560
|
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
} else {
|
|
1565
|
-
this.head = null;
|
|
1566
|
-
}
|
|
1567
|
-
this.length--;
|
|
1568
|
-
return res
|
|
1569
|
-
};
|
|
1561
|
+
Yallist.prototype.pop = function () {
|
|
1562
|
+
if (!this.tail) {
|
|
1563
|
+
return undefined
|
|
1564
|
+
}
|
|
1570
1565
|
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1566
|
+
var res = this.tail.value;
|
|
1567
|
+
this.tail = this.tail.prev;
|
|
1568
|
+
if (this.tail) {
|
|
1569
|
+
this.tail.next = null;
|
|
1570
|
+
} else {
|
|
1571
|
+
this.head = null;
|
|
1572
|
+
}
|
|
1573
|
+
this.length--;
|
|
1574
|
+
return res
|
|
1575
|
+
};
|
|
1575
1576
|
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
} else {
|
|
1581
|
-
this.tail = null;
|
|
1582
|
-
}
|
|
1583
|
-
this.length--;
|
|
1584
|
-
return res
|
|
1585
|
-
};
|
|
1577
|
+
Yallist.prototype.shift = function () {
|
|
1578
|
+
if (!this.head) {
|
|
1579
|
+
return undefined
|
|
1580
|
+
}
|
|
1586
1581
|
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
}
|
|
1582
|
+
var res = this.head.value;
|
|
1583
|
+
this.head = this.head.next;
|
|
1584
|
+
if (this.head) {
|
|
1585
|
+
this.head.prev = null;
|
|
1586
|
+
} else {
|
|
1587
|
+
this.tail = null;
|
|
1588
|
+
}
|
|
1589
|
+
this.length--;
|
|
1590
|
+
return res
|
|
1591
|
+
};
|
|
1594
1592
|
|
|
1595
|
-
Yallist
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
};
|
|
1593
|
+
Yallist.prototype.forEach = function (fn, thisp) {
|
|
1594
|
+
thisp = thisp || this;
|
|
1595
|
+
for (var walker = this.head, i = 0; walker !== null; i++) {
|
|
1596
|
+
fn.call(thisp, walker.value, i, this);
|
|
1597
|
+
walker = walker.next;
|
|
1598
|
+
}
|
|
1599
|
+
};
|
|
1602
1600
|
|
|
1603
|
-
Yallist
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
}
|
|
1611
|
-
};
|
|
1601
|
+
Yallist.prototype.forEachReverse = function (fn, thisp) {
|
|
1602
|
+
thisp = thisp || this;
|
|
1603
|
+
for (var walker = this.tail, i = this.length - 1; walker !== null; i--) {
|
|
1604
|
+
fn.call(thisp, walker.value, i, this);
|
|
1605
|
+
walker = walker.prev;
|
|
1606
|
+
}
|
|
1607
|
+
};
|
|
1612
1608
|
|
|
1613
|
-
Yallist
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
};
|
|
1609
|
+
Yallist.prototype.get = function (n) {
|
|
1610
|
+
for (var i = 0, walker = this.head; walker !== null && i < n; i++) {
|
|
1611
|
+
// abort out of the list early if we hit a cycle
|
|
1612
|
+
walker = walker.next;
|
|
1613
|
+
}
|
|
1614
|
+
if (i === n && walker !== null) {
|
|
1615
|
+
return walker.value
|
|
1616
|
+
}
|
|
1617
|
+
};
|
|
1622
1618
|
|
|
1623
|
-
Yallist
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
};
|
|
1619
|
+
Yallist.prototype.getReverse = function (n) {
|
|
1620
|
+
for (var i = 0, walker = this.tail; walker !== null && i < n; i++) {
|
|
1621
|
+
// abort out of the list early if we hit a cycle
|
|
1622
|
+
walker = walker.prev;
|
|
1623
|
+
}
|
|
1624
|
+
if (i === n && walker !== null) {
|
|
1625
|
+
return walker.value
|
|
1626
|
+
}
|
|
1627
|
+
};
|
|
1632
1628
|
|
|
1633
|
-
Yallist
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
};
|
|
1629
|
+
Yallist.prototype.map = function (fn, thisp) {
|
|
1630
|
+
thisp = thisp || this;
|
|
1631
|
+
var res = new Yallist();
|
|
1632
|
+
for (var walker = this.head; walker !== null;) {
|
|
1633
|
+
res.push(fn.call(thisp, walker.value, this));
|
|
1634
|
+
walker = walker.next;
|
|
1635
|
+
}
|
|
1636
|
+
return res
|
|
1637
|
+
};
|
|
1642
1638
|
|
|
1643
|
-
Yallist
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
throw new TypeError('Reduce of empty list with no initial value')
|
|
1653
|
-
}
|
|
1639
|
+
Yallist.prototype.mapReverse = function (fn, thisp) {
|
|
1640
|
+
thisp = thisp || this;
|
|
1641
|
+
var res = new Yallist();
|
|
1642
|
+
for (var walker = this.tail; walker !== null;) {
|
|
1643
|
+
res.push(fn.call(thisp, walker.value, this));
|
|
1644
|
+
walker = walker.prev;
|
|
1645
|
+
}
|
|
1646
|
+
return res
|
|
1647
|
+
};
|
|
1654
1648
|
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1649
|
+
Yallist.prototype.reduce = function (fn, initial) {
|
|
1650
|
+
var acc;
|
|
1651
|
+
var walker = this.head;
|
|
1652
|
+
if (arguments.length > 1) {
|
|
1653
|
+
acc = initial;
|
|
1654
|
+
} else if (this.head) {
|
|
1655
|
+
walker = this.head.next;
|
|
1656
|
+
acc = this.head.value;
|
|
1657
|
+
} else {
|
|
1658
|
+
throw new TypeError('Reduce of empty list with no initial value')
|
|
1659
|
+
}
|
|
1659
1660
|
|
|
1660
|
-
|
|
1661
|
-
|
|
1661
|
+
for (var i = 0; walker !== null; i++) {
|
|
1662
|
+
acc = fn(acc, walker.value, i);
|
|
1663
|
+
walker = walker.next;
|
|
1664
|
+
}
|
|
1662
1665
|
|
|
1663
|
-
|
|
1664
|
-
|
|
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
|
-
}
|
|
1666
|
+
return acc
|
|
1667
|
+
};
|
|
1674
1668
|
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1669
|
+
Yallist.prototype.reduceReverse = function (fn, initial) {
|
|
1670
|
+
var acc;
|
|
1671
|
+
var walker = this.tail;
|
|
1672
|
+
if (arguments.length > 1) {
|
|
1673
|
+
acc = initial;
|
|
1674
|
+
} else if (this.tail) {
|
|
1675
|
+
walker = this.tail.prev;
|
|
1676
|
+
acc = this.tail.value;
|
|
1677
|
+
} else {
|
|
1678
|
+
throw new TypeError('Reduce of empty list with no initial value')
|
|
1679
|
+
}
|
|
1679
1680
|
|
|
1680
|
-
|
|
1681
|
-
|
|
1681
|
+
for (var i = this.length - 1; walker !== null; i--) {
|
|
1682
|
+
acc = fn(acc, walker.value, i);
|
|
1683
|
+
walker = walker.prev;
|
|
1684
|
+
}
|
|
1682
1685
|
|
|
1683
|
-
|
|
1684
|
-
|
|
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
|
-
};
|
|
1686
|
+
return acc
|
|
1687
|
+
};
|
|
1691
1688
|
|
|
1692
|
-
Yallist
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
};
|
|
1689
|
+
Yallist.prototype.toArray = function () {
|
|
1690
|
+
var arr = new Array(this.length);
|
|
1691
|
+
for (var i = 0, walker = this.head; walker !== null; i++) {
|
|
1692
|
+
arr[i] = walker.value;
|
|
1693
|
+
walker = walker.next;
|
|
1694
|
+
}
|
|
1695
|
+
return arr
|
|
1696
|
+
};
|
|
1700
1697
|
|
|
1701
|
-
Yallist
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
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
|
-
};
|
|
1698
|
+
Yallist.prototype.toArrayReverse = function () {
|
|
1699
|
+
var arr = new Array(this.length);
|
|
1700
|
+
for (var i = 0, walker = this.tail; walker !== null; i++) {
|
|
1701
|
+
arr[i] = walker.value;
|
|
1702
|
+
walker = walker.prev;
|
|
1703
|
+
}
|
|
1704
|
+
return arr
|
|
1705
|
+
};
|
|
1728
1706
|
|
|
1729
|
-
Yallist
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
};
|
|
1707
|
+
Yallist.prototype.slice = function (from, to) {
|
|
1708
|
+
to = to || this.length;
|
|
1709
|
+
if (to < 0) {
|
|
1710
|
+
to += this.length;
|
|
1711
|
+
}
|
|
1712
|
+
from = from || 0;
|
|
1713
|
+
if (from < 0) {
|
|
1714
|
+
from += this.length;
|
|
1715
|
+
}
|
|
1716
|
+
var ret = new Yallist();
|
|
1717
|
+
if (to < from || to < 0) {
|
|
1718
|
+
return ret
|
|
1719
|
+
}
|
|
1720
|
+
if (from < 0) {
|
|
1721
|
+
from = 0;
|
|
1722
|
+
}
|
|
1723
|
+
if (to > this.length) {
|
|
1724
|
+
to = this.length;
|
|
1725
|
+
}
|
|
1726
|
+
for (var i = 0, walker = this.head; walker !== null && i < from; i++) {
|
|
1727
|
+
walker = walker.next;
|
|
1728
|
+
}
|
|
1729
|
+
for (; walker !== null && i < to; i++, walker = walker.next) {
|
|
1730
|
+
ret.push(walker.value);
|
|
1731
|
+
}
|
|
1732
|
+
return ret
|
|
1733
|
+
};
|
|
1756
1734
|
|
|
1757
|
-
Yallist
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1735
|
+
Yallist.prototype.sliceReverse = function (from, to) {
|
|
1736
|
+
to = to || this.length;
|
|
1737
|
+
if (to < 0) {
|
|
1738
|
+
to += this.length;
|
|
1739
|
+
}
|
|
1740
|
+
from = from || 0;
|
|
1741
|
+
if (from < 0) {
|
|
1742
|
+
from += this.length;
|
|
1743
|
+
}
|
|
1744
|
+
var ret = new Yallist();
|
|
1745
|
+
if (to < from || to < 0) {
|
|
1746
|
+
return ret
|
|
1747
|
+
}
|
|
1748
|
+
if (from < 0) {
|
|
1749
|
+
from = 0;
|
|
1750
|
+
}
|
|
1751
|
+
if (to > this.length) {
|
|
1752
|
+
to = this.length;
|
|
1753
|
+
}
|
|
1754
|
+
for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) {
|
|
1755
|
+
walker = walker.prev;
|
|
1756
|
+
}
|
|
1757
|
+
for (; walker !== null && i > from; i--, walker = walker.prev) {
|
|
1758
|
+
ret.push(walker.value);
|
|
1759
|
+
}
|
|
1760
|
+
return ret
|
|
1761
|
+
};
|
|
1764
1762
|
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1763
|
+
Yallist.prototype.splice = function (start, deleteCount, ...nodes) {
|
|
1764
|
+
if (start > this.length) {
|
|
1765
|
+
start = this.length - 1;
|
|
1766
|
+
}
|
|
1767
|
+
if (start < 0) {
|
|
1768
|
+
start = this.length + start;
|
|
1769
|
+
}
|
|
1768
1770
|
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
walker = this.removeNode(walker);
|
|
1773
|
-
}
|
|
1774
|
-
if (walker === null) {
|
|
1775
|
-
walker = this.tail;
|
|
1776
|
-
}
|
|
1771
|
+
for (var i = 0, walker = this.head; walker !== null && i < start; i++) {
|
|
1772
|
+
walker = walker.next;
|
|
1773
|
+
}
|
|
1777
1774
|
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1775
|
+
var ret = [];
|
|
1776
|
+
for (var i = 0; walker && i < deleteCount; i++) {
|
|
1777
|
+
ret.push(walker.value);
|
|
1778
|
+
walker = this.removeNode(walker);
|
|
1779
|
+
}
|
|
1780
|
+
if (walker === null) {
|
|
1781
|
+
walker = this.tail;
|
|
1782
|
+
}
|
|
1781
1783
|
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
return ret;
|
|
1786
|
-
};
|
|
1784
|
+
if (walker !== this.head && walker !== this.tail) {
|
|
1785
|
+
walker = walker.prev;
|
|
1786
|
+
}
|
|
1787
1787
|
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
walker.prev = walker.next;
|
|
1794
|
-
walker.next = p;
|
|
1795
|
-
}
|
|
1796
|
-
this.head = tail;
|
|
1797
|
-
this.tail = head;
|
|
1798
|
-
return this
|
|
1799
|
-
};
|
|
1788
|
+
for (var i = 0; i < nodes.length; i++) {
|
|
1789
|
+
walker = insert(this, walker, nodes[i]);
|
|
1790
|
+
}
|
|
1791
|
+
return ret;
|
|
1792
|
+
};
|
|
1800
1793
|
|
|
1801
|
-
function
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1794
|
+
Yallist.prototype.reverse = function () {
|
|
1795
|
+
var head = this.head;
|
|
1796
|
+
var tail = this.tail;
|
|
1797
|
+
for (var walker = head; walker !== null; walker = walker.prev) {
|
|
1798
|
+
var p = walker.prev;
|
|
1799
|
+
walker.prev = walker.next;
|
|
1800
|
+
walker.next = p;
|
|
1801
|
+
}
|
|
1802
|
+
this.head = tail;
|
|
1803
|
+
this.tail = head;
|
|
1804
|
+
return this
|
|
1805
|
+
};
|
|
1805
1806
|
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
self.head = inserted;
|
|
1811
|
-
}
|
|
1807
|
+
function insert (self, node, value) {
|
|
1808
|
+
var inserted = node === self.head ?
|
|
1809
|
+
new Node(value, null, node, self) :
|
|
1810
|
+
new Node(value, node, node.next, self);
|
|
1812
1811
|
|
|
1813
|
-
|
|
1812
|
+
if (inserted.next === null) {
|
|
1813
|
+
self.tail = inserted;
|
|
1814
|
+
}
|
|
1815
|
+
if (inserted.prev === null) {
|
|
1816
|
+
self.head = inserted;
|
|
1817
|
+
}
|
|
1814
1818
|
|
|
1815
|
-
|
|
1816
|
-
}
|
|
1819
|
+
self.length++;
|
|
1817
1820
|
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
if (!self.head) {
|
|
1821
|
-
self.head = self.tail;
|
|
1822
|
-
}
|
|
1823
|
-
self.length++;
|
|
1824
|
-
}
|
|
1821
|
+
return inserted
|
|
1822
|
+
}
|
|
1825
1823
|
|
|
1826
|
-
function
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
}
|
|
1824
|
+
function push (self, item) {
|
|
1825
|
+
self.tail = new Node(item, self.tail, null, self);
|
|
1826
|
+
if (!self.head) {
|
|
1827
|
+
self.head = self.tail;
|
|
1828
|
+
}
|
|
1829
|
+
self.length++;
|
|
1830
|
+
}
|
|
1833
1831
|
|
|
1834
|
-
function
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1832
|
+
function unshift (self, item) {
|
|
1833
|
+
self.head = new Node(item, null, self.head, self);
|
|
1834
|
+
if (!self.tail) {
|
|
1835
|
+
self.tail = self.head;
|
|
1836
|
+
}
|
|
1837
|
+
self.length++;
|
|
1838
|
+
}
|
|
1838
1839
|
|
|
1839
|
-
|
|
1840
|
-
|
|
1840
|
+
function Node (value, prev, next, list) {
|
|
1841
|
+
if (!(this instanceof Node)) {
|
|
1842
|
+
return new Node(value, prev, next, list)
|
|
1843
|
+
}
|
|
1841
1844
|
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
this.prev = prev;
|
|
1845
|
-
} else {
|
|
1846
|
-
this.prev = null;
|
|
1847
|
-
}
|
|
1845
|
+
this.list = list;
|
|
1846
|
+
this.value = value;
|
|
1848
1847
|
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1848
|
+
if (prev) {
|
|
1849
|
+
prev.next = this;
|
|
1850
|
+
this.prev = prev;
|
|
1851
|
+
} else {
|
|
1852
|
+
this.prev = null;
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1855
|
+
if (next) {
|
|
1856
|
+
next.prev = this;
|
|
1857
|
+
this.next = next;
|
|
1858
|
+
} else {
|
|
1859
|
+
this.next = null;
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
try {
|
|
1864
|
+
// add if support for Symbol.iterator is present
|
|
1865
|
+
requireIterator()(Yallist);
|
|
1866
|
+
} catch (er) {}
|
|
1867
|
+
return yallist;
|
|
1855
1868
|
}
|
|
1856
1869
|
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
const
|
|
1866
|
-
|
|
1867
|
-
const
|
|
1868
|
-
const
|
|
1869
|
-
const
|
|
1870
|
-
const
|
|
1871
|
-
const
|
|
1872
|
-
const
|
|
1873
|
-
const
|
|
1874
|
-
const
|
|
1875
|
-
|
|
1876
|
-
const
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
//
|
|
1881
|
-
//
|
|
1882
|
-
//
|
|
1883
|
-
//
|
|
1884
|
-
//
|
|
1885
|
-
//
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1870
|
+
var lruCache;
|
|
1871
|
+
var hasRequiredLruCache;
|
|
1872
|
+
|
|
1873
|
+
function requireLruCache () {
|
|
1874
|
+
if (hasRequiredLruCache) return lruCache;
|
|
1875
|
+
hasRequiredLruCache = 1;
|
|
1876
|
+
|
|
1877
|
+
// A linked list to keep track of recently-used-ness
|
|
1878
|
+
const Yallist = requireYallist();
|
|
1879
|
+
|
|
1880
|
+
const MAX = Symbol('max');
|
|
1881
|
+
const LENGTH = Symbol('length');
|
|
1882
|
+
const LENGTH_CALCULATOR = Symbol('lengthCalculator');
|
|
1883
|
+
const ALLOW_STALE = Symbol('allowStale');
|
|
1884
|
+
const MAX_AGE = Symbol('maxAge');
|
|
1885
|
+
const DISPOSE = Symbol('dispose');
|
|
1886
|
+
const NO_DISPOSE_ON_SET = Symbol('noDisposeOnSet');
|
|
1887
|
+
const LRU_LIST = Symbol('lruList');
|
|
1888
|
+
const CACHE = Symbol('cache');
|
|
1889
|
+
const UPDATE_AGE_ON_GET = Symbol('updateAgeOnGet');
|
|
1890
|
+
|
|
1891
|
+
const naiveLength = () => 1;
|
|
1892
|
+
|
|
1893
|
+
// lruList is a yallist where the head is the youngest
|
|
1894
|
+
// item, and the tail is the oldest. the list contains the Hit
|
|
1895
|
+
// objects as the entries.
|
|
1896
|
+
// Each Hit object has a reference to its Yallist.Node. This
|
|
1897
|
+
// never changes.
|
|
1898
|
+
//
|
|
1899
|
+
// cache is a Map (or PseudoMap) that matches the keys to
|
|
1900
|
+
// the Yallist.Node object.
|
|
1901
|
+
class LRUCache {
|
|
1902
|
+
constructor (options) {
|
|
1903
|
+
if (typeof options === 'number')
|
|
1904
|
+
options = { max: options };
|
|
1905
|
+
|
|
1906
|
+
if (!options)
|
|
1907
|
+
options = {};
|
|
1908
|
+
|
|
1909
|
+
if (options.max && (typeof options.max !== 'number' || options.max < 0))
|
|
1910
|
+
throw new TypeError('max must be a non-negative number')
|
|
1911
|
+
// Kind of weird to have a default max of Infinity, but oh well.
|
|
1912
|
+
this[MAX] = options.max || Infinity;
|
|
1913
|
+
|
|
1914
|
+
const lc = options.length || naiveLength;
|
|
1915
|
+
this[LENGTH_CALCULATOR] = (typeof lc !== 'function') ? naiveLength : lc;
|
|
1916
|
+
this[ALLOW_STALE] = options.stale || false;
|
|
1917
|
+
if (options.maxAge && typeof options.maxAge !== 'number')
|
|
1918
|
+
throw new TypeError('maxAge must be a number')
|
|
1919
|
+
this[MAX_AGE] = options.maxAge || 0;
|
|
1920
|
+
this[DISPOSE] = options.dispose;
|
|
1921
|
+
this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false;
|
|
1922
|
+
this[UPDATE_AGE_ON_GET] = options.updateAgeOnGet || false;
|
|
1923
|
+
this.reset();
|
|
1924
|
+
}
|
|
1910
1925
|
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1926
|
+
// resize the cache when the max changes.
|
|
1927
|
+
set max (mL) {
|
|
1928
|
+
if (typeof mL !== 'number' || mL < 0)
|
|
1929
|
+
throw new TypeError('max must be a non-negative number')
|
|
1915
1930
|
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1931
|
+
this[MAX] = mL || Infinity;
|
|
1932
|
+
trim(this);
|
|
1933
|
+
}
|
|
1934
|
+
get max () {
|
|
1935
|
+
return this[MAX]
|
|
1936
|
+
}
|
|
1922
1937
|
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1938
|
+
set allowStale (allowStale) {
|
|
1939
|
+
this[ALLOW_STALE] = !!allowStale;
|
|
1940
|
+
}
|
|
1941
|
+
get allowStale () {
|
|
1942
|
+
return this[ALLOW_STALE]
|
|
1943
|
+
}
|
|
1929
1944
|
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1945
|
+
set maxAge (mA) {
|
|
1946
|
+
if (typeof mA !== 'number')
|
|
1947
|
+
throw new TypeError('maxAge must be a non-negative number')
|
|
1933
1948
|
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1949
|
+
this[MAX_AGE] = mA;
|
|
1950
|
+
trim(this);
|
|
1951
|
+
}
|
|
1952
|
+
get maxAge () {
|
|
1953
|
+
return this[MAX_AGE]
|
|
1954
|
+
}
|
|
1940
1955
|
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1956
|
+
// resize the cache when the lengthCalculator changes.
|
|
1957
|
+
set lengthCalculator (lC) {
|
|
1958
|
+
if (typeof lC !== 'function')
|
|
1959
|
+
lC = naiveLength;
|
|
1960
|
+
|
|
1961
|
+
if (lC !== this[LENGTH_CALCULATOR]) {
|
|
1962
|
+
this[LENGTH_CALCULATOR] = lC;
|
|
1963
|
+
this[LENGTH] = 0;
|
|
1964
|
+
this[LRU_LIST].forEach(hit => {
|
|
1965
|
+
hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key);
|
|
1966
|
+
this[LENGTH] += hit.length;
|
|
1967
|
+
});
|
|
1968
|
+
}
|
|
1969
|
+
trim(this);
|
|
1970
|
+
}
|
|
1971
|
+
get lengthCalculator () { return this[LENGTH_CALCULATOR] }
|
|
1957
1972
|
|
|
1958
|
-
|
|
1959
|
-
|
|
1973
|
+
get length () { return this[LENGTH] }
|
|
1974
|
+
get itemCount () { return this[LRU_LIST].length }
|
|
1960
1975
|
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1976
|
+
rforEach (fn, thisp) {
|
|
1977
|
+
thisp = thisp || this;
|
|
1978
|
+
for (let walker = this[LRU_LIST].tail; walker !== null;) {
|
|
1979
|
+
const prev = walker.prev;
|
|
1980
|
+
forEachStep(this, fn, walker, thisp);
|
|
1981
|
+
walker = prev;
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1969
1984
|
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1985
|
+
forEach (fn, thisp) {
|
|
1986
|
+
thisp = thisp || this;
|
|
1987
|
+
for (let walker = this[LRU_LIST].head; walker !== null;) {
|
|
1988
|
+
const next = walker.next;
|
|
1989
|
+
forEachStep(this, fn, walker, thisp);
|
|
1990
|
+
walker = next;
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1978
1993
|
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1994
|
+
keys () {
|
|
1995
|
+
return this[LRU_LIST].toArray().map(k => k.key)
|
|
1996
|
+
}
|
|
1982
1997
|
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1998
|
+
values () {
|
|
1999
|
+
return this[LRU_LIST].toArray().map(k => k.value)
|
|
2000
|
+
}
|
|
1986
2001
|
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
2002
|
+
reset () {
|
|
2003
|
+
if (this[DISPOSE] &&
|
|
2004
|
+
this[LRU_LIST] &&
|
|
2005
|
+
this[LRU_LIST].length) {
|
|
2006
|
+
this[LRU_LIST].forEach(hit => this[DISPOSE](hit.key, hit.value));
|
|
2007
|
+
}
|
|
1993
2008
|
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
2009
|
+
this[CACHE] = new Map(); // hash of items by key
|
|
2010
|
+
this[LRU_LIST] = new Yallist(); // list of items in order of use recency
|
|
2011
|
+
this[LENGTH] = 0; // length of items in the list
|
|
2012
|
+
}
|
|
1998
2013
|
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2014
|
+
dump () {
|
|
2015
|
+
return this[LRU_LIST].map(hit =>
|
|
2016
|
+
isStale(this, hit) ? false : {
|
|
2017
|
+
k: hit.key,
|
|
2018
|
+
v: hit.value,
|
|
2019
|
+
e: hit.now + (hit.maxAge || 0)
|
|
2020
|
+
}).toArray().filter(h => h)
|
|
2021
|
+
}
|
|
2007
2022
|
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2023
|
+
dumpLru () {
|
|
2024
|
+
return this[LRU_LIST]
|
|
2025
|
+
}
|
|
2011
2026
|
|
|
2012
|
-
|
|
2013
|
-
|
|
2027
|
+
set (key, value, maxAge) {
|
|
2028
|
+
maxAge = maxAge || this[MAX_AGE];
|
|
2014
2029
|
|
|
2015
|
-
|
|
2016
|
-
|
|
2030
|
+
if (maxAge && typeof maxAge !== 'number')
|
|
2031
|
+
throw new TypeError('maxAge must be a number')
|
|
2017
2032
|
|
|
2018
|
-
|
|
2019
|
-
|
|
2033
|
+
const now = maxAge ? Date.now() : 0;
|
|
2034
|
+
const len = this[LENGTH_CALCULATOR](value, key);
|
|
2020
2035
|
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2036
|
+
if (this[CACHE].has(key)) {
|
|
2037
|
+
if (len > this[MAX]) {
|
|
2038
|
+
del(this, this[CACHE].get(key));
|
|
2039
|
+
return false
|
|
2040
|
+
}
|
|
2026
2041
|
|
|
2027
|
-
|
|
2028
|
-
|
|
2042
|
+
const node = this[CACHE].get(key);
|
|
2043
|
+
const item = node.value;
|
|
2029
2044
|
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2045
|
+
// dispose of the old one before overwriting
|
|
2046
|
+
// split out into 2 ifs for better coverage tracking
|
|
2047
|
+
if (this[DISPOSE]) {
|
|
2048
|
+
if (!this[NO_DISPOSE_ON_SET])
|
|
2049
|
+
this[DISPOSE](key, item.value);
|
|
2050
|
+
}
|
|
2036
2051
|
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2052
|
+
item.now = now;
|
|
2053
|
+
item.maxAge = maxAge;
|
|
2054
|
+
item.value = value;
|
|
2055
|
+
this[LENGTH] += len - item.length;
|
|
2056
|
+
item.length = len;
|
|
2057
|
+
this.get(key);
|
|
2058
|
+
trim(this);
|
|
2059
|
+
return true
|
|
2060
|
+
}
|
|
2046
2061
|
|
|
2047
|
-
|
|
2062
|
+
const hit = new Entry(key, value, len, now, maxAge);
|
|
2048
2063
|
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2064
|
+
// oversized objects fall out of cache automatically.
|
|
2065
|
+
if (hit.length > this[MAX]) {
|
|
2066
|
+
if (this[DISPOSE])
|
|
2067
|
+
this[DISPOSE](key, value);
|
|
2053
2068
|
|
|
2054
|
-
|
|
2055
|
-
|
|
2069
|
+
return false
|
|
2070
|
+
}
|
|
2056
2071
|
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2072
|
+
this[LENGTH] += hit.length;
|
|
2073
|
+
this[LRU_LIST].unshift(hit);
|
|
2074
|
+
this[CACHE].set(key, this[LRU_LIST].head);
|
|
2075
|
+
trim(this);
|
|
2076
|
+
return true
|
|
2077
|
+
}
|
|
2063
2078
|
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2079
|
+
has (key) {
|
|
2080
|
+
if (!this[CACHE].has(key)) return false
|
|
2081
|
+
const hit = this[CACHE].get(key).value;
|
|
2082
|
+
return !isStale(this, hit)
|
|
2083
|
+
}
|
|
2069
2084
|
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2085
|
+
get (key) {
|
|
2086
|
+
return get(this, key, true)
|
|
2087
|
+
}
|
|
2073
2088
|
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2089
|
+
peek (key) {
|
|
2090
|
+
return get(this, key, false)
|
|
2091
|
+
}
|
|
2077
2092
|
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2093
|
+
pop () {
|
|
2094
|
+
const node = this[LRU_LIST].tail;
|
|
2095
|
+
if (!node)
|
|
2096
|
+
return null
|
|
2082
2097
|
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2098
|
+
del(this, node);
|
|
2099
|
+
return node.value
|
|
2100
|
+
}
|
|
2086
2101
|
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2102
|
+
del (key) {
|
|
2103
|
+
del(this, this[CACHE].get(key));
|
|
2104
|
+
}
|
|
2090
2105
|
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2106
|
+
load (arr) {
|
|
2107
|
+
// reset the cache
|
|
2108
|
+
this.reset();
|
|
2109
|
+
|
|
2110
|
+
const now = Date.now();
|
|
2111
|
+
// A previous serialized cache has the most recent items first
|
|
2112
|
+
for (let l = arr.length - 1; l >= 0; l--) {
|
|
2113
|
+
const hit = arr[l];
|
|
2114
|
+
const expiresAt = hit.e || 0;
|
|
2115
|
+
if (expiresAt === 0)
|
|
2116
|
+
// the item was created without expiration in a non aged cache
|
|
2117
|
+
this.set(hit.k, hit.v);
|
|
2118
|
+
else {
|
|
2119
|
+
const maxAge = expiresAt - now;
|
|
2120
|
+
// dont add already expired items
|
|
2121
|
+
if (maxAge > 0) {
|
|
2122
|
+
this.set(hit.k, hit.v, maxAge);
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2112
2127
|
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
}
|
|
2128
|
+
prune () {
|
|
2129
|
+
this[CACHE].forEach((value, key) => get(this, key, false));
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2117
2132
|
|
|
2118
|
-
const get = (self, key, doUse) => {
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
};
|
|
2133
|
+
const get = (self, key, doUse) => {
|
|
2134
|
+
const node = self[CACHE].get(key);
|
|
2135
|
+
if (node) {
|
|
2136
|
+
const hit = node.value;
|
|
2137
|
+
if (isStale(self, hit)) {
|
|
2138
|
+
del(self, node);
|
|
2139
|
+
if (!self[ALLOW_STALE])
|
|
2140
|
+
return undefined
|
|
2141
|
+
} else {
|
|
2142
|
+
if (doUse) {
|
|
2143
|
+
if (self[UPDATE_AGE_ON_GET])
|
|
2144
|
+
node.value.now = Date.now();
|
|
2145
|
+
self[LRU_LIST].unshiftNode(node);
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
return hit.value
|
|
2149
|
+
}
|
|
2150
|
+
};
|
|
2136
2151
|
|
|
2137
|
-
const isStale = (self, hit) => {
|
|
2138
|
-
|
|
2139
|
-
|
|
2152
|
+
const isStale = (self, hit) => {
|
|
2153
|
+
if (!hit || (!hit.maxAge && !self[MAX_AGE]))
|
|
2154
|
+
return false
|
|
2140
2155
|
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
};
|
|
2156
|
+
const diff = Date.now() - hit.now;
|
|
2157
|
+
return hit.maxAge ? diff > hit.maxAge
|
|
2158
|
+
: self[MAX_AGE] && (diff > self[MAX_AGE])
|
|
2159
|
+
};
|
|
2145
2160
|
|
|
2146
|
-
const trim = self => {
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
};
|
|
2161
|
+
const trim = self => {
|
|
2162
|
+
if (self[LENGTH] > self[MAX]) {
|
|
2163
|
+
for (let walker = self[LRU_LIST].tail;
|
|
2164
|
+
self[LENGTH] > self[MAX] && walker !== null;) {
|
|
2165
|
+
// We know that we're about to delete this one, and also
|
|
2166
|
+
// what the next least recently used key will be, so just
|
|
2167
|
+
// go ahead and set it now.
|
|
2168
|
+
const prev = walker.prev;
|
|
2169
|
+
del(self, walker);
|
|
2170
|
+
walker = prev;
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
};
|
|
2159
2174
|
|
|
2160
|
-
const del = (self, node) => {
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2175
|
+
const del = (self, node) => {
|
|
2176
|
+
if (node) {
|
|
2177
|
+
const hit = node.value;
|
|
2178
|
+
if (self[DISPOSE])
|
|
2179
|
+
self[DISPOSE](hit.key, hit.value);
|
|
2165
2180
|
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
};
|
|
2181
|
+
self[LENGTH] -= hit.length;
|
|
2182
|
+
self[CACHE].delete(hit.key);
|
|
2183
|
+
self[LRU_LIST].removeNode(node);
|
|
2184
|
+
}
|
|
2185
|
+
};
|
|
2171
2186
|
|
|
2172
|
-
class Entry {
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
}
|
|
2187
|
+
class Entry {
|
|
2188
|
+
constructor (key, value, length, now, maxAge) {
|
|
2189
|
+
this.key = key;
|
|
2190
|
+
this.value = value;
|
|
2191
|
+
this.length = length;
|
|
2192
|
+
this.now = now;
|
|
2193
|
+
this.maxAge = maxAge || 0;
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2181
2196
|
|
|
2182
|
-
const forEachStep = (self, fn, node, thisp) => {
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
};
|
|
2197
|
+
const forEachStep = (self, fn, node, thisp) => {
|
|
2198
|
+
let hit = node.value;
|
|
2199
|
+
if (isStale(self, hit)) {
|
|
2200
|
+
del(self, node);
|
|
2201
|
+
if (!self[ALLOW_STALE])
|
|
2202
|
+
hit = undefined;
|
|
2203
|
+
}
|
|
2204
|
+
if (hit)
|
|
2205
|
+
fn.call(thisp, hit.value, hit.key, self);
|
|
2206
|
+
};
|
|
2192
2207
|
|
|
2193
|
-
|
|
2208
|
+
lruCache = LRUCache;
|
|
2209
|
+
return lruCache;
|
|
2210
|
+
}
|
|
2194
2211
|
|
|
2195
2212
|
var range;
|
|
2196
2213
|
var hasRequiredRange;
|
|
@@ -2398,7 +2415,7 @@ function requireRange () {
|
|
|
2398
2415
|
|
|
2399
2416
|
range = Range;
|
|
2400
2417
|
|
|
2401
|
-
const LRU =
|
|
2418
|
+
const LRU = requireLruCache();
|
|
2402
2419
|
const cache = new LRU({ max: 1000 });
|
|
2403
2420
|
|
|
2404
2421
|
const parseOptions = parseOptions_1;
|
|
@@ -3898,7 +3915,15 @@ class Machine {
|
|
|
3898
3915
|
index: 0,
|
|
3899
3916
|
hash: ''
|
|
3900
3917
|
},
|
|
3901
|
-
accounts: {}
|
|
3918
|
+
accounts: {},
|
|
3919
|
+
info: {
|
|
3920
|
+
nativeCalls: 0,
|
|
3921
|
+
nativeMints: 0,
|
|
3922
|
+
nativeBurns: 0,
|
|
3923
|
+
nativeTransfers: 0,
|
|
3924
|
+
totalTransactions: 0,
|
|
3925
|
+
totalBlocks: 0
|
|
3926
|
+
}
|
|
3902
3927
|
};
|
|
3903
3928
|
// @ts-ignore
|
|
3904
3929
|
return this.#init(blocks);
|
|
@@ -3992,7 +4017,18 @@ class Machine {
|
|
|
3992
4017
|
const tasks = [
|
|
3993
4018
|
stateStore.put('lastBlock', JSON.stringify(await this.lastBlock)),
|
|
3994
4019
|
stateStore.put('states', JSON.stringify(state)),
|
|
3995
|
-
stateStore.put('accounts', JSON.stringify(accounts))
|
|
4020
|
+
stateStore.put('accounts', JSON.stringify(accounts)),
|
|
4021
|
+
stateStore.put('info', JSON.stringify({
|
|
4022
|
+
nativeCalls: this.nativeCalls,
|
|
4023
|
+
nativeMints: this.nativeMints,
|
|
4024
|
+
nativeBurns: this.nativeBurns,
|
|
4025
|
+
nativeTransfers: this.nativeTransfers,
|
|
4026
|
+
totalTransactions: this.totalTransactions,
|
|
4027
|
+
totalBurnAmount: this.totalBurnAmount,
|
|
4028
|
+
totaMintAmount: this.totaMintAmount,
|
|
4029
|
+
totalTransferAmount: this.totalTransferAmount,
|
|
4030
|
+
totalBlocks: await blockStore.length
|
|
4031
|
+
}))
|
|
3996
4032
|
// accountsStore.clear()
|
|
3997
4033
|
];
|
|
3998
4034
|
await Promise.all(tasks);
|
|
@@ -4031,9 +4067,19 @@ class Machine {
|
|
|
4031
4067
|
this.states.states = JSON.parse(new TextDecoder().decode(await stateStore.get('states')));
|
|
4032
4068
|
try {
|
|
4033
4069
|
this.states.accounts = JSON.parse(new TextDecoder().decode(await stateStore.get('accounts')));
|
|
4070
|
+
this.states.info = JSON.parse(new TextDecoder().decode(await stateStore.get('info')));
|
|
4034
4071
|
}
|
|
4035
4072
|
catch {
|
|
4036
4073
|
this.states.accounts = {};
|
|
4074
|
+
// todo try fetching info from fully synced peer
|
|
4075
|
+
this.states.info = {
|
|
4076
|
+
nativeCalls: 0,
|
|
4077
|
+
nativeMints: 0,
|
|
4078
|
+
nativeBurns: 0,
|
|
4079
|
+
nativeTransfers: 0,
|
|
4080
|
+
totalTransactions: 0,
|
|
4081
|
+
totalBlocks: 0
|
|
4082
|
+
};
|
|
4037
4083
|
}
|
|
4038
4084
|
console.log({ balances: this.states.states[addresses.nativeToken].balances });
|
|
4039
4085
|
}
|
|
@@ -4044,6 +4090,7 @@ class Machine {
|
|
|
4044
4090
|
fromState: this.states.lastBlock.index > 0,
|
|
4045
4091
|
lastBlock: this.states.lastBlock,
|
|
4046
4092
|
state: this.states.states,
|
|
4093
|
+
info: this.states.info,
|
|
4047
4094
|
// @ts-ignore
|
|
4048
4095
|
peerid: peernet.peerId
|
|
4049
4096
|
}
|
|
@@ -4209,6 +4256,15 @@ class Machine {
|
|
|
4209
4256
|
get totalBlocks() {
|
|
4210
4257
|
return this.#askWorker('totalBlocks');
|
|
4211
4258
|
}
|
|
4259
|
+
get totalBurnAmount() {
|
|
4260
|
+
return this.#askWorker('totalBurnAmount');
|
|
4261
|
+
}
|
|
4262
|
+
get totaMintAmount() {
|
|
4263
|
+
return this.#askWorker('totaMintAmount');
|
|
4264
|
+
}
|
|
4265
|
+
get totalTransferAmount() {
|
|
4266
|
+
return this.#askWorker('totalTransferAmount');
|
|
4267
|
+
}
|
|
4212
4268
|
getBlocks(from, to) {
|
|
4213
4269
|
return this.#askWorker('blocks', { from, to });
|
|
4214
4270
|
}
|
|
@@ -5034,9 +5090,11 @@ class Chain extends VersionControl {
|
|
|
5034
5090
|
else if (!this.knownBlocks)
|
|
5035
5091
|
this.knownBlocks = await this.#makeRequest(peer, 'knownBlocks');
|
|
5036
5092
|
}
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5093
|
+
setTimeout(async () => {
|
|
5094
|
+
const peerTransactionPool = (higherThenCurrentLocal && (await this.getPeerTransactionPool(peer))) || [];
|
|
5095
|
+
if (this.#participating && peerTransactionPool.length > 0)
|
|
5096
|
+
return this.#runEpoch();
|
|
5097
|
+
}, 3000);
|
|
5040
5098
|
}
|
|
5041
5099
|
#epochTimeout;
|
|
5042
5100
|
async #transactionPoolHandler() {
|