@gudhub/core 1.2.4-beta.4 → 1.2.4-beta.6

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.
@@ -319,6 +319,10 @@ export class AppProcessor {
319
319
  }
320
320
  }
321
321
 
322
+ handleAppChange(v1, v2) {
323
+ // generate required events etc, do job
324
+ }
325
+
322
326
  clearAppProcessor() {
323
327
  this.getAppListPromises = null;
324
328
  this.getAppPromises = {};
@@ -11,13 +11,15 @@ import { IndexedDBService } from "./IndexedDBService.js";
11
11
  // }
12
12
 
13
13
  export class IndexedDBAppService extends AppDataService {
14
- constructor(req, conf) {
14
+ constructor(req, conf, gudhub) {
15
15
  super(req, conf);
16
16
 
17
17
  this.dataService = new AppHttpService(req);
18
18
 
19
19
  let indexDBService = new IndexedDBService(conf);
20
20
 
21
+ this.gudhub = gudhub;
22
+
21
23
  objectAssignWithOverride(this, indexDBService);
22
24
  }
23
25
 
@@ -28,7 +30,7 @@ export class IndexedDBAppService extends AppDataService {
28
30
  if (instance instanceof IndexedDBService) return true; //TODO requires multiple inheritance, thhink how to overcome it
29
31
  return false;
30
32
  } catch (error) {
31
- return false;
33
+ return false;
32
34
  }
33
35
  }
34
36
 
@@ -39,55 +41,54 @@ export class IndexedDBAppService extends AppDataService {
39
41
  async getApp(id) {
40
42
  if (this.requestCache.has(id)) return this.requestCache.get(id);
41
43
 
42
- let dataServiceRequest = this.dataService.getApp(id);
44
+ let self = this;
43
45
 
44
- dataServiceRequest.then(data => this.putApp(id, data));
45
-
46
- try {
47
- let self = this;
48
-
49
- let pr = new Promise(async (resolve, reject) => {
50
- try {
51
- const db = await self.openDatabase();
52
- const transaction = db.transaction(self.store, "readonly");
53
- const store = transaction.objectStore(self.store);
54
-
55
- const storeRequest = store.get(id);
46
+ let dataServiceRequest = this.dataService.getApp(id);
56
47
 
57
- storeRequest.onsuccess = (e) => {
58
-
59
- let cachedData = e.target.result;
60
-
61
- if (
62
- !cachedData
63
- ) {
64
- reject();
65
- }
48
+ let pr = new Promise(async (resolve, reject) => {
49
+ try {
50
+ const db = await self.openDatabase();
51
+ const transaction = db.transaction(self.store, "readonly");
52
+ const store = transaction.objectStore(self.store);
66
53
 
67
- if (
68
- cachedData
69
- ) {
70
- resolve(cachedData);
71
- }
72
- };
73
-
74
- storeRequest.onerror = reject
75
- } catch (error) {
76
- reject();
77
- }
78
- });
79
-
80
- self.requestCache.set(id, pr);
54
+ const storeRequest = store.get(id);
81
55
 
82
- await pr;
56
+ storeRequest.onsuccess = (e) => {
57
+
58
+ let cachedData = e.target.result;
83
59
 
84
- return pr;
85
-
86
- } catch(e) {
87
- this.requestCache.set(id, dataServiceRequest);
60
+ if (
61
+ !cachedData
62
+ ) {
63
+ dataServiceRequest.then(resolve, reject);
64
+ dataServiceRequest.then(data => self.putApp(id, data));
65
+ }
66
+
67
+ if (
68
+ cachedData
69
+ ) {
70
+ resolve(cachedData);
71
+
72
+ dataServiceRequest.then(data => {
73
+ self.gudhub.processAppUpd(data, cachedData);
74
+ self.putApp(id, data);
75
+ });
76
+ }
77
+ };
78
+
79
+ storeRequest.onerror = () => {
80
+ dataServiceRequest.then(resolve, reject);
81
+ dataServiceRequest.then(data => self.putApp(id, data));
82
+ }
83
+ } catch (error) {
84
+ dataServiceRequest.then(resolve, reject);
85
+ dataServiceRequest.then(data => self.putApp(id, data));
86
+ }
87
+ });
88
88
 
89
- return dataServiceRequest;
90
- }
89
+ self.requestCache.set(id, pr);
90
+
91
+ return pr;
91
92
  }
92
93
 
93
94
  async putApp(id, data) {
@@ -4,7 +4,7 @@ import { objectAssignWithOverride } from "../utils.js";
4
4
  import { HttpService } from "./HttpService.js";
5
5
 
6
6
  export class AppHttpService extends AppDataService {
7
- constructor(req, conf) {
7
+ constructor(req, conf, gudhub) {
8
8
  super();
9
9
 
10
10
  this.appApi = new AppAPI(req);
@@ -118,6 +118,13 @@ export class ItemProcessor {
118
118
  return items;
119
119
  }
120
120
 
121
+ handleItemsChange(v1, v2) {
122
+ let compareRes = this.util.compareItems(v1.items_list, v2.items_list);
123
+
124
+ this.updateItemsInStorage(v1.app_id, compareRes.diff_src_items);
125
+ this.addItemsToStorage(v1.app_id, compareRes.new_src_items);
126
+ }
127
+
121
128
  async deleteItemsFromStorage(app_id, itemsForDelete = []) {
122
129
  const app = await this.appProcessor.getApp(app_id);
123
130
  if (app) {
package/GUDHUB/gudhub.js CHANGED
@@ -74,7 +74,7 @@ export class GudHub {
74
74
  this.chunksManager,
75
75
  this.util,
76
76
  options.activateSW,
77
- new AppDataService(this.req, appDataServiceConf),
77
+ new AppDataService(this.req, appDataServiceConf, this),
78
78
  );
79
79
  this.itemProcessor = new ItemProcessor(
80
80
  this.storage,
@@ -234,6 +234,11 @@ export class GudHub {
234
234
  return this.util.sortItems(items, options);
235
235
  }
236
236
 
237
+ processAppUpd(v1, v2) {
238
+ this.itemProcessor.handleItemsChange(v1, v2);
239
+ this.appProcessor.handleAppChange(v1, v2);
240
+ }
241
+
237
242
  jsonToItems(json, map) {
238
243
  return this.util.jsonToItems(json, map);
239
244
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gudhub/core",
3
- "version": "1.2.4-beta.4",
3
+ "version": "1.2.4-beta.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -17,7 +17,7 @@
17
17
  "esmodules": true
18
18
  },
19
19
  "exclude": [
20
- "plugin-transform-classes"
20
+ "babel-plugin-transform-classes"
21
21
  ]
22
22
  }
23
23
  ]
@@ -47,7 +47,6 @@
47
47
  "express": "^4.17.1",
48
48
  "jsdom": "^20.0.0",
49
49
  "mocha": "^8.1.2",
50
- "parcel-bundler": "^1.12.5",
51
50
  "should": "^13.2.3",
52
51
  "sinon": "^14.0.0",
53
52
  "webpack": "^5.91.0"