@gudhub/core 1.1.57 → 1.1.59

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.
@@ -98,6 +98,17 @@ export class FieldProcessor {
98
98
  return null;
99
99
  }
100
100
 
101
+ async getFieldIdByNameSpace(app_id, name_space) {
102
+ const app = await this.appProcessor.getApp(app_id);
103
+ if(!app) return null;
104
+ for(let i = 0; i < app.field_list.length; i++) {
105
+ if(app.field_list[i].name_space == name_space) {
106
+ return app.field_list[i].field_id;
107
+ }
108
+ }
109
+ return null;
110
+ }
111
+
101
112
  //!!!!! Shou Be Renamed to getFields() !!!!!!!
102
113
  async getFieldModels(app_id) {
103
114
  const app = await this.appProcessor.getApp(app_id);
@@ -12,6 +12,11 @@ describe("FIELD PROCESSOR", async function() {
12
12
  (typeof fieldModel).should.equal('object');
13
13
  });
14
14
 
15
+ it("GET FIELD ID BY NAMESPACE / should return a field id", async function() {
16
+ const fieldId = await gudhub.getFieldIdByNameSpace(16259, 'name');
17
+ fieldId.should.equal(254056);
18
+ });
19
+
15
20
  it('GET FIELD VALUE / should return a field value', async () => {
16
21
  let value = await gudhub.getFieldValue(16259, 1064673, 254055);
17
22
  value.should.equal('Hall up');
@@ -68,9 +68,8 @@ describe("PipeService", () => {
68
68
  gudhub
69
69
  .emit("test", { app_id: 4, item_id: 3, field_id: 2 }, {"message" : "this is the data"})
70
70
  .on("test", { app_id: 4, item_id: 3, field_id: 2 }, (event, data) => {
71
- incomeData = data.message;
71
+ data.message.should.equal("this is the data");
72
72
  });
73
- incomeData.should.equal("this is the data");
74
73
  });
75
74
 
76
75
 
@@ -17,26 +17,25 @@ export default class AppsTemplateService {
17
17
  let currentStep = 0;
18
18
  self.createApps(pack, (status) => {
19
19
  currentStep += 1;
20
- progressCallback.call(this, {
20
+ progressCallback ? progressCallback.call(this, {
21
21
  percent: currentStep * stepPercents,
22
22
  status
23
- })
23
+ }) : null;
24
24
  }).then(success => {
25
25
  self.createItems(success, maxNumberOfInsstalledItems, (status) => {
26
26
  if (typeof status === 'string') {
27
27
  currentStep += 1;
28
- progressCallback.call(this, {
28
+ progressCallback ? progressCallback.call(this, {
29
29
  percent: currentStep * stepPercents,
30
30
  status
31
- })
31
+ }) : null;
32
32
  } else if (typeof status === 'object') {
33
- progressCallback.call(this, {
33
+ progressCallback ? progressCallback.call(this, {
34
34
  status: 'Done',
35
35
  apps: status
36
- })
36
+ }) : null;
37
+ resolve();
37
38
  }
38
- }).then(() => {
39
- resolve();
40
39
  })
41
40
  })
42
41
  });
@@ -61,64 +60,64 @@ export default class AppsTemplateService {
61
60
  fields: []
62
61
  }
63
62
  }).filter((item, index) => index <= MAX_NUMBER_OF_INSTALLED_ITEMS);
