@formant/data-sdk 1.17.0 → 1.19.0
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/data-sdk.cjs.js +2 -2
- package/dist/data-sdk.cjs.js.map +1 -1
- package/dist/data-sdk.es.js +335 -326
- package/dist/data-sdk.es.js.map +1 -1
- package/dist/data-sdk.es6.js +34 -25
- package/dist/data-sdk.umd.js +2 -2
- package/dist/types/data-sdk/src/cache/StoreCache.d.ts +4 -2
- package/dist/types/data-sdk/src/main.d.ts +1 -0
- package/package.json +1 -1
package/dist/data-sdk.es6.js
CHANGED
|
@@ -851,8 +851,6 @@ function filterDataByTime(e, t, n) {
|
|
|
851
851
|
)
|
|
852
852
|
})).filter(({ points: l }) => l.length > 0);
|
|
853
853
|
}
|
|
854
|
-
function fork(e) {
|
|
855
|
-
}
|
|
856
854
|
class StoreCache {
|
|
857
855
|
constructor({
|
|
858
856
|
capacity: t,
|
|
@@ -861,20 +859,21 @@ class StoreCache {
|
|
|
861
859
|
be(this, "entries", /* @__PURE__ */ new Map());
|
|
862
860
|
be(this, "metadata", /* @__PURE__ */ new Map());
|
|
863
861
|
be(this, "capacity");
|
|
864
|
-
be(this, "
|
|
865
|
-
this.capacity = t || 1e4, this.
|
|
862
|
+
be(this, "staleIntervalMs");
|
|
863
|
+
this.capacity = t || 1e4, this.staleIntervalMs = n || duration.minute;
|
|
866
864
|
}
|
|
867
865
|
get(t, n) {
|
|
868
|
-
const r = this.keyToCacheKey(t)
|
|
869
|
-
return
|
|
866
|
+
const r = this.keyToCacheKey(t);
|
|
867
|
+
return this.isStale(r) && !this.isGenerating(r) && n && this.generate(t, n), this.entries.get(r);
|
|
870
868
|
}
|
|
871
869
|
set(t, n) {
|
|
872
870
|
const r = this.keyToCacheKey(t);
|
|
873
871
|
this.metadata.set(r, {
|
|
874
872
|
generating: !1,
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
873
|
+
staleAt: performance.now() + this.staleIntervalMs
|
|
874
|
+
});
|
|
875
|
+
const o = this.entries.get(r);
|
|
876
|
+
JSON.stringify(o) === JSON.stringify(n) || (this.entries.set(r, n), this.enforceMaxSize());
|
|
878
877
|
}
|
|
879
878
|
clear() {
|
|
880
879
|
this.entries.clear(), [...this.metadata.values()].forEach((t) => t.generating = !1);
|
|
@@ -885,26 +884,34 @@ class StoreCache {
|
|
|
885
884
|
keyToCacheKey(t) {
|
|
886
885
|
return JSON.stringify(t);
|
|
887
886
|
}
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
887
|
+
enforceMaxSize() {
|
|
888
|
+
for (; this.metadata.size > this.capacity && this.metadata.size > 0; ) {
|
|
889
|
+
const [t] = [...this.metadata.entries()].reduce(
|
|
890
|
+
([n, r], [o, l]) => l.staleAt < r.staleAt ? [o, l] : [n, r]
|
|
891
|
+
);
|
|
892
|
+
this.clearKey(t);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
isStale(t) {
|
|
896
|
+
const n = this.metadata.get(t);
|
|
897
|
+
return n ? (n == null ? void 0 : n.staleAt) < performance.now() : !0;
|
|
898
|
+
}
|
|
899
|
+
isGenerating(t) {
|
|
900
|
+
const n = this.metadata.get(t);
|
|
901
|
+
return n ? n.generating : !1;
|
|
895
902
|
}
|
|
896
903
|
generate(t, n) {
|
|
897
|
-
const r = this.keyToCacheKey(t), o = this.metadata.get(r) || {}
|
|
904
|
+
const r = this.keyToCacheKey(t), o = this.metadata.get(r) || {}, l = n().then((u) => {
|
|
905
|
+
const s = this.metadata.get(r);
|
|
906
|
+
return (s == null ? void 0 : s.generating) !== l || this.set(t, u), u;
|
|
907
|
+
}).catch((u) => {
|
|
908
|
+
throw this.metadata.delete(r), u;
|
|
909
|
+
});
|
|
898
910
|
this.metadata.set(r, {
|
|
899
911
|
...o,
|
|
900
|
-
generating:
|
|
901
|
-
|
|
902
|
-
})
|
|
903
|
-
n.then((l) => {
|
|
904
|
-
const u = this.metadata.get(r);
|
|
905
|
-
!(u != null && u.generating) || this.set(t, l);
|
|
906
|
-
});
|
|
907
|
-
}, 0);
|
|
912
|
+
generating: l,
|
|
913
|
+
staleAt: performance.now() + this.staleIntervalMs
|
|
914
|
+
});
|
|
908
915
|
}
|
|
909
916
|
}
|
|
910
917
|
async function queryTelemetry(e) {
|
|
@@ -24961,6 +24968,8 @@ class KeyValue {
|
|
|
24961
24968
|
function stringToArrayBuffer(e) {
|
|
24962
24969
|
return Uint8Array.from(base64Exports.decode(e), (t) => t.charCodeAt(0));
|
|
24963
24970
|
}
|
|
24971
|
+
function fork(e) {
|
|
24972
|
+
}
|
|
24964
24973
|
function browser() {
|
|
24965
24974
|
const { userAgent: e } = navigator;
|
|
24966
24975
|
return e ? e.includes("Firefox/") ? "Firefox" : e.includes("Edg/") ? "Edge" : e.includes("Chrome/") ? "Chrome" : e.includes("Safari/") ? "Safari" : e.includes("MSIE/") || e.includes("Trident/") ? "IE" : "Other" : "Other";
|