universe-code 0.0.58 → 0.0.59
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/angular/services/idbService.ts +92 -0
- package/dist/core/index.ts +1 -0
- package/dist/core/{time.js → time.ts} +2 -2
- package/dist/index.ts +6 -0
- package/dist/indexdb/{db.js → db.ts} +16 -6
- package/dist/indexdb/{index.js → index.ts} +2 -2
- package/dist/indexdb/store.ts +78 -0
- package/dist/react/{index.js → index.ts} +3 -3
- package/dist/react/indexdb/hooks/{idbHook.js → idbHook.tsx} +1 -1
- package/dist/react/indexdb/store/{config.js → config.tsx} +8 -2
- package/dist/react/indexdb/store/idbStore.tsx +39 -0
- package/package.json +12 -9
- package/dist/angular/services/idbService.js +0 -54
- package/dist/core/index.js +0 -1
- package/dist/index.js +0 -10
- package/dist/indexdb/store.js +0 -55
- package/dist/react/indexdb/store/idbStore.js +0 -39
- /package/dist/angular/{index.js → index.ts} +0 -0
- /package/dist/socket/{index.js → index.ts} +0 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { DBManager, DB } from 'universe-code/indexdb';
|
|
3
|
+
|
|
4
|
+
@Injectable({
|
|
5
|
+
providedIn: 'root'
|
|
6
|
+
})
|
|
7
|
+
export class idbService {
|
|
8
|
+
private manager = new DBManager('exchange', 1);
|
|
9
|
+
private db!: IDBDatabase;
|
|
10
|
+
private store: {
|
|
11
|
+
get: (key: string) => Promise<any>;
|
|
12
|
+
getWithExpiry: (
|
|
13
|
+
key: string,
|
|
14
|
+
ttl: number,
|
|
15
|
+
api: () => Promise<any>
|
|
16
|
+
) => Promise<any>;
|
|
17
|
+
put: (data: any) => Promise<any>;
|
|
18
|
+
remove: (key: string) => Promise<any>;
|
|
19
|
+
clear: () => Promise<any>;
|
|
20
|
+
} | null = null;
|
|
21
|
+
|
|
22
|
+
private readonly storeName = 'exchangeStore';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Initialize DB + Store only once (Singleton)
|
|
26
|
+
*/
|
|
27
|
+
private async getStore() {
|
|
28
|
+
if (!this.store) {
|
|
29
|
+
if (!this.db) {
|
|
30
|
+
this.db = await this.manager.connect([
|
|
31
|
+
{ name: this.storeName }
|
|
32
|
+
]);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
this.store = {
|
|
36
|
+
get: (key: string) =>
|
|
37
|
+
DB.get(this.db, this.storeName, key),
|
|
38
|
+
|
|
39
|
+
getWithExpiry: (
|
|
40
|
+
key: string,
|
|
41
|
+
ttl: number,
|
|
42
|
+
api: () => Promise<any>
|
|
43
|
+
) =>
|
|
44
|
+
DB.getWithExpiry(this.db, this.storeName, key, ttl, api),
|
|
45
|
+
|
|
46
|
+
put: (data: any) =>
|
|
47
|
+
DB.put(this.db, this.storeName, data),
|
|
48
|
+
|
|
49
|
+
remove: (key: string) =>
|
|
50
|
+
DB.remove(this.db, this.storeName, key),
|
|
51
|
+
|
|
52
|
+
clear: () =>
|
|
53
|
+
DB.clear(this.db, this.storeName)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return this.store;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* =======================
|
|
61
|
+
PUBLIC METHODS
|
|
62
|
+
======================= */
|
|
63
|
+
|
|
64
|
+
async fetchWithCache(
|
|
65
|
+
key: string,
|
|
66
|
+
ttl: number,
|
|
67
|
+
apiFn: () => Promise<any>
|
|
68
|
+
) {
|
|
69
|
+
const store = await this.getStore();
|
|
70
|
+
return store.getWithExpiry(key, ttl, apiFn);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async get(key: string) {
|
|
74
|
+
const store = await this.getStore();
|
|
75
|
+
return store.get(key);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async set(data: any) {
|
|
79
|
+
const store = await this.getStore();
|
|
80
|
+
return store.put(data);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async remove(key: string) {
|
|
84
|
+
const store = await this.getStore();
|
|
85
|
+
return store.remove(key);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async clear() {
|
|
89
|
+
const store = await this.getStore();
|
|
90
|
+
return store.clear();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './time.ts';
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* @param {number} minutes
|
|
4
4
|
* @returns {number} milliseconds
|
|
5
5
|
*/
|
|
6
|
-
export const minutesToMs = (minutes) => minutes * 60 * 1000;
|
|
6
|
+
export const minutesToMs = (minutes: any) => minutes * 60 * 1000;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Converts hours to milliseconds
|
|
10
10
|
* @param {number} hours
|
|
11
11
|
* @returns {number} milliseconds
|
|
12
12
|
*/
|
|
13
|
-
export const hoursToMs = (hours) => hours * 60 * 60 * 1000;
|
|
13
|
+
export const hoursToMs = (hours: any) => hours * 60 * 60 * 1000;
|
package/dist/index.ts
ADDED
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
export class DBManager {
|
|
2
|
-
|
|
2
|
+
dbName: any;
|
|
3
|
+
version: any;
|
|
4
|
+
db: any;
|
|
5
|
+
|
|
6
|
+
constructor(dbName: any, version: any = 1) {
|
|
3
7
|
this.dbName = dbName;
|
|
4
8
|
this.version = version;
|
|
5
9
|
this.db = null;
|
|
6
10
|
}
|
|
7
11
|
|
|
8
|
-
async connect(stores = []) {
|
|
12
|
+
async connect(stores: any[] = []): Promise<any> {
|
|
9
13
|
if (this.db) return this.db;
|
|
10
14
|
|
|
11
15
|
return new Promise((resolve, reject) => {
|
|
12
|
-
const request = indexedDB.open(this.dbName, this.version);
|
|
16
|
+
const request: any = indexedDB.open(this.dbName, this.version);
|
|
13
17
|
|
|
14
|
-
request.onupgradeneeded = (e) => {
|
|
18
|
+
request.onupgradeneeded = (e: any) => {
|
|
15
19
|
const db = e.target.result;
|
|
16
|
-
|
|
20
|
+
|
|
21
|
+
stores.forEach((store: any) => {
|
|
22
|
+
const name = store.name;
|
|
23
|
+
const keyPath = store.keyPath || "id";
|
|
24
|
+
const autoIncrement = store.autoIncrement || false;
|
|
25
|
+
|
|
17
26
|
if (!db.objectStoreNames.contains(name)) {
|
|
18
27
|
db.createObjectStore(name, { keyPath, autoIncrement });
|
|
19
28
|
}
|
|
@@ -24,7 +33,8 @@ export class DBManager {
|
|
|
24
33
|
this.db = request.result;
|
|
25
34
|
resolve(this.db);
|
|
26
35
|
};
|
|
36
|
+
|
|
27
37
|
request.onerror = () => reject(request.error);
|
|
28
38
|
});
|
|
29
39
|
}
|
|
30
|
-
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Transaction Wrapper
|
|
3
|
+
*/
|
|
4
|
+
const perform = (
|
|
5
|
+
db: any,
|
|
6
|
+
storeName: any,
|
|
7
|
+
mode: any,
|
|
8
|
+
action: any
|
|
9
|
+
): Promise<any> => {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
const tx: any = db.transaction(storeName, mode);
|
|
12
|
+
const store: any = tx.objectStore(storeName);
|
|
13
|
+
const request: any = action(store);
|
|
14
|
+
|
|
15
|
+
request.onsuccess = () => resolve(request.result);
|
|
16
|
+
request.onerror = () => reject(request.error);
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const DB: any = {
|
|
21
|
+
get: (db: any, store: any, key: any) =>
|
|
22
|
+
perform(db, store, "readonly", (s: any) => s.get(key)),
|
|
23
|
+
|
|
24
|
+
put: (db: any, store: any, data: any) =>
|
|
25
|
+
perform(db, store, "readwrite", (s: any) => s.put(data)),
|
|
26
|
+
|
|
27
|
+
remove: (db: any, store: any, key: any) =>
|
|
28
|
+
perform(db, store, "readwrite", (s: any) => s.delete(key)),
|
|
29
|
+
|
|
30
|
+
clear: (db: any, store: any) =>
|
|
31
|
+
perform(db, store, "readwrite", (s: any) => s.clear()),
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* PRO FEATURE: getWithExpiry
|
|
35
|
+
* Automatically refreshes data from an API if the local version is too old.
|
|
36
|
+
*/
|
|
37
|
+
async getWithExpiry(
|
|
38
|
+
db: any,
|
|
39
|
+
storeName: any,
|
|
40
|
+
key: any,
|
|
41
|
+
ttl: any,
|
|
42
|
+
apiCall: any
|
|
43
|
+
): Promise<any> {
|
|
44
|
+
try {
|
|
45
|
+
const cached: any = await this.get(db, storeName, key);
|
|
46
|
+
const now: any = Date.now();
|
|
47
|
+
|
|
48
|
+
// If valid data exists and is NOT expired, return it
|
|
49
|
+
if (
|
|
50
|
+
cached &&
|
|
51
|
+
cached.timestamp &&
|
|
52
|
+
now - cached.timestamp < ttl
|
|
53
|
+
) {
|
|
54
|
+
return cached.data;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Otherwise, call API
|
|
58
|
+
const freshData: any = await apiCall();
|
|
59
|
+
|
|
60
|
+
// Save to IndexedDB with new timestamp
|
|
61
|
+
await this.put(db, storeName, {
|
|
62
|
+
id: key,
|
|
63
|
+
data: freshData,
|
|
64
|
+
timestamp: now,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return freshData;
|
|
68
|
+
} catch (error: any) {
|
|
69
|
+
console.warn(
|
|
70
|
+
"API/DB Error, returning fallback if available:",
|
|
71
|
+
error
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const fallback: any = await this.get(db, storeName, key);
|
|
75
|
+
return fallback ? fallback.data : null;
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { getIdbStore } from './indexdb/store/idbStore.
|
|
2
|
-
import { useIdbStore } from './indexdb/hooks/idbHook.
|
|
3
|
-
import { configureIdb } from "./indexdb/store/config.
|
|
1
|
+
import { getIdbStore } from './indexdb/store/idbStore.ts';
|
|
2
|
+
import { useIdbStore } from './indexdb/hooks/idbHook.ts';
|
|
3
|
+
import { configureIdb } from "./indexdb/store/config.ts";
|
|
4
4
|
|
|
5
5
|
// Export everything as a unified object or individual pieces
|
|
6
6
|
export { configureIdb, getIdbStore, useIdbStore };
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
let config = null;
|
|
1
|
+
let config: any = null;
|
|
2
2
|
|
|
3
|
-
export const configureIdb = (options) => {
|
|
3
|
+
export const configureIdb = (options: any) => {
|
|
4
4
|
if (config) {
|
|
5
5
|
return;
|
|
6
6
|
}
|
|
7
|
+
|
|
8
|
+
if (!options) {
|
|
9
|
+
throw new Error("configureIdb requires options");
|
|
10
|
+
}
|
|
11
|
+
|
|
7
12
|
config = options;
|
|
8
13
|
};
|
|
9
14
|
|
|
@@ -13,5 +18,6 @@ export const getConfig = () => {
|
|
|
13
18
|
"IndexedDB not configured. Call configureIdb() before using the store."
|
|
14
19
|
);
|
|
15
20
|
}
|
|
21
|
+
|
|
16
22
|
return config;
|
|
17
23
|
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DBManager, DB } from "universe-code";
|
|
2
|
+
import { getConfig } from "./config.ts";
|
|
3
|
+
|
|
4
|
+
let db: any = null;
|
|
5
|
+
let store: any = null;
|
|
6
|
+
let manager: any = null;
|
|
7
|
+
|
|
8
|
+
// ✅ index db connection
|
|
9
|
+
const connectDB = async (): Promise<any> => {
|
|
10
|
+
const { dbName, dbVersion, storeName }: any = getConfig();
|
|
11
|
+
|
|
12
|
+
if (!manager) {
|
|
13
|
+
manager = new DBManager(dbName, dbVersion);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (!db) {
|
|
17
|
+
db = await manager.connect([{ name: storeName }]);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return db;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const getIdbStore = async (): Promise<any> => {
|
|
24
|
+
if (!store) {
|
|
25
|
+
const { storeName }: any = getConfig();
|
|
26
|
+
const database: any = await connectDB();
|
|
27
|
+
|
|
28
|
+
store = {
|
|
29
|
+
get: (key: any) => DB.get(database, storeName, key),
|
|
30
|
+
getWithExpiry: (key: any, ttl: any, api: any) =>
|
|
31
|
+
DB.getWithExpiry(database, storeName, key, ttl, api),
|
|
32
|
+
put: (data: any) => DB.put(database, storeName, data),
|
|
33
|
+
remove: (key: any) => DB.remove(database, storeName, key),
|
|
34
|
+
clear: () => DB.clear(database, storeName),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return store;
|
|
39
|
+
};
|
package/package.json
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "universe-code",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.59",
|
|
4
4
|
"description": "Universal utility functions for all JS frameworks",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"main": "./dist/index.
|
|
8
|
-
"module": "./dist/index.
|
|
7
|
+
"main": "./dist/index.ts",
|
|
8
|
+
"module": "./dist/index.ts",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
-
"import": "./dist/indexdb/index.
|
|
12
|
+
"import": "./dist/indexdb/index.ts",
|
|
13
13
|
"types": "./dist/index.d.ts"
|
|
14
14
|
},
|
|
15
15
|
"./react": {
|
|
16
|
-
"import": "./dist/react/index.
|
|
16
|
+
"import": "./dist/react/index.ts",
|
|
17
17
|
"types": "./dist/index.d.ts"
|
|
18
18
|
},
|
|
19
19
|
"./angular": {
|
|
20
|
-
"import": "./dist/angular/index.
|
|
20
|
+
"import": "./dist/angular/index.ts",
|
|
21
21
|
"types": "./dist/index.d.ts"
|
|
22
22
|
},
|
|
23
23
|
"./indexdb": {
|
|
24
|
-
"import": "./dist/indexdb/index.
|
|
24
|
+
"import": "./dist/indexdb/index.ts",
|
|
25
25
|
"types": "./dist/index.d.ts"
|
|
26
26
|
},
|
|
27
27
|
"./socket": {
|
|
28
|
-
"import": "./dist/socket/index.
|
|
28
|
+
"import": "./dist/socket/index.ts",
|
|
29
29
|
"types": "./dist/index.d.ts"
|
|
30
30
|
},
|
|
31
31
|
"./core": {
|
|
32
|
-
"import": "./dist/core/index.
|
|
32
|
+
"import": "./dist/core/index.ts",
|
|
33
33
|
"types": "./dist/index.d.ts"
|
|
34
34
|
}
|
|
35
35
|
},
|
|
@@ -50,5 +50,8 @@
|
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@angular/core": "^21.0.6",
|
|
52
52
|
"react": "^19.2.3"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/react": "^19.2.7"
|
|
53
56
|
}
|
|
54
57
|
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@angular/core';
|
|
2
|
-
import { DBManager, DB } from 'universe-code/indexdb';
|
|
3
|
-
|
|
4
|
-
@Injectable({
|
|
5
|
-
providedIn: 'root'
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
export class idbService {
|
|
9
|
-
constructor() {
|
|
10
|
-
this.manager = new DBManager('exchange', 1);
|
|
11
|
-
this.db = null;
|
|
12
|
-
this.storeName = 'exchangeStore';
|
|
13
|
-
this.store = null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async getStore() {
|
|
17
|
-
if (!this.store) {
|
|
18
|
-
if (!this.db) {
|
|
19
|
-
this.db = await this.manager.connect([{ name: this.storeName }]);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
this.store = {
|
|
23
|
-
get: (key) => DB.get(this.db, this.storeName, key),
|
|
24
|
-
getWithExpiry: (key, ttl, api) =>
|
|
25
|
-
DB.getWithExpiry(this.db, this.storeName, key, ttl, api),
|
|
26
|
-
put: (data) => DB.put(this.db, this.storeName, data),
|
|
27
|
-
remove: (key) => DB.remove(this.db, this.storeName, key),
|
|
28
|
-
clear: () => DB.clear(this.db, this.storeName)
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
return this.store;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async fetchWithCache(key, ttl, apiFn) {
|
|
35
|
-
const store = await this.getStore();
|
|
36
|
-
return store.getWithExpiry(key, ttl, apiFn);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async get(key) {
|
|
40
|
-
return (await this.getStore()).get(key);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async set(data) {
|
|
44
|
-
return (await this.getStore()).put(data);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async remove(key) {
|
|
48
|
-
return (await this.getStore()).remove(key);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async clear() {
|
|
52
|
-
return (await this.getStore()).clear();
|
|
53
|
-
}
|
|
54
|
-
}
|
package/dist/core/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './time.js';
|
package/dist/index.js
DELETED
package/dist/indexdb/store.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic Transaction Wrapper
|
|
3
|
-
*/
|
|
4
|
-
const perform = (db, storeName, mode, action) => {
|
|
5
|
-
return new Promise((resolve, reject) => {
|
|
6
|
-
const tx = db.transaction(storeName, mode);
|
|
7
|
-
const store = tx.objectStore(storeName);
|
|
8
|
-
const request = action(store);
|
|
9
|
-
|
|
10
|
-
request.onsuccess = () => resolve(request.result);
|
|
11
|
-
request.onerror = () => reject(request.error);
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const DB = {
|
|
16
|
-
get: (db, store, key) => perform(db, store, "readonly", s => s.get(key)),
|
|
17
|
-
|
|
18
|
-
put: (db, store, data) => perform(db, store, "readwrite", s => s.put(data)),
|
|
19
|
-
|
|
20
|
-
remove: (db, store, key) => perform(db, store, "readwrite", s => s.delete(key)),
|
|
21
|
-
|
|
22
|
-
clear: (db, store) => perform(db, store, "readwrite", s => s.clear()),
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* PRO FEATURE: getWithExpiry
|
|
26
|
-
* Automatically refreshes data from an API if the local version is too old.
|
|
27
|
-
*/
|
|
28
|
-
async getWithExpiry(db, storeName, key, ttl, apiCall) {
|
|
29
|
-
try {
|
|
30
|
-
const cached = await this.get(db, storeName, key);
|
|
31
|
-
const now = Date.now();
|
|
32
|
-
|
|
33
|
-
// If valid data exists and is NOT expired, return it
|
|
34
|
-
if (cached && cached.timestamp && (now - cached.timestamp < ttl)) {
|
|
35
|
-
return cached.data;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Otherwise, call API
|
|
39
|
-
const freshData = await apiCall();
|
|
40
|
-
|
|
41
|
-
// Save to IndexedDB with new timestamp
|
|
42
|
-
await this.put(db, storeName, {
|
|
43
|
-
id: key,
|
|
44
|
-
data: freshData,
|
|
45
|
-
timestamp: now
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
return freshData;
|
|
49
|
-
} catch (error) {
|
|
50
|
-
console.warn("API/DB Error, returning fallback if available:", error);
|
|
51
|
-
const fallback = await this.get(db, storeName, key);
|
|
52
|
-
return fallback ? fallback.data : null;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { DBManager, DB } from "universe-code";
|
|
2
|
-
import { getConfig } from "./config.js";
|
|
3
|
-
|
|
4
|
-
let db = null;
|
|
5
|
-
let store = null;
|
|
6
|
-
let manager = null;
|
|
7
|
-
|
|
8
|
-
// ✅ index db connection
|
|
9
|
-
const connectDB = async () => {
|
|
10
|
-
const { dbName, dbVersion, storeName } = getConfig(); // ✅ FIXED
|
|
11
|
-
|
|
12
|
-
if (!manager) {
|
|
13
|
-
manager = new DBManager(dbName, dbVersion);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (!db) {
|
|
17
|
-
db = await manager.connect([{ name: storeName }]); // ✅ FIXED
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return db;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const getIdbStore = async () => {
|
|
24
|
-
if (!store) {
|
|
25
|
-
const { storeName } = getConfig(); // ✅ FIXED
|
|
26
|
-
const database = await connectDB();
|
|
27
|
-
|
|
28
|
-
store = {
|
|
29
|
-
get: (key) => DB.get(database, storeName, key),
|
|
30
|
-
getWithExpiry: (key, ttl, api) =>
|
|
31
|
-
DB.getWithExpiry(database, storeName, key, ttl, api),
|
|
32
|
-
put: (data) => DB.put(database, storeName, data),
|
|
33
|
-
remove: (key) => DB.remove(database, storeName, key),
|
|
34
|
-
clear: () => DB.clear(database, storeName),
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return store;
|
|
39
|
-
};
|
|
File without changes
|
|
File without changes
|