64
-
65
63
  self.gudhub.addNewItems(app.app_id, items).then(items => {
66
64
  callback ? callback.call(this, `ADD NEW ITEMS: ${result_app.app_name} (Items steps)`) : null;
67
65
 
68
- if (items.length === 0) {
69
- callback ? callback.call(this, `NO ITEMS TO REPLACE VALUE: ${result_app.app_name} (Items steps)`) : null;
70
- app_resolve();
71
- }
72
-
73
66
  app.items_list = items;
74
67
  self._updateMap(app.items_list, source_app.items_list);
75
68
  self._addFieldValue(source_app.items_list, app.items_list, self.appsConnectingMap);
76
69
 
77
70
  createsItems.push(app);
78
71
 
79
- if (self.appsConnectingMap.apps.length === createsItems.length) {
80
- createsItems.forEach(app => {
81
- app.items_list.forEach(item => {
82
- item.fields.forEach(field_item => {
83
- self.appsConnectingMap.fields.forEach(field_map => {
84
- if (field_item.field_id === field_map.old_field_id) {
85
- field_item.field_id = field_map.new_field_id;
86
- field_item.element_id = field_map.new_field_id;
87
- }
88
- })
89
- })
90
- })
91
- });
92
-
93
- self.deleteField(createsItems);
94
-
95
- self.replaceValue(createsItems, self.appsConnectingMap).then(() => {
96
- callback ? callback.call(this, `REPLACE VALUE: ${result_app.app_name} (Items steps)`) : null;
97
- createsItems.forEach(created_app => {
98
- let newItems = created_app.items_list.map(item => {
99
- item.fields.forEach(field => {
100
- delete field.data_id;
101
- });
102
- return item;
103
- });
104
-
105
- self.gudhub.updateItems(created_app.app_id, newItems).then(() => {
106
- app_resolve();
107
- })
108
- })
109
- });
110
- }
72
+ app_resolve();
111
73
  });
112
74
  });
113
75
  }));
114
76
  });
115
77
 
116
78
  Promise.all(promises).then(() => {
117
- let apps = create_apps.map(app => {
118
- return app.app_id;
79
+
80
+ createsItems.forEach(app => {
81
+ app.items_list.forEach(item => {
82
+ item.fields.forEach(field_item => {
83
+ self.appsConnectingMap.fields.forEach(field_map => {
84
+ if (field_item.field_id === field_map.old_field_id) {
85
+ field_item.field_id = field_map.new_field_id;
86
+ field_item.element_id = field_map.new_field_id;
87
+ }
88
+ })
89
+ })
90
+ })
91
+ });
92
+
93
+ self.deleteField(createsItems);
94
+
95
+ self.replaceValue(createsItems, self.appsConnectingMap).then(() => {
96
+
97
+ const promises = [];
98
+
99
+ createsItems.forEach(created_app => {
100
+ promises.push(new Promise(resolve => {
101
+ let newItems = created_app.items_list.map(item => {
102
+ item.fields.forEach(field => {
103
+ delete field.data_id;
104
+ });
105
+ return item;
106
+ });
107
+
108
+ self.gudhub.updateItems(created_app.app_id, newItems).then(() => {
109
+ callback ? callback.call(this, `REPLACE VALUE: ${created_app.app_name} (Items steps)`) : null;
110
+ resolve();
111
+ })
112
+ }));
113
+ });
114
+
115
+ Promise.all(promises).then(() => {
116
+ callback.call(this, createsItems);
117
+ resolve();
119
118
  });
120
- callback.call(this, apps);
121
- resolve();
119
+
120
+ });
122
121
  })
123
122
  })
124
123
  }
