universe-code 0.0.45 → 0.0.46
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/react/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { getIdbStore
|
|
1
|
+
import { getIdbStore } from './indexdb/store/idbStore.js';
|
|
2
2
|
import { useIdbStore } from './indexdb/hooks/idbHook.js';
|
|
3
3
|
|
|
4
4
|
// Export everything as a unified object or individual pieces
|
|
5
|
-
export { getIdbStore, useIdbStore
|
|
5
|
+
export { getIdbStore, useIdbStore };
|
|
6
6
|
|
|
7
7
|
// Default export for easy usage
|
|
8
8
|
export default {
|
|
9
|
-
setDBConfig,
|
|
10
9
|
getIdbStore,
|
|
11
10
|
useIdbStore,
|
|
12
11
|
};
|
|
@@ -1,65 +1,15 @@
|
|
|
1
1
|
import { DBManager, DB } from "universe-code";
|
|
2
2
|
|
|
3
|
-
let DB_NAME = null;
|
|
4
|
-
let DB_VERSION = null;
|
|
5
|
-
let STORE_NAME = null;
|
|
3
|
+
let DB_NAME = process.env.DB_NAME | null;
|
|
4
|
+
let DB_VERSION = process.env.DB_NAME | null;
|
|
5
|
+
let STORE_NAME = process.env.DB_NAME | null;
|
|
6
6
|
|
|
7
7
|
let db = null;
|
|
8
8
|
let store = null;
|
|
9
9
|
let manager = null; // ⬅️ IMPORTANT
|
|
10
10
|
|
|
11
|
-
// ✅ set index db config from outside
|
|
12
|
-
export const setDBConfig = async ({
|
|
13
|
-
dbName,
|
|
14
|
-
storeName,
|
|
15
|
-
version,
|
|
16
|
-
}) => {
|
|
17
|
-
|
|
18
|
-
if (!dbName) {
|
|
19
|
-
throw new Error("index db name is missing");
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (!storeName) {
|
|
23
|
-
throw new Error("index db store name is missing");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (!version) {
|
|
27
|
-
throw new Error("index db version is missing");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (db || store) {
|
|
31
|
-
throw new Error("DB already initialized");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (dbName) DB_NAME = dbName;
|
|
35
|
-
if (storeName) STORE_NAME = storeName;
|
|
36
|
-
if (version) DB_VERSION = version;
|
|
37
|
-
|
|
38
|
-
await DB.put(dbName, storeName, {
|
|
39
|
-
id: 'config',
|
|
40
|
-
data: {
|
|
41
|
-
DB_NAME: dbName,
|
|
42
|
-
STORE_NAME: storeName,
|
|
43
|
-
DB_VERSION: version
|
|
44
|
-
},
|
|
45
|
-
timestamp: now
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
|
|
49
11
|
// ✅ index db connection
|
|
50
12
|
const connectDB = async () => {
|
|
51
|
-
if (!DB_NAME) {
|
|
52
|
-
throw new Error("index db name is missing");
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (!STORE_NAME) {
|
|
56
|
-
throw new Error("index db store name is missing");
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (!DB_VERSION) {
|
|
60
|
-
throw new Error("index db version is missing");
|
|
61
|
-
}
|
|
62
|
-
|
|
63
13
|
if (!manager) {
|
|
64
14
|
manager = new DBManager(DB_NAME, DB_VERSION);
|
|
65
15
|
}
|