@leofcoin/chain 1.7.8 → 1.7.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.
- package/exports/browser/chain.js +675 -675
- package/exports/browser/workers/machine-worker.js +49 -28
- package/exports/chain.js +19 -2
- package/exports/machine.d.ts +1 -0
- package/exports/state.d.ts +1 -1
- package/exports/workers/machine-worker.js +49 -28
- package/package.json +1 -1
package/exports/browser/chain.js
CHANGED
|
@@ -1433,781 +1433,764 @@ function requireIterator () {
|
|
|
1433
1433
|
return iterator;
|
|
1434
1434
|
}
|
|
1435
1435
|
|
|
1436
|
-
var yallist;
|
|
1437
|
-
var hasRequiredYallist;
|
|
1436
|
+
var yallist = Yallist$1;
|
|
1438
1437
|
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
hasRequiredYallist = 1;
|
|
1442
|
-
yallist = Yallist;
|
|
1438
|
+
Yallist$1.Node = Node;
|
|
1439
|
+
Yallist$1.create = Yallist$1;
|
|
1443
1440
|
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
if (!(self instanceof Yallist)) {
|
|
1450
|
-
self = new Yallist();
|
|
1451
|
-
}
|
|
1441
|
+
function Yallist$1 (list) {
|
|
1442
|
+
var self = this;
|
|
1443
|
+
if (!(self instanceof Yallist$1)) {
|
|
1444
|
+
self = new Yallist$1();
|
|
1445
|
+
}
|
|
1452
1446
|
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1447
|
+
self.tail = null;
|
|
1448
|
+
self.head = null;
|
|
1449
|
+
self.length = 0;
|
|
1456
1450
|
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
return self
|
|
1468
|
-
}
|
|
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
|
+
}
|
|
1469
1460
|
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
throw new Error('removing node which does not belong to this list')
|
|
1473
|
-
}
|
|
1461
|
+
return self
|
|
1462
|
+
}
|
|
1474
1463
|
|
|
1475
|
-
|
|
1476
|
-
|
|
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
|
+
}
|
|
1477
1468
|
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
}
|
|
1469
|
+
var next = node.next;
|
|
1470
|
+
var prev = node.prev;
|
|
1481
1471
|
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1472
|
+
if (next) {
|
|
1473
|
+
next.prev = prev;
|
|
1474
|
+
}
|
|
1485
1475
|
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
if (node === this.tail) {
|
|
1490
|
-
this.tail = prev;
|
|
1491
|
-
}
|
|
1476
|
+
if (prev) {
|
|
1477
|
+
prev.next = next;
|
|
1478
|
+
}
|
|
1492
1479
|
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1480
|
+
if (node === this.head) {
|
|
1481
|
+
this.head = next;
|
|
1482
|
+
}
|
|
1483
|
+
if (node === this.tail) {
|
|
1484
|
+
this.tail = prev;
|
|
1485
|
+
}
|
|
1497
1486
|
|
|
1498
|
-
|
|
1499
|
-
|
|
1487
|
+
node.list.length--;
|
|
1488
|
+
node.next = null;
|
|
1489
|
+
node.prev = null;
|
|
1490
|
+
node.list = null;
|
|
1500
1491
|
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
return
|
|
1504
|
-
}
|
|
1492
|
+
return next
|
|
1493
|
+
};
|
|
1505
1494
|
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1495
|
+
Yallist$1.prototype.unshiftNode = function (node) {
|
|
1496
|
+
if (node === this.head) {
|
|
1497
|
+
return
|
|
1498
|
+
}
|
|
1509
1499
|
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
if (head) {
|
|
1514
|
-
head.prev = node;
|
|
1515
|
-
}
|
|
1500
|
+
if (node.list) {
|
|
1501
|
+
node.list.removeNode(node);
|
|
1502
|
+
}
|
|
1516
1503
|
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1504
|
+
var head = this.head;
|
|
1505
|
+
node.list = this;
|
|
1506
|
+
node.next = head;
|
|
1507
|
+
if (head) {
|
|
1508
|
+
head.prev = node;
|
|
1509
|
+
}
|
|
1523
1510
|
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1511
|
+
this.head = node;
|
|
1512
|
+
if (!this.tail) {
|
|
1513
|
+
this.tail = node;
|
|
1514
|
+
}
|
|
1515
|
+
this.length++;
|
|
1516
|
+
};
|
|
1528
1517
|
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1518
|
+
Yallist$1.prototype.pushNode = function (node) {
|
|
1519
|
+
if (node === this.tail) {
|
|
1520
|
+
return
|
|
1521
|
+
}
|
|
1532
1522
|
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
if (tail) {
|
|
1537
|
-
tail.next = node;
|
|
1538
|
-
}
|
|
1523
|
+
if (node.list) {
|
|
1524
|
+
node.list.removeNode(node);
|
|
1525
|
+
}
|
|
1539
1526
|
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1527
|
+
var tail = this.tail;
|
|
1528
|
+
node.list = this;
|
|
1529
|
+
node.prev = tail;
|
|
1530
|
+
if (tail) {
|
|
1531
|
+
tail.next = node;
|
|
1532
|
+
}
|
|
1546
1533
|
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1534
|
+
this.tail = node;
|
|
1535
|
+
if (!this.head) {
|
|
1536
|
+
this.head = node;
|
|
1537
|
+
}
|
|
1538
|
+
this.length++;
|
|
1539
|
+
};
|
|
1553
1540
|
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
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
|
+
};
|
|
1560
1547
|
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
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
|
+
};
|
|
1565
1554
|
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
} else {
|
|
1571
|
-
this.head = null;
|
|
1572
|
-
}
|
|
1573
|
-
this.length--;
|
|
1574
|
-
return res
|
|
1575
|
-
};
|
|
1555
|
+
Yallist$1.prototype.pop = function () {
|
|
1556
|
+
if (!this.tail) {
|
|
1557
|
+
return undefined
|
|
1558
|
+
}
|
|
1576
1559
|
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
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
|
+
};
|
|
1581
1570
|
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
} else {
|
|
1587
|
-
this.tail = null;
|
|
1588
|
-
}
|
|
1589
|
-
this.length--;
|
|
1590
|
-
return res
|
|
1591
|
-
};
|
|
1571
|
+
Yallist$1.prototype.shift = function () {
|
|
1572
|
+
if (!this.head) {
|
|
1573
|
+
return undefined
|
|
1574
|
+
}
|
|
1592
1575
|
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
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
|
+
};
|
|
1600
1586
|
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
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
|
+
};
|
|
1608
1594
|
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
}
|
|
1617
|
-
};
|
|
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
|
+
};
|
|
1618
1602
|
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
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
|
+
};
|
|
1628
1612
|
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
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
|
+
};
|
|
1638
1622
|
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
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
|
+
};
|
|
1648
1632
|
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
throw new TypeError('Reduce of empty list with no initial value')
|
|
1659
|
-
}
|
|
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
|
+
};
|
|
1660
1642
|
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
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
|
+
}
|
|
1665
1654
|
|
|
1666
|
-
|
|
1667
|
-
|
|
1655
|
+
for (var i = 0; walker !== null; i++) {
|
|
1656
|
+
acc = fn(acc, walker.value, i);
|
|
1657
|
+
walker = walker.next;
|
|
1658
|
+
}
|
|
1668
1659
|
|
|
1669
|
-
|
|
1670
|
-
|
|
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
|
-
}
|
|
1660
|
+
return acc
|
|
1661
|
+
};
|
|
1680
1662
|
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
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
|
+
}
|
|
1685
1674
|
|
|
1686
|
-
|
|
1687
|
-
|
|
1675
|
+
for (var i = this.length - 1; walker !== null; i--) {
|
|
1676
|
+
acc = fn(acc, walker.value, i);
|
|
1677
|
+
walker = walker.prev;
|
|
1678
|
+
}
|
|
1688
1679
|
|
|
1689
|
-
|
|
1690
|
-
|
|
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
|
-
};
|
|
1680
|
+
return acc
|
|
1681
|
+
};
|
|
1697
1682
|
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
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
|
+
};
|
|
1706
1691
|
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
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
|
-
};
|
|
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
|
+
};
|
|
1734
1700
|
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
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
|
+
};
|
|
1762
1728
|
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
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
|
+
};
|
|
1770
1756
|
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
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
|
+
}
|
|
1774
1764
|
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
walker = this.removeNode(walker);
|
|
1779
|
-
}
|
|
1780
|
-
if (walker === null) {
|
|
1781
|
-
walker = this.tail;
|
|
1782
|
-
}
|
|
1765
|
+
for (var i = 0, walker = this.head; walker !== null && i < start; i++) {
|
|
1766
|
+
walker = walker.next;
|
|
1767
|
+
}
|
|
1783
1768
|
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
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
|
+
}
|
|
1787
1777
|
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
return ret;
|
|
1792
|
-
};
|
|
1778
|
+
if (walker !== this.head && walker !== this.tail) {
|
|
1779
|
+
walker = walker.prev;
|
|
1780
|
+
}
|
|
1793
1781
|
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
walker.prev = walker.next;
|
|
1800
|
-
walker.next = p;
|
|
1801
|
-
}
|
|
1802
|
-
this.head = tail;
|
|
1803
|
-
this.tail = head;
|
|
1804
|
-
return this
|
|
1805
|
-
};
|
|
1782
|
+
for (var i = 0; i < nodes.length; i++) {
|
|
1783
|
+
walker = insert(this, walker, nodes[i]);
|
|
1784
|
+
}
|
|
1785
|
+
return ret;
|
|
1786
|
+
};
|
|
1806
1787
|
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
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
|
+
};
|
|
1811
1800
|
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
self.head = inserted;
|
|
1817
|
-
}
|
|
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);
|
|
1818
1805
|
|
|
1819
|
-
|
|
1806
|
+
if (inserted.next === null) {
|
|
1807
|
+
self.tail = inserted;
|
|
1808
|
+
}
|
|
1809
|
+
if (inserted.prev === null) {
|
|
1810
|
+
self.head = inserted;
|
|
1811
|
+
}
|
|
1820
1812
|
|
|
1821
|
-
|
|
1822
|
-
}
|
|
1813
|
+
self.length++;
|
|
1823
1814
|
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
if (!self.head) {
|
|
1827
|
-
self.head = self.tail;
|
|
1828
|
-
}
|
|
1829
|
-
self.length++;
|
|
1830
|
-
}
|
|
1815
|
+
return inserted
|
|
1816
|
+
}
|
|
1831
1817
|
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
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
|
+
}
|
|
1839
1825
|
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
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
|
+
}
|
|
1844
1833
|
|
|
1845
|
-
|
|
1846
|
-
|
|
1834
|
+
function Node (value, prev, next, list) {
|
|
1835
|
+
if (!(this instanceof Node)) {
|
|
1836
|
+
return new Node(value, prev, next, list)
|
|
1837
|
+
}
|
|
1847
1838
|
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
this.prev = prev;
|
|
1851
|
-
} else {
|
|
1852
|
-
this.prev = null;
|
|
1853
|
-
}
|
|
1839
|
+
this.list = list;
|
|
1840
|
+
this.value = value;
|
|
1854
1841
|
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
}
|
|
1842
|
+
if (prev) {
|
|
1843
|
+
prev.next = this;
|
|
1844
|
+
this.prev = prev;
|
|
1845
|
+
} else {
|
|
1846
|
+
this.prev = null;
|
|
1847
|
+
}
|
|
1862
1848
|
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1849
|
+
if (next) {
|
|
1850
|
+
next.prev = this;
|
|
1851
|
+
this.next = next;
|
|
1852
|
+
} else {
|
|
1853
|
+
this.next = null;
|
|
1854
|
+
}
|
|
1868
1855
|
}
|
|
1869
1856
|
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
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
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
this.reset();
|
|
1924
|
-
}
|
|
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
|
+
}
|
|
1925
1910
|
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
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')
|
|
1930
1915
|
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1916
|
+
this[MAX] = mL || Infinity;
|
|
1917
|
+
trim(this);
|
|
1918
|
+
}
|
|
1919
|
+
get max () {
|
|
1920
|
+
return this[MAX]
|
|
1921
|
+
}
|
|
1937
1922
|
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1923
|
+
set allowStale (allowStale) {
|
|
1924
|
+
this[ALLOW_STALE] = !!allowStale;
|
|
1925
|
+
}
|
|
1926
|
+
get allowStale () {
|
|
1927
|
+
return this[ALLOW_STALE]
|
|
1928
|
+
}
|
|
1944
1929
|
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1930
|
+
set maxAge (mA) {
|
|
1931
|
+
if (typeof mA !== 'number')
|
|
1932
|
+
throw new TypeError('maxAge must be a non-negative number')
|
|
1948
1933
|
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1934
|
+
this[MAX_AGE] = mA;
|
|
1935
|
+
trim(this);
|
|
1936
|
+
}
|
|
1937
|
+
get maxAge () {
|
|
1938
|
+
return this[MAX_AGE]
|
|
1939
|
+
}
|
|
1955
1940
|
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
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] }
|
|
1972
1957
|
|
|
1973
|
-
|
|
1974
|
-
|
|
1958
|
+
get length () { return this[LENGTH] }
|
|
1959
|
+
get itemCount () { return this[LRU_LIST].length }
|
|
1975
1960
|
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
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
|
+
}
|
|
1984
1969
|
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
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
|
+
}
|
|
1993
1978
|
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1979
|
+
keys () {
|
|
1980
|
+
return this[LRU_LIST].toArray().map(k => k.key)
|
|
1981
|
+
}
|
|
1997
1982
|
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
1983
|
+
values () {
|
|
1984
|
+
return this[LRU_LIST].toArray().map(k => k.value)
|
|
1985
|
+
}
|
|
2001
1986
|
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
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
|
+
}
|
|
2008
1993
|
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
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
|
+
}
|
|
2013
1998
|
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
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
|
+
}
|
|
2022
2007
|
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2008
|
+
dumpLru () {
|
|
2009
|
+
return this[LRU_LIST]
|
|
2010
|
+
}
|
|
2026
2011
|
|
|
2027
|
-
|
|
2028
|
-
|
|
2012
|
+
set (key, value, maxAge) {
|
|
2013
|
+
maxAge = maxAge || this[MAX_AGE];
|
|
2029
2014
|
|
|
2030
|
-
|
|
2031
|
-
|
|
2015
|
+
if (maxAge && typeof maxAge !== 'number')
|
|
2016
|
+
throw new TypeError('maxAge must be a number')
|
|
2032
2017
|
|
|
2033
|
-
|
|
2034
|
-
|
|
2018
|
+
const now = maxAge ? Date.now() : 0;
|
|
2019
|
+
const len = this[LENGTH_CALCULATOR](value, key);
|
|
2035
2020
|
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2021
|
+
if (this[CACHE].has(key)) {
|
|
2022
|
+
if (len > this[MAX]) {
|
|
2023
|
+
del(this, this[CACHE].get(key));
|
|
2024
|
+
return false
|
|
2025
|
+
}
|
|
2041
2026
|
|
|
2042
|
-
|
|
2043
|
-
|
|
2027
|
+
const node = this[CACHE].get(key);
|
|
2028
|
+
const item = node.value;
|
|
2044
2029
|
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
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
|
+
}
|
|
2051
2036
|
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
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
|
+
}
|
|
2061
2046
|
|
|
2062
|
-
|
|
2047
|
+
const hit = new Entry(key, value, len, now, maxAge);
|
|
2063
2048
|
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2049
|
+
// oversized objects fall out of cache automatically.
|
|
2050
|
+
if (hit.length > this[MAX]) {
|
|
2051
|
+
if (this[DISPOSE])
|
|
2052
|
+
this[DISPOSE](key, value);
|
|
2068
2053
|
|
|
2069
|
-
|
|
2070
|
-
|
|
2054
|
+
return false
|
|
2055
|
+
}
|
|
2071
2056
|
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
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
|
+
}
|
|
2078
2063
|
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
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
|
+
}
|
|
2084
2069
|
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2070
|
+
get (key) {
|
|
2071
|
+
return get(this, key, true)
|
|
2072
|
+
}
|
|
2088
2073
|
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2074
|
+
peek (key) {
|
|
2075
|
+
return get(this, key, false)
|
|
2076
|
+
}
|
|
2092
2077
|
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2078
|
+
pop () {
|
|
2079
|
+
const node = this[LRU_LIST].tail;
|
|
2080
|
+
if (!node)
|
|
2081
|
+
return null
|
|
2097
2082
|
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2083
|
+
del(this, node);
|
|
2084
|
+
return node.value
|
|
2085
|
+
}
|
|
2101
2086
|
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2087
|
+
del (key) {
|
|
2088
|
+
del(this, this[CACHE].get(key));
|
|
2089
|
+
}
|
|
2105
2090
|
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
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
|
+
}
|
|
2127
2112
|
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2113
|
+
prune () {
|
|
2114
|
+
this[CACHE].forEach((value, key) => get(this, key, false));
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2132
2117
|
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
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
|
+
};
|
|
2151
2136
|
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2137
|
+
const isStale = (self, hit) => {
|
|
2138
|
+
if (!hit || (!hit.maxAge && !self[MAX_AGE]))
|
|
2139
|
+
return false
|
|
2155
2140
|
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2141
|
+
const diff = Date.now() - hit.now;
|
|
2142
|
+
return hit.maxAge ? diff > hit.maxAge
|
|
2143
|
+
: self[MAX_AGE] && (diff > self[MAX_AGE])
|
|
2144
|
+
};
|
|
2160
2145
|
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
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
|
+
};
|
|
2174
2159
|
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2160
|
+
const del = (self, node) => {
|
|
2161
|
+
if (node) {
|
|
2162
|
+
const hit = node.value;
|
|
2163
|
+
if (self[DISPOSE])
|
|
2164
|
+
self[DISPOSE](hit.key, hit.value);
|
|
2180
2165
|
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2166
|
+
self[LENGTH] -= hit.length;
|
|
2167
|
+
self[CACHE].delete(hit.key);
|
|
2168
|
+
self[LRU_LIST].removeNode(node);
|
|
2169
|
+
}
|
|
2170
|
+
};
|
|
2186
2171
|
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
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
|
+
}
|
|
2196
2181
|
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
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
|
+
};
|
|
2207
2192
|
|
|
2208
|
-
|
|
2209
|
-
return lruCache;
|
|
2210
|
-
}
|
|
2193
|
+
var lruCache = LRUCache;
|
|
2211
2194
|
|
|
2212
2195
|
var range;
|
|
2213
2196
|
var hasRequiredRange;
|
|
@@ -2415,7 +2398,7 @@ function requireRange () {
|
|
|
2415
2398
|
|
|
2416
2399
|
range = Range;
|
|
2417
2400
|
|
|
2418
|
-
const LRU =
|
|
2401
|
+
const LRU = lruCache;
|
|
2419
2402
|
const cache = new LRU({ max: 1000 });
|
|
2420
2403
|
|
|
2421
2404
|
const parseOptions = parseOptions_1;
|
|
@@ -3925,6 +3908,7 @@ class Machine {
|
|
|
3925
3908
|
totalBlocks: 0
|
|
3926
3909
|
}
|
|
3927
3910
|
};
|
|
3911
|
+
this.wantList = [];
|
|
3928
3912
|
// @ts-ignore
|
|
3929
3913
|
return this.#init(blocks);
|
|
3930
3914
|
}
|
|
@@ -3978,10 +3962,20 @@ class Machine {
|
|
|
3978
3962
|
pubsub.publish(data.id, data.value || false);
|
|
3979
3963
|
break;
|
|
3980
3964
|
}
|
|
3965
|
+
case 'addToWantList': {
|
|
3966
|
+
this.wantList.push(data.hash);
|
|
3967
|
+
}
|
|
3981
3968
|
case 'ask': {
|
|
3982
3969
|
if (data.question === 'contract' || data.question === 'transaction') {
|
|
3983
|
-
|
|
3984
|
-
|
|
3970
|
+
try {
|
|
3971
|
+
const input = await peernet.get(data.input);
|
|
3972
|
+
this.worker.postMessage({ id: data.id, input });
|
|
3973
|
+
}
|
|
3974
|
+
catch (error) {
|
|
3975
|
+
console.error(error);
|
|
3976
|
+
this.worker.postMessage({ id: data.id, input: data.input });
|
|
3977
|
+
this.wantList.push(data.input);
|
|
3978
|
+
}
|
|
3985
3979
|
}
|
|
3986
3980
|
}
|
|
3987
3981
|
}
|
|
@@ -4342,6 +4336,12 @@ class State extends Contract {
|
|
|
4342
4336
|
#totalSize;
|
|
4343
4337
|
#machine;
|
|
4344
4338
|
#loaded;
|
|
4339
|
+
/**
|
|
4340
|
+
* contains transactions we need before we can successfully load
|
|
4341
|
+
*/
|
|
4342
|
+
get wantList() {
|
|
4343
|
+
return this.#machine.wantList;
|
|
4344
|
+
}
|
|
4345
4345
|
get state() {
|
|
4346
4346
|
return {
|
|
4347
4347
|
sync: this.#syncState,
|