@@ -185,26 +184,30 @@ export default class AppsTemplateService {
185
184
  documentInstallerHelper(appId, items, elementId) {
186
185
  const self = this;
187
186
  return new Promise(async (resolve) => {
188
- items.forEach(item => {
187
+ for(const item of items) {
189
188
  const itemId = item.item_id;
190
189
  const field = item.fields.find(field => field.element_id === elementId);
191
190
 
192
191
  if (field && field.field_value && field.field_value.length > 0) {
193
- self.gudhub.getDocument({
192
+ const document = await self.gudhub.getDocument({
194
193
  _id: field.field_value
195
- }).then(document => {
196
- self.gudhub.createDocument({
194
+ });
195
+
196
+ if(document && document.data) {
197
+
198
+ const newDocument = await self.gudhub.createDocument({
197
199
  app_id: appId,
198
200
  item_id: itemId,
199
201
  element_id: elementId,
200
202
  data: document.data
201
- }).then(new_document => {
202
- field.field_value = new_document._id;
203
- resolve();
204
- })
205
- })
203
+ });
204
+
205
+ field.field_value = newDocument._id;
206
+
207
+ }
206
208
  }
207
- });
209
+ }
210
+ resolve();
208
211
  });
209
212
  }
210
213
 
@@ -21,6 +21,7 @@ import { compiler } from "./json_constructor/json_constructor.js";
21
21
  import AppsTemplateService from "./AppsTemplateService/AppsTemplateService.js";
22
22
  import { FileHelper } from "./FIleHelper/FileHelper.js";
23
23
  import { compareObjects } from "./compareObjects/compareObjects.js";
24
+ import { dynamicPromiseAll } from "./dynamicPromiseAll/dynamicPromiseAll.js";
24
25
 
25
26
  export class Utils {
26
27
  constructor(gudhub) {
@@ -206,4 +207,8 @@ export class Utils {
206
207
  callback(diff);
207
208
  });
208
209
  }
210
+
211
+ dynamicPromiseAll(promisesArray) {
212
+ return dynamicPromiseAll(promisesArray);
213
+ }
209
214
  }
