universe-code 0.0.61 → 0.0.63
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/index.js
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// Export everything as a unified object or individual pieces
|
|
4
|
-
export { idbService };
|
|
5
|
-
|
|
6
|
-
// Default export for easy usage
|
|
7
|
-
export default {
|
|
8
|
-
idbService,
|
|
9
|
-
};
|
|
1
|
+
export { IdbService } from './services/idbService.ts';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { DBManager, DB } from 'universe-code/indexdb';
|
|
3
|
+
|
|
4
|
+
@Injectable({ providedIn: 'root' })
|
|
5
|
+
export class IdbService {
|
|
6
|
+
|
|
7
|
+
private manager = new DBManager('exchange', 1);
|
|
8
|
+
private db: IDBDatabase | null = null;
|
|
9
|
+
private store: any = null;
|
|
10
|
+
private readonly storeName = 'exchangeStore';
|
|
11
|
+
|
|
12
|
+
private async getStore() {
|
|
13
|
+
if (!this.store) {
|
|
14
|
+
if (!this.db) {
|
|
15
|
+
this.db = await this.manager.connect([{ name: this.storeName }]);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
this.store = {
|
|
19
|
+
get: (key: string) =>
|
|
20
|
+
DB.get(this.db!, this.storeName, key),
|
|
21
|
+
|
|
22
|
+
getWithExpiry: (
|
|
23
|
+
key: string,
|
|
24
|
+
ttl: number,
|
|
25
|
+
api: () => Promise<any>
|
|
26
|
+
) =>
|
|
27
|
+
DB.getWithExpiry(this.db!, this.storeName, key, ttl, api),
|
|
28
|
+
|
|
29
|
+
put: (data: any) =>
|
|
30
|
+
DB.put(this.db!, this.storeName, data),
|
|
31
|
+
|
|
32
|
+
remove: (key: string) =>
|
|
33
|
+
DB.remove(this.db!, this.storeName, key),
|
|
34
|
+
|
|
35
|
+
clear: () =>
|
|
36
|
+
DB.clear(this.db!, this.storeName)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return this.store;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async fetchWithCache(
|
|
44
|
+
key: string,
|
|
45
|
+
ttl: number,
|
|
46
|
+
apiFn: () => Promise<any>
|
|
47
|
+
) {
|
|
48
|
+
return (await this.getStore()).getWithExpiry(key, ttl, apiFn);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async get(key: string) {
|
|
52
|
+
return (await this.getStore()).get(key);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async set(data: any) {
|
|
56
|
+
return (await this.getStore()).put(data);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async remove(key: string) {
|
|
60
|
+
return (await this.getStore()).remove(key);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async clear() {
|
|
64
|
+
return (await this.getStore()).clear();
|
|
65
|
+
}
|
|
66
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "universe-code",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.63",
|
|
4
4
|
"description": "Universal utility functions for all JS frameworks",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"type": "module",
|
|
@@ -50,5 +50,10 @@
|
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@angular/core": "^21.0.6",
|
|
52
52
|
"react": "^19.2.3"
|
|
53
|
-
}
|
|
54
|
-
|
|
53
|
+
},
|
|
54
|
+
"keywords": [
|
|
55
|
+
"universe-code",
|
|
56
|
+
"angular-indexdb",
|
|
57
|
+
"react-indexdb"
|
|
58
|
+
]
|
|
59
|
+
}
|
|
@@ -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
|
-
}
|