@gudhub/core 1.2.2 → 1.2.4-beta.0
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/.vscode/launch.json +31 -0
- package/GUDHUB/AppProcessor/AppProcessor.js +2 -6
- package/GUDHUB/DataService/IndexedDB/IndexedDBAppService.js +40 -24
- package/GUDHUB/DataService/IndexedDB/IndexedDBChunkService.js +46 -28
- package/GUDHUB/DataService/IndexedDB/IndexedDBService.js +2 -0
- package/GUDHUB/api/AppApi.js +1 -1
- package/package.json +1 -1
- package/umd/library.min.js +69 -53
- package/umd/library.min.js.map +1 -1
- package/GUDHUB/ChunksManager/ChunkApi.js +0 -19
- package/GUDHUB/ChunksManager/DataService/IndexedDBCacheService.js +0 -101
- package/GUDHUB/ChunksManager/DataService/export.js +0 -13
- package/GUDHUB/ChunksManager/DataService/httpDataService.js +0 -21
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export class ChunkAPI {
|
|
2
|
-
constructor(req) {
|
|
3
|
-
this.req = req;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
async getChunk(app_id, chunk_id) {
|
|
7
|
-
return this.req.get({
|
|
8
|
-
url: `${this.req.root}/api/get-items-chunk/${app_id}/${chunk_id}`,
|
|
9
|
-
method: 'GET'
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async getLastChunk(app_id) {
|
|
14
|
-
return this.req.axiosRequest({
|
|
15
|
-
url: `${this.req.root}/api/get-last-items-chunk/${app_id}`,
|
|
16
|
-
method: 'GET'
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { ChunkDataService, HttpDataService } from "./httpDataService.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
//this should be global in project
|
|
5
|
-
// class IndexedDBFacade extends CacheService {
|
|
6
|
-
|
|
7
|
-
// }
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class ChunkCachedDataService extends ChunkDataService {
|
|
12
|
-
dataService;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export class IndexedDBChunkCacheService extends ChunkCachedDataService {
|
|
17
|
-
constructor(req) {
|
|
18
|
-
super();
|
|
19
|
-
|
|
20
|
-
this.dataService = new HttpDataService(req);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
OBJECT_STORE = "chunks";
|
|
25
|
-
DatabaseName = "gudhubapi-data";
|
|
26
|
-
DatabaseVersion = 1;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
//TODO use IndexedDBFacade here
|
|
30
|
-
// indexDBAccess = new IndexedDBFacade;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
async putChunk(id, data) {
|
|
34
|
-
try {
|
|
35
|
-
const db = await this.openDatabase();
|
|
36
|
-
|
|
37
|
-
const transaction = db.transaction(this.OBJECT_STORE, "readwrite");
|
|
38
|
-
const store = transaction.objectStore(this.OBJECT_STORE);
|
|
39
|
-
|
|
40
|
-
store.put(data, id);
|
|
41
|
-
} catch (error) {
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
async getChunk(app_id, id) {
|
|
48
|
-
try {
|
|
49
|
-
const db = await this.openDatabase();
|
|
50
|
-
const transaction = db.transaction(this.OBJECT_STORE, "readonly");
|
|
51
|
-
const store = transaction.objectStore(this.OBJECT_STORE);
|
|
52
|
-
|
|
53
|
-
const storeRequest = store.get(id);
|
|
54
|
-
|
|
55
|
-
return await new Promise((resolve, reject) => {
|
|
56
|
-
storeRequest.onsuccess = (e) => {
|
|
57
|
-
|
|
58
|
-
let cachedData = e.target.result;
|
|
59
|
-
|
|
60
|
-
if (
|
|
61
|
-
!cachedData
|
|
62
|
-
) {
|
|
63
|
-
reject();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
cachedData
|
|
68
|
-
) {
|
|
69
|
-
|
|
70
|
-
resolve(cachedData);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
storeRequest.onerror = reject
|
|
75
|
-
});
|
|
76
|
-
} catch(e) {
|
|
77
|
-
let res = await this.dataService.getChunk(app_id, id);
|
|
78
|
-
|
|
79
|
-
await this.putChunk(id, res);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return res;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async openDatabase() {
|
|
87
|
-
return new Promise((resolve, reject) => {
|
|
88
|
-
const request = indexedDB.open(this.DatabaseName, this.DatabaseVersion);
|
|
89
|
-
request.onupgradeneeded = event => {
|
|
90
|
-
const db = event.target.result;
|
|
91
|
-
db.createObjectStore(this.OBJECT_STORE);
|
|
92
|
-
};
|
|
93
|
-
request.onsuccess = event => {
|
|
94
|
-
resolve(event.target.result);
|
|
95
|
-
};
|
|
96
|
-
request.onerror = event => {
|
|
97
|
-
reject(event.target.error);
|
|
98
|
-
};
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { IS_WEB } from "../../consts.js";
|
|
2
|
-
import { IndexedDBChunkCacheService } from "./IndexedDBCacheService.js";
|
|
3
|
-
import { HttpDataService } from "./httpDataService.js";
|
|
4
|
-
|
|
5
|
-
let exportClass;
|
|
6
|
-
|
|
7
|
-
if (IS_WEB) {
|
|
8
|
-
exportClass = IndexedDBChunkCacheService
|
|
9
|
-
} else {
|
|
10
|
-
exportClass = HttpDataService
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export { exportClass as DataService };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ChunkAPI } from "../ChunkApi.js";
|
|
2
|
-
|
|
3
|
-
export class ChunkDataService {}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export class HttpDataService extends ChunkDataService {
|
|
7
|
-
constructor(req) {
|
|
8
|
-
super();
|
|
9
|
-
|
|
10
|
-
this.chunkApi = new ChunkAPI(req);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async getChunk(app_id, id) {
|
|
14
|
-
return this.chunkApi.getChunk(app_id, id);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
putChunk() {
|
|
19
|
-
//do nothing
|
|
20
|
-
}
|
|
21
|
-
}
|