@@ -0,0 +1,49 @@
1
+ export async function dynamicPromiseAll(promises) {
2
+
3
+ await Promise.all(promises);
4
+
5
+ let allDone = true;
6
+
7
+ for(const promise of promises) {
8
+ const result = await _checkPromiseStatus(promise);
9
+ if(result.state === 'pending') {
10
+ allDone = false;
11
+ break;
12
+ }
13
+ if(result.state === 'rejected') {
14
+ throw result.reason;
15
+ break;
16
+ }
17
+ }
18
+
19
+ if(allDone) {
20
+ return true;
21
+ }
22
+
23
+ return dynamicPromiseAll(promises);
24
+
25
+ }
26
+
27
+ function _checkPromiseStatus(promise) {
28
+
29
+ const pending = {
30
+ state: 'pending',
31
+ };
32
+
33
+ return Promise.race([promise, pending]).then(
34
+ (value) => {
35
+ if (value === pending) {
36
+ return value;
37
+ }
38
+ return {
39
+ state: 'resolved',
40
+ value
41
+ };
42
+ },
43
+ (reason) => ({
44
+ state: 'rejected',
45
+ reason
46
+ })
47
+ );
48
+ }
49
+
@@ -114,16 +114,19 @@ export function compiler(scheme, item, util, variables, appId) {
114
114
 
115
115
  case "function":
116
116
  if(typeof scheme.function === 'function') {
117
- let result = scheme.function(item, appId, ...scheme.args);
117
+ let result = scheme.function(item, appId, util.gudhub, ...scheme.args);
118
118
  return result;
119
119
  } else {
120
- const func = new Function('item, appId', 'return (async ' + scheme.function + ')(item, appId)');
121
- let result = await func(item, appId);
120
+ const func = new Function('item, appId, gudhub', 'return (async ' + scheme.function + ')(item, appId, gudhub)');
121
+ let result = await func(item, appId, util.gudhub);
122
122
  return result;
123
123
  }
124
124
 
125
125
  case "field_value":
126
126
  default:
127
+ if(!scheme.field_id && scheme.name_space) {
128
+ scheme.field_id = await util.gudhub.getFieldIdByNameSpace(appId, scheme.name_space);
129
+ }
127
130
  if (Boolean(Number(scheme.interpretation))) {
128
131
  let interpretatedValue = await util.gudhub.getInterpretationById(Number(appId), Number(item.item_id), Number(scheme.field_id), 'value');
129
132
  return interpretatedValue;
@@ -20,13 +20,14 @@ describe("JSON CONSTRUCTOR", function () {
20
20
  gudhub.ghconstructor.initJsdomWindow(window);
21
21
 
22
22
  it("JSON FROM ONE APP : Here we construct simple json from one App", async function () {
23
- this.timeout(4000);
23
+ this.timeout(5000);
24
24
  //-- checking if json was generated properly
25
25
  let json = await gudhub.jsonConstructor(fishtank_scheme);
26
26
  json.fishtank[0].should.have.property("name", "Big Fish Tank");
27
27
  json.fishtank[0].should.have.property("state", "Normal ");
28
28
  });
29
29
  it("CHECK INTERPRETATION VALUE FOR FILES: output: we should get url's", async function () {
30
+ this.timeout(5000);
30
31
  //-- checking interpretation mode
31
32
  let json = await gudhub.jsonConstructor(fishtank_scheme);
32
33
  json.fishtank[0].should.have.property("image","https://gudhub.com/userdata/16259/809199.jpg,https://gudhub.com/userdata/16259/811768.png");
@@ -34,6 +35,7 @@ describe("JSON CONSTRUCTOR", function () {
34
35
  json.fishtank[0].should.have.property("notes","https://gudhub.com/userdata/16259/811770.html?timestamp=0");
35
36
  });
36
37
  it("GET FILTERED ITEMS LENGTH WITH CURRENT ITEM FILTER", async function () {
38
+ this.timeout(5000);
37
39
  let json = await gudhub.jsonConstructor(currentItemScheme);
38
40
  let firstLength = json.scheme[0].array.length;
39
41
  let secondLength = json.scheme[1].array.length;
@@ -42,6 +44,11 @@ describe("JSON CONSTRUCTOR", function () {
42
44
  secondLength.should.equal(4);
43
45
 
44
46
  });
47
+ it("WORK WITH NAMESPACE INSTEAD OF FIELD ID", async function () {
48
+ this.timeout(5000);
49
+ let json = await gudhub.jsonConstructor(schemeWithNamespace);
50
+ json.scheme[0].name.should.equal("Big Fish Tank");
51
+ });
45
52
  });
46
53
 
47
54
  var fishtank_scheme = {
@@ -146,3 +153,20 @@ let currentItemScheme = {
146
153
  app_id: "16259",
147
154
  filter: [],
148
155
  };
156
+
157
+ let schemeWithNamespace = {
158
+ type: "array",
159
+ id: 1,
160
+ childs: [
161
+ {
162
+ type: "property",
163
+ id: 2,
164
+ property_name: "name",
165
+ property_type: "field_value",
166
+ name_space: "name"
167
+ }
168
+ ],
169
+ property_name: "scheme",
170
+ app_id: "16259",
171
+ filter: []
172
+ }
package/GUDHUB/config.js CHANGED
@@ -3,7 +3,7 @@ export const server_url = "https://gudhub.com/GudHub_Test";
3
3
  //export const server_url = "https://integration.gudhub.com/GudHub_Test";
4
4
  //export const server_url = "http://localhost:9000";
5
5
  export const wss_url = "wss://gudhub.com/GudHub/ws/app/";
6
- export const async_modules_path = 'build/latest/async_modules/';
6
+ export const async_modules_path = 'build/latest/async_modules_node/';
7
7
  export const automation_modules_path = 'build/latest/automation_modules/'
8
8
  export const file_server_url = 'https://gudhub.com'
9
9
 
package/GUDHUB/gudhub.js CHANGED
@@ -314,6 +314,10 @@ export class GudHub {
314
314
  return this.fieldProcessor.getField(app_id, field_id);
315
315
  }
316
316
 
317
+ getFieldIdByNameSpace(app_id, name_space) {
318
+ return this.fieldProcessor.getFieldIdByNameSpace(app_id, name_space);
319
+ }
320
+
317
321
  getFieldModels(app_id) {
318
322
  return this.fieldProcessor.getFieldModels(app_id);
319
323
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gudhub/core",
3
- "version": "1.1.57",
3
+ "version": "1.1.59",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {