universe-code 0.0.47 → 0.0.49
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,11 +1,13 @@
|
|
|
1
1
|
import { getIdbStore } from './indexdb/store/idbStore.js';
|
|
2
2
|
import { useIdbStore } from './indexdb/hooks/idbHook.js';
|
|
3
|
+
import { configureIdb } from "./indexdb/store/config.js";
|
|
3
4
|
|
|
4
5
|
// Export everything as a unified object or individual pieces
|
|
5
|
-
export { getIdbStore, useIdbStore };
|
|
6
|
+
export { configureIdb, getIdbStore, useIdbStore };
|
|
6
7
|
|
|
7
8
|
// Default export for easy usage
|
|
8
9
|
export default {
|
|
10
|
+
configureIdb,
|
|
9
11
|
getIdbStore,
|
|
10
12
|
useIdbStore,
|
|
11
13
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
let config = null;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configure IndexedDB once at app startup
|
|
5
|
+
* @param {Object} options
|
|
6
|
+
* @param {string} options.DB_NAME
|
|
7
|
+
* @param {number} [options.DB_VERSION]
|
|
8
|
+
* @param {string} options.STORE_NAME
|
|
9
|
+
*/
|
|
10
|
+
export const configureIdb = (options) => {
|
|
11
|
+
if (!options || !options.DB_NAME || !options.STORE_NAME) {
|
|
12
|
+
throw new Error("configureIdb requires dbName and storeName");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
config = options;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const getConfig = () => {
|
|
19
|
+
if (!config) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
"IndexedDB not configured. Call configureIdb() before using the store."
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return config;
|
|
26
|
+
};
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { DBManager, DB } from "universe-code";
|
|
2
|
-
|
|
3
|
-
let DB_NAME = process.env.DB_NAME | null;
|
|
4
|
-
let DB_VERSION = process.env.DB_VERSION | null;
|
|
5
|
-
let STORE_NAME = process.env.STORE_NAME | null;
|
|
2
|
+
import { getConfig } from "./config.js";
|
|
6
3
|
|
|
7
4
|
let db = null;
|
|
8
5
|
let store = null;
|
|
@@ -10,6 +7,8 @@ let manager = null; // ⬅️ IMPORTANT
|
|
|
10
7
|
|
|
11
8
|
// ✅ index db connection
|
|
12
9
|
const connectDB = async () => {
|
|
10
|
+
const { DB_NAME, DB_VERSION } = getConfig();
|
|
11
|
+
|
|
13
12
|
if (!manager) {
|
|
14
13
|
manager = new DBManager(DB_NAME, DB_VERSION);
|
|
15
14
|
}
|
|
@@ -24,6 +23,7 @@ const connectDB = async () => {
|
|
|
24
23
|
export const getIdbStore = async () => {
|
|
25
24
|
if (!store) {
|
|
26
25
|
const database = await connectDB();
|
|
26
|
+
const { STORE_NAME } = getConfig();
|
|
27
27
|
|
|
28
28
|
store = {
|
|
29
29
|
get: (key) => DB.get(database, STORE_NAME, key),
|