@gudhub/core 1.2.4-beta.3 → 1.2.4-beta.32
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/GUDHUB/AppProcessor/AppProcessor.js +62 -24
- package/GUDHUB/ChunksManager/ChunksManager.js +61 -61
- package/GUDHUB/ChunksManager/ChunksManager.test.js +8 -4
- package/GUDHUB/DataService/AppDataService.js +232 -0
- package/GUDHUB/DataService/ChunkDataService.js +10 -0
- package/GUDHUB/DataService/IndexedDB/IndexedDBAppService.js +799 -63
- package/GUDHUB/DataService/IndexedDB/IndexedDBChunkService.js +303 -46
- package/GUDHUB/DataService/IndexedDB/IndexedDBService.js +342 -2
- package/GUDHUB/DataService/IndexedDB/StoreManager/BaseStoreManager.js +124 -0
- package/GUDHUB/DataService/IndexedDB/StoreManager/managers.js +113 -0
- package/GUDHUB/DataService/IndexedDB/appDataConf.js +6 -3
- package/GUDHUB/DataService/IndexedDB/appRequestWorker.js +225 -0
- package/GUDHUB/DataService/IndexedDB/chunkDataConf.js +3 -3
- package/GUDHUB/DataService/IndexedDB/consts.js +3 -1
- package/GUDHUB/DataService/IndexedDB/init.js +15 -14
- package/GUDHUB/DataService/IndexedDB/storeManagerConf/chunkCacheStoreManagerConf.js +11 -0
- package/GUDHUB/DataService/IndexedDB/storeManagerConf/init.js +1 -0
- package/GUDHUB/DataService/export.js +8 -5
- package/GUDHUB/DataService/httpService/AppHttpService.js +22 -4
- package/GUDHUB/DataService/httpService/ChunkHttpService.js +19 -2
- package/GUDHUB/DataService/utils.js +104 -1
- package/GUDHUB/FileManager/FileManager.js +7 -3
- package/GUDHUB/GHConstructor/createAngularModuleInstance.js +3 -3
- package/GUDHUB/GHConstructor/createClassInstance.js +3 -3
- package/GUDHUB/ItemProcessor/ItemProcessor.js +24 -0
- package/GUDHUB/Storage/ModulesList.js +18 -2
- package/GUDHUB/Utils/AppsTemplateService/AppsTemplateService.js +37 -1
- package/GUDHUB/Utils/Utils.js +29 -1
- 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/WebSocket/WebSocket.js +2 -1
- package/GUDHUB/consts.js +21 -1
- package/GUDHUB/gudhub.js +39 -14
- package/appRequestWorker.js +1 -0
- package/appRequestWorker.js.LICENSE.txt +13 -0
- package/appRequestWorker.js.map +1 -0
- package/package.json +17 -6
- package/umd/appRequestWorker.js +1 -0
- package/umd/library.min.js +1 -300
- package/webpack.config.js +154 -0
- package/.vscode/launch.json +0 -31
- package/umd/library.min.js.map +0 -1
|
@@ -2,6 +2,7 @@ import { ChunkDataService } from "../ChunkDataService.js"; // removed "ChunkCach
|
|
|
2
2
|
import { ChunkHttpService } from "../httpService/ChunkHttpService.js";
|
|
3
3
|
import { objectAssignWithOverride } from "../utils.js";
|
|
4
4
|
import { IndexedDBService } from "./IndexedDBService.js";
|
|
5
|
+
import { ChunksStoreManager, MergedChunksStoreManager } from "./StoreManager/managers.js";
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
//this should be global in project
|
|
@@ -17,15 +18,28 @@ import { IndexedDBService } from "./IndexedDBService.js";
|
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
export class IndexedDBChunkService extends ChunkDataService {
|
|
20
|
-
constructor(req, conf) {
|
|
21
|
+
constructor(req, conf, gudhub) {
|
|
21
22
|
super(req, conf);
|
|
22
23
|
|
|
23
24
|
this.dataService = new ChunkHttpService(req);
|
|
24
25
|
|
|
26
|
+
// let indexDBService = new IndexedDBService(conf);
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
this.requestCache = new Map; // id -> promise ///TODO seems irrelevant to class IndexedDBManager (could be renamed to Facade already)
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
|
|
31
|
+
this.gudhub = gudhub;
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
// this.storeManager = new ChunksStoreManager;
|
|
35
|
+
this.storeManager = new MergedChunksStoreManager;
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
// this.storeManager = new ChunksStoreManager;
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
// objectAssignWithOverride(this, indexDBService);
|
|
42
|
+
// objectAssignWithOverride(this, new ChunksStoreManager);
|
|
29
43
|
}
|
|
30
44
|
|
|
31
45
|
//TODO use IndexedDBFacade here
|
|
@@ -43,60 +57,302 @@ export class IndexedDBChunkService extends ChunkDataService {
|
|
|
43
57
|
}
|
|
44
58
|
}
|
|
45
59
|
|
|
60
|
+
async getCachedMergedChunk(id, chunkHashesList) {
|
|
61
|
+
try {
|
|
62
|
+
let cachedData = await this.storeManager.get(id);
|
|
63
|
+
|
|
64
|
+
return cachedData.mergedData;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
// let newHashes = chunkHashesList.filter(c => !cachedData.hashes.includes(c));
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
const requests = chunkHashesList.map(hash => this.dataService.getChunk(id, hash));
|
|
70
|
+
|
|
71
|
+
const newChunks = await Promise.all(requests);
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
let mergedData = await this.gudhub.util.mergeChunks(newChunks);
|
|
75
|
+
|
|
76
|
+
this.putMergedChunks(id, {hashes: chunkHashesList, mergedData: {items_list: mergedData}});
|
|
77
|
+
|
|
78
|
+
return {items_list: mergedData};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
isWithCache() {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
async getMergedChunkForApp(id) {
|
|
88
|
+
// here request api and get chunks list
|
|
89
|
+
|
|
90
|
+
//then perform all required checks for cached chunk and hashes and new hashes
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
//here // TODO replace this with getMergedChunkForApp in future
|
|
94
|
+
async getMergedChunkForIDList(id, chunkHashesList) {
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
//TODO promise cache
|
|
98
|
+
|
|
99
|
+
// TODO also try catch maybe
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
let isCachedValid = true;
|
|
106
|
+
|
|
107
|
+
let cachedData = await this.storeManager.get(id);
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
|
|
112
|
+
if (chunkHashesList.length < cachedData.hashes.length) throw new Error;
|
|
113
|
+
|
|
114
|
+
for (let hash of cachedData.hashes) {
|
|
115
|
+
if (
|
|
116
|
+
chunkHashesList.indexOf(hash) != cachedData.hashes.indexOf(hash)
|
|
117
|
+
) isCachedValid = false;
|
|
118
|
+
}
|
|
119
|
+
} catch (error) {
|
|
120
|
+
isCachedValid = false;
|
|
121
|
+
}
|
|
122
|
+
|
|
46
123
|
|
|
47
124
|
|
|
48
125
|
|
|
49
|
-
async putChunk(id, data) {
|
|
50
|
-
try {
|
|
51
|
-
const db = await this.openDatabase();
|
|
52
126
|
|
|
53
|
-
|
|
54
|
-
|
|
127
|
+
if (
|
|
128
|
+
!isCachedValid
|
|
129
|
+
) {
|
|
130
|
+
// todo reload all data
|
|
131
|
+
}
|
|
55
132
|
|
|
56
|
-
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
let newChunkHashes = [];
|
|
136
|
+
let newChunks = [];
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
if (
|
|
141
|
+
chunkHashesList.length > cachedData.hashes.length
|
|
142
|
+
) {
|
|
143
|
+
newChunkHashes = chunkHashesList.slice(cachedData.hashes.length);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (
|
|
147
|
+
!isCachedValid
|
|
148
|
+
) {
|
|
149
|
+
newChunkHashes = chunkHashesList;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (
|
|
153
|
+
newChunkHashes.length > 0
|
|
154
|
+
) {
|
|
155
|
+
const requests = newChunkHashes.map(hash => this.dataService.getChunk(id, hash));
|
|
156
|
+
|
|
157
|
+
newChunks = await Promise.all(requests);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
let mergedData;
|
|
161
|
+
if (
|
|
162
|
+
!isCachedValid
|
|
163
|
+
) {
|
|
164
|
+
mergedData = await this.gudhub.util.mergeChunks([
|
|
165
|
+
// cachedData.mergedData,
|
|
166
|
+
...newChunks,
|
|
167
|
+
]);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (
|
|
171
|
+
isCachedValid
|
|
172
|
+
) {
|
|
173
|
+
mergedData = await this.gudhub.util.mergeChunks([
|
|
174
|
+
cachedData.mergedData,
|
|
175
|
+
...newChunks,
|
|
176
|
+
]);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
if (
|
|
181
|
+
newChunkHashes.length > 0
|
|
182
|
+
) {
|
|
183
|
+
this.putMergedChunks(id, {hashes: chunkHashesList, mergedData: {items_list: mergedData}});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return {items_list: mergedData};
|
|
57
187
|
} catch (error) {
|
|
188
|
+
// let newHashes = chunkHashesList.filter(c => !cachedData.hashes.includes(c));
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
const requests = chunkHashesList.map(hash => this.dataService.getChunk(id, hash));
|
|
192
|
+
|
|
193
|
+
const newChunks = await Promise.all(requests);
|
|
194
|
+
|
|
58
195
|
|
|
196
|
+
let mergedData = await this.gudhub.util.mergeChunks(newChunks);
|
|
197
|
+
|
|
198
|
+
this.putMergedChunks(id, {hashes: chunkHashesList, mergedData: {items_list: mergedData}});
|
|
199
|
+
|
|
200
|
+
return {items_list: mergedData};
|
|
59
201
|
}
|
|
60
202
|
}
|
|
61
203
|
|
|
62
204
|
|
|
205
|
+
|
|
206
|
+
// async function fetchAndMergeArrays(urls) {
|
|
207
|
+
// try {
|
|
208
|
+
// // Create an array of fetch promises
|
|
209
|
+
// const requests = urls.map(url => fetch(url).then(response => response.json()));
|
|
210
|
+
|
|
211
|
+
// // Wait for all requests to complete
|
|
212
|
+
// const results = await Promise.all(requests);
|
|
213
|
+
|
|
214
|
+
// // Merge all arrays
|
|
215
|
+
// const mergedArray = results.flat(); // or use reduce: results.reduce((acc, arr) => acc.concat(arr), []);
|
|
216
|
+
|
|
217
|
+
// return mergedArray;
|
|
218
|
+
// } catch (error) {
|
|
219
|
+
// console.error('Error fetching data:', error);
|
|
220
|
+
// throw error;
|
|
221
|
+
// }
|
|
222
|
+
// }
|
|
223
|
+
|
|
224
|
+
// // Example usage:
|
|
225
|
+
// const urls = ['https://api.example.com/data1', 'https://api.example.com/data2'];
|
|
226
|
+
// fetchAndMergeArrays(urls)
|
|
227
|
+
// .then(mergedArray => console.log(mergedArray))
|
|
228
|
+
// .catch(error => console.error('Error:', error));
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
//todo also optimize chunks transactions etc
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
async putMergedChunks(id, data) {
|
|
236
|
+
return this.storeManager.put(id, data);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
// async getMergedChunks(id, data) {
|
|
241
|
+
// return this.storeManager.get(id, data);
|
|
242
|
+
// }
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
async putChunk(id, data) {
|
|
246
|
+
return this.storeManager.putChunk(id, data);
|
|
247
|
+
|
|
248
|
+
// try {
|
|
249
|
+
// const db = await this.openDatabase(); //here
|
|
250
|
+
|
|
251
|
+
// const transaction = db.transaction(this.store, "readwrite");
|
|
252
|
+
// const store = transaction.objectStore(this.store);
|
|
253
|
+
|
|
254
|
+
// store.put(data, id);
|
|
255
|
+
// } catch (error) {
|
|
256
|
+
|
|
257
|
+
// }
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
// async getApp(id) {
|
|
262
|
+
// if (this.requestCache.has(id)) return this.requestCache.get(id);
|
|
263
|
+
|
|
264
|
+
// let self = this;
|
|
265
|
+
|
|
266
|
+
// let dataServiceRequest = this.dataService.getApp(id);
|
|
267
|
+
|
|
268
|
+
// let pr = new Promise(async (resolve, reject) => {
|
|
269
|
+
// try {
|
|
270
|
+
// const db = await self.openDatabase();
|
|
271
|
+
// const transaction = db.transaction(self.store, "readonly");
|
|
272
|
+
// const store = transaction.objectStore(self.store);
|
|
273
|
+
|
|
274
|
+
// const storeRequest = store.get(id);
|
|
275
|
+
|
|
276
|
+
// storeRequest.onsuccess = (e) => {
|
|
277
|
+
|
|
278
|
+
// let cachedData = e.target.result;
|
|
279
|
+
|
|
280
|
+
// if (
|
|
281
|
+
// !cachedData
|
|
282
|
+
// ) {
|
|
283
|
+
// dataServiceRequest.then(resolve, reject);
|
|
284
|
+
// dataServiceRequest.then(data => self.putApp(id, data));
|
|
285
|
+
// }
|
|
286
|
+
|
|
287
|
+
// if (
|
|
288
|
+
// cachedData
|
|
289
|
+
// ) {
|
|
290
|
+
// resolve(cachedData);
|
|
291
|
+
|
|
292
|
+
// dataServiceRequest.then(async (data) => {
|
|
293
|
+
// // self.gudhub.processAppUpd(data, cachedData);//
|
|
294
|
+
// await self.putApp(id, data);
|
|
295
|
+
// self.gudhub.triggerAppUpdate(id, prevVersion, newVersion);
|
|
296
|
+
// });
|
|
297
|
+
// }
|
|
298
|
+
// };
|
|
299
|
+
|
|
300
|
+
// storeRequest.onerror = () => {
|
|
301
|
+
// dataServiceRequest.then(resolve, reject);
|
|
302
|
+
// dataServiceRequest.then(data => self.putApp(id, data));
|
|
303
|
+
// }
|
|
304
|
+
// } catch (error) {
|
|
305
|
+
// dataServiceRequest.then(resolve, reject);
|
|
306
|
+
// dataServiceRequest.then(data => self.putApp(id, data));
|
|
307
|
+
// }
|
|
308
|
+
// });
|
|
309
|
+
|
|
310
|
+
// self.requestCache.set(id, pr);
|
|
311
|
+
|
|
312
|
+
// return pr;
|
|
313
|
+
// }
|
|
314
|
+
|
|
315
|
+
|
|
63
316
|
async getChunk(app_id, id) {
|
|
64
317
|
if (this.requestCache.has(id)) return this.requestCache.get(id);
|
|
65
318
|
|
|
66
319
|
try {
|
|
67
|
-
let self = this;
|
|
68
320
|
|
|
69
|
-
let pr =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
321
|
+
let pr = this.storeManager.getChunk(id);
|
|
322
|
+
|
|
323
|
+
// let self = this;
|
|
324
|
+
|
|
325
|
+
// let pr = new Promise(async (resolve, reject) => {
|
|
326
|
+
// try {
|
|
327
|
+
// const db = await self.openDatabase();
|
|
328
|
+
// const transaction = db.transaction(self.store, "readonly");
|
|
329
|
+
// const store = transaction.objectStore(self.store);
|
|
74
330
|
|
|
75
|
-
|
|
331
|
+
// const storeRequest = store.get(id);
|
|
76
332
|
|
|
77
|
-
|
|
333
|
+
// storeRequest.onsuccess = (e) => {
|
|
78
334
|
|
|
79
|
-
|
|
335
|
+
// let cachedData = e.target.result;
|
|
80
336
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
337
|
+
// if (
|
|
338
|
+
// !cachedData
|
|
339
|
+
// ) {
|
|
340
|
+
// reject();
|
|
341
|
+
// }
|
|
86
342
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
343
|
+
// if (
|
|
344
|
+
// cachedData
|
|
345
|
+
// ) {
|
|
90
346
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
347
|
+
// resolve(cachedData);
|
|
348
|
+
// }
|
|
349
|
+
// };
|
|
94
350
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
});
|
|
351
|
+
// storeRequest.onerror = reject
|
|
352
|
+
// } catch (error) {
|
|
353
|
+
// reject();
|
|
354
|
+
// }
|
|
355
|
+
// });
|
|
100
356
|
|
|
101
357
|
self.requestCache.set(id, pr);
|
|
102
358
|
|
|
@@ -112,21 +368,22 @@ export class IndexedDBChunkService extends ChunkDataService {
|
|
|
112
368
|
let res = await reqPrms;
|
|
113
369
|
|
|
114
370
|
this.putChunk(id, res);
|
|
371
|
+
// putPrms.then(() => self.gudhub.triggerAppUpdate(id));
|
|
115
372
|
|
|
116
373
|
return reqPrms;
|
|
117
374
|
}
|
|
118
375
|
}
|
|
119
376
|
|
|
120
|
-
async openDatabase() {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
377
|
+
// async openDatabase() {
|
|
378
|
+
// return new Promise((resolve, reject) => {
|
|
379
|
+
// const request = indexedDB.open(this.dbName, this.dbVersion);
|
|
380
|
+
|
|
381
|
+
// request.onsuccess = event => {
|
|
382
|
+
// resolve(event.target.result);
|
|
383
|
+
// };
|
|
384
|
+
// request.onerror = event => {
|
|
385
|
+
// reject(event.target.error);
|
|
386
|
+
// };
|
|
387
|
+
// });
|
|
388
|
+
// }
|
|
132
389
|
}
|