@gudhub/core 1.2.4-beta.45 → 1.2.4-beta.47
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/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 +160 -163
- package/GUDHUB/AppProcessor/AppProcessor.js +6 -20
- package/GUDHUB/ChunksManager/ChunksManager.test.js +3 -0
- package/GUDHUB/DataService/AppDataService.js +1 -200
- package/GUDHUB/DataService/ChunkDataService.js +0 -4
- package/GUDHUB/DataService/IndexedDB/IndexedDBAppService.js +224 -263
- package/GUDHUB/DataService/IndexedDB/IndexedDBChunkService.js +3 -227
- package/GUDHUB/DataService/IndexedDB/IndexedDBService.js +124 -302
- package/GUDHUB/DataService/IndexedDB/StoreManager/BaseStoreManager.js +9 -36
- package/GUDHUB/DataService/IndexedDB/StoreManager/managers.js +4 -40
- package/GUDHUB/DataService/IndexedDB/appRequestWorker.js +23 -88
- package/GUDHUB/DataService/IndexedDB/consts.js +1 -3
- package/GUDHUB/DataService/IndexedDB/init.js +1 -1
- package/GUDHUB/DataService/IndexedDB/storeManagerConf/init.js +1 -1
- package/GUDHUB/DataService/export.js +73 -13
- package/GUDHUB/DataService/httpService/AppHttpService.js +5 -15
- package/GUDHUB/DataService/httpService/ChunkHttpService.js +35 -37
- package/GUDHUB/DataService/utils.js +24 -127
- package/GUDHUB/GHConstructor/createAngularModuleInstance.js +7 -4
- package/GUDHUB/GHConstructor/createClassInstance.js +8 -3
- package/GUDHUB/ItemProcessor/ItemProcessor.js +0 -18
- package/GUDHUB/Utils/Utils.js +0 -14
- package/GUDHUB/WebSocket/WebSocket.js +2 -2
- package/GUDHUB/api/AppApi.js +13 -13
- package/GUDHUB/api/ChunkApi.js +5 -5
- package/GUDHUB/config.js +11 -2
- package/GUDHUB/consts.js +6 -12
- package/GUDHUB/gudhub.js +7 -30
- package/GUDHUB/gudhubAppRequestWorker.js +1 -2
- package/dist/gudhub.es.js +8 -1
- package/dist/gudhub.umd.js +2 -2
- package/package.json +4 -2
- package/GUDHUB/ChunksManager/ChunksManager.js +0 -68
- package/indextest.html +0 -35
|
@@ -1,175 +1,29 @@
|
|
|
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 { IndexedDBManager, IndexedDBService } from "./IndexedDBService.js";
|
|
6
3
|
|
|
7
4
|
import { IndexedDBChunkService } from "./IndexedDBChunkService.js";
|
|
8
|
-
import { chunksConf } from "./chunkDataConf.js";
|
|
9
5
|
import { AppStoreManager } from "./StoreManager/managers.js";
|
|
10
|
-
import { dbName, dbVersion } from "./consts.js";
|
|
11
|
-
import { appsConf } from "./appDataConf.js";
|
|
12
6
|
import { chunksMergeConf } from "./storeManagerConf/chunkCacheStoreManagerConf.js";
|
|
13
7
|
|
|
14
8
|
|
|
9
|
+
// TODO remove query parameters and check build success
|
|
15
10
|
import AppRequestWorkerScript from '../../../dist/PARCEL_APP_REQUEST_WORKER_FILENAME.js?worker&inline';
|
|
16
11
|
|
|
17
|
-
//this should be global in project
|
|
18
|
-
// class IndexedDBFacade extends CacheService {
|
|
19
12
|
|
|
20
|
-
// }
|
|
21
13
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.storeName = storeName;
|
|
28
|
-
this.db = null;
|
|
29
|
-
this.queue = [];
|
|
30
|
-
this.isProcessing = false;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async openDB() {
|
|
34
|
-
if (this.db) return this.db;
|
|
35
|
-
|
|
36
|
-
return new Promise((resolve, reject) => {
|
|
37
|
-
const request = indexedDB.open(this.dbName, 1);
|
|
38
|
-
|
|
39
|
-
request.onupgradeneeded = (event) => {
|
|
40
|
-
const db = event.target.result;
|
|
41
|
-
if (!db.objectStoreNames.contains(this.storeName)) {
|
|
42
|
-
db.createObjectStore(this.storeName, { keyPath: 'id', autoIncrement: true });
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
request.onsuccess = (event) => {
|
|
47
|
-
this.db = event.target.result;
|
|
48
|
-
resolve(this.db);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
request.onerror = (event) => {
|
|
52
|
-
reject(event.target.error);
|
|
53
|
-
};
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async executeOperation(operation) {
|
|
58
|
-
await this.openDB();
|
|
59
|
-
return new Promise((resolve, reject) => {
|
|
60
|
-
const transaction = this.db.transaction(this.storeName, 'readwrite');
|
|
61
|
-
const store = transaction.objectStore(this.storeName);
|
|
62
|
-
|
|
63
|
-
transaction.oncomplete = () => resolve();
|
|
64
|
-
transaction.onerror = (event) => reject(event.target.error);
|
|
65
|
-
|
|
66
|
-
operation(store);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async enqueueOperation(operation) {
|
|
71
|
-
this.queue.push(operation);
|
|
72
|
-
|
|
73
|
-
if (!this.isProcessing) {
|
|
74
|
-
this.isProcessing = true;
|
|
75
|
-
while (this.queue.length > 0) {
|
|
76
|
-
const currentOperation = this.queue.shift();
|
|
77
|
-
try {
|
|
78
|
-
await this.executeOperation(currentOperation);
|
|
79
|
-
} catch (error) {
|
|
80
|
-
console.error('Operation failed:', error);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
this.isProcessing = false;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
class IndexedDBManager2 {
|
|
93
|
-
constructor(dbName, storeName) {
|
|
94
|
-
this.dbName = dbName;
|
|
95
|
-
this.storeName = storeName;
|
|
96
|
-
this.db = null;
|
|
97
|
-
this.queue = [];
|
|
98
|
-
this.isProcessing = false;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async openDB() {
|
|
102
|
-
if (this.db) return this.db;
|
|
103
|
-
|
|
104
|
-
return new Promise((resolve, reject) => {
|
|
105
|
-
const request = indexedDB.open(this.dbName, 1);
|
|
106
|
-
|
|
107
|
-
request.onupgradeneeded = (event) => {
|
|
108
|
-
const db = event.target.result;
|
|
109
|
-
if (!db.objectStoreNames.contains(this.storeName)) {
|
|
110
|
-
db.createObjectStore(this.storeName, { keyPath: 'id', autoIncrement: true });
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
request.onsuccess = (event) => {
|
|
115
|
-
this.db = event.target.result;
|
|
116
|
-
resolve(this.db);
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
request.onerror = (event) => {
|
|
120
|
-
reject(event.target.error);
|
|
121
|
-
};
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async executeOperation(operation) {
|
|
126
|
-
await this.openDB();
|
|
127
|
-
return new Promise((resolve, reject) => {
|
|
128
|
-
const transaction = this.db.transaction(this.storeName, 'readwrite');
|
|
129
|
-
const store = transaction.objectStore(this.storeName);
|
|
130
|
-
|
|
131
|
-
transaction.oncomplete = () => resolve();
|
|
132
|
-
transaction.onerror = (event) => reject(event.target.error);
|
|
133
|
-
|
|
134
|
-
operation(store);
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
async enqueueOperation(operation) {
|
|
139
|
-
this.queue.push(operation);
|
|
140
|
-
|
|
141
|
-
if (!this.isProcessing) {
|
|
142
|
-
this.isProcessing = true;
|
|
143
|
-
while (this.queue.length > 0) {
|
|
144
|
-
const currentOperation = this.queue.shift();
|
|
145
|
-
try {
|
|
146
|
-
await this.executeOperation(currentOperation);
|
|
147
|
-
} catch (error) {
|
|
148
|
-
console.error('Operation failed:', error);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
this.isProcessing = false;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
14
|
+
export let WORKER_EVENTS = {
|
|
15
|
+
INIT: 1,
|
|
16
|
+
REQUEST_APP: 2,
|
|
17
|
+
PROCESS_DATA: 3,
|
|
18
|
+
DECLINE_PROCESS_DATA_REQUEST: 4,
|
|
154
19
|
}
|
|
155
20
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
//todo андрей сказал чанки два раза грузятся
|
|
159
|
-
//при первой загрузке когда нет бд ничего не отображается
|
|
160
|
-
//андрей предлагает грохать бд если проблемы со сторами
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
// может поменять имя на StoreAppService???? потому что я уже сделал абстракцию
|
|
164
|
-
|
|
21
|
+
// old class for worker. Contains useful code therefore isnt removed
|
|
165
22
|
export class IndexedDBAppServiceForWorker extends AppDataService {
|
|
166
23
|
constructor(req, conf, gudhub) {
|
|
167
24
|
super(req, conf, gudhub);
|
|
168
25
|
|
|
169
|
-
this.dataService = new AppHttpService(req,
|
|
170
|
-
|
|
171
|
-
// let indexDBService = new IndexedDBService(conf);
|
|
172
|
-
// let indexDBAppStoreManager = new AppStoreManager;
|
|
26
|
+
this.dataService = new AppHttpService(req, null, gudhub);
|
|
173
27
|
|
|
174
28
|
this.requestCache = new Map; // id -> promise ///TODO seems irrelevant to class IndexedDBManager (could be renamed to Facade already)
|
|
175
29
|
|
|
@@ -185,7 +39,7 @@ export class IndexedDBAppServiceForWorker extends AppDataService {
|
|
|
185
39
|
|
|
186
40
|
|
|
187
41
|
//TODO objectAssignWithOverride here too?
|
|
188
|
-
// this.
|
|
42
|
+
// this.storeBackend = new IndexedDBManager('myDatabase', 'appsStore');
|
|
189
43
|
|
|
190
44
|
|
|
191
45
|
|
|
@@ -213,7 +67,7 @@ export class IndexedDBAppServiceForWorker extends AppDataService {
|
|
|
213
67
|
static [Symbol.hasInstance](instance) {
|
|
214
68
|
try {
|
|
215
69
|
if (instance instanceof IndexedDBAppServiceForWorker) return true;
|
|
216
|
-
if (instance instanceof IndexedDBService) return true; //TODO requires multiple inheritance, thhink how to overcome it
|
|
70
|
+
// if (instance instanceof IndexedDBService) return true; //TODO requires multiple inheritance, thhink how to overcome it
|
|
217
71
|
return false;
|
|
218
72
|
} catch (error) {
|
|
219
73
|
return false;
|
|
@@ -433,83 +287,28 @@ export class IndexedDBAppServiceForWorker extends AppDataService {
|
|
|
433
287
|
return pr;
|
|
434
288
|
}
|
|
435
289
|
|
|
436
|
-
async getCached(id) {
|
|
437
|
-
|
|
438
|
-
return this.storeManager.getApp(id); //TODO investigate method name
|
|
439
290
|
|
|
291
|
+
async has(id) {
|
|
440
292
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
let pr = new Promise(async (resolve, reject) => {
|
|
444
|
-
try {
|
|
445
|
-
await self.openDatabase();
|
|
446
|
-
|
|
447
|
-
const transaction = self.db.transaction(self.store, "readonly");
|
|
448
|
-
const store = transaction.objectStore(self.store);
|
|
293
|
+
try {
|
|
449
294
|
|
|
450
|
-
|
|
295
|
+
return this.storeManager.hasApp(id);
|
|
296
|
+
} catch (error) {
|
|
297
|
+
// debugger
|
|
298
|
+
}
|
|
299
|
+
}
|
|
451
300
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
let cachedData = e.target.result;
|
|
455
|
-
|
|
456
|
-
if (
|
|
457
|
-
!cachedData
|
|
458
|
-
) {
|
|
459
|
-
reject();
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
if (
|
|
463
|
-
cachedData
|
|
464
|
-
) {
|
|
465
|
-
resolve(cachedData);
|
|
466
|
-
}
|
|
467
|
-
};
|
|
468
|
-
|
|
469
|
-
storeRequest.onerror = reject;
|
|
470
|
-
} catch (error) {
|
|
471
|
-
reject();
|
|
472
|
-
}
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
return pr;
|
|
301
|
+
async getCached(id) {
|
|
302
|
+
return this.storeManager.getApp(id);
|
|
476
303
|
}
|
|
477
304
|
|
|
478
305
|
async putApp(id, data) {
|
|
479
306
|
return this.storeManager.putApp(id, data);
|
|
480
|
-
|
|
481
|
-
// try {
|
|
482
|
-
// await this.openDatabase();
|
|
483
|
-
|
|
484
|
-
// const transaction = this.db.transaction(this.store, "readwrite");
|
|
485
|
-
// const store = transaction.objectStore(this.store);
|
|
486
|
-
|
|
487
|
-
// store.put(data, id);
|
|
488
|
-
// } catch (error) {
|
|
489
|
-
|
|
490
|
-
// }
|
|
491
307
|
}
|
|
492
|
-
|
|
493
|
-
// duplicated code 2 times in 2 classes openDatabase
|
|
494
|
-
|
|
495
|
-
// async openDatabase() {
|
|
496
|
-
// if (this.db) return this.db;
|
|
497
|
-
|
|
498
|
-
// return new Promise((resolve, reject) => {
|
|
499
|
-
// const request = indexedDB.open(this.dbName, this.dbVersion);
|
|
500
|
-
|
|
501
|
-
// request.onsuccess = event => {
|
|
502
|
-
// this.db = event.target.result;
|
|
503
|
-
// resolve(this.db);
|
|
504
|
-
// };
|
|
505
|
-
// request.onerror = event => {
|
|
506
|
-
// reject(event.target.error);
|
|
507
|
-
// };
|
|
508
|
-
// });
|
|
509
|
-
// }
|
|
510
308
|
}
|
|
511
309
|
|
|
512
310
|
|
|
311
|
+
// this class means work directly with indexeddb without worker
|
|
513
312
|
export class IndexedDBAppService extends AppDataService {
|
|
514
313
|
constructor(req, conf, gudhub) {
|
|
515
314
|
super(req, conf, gudhub);
|
|
@@ -564,7 +363,7 @@ export class IndexedDBAppService extends AppDataService {
|
|
|
564
363
|
// new Worker(new URL('./worker.js', import.meta.url));
|
|
565
364
|
|
|
566
365
|
|
|
567
|
-
this.appRequestAndProcessWorker.postMessage({ type:
|
|
366
|
+
this.appRequestAndProcessWorker.postMessage({ type: WORKER_EVENTS.INIT, gudhubSerialized: this.gudhub.serialized });
|
|
568
367
|
|
|
569
368
|
|
|
570
369
|
let self = this;
|
|
@@ -585,7 +384,7 @@ export class IndexedDBAppService extends AppDataService {
|
|
|
585
384
|
|
|
586
385
|
|
|
587
386
|
if (
|
|
588
|
-
e.data.type ==
|
|
387
|
+
e.data.type == WORKER_EVENTS.REQUEST_APP
|
|
589
388
|
) {
|
|
590
389
|
|
|
591
390
|
if (
|
|
@@ -605,7 +404,7 @@ export class IndexedDBAppService extends AppDataService {
|
|
|
605
404
|
// todo check this for new code
|
|
606
405
|
// todo outdated code, to remove
|
|
607
406
|
if (
|
|
608
|
-
e.data.type ==
|
|
407
|
+
e.data.type == WORKER_EVENTS.PROCESS_DATA
|
|
609
408
|
) {
|
|
610
409
|
// if (id == e.data.id) {
|
|
611
410
|
self.gudhub.itemProcessor.handleDiff(e.data.id, e.data.compareRes);
|
|
@@ -651,6 +450,13 @@ export class IndexedDBAppService extends AppDataService {
|
|
|
651
450
|
//todo worker pool?
|
|
652
451
|
|
|
653
452
|
|
|
453
|
+
if (
|
|
454
|
+
this.isWithCache()
|
|
455
|
+
) {
|
|
456
|
+
// move here storeManager
|
|
457
|
+
//TODO store could be with different implementations - indexeddb, cacheapi, others
|
|
458
|
+
}
|
|
459
|
+
|
|
654
460
|
this.storeManager = new AppStoreManager;
|
|
655
461
|
|
|
656
462
|
// objectAssignWithOverride(this, indexDBService);
|
|
@@ -661,7 +467,7 @@ export class IndexedDBAppService extends AppDataService {
|
|
|
661
467
|
static [Symbol.hasInstance](instance) {
|
|
662
468
|
try {
|
|
663
469
|
if (instance instanceof IndexedDBAppService) return true;
|
|
664
|
-
if (instance instanceof IndexedDBService) return true; //TODO requires multiple inheritance, thhink how to overcome it
|
|
470
|
+
// if (instance instanceof IndexedDBService) return true; //TODO requires multiple inheritance, thhink how to overcome it
|
|
665
471
|
return false;
|
|
666
472
|
} catch (error) {
|
|
667
473
|
return false;
|
|
@@ -673,7 +479,7 @@ export class IndexedDBAppService extends AppDataService {
|
|
|
673
479
|
|
|
674
480
|
|
|
675
481
|
isWithCache() {
|
|
676
|
-
return
|
|
482
|
+
return true;
|
|
677
483
|
}
|
|
678
484
|
|
|
679
485
|
async getApp(id) {//TODO -> get?
|
|
@@ -685,9 +491,11 @@ export class IndexedDBAppService extends AppDataService {
|
|
|
685
491
|
|
|
686
492
|
let hasId = await this.has(id);
|
|
687
493
|
|
|
494
|
+
hasId = false;
|
|
495
|
+
|
|
688
496
|
|
|
689
497
|
if (
|
|
690
|
-
|
|
498
|
+
hasId
|
|
691
499
|
) {
|
|
692
500
|
|
|
693
501
|
// let promiseObject = Promise.
|
|
@@ -712,7 +520,7 @@ export class IndexedDBAppService extends AppDataService {
|
|
|
712
520
|
// let getFromDBPrms = await this.getCached(id); // todo here should be merged with cached mergedChunk
|
|
713
521
|
this.requestCache.set(id, getFromDBPrms);
|
|
714
522
|
|
|
715
|
-
this.appRequestAndProcessWorker.postMessage({ type:
|
|
523
|
+
this.appRequestAndProcessWorker.postMessage({ type: WORKER_EVENTS.PROCESS_DATA, id: id });
|
|
716
524
|
|
|
717
525
|
return getFromDBPrms;
|
|
718
526
|
} else {
|
|
@@ -725,8 +533,7 @@ export class IndexedDBAppService extends AppDataService {
|
|
|
725
533
|
|
|
726
534
|
this.requestCache.set(id, prms);
|
|
727
535
|
|
|
728
|
-
|
|
729
|
-
this.appRequestAndProcessWorker.postMessage({ type: 'requestApp', id: id });
|
|
536
|
+
this.appRequestAndProcessWorker.postMessage({ type: WORKER_EVENTS.REQUEST_APP, id: id });
|
|
730
537
|
|
|
731
538
|
|
|
732
539
|
|
|
@@ -835,49 +642,203 @@ export class IndexedDBAppService extends AppDataService {
|
|
|
835
642
|
} catch (error) {
|
|
836
643
|
debugger
|
|
837
644
|
}
|
|
645
|
+
}
|
|
838
646
|
|
|
839
|
-
|
|
840
|
-
|
|
647
|
+
async putApp(id, data) {
|
|
648
|
+
return this.storeManager.putApp(id, data);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
841
651
|
|
|
842
|
-
|
|
652
|
+
export class AppHttpWorkerService extends AppDataService {
|
|
653
|
+
constructor(req, conf, gudhub) {
|
|
654
|
+
super(req, conf, gudhub);
|
|
843
655
|
|
|
844
|
-
|
|
845
|
-
// } catch(e) {
|
|
846
|
-
// //todo check error type and then rethrow maybe here
|
|
656
|
+
this.dataService = new AppHttpService(req, null, gudhub);
|
|
847
657
|
|
|
848
|
-
//
|
|
849
|
-
|
|
658
|
+
this.requestCache = new Map; // id -> promise ///TODO seems irrelevant to class IndexedDBManager (could be renamed to Facade already)
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
this.gudhub = gudhub;
|
|
850
662
|
}
|
|
851
663
|
|
|
852
|
-
async putApp(id, data) { //TODO -> put?
|
|
853
|
-
return this.storeManager.putApp(id, data);
|
|
854
664
|
|
|
855
|
-
// try {
|
|
856
|
-
// const db = await this.openDatabase();
|
|
857
665
|
|
|
858
|
-
|
|
859
|
-
|
|
666
|
+
isWithCache() {
|
|
667
|
+
return false;
|
|
668
|
+
}
|
|
860
669
|
|
|
861
|
-
|
|
862
|
-
|
|
670
|
+
async getAppWithoutProcessing(id) {
|
|
671
|
+
let data = await this.dataService.getAppWithoutProcessing(id);
|
|
863
672
|
|
|
864
|
-
|
|
673
|
+
await this.putApp(id, data);
|
|
674
|
+
|
|
675
|
+
return data;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
async getApp(id) {
|
|
679
|
+
if (this.requestCache.has(id)) return this.requestCache.get(id);
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
let resolver, rejecter;
|
|
683
|
+
|
|
684
|
+
let prms = new Promise((resolve, reject) => {
|
|
685
|
+
resolver = resolve;
|
|
686
|
+
rejecter = reject;
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
this.requestCache.set(id, prms);
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
let data = await this.dataService.getAppWithoutProcessing(id);
|
|
694
|
+
let processedData = await this.processRequestedApp(id, data);
|
|
695
|
+
|
|
696
|
+
resolver(processedData);
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
return processedData;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
async has(id) {
|
|
703
|
+
return false;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
async getCached(id) {
|
|
707
|
+
throw new Error;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
async putApp(id, data) {
|
|
711
|
+
throw new Error;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
// this means works with indexeddb and http from worker env
|
|
717
|
+
export class AppIndexedDBWorkerService extends AppDataService {
|
|
718
|
+
// todo set appropriate class from config !!!!!!!!!! this or AppHttpWorkerService
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
export class AppThroughWebWorkerService extends AppDataService {
|
|
722
|
+
constructor(req, conf, gudhub) {
|
|
723
|
+
super(req, conf, gudhub);
|
|
724
|
+
|
|
725
|
+
this.dataService = new AppHttpService(req, conf, gudhub);
|
|
726
|
+
|
|
727
|
+
this.requestCache = new Map; // id -> promise ///TODO seems irrelevant to class IndexedDBManager (could be renamed to Facade already)
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
this.gudhub = gudhub;
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
this.resolveFnMap = new Map; // id -> resolve
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
//todo worker pool?
|
|
737
|
+
this.appRequestAndProcessWorker = new AppRequestWorkerScript;
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
this.appRequestAndProcessWorker.postMessage({ type: WORKER_EVENTS.INIT, gudhubSerialized: this.gudhub.serialized });
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
let self = this;
|
|
745
|
+
this.appRequestAndProcessWorker.onerror = function(e) {
|
|
746
|
+
// self.appRequestAndProcessWorker.terminate();
|
|
747
|
+
// // worker.terminate();
|
|
748
|
+
// console.error('Error in worker:', e);
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
this.appRequestAndProcessWorker.onmessage = function(e) {
|
|
753
|
+
|
|
754
|
+
if (
|
|
755
|
+
e.data.type == WORKER_EVENTS.REQUEST_APP
|
|
756
|
+
) {
|
|
757
|
+
|
|
758
|
+
if (
|
|
759
|
+
self.resolveFnMap.has(e.data.id)
|
|
760
|
+
) {
|
|
761
|
+
let resolver = self.resolveFnMap.get(e.data.id);
|
|
762
|
+
|
|
763
|
+
resolver(e.data.data);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
if (
|
|
768
|
+
e.data.type == WORKER_EVENTS.PROCESS_DATA
|
|
769
|
+
) {
|
|
770
|
+
self.gudhub.itemProcessor.handleDiff(e.data.id, e.data.compareRes);
|
|
771
|
+
|
|
772
|
+
|
|
773
|
+
if (
|
|
774
|
+
e.data.viewListChanged ||
|
|
775
|
+
e.data.fieldListChanged
|
|
776
|
+
) {
|
|
777
|
+
self.gudhub.appProcessor.updateAppFieldsAndViews(e.data.newVersion);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
if (
|
|
784
|
+
this.isWithCache()
|
|
785
|
+
) {
|
|
786
|
+
// return false;
|
|
787
|
+
// move here storeManager
|
|
788
|
+
//TODO store could be with different implementations - indexeddb, cacheapi, others
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
this.storeManager = new AppStoreManager;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
static [Symbol.hasInstance](instance) {
|
|
796
|
+
try {
|
|
797
|
+
if (instance instanceof IndexedDBAppService) return true;
|
|
798
|
+
// if (instance instanceof IndexedDBService) return true; //TODO requires multiple inheritance, thhink how to overcome it
|
|
799
|
+
return false;
|
|
800
|
+
} catch (error) {
|
|
801
|
+
return false;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
isWithCache() {
|
|
806
|
+
return false;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
//TODO -> rename to get ? Also should be for all derived classes and class tree
|
|
810
|
+
async getApp(id) {
|
|
811
|
+
if (this.requestCache.has(id)) return this.requestCache.get(id); // по этому коду есть вопрос - вызовы getApp кешируются выше и тогда выходит возвращается старая версия?
|
|
812
|
+
|
|
813
|
+
let prms = new Promise((resolve, reject) => {
|
|
814
|
+
self.resolveFnMap.set(id, resolve);
|
|
815
|
+
});
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
this.requestCache.set(id, prms);
|
|
819
|
+
|
|
820
|
+
this.appRequestAndProcessWorker.postMessage({ type: WORKER_EVENTS.REQUEST_APP, id: id });
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
return prms;
|
|
865
825
|
}
|
|
866
826
|
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
827
|
+
async getCached(id) {//TODO -> getFromStore?
|
|
828
|
+
return this.storeManager.getApp(id); //TODO investigate method name
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
async has(id) {
|
|
832
|
+
|
|
833
|
+
try {
|
|
834
|
+
|
|
835
|
+
return this.storeManager.hasApp(id);
|
|
836
|
+
} catch (error) {
|
|
837
|
+
debugger
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
async putApp(id, data) {
|
|
842
|
+
return this.storeManager.putApp(id, data);
|
|
843
|
+
}
|
|
883
844
|
}
|