@gudhub/core 1.2.4-beta.6 → 1.2.4-beta.61
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/.parcel-cache/83e7562660f7cc15-BundleGraph +0 -0
- package/.parcel-cache/9a0d07555444f4da-AssetGraph +0 -0
- package/.parcel-cache/d3a1b9507cb44047-AssetGraph +0 -0
- package/.parcel-cache/data.mdb +0 -0
- package/.parcel-cache/dc1da35000e13623-RequestGraph +0 -0
- package/.parcel-cache/lock.mdb +0 -0
- package/.parcel-cache/snapshot-dc1da35000e13623.txt +29002 -0
- package/.parcelrc.appRequestWorker +4 -0
- package/GUDHUB/AppProcessor/AppProcessor.js +58 -26
- package/GUDHUB/ChunksManager/ChunksManager.test.js +11 -4
- package/GUDHUB/DataService/AppDataService.js +36 -1
- package/GUDHUB/DataService/ChunkDataService.js +7 -1
- package/GUDHUB/DataService/IndexedDB/IndexedDBAppService.js +773 -43
- package/GUDHUB/DataService/IndexedDB/IndexedDBChunkService.js +118 -85
- package/GUDHUB/DataService/IndexedDB/IndexedDBService.js +171 -7
- package/GUDHUB/DataService/IndexedDB/StoreManager/BaseStoreManager.js +97 -0
- package/GUDHUB/DataService/IndexedDB/StoreManager/managers.js +77 -0
- package/GUDHUB/DataService/IndexedDB/appDataConf.js +6 -3
- package/GUDHUB/DataService/IndexedDB/appRequestWorker.js +163 -0
- package/GUDHUB/DataService/IndexedDB/chunkDataConf.js +3 -3
- package/GUDHUB/DataService/IndexedDB/consts.js +1 -1
- package/GUDHUB/DataService/IndexedDB/init.js +18 -17
- package/GUDHUB/DataService/IndexedDB/storeManagerConf/chunkCacheStoreManagerConf.js +11 -0
- package/GUDHUB/DataService/IndexedDB/storeManagerConf/init.js +1 -0
- package/GUDHUB/DataService/export.js +69 -14
- package/GUDHUB/DataService/httpService/AppHttpService.js +13 -5
- package/GUDHUB/DataService/httpService/ChunkHttpService.js +41 -26
- package/GUDHUB/DataService/utils.js +27 -27
- package/GUDHUB/FileManager/FileManager.js +7 -3
- package/GUDHUB/GHConstructor/createAngularModuleInstance.js +63 -42
- package/GUDHUB/GHConstructor/createClassInstance.js +8 -3
- package/GUDHUB/ItemProcessor/ItemProcessor.js +14 -6
- package/GUDHUB/Storage/ModulesList.js +66 -3
- package/GUDHUB/Utils/AppsTemplateService/AppsTemplateService.js +48 -5
- package/GUDHUB/Utils/Utils.js +29 -1
- package/GUDHUB/Utils/filter/filter.js +32 -1
- package/GUDHUB/Utils/get_date/get_date.test.js +3 -12
- package/GUDHUB/Utils/merge_chunks/merge_chunks.js +36 -28
- package/GUDHUB/Utils/merge_chunks/merge_chunks.worker.js +78 -0
- package/GUDHUB/Utils/merge_compare_items/merge_compare_items.js +40 -9
- package/GUDHUB/Utils/nested_list/nested_list.js +53 -50
- package/GUDHUB/Utils/nested_list/nested_list.test.js +140 -2
- package/GUDHUB/WebSocket/WebSocket.js +2 -1
- package/GUDHUB/api/AppApi.js +13 -13
- package/GUDHUB/api/ChunkApi.js +6 -6
- package/GUDHUB/config.js +11 -2
- package/GUDHUB/consts.js +15 -1
- package/GUDHUB/gudhub.js +48 -26
- package/GUDHUB/gudhubAppRequestWorker.js +18 -0
- package/build.sh +127 -0
- package/diff.txt +1221 -0
- package/dist/gudhub.es.js +13455 -0
- package/dist/gudhub.umd.js +197 -0
- package/index.js +3 -1
- package/indexUMD.js +0 -2
- package/package.json +39 -22
- package/umd/library.min.js +285 -2
- package/umd/library.min.js.map +1 -1
- package/vite.config.esm.js +92 -0
- package/vite.config.umd.js +98 -0
- package/.vscode/launch.json +0 -31
- package/GUDHUB/ChunksManager/ChunksManager.js +0 -68
- package/umd/library.min.js.LICENSE.txt +0 -13
- package/webpack.config.js +0 -33
|
@@ -1,132 +1,165 @@
|
|
|
1
|
-
import { ChunkDataService } from "../ChunkDataService.js";
|
|
1
|
+
import { ChunkDataService } from "../ChunkDataService.js";
|
|
2
2
|
import { ChunkHttpService } from "../httpService/ChunkHttpService.js";
|
|
3
|
-
import {
|
|
4
|
-
import { IndexedDBService } from "./IndexedDBService.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
//this should be global in project
|
|
8
|
-
// class IndexedDBFacade extends CacheService {
|
|
9
|
-
|
|
10
|
-
// }
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// class ChunkCachedDataService extends ChunkDataService {
|
|
15
|
-
// dataService;
|
|
16
|
-
// }
|
|
3
|
+
import { ChunksStoreManager, MergedChunksStoreManager } from "./StoreManager/managers.js";
|
|
17
4
|
|
|
18
5
|
|
|
19
6
|
export class IndexedDBChunkService extends ChunkDataService {
|
|
20
|
-
constructor(req, conf) {
|
|
7
|
+
constructor(req, conf, gudhub) {
|
|
21
8
|
super(req, conf);
|
|
22
9
|
|
|
23
10
|
this.dataService = new ChunkHttpService(req);
|
|
24
11
|
|
|
12
|
+
this.requestCache = new Map;
|
|
25
13
|
|
|
26
|
-
let indexDBService = new IndexedDBService(conf);
|
|
27
|
-
|
|
28
|
-
objectAssignWithOverride(this, indexDBService);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
//TODO use IndexedDBFacade here
|
|
32
|
-
// indexDBAccess = new IndexedDBFacade;
|
|
33
14
|
|
|
15
|
+
this.gudhub = gudhub;
|
|
34
16
|
|
|
17
|
+
this.storeManager = new MergedChunksStoreManager;
|
|
18
|
+
}
|
|
35
19
|
|
|
36
20
|
static [Symbol.hasInstance](instance) {
|
|
37
21
|
try {
|
|
38
22
|
if (instance instanceof IndexedDBChunkService) return true;
|
|
39
|
-
if (instance instanceof IndexedDBService) return true; //TODO requires multiple inheritance, thhink how to overcome it
|
|
23
|
+
// if (instance instanceof IndexedDBService) return true; //TODO requires multiple inheritance, thhink how to overcome it
|
|
40
24
|
return false;
|
|
41
25
|
} catch (error) {
|
|
42
26
|
return false;
|
|
43
27
|
}
|
|
44
28
|
}
|
|
45
29
|
|
|
30
|
+
async getCachedMergedChunk(id, chunkHashesList) {
|
|
31
|
+
try {
|
|
32
|
+
let cachedData = await this.storeManager.get(id);
|
|
46
33
|
|
|
34
|
+
return cachedData.mergedData;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
const requests = chunkHashesList.map(hash => this.dataService.getChunk(id, hash));
|
|
37
|
+
|
|
38
|
+
const newChunks = await Promise.all(requests);
|
|
47
39
|
|
|
48
40
|
|
|
49
|
-
|
|
50
|
-
try {
|
|
51
|
-
const db = await this.openDatabase();
|
|
52
|
-
|
|
53
|
-
const transaction = db.transaction(this.store, "readwrite");
|
|
54
|
-
const store = transaction.objectStore(this.store);
|
|
41
|
+
let mergedData = await this.gudhub.util.mergeChunks(newChunks);
|
|
55
42
|
|
|
56
|
-
|
|
57
|
-
} catch (error) {
|
|
43
|
+
this.putMergedChunks(id, {hashes: chunkHashesList, mergedData: {items_list: mergedData}});
|
|
58
44
|
|
|
45
|
+
return {items_list: mergedData};
|
|
59
46
|
}
|
|
60
47
|
}
|
|
61
48
|
|
|
49
|
+
isWithCache() {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
62
52
|
|
|
63
|
-
async getChunk(app_id, id) {
|
|
64
|
-
if (this.requestCache.has(id)) return this.requestCache.get(id);
|
|
65
53
|
|
|
66
|
-
|
|
67
|
-
|
|
54
|
+
async getMergedChunkForApp(id) {
|
|
55
|
+
// here request api and get chunks list
|
|
68
56
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const storeRequest = store.get(id);
|
|
57
|
+
//then perform all required checks for cached chunk and hashes and new hashes
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//here // TODO replace this with getMergedChunkForApp in future
|
|
61
|
+
async getMergedChunkForIDList(id, chunkHashesList) {
|
|
62
|
+
try {
|
|
76
63
|
|
|
77
|
-
storeRequest.onsuccess = (e) => {
|
|
78
|
-
|
|
79
|
-
let cachedData = e.target.result;
|
|
80
|
-
|
|
81
|
-
if (
|
|
82
|
-
!cachedData
|
|
83
|
-
) {
|
|
84
|
-
reject();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
cachedData
|
|
89
|
-
) {
|
|
90
|
-
|
|
91
|
-
resolve(cachedData);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
64
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
65
|
+
let isCachedValid = true;
|
|
66
|
+
|
|
67
|
+
let cachedData = await this.storeManager.get(id);
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
|
|
72
|
+
if (chunkHashesList.length < cachedData.hashes.length) throw new Error;
|
|
73
|
+
|
|
74
|
+
for (let hash of cachedData.hashes) {
|
|
75
|
+
if (
|
|
76
|
+
chunkHashesList.indexOf(hash) != cachedData.hashes.indexOf(hash)
|
|
77
|
+
) isCachedValid = false;
|
|
98
78
|
}
|
|
99
|
-
})
|
|
79
|
+
} catch (error) {
|
|
80
|
+
isCachedValid = false;
|
|
81
|
+
}
|
|
100
82
|
|
|
101
|
-
self.requestCache.set(id, pr);
|
|
102
83
|
|
|
103
|
-
await pr;
|
|
104
84
|
|
|
105
|
-
return pr;
|
|
106
85
|
|
|
107
|
-
} catch(e) {
|
|
108
|
-
let reqPrms = this.dataService.getChunk(app_id, id);
|
|
109
86
|
|
|
110
|
-
|
|
87
|
+
if (
|
|
88
|
+
!isCachedValid
|
|
89
|
+
) {
|
|
90
|
+
// todo reload all data
|
|
91
|
+
}
|
|
111
92
|
|
|
112
|
-
let res = await reqPrms;
|
|
113
93
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
94
|
+
|
|
95
|
+
let newChunkHashes = [];
|
|
96
|
+
let newChunks = [];
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
if (
|
|
101
|
+
chunkHashesList.length > cachedData.hashes.length
|
|
102
|
+
) {
|
|
103
|
+
newChunkHashes = chunkHashesList.slice(cachedData.hashes.length);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (
|
|
107
|
+
!isCachedValid
|
|
108
|
+
) {
|
|
109
|
+
newChunkHashes = chunkHashesList;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (
|
|
113
|
+
newChunkHashes.length > 0
|
|
114
|
+
) {
|
|
115
|
+
const requests = newChunkHashes.map(hash => this.dataService.getChunk(id, hash));
|
|
116
|
+
|
|
117
|
+
newChunks = await Promise.all(requests);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
let mergedData;
|
|
121
|
+
if (
|
|
122
|
+
!isCachedValid
|
|
123
|
+
) {
|
|
124
|
+
mergedData = await this.gudhub.util.mergeChunks([
|
|
125
|
+
// cachedData.mergedData,
|
|
126
|
+
...newChunks,
|
|
127
|
+
]);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (
|
|
131
|
+
isCachedValid
|
|
132
|
+
) {
|
|
133
|
+
mergedData = await this.gudhub.util.mergeChunks([
|
|
134
|
+
cachedData.mergedData,
|
|
135
|
+
...newChunks,
|
|
136
|
+
]);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
if (
|
|
141
|
+
newChunkHashes.length > 0
|
|
142
|
+
) {
|
|
143
|
+
this.putMergedChunks(id, {hashes: chunkHashesList, mergedData: {items_list: mergedData}});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return {items_list: mergedData};
|
|
147
|
+
} catch (error) {
|
|
148
|
+
|
|
149
|
+
const requests = chunkHashesList.map(hash => this.dataService.getChunk(id, hash));
|
|
150
|
+
|
|
151
|
+
const newChunks = await Promise.all(requests);
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
let mergedData = await this.gudhub.util.mergeChunks(newChunks);
|
|
155
|
+
|
|
156
|
+
this.putMergedChunks(id, {hashes: chunkHashesList, mergedData: {items_list: mergedData}});
|
|
157
|
+
|
|
158
|
+
return {items_list: mergedData};
|
|
117
159
|
}
|
|
118
160
|
}
|
|
119
161
|
|
|
120
|
-
async
|
|
121
|
-
return
|
|
122
|
-
const request = indexedDB.open(this.dbName, this.dbVersion);
|
|
123
|
-
|
|
124
|
-
request.onsuccess = event => {
|
|
125
|
-
resolve(event.target.result);
|
|
126
|
-
};
|
|
127
|
-
request.onerror = event => {
|
|
128
|
-
reject(event.target.error);
|
|
129
|
-
};
|
|
130
|
-
});
|
|
162
|
+
async putMergedChunks(id, data) {
|
|
163
|
+
return this.storeManager.put(id, data);
|
|
131
164
|
}
|
|
132
165
|
}
|
|
@@ -1,9 +1,173 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
this.dbVersion = conf.dbVersion;
|
|
1
|
+
import { appsConf } from "./appDataConf.js";
|
|
2
|
+
import { chunksConf } from "./chunkDataConf.js";
|
|
3
|
+
import { dbName, dbVersion } from "./consts.js";
|
|
4
|
+
import { chunksMergeConf } from "./storeManagerConf/chunkCacheStoreManagerConf.js";
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export class StoreBackend { }
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
export class IndexedDBManager extends StoreBackend {
|
|
12
|
+
constructor(
|
|
13
|
+
dbName,
|
|
14
|
+
storeNameList,
|
|
15
|
+
) {
|
|
16
|
+
super();
|
|
17
|
+
|
|
18
|
+
if (
|
|
19
|
+
!IndexedDBManager.dbNameToInstanceMap
|
|
20
|
+
) {
|
|
21
|
+
IndexedDBManager.dbNameToInstanceMap = new Map;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (
|
|
25
|
+
IndexedDBManager.dbNameToInstanceMap.has(dbName)
|
|
26
|
+
) return IndexedDBManager.dbNameToInstanceMap.get(dbName);
|
|
27
|
+
|
|
28
|
+
this.db = null;
|
|
29
|
+
// this.queue = [];
|
|
30
|
+
// this.isProcessing = false;
|
|
31
|
+
|
|
32
|
+
this.dbName = dbName;
|
|
33
|
+
this.storeNameList = storeNameList;
|
|
34
|
+
|
|
35
|
+
IndexedDBManager.dbNameToInstanceMap.set(dbName, this);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async checkAndCreateStore(storeName) {
|
|
39
|
+
const databases = await indexedDB.databases();
|
|
40
|
+
const dbInfo = databases.find(db => db.name === this.dbName);
|
|
41
|
+
|
|
42
|
+
let storeExists = false;
|
|
43
|
+
|
|
44
|
+
let self = this;
|
|
45
|
+
|
|
46
|
+
if (
|
|
47
|
+
dbInfo
|
|
48
|
+
) {
|
|
49
|
+
storeExists = await new Promise((resolve, reject) => {
|
|
50
|
+
const request = indexedDB.open(self.dbName);
|
|
51
|
+
|
|
52
|
+
request.onsuccess = function (event) {
|
|
53
|
+
const db = event.target.result;
|
|
54
|
+
const exists = db.objectStoreNames.contains(storeName);
|
|
55
|
+
db.close();
|
|
56
|
+
resolve(exists);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
request.onerror = function (event) {
|
|
60
|
+
reject(event.target.error);
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
//TODO try catch for promise reject
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (
|
|
68
|
+
!storeExists
|
|
69
|
+
) {
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
const request = indexedDB.open(self.dbName, dbInfo ? dbInfo.version + 1 : 1);
|
|
72
|
+
|
|
73
|
+
request.onupgradeneeded = function (event) {
|
|
74
|
+
const db = event.target.result;
|
|
75
|
+
if (
|
|
76
|
+
!db.objectStoreNames.contains(storeName)
|
|
77
|
+
) {
|
|
78
|
+
db.createObjectStore(storeName);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
request.onsuccess = function (event) {
|
|
83
|
+
const db = event.target.result;
|
|
84
|
+
db.close();
|
|
85
|
+
resolve();
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
request.onerror = reject;
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
//TODO try catch for reject
|
|
8
93
|
}
|
|
9
|
-
|
|
94
|
+
|
|
95
|
+
//TODO maybe not return anything it will be ok for promise resolve
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async openDB() {
|
|
100
|
+
if (this.db) return this.db;
|
|
101
|
+
|
|
102
|
+
let resolver, rejecter;
|
|
103
|
+
|
|
104
|
+
let dbPrms = new Promise((resolve, reject) => {
|
|
105
|
+
resolver = resolve;
|
|
106
|
+
rejecter = reject;
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
for (let storeName of this.storeNameList) {
|
|
110
|
+
await this.checkAndCreateStore(storeName);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
let self = this;
|
|
114
|
+
|
|
115
|
+
const request = indexedDB.open(this.dbName);
|
|
116
|
+
|
|
117
|
+
request.onsuccess = (event) => {
|
|
118
|
+
self.db = event.target.result;
|
|
119
|
+
resolver(this.db);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
request.onerror = rejecter;
|
|
123
|
+
|
|
124
|
+
return dbPrms;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async executeOperation(storeName, operation) {
|
|
128
|
+
|
|
129
|
+
// TODO this get executed more than 1 time
|
|
130
|
+
let db = await this.openDB();
|
|
131
|
+
|
|
132
|
+
return new Promise((resolve, reject) => {
|
|
133
|
+
const transaction = db.transaction(storeName, 'readwrite'); //TODO not all operations readwrite
|
|
134
|
+
const store = transaction.objectStore(storeName);
|
|
135
|
+
|
|
136
|
+
transaction.oncomplete = () => resolve();
|
|
137
|
+
transaction.onerror = (event) => reject(`Transaction failed: ${event.target.error}`);
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
operation(store);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
reject(`Operation failed: ${error.message}`);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// async enqueueOperation(storeName, operation) {
|
|
148
|
+
// this.queue.push({ storeName, operation });
|
|
149
|
+
|
|
150
|
+
// if (!this.isProcessing) {
|
|
151
|
+
// this.isProcessing = true;
|
|
152
|
+
// while (this.queue.length > 0) {
|
|
153
|
+
// const { storeName, operation } = this.queue.shift();
|
|
154
|
+
// try {
|
|
155
|
+
// await this.executeOperation(storeName, operation);
|
|
156
|
+
// } catch (error) {
|
|
157
|
+
// console.error('Operation failed:', error);
|
|
158
|
+
// }
|
|
159
|
+
// }
|
|
160
|
+
// this.isProcessing = false;
|
|
161
|
+
// }
|
|
162
|
+
// }
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
export const indexedDBStoreBackendSingleton = new IndexedDBManager(
|
|
167
|
+
dbName,
|
|
168
|
+
[
|
|
169
|
+
appsConf.store,
|
|
170
|
+
chunksConf.store,
|
|
171
|
+
chunksMergeConf.store,
|
|
172
|
+
],
|
|
173
|
+
);
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export class BaseStoreManager {
|
|
2
|
+
constructor(storeBackend, storeName) {
|
|
3
|
+
this.storeBackend = storeBackend;
|
|
4
|
+
this.storeName = storeName;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
async addItem(id, data) {
|
|
8
|
+
return new Promise(async (resolve, reject) => {
|
|
9
|
+
|
|
10
|
+
this.storeBackend.executeOperation(this.storeName, (store) => {
|
|
11
|
+
const request = store.add(data, id);
|
|
12
|
+
|
|
13
|
+
request.onsuccess = resolve;
|
|
14
|
+
request.onerror = reject;
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async putItem(id, data) {
|
|
21
|
+
return new Promise(async (resolve, reject) => {
|
|
22
|
+
|
|
23
|
+
this.storeBackend.executeOperation(this.storeName, (store) => {
|
|
24
|
+
const request = store.put(data, id);
|
|
25
|
+
|
|
26
|
+
request.onsuccess = resolve;
|
|
27
|
+
request.onerror = reject;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async hasItem(id) {
|
|
34
|
+
try {
|
|
35
|
+
let item = await this.getItem(id);
|
|
36
|
+
|
|
37
|
+
if (!item) return false;
|
|
38
|
+
|
|
39
|
+
return true;
|
|
40
|
+
} catch(e) {
|
|
41
|
+
//todo check error type and then rethrow maybe here
|
|
42
|
+
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async getItem(id) {
|
|
48
|
+
return new Promise(async (resolve, reject) => {
|
|
49
|
+
|
|
50
|
+
this.storeBackend.executeOperation(this.storeName, (store) => {
|
|
51
|
+
const request = store.get(id);
|
|
52
|
+
|
|
53
|
+
request.onsuccess = () => {
|
|
54
|
+
const data = request.result;
|
|
55
|
+
resolve(data);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
request.onerror = reject;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async updateItem(id, updatedItem) {
|
|
65
|
+
return new Promise(async (resolve, reject) => {
|
|
66
|
+
|
|
67
|
+
this.storeBackend.executeOperation(this.storeName, (store) => {
|
|
68
|
+
const request = store.get(id);
|
|
69
|
+
|
|
70
|
+
request.onsuccess = () => {
|
|
71
|
+
const data = request.result;
|
|
72
|
+
Object.assign(data, updatedItem);
|
|
73
|
+
store.put(data, id);
|
|
74
|
+
|
|
75
|
+
//TODO wait put operation before resolve?
|
|
76
|
+
resolve();
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
request.onerror = reject;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async deleteItem(id) {
|
|
86
|
+
return new Promise(async (resolve, reject) => {
|
|
87
|
+
|
|
88
|
+
this.storeBackend.executeOperation(this.storeName, (store) => {
|
|
89
|
+
const request = store.delete(id);
|
|
90
|
+
|
|
91
|
+
request.onsuccess = resolve;
|
|
92
|
+
request.onerror = reject;
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { appsConf } from "../appDataConf.js";
|
|
2
|
+
import { chunksConf } from "../chunkDataConf.js";
|
|
3
|
+
import { indexedDBStoreBackendSingleton } from "../IndexedDBService.js";
|
|
4
|
+
import { chunksMergeConf } from "../storeManagerConf/chunkCacheStoreManagerConf.js";
|
|
5
|
+
import { BaseStoreManager } from "./BaseStoreManager.js";
|
|
6
|
+
|
|
7
|
+
export class AppStoreManager extends BaseStoreManager {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(indexedDBStoreBackendSingleton, appsConf.store);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async getApp(id) {
|
|
13
|
+
return this.getItem(id);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async addApp(id, data) {
|
|
17
|
+
return this.addItem(id, data);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async putApp(id, data) {
|
|
21
|
+
return this.putItem(id, data);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async hasApp(id) {
|
|
25
|
+
return this.hasItem(id);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async deleteApp(id) {
|
|
29
|
+
return this.deleteItem(id);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class ChunksStoreManager extends BaseStoreManager {
|
|
34
|
+
constructor() {
|
|
35
|
+
super(indexedDBStoreBackendSingleton, chunksConf.store);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
async getChunk(id) {
|
|
40
|
+
return this.getItem(id);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async addChunk(id, chunk) {
|
|
44
|
+
return this.addItem(id, chunk);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async putChunk(id, chunk) {
|
|
48
|
+
return this.putItem(id, chunk);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async deleteChunk(id) {
|
|
52
|
+
return this.deleteItem(id);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class MergedChunksStoreManager extends BaseStoreManager {
|
|
57
|
+
constructor() {
|
|
58
|
+
super(indexedDBStoreBackendSingleton, chunksMergeConf.store);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async get(id) {
|
|
62
|
+
return this.getItem(id);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async add(id, chunk) {
|
|
66
|
+
return this.addItem(id, chunk);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//TODO update here ok?
|
|
70
|
+
async put(id, chunk) {
|
|
71
|
+
return this.putItem(id, chunk);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async delete(id) {
|
|
75
|
+
return this.deleteItem(id);
|
|
76
|
+
}
|
|
77
|
+
}
|