universe-code 0.0.47 → 0.0.48

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.
@@ -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),
@@ -36,4 +36,6 @@ export const getIdbStore = async () => {
36
36
  }
37
37
 
38
38
  return store;
39
- };
39
+ };
40
+
41
+ export { configureIdb } from "./config";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "universe-code",
3
- "version": "0.0.47",
3
+ "version": "0.0.48",
4
4
  "description": "Universal utility functions for all JS frameworks",
5
5
  "license": "ISC",
6
6
  "type": "module",