@taphubhq/sdk-core 0.21.0 → 0.22.1
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/index.cjs +5 -23
- package/dist/index.d.mts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +5 -23
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1816,10 +1816,8 @@ var RTT_FAIR_TO_POOR = 450;
|
|
|
1816
1816
|
var RTT_POOR_TO_FAIR = 350;
|
|
1817
1817
|
var JITTER_POOR = 150;
|
|
1818
1818
|
var JITTER_LEAVE_POOR = 120;
|
|
1819
|
-
var
|
|
1820
|
-
var
|
|
1821
|
-
var isPoor = (m) => m.rtt > RTT_FAIR_TO_POOR || m.jitter > JITTER_POOR || m.lossRate > LOSS_POOR;
|
|
1822
|
-
var canLeavePoor = (m) => m.rtt < RTT_POOR_TO_FAIR && m.jitter < JITTER_LEAVE_POOR && m.lossRate < LOSS_LEAVE_POOR;
|
|
1819
|
+
var isPoor = (m) => m.rtt > RTT_FAIR_TO_POOR || m.jitter > JITTER_POOR;
|
|
1820
|
+
var canLeavePoor = (m) => m.rtt < RTT_POOR_TO_FAIR && m.jitter < JITTER_LEAVE_POOR;
|
|
1823
1821
|
var isFairUpper = (rtt) => rtt > RTT_GOOD_TO_FAIR;
|
|
1824
1822
|
var canReachGood = (rtt) => rtt < RTT_FAIR_TO_GOOD;
|
|
1825
1823
|
function classifyNetworkLevel(metrics, current) {
|
|
@@ -1867,10 +1865,7 @@ var RttSmoother = class {
|
|
|
1867
1865
|
this.consecutiveOutliers = 0;
|
|
1868
1866
|
}
|
|
1869
1867
|
this.ema = this.ema === 0 ? rtt : EMA_ALPHA * rtt + (1 - EMA_ALPHA) * this.ema;
|
|
1870
|
-
const next = classifyNetworkLevel(
|
|
1871
|
-
{ rtt, jitter: metrics.jitter, lossRate: metrics.lossRate },
|
|
1872
|
-
this.committed
|
|
1873
|
-
);
|
|
1868
|
+
const next = classifyNetworkLevel({ rtt, jitter: metrics.jitter }, this.committed);
|
|
1874
1869
|
if (next === this.candidate) {
|
|
1875
1870
|
this.candidateCount += 1;
|
|
1876
1871
|
} else {
|
|
@@ -1929,7 +1924,6 @@ var NetworkQualityMonitor = class {
|
|
|
1929
1924
|
smoother = new RttSmoother();
|
|
1930
1925
|
mqttConnected = false;
|
|
1931
1926
|
mqttDisconnectedAt = null;
|
|
1932
|
-
lastSuccessfulHttpAt = null;
|
|
1933
1927
|
committedNetwork = "good";
|
|
1934
1928
|
committedBackend = "ok";
|
|
1935
1929
|
tickHandle = null;
|
|
@@ -1948,9 +1942,6 @@ var NetworkQualityMonitor = class {
|
|
|
1948
1942
|
if (bucket.length > WINDOW_MAX_SAMPLES_PER_SOURCE) {
|
|
1949
1943
|
bucket.shift();
|
|
1950
1944
|
}
|
|
1951
|
-
if (sample.reason === "ok" && sample.source !== "connection" && sample.source !== "browser") {
|
|
1952
|
-
this.lastSuccessfulHttpAt = sample.ts;
|
|
1953
|
-
}
|
|
1954
1945
|
if (sample.source === "mqtt" && sample.reason === "ok") {
|
|
1955
1946
|
this.smoother.add(sample.rtt, this.deriveMetrics());
|
|
1956
1947
|
}
|
|
@@ -2014,7 +2005,6 @@ var NetworkQualityMonitor = class {
|
|
|
2014
2005
|
this.smoother.reset();
|
|
2015
2006
|
this.mqttConnected = false;
|
|
2016
2007
|
this.mqttDisconnectedAt = null;
|
|
2017
|
-
this.lastSuccessfulHttpAt = null;
|
|
2018
2008
|
this.committedNetwork = "good";
|
|
2019
2009
|
this.committedBackend = "ok";
|
|
2020
2010
|
const current = this.snapshot();
|
|
@@ -2086,7 +2076,7 @@ var NetworkQualityMonitor = class {
|
|
|
2086
2076
|
const backend = classifyBackendHealth(httpSamples);
|
|
2087
2077
|
const metrics = this.deriveMetricsFrom(effectiveSamples);
|
|
2088
2078
|
const candidate = classifyNetworkLevel(
|
|
2089
|
-
{ rtt: metrics.emaForLevel, jitter: metrics.jitter
|
|
2079
|
+
{ rtt: metrics.emaForLevel, jitter: metrics.jitter },
|
|
2090
2080
|
this.committedNetwork
|
|
2091
2081
|
);
|
|
2092
2082
|
let nextNetwork = this.smoother.level;
|
|
@@ -2139,15 +2129,7 @@ var NetworkQualityMonitor = class {
|
|
|
2139
2129
|
return true;
|
|
2140
2130
|
}
|
|
2141
2131
|
const now = this.now();
|
|
2142
|
-
|
|
2143
|
-
(s) => s.ts >= now - OFFLINE_HOLD_MS && (s.source === "graphql" || s.source === "rest")
|
|
2144
|
-
);
|
|
2145
|
-
if (recent.length >= 3 && recent.every(
|
|
2146
|
-
(s) => s.reason === "network" || s.reason === "timeout" || s.reason === "offline"
|
|
2147
|
-
)) {
|
|
2148
|
-
return true;
|
|
2149
|
-
}
|
|
2150
|
-
if (this.mqttDisconnectedAt !== null && now - this.mqttDisconnectedAt > OFFLINE_HOLD_MS && (this.lastSuccessfulHttpAt === null || now - this.lastSuccessfulHttpAt > OFFLINE_HOLD_MS)) {
|
|
2132
|
+
if (this.mqttDisconnectedAt !== null && now - this.mqttDisconnectedAt > OFFLINE_HOLD_MS) {
|
|
2151
2133
|
return true;
|
|
2152
2134
|
}
|
|
2153
2135
|
return false;
|
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1751,10 +1751,8 @@ var RTT_FAIR_TO_POOR = 450;
|
|
|
1751
1751
|
var RTT_POOR_TO_FAIR = 350;
|
|
1752
1752
|
var JITTER_POOR = 150;
|
|
1753
1753
|
var JITTER_LEAVE_POOR = 120;
|
|
1754
|
-
var
|
|
1755
|
-
var
|
|
1756
|
-
var isPoor = (m) => m.rtt > RTT_FAIR_TO_POOR || m.jitter > JITTER_POOR || m.lossRate > LOSS_POOR;
|
|
1757
|
-
var canLeavePoor = (m) => m.rtt < RTT_POOR_TO_FAIR && m.jitter < JITTER_LEAVE_POOR && m.lossRate < LOSS_LEAVE_POOR;
|
|
1754
|
+
var isPoor = (m) => m.rtt > RTT_FAIR_TO_POOR || m.jitter > JITTER_POOR;
|
|
1755
|
+
var canLeavePoor = (m) => m.rtt < RTT_POOR_TO_FAIR && m.jitter < JITTER_LEAVE_POOR;
|
|
1758
1756
|
var isFairUpper = (rtt) => rtt > RTT_GOOD_TO_FAIR;
|
|
1759
1757
|
var canReachGood = (rtt) => rtt < RTT_FAIR_TO_GOOD;
|
|
1760
1758
|
function classifyNetworkLevel(metrics, current) {
|
|
@@ -1802,10 +1800,7 @@ var RttSmoother = class {
|
|
|
1802
1800
|
this.consecutiveOutliers = 0;
|
|
1803
1801
|
}
|
|
1804
1802
|
this.ema = this.ema === 0 ? rtt : EMA_ALPHA * rtt + (1 - EMA_ALPHA) * this.ema;
|
|
1805
|
-
const next = classifyNetworkLevel(
|
|
1806
|
-
{ rtt, jitter: metrics.jitter, lossRate: metrics.lossRate },
|
|
1807
|
-
this.committed
|
|
1808
|
-
);
|
|
1803
|
+
const next = classifyNetworkLevel({ rtt, jitter: metrics.jitter }, this.committed);
|
|
1809
1804
|
if (next === this.candidate) {
|
|
1810
1805
|
this.candidateCount += 1;
|
|
1811
1806
|
} else {
|
|
@@ -1864,7 +1859,6 @@ var NetworkQualityMonitor = class {
|
|
|
1864
1859
|
smoother = new RttSmoother();
|
|
1865
1860
|
mqttConnected = false;
|
|
1866
1861
|
mqttDisconnectedAt = null;
|
|
1867
|
-
lastSuccessfulHttpAt = null;
|
|
1868
1862
|
committedNetwork = "good";
|
|
1869
1863
|
committedBackend = "ok";
|
|
1870
1864
|
tickHandle = null;
|
|
@@ -1883,9 +1877,6 @@ var NetworkQualityMonitor = class {
|
|
|
1883
1877
|
if (bucket.length > WINDOW_MAX_SAMPLES_PER_SOURCE) {
|
|
1884
1878
|
bucket.shift();
|
|
1885
1879
|
}
|
|
1886
|
-
if (sample.reason === "ok" && sample.source !== "connection" && sample.source !== "browser") {
|
|
1887
|
-
this.lastSuccessfulHttpAt = sample.ts;
|
|
1888
|
-
}
|
|
1889
1880
|
if (sample.source === "mqtt" && sample.reason === "ok") {
|
|
1890
1881
|
this.smoother.add(sample.rtt, this.deriveMetrics());
|
|
1891
1882
|
}
|
|
@@ -1949,7 +1940,6 @@ var NetworkQualityMonitor = class {
|
|
|
1949
1940
|
this.smoother.reset();
|
|
1950
1941
|
this.mqttConnected = false;
|
|
1951
1942
|
this.mqttDisconnectedAt = null;
|
|
1952
|
-
this.lastSuccessfulHttpAt = null;
|
|
1953
1943
|
this.committedNetwork = "good";
|
|
1954
1944
|
this.committedBackend = "ok";
|
|
1955
1945
|
const current = this.snapshot();
|
|
@@ -2021,7 +2011,7 @@ var NetworkQualityMonitor = class {
|
|
|
2021
2011
|
const backend = classifyBackendHealth(httpSamples);
|
|
2022
2012
|
const metrics = this.deriveMetricsFrom(effectiveSamples);
|
|
2023
2013
|
const candidate = classifyNetworkLevel(
|
|
2024
|
-
{ rtt: metrics.emaForLevel, jitter: metrics.jitter
|
|
2014
|
+
{ rtt: metrics.emaForLevel, jitter: metrics.jitter },
|
|
2025
2015
|
this.committedNetwork
|
|
2026
2016
|
);
|
|
2027
2017
|
let nextNetwork = this.smoother.level;
|
|
@@ -2074,15 +2064,7 @@ var NetworkQualityMonitor = class {
|
|
|
2074
2064
|
return true;
|
|
2075
2065
|
}
|
|
2076
2066
|
const now = this.now();
|
|
2077
|
-
|
|
2078
|
-
(s) => s.ts >= now - OFFLINE_HOLD_MS && (s.source === "graphql" || s.source === "rest")
|
|
2079
|
-
);
|
|
2080
|
-
if (recent.length >= 3 && recent.every(
|
|
2081
|
-
(s) => s.reason === "network" || s.reason === "timeout" || s.reason === "offline"
|
|
2082
|
-
)) {
|
|
2083
|
-
return true;
|
|
2084
|
-
}
|
|
2085
|
-
if (this.mqttDisconnectedAt !== null && now - this.mqttDisconnectedAt > OFFLINE_HOLD_MS && (this.lastSuccessfulHttpAt === null || now - this.lastSuccessfulHttpAt > OFFLINE_HOLD_MS)) {
|
|
2067
|
+
if (this.mqttDisconnectedAt !== null && now - this.mqttDisconnectedAt > OFFLINE_HOLD_MS) {
|
|
2086
2068
|
return true;
|
|
2087
2069
|
}
|
|
2088
2070
|
return false;
|