@gudhub/core 1.2.4-beta.6 → 1.2.4-beta.60
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 +29402 -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 +38 -22
- package/umd/library.min.js +285 -2
- package/umd/library.min.js.map +1 -1
- package/vite.config.esm.js +72 -0
- package/vite.config.umd.js +68 -0
- package/GUDHUB/ChunksManager/ChunksManager.js +0 -68
- package/umd/library.min.js.LICENSE.txt +0 -13
- package/webpack.config.js +0 -33
|
@@ -1,33 +1,73 @@
|
|
|
1
1
|
import { AppDataService } from "../AppDataService.js";
|
|
2
|
-
import { ChunkDataService } from "../ChunkDataService.js"; // removed "ChunkCacheDataService" from imported because it was causing an error "{ ChunkCacheDataService } not found in exported names" in "gudhub-node-server"
|
|
3
2
|
import { AppHttpService } from "../httpService/AppHttpService.js";
|
|
4
|
-
import { objectAssignWithOverride } from "../utils.js";
|
|
5
|
-
import { IndexedDBService } from "./IndexedDBService.js";
|
|
6
3
|
|
|
4
|
+
import { IndexedDBChunkService } from "./IndexedDBChunkService.js";
|
|
5
|
+
import { AppStoreManager } from "./StoreManager/managers.js";
|
|
6
|
+
import { chunksMergeConf } from "./storeManagerConf/chunkCacheStoreManagerConf.js";
|
|
7
7
|
|
|
8
|
-
//this should be global in project
|
|
9
|
-
// class IndexedDBFacade extends CacheService {
|
|
10
8
|
|
|
11
|
-
//
|
|
9
|
+
// TODO remove query parameters and check build success
|
|
10
|
+
import AppRequestWorkerScript from '../../../dist/PARCEL_APP_REQUEST_WORKER_FILENAME.js';
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export let WORKER_EVENTS = {
|
|
15
|
+
INIT: 1,
|
|
16
|
+
REQUEST_APP: 2,
|
|
17
|
+
PROCESS_DATA: 3,
|
|
18
|
+
DECLINE_PROCESS_DATA_REQUEST: 4,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// old class for worker. Contains useful code therefore isnt removed
|
|
22
|
+
export class IndexedDBAppServiceForWorker extends AppDataService {
|
|
14
23
|
constructor(req, conf, gudhub) {
|
|
15
|
-
super(req, conf);
|
|
24
|
+
super(req, conf, gudhub);
|
|
16
25
|
|
|
17
|
-
this.dataService = new AppHttpService(req);
|
|
26
|
+
this.dataService = new AppHttpService(req, null, gudhub);
|
|
27
|
+
|
|
28
|
+
this.requestCache = new Map; // id -> promise ///TODO seems irrelevant to class IndexedDBManager (could be renamed to Facade already)
|
|
18
29
|
|
|
19
|
-
let indexDBService = new IndexedDBService(conf);
|
|
20
30
|
|
|
21
31
|
this.gudhub = gudhub;
|
|
22
32
|
|
|
23
|
-
|
|
33
|
+
|
|
34
|
+
this.chunkDataService = new IndexedDBChunkService(req, chunksMergeConf, gudhub);
|
|
35
|
+
|
|
36
|
+
// let res = await this.chunkDataService.getMergedChunkForIDList(id, sentData.chunks);
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
//TODO objectAssignWithOverride here too?
|
|
42
|
+
// this.storeBackend = new IndexedDBManager('myDatabase', 'appsStore');
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
//TODO also think how to use AppDataService without overriding chunkDataService here. seems it gets http chunk service for worker somehow
|
|
47
|
+
// maybe IS_WEB is wrong inside worker
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
// this.db = null;
|
|
52
|
+
// this.queue = [];
|
|
53
|
+
// this.isProcessing = false;
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
//todo worker pool?
|
|
58
|
+
|
|
59
|
+
this.storeManager = new AppStoreManager;
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
// objectAssignWithOverride(this, indexDBService);
|
|
63
|
+
// objectAssignWithOverride(this, new AppStoreManager);
|
|
24
64
|
}
|
|
25
65
|
|
|
26
66
|
|
|
27
67
|
static [Symbol.hasInstance](instance) {
|
|
28
68
|
try {
|
|
29
|
-
if (instance instanceof
|
|
30
|
-
if (instance instanceof IndexedDBService) return true; //TODO requires multiple inheritance, thhink how to overcome it
|
|
69
|
+
if (instance instanceof IndexedDBAppServiceForWorker) return true;
|
|
70
|
+
// if (instance instanceof IndexedDBService) return true; //TODO requires multiple inheritance, thhink how to overcome it
|
|
31
71
|
return false;
|
|
32
72
|
} catch (error) {
|
|
33
73
|
return false;
|
|
@@ -38,17 +78,138 @@ export class IndexedDBAppService extends AppDataService {
|
|
|
38
78
|
// indexDBAccess = new IndexedDBFacade;
|
|
39
79
|
|
|
40
80
|
|
|
81
|
+
isWithCache() {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// getApp(id) {
|
|
86
|
+
// let worker = new Worker('../../appRequestWorker.js');
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
// worker.postMessage({ type: 'init', gudhubSerialized: this.gudhub.serialized });
|
|
90
|
+
|
|
91
|
+
// // Send the main data to be processed
|
|
92
|
+
// const mainData = { /* your data here */ };
|
|
93
|
+
// worker.postMessage({ type: 'processData', data: mainData });
|
|
94
|
+
|
|
95
|
+
// worker.onmessage = function(e) {
|
|
96
|
+
// console.log('Data processed by worker:', e.data);
|
|
97
|
+
// };
|
|
98
|
+
|
|
99
|
+
// worker.onerror = function(e) {
|
|
100
|
+
// console.error('Error in worker:', e);
|
|
101
|
+
// };
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
// worker.onmessage = (msgEv) => {
|
|
105
|
+
|
|
106
|
+
// }
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
// }
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
//TODO для чанков с индексддб будет точно такой код поєтому может вынести его в какое-то место? например в отдельный класс
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
// async executeOperation(operation) {
|
|
117
|
+
// await this.openDB();
|
|
118
|
+
// return new Promise((resolve, reject) => {
|
|
119
|
+
// const transaction = this.db.transaction(this.storeName, 'readwrite');
|
|
120
|
+
// const store = transaction.objectStore(this.storeName);
|
|
121
|
+
|
|
122
|
+
// transaction.oncomplete = () => resolve();
|
|
123
|
+
// transaction.onerror = (event) => reject(event.target.error);
|
|
124
|
+
|
|
125
|
+
// operation(store);
|
|
126
|
+
// });
|
|
127
|
+
// }
|
|
128
|
+
|
|
129
|
+
// async enqueueOperation(operation) {
|
|
130
|
+
// this.queue.push(operation);
|
|
131
|
+
|
|
132
|
+
// if (!this.isProcessing) {
|
|
133
|
+
// this.isProcessing = true;
|
|
134
|
+
// while (this.queue.length > 0) {
|
|
135
|
+
// const currentOperation = this.queue.shift();
|
|
136
|
+
// try {
|
|
137
|
+
// await this.executeOperation(currentOperation);
|
|
138
|
+
// } catch (error) {
|
|
139
|
+
// console.error('Operation failed:', error);
|
|
140
|
+
// }
|
|
141
|
+
// }
|
|
142
|
+
// this.isProcessing = false;
|
|
143
|
+
// }
|
|
144
|
+
// }
|
|
145
|
+
|
|
146
|
+
// async addData(data) {
|
|
147
|
+
// await this.enqueueOperation((store) => {
|
|
148
|
+
// store.add(data);
|
|
149
|
+
// });
|
|
150
|
+
// }
|
|
151
|
+
|
|
152
|
+
// async updateData(id, updatedData) {
|
|
153
|
+
// await this.enqueueOperation((store) => {
|
|
154
|
+
// const request = store.get(id);
|
|
155
|
+
// request.onsuccess = () => {
|
|
156
|
+
// const data = request.result;
|
|
157
|
+
// Object.assign(data, updatedData);
|
|
158
|
+
// store.put(data);
|
|
159
|
+
// };
|
|
160
|
+
// });
|
|
161
|
+
// }
|
|
162
|
+
|
|
163
|
+
// async deleteData(id) {
|
|
164
|
+
// await this.enqueueOperation((store) => {
|
|
165
|
+
// store.delete(id);
|
|
166
|
+
// });
|
|
167
|
+
// }
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
async getAppWithoutProcessing(id) {
|
|
171
|
+
let data = await this.dataService.getAppWithoutProcessing(id);
|
|
172
|
+
|
|
173
|
+
await this.putApp(id, data);
|
|
174
|
+
|
|
175
|
+
return data;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// this returns data for specific chunks + app request data
|
|
179
|
+
// async getAppWithSpecificChunksList(id, list) {
|
|
180
|
+
// let data = await this.dataService.getAppWithoutProcessing(id);
|
|
181
|
+
|
|
182
|
+
// await self.putApp(id, data);
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
// let processedData = await self.processRequestedApp(id, data);//here нужно пересмотреть
|
|
186
|
+
|
|
187
|
+
// return processedData;
|
|
188
|
+
// }
|
|
189
|
+
|
|
41
190
|
async getApp(id) {
|
|
42
|
-
if (this.requestCache.has(id)) return this.requestCache.get(id);
|
|
191
|
+
// if (this.requestCache.has(id)) return this.requestCache.get(id);
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
// return at first time cached app request?????? no seems for worker its ok
|
|
43
195
|
|
|
44
196
|
let self = this;
|
|
45
197
|
|
|
46
|
-
let dataServiceRequest = this.dataService.
|
|
198
|
+
// let dataServiceRequest = this.dataService.getAppWithoutProcessing(id);
|
|
199
|
+
let data = await this.dataService.getAppWithoutProcessing(id);
|
|
200
|
+
|
|
201
|
+
// await self.putApp(id, data);
|
|
202
|
+
|
|
203
|
+
let processedData = await self.processRequestedApp(id, data);//here нужно пересмотреть
|
|
204
|
+
|
|
205
|
+
return processedData;
|
|
47
206
|
|
|
48
207
|
let pr = new Promise(async (resolve, reject) => {
|
|
49
208
|
try {
|
|
50
|
-
|
|
51
|
-
|
|
209
|
+
await self.openDatabase();
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
const transaction = self.db.transaction(self.store, "readonly");
|
|
52
213
|
const store = transaction.objectStore(self.store);
|
|
53
214
|
|
|
54
215
|
const storeRequest = store.get(id);
|
|
@@ -60,60 +221,629 @@ export class IndexedDBAppService extends AppDataService {
|
|
|
60
221
|
if (
|
|
61
222
|
!cachedData
|
|
62
223
|
) {
|
|
63
|
-
dataServiceRequest.then(
|
|
64
|
-
|
|
224
|
+
dataServiceRequest.then(async data => {
|
|
225
|
+
let processedData = await self.processRequestedApp(id, data);//here
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
// let comparison = this.gudhub.util.compareItems([], processedData.items_list);
|
|
229
|
+
|
|
230
|
+
// let cached
|
|
231
|
+
|
|
232
|
+
resolve(processedData);
|
|
233
|
+
|
|
234
|
+
self.putApp(id, processedData);
|
|
235
|
+
|
|
236
|
+
}, reject);
|
|
65
237
|
}
|
|
66
238
|
|
|
67
239
|
if (
|
|
68
240
|
cachedData
|
|
69
241
|
) {
|
|
70
|
-
resolve(cachedData);
|
|
242
|
+
// resolve(cachedData);
|
|
243
|
+
|
|
244
|
+
dataServiceRequest.then(async data => {
|
|
245
|
+
let processedData = await self.processRequestedApp(id, data);//here
|
|
246
|
+
|
|
247
|
+
// let comparison = this.gudhub.util.compareItems(cachedData.items_list, processedData.items_list);
|
|
71
248
|
|
|
72
|
-
|
|
73
|
-
self.
|
|
74
|
-
self.putApp(id, data);
|
|
249
|
+
resolve(processedData);
|
|
250
|
+
self.putApp(id, processedData);
|
|
75
251
|
});
|
|
76
252
|
}
|
|
77
253
|
};
|
|
78
254
|
|
|
79
255
|
storeRequest.onerror = () => {
|
|
80
|
-
dataServiceRequest.then(
|
|
81
|
-
|
|
256
|
+
dataServiceRequest.then(async data => {
|
|
257
|
+
let processedData = await self.processRequestedApp(id, data);//here
|
|
258
|
+
|
|
259
|
+
// let comparison = this.gudhub.util.compareItems([], processedData.items_list);
|
|
260
|
+
|
|
261
|
+
// let cached
|
|
262
|
+
|
|
263
|
+
resolve(processedData);
|
|
264
|
+
|
|
265
|
+
self.putApp(id, processedData);
|
|
266
|
+
|
|
267
|
+
}, reject);
|
|
82
268
|
}
|
|
83
269
|
} catch (error) {
|
|
84
|
-
dataServiceRequest.then(
|
|
85
|
-
|
|
270
|
+
dataServiceRequest.then(async data => {
|
|
271
|
+
let processedData = await self.processRequestedApp(id, data);//here
|
|
272
|
+
|
|
273
|
+
// let comparison = this.gudhub.util.compareItems([], processedData.items_list);
|
|
274
|
+
|
|
275
|
+
// let cached
|
|
276
|
+
|
|
277
|
+
resolve(processedData);
|
|
278
|
+
|
|
279
|
+
self.putApp(id, processedData);
|
|
280
|
+
|
|
281
|
+
}, reject);
|
|
86
282
|
}
|
|
87
283
|
});
|
|
88
284
|
|
|
89
|
-
self.requestCache.set(id, pr);
|
|
285
|
+
// self.requestCache.set(id, pr);
|
|
90
286
|
|
|
91
287
|
return pr;
|
|
92
288
|
}
|
|
93
289
|
|
|
94
|
-
async putApp(id, data) {
|
|
95
|
-
try {
|
|
96
|
-
const db = await this.openDatabase();
|
|
97
290
|
|
|
98
|
-
|
|
99
|
-
const store = transaction.objectStore(this.store);
|
|
291
|
+
async has(id) {
|
|
100
292
|
|
|
101
|
-
|
|
293
|
+
try {
|
|
294
|
+
|
|
295
|
+
return this.storeManager.hasApp(id);
|
|
102
296
|
} catch (error) {
|
|
297
|
+
// debugger
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
async getCached(id) {
|
|
302
|
+
return this.storeManager.getApp(id);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
async putApp(id, data) {
|
|
306
|
+
return this.storeManager.putApp(id, data);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
// this class means work directly with indexeddb without worker
|
|
312
|
+
export class IndexedDBAppService extends AppDataService {
|
|
313
|
+
constructor(req, conf, gudhub) {
|
|
314
|
+
super(req, conf, gudhub);
|
|
315
|
+
|
|
316
|
+
this.dataService = new AppHttpService(req, conf, gudhub);// TODO isnt used in class. Why?
|
|
317
|
+
|
|
318
|
+
// let indexDBService = new IndexedDBService(conf);
|
|
319
|
+
|
|
320
|
+
this.requestCache = new Map; // id -> promise ///TODO seems irrelevant to class IndexedDBManager (could be renamed to Facade already)
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
this.gudhub = gudhub;
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
this.resolveFnMap = new Map; // id -> resolve
|
|
327
|
+
|
|
103
328
|
|
|
329
|
+
|
|
330
|
+
//TODO replace by worker-loader when it will work in webpack 5, take a look to webpack config
|
|
331
|
+
// let csvWorkerFileAsString = require('./csv.worker.js');
|
|
332
|
+
// let worker = new Blob([AppRequestWorkerScript], {type: 'application/javascript'});
|
|
333
|
+
|
|
334
|
+
// angular.module('csvService', [
|
|
335
|
+
// 'itemDataProcessor'
|
|
336
|
+
// ])
|
|
337
|
+
|
|
338
|
+
// .service('csvService', ['itemsDataProcessing', 'PipeService', function(itemsDataProcessing, PipeService) {
|
|
339
|
+
|
|
340
|
+
// var self = this,
|
|
341
|
+
// this.appRequestAndProcessWorker = new Worker(URL.createObjectURL(worker));//TODO URL.createObjectURL - revoke isn't called
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
// this.appRequestAndProcessWorker = new Worker('./appRequestWorker.js');
|
|
346
|
+
// this.appRequestAndProcessWorker = new Worker(new URL('./appRequestWorker.js', import.meta.url));
|
|
347
|
+
// this.appRequestAndProcessWorker = new Worker('node_modules/@gudhub/core/umd/appRequestWorker.js');
|
|
348
|
+
// this.appRequestAndProcessWorker = new Worker('dist/appRequestWorker.built.js', import.meta.url);
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
// const workerBlob = new Blob([atob(AppRequestWorkerScript.split(',')[1])], { type: 'application/javascript' });
|
|
352
|
+
// const workerUrl = URL.createObjectURL(workerBlob);
|
|
353
|
+
// this.appRequestAndProcessWorker = new Worker(workerUrl);
|
|
354
|
+
|
|
355
|
+
this.appRequestAndProcessWorker = new AppRequestWorkerScript;
|
|
356
|
+
// this.appRequestAndProcessWorker = new Worker(
|
|
357
|
+
// // parcel bundler specific syntax. Check https://parceljs.org/features/bundle-inlining/
|
|
358
|
+
// {type: 'module'}
|
|
359
|
+
// );
|
|
360
|
+
// this.appRequestAndProcessWorker = new Worker('override_npm/gudhub/umd/appRequestWorker.js');
|
|
361
|
+
// this.appRequestAndProcessWorker = new AppRequestWorker();
|
|
362
|
+
|
|
363
|
+
// new Worker(new URL('./worker.js', import.meta.url));
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
this.appRequestAndProcessWorker.postMessage({ type: WORKER_EVENTS.INIT, gudhubSerialized: this.gudhub.serialized });
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
let self = this;
|
|
370
|
+
this.appRequestAndProcessWorker.onerror = function(e) {
|
|
371
|
+
// self.appRequestAndProcessWorker.terminate();
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
// console.error('Error in worker:', e);
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
// let self = this;
|
|
379
|
+
|
|
380
|
+
this.appRequestAndProcessWorker.onmessage = function(e) {
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
if (
|
|
387
|
+
e.data.type == WORKER_EVENTS.REQUEST_APP
|
|
388
|
+
) {
|
|
389
|
+
|
|
390
|
+
if (
|
|
391
|
+
self.resolveFnMap.has(e.data.id)
|
|
392
|
+
) {
|
|
393
|
+
let resolver = self.resolveFnMap.get(e.data.id);
|
|
394
|
+
|
|
395
|
+
resolver(e.data.data);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
// self.requestCache.set(id, new Promise);
|
|
400
|
+
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
// todo check this for new code
|
|
405
|
+
// todo outdated code, to remove
|
|
406
|
+
if (
|
|
407
|
+
e.data.type == WORKER_EVENTS.PROCESS_DATA
|
|
408
|
+
) {
|
|
409
|
+
// if (id == e.data.id) {
|
|
410
|
+
self.gudhub.itemProcessor.handleDiff(e.data.id, e.data.compareRes);
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
if (
|
|
414
|
+
e.data.viewListChanged ||
|
|
415
|
+
e.data.fieldListChanged
|
|
416
|
+
) {
|
|
417
|
+
self.gudhub.appProcessor.updateAppFieldsAndViews(e.data.newVersion);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
//here
|
|
424
|
+
|
|
425
|
+
// }
|
|
104
426
|
}
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
// worker.terminate();
|
|
434
|
+
|
|
435
|
+
// this.postMessage({id: e.data.id, compareRes: comparison});
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
// console.log('Data processed by worker:', e.data);
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
// worker.onerror = function(e) {
|
|
442
|
+
// // worker.terminate();
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
// // console.error('Error in worker:', e);
|
|
446
|
+
// };
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
//todo worker pool?
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
if (
|
|
454
|
+
this.isWithCache()
|
|
455
|
+
) {
|
|
456
|
+
// move here storeManager
|
|
457
|
+
//TODO store could be with different implementations - indexeddb, cacheapi, others
|
|
105
458
|
}
|
|
106
459
|
|
|
107
|
-
|
|
108
|
-
return new Promise((resolve, reject) => {
|
|
109
|
-
const request = indexedDB.open(this.dbName, this.dbVersion);
|
|
460
|
+
this.storeManager = new AppStoreManager;
|
|
110
461
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
462
|
+
// objectAssignWithOverride(this, indexDBService);
|
|
463
|
+
// objectAssignWithOverride(this, new AppStoreManager());
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
static [Symbol.hasInstance](instance) {
|
|
468
|
+
try {
|
|
469
|
+
if (instance instanceof IndexedDBAppService) return true;
|
|
470
|
+
// if (instance instanceof IndexedDBService) return true; //TODO requires multiple inheritance, thhink how to overcome it
|
|
471
|
+
return false;
|
|
472
|
+
} catch (error) {
|
|
473
|
+
return false;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
//TODO use IndexedDBFacade here
|
|
478
|
+
// indexDBAccess = new IndexedDBFacade;
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
isWithCache() {
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
async getApp(id) {//TODO -> get?
|
|
486
|
+
if (this.requestCache.has(id)) return this.requestCache.get(id); // по этому коду есть вопрос - вызовы getApp кешируются выше и тогда выходит возвращается старая версия?
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
let self = this;
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
let hasId = await this.has(id);
|
|
493
|
+
|
|
494
|
+
hasId = false;
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
if (
|
|
498
|
+
hasId
|
|
499
|
+
) {
|
|
500
|
+
|
|
501
|
+
// let promiseObject = Promise.
|
|
502
|
+
|
|
503
|
+
let cached = await this.getCached(id); // todo here should be merged with cached mergedChunk
|
|
504
|
+
|
|
505
|
+
// repetitive operation again, seems should be in getCached
|
|
506
|
+
let cachedMergedChunk = await this.chunkDataService.getCachedMergedChunk(id, cached.chunks);
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
// let mergedData = this.gudhub
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
cached.items_list = await this.gudhub.util.mergeChunks([
|
|
513
|
+
cachedMergedChunk,
|
|
514
|
+
cached,
|
|
515
|
+
]);
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
let getFromDBPrms = Promise.resolve(cached);
|
|
519
|
+
|
|
520
|
+
// let getFromDBPrms = await this.getCached(id); // todo here should be merged with cached mergedChunk
|
|
521
|
+
this.requestCache.set(id, getFromDBPrms);
|
|
522
|
+
|
|
523
|
+
this.appRequestAndProcessWorker.postMessage({ type: WORKER_EVENTS.PROCESS_DATA, id: id });
|
|
524
|
+
|
|
525
|
+
return getFromDBPrms;
|
|
526
|
+
} else {
|
|
527
|
+
// this.requestCache.set(id, new Promise);
|
|
528
|
+
|
|
529
|
+
// todo this doesnt work as expected. Tale a look to AppThroughWebWorkerService, it has corrct implementation
|
|
530
|
+
let prms = new Promise((resolve, reject) => {
|
|
531
|
+
self.resolveFnMap.set(id, resolve);
|
|
117
532
|
});
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
this.requestCache.set(id, prms);
|
|
536
|
+
|
|
537
|
+
this.appRequestAndProcessWorker.postMessage({ type: WORKER_EVENTS.REQUEST_APP, id: id });
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
return prms;
|
|
542
|
+
|
|
543
|
+
//todo somehow handle answer from worker
|
|
544
|
+
|
|
545
|
+
//maybe use mesage library to communicate with worker
|
|
118
546
|
}
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
// let worker = new Worker('./appRequestWorker.js');
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
// worker.postMessage({ type: 'init', gudhubSerialized: this.gudhub.serialized });
|
|
555
|
+
|
|
556
|
+
// Send the main data to be processed
|
|
557
|
+
// const mainData = { /* your data here */ };
|
|
558
|
+
// this.appRequestAndProcessWorker.postMessage({ type: 'processData', id: id });
|
|
559
|
+
|
|
560
|
+
// let self = this;
|
|
561
|
+
|
|
562
|
+
// worker.onmessage = function(e) {
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
// if (id == e.data.id) {
|
|
566
|
+
// self.gudhub.itemProcessor.handleDiff(e.data.id, e.data.compareRes);
|
|
567
|
+
// }
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
// // worker.terminate();
|
|
572
|
+
|
|
573
|
+
// // this.postMessage({id: e.data.id, compareRes: comparison});
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
// // console.log('Data processed by worker:', e.data);
|
|
577
|
+
// };
|
|
578
|
+
|
|
579
|
+
// worker.onerror = function(e) {
|
|
580
|
+
// // worker.terminate();
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
// // console.error('Error in worker:', e);
|
|
584
|
+
// };
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
// return getFromDBPrms;
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
//TODO page isnt loaded when indexeddb empty. Investigate getApp in IndexedDBAppService here
|
|
595
|
+
|
|
596
|
+
async getCached(id) {//TODO -> getFromStore?
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
return this.storeManager.getApp(id); //TODO investigate method name
|
|
600
|
+
|
|
601
|
+
let self = this;
|
|
602
|
+
|
|
603
|
+
let pr = new Promise(async (resolve, reject) => {
|
|
604
|
+
try {
|
|
605
|
+
await self.openDatabase();
|
|
606
|
+
|
|
607
|
+
const transaction = self.db.transaction(self.store, "readonly");
|
|
608
|
+
const store = transaction.objectStore(self.store);
|
|
609
|
+
|
|
610
|
+
const storeRequest = store.get(id);
|
|
611
|
+
|
|
612
|
+
storeRequest.onsuccess = (e) => {
|
|
613
|
+
|
|
614
|
+
let cachedData = e.target.result;
|
|
615
|
+
|
|
616
|
+
if (
|
|
617
|
+
!cachedData
|
|
618
|
+
) {
|
|
619
|
+
reject();
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
if (
|
|
623
|
+
cachedData
|
|
624
|
+
) {
|
|
625
|
+
resolve(cachedData);
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
storeRequest.onerror = reject;
|
|
630
|
+
} catch (error) {
|
|
631
|
+
reject();
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
return pr;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
async has(id) {
|
|
639
|
+
|
|
640
|
+
try {
|
|
641
|
+
|
|
642
|
+
return this.storeManager.hasApp(id);
|
|
643
|
+
} catch (error) {
|
|
644
|
+
debugger
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
async putApp(id, data) {
|
|
649
|
+
return this.storeManager.putApp(id, data);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
export class AppHttpWorkerService extends AppDataService {
|
|
654
|
+
constructor(req, conf, gudhub) {
|
|
655
|
+
super(req, conf, gudhub);
|
|
656
|
+
|
|
657
|
+
this.dataService = new AppHttpService(req, null, gudhub);
|
|
658
|
+
|
|
659
|
+
this.requestCache = new Map; // id -> promise ///TODO seems irrelevant to class IndexedDBManager (could be renamed to Facade already)
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
this.gudhub = gudhub;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
isWithCache() {
|
|
668
|
+
return false;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
async getAppWithoutProcessing(id) {
|
|
672
|
+
let data = await this.dataService.getAppWithoutProcessing(id);
|
|
673
|
+
|
|
674
|
+
await this.putApp(id, data);
|
|
675
|
+
|
|
676
|
+
return data;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
async getApp(id) {
|
|
680
|
+
if (this.requestCache.has(id)) return this.requestCache.get(id);
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
let resolver, rejecter;
|
|
684
|
+
|
|
685
|
+
let prms = new Promise((resolve, reject) => {
|
|
686
|
+
resolver = resolve;
|
|
687
|
+
rejecter = reject;
|
|
688
|
+
});
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
this.requestCache.set(id, prms);
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
let data = await this.dataService.getAppWithoutProcessing(id);
|
|
695
|
+
let processedData = await this.processRequestedApp(id, data);
|
|
696
|
+
|
|
697
|
+
resolver(processedData);
|
|
698
|
+
|
|
699
|
+
|
|
700
|
+
return processedData;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
async has(id) {
|
|
704
|
+
return false;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
async getCached(id) {
|
|
708
|
+
throw new Error;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
async putApp(id, data) {
|
|
712
|
+
throw new Error;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
// this means works with indexeddb and http from worker env
|
|
718
|
+
export class AppIndexedDBWorkerService extends AppDataService {
|
|
719
|
+
// todo set appropriate class from config !!!!!!!!!! this or AppHttpWorkerService
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
export class AppThroughWebWorkerService extends AppDataService {
|
|
723
|
+
constructor(req, conf, gudhub) {
|
|
724
|
+
super(req, conf, gudhub);
|
|
725
|
+
|
|
726
|
+
this.dataService = new AppHttpService(req, conf, gudhub);
|
|
727
|
+
|
|
728
|
+
this.requestCache = new Map; // id -> promise ///TODO seems irrelevant to class IndexedDBManager (could be renamed to Facade already)
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
this.gudhub = gudhub;
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
this.resolveFnMap = new Map; // id -> resolve
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
//todo worker pool?
|
|
738
|
+
this.appRequestAndProcessWorker = new AppRequestWorkerScript;
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
this.appRequestAndProcessWorker.postMessage({ type: WORKER_EVENTS.INIT, gudhubSerialized: this.gudhub.serialized });
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
let self = this;
|
|
746
|
+
this.appRequestAndProcessWorker.onerror = function(e) {
|
|
747
|
+
// self.appRequestAndProcessWorker.terminate();
|
|
748
|
+
// // worker.terminate();
|
|
749
|
+
// console.error('Error in worker:', e);
|
|
750
|
+
};
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
this.appRequestAndProcessWorker.onmessage = function(e) {
|
|
754
|
+
|
|
755
|
+
if (
|
|
756
|
+
e.data.type == WORKER_EVENTS.REQUEST_APP
|
|
757
|
+
) {
|
|
758
|
+
|
|
759
|
+
if (
|
|
760
|
+
self.resolveFnMap.has(e.data.id)
|
|
761
|
+
) {
|
|
762
|
+
let resolver = self.resolveFnMap.get(e.data.id);
|
|
763
|
+
|
|
764
|
+
resolver(e.data.data);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
if (
|
|
769
|
+
e.data.type == WORKER_EVENTS.PROCESS_DATA
|
|
770
|
+
) {
|
|
771
|
+
self.gudhub.itemProcessor.handleDiff(e.data.id, e.data.compareRes);
|
|
772
|
+
|
|
773
|
+
|
|
774
|
+
if (
|
|
775
|
+
e.data.viewListChanged ||
|
|
776
|
+
e.data.fieldListChanged
|
|
777
|
+
) {
|
|
778
|
+
self.gudhub.appProcessor.updateAppFieldsAndViews(e.data.newVersion);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
if (
|
|
785
|
+
this.isWithCache()
|
|
786
|
+
) {
|
|
787
|
+
// return false;
|
|
788
|
+
// move here storeManager
|
|
789
|
+
//TODO store could be with different implementations - indexeddb, cacheapi, others
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
this.storeManager = new AppStoreManager;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
static [Symbol.hasInstance](instance) {
|
|
797
|
+
try {
|
|
798
|
+
if (instance instanceof IndexedDBAppService) return true;
|
|
799
|
+
// if (instance instanceof IndexedDBService) return true; //TODO requires multiple inheritance, thhink how to overcome it
|
|
800
|
+
return false;
|
|
801
|
+
} catch (error) {
|
|
802
|
+
return false;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
isWithCache() {
|
|
807
|
+
return false;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
//TODO -> rename to get ? Also should be for all derived classes and class tree
|
|
811
|
+
async getApp(id) {
|
|
812
|
+
if (this.requestCache.has(id)) return this.requestCache.get(id); // по этому коду есть вопрос - вызовы getApp кешируются выше и тогда выходит возвращается старая версия?
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
let resolver, rejecter;
|
|
816
|
+
let prms = new Promise((resolve, reject) => {
|
|
817
|
+
resolver = resolve;
|
|
818
|
+
rejecter = reject;
|
|
819
|
+
});
|
|
820
|
+
|
|
821
|
+
this.resolveFnMap.set(id, resolver);
|
|
822
|
+
|
|
823
|
+
this.requestCache.set(id, prms);
|
|
824
|
+
|
|
825
|
+
this.appRequestAndProcessWorker.postMessage({ type: WORKER_EVENTS.REQUEST_APP, id: id });
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
|
|
829
|
+
return prms;
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
async getCached(id) {//TODO -> getFromStore?
|
|
833
|
+
return this.storeManager.getApp(id); //TODO investigate method name
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
async has(id) {
|
|
837
|
+
|
|
838
|
+
try {
|
|
839
|
+
|
|
840
|
+
return this.storeManager.hasApp(id);
|
|
841
|
+
} catch (error) {
|
|
842
|
+
debugger
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
async putApp(id, data) {
|
|
847
|
+
return this.storeManager.putApp(id, data);
|
|
848
|
+
}
|
|
119
849
|
}
|