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