universe-code 0.0.29 → 0.0.31

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.
@@ -1,20 +1,20 @@
1
+ import { useEffect, useState } from 'react';
1
2
  import { getIdbStore } from '../store/idbStore';
2
3
 
3
- let promise: Promise<any> | null = null;
4
- let store: any = null;
4
+ export const useIdbStore = () => {
5
+ const [store, setStore] = useState(null); // ✅ no type argument needed
5
6
 
6
- export const idbHook = {
7
- read() {
8
- if (store) return store;
7
+ useEffect(() => {
8
+ let mounted = true;
9
9
 
10
- if (!promise) {
11
- promise = getIdbStore().then(s => {
12
- store = s;
13
- return s;
14
- });
15
- }
10
+ getIdbStore().then(s => {
11
+ if (mounted) setStore(s);
12
+ });
16
13
 
17
- // 🚨 Suspense magic
18
- throw promise;
19
- }
14
+ return () => {
15
+ mounted = false;
16
+ };
17
+ }, []);
18
+
19
+ return store;
20
20
  };
@@ -1,5 +1,5 @@
1
- import useIdbStore from "./wrapper/useIdbStore";
2
- import getIdbStore from "./store/idbStore";
1
+ import { useIdbStore } from "./wrapper/useIdbStore";
2
+ import { getIdbStore } from "./store/idbStore";
3
3
 
4
4
  export { getIdbStore, useIdbStore };
5
5
  export default { getIdbStore, useIdbStore };
@@ -1,4 +1,4 @@
1
- import { DBManager, DB } from "./../../index";
1
+ import { DBManager, DB } from "universe-code/indexdb";
2
2
 
3
3
  const DB_NAME = "exchange";
4
4
  const DB_VERSION = 1;
@@ -6,43 +6,43 @@ const STORE_NAME = "exchangeStore";
6
6
 
7
7
  let db: IDBDatabase | null = null;
8
8
  let store: {
9
- get: (key: string) => Promise<any>;
10
- getWithExpiry: (
11
- key: string,
12
- ttl: number,
13
- api: () => Promise<any>
14
- ) => Promise<any>;
15
- put: (data: any) => Promise<any>;
16
- remove: (key: string) => Promise<any>;
17
- clear: () => Promise<any>;
9
+ get: (key: string) => Promise<any>;
10
+ getWithExpiry: (
11
+ key: string,
12
+ ttl: number,
13
+ api: () => Promise<any>
14
+ ) => Promise<any>;
15
+ put: (data: any) => Promise<any>;
16
+ remove: (key: string) => Promise<any>;
17
+ clear: () => Promise<any>;
18
18
  } | null = null;
19
19
 
20
20
  const manager = new DBManager(DB_NAME, DB_VERSION);
21
21
 
22
22
  const connectDB = async () => {
23
- if (!db) {
24
- db = await manager.connect([{ name: STORE_NAME }]);
25
- }
26
- return db;
23
+ if (!db) {
24
+ db = await manager.connect([{ name: STORE_NAME }]);
25
+ }
26
+ return db;
27
27
  };
28
28
 
29
29
  export const getIdbStore = async () => {
30
- if (!store) {
31
- const database = await connectDB();
30
+ if (!store) {
31
+ const database = await connectDB();
32
32
 
33
- store = {
34
- get: (key: string) => DB.get(database, STORE_NAME, key),
33
+ store = {
34
+ get: (key: string) => DB.get(database, STORE_NAME, key),
35
35
 
36
- getWithExpiry: (key: string, ttl: number, api: () => Promise<any>) =>
37
- DB.getWithExpiry(database, STORE_NAME, key, ttl, api),
36
+ getWithExpiry: (key: string, ttl: number, api: () => Promise<any>) =>
37
+ DB.getWithExpiry(database, STORE_NAME, key, ttl, api),
38
38
 
39
- put: (data: any) => DB.put(database, STORE_NAME, data),
39
+ put: (data: any) => DB.put(database, STORE_NAME, data),
40
40
 
41
- remove: (key: string) => DB.remove(database, STORE_NAME, key),
41
+ remove: (key: string) => DB.remove(database, STORE_NAME, key),
42
42
 
43
- clear: () => DB.clear(database, STORE_NAME),
44
- };
45
- }
43
+ clear: () => DB.clear(database, STORE_NAME),
44
+ };
45
+ }
46
46
 
47
- return store;
47
+ return store;
48
48
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "universe-code",
3
- "version": "0.0.29",
3
+ "version": "0.0.31",
4
4
  "description": "Universal utility functions for all JS frameworks",
5
5
  "license": "ISC",
6
6
  "type": "module",
@@ -42,5 +42,8 @@
42
42
  "homepage": "https://github.com/connectwithfalco/universe-code#readme",
43
43
  "scripts": {
44
44
  "test": "echo \"No tests yet\""
45
+ },
46
+ "dependencies": {
47
+ "react": "^19.2.3"
45
48
  }
46
- }
49
+ }
@@ -1,5 +0,0 @@
1
- import { idbHook } from './../hooks/idbHook';
2
-
3
- export const useIdbStore = () => {
4
- return idbHook.read();
5
- };