@har-analyzer/components 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,15 +4,15 @@ import { PropsWithChildren } from 'react';
4
4
  import { SetStateAction } from 'react';
5
5
 
6
6
  declare function HARAnalyzerPreferencesProvider({ store, children }: PropsWithChildren<{
7
- store: UserPreferenceStore;
7
+ store: PreferencesStore;
8
8
  }>): JSX.Element;
9
9
  export default HARAnalyzerPreferencesProvider;
10
10
 
11
- export declare function useHARAnalyzerPreferences<T>(preferenceKey: string, defaultValue: T): readonly [T, Dispatch<SetStateAction<T>>];
12
-
13
- declare interface UserPreferenceStore {
11
+ declare interface PreferencesStore {
14
12
  getPreference: (key: string) => Promise<string | undefined>;
15
13
  setPreference: (key: string, value: string) => Promise<void>;
16
14
  }
17
15
 
16
+ export declare function useHARAnalyzerPreferences<T>(preferenceKey: string, defaultValue: T): readonly [T, Dispatch<SetStateAction<T>>];
17
+
18
18
  export { }
@@ -1,13 +1,6 @@
1
- import { jsx as v } from "react/jsx-runtime";
2
- import { createContext as D, use as E, useState as F, useCallback as h, useEffect as m } from "react";
3
- function x(t, e) {
4
- try {
5
- return JSON.parse(t ?? "");
6
- } catch (r) {
7
- return console.warn("Failed to parse JSON string:", t, "Error:", r), e;
8
- }
9
- }
10
- async function i(t, e) {
1
+ import { jsx as D } from "react/jsx-runtime";
2
+ import { createContext as E, use as F, useMemo as x, useState as A, useCallback as m, useEffect as b } from "react";
3
+ async function c(t, e) {
11
4
  return new Promise((r, n) => {
12
5
  t.addEventListener("success", () => {
13
6
  r(t.result);
@@ -16,82 +9,88 @@ async function i(t, e) {
16
9
  });
17
10
  });
18
11
  }
19
- var y = function(t, e, r, n, o) {
12
+ var S = function(t, e, r, n, a) {
20
13
  if (n === "m") throw new TypeError("Private method is not writable");
21
- if (n === "a" && !o) throw new TypeError("Private accessor was defined without a setter");
22
- if (typeof e == "function" ? t !== e || !o : !e.has(t)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
23
- return n === "a" ? o.call(t, r) : o ? o.value = r : e.set(t, r), r;
24
- }, a = function(t, e, r, n) {
14
+ if (n === "a" && !a) throw new TypeError("Private accessor was defined without a setter");
15
+ if (typeof e == "function" ? t !== e || !a : !e.has(t)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
16
+ return n === "a" ? a.call(t, r) : a ? a.value = r : e.set(t, r), r;
17
+ }, o = function(t, e, r, n) {
25
18
  if (r === "a" && !n) throw new TypeError("Private accessor was defined without a getter");
26
19
  if (typeof e == "function" ? t !== e || !n : !e.has(t)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
27
20
  return r === "m" ? n : r === "a" ? n.call(t) : n ? n.value : e.get(t);
28
- }, s, l, c, d, b, g;
29
- class A {
21
+ }, s, l, i, d, g, _;
22
+ class C {
30
23
  constructor({ name: e }) {
31
- s.add(this), l.set(this, void 0), c.set(this, void 0), y(this, l, e, "f");
24
+ s.add(this), l.set(this, void 0), i.set(this, void 0), S(this, l, e, "f");
32
25
  }
33
26
  async getItem(e) {
34
- const r = await a(this, s, "m", d).call(this);
35
- return i(r.get(e), "Failed to get item");
27
+ const r = await o(this, s, "m", d).call(this);
28
+ return c(r.get(e), "Failed to get item");
36
29
  }
37
30
  async setItem(e, r) {
38
- const n = await a(this, s, "m", d).call(this);
39
- return i(n.put(r, e), "Failed to set item");
31
+ const n = await o(this, s, "m", d).call(this);
32
+ return c(n.put(r, e), "Failed to set item");
40
33
  }
41
34
  async removeItem(e) {
42
- const r = await a(this, s, "m", d).call(this);
43
- return i(r.delete(e), "Failed to remove item");
35
+ const r = await o(this, s, "m", d).call(this);
36
+ return c(r.delete(e), "Failed to remove item");
44
37
  }
45
38
  async clear() {
46
- const e = await a(this, s, "m", d).call(this);
47
- return i(e.clear(), "Failed to clear store");
39
+ const e = await o(this, s, "m", d).call(this);
40
+ return c(e.clear(), "Failed to clear store");
48
41
  }
49
42
  }
50
- l = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), s = /* @__PURE__ */ new WeakSet(), d = async function() {
51
- return (await a(this, s, "m", b).call(this)).transaction("store", "readwrite").objectStore("store");
52
- }, b = async function() {
53
- return a(this, c, "f") === void 0 && y(this, c, a(this, s, "m", g).call(this), "f"), a(this, c, "f");
43
+ l = /* @__PURE__ */ new WeakMap(), i = /* @__PURE__ */ new WeakMap(), s = /* @__PURE__ */ new WeakSet(), d = async function() {
44
+ return (await o(this, s, "m", g).call(this)).transaction("store", "readwrite").objectStore("store");
54
45
  }, g = async function() {
55
- const e = indexedDB.open(a(this, l, "f"), 1);
46
+ return o(this, i, "f") === void 0 && S(this, i, o(this, s, "m", _).call(this), "f"), o(this, i, "f");
47
+ }, _ = async function() {
48
+ const e = indexedDB.open(o(this, l, "f"), 1);
56
49
  return e.addEventListener("upgradeneeded", () => {
57
50
  e.result.createObjectStore("store");
58
- }), i(e, "Failed to open IndexedDB");
51
+ }), c(e, "Failed to open IndexedDB");
59
52
  };
60
- const _ = new A({ name: "node_modules/local-db-storage" }), p = {
61
- get: async (t) => await _.getItem(t),
53
+ const p = new C({ name: "node_modules/local-db-storage" }), y = {
54
+ get: async (t) => await p.getItem(t),
62
55
  set: async (t, e) => {
63
- await _.setItem(t, e);
56
+ await p.setItem(t, e);
57
+ }
58
+ };
59
+ function I(t, e) {
60
+ try {
61
+ return JSON.parse(t ?? "");
62
+ } catch (r) {
63
+ return console.warn("Failed to parse JSON string:", t, "Error:", r), e;
64
64
  }
65
- }, P = D(void 0);
66
- function T({ store: t, children: e }) {
67
- return /* @__PURE__ */ v(P, { value: t, children: e });
68
65
  }
69
- const C = {
70
- getPreference: p.get,
71
- setPreference: p.set
66
+ const P = E(void 0);
67
+ function L({ store: t, children: e }) {
68
+ return /* @__PURE__ */ D(P, { value: t, children: e });
69
+ }
70
+ const O = {
71
+ getPreference: y.get,
72
+ setPreference: y.set
72
73
  };
73
- function z(t, e) {
74
- let r = E(P);
75
- r || (console.warn("Invoked outside of HARAnalyzerPreferencesProvider. Falling back to use fallback preferences store."), r = C);
76
- const [n, o] = F(e), f = h(async () => {
77
- const u = await r.getPreference(t), S = x(u, e);
78
- o(S);
79
- }, [r, t, e]);
80
- m(() => {
81
- f();
82
- }, [f]);
83
- const w = h(async () => {
74
+ function R(t, e) {
75
+ const r = F(P), n = x(() => r || (console.warn("Invoked outside of HARAnalyzerPreferencesProvider. Falling back to use fallback preferences store."), O), [r]), [a, f] = A(e), w = m(async () => {
76
+ const u = await n.getPreference(t), v = I(u, e);
77
+ f(v);
78
+ }, [n, t, e]);
79
+ b(() => {
80
+ w();
81
+ }, [w]);
82
+ const h = m(async () => {
84
83
  try {
85
- await r.setPreference(t, JSON.stringify(n));
84
+ await n.setPreference(t, JSON.stringify(a));
86
85
  } catch (u) {
87
86
  console.error(`Failed to update preference for key ${t}:`, u);
88
87
  }
89
- }, [r, t, n]);
90
- return m(() => {
91
- w();
92
- }, [w]), [n, o];
88
+ }, [n, t, a]);
89
+ return b(() => {
90
+ h();
91
+ }, [h]), [a, f];
93
92
  }
94
93
  export {
95
- T as default,
96
- z as useHARAnalyzerPreferences
94
+ L as default,
95
+ R as useHARAnalyzerPreferences
97
96
  };
package/dist/index.d.ts CHANGED
@@ -20,7 +20,7 @@ export declare function getUniqueHeaderNames(harEntries: HAREntry[], type: 'requ
20
20
  export declare function HARAnalyzer({ logo, appName }: HARAnalyzerProps): JSX.Element;
21
21
 
22
22
  export declare function HARAnalyzerPreferencesProvider({ store, children }: PropsWithChildren<{
23
- store: UserPreferenceStore;
23
+ store: PreferencesStore;
24
24
  }>): JSX.Element;
25
25
 
26
26
  declare interface HARAnalyzerProps {
@@ -64,14 +64,14 @@ declare type HARResponseWithError = HAREntryWithoutError['response'] & {
64
64
 
65
65
  export declare function isErrorResponse(harEntry: HAREntry): boolean;
66
66
 
67
+ declare interface PreferencesStore {
68
+ getPreference: (key: string) => Promise<string | undefined>;
69
+ setPreference: (key: string, value: string) => Promise<void>;
70
+ }
71
+
67
72
  export declare function useHAREntriesFilters(harEntries: HAREntry[]): {
68
73
  filteredHAREntries: HAREntry[];
69
74
  HAREntriesFilters: () => JSX.Element;
70
75
  };
71
76
 
72
- declare interface UserPreferenceStore {
73
- getPreference: (key: string) => Promise<string | undefined>;
74
- setPreference: (key: string, value: string) => Promise<void>;
75
- }
76
-
77
77
  export { }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@har-analyzer/components",
3
3
  "type": "module",
4
- "version": "0.0.9",
4
+ "version": "0.0.10",
5
5
  "description": "Reusable React components for HAR Analyzer",
6
6
  "author": "Allan Joshua",
7
7
  "license": "MIT",