@gudhub/core 1.2.3 → 1.2.4-beta.1

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.
@@ -0,0 +1,31 @@
1
+ {
2
+ "version": "0.2.0",
3
+ "configurations": [
4
+ {
5
+ "name": "Launch Program",
6
+ "program": "${workspaceFolder}/app.js",
7
+ "request": "launch",
8
+ "skipFiles": [
9
+ "<node_internals>/**"
10
+ ],
11
+ "type": "node"
12
+ },
13
+ {
14
+ "type": "node",
15
+ "request": "launch",
16
+ "runtimeVersion": "16",
17
+ "name": "Launch Program",
18
+ "skipFiles": [
19
+ "<node_internals>/**"
20
+ ],
21
+ "program": "${workspaceFolder}/index.js"
22
+ },
23
+ {
24
+ "type": "node-terminal",
25
+ "name": "Run Script: test",
26
+ "request": "launch",
27
+ "command": "npm run test",
28
+ "cwd": "${workspaceFolder}"
29
+ }
30
+ ]
31
+ }
@@ -78,10 +78,6 @@ export class AppProcessor {
78
78
  }
79
79
  }
80
80
 
81
- async getAppApi(app_id) {
82
- return this.dataService.getApp(app_id);
83
- }
84
-
85
81
  getAppListFromStorage() {
86
82
  return this.storage.getAppsList();
87
83
  }
