@leofcoin/chain 1.5.44 → 1.5.45
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 +689 -664
- package/exports/browser/{index-2836cc96-40ed5df4.js → index-687f692b-bcdff490.js} +1 -1
- package/exports/browser/{messages-554d2a85-ce06f6eb.js → messages-1c117282-a35a5fbc.js} +1 -1
- package/exports/browser/{node-browser-77f8d4c5.js → node-browser-2c421007.js} +95 -68
- package/exports/browser/node-browser.js +1 -1
- package/exports/browser/workers/block-worker.js +4 -2
- package/exports/browser/workers/machine-worker.js +34 -14
- package/exports/chain.js +16 -8
- package/exports/workers/block-worker.js +4 -2
- package/exports/workers/machine-worker.js +34 -14
- package/package.json +1 -1
package/exports/browser/chain.js
CHANGED
|
@@ -1388,764 +1388,781 @@ function requireIterator () {
|
|
|
1388
1388
|
return iterator;
|
|
1389
1389
|
}
|
|
1390
1390
|
|
|
1391
|
-
var yallist
|
|
1391
|
+
var yallist;
|
|
1392
|
+
var hasRequiredYallist;
|
|
1392
1393
|
|
|
1393
|
-
|
|
1394
|
-
|
|
1394
|
+
function requireYallist () {
|
|
1395
|
+
if (hasRequiredYallist) return yallist;
|
|
1396
|
+
hasRequiredYallist = 1;
|
|
1397
|
+
yallist = Yallist;
|
|
1395
1398
|
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
if (!(self instanceof Yallist$1)) {
|
|
1399
|
-
self = new Yallist$1();
|
|
1400
|
-
}
|
|
1399
|
+
Yallist.Node = Node;
|
|
1400
|
+
Yallist.create = Yallist;
|
|
1401
1401
|
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1402
|
+
function Yallist (list) {
|
|
1403
|
+
var self = this;
|
|
1404
|
+
if (!(self instanceof Yallist)) {
|
|
1405
|
+
self = new Yallist();
|
|
1406
|
+
}
|
|
1405
1407
|
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
});
|
|
1410
|
-
} else if (arguments.length > 0) {
|
|
1411
|
-
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
1412
|
-
self.push(arguments[i]);
|
|
1413
|
-
}
|
|
1414
|
-
}
|
|
1408
|
+
self.tail = null;
|
|
1409
|
+
self.head = null;
|
|
1410
|
+
self.length = 0;
|
|
1415
1411
|
|
|
1416
|
-
|
|
1417
|
-
|
|
1412
|
+
if (list && typeof list.forEach === 'function') {
|
|
1413
|
+
list.forEach(function (item) {
|
|
1414
|
+
self.push(item);
|
|
1415
|
+
});
|
|
1416
|
+
} else if (arguments.length > 0) {
|
|
1417
|
+
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
1418
|
+
self.push(arguments[i]);
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1418
1421
|
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
throw new Error('removing node which does not belong to this list')
|
|
1422
|
-
}
|
|
1422
|
+
return self
|
|
1423
|
+
}
|
|
1423
1424
|
|
|
1424
|
-
|
|
1425
|
-
|
|
1425
|
+
Yallist.prototype.removeNode = function (node) {
|
|
1426
|
+
if (node.list !== this) {
|
|
1427
|
+
throw new Error('removing node which does not belong to this list')
|
|
1428
|
+
}
|
|
1426
1429
|
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
}
|
|
1430
|
+
var next = node.next;
|
|
1431
|
+
var prev = node.prev;
|
|
1430
1432
|
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1433
|
+
if (next) {
|
|
1434
|
+
next.prev = prev;
|
|
1435
|
+
}
|
|
1434
1436
|
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
if (node === this.tail) {
|
|
1439
|
-
this.tail = prev;
|
|
1440
|
-
}
|
|
1437
|
+
if (prev) {
|
|
1438
|
+
prev.next = next;
|
|
1439
|
+
}
|
|
1441
1440
|
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1441
|
+
if (node === this.head) {
|
|
1442
|
+
this.head = next;
|
|
1443
|
+
}
|
|
1444
|
+
if (node === this.tail) {
|
|
1445
|
+
this.tail = prev;
|
|
1446
|
+
}
|
|
1446
1447
|
|
|
1447
|
-
|
|
1448
|
-
|
|
1448
|
+
node.list.length--;
|
|
1449
|
+
node.next = null;
|
|
1450
|
+
node.prev = null;
|
|
1451
|
+
node.list = null;
|
|
1449
1452
|
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
return
|
|
1453
|
-
}
|
|
1453
|
+
return next
|
|
1454
|
+
};
|
|
1454
1455
|
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1456
|
+
Yallist.prototype.unshiftNode = function (node) {
|
|
1457
|
+
if (node === this.head) {
|
|
1458
|
+
return
|
|
1459
|
+
}
|
|
1458
1460
|
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
if (head) {
|
|
1463
|
-
head.prev = node;
|
|
1464
|
-
}
|
|
1461
|
+
if (node.list) {
|
|
1462
|
+
node.list.removeNode(node);
|
|
1463
|
+
}
|
|
1465
1464
|
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
}
|
|
1465
|
+
var head = this.head;
|
|
1466
|
+
node.list = this;
|
|
1467
|
+
node.next = head;
|
|
1468
|
+
if (head) {
|
|
1469
|
+
head.prev = node;
|
|
1470
|
+
}
|
|
1472
1471
|
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1472
|
+
this.head = node;
|
|
1473
|
+
if (!this.tail) {
|
|
1474
|
+
this.tail = node;
|
|
1475
|
+
}
|
|
1476
|
+
this.length++;
|
|
1477
|
+
};
|
|
1477
1478
|
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1479
|
+
Yallist.prototype.pushNode = function (node) {
|
|
1480
|
+
if (node === this.tail) {
|
|
1481
|
+
return
|
|
1482
|
+
}
|
|
1481
1483
|
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
if (tail) {
|
|
1486
|
-
tail.next = node;
|
|
1487
|
-
}
|
|
1484
|
+
if (node.list) {
|
|
1485
|
+
node.list.removeNode(node);
|
|
1486
|
+
}
|
|
1488
1487
|
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
}
|
|
1488
|
+
var tail = this.tail;
|
|
1489
|
+
node.list = this;
|
|
1490
|
+
node.prev = tail;
|
|
1491
|
+
if (tail) {
|
|
1492
|
+
tail.next = node;
|
|
1493
|
+
}
|
|
1495
1494
|
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
};
|
|
1495
|
+
this.tail = node;
|
|
1496
|
+
if (!this.head) {
|
|
1497
|
+
this.head = node;
|
|
1498
|
+
}
|
|
1499
|
+
this.length++;
|
|
1500
|
+
};
|
|
1502
1501
|
|
|
1503
|
-
Yallist
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
};
|
|
1502
|
+
Yallist.prototype.push = function () {
|
|
1503
|
+
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
1504
|
+
push(this, arguments[i]);
|
|
1505
|
+
}
|
|
1506
|
+
return this.length
|
|
1507
|
+
};
|
|
1509
1508
|
|
|
1510
|
-
Yallist
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1509
|
+
Yallist.prototype.unshift = function () {
|
|
1510
|
+
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
1511
|
+
unshift(this, arguments[i]);
|
|
1512
|
+
}
|
|
1513
|
+
return this.length
|
|
1514
|
+
};
|
|
1514
1515
|
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
} else {
|
|
1520
|
-
this.head = null;
|
|
1521
|
-
}
|
|
1522
|
-
this.length--;
|
|
1523
|
-
return res
|
|
1524
|
-
};
|
|
1516
|
+
Yallist.prototype.pop = function () {
|
|
1517
|
+
if (!this.tail) {
|
|
1518
|
+
return undefined
|
|
1519
|
+
}
|
|
1525
1520
|
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1521
|
+
var res = this.tail.value;
|
|
1522
|
+
this.tail = this.tail.prev;
|
|
1523
|
+
if (this.tail) {
|
|
1524
|
+
this.tail.next = null;
|
|
1525
|
+
} else {
|
|
1526
|
+
this.head = null;
|
|
1527
|
+
}
|
|
1528
|
+
this.length--;
|
|
1529
|
+
return res
|
|
1530
|
+
};
|
|
1530
1531
|
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
} else {
|
|
1536
|
-
this.tail = null;
|
|
1537
|
-
}
|
|
1538
|
-
this.length--;
|
|
1539
|
-
return res
|
|
1540
|
-
};
|
|
1532
|
+
Yallist.prototype.shift = function () {
|
|
1533
|
+
if (!this.head) {
|
|
1534
|
+
return undefined
|
|
1535
|
+
}
|
|
1541
1536
|
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
}
|
|
1537
|
+
var res = this.head.value;
|
|
1538
|
+
this.head = this.head.next;
|
|
1539
|
+
if (this.head) {
|
|
1540
|
+
this.head.prev = null;
|
|
1541
|
+
} else {
|
|
1542
|
+
this.tail = null;
|
|
1543
|
+
}
|
|
1544
|
+
this.length--;
|
|
1545
|
+
return res
|
|
1546
|
+
};
|
|
1549
1547
|
|
|
1550
|
-
Yallist
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
};
|
|
1548
|
+
Yallist.prototype.forEach = function (fn, thisp) {
|
|
1549
|
+
thisp = thisp || this;
|
|
1550
|
+
for (var walker = this.head, i = 0; walker !== null; i++) {
|
|
1551
|
+
fn.call(thisp, walker.value, i, this);
|
|
1552
|
+
walker = walker.next;
|
|
1553
|
+
}
|
|
1554
|
+
};
|
|
1557
1555
|
|
|
1558
|
-
Yallist
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
}
|
|
1566
|
-
};
|
|
1556
|
+
Yallist.prototype.forEachReverse = function (fn, thisp) {
|
|
1557
|
+
thisp = thisp || this;
|
|
1558
|
+
for (var walker = this.tail, i = this.length - 1; walker !== null; i--) {
|
|
1559
|
+
fn.call(thisp, walker.value, i, this);
|
|
1560
|
+
walker = walker.prev;
|
|
1561
|
+
}
|
|
1562
|
+
};
|
|
1567
1563
|
|
|
1568
|
-
Yallist
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
};
|
|
1564
|
+
Yallist.prototype.get = function (n) {
|
|
1565
|
+
for (var i = 0, walker = this.head; walker !== null && i < n; i++) {
|
|
1566
|
+
// abort out of the list early if we hit a cycle
|
|
1567
|
+
walker = walker.next;
|
|
1568
|
+
}
|
|
1569
|
+
if (i === n && walker !== null) {
|
|
1570
|
+
return walker.value
|
|
1571
|
+
}
|
|
1572
|
+
};
|
|
1577
1573
|
|
|
1578
|
-
Yallist
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
};
|
|
1574
|
+
Yallist.prototype.getReverse = function (n) {
|
|
1575
|
+
for (var i = 0, walker = this.tail; walker !== null && i < n; i++) {
|
|
1576
|
+
// abort out of the list early if we hit a cycle
|
|
1577
|
+
walker = walker.prev;
|
|
1578
|
+
}
|
|
1579
|
+
if (i === n && walker !== null) {
|
|
1580
|
+
return walker.value
|
|
1581
|
+
}
|
|
1582
|
+
};
|
|
1587
1583
|
|
|
1588
|
-
Yallist
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
};
|
|
1584
|
+
Yallist.prototype.map = function (fn, thisp) {
|
|
1585
|
+
thisp = thisp || this;
|
|
1586
|
+
var res = new Yallist();
|
|
1587
|
+
for (var walker = this.head; walker !== null;) {
|
|
1588
|
+
res.push(fn.call(thisp, walker.value, this));
|
|
1589
|
+
walker = walker.next;
|
|
1590
|
+
}
|
|
1591
|
+
return res
|
|
1592
|
+
};
|
|
1597
1593
|
|
|
1598
|
-
Yallist
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
throw new TypeError('Reduce of empty list with no initial value')
|
|
1608
|
-
}
|
|
1594
|
+
Yallist.prototype.mapReverse = function (fn, thisp) {
|
|
1595
|
+
thisp = thisp || this;
|
|
1596
|
+
var res = new Yallist();
|
|
1597
|
+
for (var walker = this.tail; walker !== null;) {
|
|
1598
|
+
res.push(fn.call(thisp, walker.value, this));
|
|
1599
|
+
walker = walker.prev;
|
|
1600
|
+
}
|
|
1601
|
+
return res
|
|
1602
|
+
};
|
|
1609
1603
|
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1604
|
+
Yallist.prototype.reduce = function (fn, initial) {
|
|
1605
|
+
var acc;
|
|
1606
|
+
var walker = this.head;
|
|
1607
|
+
if (arguments.length > 1) {
|
|
1608
|
+
acc = initial;
|
|
1609
|
+
} else if (this.head) {
|
|
1610
|
+
walker = this.head.next;
|
|
1611
|
+
acc = this.head.value;
|
|
1612
|
+
} else {
|
|
1613
|
+
throw new TypeError('Reduce of empty list with no initial value')
|
|
1614
|
+
}
|
|
1614
1615
|
|
|
1615
|
-
|
|
1616
|
-
|
|
1616
|
+
for (var i = 0; walker !== null; i++) {
|
|
1617
|
+
acc = fn(acc, walker.value, i);
|
|
1618
|
+
walker = walker.next;
|
|
1619
|
+
}
|
|
1617
1620
|
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
var walker = this.tail;
|
|
1621
|
-
if (arguments.length > 1) {
|
|
1622
|
-
acc = initial;
|
|
1623
|
-
} else if (this.tail) {
|
|
1624
|
-
walker = this.tail.prev;
|
|
1625
|
-
acc = this.tail.value;
|
|
1626
|
-
} else {
|
|
1627
|
-
throw new TypeError('Reduce of empty list with no initial value')
|
|
1628
|
-
}
|
|
1621
|
+
return acc
|
|
1622
|
+
};
|
|
1629
1623
|
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1624
|
+
Yallist.prototype.reduceReverse = function (fn, initial) {
|
|
1625
|
+
var acc;
|
|
1626
|
+
var walker = this.tail;
|
|
1627
|
+
if (arguments.length > 1) {
|
|
1628
|
+
acc = initial;
|
|
1629
|
+
} else if (this.tail) {
|
|
1630
|
+
walker = this.tail.prev;
|
|
1631
|
+
acc = this.tail.value;
|
|
1632
|
+
} else {
|
|
1633
|
+
throw new TypeError('Reduce of empty list with no initial value')
|
|
1634
|
+
}
|
|
1634
1635
|
|
|
1635
|
-
|
|
1636
|
-
|
|
1636
|
+
for (var i = this.length - 1; walker !== null; i--) {
|
|
1637
|
+
acc = fn(acc, walker.value, i);
|
|
1638
|
+
walker = walker.prev;
|
|
1639
|
+
}
|
|
1637
1640
|
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
for (var i = 0, walker = this.head; walker !== null; i++) {
|
|
1641
|
-
arr[i] = walker.value;
|
|
1642
|
-
walker = walker.next;
|
|
1643
|
-
}
|
|
1644
|
-
return arr
|
|
1645
|
-
};
|
|
1641
|
+
return acc
|
|
1642
|
+
};
|
|
1646
1643
|
|
|
1647
|
-
Yallist
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
};
|
|
1644
|
+
Yallist.prototype.toArray = function () {
|
|
1645
|
+
var arr = new Array(this.length);
|
|
1646
|
+
for (var i = 0, walker = this.head; walker !== null; i++) {
|
|
1647
|
+
arr[i] = walker.value;
|
|
1648
|
+
walker = walker.next;
|
|
1649
|
+
}
|
|
1650
|
+
return arr
|
|
1651
|
+
};
|
|
1655
1652
|
|
|
1656
|
-
Yallist
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
}
|
|
1665
|
-
var ret = new Yallist$1();
|
|
1666
|
-
if (to < from || to < 0) {
|
|
1667
|
-
return ret
|
|
1668
|
-
}
|
|
1669
|
-
if (from < 0) {
|
|
1670
|
-
from = 0;
|
|
1671
|
-
}
|
|
1672
|
-
if (to > this.length) {
|
|
1673
|
-
to = this.length;
|
|
1674
|
-
}
|
|
1675
|
-
for (var i = 0, walker = this.head; walker !== null && i < from; i++) {
|
|
1676
|
-
walker = walker.next;
|
|
1677
|
-
}
|
|
1678
|
-
for (; walker !== null && i < to; i++, walker = walker.next) {
|
|
1679
|
-
ret.push(walker.value);
|
|
1680
|
-
}
|
|
1681
|
-
return ret
|
|
1682
|
-
};
|
|
1653
|
+
Yallist.prototype.toArrayReverse = function () {
|
|
1654
|
+
var arr = new Array(this.length);
|
|
1655
|
+
for (var i = 0, walker = this.tail; walker !== null; i++) {
|
|
1656
|
+
arr[i] = walker.value;
|
|
1657
|
+
walker = walker.prev;
|
|
1658
|
+
}
|
|
1659
|
+
return arr
|
|
1660
|
+
};
|
|
1683
1661
|
|
|
1684
|
-
Yallist
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
};
|
|
1662
|
+
Yallist.prototype.slice = function (from, to) {
|
|
1663
|
+
to = to || this.length;
|
|
1664
|
+
if (to < 0) {
|
|
1665
|
+
to += this.length;
|
|
1666
|
+
}
|
|
1667
|
+
from = from || 0;
|
|
1668
|
+
if (from < 0) {
|
|
1669
|
+
from += this.length;
|
|
1670
|
+
}
|
|
1671
|
+
var ret = new Yallist();
|
|
1672
|
+
if (to < from || to < 0) {
|
|
1673
|
+
return ret
|
|
1674
|
+
}
|
|
1675
|
+
if (from < 0) {
|
|
1676
|
+
from = 0;
|
|
1677
|
+
}
|
|
1678
|
+
if (to > this.length) {
|
|
1679
|
+
to = this.length;
|
|
1680
|
+
}
|
|
1681
|
+
for (var i = 0, walker = this.head; walker !== null && i < from; i++) {
|
|
1682
|
+
walker = walker.next;
|
|
1683
|
+
}
|
|
1684
|
+
for (; walker !== null && i < to; i++, walker = walker.next) {
|
|
1685
|
+
ret.push(walker.value);
|
|
1686
|
+
}
|
|
1687
|
+
return ret
|
|
1688
|
+
};
|
|
1711
1689
|
|
|
1712
|
-
Yallist
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1690
|
+
Yallist.prototype.sliceReverse = function (from, to) {
|
|
1691
|
+
to = to || this.length;
|
|
1692
|
+
if (to < 0) {
|
|
1693
|
+
to += this.length;
|
|
1694
|
+
}
|
|
1695
|
+
from = from || 0;
|
|
1696
|
+
if (from < 0) {
|
|
1697
|
+
from += this.length;
|
|
1698
|
+
}
|
|
1699
|
+
var ret = new Yallist();
|
|
1700
|
+
if (to < from || to < 0) {
|
|
1701
|
+
return ret
|
|
1702
|
+
}
|
|
1703
|
+
if (from < 0) {
|
|
1704
|
+
from = 0;
|
|
1705
|
+
}
|
|
1706
|
+
if (to > this.length) {
|
|
1707
|
+
to = this.length;
|
|
1708
|
+
}
|
|
1709
|
+
for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) {
|
|
1710
|
+
walker = walker.prev;
|
|
1711
|
+
}
|
|
1712
|
+
for (; walker !== null && i > from; i--, walker = walker.prev) {
|
|
1713
|
+
ret.push(walker.value);
|
|
1714
|
+
}
|
|
1715
|
+
return ret
|
|
1716
|
+
};
|
|
1719
1717
|
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1718
|
+
Yallist.prototype.splice = function (start, deleteCount, ...nodes) {
|
|
1719
|
+
if (start > this.length) {
|
|
1720
|
+
start = this.length - 1;
|
|
1721
|
+
}
|
|
1722
|
+
if (start < 0) {
|
|
1723
|
+
start = this.length + start;
|
|
1724
|
+
}
|
|
1723
1725
|
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
walker = this.removeNode(walker);
|
|
1728
|
-
}
|
|
1729
|
-
if (walker === null) {
|
|
1730
|
-
walker = this.tail;
|
|
1731
|
-
}
|
|
1726
|
+
for (var i = 0, walker = this.head; walker !== null && i < start; i++) {
|
|
1727
|
+
walker = walker.next;
|
|
1728
|
+
}
|
|
1732
1729
|
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1730
|
+
var ret = [];
|
|
1731
|
+
for (var i = 0; walker && i < deleteCount; i++) {
|
|
1732
|
+
ret.push(walker.value);
|
|
1733
|
+
walker = this.removeNode(walker);
|
|
1734
|
+
}
|
|
1735
|
+
if (walker === null) {
|
|
1736
|
+
walker = this.tail;
|
|
1737
|
+
}
|
|
1736
1738
|
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
return ret;
|
|
1741
|
-
};
|
|
1739
|
+
if (walker !== this.head && walker !== this.tail) {
|
|
1740
|
+
walker = walker.prev;
|
|
1741
|
+
}
|
|
1742
1742
|
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
walker.prev = walker.next;
|
|
1749
|
-
walker.next = p;
|
|
1750
|
-
}
|
|
1751
|
-
this.head = tail;
|
|
1752
|
-
this.tail = head;
|
|
1753
|
-
return this
|
|
1754
|
-
};
|
|
1743
|
+
for (var i = 0; i < nodes.length; i++) {
|
|
1744
|
+
walker = insert(this, walker, nodes[i]);
|
|
1745
|
+
}
|
|
1746
|
+
return ret;
|
|
1747
|
+
};
|
|
1755
1748
|
|
|
1756
|
-
function
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1749
|
+
Yallist.prototype.reverse = function () {
|
|
1750
|
+
var head = this.head;
|
|
1751
|
+
var tail = this.tail;
|
|
1752
|
+
for (var walker = head; walker !== null; walker = walker.prev) {
|
|
1753
|
+
var p = walker.prev;
|
|
1754
|
+
walker.prev = walker.next;
|
|
1755
|
+
walker.next = p;
|
|
1756
|
+
}
|
|
1757
|
+
this.head = tail;
|
|
1758
|
+
this.tail = head;
|
|
1759
|
+
return this
|
|
1760
|
+
};
|
|
1760
1761
|
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
self.head = inserted;
|
|
1766
|
-
}
|
|
1762
|
+
function insert (self, node, value) {
|
|
1763
|
+
var inserted = node === self.head ?
|
|
1764
|
+
new Node(value, null, node, self) :
|
|
1765
|
+
new Node(value, node, node.next, self);
|
|
1767
1766
|
|
|
1768
|
-
|
|
1767
|
+
if (inserted.next === null) {
|
|
1768
|
+
self.tail = inserted;
|
|
1769
|
+
}
|
|
1770
|
+
if (inserted.prev === null) {
|
|
1771
|
+
self.head = inserted;
|
|
1772
|
+
}
|
|
1769
1773
|
|
|
1770
|
-
|
|
1771
|
-
}
|
|
1774
|
+
self.length++;
|
|
1772
1775
|
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
if (!self.head) {
|
|
1776
|
-
self.head = self.tail;
|
|
1777
|
-
}
|
|
1778
|
-
self.length++;
|
|
1779
|
-
}
|
|
1776
|
+
return inserted
|
|
1777
|
+
}
|
|
1780
1778
|
|
|
1781
|
-
function
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
}
|
|
1779
|
+
function push (self, item) {
|
|
1780
|
+
self.tail = new Node(item, self.tail, null, self);
|
|
1781
|
+
if (!self.head) {
|
|
1782
|
+
self.head = self.tail;
|
|
1783
|
+
}
|
|
1784
|
+
self.length++;
|
|
1785
|
+
}
|
|
1788
1786
|
|
|
1789
|
-
function
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1787
|
+
function unshift (self, item) {
|
|
1788
|
+
self.head = new Node(item, null, self.head, self);
|
|
1789
|
+
if (!self.tail) {
|
|
1790
|
+
self.tail = self.head;
|
|
1791
|
+
}
|
|
1792
|
+
self.length++;
|
|
1793
|
+
}
|
|
1793
1794
|
|
|
1794
|
-
|
|
1795
|
-
|
|
1795
|
+
function Node (value, prev, next, list) {
|
|
1796
|
+
if (!(this instanceof Node)) {
|
|
1797
|
+
return new Node(value, prev, next, list)
|
|
1798
|
+
}
|
|
1796
1799
|
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
this.prev = prev;
|
|
1800
|
-
} else {
|
|
1801
|
-
this.prev = null;
|
|
1802
|
-
}
|
|
1800
|
+
this.list = list;
|
|
1801
|
+
this.value = value;
|
|
1803
1802
|
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1803
|
+
if (prev) {
|
|
1804
|
+
prev.next = this;
|
|
1805
|
+
this.prev = prev;
|
|
1806
|
+
} else {
|
|
1807
|
+
this.prev = null;
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
if (next) {
|
|
1811
|
+
next.prev = this;
|
|
1812
|
+
this.next = next;
|
|
1813
|
+
} else {
|
|
1814
|
+
this.next = null;
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
|
|
1818
|
+
try {
|
|
1819
|
+
// add if support for Symbol.iterator is present
|
|
1820
|
+
requireIterator()(Yallist);
|
|
1821
|
+
} catch (er) {}
|
|
1822
|
+
return yallist;
|
|
1810
1823
|
}
|
|
1811
1824
|
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
const
|
|
1821
|
-
|
|
1822
|
-
const
|
|
1823
|
-
const
|
|
1824
|
-
const
|
|
1825
|
-
const
|
|
1826
|
-
const
|
|
1827
|
-
const
|
|
1828
|
-
const
|
|
1829
|
-
const
|
|
1830
|
-
|
|
1831
|
-
const
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
//
|
|
1836
|
-
//
|
|
1837
|
-
//
|
|
1838
|
-
//
|
|
1839
|
-
//
|
|
1840
|
-
//
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1825
|
+
var lruCache;
|
|
1826
|
+
var hasRequiredLruCache;
|
|
1827
|
+
|
|
1828
|
+
function requireLruCache () {
|
|
1829
|
+
if (hasRequiredLruCache) return lruCache;
|
|
1830
|
+
hasRequiredLruCache = 1;
|
|
1831
|
+
|
|
1832
|
+
// A linked list to keep track of recently-used-ness
|
|
1833
|
+
const Yallist = requireYallist();
|
|
1834
|
+
|
|
1835
|
+
const MAX = Symbol('max');
|
|
1836
|
+
const LENGTH = Symbol('length');
|
|
1837
|
+
const LENGTH_CALCULATOR = Symbol('lengthCalculator');
|
|
1838
|
+
const ALLOW_STALE = Symbol('allowStale');
|
|
1839
|
+
const MAX_AGE = Symbol('maxAge');
|
|
1840
|
+
const DISPOSE = Symbol('dispose');
|
|
1841
|
+
const NO_DISPOSE_ON_SET = Symbol('noDisposeOnSet');
|
|
1842
|
+
const LRU_LIST = Symbol('lruList');
|
|
1843
|
+
const CACHE = Symbol('cache');
|
|
1844
|
+
const UPDATE_AGE_ON_GET = Symbol('updateAgeOnGet');
|
|
1845
|
+
|
|
1846
|
+
const naiveLength = () => 1;
|
|
1847
|
+
|
|
1848
|
+
// lruList is a yallist where the head is the youngest
|
|
1849
|
+
// item, and the tail is the oldest. the list contains the Hit
|
|
1850
|
+
// objects as the entries.
|
|
1851
|
+
// Each Hit object has a reference to its Yallist.Node. This
|
|
1852
|
+
// never changes.
|
|
1853
|
+
//
|
|
1854
|
+
// cache is a Map (or PseudoMap) that matches the keys to
|
|
1855
|
+
// the Yallist.Node object.
|
|
1856
|
+
class LRUCache {
|
|
1857
|
+
constructor (options) {
|
|
1858
|
+
if (typeof options === 'number')
|
|
1859
|
+
options = { max: options };
|
|
1860
|
+
|
|
1861
|
+
if (!options)
|
|
1862
|
+
options = {};
|
|
1863
|
+
|
|
1864
|
+
if (options.max && (typeof options.max !== 'number' || options.max < 0))
|
|
1865
|
+
throw new TypeError('max must be a non-negative number')
|
|
1866
|
+
// Kind of weird to have a default max of Infinity, but oh well.
|
|
1867
|
+
this[MAX] = options.max || Infinity;
|
|
1868
|
+
|
|
1869
|
+
const lc = options.length || naiveLength;
|
|
1870
|
+
this[LENGTH_CALCULATOR] = (typeof lc !== 'function') ? naiveLength : lc;
|
|
1871
|
+
this[ALLOW_STALE] = options.stale || false;
|
|
1872
|
+
if (options.maxAge && typeof options.maxAge !== 'number')
|
|
1873
|
+
throw new TypeError('maxAge must be a number')
|
|
1874
|
+
this[MAX_AGE] = options.maxAge || 0;
|
|
1875
|
+
this[DISPOSE] = options.dispose;
|
|
1876
|
+
this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false;
|
|
1877
|
+
this[UPDATE_AGE_ON_GET] = options.updateAgeOnGet || false;
|
|
1878
|
+
this.reset();
|
|
1879
|
+
}
|
|
1865
1880
|
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1881
|
+
// resize the cache when the max changes.
|
|
1882
|
+
set max (mL) {
|
|
1883
|
+
if (typeof mL !== 'number' || mL < 0)
|
|
1884
|
+
throw new TypeError('max must be a non-negative number')
|
|
1870
1885
|
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1886
|
+
this[MAX] = mL || Infinity;
|
|
1887
|
+
trim(this);
|
|
1888
|
+
}
|
|
1889
|
+
get max () {
|
|
1890
|
+
return this[MAX]
|
|
1891
|
+
}
|
|
1877
1892
|
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1893
|
+
set allowStale (allowStale) {
|
|
1894
|
+
this[ALLOW_STALE] = !!allowStale;
|
|
1895
|
+
}
|
|
1896
|
+
get allowStale () {
|
|
1897
|
+
return this[ALLOW_STALE]
|
|
1898
|
+
}
|
|
1884
1899
|
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1900
|
+
set maxAge (mA) {
|
|
1901
|
+
if (typeof mA !== 'number')
|
|
1902
|
+
throw new TypeError('maxAge must be a non-negative number')
|
|
1888
1903
|
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1904
|
+
this[MAX_AGE] = mA;
|
|
1905
|
+
trim(this);
|
|
1906
|
+
}
|
|
1907
|
+
get maxAge () {
|
|
1908
|
+
return this[MAX_AGE]
|
|
1909
|
+
}
|
|
1895
1910
|
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1911
|
+
// resize the cache when the lengthCalculator changes.
|
|
1912
|
+
set lengthCalculator (lC) {
|
|
1913
|
+
if (typeof lC !== 'function')
|
|
1914
|
+
lC = naiveLength;
|
|
1915
|
+
|
|
1916
|
+
if (lC !== this[LENGTH_CALCULATOR]) {
|
|
1917
|
+
this[LENGTH_CALCULATOR] = lC;
|
|
1918
|
+
this[LENGTH] = 0;
|
|
1919
|
+
this[LRU_LIST].forEach(hit => {
|
|
1920
|
+
hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key);
|
|
1921
|
+
this[LENGTH] += hit.length;
|
|
1922
|
+
});
|
|
1923
|
+
}
|
|
1924
|
+
trim(this);
|
|
1925
|
+
}
|
|
1926
|
+
get lengthCalculator () { return this[LENGTH_CALCULATOR] }
|
|
1912
1927
|
|
|
1913
|
-
|
|
1914
|
-
|
|
1928
|
+
get length () { return this[LENGTH] }
|
|
1929
|
+
get itemCount () { return this[LRU_LIST].length }
|
|
1915
1930
|
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1931
|
+
rforEach (fn, thisp) {
|
|
1932
|
+
thisp = thisp || this;
|
|
1933
|
+
for (let walker = this[LRU_LIST].tail; walker !== null;) {
|
|
1934
|
+
const prev = walker.prev;
|
|
1935
|
+
forEachStep(this, fn, walker, thisp);
|
|
1936
|
+
walker = prev;
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1924
1939
|
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1940
|
+
forEach (fn, thisp) {
|
|
1941
|
+
thisp = thisp || this;
|
|
1942
|
+
for (let walker = this[LRU_LIST].head; walker !== null;) {
|
|
1943
|
+
const next = walker.next;
|
|
1944
|
+
forEachStep(this, fn, walker, thisp);
|
|
1945
|
+
walker = next;
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1933
1948
|
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1949
|
+
keys () {
|
|
1950
|
+
return this[LRU_LIST].toArray().map(k => k.key)
|
|
1951
|
+
}
|
|
1937
1952
|
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1953
|
+
values () {
|
|
1954
|
+
return this[LRU_LIST].toArray().map(k => k.value)
|
|
1955
|
+
}
|
|
1941
1956
|
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1957
|
+
reset () {
|
|
1958
|
+
if (this[DISPOSE] &&
|
|
1959
|
+
this[LRU_LIST] &&
|
|
1960
|
+
this[LRU_LIST].length) {
|
|
1961
|
+
this[LRU_LIST].forEach(hit => this[DISPOSE](hit.key, hit.value));
|
|
1962
|
+
}
|
|
1948
1963
|
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1964
|
+
this[CACHE] = new Map(); // hash of items by key
|
|
1965
|
+
this[LRU_LIST] = new Yallist(); // list of items in order of use recency
|
|
1966
|
+
this[LENGTH] = 0; // length of items in the list
|
|
1967
|
+
}
|
|
1953
1968
|
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1969
|
+
dump () {
|
|
1970
|
+
return this[LRU_LIST].map(hit =>
|
|
1971
|
+
isStale(this, hit) ? false : {
|
|
1972
|
+
k: hit.key,
|
|
1973
|
+
v: hit.value,
|
|
1974
|
+
e: hit.now + (hit.maxAge || 0)
|
|
1975
|
+
}).toArray().filter(h => h)
|
|
1976
|
+
}
|
|
1962
1977
|
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1978
|
+
dumpLru () {
|
|
1979
|
+
return this[LRU_LIST]
|
|
1980
|
+
}
|
|
1966
1981
|
|
|
1967
|
-
|
|
1968
|
-
|
|
1982
|
+
set (key, value, maxAge) {
|
|
1983
|
+
maxAge = maxAge || this[MAX_AGE];
|
|
1969
1984
|
|
|
1970
|
-
|
|
1971
|
-
|
|
1985
|
+
if (maxAge && typeof maxAge !== 'number')
|
|
1986
|
+
throw new TypeError('maxAge must be a number')
|
|
1972
1987
|
|
|
1973
|
-
|
|
1974
|
-
|
|
1988
|
+
const now = maxAge ? Date.now() : 0;
|
|
1989
|
+
const len = this[LENGTH_CALCULATOR](value, key);
|
|
1975
1990
|
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1991
|
+
if (this[CACHE].has(key)) {
|
|
1992
|
+
if (len > this[MAX]) {
|
|
1993
|
+
del(this, this[CACHE].get(key));
|
|
1994
|
+
return false
|
|
1995
|
+
}
|
|
1981
1996
|
|
|
1982
|
-
|
|
1983
|
-
|
|
1997
|
+
const node = this[CACHE].get(key);
|
|
1998
|
+
const item = node.value;
|
|
1984
1999
|
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
2000
|
+
// dispose of the old one before overwriting
|
|
2001
|
+
// split out into 2 ifs for better coverage tracking
|
|
2002
|
+
if (this[DISPOSE]) {
|
|
2003
|
+
if (!this[NO_DISPOSE_ON_SET])
|
|
2004
|
+
this[DISPOSE](key, item.value);
|
|
2005
|
+
}
|
|
1991
2006
|
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2007
|
+
item.now = now;
|
|
2008
|
+
item.maxAge = maxAge;
|
|
2009
|
+
item.value = value;
|
|
2010
|
+
this[LENGTH] += len - item.length;
|
|
2011
|
+
item.length = len;
|
|
2012
|
+
this.get(key);
|
|
2013
|
+
trim(this);
|
|
2014
|
+
return true
|
|
2015
|
+
}
|
|
2001
2016
|
|
|
2002
|
-
|
|
2017
|
+
const hit = new Entry(key, value, len, now, maxAge);
|
|
2003
2018
|
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2019
|
+
// oversized objects fall out of cache automatically.
|
|
2020
|
+
if (hit.length > this[MAX]) {
|
|
2021
|
+
if (this[DISPOSE])
|
|
2022
|
+
this[DISPOSE](key, value);
|
|
2008
2023
|
|
|
2009
|
-
|
|
2010
|
-
|
|
2024
|
+
return false
|
|
2025
|
+
}
|
|
2011
2026
|
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2027
|
+
this[LENGTH] += hit.length;
|
|
2028
|
+
this[LRU_LIST].unshift(hit);
|
|
2029
|
+
this[CACHE].set(key, this[LRU_LIST].head);
|
|
2030
|
+
trim(this);
|
|
2031
|
+
return true
|
|
2032
|
+
}
|
|
2018
2033
|
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2034
|
+
has (key) {
|
|
2035
|
+
if (!this[CACHE].has(key)) return false
|
|
2036
|
+
const hit = this[CACHE].get(key).value;
|
|
2037
|
+
return !isStale(this, hit)
|
|
2038
|
+
}
|
|
2024
2039
|
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2040
|
+
get (key) {
|
|
2041
|
+
return get(this, key, true)
|
|
2042
|
+
}
|
|
2028
2043
|
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2044
|
+
peek (key) {
|
|
2045
|
+
return get(this, key, false)
|
|
2046
|
+
}
|
|
2032
2047
|
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2048
|
+
pop () {
|
|
2049
|
+
const node = this[LRU_LIST].tail;
|
|
2050
|
+
if (!node)
|
|
2051
|
+
return null
|
|
2037
2052
|
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2053
|
+
del(this, node);
|
|
2054
|
+
return node.value
|
|
2055
|
+
}
|
|
2041
2056
|
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2057
|
+
del (key) {
|
|
2058
|
+
del(this, this[CACHE].get(key));
|
|
2059
|
+
}
|
|
2045
2060
|
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2061
|
+
load (arr) {
|
|
2062
|
+
// reset the cache
|
|
2063
|
+
this.reset();
|
|
2064
|
+
|
|
2065
|
+
const now = Date.now();
|
|
2066
|
+
// A previous serialized cache has the most recent items first
|
|
2067
|
+
for (let l = arr.length - 1; l >= 0; l--) {
|
|
2068
|
+
const hit = arr[l];
|
|
2069
|
+
const expiresAt = hit.e || 0;
|
|
2070
|
+
if (expiresAt === 0)
|
|
2071
|
+
// the item was created without expiration in a non aged cache
|
|
2072
|
+
this.set(hit.k, hit.v);
|
|
2073
|
+
else {
|
|
2074
|
+
const maxAge = expiresAt - now;
|
|
2075
|
+
// dont add already expired items
|
|
2076
|
+
if (maxAge > 0) {
|
|
2077
|
+
this.set(hit.k, hit.v, maxAge);
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2067
2082
|
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
}
|
|
2083
|
+
prune () {
|
|
2084
|
+
this[CACHE].forEach((value, key) => get(this, key, false));
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2072
2087
|
|
|
2073
|
-
const get = (self, key, doUse) => {
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
};
|
|
2088
|
+
const get = (self, key, doUse) => {
|
|
2089
|
+
const node = self[CACHE].get(key);
|
|
2090
|
+
if (node) {
|
|
2091
|
+
const hit = node.value;
|
|
2092
|
+
if (isStale(self, hit)) {
|
|
2093
|
+
del(self, node);
|
|
2094
|
+
if (!self[ALLOW_STALE])
|
|
2095
|
+
return undefined
|
|
2096
|
+
} else {
|
|
2097
|
+
if (doUse) {
|
|
2098
|
+
if (self[UPDATE_AGE_ON_GET])
|
|
2099
|
+
node.value.now = Date.now();
|
|
2100
|
+
self[LRU_LIST].unshiftNode(node);
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
return hit.value
|
|
2104
|
+
}
|
|
2105
|
+
};
|
|
2091
2106
|
|
|
2092
|
-
const isStale = (self, hit) => {
|
|
2093
|
-
|
|
2094
|
-
|
|
2107
|
+
const isStale = (self, hit) => {
|
|
2108
|
+
if (!hit || (!hit.maxAge && !self[MAX_AGE]))
|
|
2109
|
+
return false
|
|
2095
2110
|
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
};
|
|
2111
|
+
const diff = Date.now() - hit.now;
|
|
2112
|
+
return hit.maxAge ? diff > hit.maxAge
|
|
2113
|
+
: self[MAX_AGE] && (diff > self[MAX_AGE])
|
|
2114
|
+
};
|
|
2100
2115
|
|
|
2101
|
-
const trim = self => {
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
};
|
|
2116
|
+
const trim = self => {
|
|
2117
|
+
if (self[LENGTH] > self[MAX]) {
|
|
2118
|
+
for (let walker = self[LRU_LIST].tail;
|
|
2119
|
+
self[LENGTH] > self[MAX] && walker !== null;) {
|
|
2120
|
+
// We know that we're about to delete this one, and also
|
|
2121
|
+
// what the next least recently used key will be, so just
|
|
2122
|
+
// go ahead and set it now.
|
|
2123
|
+
const prev = walker.prev;
|
|
2124
|
+
del(self, walker);
|
|
2125
|
+
walker = prev;
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
};
|
|
2114
2129
|
|
|
2115
|
-
const del = (self, node) => {
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2130
|
+
const del = (self, node) => {
|
|
2131
|
+
if (node) {
|
|
2132
|
+
const hit = node.value;
|
|
2133
|
+
if (self[DISPOSE])
|
|
2134
|
+
self[DISPOSE](hit.key, hit.value);
|
|
2120
2135
|
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
};
|
|
2136
|
+
self[LENGTH] -= hit.length;
|
|
2137
|
+
self[CACHE].delete(hit.key);
|
|
2138
|
+
self[LRU_LIST].removeNode(node);
|
|
2139
|
+
}
|
|
2140
|
+
};
|
|
2126
2141
|
|
|
2127
|
-
class Entry {
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
}
|
|
2142
|
+
class Entry {
|
|
2143
|
+
constructor (key, value, length, now, maxAge) {
|
|
2144
|
+
this.key = key;
|
|
2145
|
+
this.value = value;
|
|
2146
|
+
this.length = length;
|
|
2147
|
+
this.now = now;
|
|
2148
|
+
this.maxAge = maxAge || 0;
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2136
2151
|
|
|
2137
|
-
const forEachStep = (self, fn, node, thisp) => {
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
};
|
|
2152
|
+
const forEachStep = (self, fn, node, thisp) => {
|
|
2153
|
+
let hit = node.value;
|
|
2154
|
+
if (isStale(self, hit)) {
|
|
2155
|
+
del(self, node);
|
|
2156
|
+
if (!self[ALLOW_STALE])
|
|
2157
|
+
hit = undefined;
|
|
2158
|
+
}
|
|
2159
|
+
if (hit)
|
|
2160
|
+
fn.call(thisp, hit.value, hit.key, self);
|
|
2161
|
+
};
|
|
2147
2162
|
|
|
2148
|
-
|
|
2163
|
+
lruCache = LRUCache;
|
|
2164
|
+
return lruCache;
|
|
2165
|
+
}
|
|
2149
2166
|
|
|
2150
2167
|
var range;
|
|
2151
2168
|
var hasRequiredRange;
|
|
@@ -2353,7 +2370,7 @@ function requireRange () {
|
|
|
2353
2370
|
|
|
2354
2371
|
range = Range;
|
|
2355
2372
|
|
|
2356
|
-
const LRU =
|
|
2373
|
+
const LRU = requireLruCache();
|
|
2357
2374
|
const cache = new LRU({ max: 1000 });
|
|
2358
2375
|
|
|
2359
2376
|
const parseOptions = parseOptions_1;
|
|
@@ -3671,7 +3688,8 @@ class Transaction extends Protocol {
|
|
|
3671
3688
|
await globalThis.transactionPoolStore.put(hash, message.encoded);
|
|
3672
3689
|
// debug(`Added ${hash} to the transaction pool`)
|
|
3673
3690
|
peernet.publish('add-transaction', message.encoded);
|
|
3674
|
-
|
|
3691
|
+
const fee = await calculateFee(message.decoded);
|
|
3692
|
+
return { hash, data, fee, wait, message };
|
|
3675
3693
|
}
|
|
3676
3694
|
catch (error) {
|
|
3677
3695
|
console.log('remo');
|
|
@@ -3876,8 +3894,11 @@ class Machine {
|
|
|
3876
3894
|
break;
|
|
3877
3895
|
}
|
|
3878
3896
|
case 'debug': {
|
|
3879
|
-
|
|
3880
|
-
|
|
3897
|
+
globalThis.debug(data.message);
|
|
3898
|
+
break;
|
|
3899
|
+
}
|
|
3900
|
+
case 'error': {
|
|
3901
|
+
console.error(data.message);
|
|
3881
3902
|
break;
|
|
3882
3903
|
}
|
|
3883
3904
|
case 'machine-ready': {
|
|
@@ -4298,7 +4319,7 @@ class State extends Contract {
|
|
|
4298
4319
|
try {
|
|
4299
4320
|
await this.resolveBlocks();
|
|
4300
4321
|
this.#machine = await new Machine(this.#blocks);
|
|
4301
|
-
await this.#loadBlocks(this.#blocks)
|
|
4322
|
+
// await this.#loadBlocks(this.#blocks)
|
|
4302
4323
|
}
|
|
4303
4324
|
catch (error) {
|
|
4304
4325
|
if (isResolveError(error)) {
|
|
@@ -4737,6 +4758,13 @@ class Chain extends VersionControl {
|
|
|
4737
4758
|
this.#participants = [];
|
|
4738
4759
|
this.#participating = false;
|
|
4739
4760
|
this.#jail = [];
|
|
4761
|
+
this.#addTransaction = async (message) => {
|
|
4762
|
+
const transaction = new TransactionMessage(message);
|
|
4763
|
+
const hash = await transaction.hash();
|
|
4764
|
+
if (await transactionPool.has(hash))
|
|
4765
|
+
await transactionPool.delete(hash);
|
|
4766
|
+
console.log(transaction);
|
|
4767
|
+
};
|
|
4740
4768
|
// @ts-ignore
|
|
4741
4769
|
return this.#init();
|
|
4742
4770
|
}
|
|
@@ -4840,9 +4868,7 @@ class Chain extends VersionControl {
|
|
|
4840
4868
|
}, validatorInfo.timeout);
|
|
4841
4869
|
this.#jail.push(validatorInfo.address);
|
|
4842
4870
|
}
|
|
4843
|
-
#addTransaction
|
|
4844
|
-
console.log({ message });
|
|
4845
|
-
}
|
|
4871
|
+
#addTransaction;
|
|
4846
4872
|
async #prepareRequest(request) {
|
|
4847
4873
|
let node = await new globalThis.peernet.protos['peernet-request']({ request });
|
|
4848
4874
|
return globalThis.peernet.prepareMessage(node);
|
|
@@ -4867,7 +4893,6 @@ class Chain extends VersionControl {
|
|
|
4867
4893
|
}
|
|
4868
4894
|
async #peerConnected(peerId) {
|
|
4869
4895
|
const peer = peernet.getConnection(peerId);
|
|
4870
|
-
console.log({ peer });
|
|
4871
4896
|
// todo handle version changes
|
|
4872
4897
|
// for now just do nothing if version doesn't match
|
|
4873
4898
|
console.log(`${peer.version}, ${this.version}`);
|