document-dataply 0.0.10-alpha.6 → 0.0.10-alpha.8
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/dist/cjs/index.js +989 -206
- package/dist/types/core/AnalysisManager.d.ts +12 -1
- package/dist/types/core/Optimizer.d.ts +3 -0
- package/dist/types/core/QueryManager.d.ts +9 -1
- package/dist/types/types/index.d.ts +10 -0
- package/dist/types/utils/DeadlineChunker.d.ts +34 -0
- package/package.json +2 -1
- package/readme.md +137 -269
package/dist/cjs/index.js
CHANGED
|
@@ -125,8 +125,8 @@ var require_cjs = __commonJS({
|
|
|
125
125
|
* @param b Value b.
|
|
126
126
|
* @returns Negative if a < b, 0 if equal, positive if a > b (based on primary field only).
|
|
127
127
|
*/
|
|
128
|
-
primaryAsc(a,
|
|
129
|
-
return this.asc(a,
|
|
128
|
+
primaryAsc(a, b2) {
|
|
129
|
+
return this.asc(a, b2);
|
|
130
130
|
}
|
|
131
131
|
isPrimarySame(value, than) {
|
|
132
132
|
return this.primaryAsc(value, than) === 0;
|
|
@@ -139,16 +139,16 @@ var require_cjs = __commonJS({
|
|
|
139
139
|
}
|
|
140
140
|
};
|
|
141
141
|
var NumericComparator = class extends ValueComparator2 {
|
|
142
|
-
asc(a,
|
|
143
|
-
return a -
|
|
142
|
+
asc(a, b2) {
|
|
143
|
+
return a - b2;
|
|
144
144
|
}
|
|
145
145
|
match(value) {
|
|
146
146
|
return value.toString();
|
|
147
147
|
}
|
|
148
148
|
};
|
|
149
149
|
var StringComparator = class extends ValueComparator2 {
|
|
150
|
-
asc(a,
|
|
151
|
-
return a.localeCompare(
|
|
150
|
+
asc(a, b2) {
|
|
151
|
+
return a.localeCompare(b2);
|
|
152
152
|
}
|
|
153
153
|
match(value) {
|
|
154
154
|
return value;
|
|
@@ -965,11 +965,11 @@ var require_cjs = __commonJS({
|
|
|
965
965
|
readQueue;
|
|
966
966
|
writeQueue;
|
|
967
967
|
static async CatchError(promise) {
|
|
968
|
-
return await promise.then((
|
|
968
|
+
return await promise.then((v2) => [void 0, v2]).catch((err) => [err]);
|
|
969
969
|
}
|
|
970
|
-
static IsRangeOverlap(a,
|
|
970
|
+
static IsRangeOverlap(a, b2) {
|
|
971
971
|
const [start1, end1] = a;
|
|
972
|
-
const [start2, end2] =
|
|
972
|
+
const [start2, end2] = b2;
|
|
973
973
|
if (end1 <= start2 || end2 <= start1) {
|
|
974
974
|
return false;
|
|
975
975
|
}
|
|
@@ -1005,10 +1005,10 @@ var require_cjs = __commonJS({
|
|
|
1005
1005
|
rangeOverlapping(tasks, range) {
|
|
1006
1006
|
return Array.from(tasks.values()).some((t) => _Ryoiki.IsRangeOverlap(t.range, range));
|
|
1007
1007
|
}
|
|
1008
|
-
isSameRange(a,
|
|
1008
|
+
isSameRange(a, b2) {
|
|
1009
1009
|
const [a1, a2] = a;
|
|
1010
|
-
const [b1,
|
|
1011
|
-
return a1 === b1 && a2 ===
|
|
1010
|
+
const [b1, b22] = b2;
|
|
1011
|
+
return a1 === b1 && a2 === b22;
|
|
1012
1012
|
}
|
|
1013
1013
|
fetchUnitAndRun(queue, workspaces) {
|
|
1014
1014
|
for (const [id, unit] of queue) {
|
|
@@ -1071,9 +1071,9 @@ var require_cjs = __commonJS({
|
|
|
1071
1071
|
if (timeoutId !== null) {
|
|
1072
1072
|
clearTimeout(timeoutId);
|
|
1073
1073
|
}
|
|
1074
|
-
const [err,
|
|
1074
|
+
const [err, v2] = await _Ryoiki.CatchError(task(id));
|
|
1075
1075
|
if (err) reject(err);
|
|
1076
|
-
else resolve(
|
|
1076
|
+
else resolve(v2);
|
|
1077
1077
|
};
|
|
1078
1078
|
const fetch = () => {
|
|
1079
1079
|
this.fetchUnitAndRun(this.readQueue, this.readings);
|
|
@@ -1640,23 +1640,23 @@ var require_cjs = __commonJS({
|
|
|
1640
1640
|
isInitialized = false;
|
|
1641
1641
|
isDestroyed = false;
|
|
1642
1642
|
verifierMap = {
|
|
1643
|
-
gt: (nv,
|
|
1644
|
-
gte: (nv,
|
|
1645
|
-
lt: (nv,
|
|
1646
|
-
lte: (nv,
|
|
1647
|
-
equal: (nv,
|
|
1648
|
-
notEqual: (nv,
|
|
1649
|
-
or: (nv,
|
|
1650
|
-
primaryGt: (nv,
|
|
1651
|
-
primaryGte: (nv,
|
|
1652
|
-
primaryLt: (nv,
|
|
1653
|
-
primaryLte: (nv,
|
|
1654
|
-
primaryEqual: (nv,
|
|
1655
|
-
primaryNotEqual: (nv,
|
|
1656
|
-
primaryOr: (nv,
|
|
1657
|
-
like: (nv,
|
|
1643
|
+
gt: (nv, v2) => this.comparator.isHigher(nv, v2),
|
|
1644
|
+
gte: (nv, v2) => this.comparator.isHigher(nv, v2) || this.comparator.isSame(nv, v2),
|
|
1645
|
+
lt: (nv, v2) => this.comparator.isLower(nv, v2),
|
|
1646
|
+
lte: (nv, v2) => this.comparator.isLower(nv, v2) || this.comparator.isSame(nv, v2),
|
|
1647
|
+
equal: (nv, v2) => this.comparator.isSame(nv, v2),
|
|
1648
|
+
notEqual: (nv, v2) => this.comparator.isSame(nv, v2) === false,
|
|
1649
|
+
or: (nv, v2) => this.ensureValues(v2).some((v22) => this.comparator.isSame(nv, v22)),
|
|
1650
|
+
primaryGt: (nv, v2) => this.comparator.isPrimaryHigher(nv, v2),
|
|
1651
|
+
primaryGte: (nv, v2) => this.comparator.isPrimaryHigher(nv, v2) || this.comparator.isPrimarySame(nv, v2),
|
|
1652
|
+
primaryLt: (nv, v2) => this.comparator.isPrimaryLower(nv, v2),
|
|
1653
|
+
primaryLte: (nv, v2) => this.comparator.isPrimaryLower(nv, v2) || this.comparator.isPrimarySame(nv, v2),
|
|
1654
|
+
primaryEqual: (nv, v2) => this.comparator.isPrimarySame(nv, v2),
|
|
1655
|
+
primaryNotEqual: (nv, v2) => this.comparator.isPrimarySame(nv, v2) === false,
|
|
1656
|
+
primaryOr: (nv, v2) => this.ensureValues(v2).some((v22) => this.comparator.isPrimarySame(nv, v22)),
|
|
1657
|
+
like: (nv, v2) => {
|
|
1658
1658
|
const nodeValue = this.comparator.match(nv);
|
|
1659
|
-
const value =
|
|
1659
|
+
const value = v2;
|
|
1660
1660
|
if (!this._cachedRegexp.has(value)) {
|
|
1661
1661
|
const pattern = value.replace(/%/g, ".*").replace(/_/g, ".");
|
|
1662
1662
|
const regexp2 = new RegExp(`^${pattern}$`, "i");
|
|
@@ -1669,28 +1669,28 @@ var require_cjs = __commonJS({
|
|
|
1669
1669
|
searchConfigs = {
|
|
1670
1670
|
gt: {
|
|
1671
1671
|
asc: {
|
|
1672
|
-
start: (tx,
|
|
1672
|
+
start: (tx, v2) => tx.findUpperBoundLeaf(v2[0]),
|
|
1673
1673
|
end: () => null,
|
|
1674
1674
|
direction: 1,
|
|
1675
1675
|
earlyTerminate: false
|
|
1676
1676
|
},
|
|
1677
1677
|
desc: {
|
|
1678
1678
|
start: (tx) => tx.rightestNode(),
|
|
1679
|
-
end: (tx,
|
|
1679
|
+
end: (tx, v2) => tx.findOuterBoundaryLeaf(v2[0], -1),
|
|
1680
1680
|
direction: -1,
|
|
1681
1681
|
earlyTerminate: true
|
|
1682
1682
|
}
|
|
1683
1683
|
},
|
|
1684
1684
|
gte: {
|
|
1685
1685
|
asc: {
|
|
1686
|
-
start: (tx,
|
|
1686
|
+
start: (tx, v2) => tx.findLowerBoundLeaf(v2[0]),
|
|
1687
1687
|
end: () => null,
|
|
1688
1688
|
direction: 1,
|
|
1689
1689
|
earlyTerminate: false
|
|
1690
1690
|
},
|
|
1691
1691
|
desc: {
|
|
1692
1692
|
start: (tx) => tx.rightestNode(),
|
|
1693
|
-
end: (tx,
|
|
1693
|
+
end: (tx, v2) => tx.findOuterBoundaryLeaf(v2[0], -1),
|
|
1694
1694
|
direction: -1,
|
|
1695
1695
|
earlyTerminate: true
|
|
1696
1696
|
}
|
|
@@ -1698,12 +1698,12 @@ var require_cjs = __commonJS({
|
|
|
1698
1698
|
lt: {
|
|
1699
1699
|
asc: {
|
|
1700
1700
|
start: (tx) => tx.leftestNode(),
|
|
1701
|
-
end: (tx,
|
|
1701
|
+
end: (tx, v2) => tx.findOuterBoundaryLeaf(v2[0], 1),
|
|
1702
1702
|
direction: 1,
|
|
1703
1703
|
earlyTerminate: true
|
|
1704
1704
|
},
|
|
1705
1705
|
desc: {
|
|
1706
|
-
start: (tx,
|
|
1706
|
+
start: (tx, v2) => tx.findLowerBoundLeaf(v2[0]),
|
|
1707
1707
|
end: () => null,
|
|
1708
1708
|
direction: -1,
|
|
1709
1709
|
earlyTerminate: false
|
|
@@ -1712,12 +1712,12 @@ var require_cjs = __commonJS({
|
|
|
1712
1712
|
lte: {
|
|
1713
1713
|
asc: {
|
|
1714
1714
|
start: (tx) => tx.leftestNode(),
|
|
1715
|
-
end: (tx,
|
|
1715
|
+
end: (tx, v2) => tx.findOuterBoundaryLeaf(v2[0], 1),
|
|
1716
1716
|
direction: 1,
|
|
1717
1717
|
earlyTerminate: true
|
|
1718
1718
|
},
|
|
1719
1719
|
desc: {
|
|
1720
|
-
start: (tx,
|
|
1720
|
+
start: (tx, v2) => tx.findUpperBoundLeaf(v2[0]),
|
|
1721
1721
|
end: () => null,
|
|
1722
1722
|
direction: -1,
|
|
1723
1723
|
earlyTerminate: false
|
|
@@ -1725,14 +1725,14 @@ var require_cjs = __commonJS({
|
|
|
1725
1725
|
},
|
|
1726
1726
|
equal: {
|
|
1727
1727
|
asc: {
|
|
1728
|
-
start: (tx,
|
|
1729
|
-
end: (tx,
|
|
1728
|
+
start: (tx, v2) => tx.findLowerBoundLeaf(v2[0]),
|
|
1729
|
+
end: (tx, v2) => tx.findOuterBoundaryLeaf(v2[0], 1),
|
|
1730
1730
|
direction: 1,
|
|
1731
1731
|
earlyTerminate: true
|
|
1732
1732
|
},
|
|
1733
1733
|
desc: {
|
|
1734
|
-
start: (tx,
|
|
1735
|
-
end: (tx,
|
|
1734
|
+
start: (tx, v2) => tx.findOuterBoundaryLeaf(v2[0], 1),
|
|
1735
|
+
end: (tx, v2) => tx.findOuterBoundaryLeaf(v2[0], -1),
|
|
1736
1736
|
direction: -1,
|
|
1737
1737
|
earlyTerminate: true
|
|
1738
1738
|
}
|
|
@@ -1753,42 +1753,42 @@ var require_cjs = __commonJS({
|
|
|
1753
1753
|
},
|
|
1754
1754
|
or: {
|
|
1755
1755
|
asc: {
|
|
1756
|
-
start: (tx,
|
|
1757
|
-
end: (tx,
|
|
1756
|
+
start: (tx, v2) => tx.findLowerBoundLeaf(tx.lowestValue(v2)),
|
|
1757
|
+
end: (tx, v2) => tx.findOuterBoundaryLeaf(tx.highestValue(v2), 1),
|
|
1758
1758
|
direction: 1,
|
|
1759
1759
|
earlyTerminate: false
|
|
1760
1760
|
},
|
|
1761
1761
|
desc: {
|
|
1762
|
-
start: (tx,
|
|
1763
|
-
end: (tx,
|
|
1762
|
+
start: (tx, v2) => tx.findOuterBoundaryLeaf(tx.highestValue(v2), 1),
|
|
1763
|
+
end: (tx, v2) => tx.findOuterBoundaryLeaf(tx.lowestValue(v2), -1),
|
|
1764
1764
|
direction: -1,
|
|
1765
1765
|
earlyTerminate: false
|
|
1766
1766
|
}
|
|
1767
1767
|
},
|
|
1768
1768
|
primaryGt: {
|
|
1769
1769
|
asc: {
|
|
1770
|
-
start: (tx,
|
|
1770
|
+
start: (tx, v2) => tx.findUpperBoundLeaf(v2[0]),
|
|
1771
1771
|
end: () => null,
|
|
1772
1772
|
direction: 1,
|
|
1773
1773
|
earlyTerminate: false
|
|
1774
1774
|
},
|
|
1775
1775
|
desc: {
|
|
1776
1776
|
start: (tx) => tx.rightestNode(),
|
|
1777
|
-
end: (tx,
|
|
1777
|
+
end: (tx, v2) => tx.findOuterBoundaryLeaf(v2[0], -1),
|
|
1778
1778
|
direction: -1,
|
|
1779
1779
|
earlyTerminate: true
|
|
1780
1780
|
}
|
|
1781
1781
|
},
|
|
1782
1782
|
primaryGte: {
|
|
1783
1783
|
asc: {
|
|
1784
|
-
start: (tx,
|
|
1784
|
+
start: (tx, v2) => tx.findLowerBoundLeaf(v2[0]),
|
|
1785
1785
|
end: () => null,
|
|
1786
1786
|
direction: 1,
|
|
1787
1787
|
earlyTerminate: false
|
|
1788
1788
|
},
|
|
1789
1789
|
desc: {
|
|
1790
1790
|
start: (tx) => tx.rightestNode(),
|
|
1791
|
-
end: (tx,
|
|
1791
|
+
end: (tx, v2) => tx.findOuterBoundaryLeaf(v2[0], -1),
|
|
1792
1792
|
direction: -1,
|
|
1793
1793
|
earlyTerminate: true
|
|
1794
1794
|
}
|
|
@@ -1796,12 +1796,12 @@ var require_cjs = __commonJS({
|
|
|
1796
1796
|
primaryLt: {
|
|
1797
1797
|
asc: {
|
|
1798
1798
|
start: (tx) => tx.leftestNode(),
|
|
1799
|
-
end: (tx,
|
|
1799
|
+
end: (tx, v2) => tx.findOuterBoundaryLeaf(v2[0], 1),
|
|
1800
1800
|
direction: 1,
|
|
1801
1801
|
earlyTerminate: true
|
|
1802
1802
|
},
|
|
1803
1803
|
desc: {
|
|
1804
|
-
start: (tx,
|
|
1804
|
+
start: (tx, v2) => tx.findLowerBoundLeaf(v2[0]),
|
|
1805
1805
|
end: () => null,
|
|
1806
1806
|
direction: -1,
|
|
1807
1807
|
earlyTerminate: false
|
|
@@ -1810,12 +1810,12 @@ var require_cjs = __commonJS({
|
|
|
1810
1810
|
primaryLte: {
|
|
1811
1811
|
asc: {
|
|
1812
1812
|
start: (tx) => tx.leftestNode(),
|
|
1813
|
-
end: (tx,
|
|
1813
|
+
end: (tx, v2) => tx.findOuterBoundaryLeaf(v2[0], 1),
|
|
1814
1814
|
direction: 1,
|
|
1815
1815
|
earlyTerminate: true
|
|
1816
1816
|
},
|
|
1817
1817
|
desc: {
|
|
1818
|
-
start: (tx,
|
|
1818
|
+
start: (tx, v2) => tx.findUpperBoundLeaf(v2[0]),
|
|
1819
1819
|
end: () => null,
|
|
1820
1820
|
direction: -1,
|
|
1821
1821
|
earlyTerminate: false
|
|
@@ -1823,14 +1823,14 @@ var require_cjs = __commonJS({
|
|
|
1823
1823
|
},
|
|
1824
1824
|
primaryEqual: {
|
|
1825
1825
|
asc: {
|
|
1826
|
-
start: (tx,
|
|
1827
|
-
end: (tx,
|
|
1826
|
+
start: (tx, v2) => tx.findLowerBoundLeaf(v2[0]),
|
|
1827
|
+
end: (tx, v2) => tx.findOuterBoundaryLeaf(v2[0], 1),
|
|
1828
1828
|
direction: 1,
|
|
1829
1829
|
earlyTerminate: true
|
|
1830
1830
|
},
|
|
1831
1831
|
desc: {
|
|
1832
|
-
start: (tx,
|
|
1833
|
-
end: (tx,
|
|
1832
|
+
start: (tx, v2) => tx.findUpperBoundLeaf(v2[0]),
|
|
1833
|
+
end: (tx, v2) => tx.findOuterBoundaryLeaf(v2[0], -1),
|
|
1834
1834
|
direction: -1,
|
|
1835
1835
|
earlyTerminate: true
|
|
1836
1836
|
}
|
|
@@ -1851,14 +1851,14 @@ var require_cjs = __commonJS({
|
|
|
1851
1851
|
},
|
|
1852
1852
|
primaryOr: {
|
|
1853
1853
|
asc: {
|
|
1854
|
-
start: (tx,
|
|
1855
|
-
end: (tx,
|
|
1854
|
+
start: (tx, v2) => tx.findLowerBoundLeaf(tx.lowestPrimaryValue(v2)),
|
|
1855
|
+
end: (tx, v2) => tx.findOuterBoundaryLeaf(tx.highestPrimaryValue(v2), 1),
|
|
1856
1856
|
direction: 1,
|
|
1857
1857
|
earlyTerminate: false
|
|
1858
1858
|
},
|
|
1859
1859
|
desc: {
|
|
1860
|
-
start: (tx,
|
|
1861
|
-
end: (tx,
|
|
1860
|
+
start: (tx, v2) => tx.findUpperBoundLeaf(tx.highestPrimaryValue(v2)),
|
|
1861
|
+
end: (tx, v2) => tx.findOuterBoundaryLeaf(tx.lowestPrimaryValue(v2), -1),
|
|
1862
1862
|
direction: -1,
|
|
1863
1863
|
earlyTerminate: false
|
|
1864
1864
|
}
|
|
@@ -2085,27 +2085,27 @@ var require_cjs = __commonJS({
|
|
|
2085
2085
|
this.comparator = comparator;
|
|
2086
2086
|
this.option = option ?? {};
|
|
2087
2087
|
}
|
|
2088
|
-
ensureValues(
|
|
2089
|
-
if (!Array.isArray(
|
|
2090
|
-
|
|
2088
|
+
ensureValues(v2) {
|
|
2089
|
+
if (!Array.isArray(v2)) {
|
|
2090
|
+
v2 = [v2];
|
|
2091
2091
|
}
|
|
2092
|
-
return
|
|
2092
|
+
return v2;
|
|
2093
2093
|
}
|
|
2094
|
-
lowestValue(
|
|
2094
|
+
lowestValue(v2) {
|
|
2095
2095
|
const i = 0;
|
|
2096
|
-
return [...
|
|
2096
|
+
return [...v2].sort((a, b2) => this.comparator.asc(a, b2))[i];
|
|
2097
2097
|
}
|
|
2098
|
-
highestValue(
|
|
2099
|
-
const i =
|
|
2100
|
-
return [...
|
|
2098
|
+
highestValue(v2) {
|
|
2099
|
+
const i = v2.length - 1;
|
|
2100
|
+
return [...v2].sort((a, b2) => this.comparator.asc(a, b2))[i];
|
|
2101
2101
|
}
|
|
2102
|
-
lowestPrimaryValue(
|
|
2102
|
+
lowestPrimaryValue(v2) {
|
|
2103
2103
|
const i = 0;
|
|
2104
|
-
return [...
|
|
2104
|
+
return [...v2].sort((a, b2) => this.comparator.primaryAsc(a, b2))[i];
|
|
2105
2105
|
}
|
|
2106
|
-
highestPrimaryValue(
|
|
2107
|
-
const i =
|
|
2108
|
-
return [...
|
|
2106
|
+
highestPrimaryValue(v2) {
|
|
2107
|
+
const i = v2.length - 1;
|
|
2108
|
+
return [...v2].sort((a, b2) => this.comparator.primaryAsc(a, b2))[i];
|
|
2109
2109
|
}
|
|
2110
2110
|
/**
|
|
2111
2111
|
* Returns the result entries of the transaction.
|
|
@@ -2299,13 +2299,13 @@ var require_cjs = __commonJS({
|
|
|
2299
2299
|
const midValue = parentNode.values[mid];
|
|
2300
2300
|
parentNode.values = parentNode.values.slice(0, mid);
|
|
2301
2301
|
parentNode.keys = parentNode.keys.slice(0, mid + 1);
|
|
2302
|
-
for (const
|
|
2303
|
-
const n = this._cloneNode(this.getNode(
|
|
2302
|
+
for (const k2 of parentNode.keys) {
|
|
2303
|
+
const n = this._cloneNode(this.getNode(k2));
|
|
2304
2304
|
n.parent = parentNode.id;
|
|
2305
2305
|
this._updateNode(n);
|
|
2306
2306
|
}
|
|
2307
|
-
for (const
|
|
2308
|
-
const n = this._cloneNode(this.getNode(
|
|
2307
|
+
for (const k2 of newSiblingNodeRecursive.keys) {
|
|
2308
|
+
const n = this._cloneNode(this.getNode(k2));
|
|
2309
2309
|
n.parent = newSiblingNodeRecursive.id;
|
|
2310
2310
|
this._updateNode(n);
|
|
2311
2311
|
}
|
|
@@ -2519,11 +2519,11 @@ var require_cjs = __commonJS({
|
|
|
2519
2519
|
let count = 0;
|
|
2520
2520
|
const intersection = filterValues && filterValues.size > 0 ? filterValues : null;
|
|
2521
2521
|
for (const pair of generator) {
|
|
2522
|
-
const [
|
|
2523
|
-
if (intersection && !intersection.has(
|
|
2522
|
+
const [k2, v2] = pair;
|
|
2523
|
+
if (intersection && !intersection.has(k2)) {
|
|
2524
2524
|
continue;
|
|
2525
2525
|
}
|
|
2526
|
-
if (this.verify(
|
|
2526
|
+
if (this.verify(v2, condition)) {
|
|
2527
2527
|
yield pair;
|
|
2528
2528
|
count++;
|
|
2529
2529
|
if (limit !== void 0 && count >= limit) {
|
|
@@ -2571,7 +2571,7 @@ var require_cjs = __commonJS({
|
|
|
2571
2571
|
}
|
|
2572
2572
|
batchInsert(entries) {
|
|
2573
2573
|
if (entries.length === 0) return;
|
|
2574
|
-
const sorted = [...entries].sort((a,
|
|
2574
|
+
const sorted = [...entries].sort((a, b2) => this.comparator.asc(a[1], b2[1]));
|
|
2575
2575
|
let currentLeaf = null;
|
|
2576
2576
|
let modified = false;
|
|
2577
2577
|
for (const [key, value] of sorted) {
|
|
@@ -2979,11 +2979,11 @@ var require_cjs = __commonJS({
|
|
|
2979
2979
|
readQueue;
|
|
2980
2980
|
writeQueue;
|
|
2981
2981
|
static async CatchError(promise) {
|
|
2982
|
-
return await promise.then((
|
|
2982
|
+
return await promise.then((v2) => [void 0, v2]).catch((err) => [err]);
|
|
2983
2983
|
}
|
|
2984
|
-
static IsRangeOverlap(a,
|
|
2984
|
+
static IsRangeOverlap(a, b2) {
|
|
2985
2985
|
const [start1, end1] = a;
|
|
2986
|
-
const [start2, end2] =
|
|
2986
|
+
const [start2, end2] = b2;
|
|
2987
2987
|
if (end1 <= start2 || end2 <= start1) {
|
|
2988
2988
|
return false;
|
|
2989
2989
|
}
|
|
@@ -3019,10 +3019,10 @@ var require_cjs = __commonJS({
|
|
|
3019
3019
|
rangeOverlapping(tasks, range) {
|
|
3020
3020
|
return Array.from(tasks.values()).some((t) => _Ryoiki2.IsRangeOverlap(t.range, range));
|
|
3021
3021
|
}
|
|
3022
|
-
isSameRange(a,
|
|
3022
|
+
isSameRange(a, b2) {
|
|
3023
3023
|
const [a1, a2] = a;
|
|
3024
|
-
const [b1,
|
|
3025
|
-
return a1 === b1 && a2 ===
|
|
3024
|
+
const [b1, b22] = b2;
|
|
3025
|
+
return a1 === b1 && a2 === b22;
|
|
3026
3026
|
}
|
|
3027
3027
|
fetchUnitAndRun(queue, workspaces) {
|
|
3028
3028
|
for (const [id, unit] of queue) {
|
|
@@ -3085,9 +3085,9 @@ var require_cjs = __commonJS({
|
|
|
3085
3085
|
if (timeoutId !== null) {
|
|
3086
3086
|
clearTimeout(timeoutId);
|
|
3087
3087
|
}
|
|
3088
|
-
const [err,
|
|
3088
|
+
const [err, v2] = await _Ryoiki2.CatchError(task(id));
|
|
3089
3089
|
if (err) reject(err);
|
|
3090
|
-
else resolve(
|
|
3090
|
+
else resolve(v2);
|
|
3091
3091
|
};
|
|
3092
3092
|
const fetch = () => {
|
|
3093
3093
|
this.fetchUnitAndRun(this.readQueue, this.readings);
|
|
@@ -3385,13 +3385,13 @@ var require_cjs = __commonJS({
|
|
|
3385
3385
|
const midValue = parentNode.values[mid];
|
|
3386
3386
|
parentNode.values = parentNode.values.slice(0, mid);
|
|
3387
3387
|
parentNode.keys = parentNode.keys.slice(0, mid + 1);
|
|
3388
|
-
for (const
|
|
3389
|
-
const n = this._cloneNode(await this.getNode(
|
|
3388
|
+
for (const k2 of parentNode.keys) {
|
|
3389
|
+
const n = this._cloneNode(await this.getNode(k2));
|
|
3390
3390
|
n.parent = parentNode.id;
|
|
3391
3391
|
await this._updateNode(n);
|
|
3392
3392
|
}
|
|
3393
|
-
for (const
|
|
3394
|
-
const n = this._cloneNode(await this.getNode(
|
|
3393
|
+
for (const k2 of newSiblingNodeRecursive.keys) {
|
|
3394
|
+
const n = this._cloneNode(await this.getNode(k2));
|
|
3395
3395
|
n.parent = newSiblingNodeRecursive.id;
|
|
3396
3396
|
await this._updateNode(n);
|
|
3397
3397
|
}
|
|
@@ -3614,11 +3614,11 @@ var require_cjs = __commonJS({
|
|
|
3614
3614
|
let count = 0;
|
|
3615
3615
|
const intersection = filterValues && filterValues.size > 0 ? filterValues : null;
|
|
3616
3616
|
for await (const pair of generator) {
|
|
3617
|
-
const [
|
|
3618
|
-
if (intersection && !intersection.has(
|
|
3617
|
+
const [k2, v2] = pair;
|
|
3618
|
+
if (intersection && !intersection.has(k2)) {
|
|
3619
3619
|
continue;
|
|
3620
3620
|
}
|
|
3621
|
-
if (this.verify(
|
|
3621
|
+
if (this.verify(v2, condition)) {
|
|
3622
3622
|
yield pair;
|
|
3623
3623
|
count++;
|
|
3624
3624
|
if (limit !== void 0 && count >= limit) {
|
|
@@ -3669,7 +3669,7 @@ var require_cjs = __commonJS({
|
|
|
3669
3669
|
async batchInsert(entries) {
|
|
3670
3670
|
if (entries.length === 0) return;
|
|
3671
3671
|
return this.writeLock(0, async () => {
|
|
3672
|
-
const sorted = [...entries].sort((a,
|
|
3672
|
+
const sorted = [...entries].sort((a, b2) => this.comparator.asc(a[1], b2[1]));
|
|
3673
3673
|
let currentLeaf = null;
|
|
3674
3674
|
let modified = false;
|
|
3675
3675
|
for (const [key, value] of sorted) {
|
|
@@ -4208,11 +4208,11 @@ var require_cjs = __commonJS({
|
|
|
4208
4208
|
readQueue;
|
|
4209
4209
|
writeQueue;
|
|
4210
4210
|
static async CatchError(promise) {
|
|
4211
|
-
return await promise.then((
|
|
4211
|
+
return await promise.then((v2) => [void 0, v2]).catch((err) => [err]);
|
|
4212
4212
|
}
|
|
4213
|
-
static IsRangeOverlap(a,
|
|
4213
|
+
static IsRangeOverlap(a, b2) {
|
|
4214
4214
|
const [start1, end1] = a;
|
|
4215
|
-
const [start2, end2] =
|
|
4215
|
+
const [start2, end2] = b2;
|
|
4216
4216
|
if (end1 <= start2 || end2 <= start1) {
|
|
4217
4217
|
return false;
|
|
4218
4218
|
}
|
|
@@ -4248,10 +4248,10 @@ var require_cjs = __commonJS({
|
|
|
4248
4248
|
rangeOverlapping(tasks, range) {
|
|
4249
4249
|
return Array.from(tasks.values()).some((t) => _Ryoiki3.IsRangeOverlap(t.range, range));
|
|
4250
4250
|
}
|
|
4251
|
-
isSameRange(a,
|
|
4251
|
+
isSameRange(a, b2) {
|
|
4252
4252
|
const [a1, a2] = a;
|
|
4253
|
-
const [b1,
|
|
4254
|
-
return a1 === b1 && a2 ===
|
|
4253
|
+
const [b1, b22] = b2;
|
|
4254
|
+
return a1 === b1 && a2 === b22;
|
|
4255
4255
|
}
|
|
4256
4256
|
fetchUnitAndRun(queue, workspaces) {
|
|
4257
4257
|
for (const [id, unit] of queue) {
|
|
@@ -4314,9 +4314,9 @@ var require_cjs = __commonJS({
|
|
|
4314
4314
|
if (timeoutId !== null) {
|
|
4315
4315
|
clearTimeout(timeoutId);
|
|
4316
4316
|
}
|
|
4317
|
-
const [err,
|
|
4317
|
+
const [err, v2] = await _Ryoiki3.CatchError(task(id));
|
|
4318
4318
|
if (err) reject(err);
|
|
4319
|
-
else resolve(
|
|
4319
|
+
else resolve(v2);
|
|
4320
4320
|
};
|
|
4321
4321
|
const fetch = () => {
|
|
4322
4322
|
this.fetchUnitAndRun(this.readQueue, this.readings);
|
|
@@ -5721,11 +5721,11 @@ var require_cjs = __commonJS({
|
|
|
5721
5721
|
readQueue;
|
|
5722
5722
|
writeQueue;
|
|
5723
5723
|
static async CatchError(promise) {
|
|
5724
|
-
return await promise.then((
|
|
5724
|
+
return await promise.then((v2) => [void 0, v2]).catch((err) => [err]);
|
|
5725
5725
|
}
|
|
5726
|
-
static IsRangeOverlap(a,
|
|
5726
|
+
static IsRangeOverlap(a, b2) {
|
|
5727
5727
|
const [start1, end1] = a;
|
|
5728
|
-
const [start2, end2] =
|
|
5728
|
+
const [start2, end2] = b2;
|
|
5729
5729
|
if (end1 <= start2 || end2 <= start1) {
|
|
5730
5730
|
return false;
|
|
5731
5731
|
}
|
|
@@ -5761,10 +5761,10 @@ var require_cjs = __commonJS({
|
|
|
5761
5761
|
rangeOverlapping(tasks, range) {
|
|
5762
5762
|
return Array.from(tasks.values()).some((t) => _Ryoiki4.IsRangeOverlap(t.range, range));
|
|
5763
5763
|
}
|
|
5764
|
-
isSameRange(a,
|
|
5764
|
+
isSameRange(a, b2) {
|
|
5765
5765
|
const [a1, a2] = a;
|
|
5766
|
-
const [b1,
|
|
5767
|
-
return a1 === b1 && a2 ===
|
|
5766
|
+
const [b1, b22] = b2;
|
|
5767
|
+
return a1 === b1 && a2 === b22;
|
|
5768
5768
|
}
|
|
5769
5769
|
fetchUnitAndRun(queue, workspaces) {
|
|
5770
5770
|
for (const [id, unit] of queue) {
|
|
@@ -5827,9 +5827,9 @@ var require_cjs = __commonJS({
|
|
|
5827
5827
|
if (timeoutId !== null) {
|
|
5828
5828
|
clearTimeout(timeoutId);
|
|
5829
5829
|
}
|
|
5830
|
-
const [err,
|
|
5830
|
+
const [err, v2] = await _Ryoiki4.CatchError(task(id));
|
|
5831
5831
|
if (err) reject(err);
|
|
5832
|
-
else resolve(
|
|
5832
|
+
else resolve(v2);
|
|
5833
5833
|
};
|
|
5834
5834
|
const fetch = () => {
|
|
5835
5835
|
this.fetchUnitAndRun(this.readQueue, this.readings);
|
|
@@ -6465,7 +6465,7 @@ var require_cjs = __commonJS({
|
|
|
6465
6465
|
(function makeTable() {
|
|
6466
6466
|
for (let i = 0; i < 256; i++) {
|
|
6467
6467
|
let c = i;
|
|
6468
|
-
for (let
|
|
6468
|
+
for (let k2 = 0; k2 < 8; k2++) {
|
|
6469
6469
|
c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
6470
6470
|
}
|
|
6471
6471
|
CRC_TABLE[i] = c;
|
|
@@ -8149,7 +8149,7 @@ var require_cjs = __commonJS({
|
|
|
8149
8149
|
if (this.fd === null) {
|
|
8150
8150
|
this.open();
|
|
8151
8151
|
}
|
|
8152
|
-
const sortedPageIds = Array.from(pages.keys()).sort((a,
|
|
8152
|
+
const sortedPageIds = Array.from(pages.keys()).sort((a, b2) => a - b2);
|
|
8153
8153
|
for (const pageId of sortedPageIds) {
|
|
8154
8154
|
const data = pages.get(pageId);
|
|
8155
8155
|
this.view.setUint32(0, pageId, true);
|
|
@@ -8330,7 +8330,7 @@ var require_cjs = __commonJS({
|
|
|
8330
8330
|
return;
|
|
8331
8331
|
}
|
|
8332
8332
|
const snapshot = new Map(this.dirtyPages);
|
|
8333
|
-
const sortedPageIds = Array.from(snapshot.keys()).sort((a,
|
|
8333
|
+
const sortedPageIds = Array.from(snapshot.keys()).sort((a, b2) => a - b2);
|
|
8334
8334
|
for (const pageId of sortedPageIds) {
|
|
8335
8335
|
const data = snapshot.get(pageId);
|
|
8336
8336
|
const position = pageId * this.pageSize;
|
|
@@ -8347,7 +8347,7 @@ var require_cjs = __commonJS({
|
|
|
8347
8347
|
if (pages.size === 0) {
|
|
8348
8348
|
return;
|
|
8349
8349
|
}
|
|
8350
|
-
const sortedPageIds = Array.from(pages.keys()).sort((a,
|
|
8350
|
+
const sortedPageIds = Array.from(pages.keys()).sort((a, b2) => a - b2);
|
|
8351
8351
|
for (const pageId of sortedPageIds) {
|
|
8352
8352
|
const data = pages.get(pageId);
|
|
8353
8353
|
const position = pageId * this.pageSize;
|
|
@@ -9494,7 +9494,7 @@ var require_cjs = __commonJS({
|
|
|
9494
9494
|
async fetchRowsByRids(collections, itemsCount, tx) {
|
|
9495
9495
|
const result = new Array(itemsCount).fill(null);
|
|
9496
9496
|
if (itemsCount === 0) return result;
|
|
9497
|
-
const sortedPageIds = Array.from(collections.keys()).sort((a,
|
|
9497
|
+
const sortedPageIds = Array.from(collections.keys()).sort((a, b2) => a - b2);
|
|
9498
9498
|
await Promise.all(sortedPageIds.map(async (pageId) => {
|
|
9499
9499
|
const items = collections.get(pageId);
|
|
9500
9500
|
const page = await this.pfs.get(pageId, tx);
|
|
@@ -10394,12 +10394,12 @@ var import_dataply4 = __toESM(require_cjs());
|
|
|
10394
10394
|
// src/core/bptree/documentComparator.ts
|
|
10395
10395
|
var import_dataply = __toESM(require_cjs());
|
|
10396
10396
|
var DocumentValueComparator = class extends import_dataply.ValueComparator {
|
|
10397
|
-
primaryAsc(a,
|
|
10398
|
-
return this._compareValue(a.v,
|
|
10397
|
+
primaryAsc(a, b2) {
|
|
10398
|
+
return this._compareValue(a.v, b2.v);
|
|
10399
10399
|
}
|
|
10400
|
-
asc(a,
|
|
10401
|
-
const diff = this._compareValue(a.v,
|
|
10402
|
-
return diff === 0 ? a.k -
|
|
10400
|
+
asc(a, b2) {
|
|
10401
|
+
const diff = this._compareValue(a.v, b2.v);
|
|
10402
|
+
return diff === 0 ? a.k - b2.k : diff;
|
|
10403
10403
|
}
|
|
10404
10404
|
match(value) {
|
|
10405
10405
|
return value.v + "";
|
|
@@ -10407,24 +10407,24 @@ var DocumentValueComparator = class extends import_dataply.ValueComparator {
|
|
|
10407
10407
|
/**
|
|
10408
10408
|
* 두 Primitive 값을 비교합니다.
|
|
10409
10409
|
*/
|
|
10410
|
-
_compareDiff(a,
|
|
10411
|
-
if (typeof a === "string" && typeof
|
|
10412
|
-
return a.localeCompare(
|
|
10410
|
+
_compareDiff(a, b2) {
|
|
10411
|
+
if (typeof a === "string" && typeof b2 === "string") {
|
|
10412
|
+
return a.localeCompare(b2);
|
|
10413
10413
|
}
|
|
10414
|
-
return +a - +
|
|
10414
|
+
return +a - +b2;
|
|
10415
10415
|
}
|
|
10416
10416
|
/**
|
|
10417
10417
|
* 두 v 값을 비교합니다. v는 Primitive 또는 Primitive[] (복합 인덱스)일 수 있습니다.
|
|
10418
10418
|
* 배열인 경우 element-by-element로 비교합니다.
|
|
10419
10419
|
*/
|
|
10420
|
-
_compareValue(a,
|
|
10420
|
+
_compareValue(a, b2) {
|
|
10421
10421
|
const aArr = Array.isArray(a);
|
|
10422
|
-
const bArr = Array.isArray(
|
|
10422
|
+
const bArr = Array.isArray(b2);
|
|
10423
10423
|
if (!aArr && !bArr) {
|
|
10424
|
-
return this._compareDiff(a,
|
|
10424
|
+
return this._compareDiff(a, b2);
|
|
10425
10425
|
}
|
|
10426
10426
|
const aList = aArr ? a : [a];
|
|
10427
|
-
const bList = bArr ?
|
|
10427
|
+
const bList = bArr ? b2 : [b2];
|
|
10428
10428
|
const len = Math.min(aList.length, bList.length);
|
|
10429
10429
|
for (let i = 0; i < len; i++) {
|
|
10430
10430
|
const diff = this._compareDiff(aList[i], bList[i]);
|
|
@@ -10482,7 +10482,7 @@ var SELECTIVITY = {
|
|
|
10482
10482
|
/** FTS 통계 없을 때 보수적 추정 */
|
|
10483
10483
|
FTS_DEFAULT: 0.5,
|
|
10484
10484
|
/** 정렬 비용 가중치 (orderBy 미지원 시) */
|
|
10485
|
-
SORT_PENALTY: 0.
|
|
10485
|
+
SORT_PENALTY: 0.5,
|
|
10486
10486
|
/** 인메모리 정렬이 유의미해지는 임계 문서 수 */
|
|
10487
10487
|
SORT_THRESHOLD: 1e4
|
|
10488
10488
|
};
|
|
@@ -10668,9 +10668,12 @@ var Optimizer = class {
|
|
|
10668
10668
|
* 비용 계산: effectiveScanCost + sortPenalty
|
|
10669
10669
|
* - effectiveScanCost: 인덱스 순서 지원 + limit 존재 시 조기 종료 이점 반영
|
|
10670
10670
|
* - sortPenalty: 인메모리 정렬의 절대 문서 수 기반 비용
|
|
10671
|
+
* - hasUncoveredFilters: 드라이버가 커버하지 못하는 비-FTS 필터 존재 여부
|
|
10672
|
+
* true일 경우 topK/N 조기 종료를 적용하지 않음
|
|
10673
|
+
* (uncovered 필터가 행을 탈락시킬 수 있어 topK개 이상 스캔 필요)
|
|
10671
10674
|
*/
|
|
10672
|
-
calculateCost(selectivity, isIndexOrderSupported, orderByField, N, topK) {
|
|
10673
|
-
const effectiveScanCost = isIndexOrderSupported && isFinite(topK) && N > 0 ? Math.min(topK / N, selectivity) : selectivity;
|
|
10675
|
+
calculateCost(selectivity, isIndexOrderSupported, orderByField, N, topK, hasUncoveredFilters = false) {
|
|
10676
|
+
const effectiveScanCost = isIndexOrderSupported && isFinite(topK) && N > 0 && !hasUncoveredFilters ? Math.min(topK / N, selectivity) : selectivity;
|
|
10674
10677
|
const estimatedSortDocs = selectivity * N;
|
|
10675
10678
|
const sortPenalty = orderByField && !isIndexOrderSupported ? Math.min(estimatedSortDocs / SELECTIVITY.SORT_THRESHOLD, 1) * SELECTIVITY.SORT_PENALTY : 0;
|
|
10676
10679
|
return effectiveScanCost + sortPenalty;
|
|
@@ -10699,9 +10702,19 @@ var Optimizer = class {
|
|
|
10699
10702
|
orderByField
|
|
10700
10703
|
);
|
|
10701
10704
|
if (candidate) {
|
|
10705
|
+
const hasUncoveredFilters = ![...queryFields].every(
|
|
10706
|
+
(f2) => candidate.coveredFields.includes(f2)
|
|
10707
|
+
);
|
|
10702
10708
|
candidates.push({
|
|
10703
10709
|
...candidate,
|
|
10704
|
-
cost: this.calculateCost(
|
|
10710
|
+
cost: this.calculateCost(
|
|
10711
|
+
candidate.selectivity,
|
|
10712
|
+
candidate.isIndexOrderSupported,
|
|
10713
|
+
orderByField,
|
|
10714
|
+
N,
|
|
10715
|
+
topK,
|
|
10716
|
+
hasUncoveredFilters
|
|
10717
|
+
)
|
|
10705
10718
|
});
|
|
10706
10719
|
}
|
|
10707
10720
|
} else if (config.type === "fts") {
|
|
@@ -10716,7 +10729,14 @@ var Optimizer = class {
|
|
|
10716
10729
|
if (candidate) {
|
|
10717
10730
|
candidates.push({
|
|
10718
10731
|
...candidate,
|
|
10719
|
-
cost: this.calculateCost(
|
|
10732
|
+
cost: this.calculateCost(
|
|
10733
|
+
candidate.selectivity,
|
|
10734
|
+
candidate.isIndexOrderSupported,
|
|
10735
|
+
orderByField,
|
|
10736
|
+
N,
|
|
10737
|
+
topK,
|
|
10738
|
+
true
|
|
10739
|
+
)
|
|
10720
10740
|
});
|
|
10721
10741
|
}
|
|
10722
10742
|
}
|
|
@@ -10730,10 +10750,10 @@ var Optimizer = class {
|
|
|
10730
10750
|
rollback();
|
|
10731
10751
|
return null;
|
|
10732
10752
|
}
|
|
10733
|
-
candidates.sort((a,
|
|
10734
|
-
if (a.cost !==
|
|
10753
|
+
candidates.sort((a, b2) => {
|
|
10754
|
+
if (a.cost !== b2.cost) return a.cost - b2.cost;
|
|
10735
10755
|
const aConfig = this.api.indexManager.registeredIndices.get(a.indexName);
|
|
10736
|
-
const bConfig = this.api.indexManager.registeredIndices.get(
|
|
10756
|
+
const bConfig = this.api.indexManager.registeredIndices.get(b2.indexName);
|
|
10737
10757
|
const aFieldCount = aConfig ? Array.isArray(aConfig.fields) ? aConfig.fields.length : 1 : 0;
|
|
10738
10758
|
const bFieldCount = bConfig ? Array.isArray(bConfig.fields) ? bConfig.fields.length : 1 : 0;
|
|
10739
10759
|
return aFieldCount - bFieldCount;
|
|
@@ -10747,7 +10767,7 @@ var Optimizer = class {
|
|
|
10747
10767
|
let isSubset = false;
|
|
10748
10768
|
for (let j = 0, oLen = others.length; j < oLen; j++) {
|
|
10749
10769
|
const better = others[j];
|
|
10750
|
-
if (candidate.coveredFields.every((
|
|
10770
|
+
if (candidate.coveredFields.every((f2) => better.coveredFields.includes(f2))) {
|
|
10751
10771
|
isSubset = true;
|
|
10752
10772
|
break;
|
|
10753
10773
|
}
|
|
@@ -10869,19 +10889,19 @@ var QueryManager = class {
|
|
|
10869
10889
|
for (const operator in conditions) {
|
|
10870
10890
|
const before = operator;
|
|
10871
10891
|
const after = this.operatorConverters[before];
|
|
10872
|
-
const
|
|
10892
|
+
const v2 = conditions[before];
|
|
10873
10893
|
if (!after) {
|
|
10874
10894
|
if (before === "match") {
|
|
10875
|
-
newConditions[before] =
|
|
10895
|
+
newConditions[before] = v2;
|
|
10876
10896
|
}
|
|
10877
10897
|
continue;
|
|
10878
10898
|
}
|
|
10879
|
-
if (before === "or" && Array.isArray(
|
|
10880
|
-
newConditions[after] =
|
|
10899
|
+
if (before === "or" && Array.isArray(v2)) {
|
|
10900
|
+
newConditions[after] = v2.map((val) => ({ v: val }));
|
|
10881
10901
|
} else if (before === "like") {
|
|
10882
|
-
newConditions[after] =
|
|
10902
|
+
newConditions[after] = v2;
|
|
10883
10903
|
} else {
|
|
10884
|
-
newConditions[after] = { v };
|
|
10904
|
+
newConditions[after] = { v: v2 };
|
|
10885
10905
|
}
|
|
10886
10906
|
}
|
|
10887
10907
|
}
|
|
@@ -11035,12 +11055,24 @@ var QueryManager = class {
|
|
|
11035
11055
|
}
|
|
11036
11056
|
return true;
|
|
11037
11057
|
}
|
|
11038
|
-
|
|
11039
|
-
|
|
11040
|
-
|
|
11041
|
-
|
|
11042
|
-
|
|
11043
|
-
|
|
11058
|
+
/**
|
|
11059
|
+
* 최적화 공식: x = x * Math.sqrt(z / n)
|
|
11060
|
+
* @param currentChunkSize 현재 청크 크기
|
|
11061
|
+
* @param matchedCount 매칭된 문서 개수
|
|
11062
|
+
* @param limit 최대 문서 개수
|
|
11063
|
+
* @param chunkTotalSize 청크 내 문서 총 크기
|
|
11064
|
+
* @returns
|
|
11065
|
+
*/
|
|
11066
|
+
adjustChunkSize(currentChunkSize, matchedCount, limit, chunkTotalSize) {
|
|
11067
|
+
if (matchedCount <= 0 || chunkTotalSize <= 0) return currentChunkSize;
|
|
11068
|
+
const n = Math.max(matchedCount, 1);
|
|
11069
|
+
const z = isFinite(limit) ? limit : currentChunkSize * 10;
|
|
11070
|
+
const nextChunkSize = Math.ceil(currentChunkSize * Math.sqrt(z / n));
|
|
11071
|
+
const { smallChunkSize } = this.getFreeMemoryChunkSize();
|
|
11072
|
+
const avgDocSize = chunkTotalSize / currentChunkSize;
|
|
11073
|
+
const maxSafeChunkSize = Math.max(Math.floor(smallChunkSize / avgDocSize), 20);
|
|
11074
|
+
const finalChunkSize = Math.max(Math.min(nextChunkSize, maxSafeChunkSize), 20);
|
|
11075
|
+
return finalChunkSize;
|
|
11044
11076
|
}
|
|
11045
11077
|
async *processChunkedKeysWithVerify(keysStream, startIdx, initialChunkSize, limit, ftsConditions, compositeVerifyConditions, others, tx) {
|
|
11046
11078
|
const verifyOthers = others.filter((o) => !o.isFtsMatch);
|
|
@@ -11056,34 +11088,35 @@ var QueryManager = class {
|
|
|
11056
11088
|
let chunk = [];
|
|
11057
11089
|
let chunkSize = 0;
|
|
11058
11090
|
let dropped = 0;
|
|
11091
|
+
let nAccumulated = 0;
|
|
11059
11092
|
const processChunk = async (pks) => {
|
|
11060
11093
|
const docs = [];
|
|
11061
11094
|
const rawResults = await this.api.selectMany(new Float64Array(pks), false, tx);
|
|
11062
11095
|
let chunkTotalSize = 0;
|
|
11063
11096
|
for (let j = 0, len = rawResults.length; j < len; j++) {
|
|
11064
|
-
const
|
|
11065
|
-
if (!
|
|
11066
|
-
const doc = JSON.parse(
|
|
11067
|
-
chunkTotalSize +=
|
|
11097
|
+
const s2 = rawResults[j];
|
|
11098
|
+
if (!s2) continue;
|
|
11099
|
+
const doc = JSON.parse(s2);
|
|
11100
|
+
chunkTotalSize += s2.length * 2;
|
|
11068
11101
|
if (isFts && !this.verifyFts(doc, ftsConditions)) continue;
|
|
11069
11102
|
if (isCompositeVerify && this.verifyCompositeConditions(doc, compositeVerifyConditions) === false) continue;
|
|
11070
11103
|
if (isVerifyOthers) {
|
|
11071
11104
|
const flatDoc = this.api.flattenDocument(doc);
|
|
11072
11105
|
let passed = true;
|
|
11073
|
-
for (let
|
|
11074
|
-
const other = verifyOthers[
|
|
11106
|
+
for (let k2 = 0, kLen = verifyOthers.length; k2 < kLen; k2++) {
|
|
11107
|
+
const other = verifyOthers[k2];
|
|
11075
11108
|
const coveredFields = other.coveredFields;
|
|
11076
11109
|
let fieldValue;
|
|
11077
11110
|
if (coveredFields && coveredFields.length > 1) {
|
|
11078
11111
|
const values = [];
|
|
11079
11112
|
let hasMissing = false;
|
|
11080
|
-
for (let
|
|
11081
|
-
const
|
|
11082
|
-
if (
|
|
11113
|
+
for (let f2 = 0, fLen = coveredFields.length; f2 < fLen; f2++) {
|
|
11114
|
+
const v2 = flatDoc[coveredFields[f2]];
|
|
11115
|
+
if (v2 === void 0) {
|
|
11083
11116
|
hasMissing = true;
|
|
11084
11117
|
break;
|
|
11085
11118
|
}
|
|
11086
|
-
values.push(
|
|
11119
|
+
values.push(v2);
|
|
11087
11120
|
}
|
|
11088
11121
|
if (hasMissing) {
|
|
11089
11122
|
passed = false;
|
|
@@ -11107,8 +11140,9 @@ var QueryManager = class {
|
|
|
11107
11140
|
}
|
|
11108
11141
|
docs.push(doc);
|
|
11109
11142
|
}
|
|
11143
|
+
nAccumulated += docs.length;
|
|
11110
11144
|
if (!isReadQuotaLimited) {
|
|
11111
|
-
currentChunkSize = this.adjustChunkSize(currentChunkSize, chunkTotalSize);
|
|
11145
|
+
currentChunkSize = this.adjustChunkSize(currentChunkSize, nAccumulated, limit, chunkTotalSize);
|
|
11112
11146
|
}
|
|
11113
11147
|
return docs;
|
|
11114
11148
|
};
|
|
@@ -11188,9 +11222,9 @@ var QueryManager = class {
|
|
|
11188
11222
|
const topK = limit === Infinity ? Infinity : offset + limit;
|
|
11189
11223
|
let heap = null;
|
|
11190
11224
|
if (topK !== Infinity) {
|
|
11191
|
-
heap = new BinaryHeap((a,
|
|
11225
|
+
heap = new BinaryHeap((a, b2) => {
|
|
11192
11226
|
const aVal = a[orderByField] ?? a._id;
|
|
11193
|
-
const bVal =
|
|
11227
|
+
const bVal = b2[orderByField] ?? b2._id;
|
|
11194
11228
|
const cmp = aVal < bVal ? -1 : aVal > bVal ? 1 : 0;
|
|
11195
11229
|
return sortOrder === "asc" ? -cmp : cmp;
|
|
11196
11230
|
});
|
|
@@ -11222,9 +11256,9 @@ var QueryManager = class {
|
|
|
11222
11256
|
}
|
|
11223
11257
|
}
|
|
11224
11258
|
const finalDocs = heap ? heap.toArray() : results;
|
|
11225
|
-
finalDocs.sort((a,
|
|
11259
|
+
finalDocs.sort((a, b2) => {
|
|
11226
11260
|
const aVal = a[orderByField] ?? a._id;
|
|
11227
|
-
const bVal =
|
|
11261
|
+
const bVal = b2[orderByField] ?? b2._id;
|
|
11228
11262
|
const cmp = aVal < bVal ? -1 : aVal > bVal ? 1 : 0;
|
|
11229
11263
|
return sortOrder === "asc" ? cmp : -cmp;
|
|
11230
11264
|
});
|
|
@@ -11562,8 +11596,8 @@ var IndexManager = class {
|
|
|
11562
11596
|
const stream = idTree.whereStream({
|
|
11563
11597
|
primaryGte: { v: 0 }
|
|
11564
11598
|
});
|
|
11565
|
-
for await (const [
|
|
11566
|
-
const doc = await this.api.getDocument(
|
|
11599
|
+
for await (const [k2, complexValue] of stream) {
|
|
11600
|
+
const doc = await this.api.getDocument(k2, tx2);
|
|
11567
11601
|
if (!doc) continue;
|
|
11568
11602
|
const flatDoc = this.api.flattenDocument(doc);
|
|
11569
11603
|
for (let i = 0, len = backfillTargets.length; i < len; i++) {
|
|
@@ -11574,23 +11608,23 @@ var IndexManager = class {
|
|
|
11574
11608
|
const btx = indexTxMap[indexName];
|
|
11575
11609
|
if (config.type === "fts") {
|
|
11576
11610
|
const primaryField = this.getPrimaryField(config);
|
|
11577
|
-
const
|
|
11578
|
-
if (
|
|
11611
|
+
const v2 = flatDoc[primaryField];
|
|
11612
|
+
if (v2 === void 0 || typeof v2 !== "string") continue;
|
|
11579
11613
|
const ftsConfig = this.getFtsConfig(config);
|
|
11580
|
-
const tokens = ftsConfig ? tokenize(
|
|
11614
|
+
const tokens = ftsConfig ? tokenize(v2, ftsConfig) : [v2];
|
|
11581
11615
|
const batchInsertData = [];
|
|
11582
11616
|
for (let i2 = 0, len2 = tokens.length; i2 < len2; i2++) {
|
|
11583
11617
|
const token = tokens[i2];
|
|
11584
|
-
const keyToInsert = this.getTokenKey(
|
|
11585
|
-
const entry = { k, v: token };
|
|
11618
|
+
const keyToInsert = this.getTokenKey(k2, token);
|
|
11619
|
+
const entry = { k: k2, v: token };
|
|
11586
11620
|
batchInsertData.push([keyToInsert, entry]);
|
|
11587
11621
|
}
|
|
11588
11622
|
await btx.batchInsert(batchInsertData);
|
|
11589
11623
|
} else {
|
|
11590
11624
|
const indexVal = this.getIndexValue(config, flatDoc);
|
|
11591
11625
|
if (indexVal === void 0) continue;
|
|
11592
|
-
const entry = { k, v: indexVal };
|
|
11593
|
-
const batchInsertData = [[
|
|
11626
|
+
const entry = { k: k2, v: indexVal };
|
|
11627
|
+
const batchInsertData = [[k2, entry]];
|
|
11594
11628
|
await btx.batchInsert(batchInsertData);
|
|
11595
11629
|
}
|
|
11596
11630
|
}
|
|
@@ -11706,14 +11740,14 @@ var IndexManager = class {
|
|
|
11706
11740
|
getIndexValue(config, flatDoc) {
|
|
11707
11741
|
if (config.type !== "btree") return void 0;
|
|
11708
11742
|
if (config.fields.length === 1) {
|
|
11709
|
-
const
|
|
11710
|
-
return
|
|
11743
|
+
const v2 = flatDoc[config.fields[0]];
|
|
11744
|
+
return v2 === void 0 ? void 0 : v2;
|
|
11711
11745
|
}
|
|
11712
11746
|
const values = [];
|
|
11713
11747
|
for (let i = 0, len = config.fields.length; i < len; i++) {
|
|
11714
|
-
const
|
|
11715
|
-
if (
|
|
11716
|
-
values.push(
|
|
11748
|
+
const v2 = flatDoc[config.fields[i]];
|
|
11749
|
+
if (v2 === void 0) return void 0;
|
|
11750
|
+
values.push(v2);
|
|
11717
11751
|
}
|
|
11718
11752
|
return values;
|
|
11719
11753
|
}
|
|
@@ -11737,6 +11771,64 @@ async function catchPromise(promise) {
|
|
|
11737
11771
|
return promise.then((res) => [void 0, res]).catch((reason) => [reason]);
|
|
11738
11772
|
}
|
|
11739
11773
|
|
|
11774
|
+
// src/utils/DeadlineChunker.ts
|
|
11775
|
+
var DeadlineChunker = class {
|
|
11776
|
+
/**
|
|
11777
|
+
* 이벤트 루프를 막을 최대 허용 시간
|
|
11778
|
+
*/
|
|
11779
|
+
targetMs;
|
|
11780
|
+
/**
|
|
11781
|
+
* 현재 chunk size
|
|
11782
|
+
*/
|
|
11783
|
+
chunkSize;
|
|
11784
|
+
/**
|
|
11785
|
+
* Exponential Weighted Moving Average
|
|
11786
|
+
*/
|
|
11787
|
+
ewmaMs;
|
|
11788
|
+
/**
|
|
11789
|
+
* EWMA 평활화 계수
|
|
11790
|
+
*/
|
|
11791
|
+
alpha;
|
|
11792
|
+
constructor(targetMs = 14) {
|
|
11793
|
+
this.targetMs = targetMs;
|
|
11794
|
+
this.chunkSize = 50;
|
|
11795
|
+
this.ewmaMs = null;
|
|
11796
|
+
this.alpha = 0.3;
|
|
11797
|
+
}
|
|
11798
|
+
/**
|
|
11799
|
+
* EWMA 평활화 계수를 사용하여 평균 처리 시간을 업데이트합니다.
|
|
11800
|
+
*/
|
|
11801
|
+
_updateEstimate(elapsed, count) {
|
|
11802
|
+
const msPerItem = elapsed / count;
|
|
11803
|
+
this.ewmaMs = this.ewmaMs === null ? msPerItem : this.alpha * msPerItem + (1 - this.alpha) * this.ewmaMs;
|
|
11804
|
+
}
|
|
11805
|
+
/**
|
|
11806
|
+
* 현재 chunk size를 업데이트합니다.
|
|
11807
|
+
*/
|
|
11808
|
+
_nextChunkSize() {
|
|
11809
|
+
if (!this.ewmaMs || this.ewmaMs === 0) return this.chunkSize;
|
|
11810
|
+
const next = Math.floor(this.targetMs / this.ewmaMs);
|
|
11811
|
+
return Math.max(1, Math.min(next, 5e3));
|
|
11812
|
+
}
|
|
11813
|
+
/**
|
|
11814
|
+
* 주어진 items를 chunk로 분할하여 처리합니다.
|
|
11815
|
+
*/
|
|
11816
|
+
async processInChunks(items, processFn) {
|
|
11817
|
+
let i = 0;
|
|
11818
|
+
let len = items.length;
|
|
11819
|
+
while (i < len) {
|
|
11820
|
+
const chunk = items.slice(i, i + this.chunkSize);
|
|
11821
|
+
const start = performance.now();
|
|
11822
|
+
await processFn(chunk);
|
|
11823
|
+
const elapsed = performance.now() - start;
|
|
11824
|
+
this._updateEstimate(elapsed, chunk.length);
|
|
11825
|
+
this.chunkSize = this._nextChunkSize();
|
|
11826
|
+
i += chunk.length;
|
|
11827
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
11828
|
+
}
|
|
11829
|
+
}
|
|
11830
|
+
};
|
|
11831
|
+
|
|
11740
11832
|
// src/core/MutationManager.ts
|
|
11741
11833
|
var MutationManager = class {
|
|
11742
11834
|
constructor(api) {
|
|
@@ -11765,10 +11857,10 @@ var MutationManager = class {
|
|
|
11765
11857
|
if (!tree) continue;
|
|
11766
11858
|
if (config.type === "fts") {
|
|
11767
11859
|
const primaryField = this.api.indexManager.getPrimaryField(config);
|
|
11768
|
-
const
|
|
11769
|
-
if (
|
|
11860
|
+
const v2 = flattenDocument[primaryField];
|
|
11861
|
+
if (v2 === void 0 || typeof v2 !== "string") continue;
|
|
11770
11862
|
const ftsConfig = this.api.indexManager.getFtsConfig(config);
|
|
11771
|
-
const tokens = ftsConfig ? tokenize(
|
|
11863
|
+
const tokens = ftsConfig ? tokenize(v2, ftsConfig) : [v2];
|
|
11772
11864
|
for (let i = 0, len = tokens.length; i < len; i++) {
|
|
11773
11865
|
const token = tokens[i];
|
|
11774
11866
|
const keyToInsert = this.api.indexManager.getTokenKey(dpk, token);
|
|
@@ -11820,9 +11912,9 @@ var MutationManager = class {
|
|
|
11820
11912
|
const ftsConfig = this.api.indexManager.getFtsConfig(config);
|
|
11821
11913
|
for (let i = 0, len = flattenedData.length; i < len; i++) {
|
|
11822
11914
|
const item = flattenedData[i];
|
|
11823
|
-
const
|
|
11824
|
-
if (
|
|
11825
|
-
const tokens = ftsConfig ? tokenize(
|
|
11915
|
+
const v2 = item.data[primaryField];
|
|
11916
|
+
if (v2 === void 0 || typeof v2 !== "string") continue;
|
|
11917
|
+
const tokens = ftsConfig ? tokenize(v2, ftsConfig) : [v2];
|
|
11826
11918
|
for (let j = 0, tLen = tokens.length; j < tLen; j++) {
|
|
11827
11919
|
const token = tokens[j];
|
|
11828
11920
|
batchInsertData.push([this.api.indexManager.getTokenKey(item.pk, token), { k: item.pk, v: token }]);
|
|
@@ -11836,10 +11928,13 @@ var MutationManager = class {
|
|
|
11836
11928
|
batchInsertData.push([item.pk, { k: item.pk, v: indexVal }]);
|
|
11837
11929
|
}
|
|
11838
11930
|
}
|
|
11839
|
-
const
|
|
11840
|
-
|
|
11841
|
-
|
|
11842
|
-
|
|
11931
|
+
const chunker = new DeadlineChunker();
|
|
11932
|
+
await chunker.processInChunks(batchInsertData, async (chunk) => {
|
|
11933
|
+
const [error] = await catchPromise(treeTx.batchInsert(chunk));
|
|
11934
|
+
if (error) {
|
|
11935
|
+
throw error;
|
|
11936
|
+
}
|
|
11937
|
+
});
|
|
11843
11938
|
const res = await treeTx.commit();
|
|
11844
11939
|
if (!res.success) {
|
|
11845
11940
|
throw res.error;
|
|
@@ -11953,10 +12048,10 @@ var MutationManager = class {
|
|
|
11953
12048
|
if (!config) continue;
|
|
11954
12049
|
if (config.type === "fts") {
|
|
11955
12050
|
const primaryField = this.api.indexManager.getPrimaryField(config);
|
|
11956
|
-
const
|
|
11957
|
-
if (
|
|
12051
|
+
const v2 = flatDoc[primaryField];
|
|
12052
|
+
if (v2 === void 0 || typeof v2 !== "string") continue;
|
|
11958
12053
|
const ftsConfig = this.api.indexManager.getFtsConfig(config);
|
|
11959
|
-
const tokens = ftsConfig ? tokenize(
|
|
12054
|
+
const tokens = ftsConfig ? tokenize(v2, ftsConfig) : [v2];
|
|
11960
12055
|
for (let j = 0, jLen = tokens.length; j < jLen; j++) {
|
|
11961
12056
|
await tree.delete(this.api.indexManager.getTokenKey(pk, tokens[j]), { k: pk, v: tokens[j] });
|
|
11962
12057
|
}
|
|
@@ -12042,6 +12137,657 @@ var DocumentFormatter = class {
|
|
|
12042
12137
|
}
|
|
12043
12138
|
};
|
|
12044
12139
|
|
|
12140
|
+
// node_modules/croner/dist/croner.js
|
|
12141
|
+
function T(s2) {
|
|
12142
|
+
return Date.UTC(s2.y, s2.m - 1, s2.d, s2.h, s2.i, s2.s);
|
|
12143
|
+
}
|
|
12144
|
+
function D(s2, e) {
|
|
12145
|
+
return s2.y === e.y && s2.m === e.m && s2.d === e.d && s2.h === e.h && s2.i === e.i && s2.s === e.s;
|
|
12146
|
+
}
|
|
12147
|
+
function A(s2, e) {
|
|
12148
|
+
let t = new Date(Date.parse(s2));
|
|
12149
|
+
if (isNaN(t)) throw new Error("Invalid ISO8601 passed to timezone parser.");
|
|
12150
|
+
let r = s2.substring(9);
|
|
12151
|
+
return r.includes("Z") || r.includes("+") || r.includes("-") ? b(t.getUTCFullYear(), t.getUTCMonth() + 1, t.getUTCDate(), t.getUTCHours(), t.getUTCMinutes(), t.getUTCSeconds(), "Etc/UTC") : b(t.getFullYear(), t.getMonth() + 1, t.getDate(), t.getHours(), t.getMinutes(), t.getSeconds(), e);
|
|
12152
|
+
}
|
|
12153
|
+
function v(s2, e, t) {
|
|
12154
|
+
return k(A(s2, e), t);
|
|
12155
|
+
}
|
|
12156
|
+
function k(s2, e) {
|
|
12157
|
+
let t = new Date(T(s2)), r = g(t, s2.tz), n = T(s2), i = T(r), a = n - i, o = new Date(t.getTime() + a), h = g(o, s2.tz);
|
|
12158
|
+
if (D(h, s2)) {
|
|
12159
|
+
let u = new Date(o.getTime() - 36e5), d = g(u, s2.tz);
|
|
12160
|
+
return D(d, s2) ? u : o;
|
|
12161
|
+
}
|
|
12162
|
+
let l = new Date(o.getTime() + T(s2) - T(h)), y = g(l, s2.tz);
|
|
12163
|
+
if (D(y, s2)) return l;
|
|
12164
|
+
if (e) throw new Error("Invalid date passed to fromTZ()");
|
|
12165
|
+
return o.getTime() > l.getTime() ? o : l;
|
|
12166
|
+
}
|
|
12167
|
+
function g(s2, e) {
|
|
12168
|
+
let t, r;
|
|
12169
|
+
try {
|
|
12170
|
+
t = new Intl.DateTimeFormat("en-US", { timeZone: e, year: "numeric", month: "numeric", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric", hour12: false }), r = t.formatToParts(s2);
|
|
12171
|
+
} catch (i) {
|
|
12172
|
+
let a = i instanceof Error ? i.message : String(i);
|
|
12173
|
+
throw new RangeError(`toTZ: Invalid timezone '${e}' or date. Please provide a valid IANA timezone (e.g., 'America/New_York', 'Europe/Stockholm'). Original error: ${a}`);
|
|
12174
|
+
}
|
|
12175
|
+
let n = { year: 0, month: 0, day: 0, hour: 0, minute: 0, second: 0 };
|
|
12176
|
+
for (let i of r) (i.type === "year" || i.type === "month" || i.type === "day" || i.type === "hour" || i.type === "minute" || i.type === "second") && (n[i.type] = parseInt(i.value, 10));
|
|
12177
|
+
if (isNaN(n.year) || isNaN(n.month) || isNaN(n.day) || isNaN(n.hour) || isNaN(n.minute) || isNaN(n.second)) throw new Error(`toTZ: Failed to parse all date components from timezone '${e}'. This may indicate an invalid date or timezone configuration. Parsed components: ${JSON.stringify(n)}`);
|
|
12178
|
+
return n.hour === 24 && (n.hour = 0), { y: n.year, m: n.month, d: n.day, h: n.hour, i: n.minute, s: n.second, tz: e };
|
|
12179
|
+
}
|
|
12180
|
+
function b(s2, e, t, r, n, i, a) {
|
|
12181
|
+
return { y: s2, m: e, d: t, h: r, i: n, s: i, tz: a };
|
|
12182
|
+
}
|
|
12183
|
+
var O = [1, 2, 4, 8, 16];
|
|
12184
|
+
var C = class {
|
|
12185
|
+
pattern;
|
|
12186
|
+
timezone;
|
|
12187
|
+
mode;
|
|
12188
|
+
alternativeWeekdays;
|
|
12189
|
+
sloppyRanges;
|
|
12190
|
+
second;
|
|
12191
|
+
minute;
|
|
12192
|
+
hour;
|
|
12193
|
+
day;
|
|
12194
|
+
month;
|
|
12195
|
+
dayOfWeek;
|
|
12196
|
+
year;
|
|
12197
|
+
lastDayOfMonth;
|
|
12198
|
+
lastWeekday;
|
|
12199
|
+
nearestWeekdays;
|
|
12200
|
+
starDOM;
|
|
12201
|
+
starDOW;
|
|
12202
|
+
starYear;
|
|
12203
|
+
useAndLogic;
|
|
12204
|
+
constructor(e, t, r) {
|
|
12205
|
+
this.pattern = e, this.timezone = t, this.mode = r?.mode ?? "auto", this.alternativeWeekdays = r?.alternativeWeekdays ?? false, this.sloppyRanges = r?.sloppyRanges ?? false, this.second = Array(60).fill(0), this.minute = Array(60).fill(0), this.hour = Array(24).fill(0), this.day = Array(31).fill(0), this.month = Array(12).fill(0), this.dayOfWeek = Array(7).fill(0), this.year = Array(1e4).fill(0), this.lastDayOfMonth = false, this.lastWeekday = false, this.nearestWeekdays = Array(31).fill(0), this.starDOM = false, this.starDOW = false, this.starYear = false, this.useAndLogic = false, this.parse();
|
|
12206
|
+
}
|
|
12207
|
+
parse() {
|
|
12208
|
+
if (!(typeof this.pattern == "string" || this.pattern instanceof String)) throw new TypeError("CronPattern: Pattern has to be of type string.");
|
|
12209
|
+
this.pattern.indexOf("@") >= 0 && (this.pattern = this.handleNicknames(this.pattern).trim());
|
|
12210
|
+
let e = this.pattern.match(/\S+/g) || [""], t = e.length;
|
|
12211
|
+
if (e.length < 5 || e.length > 7) throw new TypeError("CronPattern: invalid configuration format ('" + this.pattern + "'), exactly five, six, or seven space separated parts are required.");
|
|
12212
|
+
if (this.mode !== "auto") {
|
|
12213
|
+
let n;
|
|
12214
|
+
switch (this.mode) {
|
|
12215
|
+
case "5-part":
|
|
12216
|
+
n = 5;
|
|
12217
|
+
break;
|
|
12218
|
+
case "6-part":
|
|
12219
|
+
n = 6;
|
|
12220
|
+
break;
|
|
12221
|
+
case "7-part":
|
|
12222
|
+
n = 7;
|
|
12223
|
+
break;
|
|
12224
|
+
case "5-or-6-parts":
|
|
12225
|
+
n = [5, 6];
|
|
12226
|
+
break;
|
|
12227
|
+
case "6-or-7-parts":
|
|
12228
|
+
n = [6, 7];
|
|
12229
|
+
break;
|
|
12230
|
+
default:
|
|
12231
|
+
n = 0;
|
|
12232
|
+
}
|
|
12233
|
+
if (!(Array.isArray(n) ? n.includes(t) : t === n)) {
|
|
12234
|
+
let a = Array.isArray(n) ? n.join(" or ") : n.toString();
|
|
12235
|
+
throw new TypeError(`CronPattern: mode '${this.mode}' requires exactly ${a} parts, but pattern '${this.pattern}' has ${t} parts.`);
|
|
12236
|
+
}
|
|
12237
|
+
}
|
|
12238
|
+
if (e.length === 5 && e.unshift("0"), e.length === 6 && e.push("*"), e[3].toUpperCase() === "LW" ? (this.lastWeekday = true, e[3] = "") : e[3].toUpperCase().indexOf("L") >= 0 && (e[3] = e[3].replace(/L/gi, ""), this.lastDayOfMonth = true), e[3] == "*" && (this.starDOM = true), e[6] == "*" && (this.starYear = true), e[4].length >= 3 && (e[4] = this.replaceAlphaMonths(e[4])), e[5].length >= 3 && (e[5] = this.alternativeWeekdays ? this.replaceAlphaDaysQuartz(e[5]) : this.replaceAlphaDays(e[5])), e[5].startsWith("+") && (this.useAndLogic = true, e[5] = e[5].substring(1), e[5] === "")) throw new TypeError("CronPattern: Day-of-week field cannot be empty after '+' modifier.");
|
|
12239
|
+
switch (e[5] == "*" && (this.starDOW = true), this.pattern.indexOf("?") >= 0 && (e[0] = e[0].replace(/\?/g, "*"), e[1] = e[1].replace(/\?/g, "*"), e[2] = e[2].replace(/\?/g, "*"), e[3] = e[3].replace(/\?/g, "*"), e[4] = e[4].replace(/\?/g, "*"), e[5] = e[5].replace(/\?/g, "*"), e[6] && (e[6] = e[6].replace(/\?/g, "*"))), this.mode) {
|
|
12240
|
+
case "5-part":
|
|
12241
|
+
e[0] = "0", e[6] = "*";
|
|
12242
|
+
break;
|
|
12243
|
+
case "6-part":
|
|
12244
|
+
e[6] = "*";
|
|
12245
|
+
break;
|
|
12246
|
+
case "5-or-6-parts":
|
|
12247
|
+
e[6] = "*";
|
|
12248
|
+
break;
|
|
12249
|
+
case "6-or-7-parts":
|
|
12250
|
+
break;
|
|
12251
|
+
case "7-part":
|
|
12252
|
+
case "auto":
|
|
12253
|
+
break;
|
|
12254
|
+
}
|
|
12255
|
+
this.throwAtIllegalCharacters(e), this.partToArray("second", e[0], 0, 1), this.partToArray("minute", e[1], 0, 1), this.partToArray("hour", e[2], 0, 1), this.partToArray("day", e[3], -1, 1), this.partToArray("month", e[4], -1, 1);
|
|
12256
|
+
let r = this.alternativeWeekdays ? -1 : 0;
|
|
12257
|
+
this.partToArray("dayOfWeek", e[5], r, 63), this.partToArray("year", e[6], 0, 1), !this.alternativeWeekdays && this.dayOfWeek[7] && (this.dayOfWeek[0] = this.dayOfWeek[7]);
|
|
12258
|
+
}
|
|
12259
|
+
partToArray(e, t, r, n) {
|
|
12260
|
+
let i = this[e], a = e === "day" && this.lastDayOfMonth, o = e === "day" && this.lastWeekday;
|
|
12261
|
+
if (t === "" && !a && !o) throw new TypeError("CronPattern: configuration entry " + e + " (" + t + ") is empty, check for trailing spaces.");
|
|
12262
|
+
if (t === "*") return i.fill(n);
|
|
12263
|
+
let h = t.split(",");
|
|
12264
|
+
if (h.length > 1) for (let l = 0; l < h.length; l++) this.partToArray(e, h[l], r, n);
|
|
12265
|
+
else t.indexOf("-") !== -1 && t.indexOf("/") !== -1 ? this.handleRangeWithStepping(t, e, r, n) : t.indexOf("-") !== -1 ? this.handleRange(t, e, r, n) : t.indexOf("/") !== -1 ? this.handleStepping(t, e, r, n) : t !== "" && this.handleNumber(t, e, r, n);
|
|
12266
|
+
}
|
|
12267
|
+
throwAtIllegalCharacters(e) {
|
|
12268
|
+
for (let t = 0; t < e.length; t++) if ((t === 3 ? /[^/*0-9,\-WwLl]+/ : t === 5 ? /[^/*0-9,\-#Ll]+/ : /[^/*0-9,\-]+/).test(e[t])) throw new TypeError("CronPattern: configuration entry " + t + " (" + e[t] + ") contains illegal characters.");
|
|
12269
|
+
}
|
|
12270
|
+
handleNumber(e, t, r, n) {
|
|
12271
|
+
let i = this.extractNth(e, t), a = e.toUpperCase().includes("W");
|
|
12272
|
+
if (t !== "day" && a) throw new TypeError("CronPattern: Nearest weekday modifier (W) only allowed in day-of-month.");
|
|
12273
|
+
a && (t = "nearestWeekdays");
|
|
12274
|
+
let o = parseInt(i[0], 10) + r;
|
|
12275
|
+
if (isNaN(o)) throw new TypeError("CronPattern: " + t + " is not a number: '" + e + "'");
|
|
12276
|
+
this.setPart(t, o, i[1] || n);
|
|
12277
|
+
}
|
|
12278
|
+
setPart(e, t, r) {
|
|
12279
|
+
if (!Object.prototype.hasOwnProperty.call(this, e)) throw new TypeError("CronPattern: Invalid part specified: " + e);
|
|
12280
|
+
if (e === "dayOfWeek") {
|
|
12281
|
+
if (t === 7 && (t = 0), t < 0 || t > 6) throw new RangeError("CronPattern: Invalid value for dayOfWeek: " + t);
|
|
12282
|
+
this.setNthWeekdayOfMonth(t, r);
|
|
12283
|
+
return;
|
|
12284
|
+
}
|
|
12285
|
+
if (e === "second" || e === "minute") {
|
|
12286
|
+
if (t < 0 || t >= 60) throw new RangeError("CronPattern: Invalid value for " + e + ": " + t);
|
|
12287
|
+
} else if (e === "hour") {
|
|
12288
|
+
if (t < 0 || t >= 24) throw new RangeError("CronPattern: Invalid value for " + e + ": " + t);
|
|
12289
|
+
} else if (e === "day" || e === "nearestWeekdays") {
|
|
12290
|
+
if (t < 0 || t >= 31) throw new RangeError("CronPattern: Invalid value for " + e + ": " + t);
|
|
12291
|
+
} else if (e === "month") {
|
|
12292
|
+
if (t < 0 || t >= 12) throw new RangeError("CronPattern: Invalid value for " + e + ": " + t);
|
|
12293
|
+
} else if (e === "year" && (t < 1 || t >= 1e4)) throw new RangeError("CronPattern: Invalid value for " + e + ": " + t + " (supported range: 1-9999)");
|
|
12294
|
+
this[e][t] = r;
|
|
12295
|
+
}
|
|
12296
|
+
validateNotNaN(e, t) {
|
|
12297
|
+
if (isNaN(e)) throw new TypeError(t);
|
|
12298
|
+
}
|
|
12299
|
+
validateRange(e, t, r, n, i) {
|
|
12300
|
+
if (e > t) throw new TypeError("CronPattern: From value is larger than to value: '" + i + "'");
|
|
12301
|
+
if (r !== void 0) {
|
|
12302
|
+
if (r === 0) throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");
|
|
12303
|
+
if (r > this[n].length) throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part (" + this[n].length + ")");
|
|
12304
|
+
}
|
|
12305
|
+
}
|
|
12306
|
+
handleRangeWithStepping(e, t, r, n) {
|
|
12307
|
+
if (e.toUpperCase().includes("W")) throw new TypeError("CronPattern: Syntax error, W is not allowed in ranges with stepping.");
|
|
12308
|
+
let i = this.extractNth(e, t), a = i[0].match(/^(\d+)-(\d+)\/(\d+)$/);
|
|
12309
|
+
if (a === null) throw new TypeError("CronPattern: Syntax error, illegal range with stepping: '" + e + "'");
|
|
12310
|
+
let [, o, h, l] = a, y = parseInt(o, 10) + r, u = parseInt(h, 10) + r, d = parseInt(l, 10);
|
|
12311
|
+
this.validateNotNaN(y, "CronPattern: Syntax error, illegal lower range (NaN)"), this.validateNotNaN(u, "CronPattern: Syntax error, illegal upper range (NaN)"), this.validateNotNaN(d, "CronPattern: Syntax error, illegal stepping: (NaN)"), this.validateRange(y, u, d, t, e);
|
|
12312
|
+
for (let c = y; c <= u; c += d) this.setPart(t, c, i[1] || n);
|
|
12313
|
+
}
|
|
12314
|
+
extractNth(e, t) {
|
|
12315
|
+
let r = e, n;
|
|
12316
|
+
if (r.includes("#")) {
|
|
12317
|
+
if (t !== "dayOfWeek") throw new Error("CronPattern: nth (#) only allowed in day-of-week field");
|
|
12318
|
+
n = r.split("#")[1], r = r.split("#")[0];
|
|
12319
|
+
} else if (r.toUpperCase().endsWith("L")) {
|
|
12320
|
+
if (t !== "dayOfWeek") throw new Error("CronPattern: L modifier only allowed in day-of-week field (use L alone for day-of-month)");
|
|
12321
|
+
n = "L", r = r.slice(0, -1);
|
|
12322
|
+
}
|
|
12323
|
+
return [r, n];
|
|
12324
|
+
}
|
|
12325
|
+
handleRange(e, t, r, n) {
|
|
12326
|
+
if (e.toUpperCase().includes("W")) throw new TypeError("CronPattern: Syntax error, W is not allowed in a range.");
|
|
12327
|
+
let i = this.extractNth(e, t), a = i[0].split("-");
|
|
12328
|
+
if (a.length !== 2) throw new TypeError("CronPattern: Syntax error, illegal range: '" + e + "'");
|
|
12329
|
+
let o = parseInt(a[0], 10) + r, h = parseInt(a[1], 10) + r;
|
|
12330
|
+
this.validateNotNaN(o, "CronPattern: Syntax error, illegal lower range (NaN)"), this.validateNotNaN(h, "CronPattern: Syntax error, illegal upper range (NaN)"), this.validateRange(o, h, void 0, t, e);
|
|
12331
|
+
for (let l = o; l <= h; l++) this.setPart(t, l, i[1] || n);
|
|
12332
|
+
}
|
|
12333
|
+
handleStepping(e, t, r, n) {
|
|
12334
|
+
if (e.toUpperCase().includes("W")) throw new TypeError("CronPattern: Syntax error, W is not allowed in parts with stepping.");
|
|
12335
|
+
let i = this.extractNth(e, t), a = i[0].split("/");
|
|
12336
|
+
if (a.length !== 2) throw new TypeError("CronPattern: Syntax error, illegal stepping: '" + e + "'");
|
|
12337
|
+
if (this.sloppyRanges) a[0] === "" && (a[0] = "*");
|
|
12338
|
+
else {
|
|
12339
|
+
if (a[0] === "") throw new TypeError("CronPattern: Syntax error, stepping with missing prefix ('" + e + "') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.");
|
|
12340
|
+
if (a[0] !== "*") throw new TypeError("CronPattern: Syntax error, stepping with numeric prefix ('" + e + "') is not allowed. Use wildcard (*/step) or range (min-max/step) instead.");
|
|
12341
|
+
}
|
|
12342
|
+
let o = 0;
|
|
12343
|
+
a[0] !== "*" && (o = parseInt(a[0], 10) + r);
|
|
12344
|
+
let h = parseInt(a[1], 10);
|
|
12345
|
+
this.validateNotNaN(h, "CronPattern: Syntax error, illegal stepping: (NaN)"), this.validateRange(0, this[t].length - 1, h, t, e);
|
|
12346
|
+
for (let l = o; l < this[t].length; l += h) this.setPart(t, l, i[1] || n);
|
|
12347
|
+
}
|
|
12348
|
+
replaceAlphaDays(e) {
|
|
12349
|
+
return e.replace(/-sun/gi, "-7").replace(/sun/gi, "0").replace(/mon/gi, "1").replace(/tue/gi, "2").replace(/wed/gi, "3").replace(/thu/gi, "4").replace(/fri/gi, "5").replace(/sat/gi, "6");
|
|
12350
|
+
}
|
|
12351
|
+
replaceAlphaDaysQuartz(e) {
|
|
12352
|
+
return e.replace(/sun/gi, "1").replace(/mon/gi, "2").replace(/tue/gi, "3").replace(/wed/gi, "4").replace(/thu/gi, "5").replace(/fri/gi, "6").replace(/sat/gi, "7");
|
|
12353
|
+
}
|
|
12354
|
+
replaceAlphaMonths(e) {
|
|
12355
|
+
return e.replace(/jan/gi, "1").replace(/feb/gi, "2").replace(/mar/gi, "3").replace(/apr/gi, "4").replace(/may/gi, "5").replace(/jun/gi, "6").replace(/jul/gi, "7").replace(/aug/gi, "8").replace(/sep/gi, "9").replace(/oct/gi, "10").replace(/nov/gi, "11").replace(/dec/gi, "12");
|
|
12356
|
+
}
|
|
12357
|
+
handleNicknames(e) {
|
|
12358
|
+
let t = e.trim().toLowerCase();
|
|
12359
|
+
if (t === "@yearly" || t === "@annually") return "0 0 1 1 *";
|
|
12360
|
+
if (t === "@monthly") return "0 0 1 * *";
|
|
12361
|
+
if (t === "@weekly") return "0 0 * * 0";
|
|
12362
|
+
if (t === "@daily" || t === "@midnight") return "0 0 * * *";
|
|
12363
|
+
if (t === "@hourly") return "0 * * * *";
|
|
12364
|
+
if (t === "@reboot") throw new TypeError("CronPattern: @reboot is not supported in this environment. This is an event-based trigger that requires system startup detection.");
|
|
12365
|
+
return e;
|
|
12366
|
+
}
|
|
12367
|
+
setNthWeekdayOfMonth(e, t) {
|
|
12368
|
+
if (typeof t != "number" && t.toUpperCase() === "L") this.dayOfWeek[e] = this.dayOfWeek[e] | 32;
|
|
12369
|
+
else if (t === 63) this.dayOfWeek[e] = 63;
|
|
12370
|
+
else if (t < 6 && t > 0) this.dayOfWeek[e] = this.dayOfWeek[e] | O[t - 1];
|
|
12371
|
+
else throw new TypeError(`CronPattern: nth weekday out of range, should be 1-5 or L. Value: ${t}, Type: ${typeof t}`);
|
|
12372
|
+
}
|
|
12373
|
+
};
|
|
12374
|
+
var P = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
12375
|
+
var f = [["month", "year", 0], ["day", "month", -1], ["hour", "day", 0], ["minute", "hour", 0], ["second", "minute", 0]];
|
|
12376
|
+
var m = class s {
|
|
12377
|
+
tz;
|
|
12378
|
+
ms;
|
|
12379
|
+
second;
|
|
12380
|
+
minute;
|
|
12381
|
+
hour;
|
|
12382
|
+
day;
|
|
12383
|
+
month;
|
|
12384
|
+
year;
|
|
12385
|
+
constructor(e, t) {
|
|
12386
|
+
if (this.tz = t, e && e instanceof Date) if (!isNaN(e)) this.fromDate(e);
|
|
12387
|
+
else throw new TypeError("CronDate: Invalid date passed to CronDate constructor");
|
|
12388
|
+
else if (e == null) this.fromDate(/* @__PURE__ */ new Date());
|
|
12389
|
+
else if (e && typeof e == "string") this.fromString(e);
|
|
12390
|
+
else if (e instanceof s) this.fromCronDate(e);
|
|
12391
|
+
else throw new TypeError("CronDate: Invalid type (" + typeof e + ") passed to CronDate constructor");
|
|
12392
|
+
}
|
|
12393
|
+
getLastDayOfMonth(e, t) {
|
|
12394
|
+
return t !== 1 ? P[t] : new Date(Date.UTC(e, t + 1, 0)).getUTCDate();
|
|
12395
|
+
}
|
|
12396
|
+
getLastWeekday(e, t) {
|
|
12397
|
+
let r = this.getLastDayOfMonth(e, t), i = new Date(Date.UTC(e, t, r)).getUTCDay();
|
|
12398
|
+
return i === 0 ? r - 2 : i === 6 ? r - 1 : r;
|
|
12399
|
+
}
|
|
12400
|
+
getNearestWeekday(e, t, r) {
|
|
12401
|
+
let n = this.getLastDayOfMonth(e, t);
|
|
12402
|
+
if (r > n) return -1;
|
|
12403
|
+
let a = new Date(Date.UTC(e, t, r)).getUTCDay();
|
|
12404
|
+
return a === 0 ? r === n ? r - 2 : r + 1 : a === 6 ? r === 1 ? r + 2 : r - 1 : r;
|
|
12405
|
+
}
|
|
12406
|
+
isNthWeekdayOfMonth(e, t, r, n) {
|
|
12407
|
+
let a = new Date(Date.UTC(e, t, r)).getUTCDay(), o = 0;
|
|
12408
|
+
for (let h = 1; h <= r; h++) new Date(Date.UTC(e, t, h)).getUTCDay() === a && o++;
|
|
12409
|
+
if (n & 63 && O[o - 1] & n) return true;
|
|
12410
|
+
if (n & 32) {
|
|
12411
|
+
let h = this.getLastDayOfMonth(e, t);
|
|
12412
|
+
for (let l = r + 1; l <= h; l++) if (new Date(Date.UTC(e, t, l)).getUTCDay() === a) return false;
|
|
12413
|
+
return true;
|
|
12414
|
+
}
|
|
12415
|
+
return false;
|
|
12416
|
+
}
|
|
12417
|
+
fromDate(e) {
|
|
12418
|
+
if (this.tz !== void 0) if (typeof this.tz == "number") this.ms = e.getUTCMilliseconds(), this.second = e.getUTCSeconds(), this.minute = e.getUTCMinutes() + this.tz, this.hour = e.getUTCHours(), this.day = e.getUTCDate(), this.month = e.getUTCMonth(), this.year = e.getUTCFullYear(), this.apply();
|
|
12419
|
+
else try {
|
|
12420
|
+
let t = g(e, this.tz);
|
|
12421
|
+
this.ms = e.getMilliseconds(), this.second = t.s, this.minute = t.i, this.hour = t.h, this.day = t.d, this.month = t.m - 1, this.year = t.y;
|
|
12422
|
+
} catch (t) {
|
|
12423
|
+
let r = t instanceof Error ? t.message : String(t);
|
|
12424
|
+
throw new TypeError(`CronDate: Failed to convert date to timezone '${this.tz}'. This may happen with invalid timezone names or dates. Original error: ${r}`);
|
|
12425
|
+
}
|
|
12426
|
+
else this.ms = e.getMilliseconds(), this.second = e.getSeconds(), this.minute = e.getMinutes(), this.hour = e.getHours(), this.day = e.getDate(), this.month = e.getMonth(), this.year = e.getFullYear();
|
|
12427
|
+
}
|
|
12428
|
+
fromCronDate(e) {
|
|
12429
|
+
this.tz = e.tz, this.year = e.year, this.month = e.month, this.day = e.day, this.hour = e.hour, this.minute = e.minute, this.second = e.second, this.ms = e.ms;
|
|
12430
|
+
}
|
|
12431
|
+
apply() {
|
|
12432
|
+
if (this.month > 11 || this.month < 0 || this.day > P[this.month] || this.day < 1 || this.hour > 59 || this.minute > 59 || this.second > 59 || this.hour < 0 || this.minute < 0 || this.second < 0) {
|
|
12433
|
+
let e = new Date(Date.UTC(this.year, this.month, this.day, this.hour, this.minute, this.second, this.ms));
|
|
12434
|
+
return this.ms = e.getUTCMilliseconds(), this.second = e.getUTCSeconds(), this.minute = e.getUTCMinutes(), this.hour = e.getUTCHours(), this.day = e.getUTCDate(), this.month = e.getUTCMonth(), this.year = e.getUTCFullYear(), true;
|
|
12435
|
+
} else return false;
|
|
12436
|
+
}
|
|
12437
|
+
fromString(e) {
|
|
12438
|
+
if (typeof this.tz == "number") {
|
|
12439
|
+
let t = v(e);
|
|
12440
|
+
this.ms = t.getUTCMilliseconds(), this.second = t.getUTCSeconds(), this.minute = t.getUTCMinutes(), this.hour = t.getUTCHours(), this.day = t.getUTCDate(), this.month = t.getUTCMonth(), this.year = t.getUTCFullYear(), this.apply();
|
|
12441
|
+
} else return this.fromDate(v(e, this.tz));
|
|
12442
|
+
}
|
|
12443
|
+
findNext(e, t, r, n) {
|
|
12444
|
+
return this._findMatch(e, t, r, n, 1);
|
|
12445
|
+
}
|
|
12446
|
+
_findMatch(e, t, r, n, i) {
|
|
12447
|
+
let a = this[t], o;
|
|
12448
|
+
r.lastDayOfMonth && (o = this.getLastDayOfMonth(this.year, this.month));
|
|
12449
|
+
let h = !r.starDOW && t == "day" ? new Date(Date.UTC(this.year, this.month, 1, 0, 0, 0, 0)).getUTCDay() : void 0, l = this[t] + n, y = i === 1 ? (u) => u < r[t].length : (u) => u >= 0;
|
|
12450
|
+
for (let u = l; y(u); u += i) {
|
|
12451
|
+
let d = r[t][u];
|
|
12452
|
+
if (t === "day" && !d) {
|
|
12453
|
+
for (let c = 0; c < r.nearestWeekdays.length; c++) if (r.nearestWeekdays[c]) {
|
|
12454
|
+
let M = this.getNearestWeekday(this.year, this.month, c - n);
|
|
12455
|
+
if (M === -1) continue;
|
|
12456
|
+
if (M === u - n) {
|
|
12457
|
+
d = 1;
|
|
12458
|
+
break;
|
|
12459
|
+
}
|
|
12460
|
+
}
|
|
12461
|
+
}
|
|
12462
|
+
if (t === "day" && r.lastWeekday) {
|
|
12463
|
+
let c = this.getLastWeekday(this.year, this.month);
|
|
12464
|
+
u - n === c && (d = 1);
|
|
12465
|
+
}
|
|
12466
|
+
if (t === "day" && r.lastDayOfMonth && u - n == o && (d = 1), t === "day" && !r.starDOW) {
|
|
12467
|
+
let c = r.dayOfWeek[(h + (u - n - 1)) % 7];
|
|
12468
|
+
if (c && c & 63) c = this.isNthWeekdayOfMonth(this.year, this.month, u - n, c) ? 1 : 0;
|
|
12469
|
+
else if (c) throw new Error(`CronDate: Invalid value for dayOfWeek encountered. ${c}`);
|
|
12470
|
+
r.useAndLogic ? d = d && c : !e.domAndDow && !r.starDOM ? d = d || c : d = d && c;
|
|
12471
|
+
}
|
|
12472
|
+
if (d) return this[t] = u - n, a !== this[t] ? 2 : 1;
|
|
12473
|
+
}
|
|
12474
|
+
return 3;
|
|
12475
|
+
}
|
|
12476
|
+
recurse(e, t, r) {
|
|
12477
|
+
if (r === 0 && !e.starYear) {
|
|
12478
|
+
if (this.year >= 0 && this.year < e.year.length && e.year[this.year] === 0) {
|
|
12479
|
+
let i = -1;
|
|
12480
|
+
for (let a = this.year + 1; a < e.year.length && a < 1e4; a++) if (e.year[a] === 1) {
|
|
12481
|
+
i = a;
|
|
12482
|
+
break;
|
|
12483
|
+
}
|
|
12484
|
+
if (i === -1) return null;
|
|
12485
|
+
this.year = i, this.month = 0, this.day = 1, this.hour = 0, this.minute = 0, this.second = 0, this.ms = 0;
|
|
12486
|
+
}
|
|
12487
|
+
if (this.year >= 1e4) return null;
|
|
12488
|
+
}
|
|
12489
|
+
let n = this.findNext(t, f[r][0], e, f[r][2]);
|
|
12490
|
+
if (n > 1) {
|
|
12491
|
+
let i = r + 1;
|
|
12492
|
+
for (; i < f.length; ) this[f[i][0]] = -f[i][2], i++;
|
|
12493
|
+
if (n === 3) {
|
|
12494
|
+
if (this[f[r][1]]++, this[f[r][0]] = -f[r][2], this.apply(), r === 0 && !e.starYear) {
|
|
12495
|
+
for (; this.year >= 0 && this.year < e.year.length && e.year[this.year] === 0 && this.year < 1e4; ) this.year++;
|
|
12496
|
+
if (this.year >= 1e4 || this.year >= e.year.length) return null;
|
|
12497
|
+
}
|
|
12498
|
+
return this.recurse(e, t, 0);
|
|
12499
|
+
} else if (this.apply()) return this.recurse(e, t, r - 1);
|
|
12500
|
+
}
|
|
12501
|
+
return r += 1, r >= f.length ? this : (e.starYear ? this.year >= 3e3 : this.year >= 1e4) ? null : this.recurse(e, t, r);
|
|
12502
|
+
}
|
|
12503
|
+
increment(e, t, r) {
|
|
12504
|
+
return this.second += t.interval !== void 0 && t.interval > 1 && r ? t.interval : 1, this.ms = 0, this.apply(), this.recurse(e, t, 0);
|
|
12505
|
+
}
|
|
12506
|
+
decrement(e, t) {
|
|
12507
|
+
return this.second -= t.interval !== void 0 && t.interval > 1 ? t.interval : 1, this.ms = 0, this.apply(), this.recurseBackward(e, t, 0, 0);
|
|
12508
|
+
}
|
|
12509
|
+
recurseBackward(e, t, r, n = 0) {
|
|
12510
|
+
if (n > 1e4) return null;
|
|
12511
|
+
if (r === 0 && !e.starYear) {
|
|
12512
|
+
if (this.year >= 0 && this.year < e.year.length && e.year[this.year] === 0) {
|
|
12513
|
+
let a = -1;
|
|
12514
|
+
for (let o = this.year - 1; o >= 0; o--) if (e.year[o] === 1) {
|
|
12515
|
+
a = o;
|
|
12516
|
+
break;
|
|
12517
|
+
}
|
|
12518
|
+
if (a === -1) return null;
|
|
12519
|
+
this.year = a, this.month = 11, this.day = 31, this.hour = 23, this.minute = 59, this.second = 59, this.ms = 0;
|
|
12520
|
+
}
|
|
12521
|
+
if (this.year < 0) return null;
|
|
12522
|
+
}
|
|
12523
|
+
let i = this.findPrevious(t, f[r][0], e, f[r][2]);
|
|
12524
|
+
if (i > 1) {
|
|
12525
|
+
let a = r + 1;
|
|
12526
|
+
for (; a < f.length; ) {
|
|
12527
|
+
let o = f[a][0], h = f[a][2], l = this.getMaxPatternValue(o, e, h);
|
|
12528
|
+
this[o] = l, a++;
|
|
12529
|
+
}
|
|
12530
|
+
if (i === 3) {
|
|
12531
|
+
if (this[f[r][1]]--, r === 0) {
|
|
12532
|
+
let y = this.getLastDayOfMonth(this.year, this.month);
|
|
12533
|
+
this.day > y && (this.day = y);
|
|
12534
|
+
}
|
|
12535
|
+
if (r === 1) if (this.day <= 0) this.day = 1;
|
|
12536
|
+
else {
|
|
12537
|
+
let y = this.year, u = this.month;
|
|
12538
|
+
for (; u < 0; ) u += 12, y--;
|
|
12539
|
+
for (; u > 11; ) u -= 12, y++;
|
|
12540
|
+
let d = u !== 1 ? P[u] : new Date(Date.UTC(y, u + 1, 0)).getUTCDate();
|
|
12541
|
+
this.day > d && (this.day = d);
|
|
12542
|
+
}
|
|
12543
|
+
this.apply();
|
|
12544
|
+
let o = f[r][0], h = f[r][2], l = this.getMaxPatternValue(o, e, h);
|
|
12545
|
+
if (o === "day") {
|
|
12546
|
+
let y = this.getLastDayOfMonth(this.year, this.month);
|
|
12547
|
+
this[o] = Math.min(l, y);
|
|
12548
|
+
} else this[o] = l;
|
|
12549
|
+
if (this.apply(), r === 0) {
|
|
12550
|
+
let y = f[1][2], u = this.getMaxPatternValue("day", e, y), d = this.getLastDayOfMonth(this.year, this.month), c = Math.min(u, d);
|
|
12551
|
+
c !== this.day && (this.day = c, this.hour = this.getMaxPatternValue("hour", e, f[2][2]), this.minute = this.getMaxPatternValue("minute", e, f[3][2]), this.second = this.getMaxPatternValue("second", e, f[4][2]));
|
|
12552
|
+
}
|
|
12553
|
+
if (r === 0 && !e.starYear) {
|
|
12554
|
+
for (; this.year >= 0 && this.year < e.year.length && e.year[this.year] === 0; ) this.year--;
|
|
12555
|
+
if (this.year < 0) return null;
|
|
12556
|
+
}
|
|
12557
|
+
return this.recurseBackward(e, t, 0, n + 1);
|
|
12558
|
+
} else if (this.apply()) return this.recurseBackward(e, t, r - 1, n + 1);
|
|
12559
|
+
}
|
|
12560
|
+
return r += 1, r >= f.length ? this : this.year < 0 ? null : this.recurseBackward(e, t, r, n + 1);
|
|
12561
|
+
}
|
|
12562
|
+
getMaxPatternValue(e, t, r) {
|
|
12563
|
+
if (e === "day" && t.lastDayOfMonth) return this.getLastDayOfMonth(this.year, this.month);
|
|
12564
|
+
if (e === "day" && !t.starDOW) return this.getLastDayOfMonth(this.year, this.month);
|
|
12565
|
+
for (let n = t[e].length - 1; n >= 0; n--) if (t[e][n]) return n - r;
|
|
12566
|
+
return t[e].length - 1 - r;
|
|
12567
|
+
}
|
|
12568
|
+
findPrevious(e, t, r, n) {
|
|
12569
|
+
return this._findMatch(e, t, r, n, -1);
|
|
12570
|
+
}
|
|
12571
|
+
getDate(e) {
|
|
12572
|
+
return e || this.tz === void 0 ? new Date(this.year, this.month, this.day, this.hour, this.minute, this.second, this.ms) : typeof this.tz == "number" ? new Date(Date.UTC(this.year, this.month, this.day, this.hour, this.minute - this.tz, this.second, this.ms)) : k(b(this.year, this.month + 1, this.day, this.hour, this.minute, this.second, this.tz), false);
|
|
12573
|
+
}
|
|
12574
|
+
getTime() {
|
|
12575
|
+
return this.getDate(false).getTime();
|
|
12576
|
+
}
|
|
12577
|
+
match(e, t) {
|
|
12578
|
+
if (!e.starYear && (this.year < 0 || this.year >= e.year.length || e.year[this.year] === 0)) return false;
|
|
12579
|
+
for (let r = 0; r < f.length; r++) {
|
|
12580
|
+
let n = f[r][0], i = f[r][2], a = this[n];
|
|
12581
|
+
if (a + i < 0 || a + i >= e[n].length) return false;
|
|
12582
|
+
let o = e[n][a + i];
|
|
12583
|
+
if (n === "day") {
|
|
12584
|
+
if (!o) {
|
|
12585
|
+
for (let h = 0; h < e.nearestWeekdays.length; h++) if (e.nearestWeekdays[h]) {
|
|
12586
|
+
let l = this.getNearestWeekday(this.year, this.month, h - i);
|
|
12587
|
+
if (l !== -1 && l === a) {
|
|
12588
|
+
o = 1;
|
|
12589
|
+
break;
|
|
12590
|
+
}
|
|
12591
|
+
}
|
|
12592
|
+
}
|
|
12593
|
+
if (e.lastWeekday) {
|
|
12594
|
+
let h = this.getLastWeekday(this.year, this.month);
|
|
12595
|
+
a === h && (o = 1);
|
|
12596
|
+
}
|
|
12597
|
+
if (e.lastDayOfMonth) {
|
|
12598
|
+
let h = this.getLastDayOfMonth(this.year, this.month);
|
|
12599
|
+
a === h && (o = 1);
|
|
12600
|
+
}
|
|
12601
|
+
if (!e.starDOW) {
|
|
12602
|
+
let h = new Date(Date.UTC(this.year, this.month, 1, 0, 0, 0, 0)).getUTCDay(), l = e.dayOfWeek[(h + (a - 1)) % 7];
|
|
12603
|
+
l && l & 63 && (l = this.isNthWeekdayOfMonth(this.year, this.month, a, l) ? 1 : 0), e.useAndLogic ? o = o && l : !t.domAndDow && !e.starDOM ? o = o || l : o = o && l;
|
|
12604
|
+
}
|
|
12605
|
+
}
|
|
12606
|
+
if (!o) return false;
|
|
12607
|
+
}
|
|
12608
|
+
return true;
|
|
12609
|
+
}
|
|
12610
|
+
};
|
|
12611
|
+
function R(s2) {
|
|
12612
|
+
if (s2 === void 0 && (s2 = {}), delete s2.name, s2.legacyMode !== void 0 && s2.domAndDow === void 0 ? s2.domAndDow = !s2.legacyMode : s2.domAndDow === void 0 && (s2.domAndDow = false), s2.legacyMode = !s2.domAndDow, s2.paused = s2.paused === void 0 ? false : s2.paused, s2.maxRuns = s2.maxRuns === void 0 ? 1 / 0 : s2.maxRuns, s2.catch = s2.catch === void 0 ? false : s2.catch, s2.interval = s2.interval === void 0 ? 0 : parseInt(s2.interval.toString(), 10), s2.utcOffset = s2.utcOffset === void 0 ? void 0 : parseInt(s2.utcOffset.toString(), 10), s2.dayOffset = s2.dayOffset === void 0 ? 0 : parseInt(s2.dayOffset.toString(), 10), s2.unref = s2.unref === void 0 ? false : s2.unref, s2.mode = s2.mode === void 0 ? "auto" : s2.mode, s2.alternativeWeekdays = s2.alternativeWeekdays === void 0 ? false : s2.alternativeWeekdays, s2.sloppyRanges = s2.sloppyRanges === void 0 ? false : s2.sloppyRanges, !["auto", "5-part", "6-part", "7-part", "5-or-6-parts", "6-or-7-parts"].includes(s2.mode)) throw new Error("CronOptions: mode must be one of 'auto', '5-part', '6-part', '7-part', '5-or-6-parts', or '6-or-7-parts'.");
|
|
12613
|
+
if (s2.startAt && (s2.startAt = new m(s2.startAt, s2.timezone)), s2.stopAt && (s2.stopAt = new m(s2.stopAt, s2.timezone)), s2.interval !== null) {
|
|
12614
|
+
if (isNaN(s2.interval)) throw new Error("CronOptions: Supplied value for interval is not a number");
|
|
12615
|
+
if (s2.interval < 0) throw new Error("CronOptions: Supplied value for interval can not be negative");
|
|
12616
|
+
}
|
|
12617
|
+
if (s2.utcOffset !== void 0) {
|
|
12618
|
+
if (isNaN(s2.utcOffset)) throw new Error("CronOptions: Invalid value passed for utcOffset, should be number representing minutes offset from UTC.");
|
|
12619
|
+
if (s2.utcOffset < -870 || s2.utcOffset > 870) throw new Error("CronOptions: utcOffset out of bounds.");
|
|
12620
|
+
if (s2.utcOffset !== void 0 && s2.timezone) throw new Error("CronOptions: Combining 'utcOffset' with 'timezone' is not allowed.");
|
|
12621
|
+
}
|
|
12622
|
+
if (s2.unref !== true && s2.unref !== false) throw new Error("CronOptions: Unref should be either true, false or undefined(false).");
|
|
12623
|
+
if (s2.dayOffset !== void 0 && s2.dayOffset !== 0 && isNaN(s2.dayOffset)) throw new Error("CronOptions: Invalid value passed for dayOffset, should be a number representing days to offset.");
|
|
12624
|
+
return s2;
|
|
12625
|
+
}
|
|
12626
|
+
function p(s2) {
|
|
12627
|
+
return Object.prototype.toString.call(s2) === "[object Function]" || typeof s2 == "function" || s2 instanceof Function;
|
|
12628
|
+
}
|
|
12629
|
+
function _(s2) {
|
|
12630
|
+
return p(s2);
|
|
12631
|
+
}
|
|
12632
|
+
function x(s2) {
|
|
12633
|
+
typeof Deno < "u" && typeof Deno.unrefTimer < "u" ? Deno.unrefTimer(s2) : s2 && typeof s2.unref < "u" && s2.unref();
|
|
12634
|
+
}
|
|
12635
|
+
var W = 30 * 1e3;
|
|
12636
|
+
var w = [];
|
|
12637
|
+
var E = class {
|
|
12638
|
+
name;
|
|
12639
|
+
options;
|
|
12640
|
+
_states;
|
|
12641
|
+
fn;
|
|
12642
|
+
getTz() {
|
|
12643
|
+
return this.options.timezone || this.options.utcOffset;
|
|
12644
|
+
}
|
|
12645
|
+
applyDayOffset(e) {
|
|
12646
|
+
if (this.options.dayOffset !== void 0 && this.options.dayOffset !== 0) {
|
|
12647
|
+
let t = this.options.dayOffset * 24 * 60 * 60 * 1e3;
|
|
12648
|
+
return new Date(e.getTime() + t);
|
|
12649
|
+
}
|
|
12650
|
+
return e;
|
|
12651
|
+
}
|
|
12652
|
+
constructor(e, t, r) {
|
|
12653
|
+
let n, i;
|
|
12654
|
+
if (p(t)) i = t;
|
|
12655
|
+
else if (typeof t == "object") n = t;
|
|
12656
|
+
else if (t !== void 0) throw new Error("Cron: Invalid argument passed for optionsIn. Should be one of function, or object (options).");
|
|
12657
|
+
if (p(r)) i = r;
|
|
12658
|
+
else if (typeof r == "object") n = r;
|
|
12659
|
+
else if (r !== void 0) throw new Error("Cron: Invalid argument passed for funcIn. Should be one of function, or object (options).");
|
|
12660
|
+
if (this.name = n?.name, this.options = R(n), this._states = { kill: false, blocking: false, previousRun: void 0, currentRun: void 0, once: void 0, currentTimeout: void 0, maxRuns: n ? n.maxRuns : void 0, paused: n ? n.paused : false, pattern: new C("* * * * *", void 0, { mode: "auto" }) }, e && (e instanceof Date || typeof e == "string" && e.indexOf(":") > 0) ? this._states.once = new m(e, this.getTz()) : this._states.pattern = new C(e, this.options.timezone, { mode: this.options.mode, alternativeWeekdays: this.options.alternativeWeekdays, sloppyRanges: this.options.sloppyRanges }), this.name) {
|
|
12661
|
+
if (w.find((o) => o.name === this.name)) throw new Error("Cron: Tried to initialize new named job '" + this.name + "', but name already taken.");
|
|
12662
|
+
w.push(this);
|
|
12663
|
+
}
|
|
12664
|
+
return i !== void 0 && _(i) && (this.fn = i, this.schedule()), this;
|
|
12665
|
+
}
|
|
12666
|
+
nextRun(e) {
|
|
12667
|
+
let t = this._next(e);
|
|
12668
|
+
return t ? this.applyDayOffset(t.getDate(false)) : null;
|
|
12669
|
+
}
|
|
12670
|
+
nextRuns(e, t) {
|
|
12671
|
+
this._states.maxRuns !== void 0 && e > this._states.maxRuns && (e = this._states.maxRuns);
|
|
12672
|
+
let r = t || this._states.currentRun || void 0;
|
|
12673
|
+
return this._enumerateRuns(e, r, "next");
|
|
12674
|
+
}
|
|
12675
|
+
previousRuns(e, t) {
|
|
12676
|
+
return this._enumerateRuns(e, t || void 0, "previous");
|
|
12677
|
+
}
|
|
12678
|
+
_enumerateRuns(e, t, r) {
|
|
12679
|
+
let n = [], i = t ? new m(t, this.getTz()) : null, a = r === "next" ? this._next : this._previous;
|
|
12680
|
+
for (; e--; ) {
|
|
12681
|
+
let o = a.call(this, i);
|
|
12682
|
+
if (!o) break;
|
|
12683
|
+
let h = o.getDate(false);
|
|
12684
|
+
n.push(this.applyDayOffset(h)), i = o;
|
|
12685
|
+
}
|
|
12686
|
+
return n;
|
|
12687
|
+
}
|
|
12688
|
+
match(e) {
|
|
12689
|
+
if (this._states.once) {
|
|
12690
|
+
let r = new m(e, this.getTz());
|
|
12691
|
+
r.ms = 0;
|
|
12692
|
+
let n = new m(this._states.once, this.getTz());
|
|
12693
|
+
return n.ms = 0, r.getTime() === n.getTime();
|
|
12694
|
+
}
|
|
12695
|
+
let t = new m(e, this.getTz());
|
|
12696
|
+
return t.ms = 0, t.match(this._states.pattern, this.options);
|
|
12697
|
+
}
|
|
12698
|
+
getPattern() {
|
|
12699
|
+
if (!this._states.once) return this._states.pattern ? this._states.pattern.pattern : void 0;
|
|
12700
|
+
}
|
|
12701
|
+
getOnce() {
|
|
12702
|
+
return this._states.once ? this._states.once.getDate() : null;
|
|
12703
|
+
}
|
|
12704
|
+
isRunning() {
|
|
12705
|
+
let e = this.nextRun(this._states.currentRun), t = !this._states.paused, r = this.fn !== void 0, n = !this._states.kill;
|
|
12706
|
+
return t && r && n && e !== null;
|
|
12707
|
+
}
|
|
12708
|
+
isStopped() {
|
|
12709
|
+
return this._states.kill;
|
|
12710
|
+
}
|
|
12711
|
+
isBusy() {
|
|
12712
|
+
return this._states.blocking;
|
|
12713
|
+
}
|
|
12714
|
+
currentRun() {
|
|
12715
|
+
return this._states.currentRun ? this._states.currentRun.getDate() : null;
|
|
12716
|
+
}
|
|
12717
|
+
previousRun() {
|
|
12718
|
+
return this._states.previousRun ? this._states.previousRun.getDate() : null;
|
|
12719
|
+
}
|
|
12720
|
+
msToNext(e) {
|
|
12721
|
+
let t = this._next(e);
|
|
12722
|
+
return t ? e instanceof m || e instanceof Date ? t.getTime() - e.getTime() : t.getTime() - new m(e).getTime() : null;
|
|
12723
|
+
}
|
|
12724
|
+
stop() {
|
|
12725
|
+
this._states.kill = true, this._states.currentTimeout && clearTimeout(this._states.currentTimeout);
|
|
12726
|
+
let e = w.indexOf(this);
|
|
12727
|
+
e >= 0 && w.splice(e, 1);
|
|
12728
|
+
}
|
|
12729
|
+
pause() {
|
|
12730
|
+
return this._states.paused = true, !this._states.kill;
|
|
12731
|
+
}
|
|
12732
|
+
resume() {
|
|
12733
|
+
return this._states.paused = false, !this._states.kill;
|
|
12734
|
+
}
|
|
12735
|
+
schedule(e) {
|
|
12736
|
+
if (e && this.fn) throw new Error("Cron: It is not allowed to schedule two functions using the same Croner instance.");
|
|
12737
|
+
e && (this.fn = e);
|
|
12738
|
+
let t = this.msToNext(), r = this.nextRun(this._states.currentRun);
|
|
12739
|
+
return t == null || isNaN(t) || r === null ? this : (t > W && (t = W), this._states.currentTimeout = setTimeout(() => this._checkTrigger(r), t), this._states.currentTimeout && this.options.unref && x(this._states.currentTimeout), this);
|
|
12740
|
+
}
|
|
12741
|
+
async _trigger(e) {
|
|
12742
|
+
this._states.blocking = true, this._states.currentRun = new m(void 0, this.getTz());
|
|
12743
|
+
try {
|
|
12744
|
+
if (this.options.catch) try {
|
|
12745
|
+
this.fn !== void 0 && await this.fn(this, this.options.context);
|
|
12746
|
+
} catch (t) {
|
|
12747
|
+
if (p(this.options.catch)) try {
|
|
12748
|
+
this.options.catch(t, this);
|
|
12749
|
+
} catch {
|
|
12750
|
+
}
|
|
12751
|
+
}
|
|
12752
|
+
else this.fn !== void 0 && await this.fn(this, this.options.context);
|
|
12753
|
+
} finally {
|
|
12754
|
+
this._states.previousRun = new m(e, this.getTz()), this._states.blocking = false;
|
|
12755
|
+
}
|
|
12756
|
+
}
|
|
12757
|
+
async trigger() {
|
|
12758
|
+
await this._trigger();
|
|
12759
|
+
}
|
|
12760
|
+
runsLeft() {
|
|
12761
|
+
return this._states.maxRuns;
|
|
12762
|
+
}
|
|
12763
|
+
_checkTrigger(e) {
|
|
12764
|
+
let t = /* @__PURE__ */ new Date(), r = !this._states.paused && t.getTime() >= e.getTime(), n = this._states.blocking && this.options.protect;
|
|
12765
|
+
r && !n ? (this._states.maxRuns !== void 0 && this._states.maxRuns--, this._trigger()) : r && n && p(this.options.protect) && setTimeout(() => this.options.protect(this), 0), this.schedule();
|
|
12766
|
+
}
|
|
12767
|
+
_next(e) {
|
|
12768
|
+
let t = !!(e || this._states.currentRun), r = false;
|
|
12769
|
+
!e && this.options.startAt && this.options.interval && ([e, t] = this._calculatePreviousRun(e, t), r = !e), e = new m(e, this.getTz()), this.options.startAt && e && e.getTime() < this.options.startAt.getTime() && (e = this.options.startAt);
|
|
12770
|
+
let n = this._states.once || new m(e, this.getTz());
|
|
12771
|
+
return !r && n !== this._states.once && (n = n.increment(this._states.pattern, this.options, t)), this._states.once && this._states.once.getTime() <= e.getTime() || n === null || this._states.maxRuns !== void 0 && this._states.maxRuns <= 0 || this._states.kill || this.options.stopAt && n.getTime() >= this.options.stopAt.getTime() ? null : n;
|
|
12772
|
+
}
|
|
12773
|
+
_previous(e) {
|
|
12774
|
+
let t = new m(e, this.getTz());
|
|
12775
|
+
this.options.stopAt && t.getTime() > this.options.stopAt.getTime() && (t = this.options.stopAt);
|
|
12776
|
+
let r = new m(t, this.getTz());
|
|
12777
|
+
return this._states.once ? this._states.once.getTime() < t.getTime() ? this._states.once : null : (r = r.decrement(this._states.pattern, this.options), r === null || this.options.startAt && r.getTime() < this.options.startAt.getTime() ? null : r);
|
|
12778
|
+
}
|
|
12779
|
+
_calculatePreviousRun(e, t) {
|
|
12780
|
+
let r = new m(void 0, this.getTz()), n = e;
|
|
12781
|
+
if (this.options.startAt.getTime() <= r.getTime()) {
|
|
12782
|
+
n = this.options.startAt;
|
|
12783
|
+
let i = n.getTime() + this.options.interval * 1e3;
|
|
12784
|
+
for (; i <= r.getTime(); ) n = new m(n, this.getTz()).increment(this._states.pattern, this.options, true), i = n.getTime() + this.options.interval * 1e3;
|
|
12785
|
+
t = true;
|
|
12786
|
+
}
|
|
12787
|
+
return n === null && (n = void 0), [n, t];
|
|
12788
|
+
}
|
|
12789
|
+
};
|
|
12790
|
+
|
|
12045
12791
|
// src/core/AnalysisProvider.ts
|
|
12046
12792
|
var AnalysisProvider = class {
|
|
12047
12793
|
constructor(api) {
|
|
@@ -12068,8 +12814,8 @@ var IntervalAnalysisProvider = class extends AnalysisProvider {
|
|
|
12068
12814
|
const pks = await this.api.queryManager.getKeys({});
|
|
12069
12815
|
const total = pks.length;
|
|
12070
12816
|
if (total === 0) return [];
|
|
12071
|
-
const
|
|
12072
|
-
const sampleCount = Math.min(Math.max(
|
|
12817
|
+
const k2 = "rate" in sampleOptions && sampleOptions.rate != null ? Math.ceil(total * Math.min(Math.max(sampleOptions.rate, 0), 1)) : sampleOptions.count;
|
|
12818
|
+
const sampleCount = Math.min(Math.max(k2, 0), total);
|
|
12073
12819
|
if (sampleCount === 0) return [];
|
|
12074
12820
|
for (let i = 0; i < sampleCount; i++) {
|
|
12075
12821
|
const j = i + Math.floor(Math.random() * (total - i));
|
|
@@ -12094,7 +12840,7 @@ var FTSTermCount = class extends IntervalAnalysisProvider {
|
|
|
12094
12840
|
termCount = {};
|
|
12095
12841
|
sampleSize = 0;
|
|
12096
12842
|
async serialize(tx) {
|
|
12097
|
-
const docs = await this.sample({ count:
|
|
12843
|
+
const docs = await this.sample({ count: this.api.analysisManager.sampleSize }, tx);
|
|
12098
12844
|
this.termCount = {};
|
|
12099
12845
|
this.sampleSize = docs.length;
|
|
12100
12846
|
if (docs.length === 0) return JSON.stringify({ _sampleSize: 0 });
|
|
@@ -12110,10 +12856,10 @@ var FTSTermCount = class extends IntervalAnalysisProvider {
|
|
|
12110
12856
|
const flatDoc = this.api.flattenDocument(doc);
|
|
12111
12857
|
for (const [indexName, config] of ftsIndices) {
|
|
12112
12858
|
const primaryField = this.api.indexManager.getPrimaryField(config);
|
|
12113
|
-
const
|
|
12114
|
-
if (typeof
|
|
12859
|
+
const v2 = flatDoc[primaryField];
|
|
12860
|
+
if (typeof v2 === "string" && v2.length > 0) {
|
|
12115
12861
|
const ftsConfig = this.api.indexManager.getFtsConfig(config);
|
|
12116
|
-
const tokens = ftsConfig ? tokenize(
|
|
12862
|
+
const tokens = ftsConfig ? tokenize(v2, ftsConfig) : [v2];
|
|
12117
12863
|
const tokenizerStrategy = ftsConfig ? ftsConfig.tokenizer === "ngram" ? `${ftsConfig.gramSize}gram` : ftsConfig.tokenizer : "whitespace";
|
|
12118
12864
|
if (!this.termCount[primaryField]) {
|
|
12119
12865
|
this.termCount[primaryField] = {};
|
|
@@ -12134,7 +12880,7 @@ var FTSTermCount = class extends IntervalAnalysisProvider {
|
|
|
12134
12880
|
optimizedTermCount[field] = {};
|
|
12135
12881
|
for (const strategy in this.termCount[field]) {
|
|
12136
12882
|
const tokenMap = this.termCount[field][strategy];
|
|
12137
|
-
const sorted = Object.entries(tokenMap).sort((a,
|
|
12883
|
+
const sorted = Object.entries(tokenMap).sort((a, b2) => b2[1] - a[1]).slice(0, 1e3);
|
|
12138
12884
|
optimizedTermCount[field][strategy] = {};
|
|
12139
12885
|
for (let i = 0, len = sorted.length; i < len; i++) {
|
|
12140
12886
|
optimizedTermCount[field][strategy][sorted[i][0]] = sorted[i][1];
|
|
@@ -12201,10 +12947,26 @@ var BuiltinAnalysisProviders = [
|
|
|
12201
12947
|
|
|
12202
12948
|
// src/core/AnalysisManager.ts
|
|
12203
12949
|
var AnalysisManager = class {
|
|
12204
|
-
constructor(api) {
|
|
12950
|
+
constructor(api, schedule, sampleSize) {
|
|
12205
12951
|
this.api = api;
|
|
12952
|
+
this.sampleSize = sampleSize;
|
|
12953
|
+
this.cron = new E(schedule, async () => {
|
|
12954
|
+
if (this.flushing) return;
|
|
12955
|
+
await this.api.flushAnalysis();
|
|
12956
|
+
});
|
|
12206
12957
|
}
|
|
12207
12958
|
providers = /* @__PURE__ */ new Map();
|
|
12959
|
+
cron = null;
|
|
12960
|
+
flushing = false;
|
|
12961
|
+
/**
|
|
12962
|
+
* Stop the background analysis cron job.
|
|
12963
|
+
*/
|
|
12964
|
+
close() {
|
|
12965
|
+
if (this.cron && this.cron.isRunning()) {
|
|
12966
|
+
this.cron.stop();
|
|
12967
|
+
this.cron = null;
|
|
12968
|
+
}
|
|
12969
|
+
}
|
|
12208
12970
|
/**
|
|
12209
12971
|
* Register all built-in analysis providers.
|
|
12210
12972
|
* Each provider class is instantiated with the API reference and registered.
|
|
@@ -12255,6 +13017,14 @@ var AnalysisManager = class {
|
|
|
12255
13017
|
}
|
|
12256
13018
|
}
|
|
12257
13019
|
}
|
|
13020
|
+
/**
|
|
13021
|
+
* Trigger the background analysis cron job.
|
|
13022
|
+
*/
|
|
13023
|
+
triggerCron() {
|
|
13024
|
+
if (this.cron && !this.cron.isRunning()) {
|
|
13025
|
+
this.cron.trigger();
|
|
13026
|
+
}
|
|
13027
|
+
}
|
|
12258
13028
|
/**
|
|
12259
13029
|
* Notify all realtime providers that documents were inserted.
|
|
12260
13030
|
* Data is persisted immediately after each provider processes the mutation.
|
|
@@ -12305,11 +13075,16 @@ var AnalysisManager = class {
|
|
|
12305
13075
|
* @param tx The transaction to use (must be a write transaction)
|
|
12306
13076
|
*/
|
|
12307
13077
|
async flush(tx) {
|
|
13078
|
+
if (this.flushing) {
|
|
13079
|
+
throw new Error("Cannot flush analysis while analysis is already flushing.");
|
|
13080
|
+
}
|
|
13081
|
+
this.flushing = true;
|
|
12308
13082
|
for (const [name, provider] of this.providers) {
|
|
12309
13083
|
if (provider instanceof IntervalAnalysisProvider) {
|
|
12310
13084
|
await this.setAnalysisData(name, await provider.serialize(tx), tx);
|
|
12311
13085
|
}
|
|
12312
13086
|
}
|
|
13087
|
+
this.flushing = false;
|
|
12313
13088
|
}
|
|
12314
13089
|
/**
|
|
12315
13090
|
* Get the analysis header row.
|
|
@@ -12442,7 +13217,14 @@ var DocumentDataplyAPI = class extends import_dataply4.DataplyAPI {
|
|
|
12442
13217
|
this.mutationManager = new MutationManager(this);
|
|
12443
13218
|
this.metadataManager = new MetadataManager(this);
|
|
12444
13219
|
this.documentFormatter = new DocumentFormatter();
|
|
12445
|
-
this.analysisManager = new AnalysisManager(
|
|
13220
|
+
this.analysisManager = new AnalysisManager(
|
|
13221
|
+
this,
|
|
13222
|
+
options.analysisSchedule ?? "* */1 * * *",
|
|
13223
|
+
options.analysisSampleSize ?? 1e3
|
|
13224
|
+
);
|
|
13225
|
+
this.hook.onceAfter("close", async () => {
|
|
13226
|
+
this.analysisManager.close();
|
|
13227
|
+
});
|
|
12446
13228
|
this.hook.onceAfter("init", async (tx, isNewlyCreated) => {
|
|
12447
13229
|
if (isNewlyCreated) {
|
|
12448
13230
|
await this.initializeDocumentFile(tx);
|
|
@@ -12454,6 +13236,7 @@ var DocumentDataplyAPI = class extends import_dataply4.DataplyAPI {
|
|
|
12454
13236
|
await this.indexManager.initializeIndices(metadata, isNewlyCreated, tx);
|
|
12455
13237
|
this.analysisManager.registerBuiltinProviders();
|
|
12456
13238
|
await this.analysisManager.initializeProviders(tx);
|
|
13239
|
+
this.analysisManager.triggerCron();
|
|
12457
13240
|
this._initialized = true;
|
|
12458
13241
|
return tx;
|
|
12459
13242
|
});
|