@@ -186,7 +182,7 @@ export class AppProcessor {
186
182
  for (const app_id of apps_id) {
187
183
  if (app_id != undefined) {
188
184
  try {
189
- const app = await this.getAppApi(app_id);
185
+ const app = await this.dataService.getApp(app_id);
190
186
  if (app) {
191
187
  app.items_object = {};
192
188
 
@@ -259,7 +255,7 @@ export class AppProcessor {
259
255
  let app = this.getAppFromStorage(app_id);
260
256
  if (app) return app;
261
257
 
262
- let receivedApp = await this.getAppApi(app_id);
258
+ let receivedApp = await this.dataService.getApp(app_id);
263
259
  if (!receivedApp) return;
264
260
 
265
261
  //!!! temporary check !!!! if app has chanks property then we start getting it
@@ -23,9 +23,13 @@ export class IndexedDBAppService extends AppDataService {
23
23
 
24
24
 
25
25
  static [Symbol.hasInstance](instance) {
26
- if (instance instanceof IndexedDBService) return true;
27
- if (instance.chunkDataService instanceof IndexedDBAppService) return true;
26
+ try {
27
+ if (instance instanceof IndexedDBAppService) return true;
28
+ if (instance instanceof IndexedDBService) return true; //TODO requires multiple inheritance, thhink how to overcome it
29
+ return false;
30
+ } catch (error) {
28
31
  return false;
32
+ }
29
33
  }
30
34
 
31
35
  //TODO use IndexedDBFacade here
@@ -33,39 +37,55 @@ export class IndexedDBAppService extends AppDataService {
33
37
 
34
38
 
35
39
  async getApp(id) {
40
+ if (this.requestCache.has(id)) return this.requestCache.get(id);
41
+
36
42
  let dataServiceRequest = this.dataService.getApp(id);
37
43
 
38
44
  dataServiceRequest.then(data => this.putApp(id, data));
39
45
 
40
46
  try {
41
- const db = await this.openDatabase();
42
- const transaction = db.transaction(this.store, "readonly");
43
- const store = transaction.objectStore(this.store);
44
-
45
- const storeRequest = store.get(id);
46
-
47
- return await new Promise((resolve, reject) => {
48
- storeRequest.onsuccess = (e) => {
49
-
50
- let cachedData = e.target.result;
51
-
52
- if (
53
- !cachedData
54
- ) {
55
- reject();
56
- }
57
-
58
- if (
59
- cachedData
60
- ) {
47
+ let self = this;
61
48
 
62
- resolve(cachedData);
63
- }
64
- };
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);
56
+
57
+ storeRequest.onsuccess = (e) => {
65
58
 
66
- storeRequest.onerror = reject
59
+ let cachedData = e.target.result;
60
+
61
+ if (
62
+ !cachedData
63
+ ) {
64
+ reject();
65
+ }
66
+
67
+ if (
68
+ cachedData
69
+ ) {
70
+ resolve(cachedData);
71
+ }
72
+ };
73
+
74
+ storeRequest.onerror = reject
75
+ } catch (error) {
76
+ reject();
77
+ }
67
78
  });
79
+
80
+ self.requestCache.set(id, pr);
81
+
82
+ await pr;
83
+
84
+ return pr;
85
+
68
86
  } catch(e) {
87
+ this.requestCache.set(id, dataServiceRequest);
88
+
69
89
  return dataServiceRequest;
70
90
  }
71
91
  }
@@ -34,9 +34,13 @@ export class IndexedDBChunkService extends ChunkDataService {
34
34
 
35
35
 
36
36
  static [Symbol.hasInstance](instance) {
37
- if (instance instanceof IndexedDBService) return true;
38
- if (instance.chunkDataService instanceof IndexedDBChunkService) return true;
39
- return false;
37
+ try {
38
+ if (instance instanceof IndexedDBChunkService) return true;
39
+ if (instance instanceof IndexedDBService) return true; //TODO requires multiple inheritance, thhink how to overcome it
40
+ return false;
41
+ } catch (error) {
42
+ return false;
43
+ }
40
44
  }
41
45
 
42
46
 
@@ -57,41 +61,59 @@ export class IndexedDBChunkService extends ChunkDataService {
57
61
 
58
62
 
59
63
  async getChunk(app_id, id) {
64
+ if (this.requestCache.has(id)) return this.requestCache.get(id);
65
+
60
66
  try {
61
- const db = await this.openDatabase();
62
- const transaction = db.transaction(this.store, "readonly");
63
- const store = transaction.objectStore(this.store);
64
-
65
- const storeRequest = store.get(id);
66
-
67
- return await new Promise((resolve, reject) => {
68
- storeRequest.onsuccess = (e) => {
69
-
70
- let cachedData = e.target.result;
71
-
72
- if (
73
- !cachedData
74
- ) {
75
- reject();
76
- }
77
-
78
- if (
79
- cachedData
80
- ) {
67
+ let self = this;
68
+
69
+ let pr = new Promise(async (resolve, reject) => {
70
+ try {
71
+ const db = await self.openDatabase();
72
+ const transaction = db.transaction(self.store, "readonly");
73
+ const store = transaction.objectStore(self.store);
74
+
75
+ const storeRequest = store.get(id);
81
76
 
82
- resolve(cachedData);
83
- }
84
- };
77
+ storeRequest.onsuccess = (e) => {
85
78
 
86
- storeRequest.onerror = reject
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
+
95
+ storeRequest.onerror = reject
96
+ } catch (error) {
97
+ reject();
98
+ }
87
99
  });
100
+
101
+ self.requestCache.set(id, pr);
102
+
103
+ await pr;
104
+
105
+ return pr;
106
+
88
107
  } catch(e) {
89
- let res = await this.dataService.getChunk(app_id, id);
108
+ let reqPrms = this.dataService.getChunk(app_id, id);
90
109
 
91
- await this.putChunk(id, res);
92
-
110
+ this.requestCache.set(id, reqPrms);
111
+
112
+ let res = await reqPrms;
113
+
114
+ this.putChunk(id, res);
93
115
 
94
- return res;
116
+ return reqPrms;
95
117
  }
96
118
  }
97
119
 
@@ -3,5 +3,7 @@ export class IndexedDBService {
3
3
  this.store = conf.store;
4
4
  this.dbName = conf.dbName;
5
5
  this.dbVersion = conf.dbVersion;
6
+
7
+ this.requestCache = new Map; // id -> promise
6
8
  }
7
9
  }
@@ -24,8 +24,12 @@ export class AppHttpService extends AppDataService {
24
24
  }
25
25
 
26
26
  static [Symbol.hasInstance](instance) {
27
- if (instance instanceof AppHttpService) return true;
28
- if (instance.chunkDataService instanceof HttpService) return true;
29
- return false;
27
+ try {
28
+ if (instance instanceof AppHttpService) return true;
29
+ if (instance instanceof HttpService) return true; //TODO requires multiple inheritance, thhink how to overcome it
30
+ return false;
31
+ } catch (error) {
32
+ return false;
33
+ }
30
34
  }
31
35
  }
@@ -25,8 +25,12 @@ export class ChunkHttpService extends ChunkDataService {
25
25
 
26
26
 
27
27
  static [Symbol.hasInstance](instance) {
28
- if (instance instanceof ChunkHttpService) return true;
29
- if (instance.chunkDataService instanceof HttpService) return true;
30
- return false;
28
+ try {
29
+ if (instance instanceof ChunkHttpService) return true;
30
+ if (instance instanceof HttpService) return true; //TODO requires multiple inheritance, thhink how to overcome it
31
+ return false;
32
+ } catch (error) {
33
+ return false;
34
+ }
31
35
  }
32
36
  }
@@ -5,7 +5,7 @@ export class AppAPI {
5
5
 
6
6
  async getApp(app_id) {
7
7
  return this.req.get({
8
- url: `${this.req.root}/api/app/get`,
8
+ url: `/api/app/get`,
9
9
  params: {
10
10
  app_id: app_id,
11
11
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gudhub/core",
3
- "version": "1.2.3",
3
+ "version": "1.2.4-beta.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {