@gudhub/core 1.1.73 → 1.1.75

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.
@@ -25,7 +25,8 @@ export class DocumentManager {
25
25
  }
26
26
 
27
27
  emitDocumentInsert(data) {
28
- this.pipeService.emit("gh_document_insert_one", { app_id: data.app_id, item_id: data.item_id, element_id: data.element_id }, JSON.parse(data.data));
28
+ const dataToEmit = typeof data.data === "string" ? JSON.parse(data.data) : data.data;
29
+ this.pipeService.emit("gh_document_insert_one", { app_id: data.app_id, item_id: data.item_id, element_id: data.element_id }, dataToEmit);
29
30
  }
30
31
 
31
32
  getDocument(documentAddress) {
@@ -7,9 +7,8 @@ export class Interpritate {
7
7
  // In this method we are looking for interpretation in data model according to interpretation src
8
8
  // then we merged with default interpretation from defaultFieldDataModel
9
9
  // if there are no current interpretation we use default interpretation
10
- getInterpretationObj(fieldDataModel, defaultFieldDataModel, src, containerId) {
11
- var currentIntrpr = {};
12
-
10
+ async getInterpretationObj(fieldDataModel, defaultFieldDataModel, src, containerId, itemId, appId) {
11
+ var currentIntrpr = [];
13
12
  // Creating default interpretation
14
13
  var defaultIntrprObj = defaultFieldDataModel.data_model.interpretation.find(function (interpritation) {
15
14
  return interpritation.src == src;
@@ -17,15 +16,34 @@ export class Interpritate {
17
16
  return interpritation.src == 'table';
18
17
  }) || { id: 'default' };
19
18
 
19
+ var interpretation = defaultIntrprObj;
20
+
20
21
  if (fieldDataModel.data_model && fieldDataModel.data_model.interpretation) {
21
22
  // To detect interpretation we use (container_id), if there is not (container_id) we use (src)
22
- currentIntrpr = fieldDataModel.data_model.interpretation.find(function (interpritation) {
23
- return interpritation.src == containerId;
24
- }) || fieldDataModel.data_model.interpretation.find(function (interpritation) {
25
- return interpritation.src == src;
26
- });
23
+ for(var i = 0; i < fieldDataModel.data_model.interpretation.length; i++) {
24
+ if(fieldDataModel.data_model.interpretation[i].src == src || fieldDataModel.data_model.interpretation[i].src == containerId) {
25
+ currentIntrpr.push(fieldDataModel.data_model.interpretation[i]);
26
+ }
27
+ }
28
+
29
+ for(var i = 0; i < currentIntrpr.length; i++) {
30
+ if(currentIntrpr[i].settings.condition_filter && currentIntrpr[i].settings.filters_list.length > 0) {
31
+ const item = await gudhub.getItem(appId, itemId);
32
+ if(item) {
33
+ const filteredItems = gudhub.filter([item], currentIntrpr[i].settings.filters_list);
34
+ if(filteredItems.length > 0) {
35
+ interpretation = currentIntrpr[i];
36
+ break;
37
+ }
38
+ }
39
+ } else {
40
+ interpretation = gudhub.mergeObjects(interpretation, currentIntrpr[i]);
41
+ }
42
+ }
43
+
27
44
  }
28
- return gudhub.mergeObjects(defaultIntrprObj, currentIntrpr);
45
+
46
+ return interpretation;
29
47
  }
30
48
 
31
49
  /*********************** GET INTERPRETATION ***********************/
@@ -39,9 +57,9 @@ export class Interpritate {
39
57
  /*---- Constructing Data Object ----*/
40
58
  if (data_type) {
41
59
  /*-- if we have data_type then we construct new data object to interpritate value*/
42
- gudhub.ghconstructor.getInstance(data_type).then(function (data) {
60
+ gudhub.ghconstructor.getInstance(data_type).then(async function (data) {
43
61
  if(data) {
44
- var interpretationObj = self.getInterpretationObj(field, data.getTemplate().model, source, containerId);
62
+ var interpretationObj = await self.getInterpretationObj(field, data.getTemplate().model, source, containerId, itemId, appId);
45
63
  data.getInterpretation(value, interpretationObj.id, data_type, field, itemId, appId).then(function (result) {
46
64
  // console.log(result, interpretationObj)
47
65
 
@@ -1162,11 +1162,25 @@ export default function generateModulesList(async_modules_path, file_server_url,
1162
1162
  },
1163
1163
  {
1164
1164
  data_type: 'TwilioSMS',
1165
- name: 'Twilio',
1165
+ name: 'Twilio SMS',
1166
1166
  url: file_server_url + '/' + automation_modules_path + 'twilio_sms.js',
1167
1167
  type: 'automation',
1168
1168
  icon: 'automation_twilio'
1169
1169
  },
1170
+ {
1171
+ data_type: 'TwilioAuth',
1172
+ name: 'Twilio Auth',
1173
+ url: file_server_url + '/' + automation_modules_path + 'twilio_auth.js',
1174
+ type: 'automation',
1175
+ icon: 'table'
1176
+ },
1177
+ {
1178
+ data_type: 'TwilioDevice',
1179
+ name: 'Twilio Device',
1180
+ url: file_server_url + '/' + automation_modules_path + 'twilio_device.js',
1181
+ type: 'automation',
1182
+ icon: 'table'
1183
+ },
1170
1184
  {
1171
1185
  data_type: 'UpdateItemsApi',
1172
1186
  name: 'Update Items Api',
@@ -313,6 +313,8 @@ class ItemsFilter {
313
313
 
314
314
  filter(filters, items) {
315
315
 
316
+ const allFiltersAndStrategy = this.checkIfAllFiltersHaveAndStrategy(filters);
317
+
316
318
  const filteredItems = [];
317
319
  const activeFilters = filters.filter(function (filter) {
318
320
  return filter.valuesArray.length;
@@ -352,6 +354,12 @@ class ItemsFilter {
352
354
  default:
353
355
  result = result && filterChecker.check(filterAggregate);
354
356
  }
357
+
358
+ // Needed for performance optimization
359
+ // We don't need to check other filters if we already know that result is false in case of 'and' strategy
360
+ if(!result && allFiltersAndStrategy) {
361
+ break;
362
+ }
355
363
 
356
364
  }
357
365
 
@@ -368,4 +376,14 @@ class ItemsFilter {
368
376
  }
369
377
 
370
378
  }
379
+
380
+ checkIfAllFiltersHaveAndStrategy(filters) {
381
+ return filters.every((filter) => {
382
+ if(!filter.boolean_strategy || filter.boolean_strategy == 'and') {
383
+ return true;
384
+ }
385
+ return false;
386
+ });
387
+ }
388
+
371
389
  }
@@ -92,6 +92,49 @@ import { app_8263 } from '../../../fake_server/fake_server_data/app_8263.js';
92
92
  filter[0].valuesArray[1].should.equal(true);
93
93
 
94
94
  });
95
+
96
+ it('CHECK FILTER PERFORMANCE / filter with and strategy should run in less than 200ms', async () => {
97
+
98
+ const filters = [
99
+ {
100
+ "field_id": 96606,
101
+ "data_type": "text",
102
+ "valuesArray": [
103
+ "Oklahoma"
104
+ ],
105
+ "search_type": "contain_or",
106
+ "boolean_strategy": "and",
107
+ "selected_search_option_variable": "Value"
108
+ },
109
+
110
+ {
111
+ "field_id": 96608,
112
+ "data_type": "phone",
113
+ "valuesArray": [
114
+ "8453"
115
+ ],
116
+ "search_type": "contain_or",
117
+ "boolean_strategy": "and",
118
+ "selected_search_option_variable": "Value"
119
+ }
120
+ ];
121
+
122
+ let totalTime = 0;
123
+
124
+ const iterationsCount = 1000;
125
+
126
+ for (let i = 0; i < iterationsCount; i++) {
127
+ const startTime = new Date().getTime();
128
+ gudhub.filter(app_8263.items_list, filters);
129
+ totalTime += new Date().getTime() - startTime;
130
+ }
131
+
132
+ // Ideally, on my laptop with i7-9750H 2.60 it takes 60ms
133
+ totalTime.should.be.below(200);
134
+
135
+ console.log('Average time for filter with and strategy: ', totalTime);
136
+
137
+ });
95
138
 
96
139
  });
97
140
 
@@ -26,6 +26,20 @@ export function compiler(scheme, item, util, variables, appId) {
26
26
  value = await getFieldValue(scheme, item, appId);
27
27
  }
28
28
 
29
+ if (typeof scheme === "object" && typeof scheme.type === 'undefined') {
30
+ const result = {};
31
+
32
+ for (const key in scheme) {
33
+ if (scheme.hasOwnProperty(key)) {
34
+ const element = scheme[key];
35
+ const res = await schemeCompiler(element, item, appId);
36
+ result[key] = res[element.property_name];
37
+ }
38
+ }
39
+
40
+ return result;
41
+ }
42
+
29
43
  return { [scheme.property_name]: value };
30
44
  }
31
45
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gudhub/core",
3
- "version": "1.1.73",
3
+ "version": "1.1.75",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {