@gudhub/core 1.0.37

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.
Files changed (67) hide show
  1. package/GUDHUB/Auth/Auth.js +137 -0
  2. package/GUDHUB/Auth/Auth.test.js +15 -0
  3. package/GUDHUB/Managers/ChunksManager/ChunksManager.js +80 -0
  4. package/GUDHUB/Managers/ChunksManager/ChunksManager.test.js +46 -0
  5. package/GUDHUB/Managers/DocumentManager/DocumentManager.js +48 -0
  6. package/GUDHUB/Managers/FileManager/FileManager.js +208 -0
  7. package/GUDHUB/Managers/FileManager/file_manager.test.js +17 -0
  8. package/GUDHUB/Managers/managers.js +5 -0
  9. package/GUDHUB/PipeService/PipeService.js +167 -0
  10. package/GUDHUB/PipeService/PipeService.test.js +64 -0
  11. package/GUDHUB/PipeService/utils.js +32 -0
  12. package/GUDHUB/Processors/AppProcessor/AppProcessor.js +433 -0
  13. package/GUDHUB/Processors/AppProcessor/AppProcessor.test.js +38 -0
  14. package/GUDHUB/Processors/AppProcessor/AppProcessorMocks.js +83 -0
  15. package/GUDHUB/Processors/FieldProcessor/FieldProcessor.js +139 -0
  16. package/GUDHUB/Processors/FieldProcessor/FieldProcessor.test.js +16 -0
  17. package/GUDHUB/Processors/FieldProcessor/Untitled-1.json +17 -0
  18. package/GUDHUB/Processors/FieldProcessor/field_processor.md +85 -0
  19. package/GUDHUB/Processors/ItemProcessor/ItemProcessor.js +247 -0
  20. package/GUDHUB/Processors/ItemProcessor/item_processor.md +50 -0
  21. package/GUDHUB/Processors/processors.js +5 -0
  22. package/GUDHUB/Storage/Storage.js +115 -0
  23. package/GUDHUB/Storage/Storage.test.js +112 -0
  24. package/GUDHUB/Utils/Utils.js +153 -0
  25. package/GUDHUB/Utils/compare_items_lists_worker/compare_items_lists.worker.js +50 -0
  26. package/GUDHUB/Utils/filter/filter.js +308 -0
  27. package/GUDHUB/Utils/filter/filter.test.js +94 -0
  28. package/GUDHUB/Utils/filter/filterPreparation.js +103 -0
  29. package/GUDHUB/Utils/filter/group.js +41 -0
  30. package/GUDHUB/Utils/filter/utils.js +119 -0
  31. package/GUDHUB/Utils/get_date/get_date.js +90 -0
  32. package/GUDHUB/Utils/get_date/get_date.test.js +53 -0
  33. package/GUDHUB/Utils/interpretation/interpretation.js +100 -0
  34. package/GUDHUB/Utils/json_constructor/json_constructor.js +130 -0
  35. package/GUDHUB/Utils/json_constructor/json_constructor.test.js +70 -0
  36. package/GUDHUB/Utils/json_to_items/json_to_items.js +161 -0
  37. package/GUDHUB/Utils/json_to_items/json_to_items.test.js +85 -0
  38. package/GUDHUB/Utils/merge_chunks/merge_chunks.js +30 -0
  39. package/GUDHUB/Utils/merge_compare_items/merge_compare_items.js +316 -0
  40. package/GUDHUB/Utils/merge_compare_items/merge_compare_items.test.js +632 -0
  41. package/GUDHUB/Utils/merge_objects/merge_objects.js +120 -0
  42. package/GUDHUB/Utils/merge_objects/merge_objects.test.js +137 -0
  43. package/GUDHUB/Utils/nested_list/nested_list.js +38 -0
  44. package/GUDHUB/Utils/nested_list/nested_list.test.js +70 -0
  45. package/GUDHUB/Utils/populate_items/populate_items.js +66 -0
  46. package/GUDHUB/WebSocket/WebSocket.js +136 -0
  47. package/GUDHUB/config.js +8 -0
  48. package/GUDHUB/consts.js +1 -0
  49. package/GUDHUB/gudhub-https-service.js +193 -0
  50. package/GUDHUB/gudhub.js +477 -0
  51. package/GUDHUB/gudhub.test.js +218 -0
  52. package/GUDHUB/utils.js +25 -0
  53. package/Readme.md +537 -0
  54. package/fake_server/fake_java_server.js +112 -0
  55. package/fake_server/fake_server_data/app_132.js +3037 -0
  56. package/fake_server/fake_server_data/app_16259.js +1152 -0
  57. package/fake_server/fake_server_data/app_214.js +2057 -0
  58. package/fake_server/fake_server_data/app_8263.js +4167 -0
  59. package/fake_server/fake_server_data/chunks_mocks/bcacjbgqorherqmtykrj_8263.js +44561 -0
  60. package/fake_server/fake_server_data/chunks_mocks/bcjyuoqaewybudfyhir_8263.js +44197 -0
  61. package/fake_server/fake_server_data/chunks_mocks/tpajkpolmzklodcba_8263.js +44977 -0
  62. package/fake_server/fake_server_data/fake_server_data.js +111 -0
  63. package/index.js +3 -0
  64. package/indexUMD.js +5 -0
  65. package/package.json +45 -0
  66. package/umd/library.min.js +186 -0
  67. package/umd/library.min.js.map +1 -0
@@ -0,0 +1,30 @@
1
+ export function mergeChunks(chunks) {
2
+ const result = {};
3
+
4
+ chunks.forEach((chunk) => {
5
+ chunk.items_list.forEach((item) => {
6
+ const dstItem = result[item.item_id];
7
+ if (dstItem) {
8
+ return item.fields.forEach((srcField) => {
9
+ let isFieldNonExist = true;
10
+ dstItem.fields = dstItem.fields.map((dstField) => {
11
+ if (Number(dstField.field_id) === Number(srcField.field_id)) {
12
+ isFieldNonExist = false;
13
+ if (dstField.field_value != srcField.field_value) {
14
+ return {
15
+ ...srcField,
16
+ history: srcField.history.concat(dstField.history),
17
+ };
18
+ }
19
+ return dstField;
20
+ }
21
+ return dstField;
22
+ });
23
+ if (isFieldNonExist) dstItem.fields.push(srcField);
24
+ });
25
+ }
26
+ return (result[item.item_id] = item);
27
+ });
28
+ });
29
+ return Object.values(result);
30
+ }
@@ -0,0 +1,316 @@
1
+ //********************************************//
2
+ //******************* ITEMS ******************//
3
+ //********************************************//
4
+
5
+ /*
6
+ |============================================== POPULATE WITH ITEM REFFERENCE ==========================================================|
7
+ |===== populateWithItemRef (sorceItemsRef, srcFieldIdToCompare, destinationItems, destFieldIdToCompare, destFieldForRef, app_id) =====|
8
+ |=======================================================================================================================================|
9
+ | We update destination Items with item_ref of sorce Items. Connectiontion between sorceItemsRef & srcFieldIdToCompare we are checking with
10
+ | help of srcFieldIdToCompare & destFieldIdToCompare. After connection is detected we save the item_ref into destFieldForRef.
11
+ |
12
+ | Arguments:
13
+ | - sorceItemsRef - items those are will be used as referense for item_ref
14
+ | - destinationItems - items those are will be used to save item_ref to sorceItemsRef
15
+ | - srcFieldIdToCompare - we use value from this field to find the similar items in source and destimation items array
16
+ | - destFieldIdToCompare - we use value from this field to find the similar items in source and destimation items array
17
+ | - destFieldForRef - field where value of item_ref
18
+ | - app_id - we use aplication id to generate value for item_ref
19
+ |
20
+ | Return:
21
+ | [{},{}...] - returns arey of updated items
22
+ |
23
+ |=====================================================================================================================================|
24
+ */
25
+
26
+ //********************** POPULATE WITH ITEM REFFERENCE ************************/
27
+ export function populateWithItemRef(sorceItemsRef, srcFieldIdToCompare, destinationItems, destFieldIdToCompare, destFieldForRef, app_id){
28
+ let resultedItems = [];
29
+
30
+ const theSameIdValueFn = function(srcComprItem, dstComprItem){
31
+ let fieldForRef = getFieldById(dstComprItem, destFieldForRef);
32
+
33
+ if(fieldForRef){
34
+ fieldForRef.field_value = app_id + "." + srcComprItem.item_id;
35
+ resultedItems.push(dstComprItem);
36
+ }
37
+ }
38
+
39
+ destinationItems.forEach(dstItem => {
40
+ sorceItemsRef.forEach(srcItem => {
41
+ compareTwoItemsByFieldId(srcItem, dstItem, srcFieldIdToCompare, destFieldIdToCompare, theSameIdValueFn);
42
+ })
43
+ });
44
+
45
+ return resultedItems;
46
+ }
47
+
48
+
49
+
50
+ /*
51
+ |====================================== MERGE ITEM ==================================|
52
+ |============== mergeItems (sorceItems, destinationItems) ============|
53
+ |====================================================================================|
54
+ | We replace all fields with values in destinationItems by values from sorceItems.
55
+ | If destinationItems doesn't have fields that sorceItems then we create them in destinationItems
56
+ |
57
+ | NOTE: items from chanks hase a history properti in a field
58
+ |
59
+ | Arguments:
60
+ | - sorceItems - array of items that will be used to update items from destinationItems items array
61
+ | - destinationItems - array of items that is gong to be updated
62
+ |
63
+ | Return:
64
+ | [{},{}...] - returns arey of updated items
65
+ |
66
+ |==================================================================================|
67
+ */
68
+
69
+ //********************** MERGE ITEMS ************************/
70
+ export function mergeItems(sorceItems, destinationItems, mergeByFieldId){
71
+ let src = JSON.parse(JSON.stringify(sorceItems));
72
+ let dst = JSON.parse(JSON.stringify(destinationItems));
73
+ let result = [];
74
+
75
+ //-- The Source and in the Destination has the same item ids but different field values
76
+ const differentSrcItemFn = function(srcItem, dstItem){
77
+ result.push( mergeTwoItems(srcItem, dstItem));
78
+ }
79
+
80
+ //-- The Source and in the Destination has the same item ids and field values
81
+ const theSameSrcItemFn = function(srcItem){
82
+ result.push(srcItem);
83
+ }
84
+
85
+ //-- Items thoase exist in the Source but they are not exist in the Destination list
86
+ const newSrcItemFn = function(srcItem){
87
+ result.push(srcItem);
88
+ }
89
+
90
+ //-- Items thoase exist in the Destination list but they are not exist in the Source list
91
+ const uniqDestItemFn = function(dstItem){
92
+ result.push(dstItem);
93
+ }
94
+
95
+ //--------- Compearing Src & Dst Items by item_id ---------//
96
+ if(mergeByFieldId){
97
+ compareItemsByFieldId(src, dst, mergeByFieldId, differentSrcItemFn, theSameSrcItemFn, newSrcItemFn)
98
+ }else compareItemsByItemId(src, dst, differentSrcItemFn, theSameSrcItemFn, newSrcItemFn, uniqDestItemFn)
99
+
100
+
101
+ //--------- Final Report ---------//
102
+ return result;
103
+ }
104
+
105
+
106
+
107
+ /*
108
+ |==================================== COMPARE ITEM ==================================================|
109
+ |=========== compareItems (sorceItems, destinationItems, fieldToCompare) =============|
110
+ |====================================================================================================|
111
+ | We compare fields of sorceItems with fields of destinationItems. It means that if sorceItems
112
+ | have the same fields with the same values as destinationItems thay will be described as 'same_items'
113
+ | even if destinationItems have additional fields those sorceItems doesn't have
114
+ |
115
+ | There to ways how it works:
116
+ | 1 compering items by item_id (if fieldToCompare is undefined)
117
+ | 2 compering items by value of specific field_id (if fieldToCompare is defined)
118
+ |
119
+ | Arguments:
120
+ | - sorceItems - array of items that is going to be used as a sorce for comperison
121
+ | - destinationItems - array of items that is gong to be compared with sorceItems
122
+ | - fieldToCompare - field that we use to compare sorce items with destination items, if this is not specified then we compare items by item_id
123
+ |
124
+ | Return:
125
+ | {
126
+ | is_items_diff: false,
127
+ | new_src_items:[],
128
+ | diff_src_items:[],
129
+ | same_items:[]
130
+ | }
131
+ |
132
+ |==================================================================================|
133
+ */
134
+
135
+ //********************** COMPARE ITEMS ************************/
136
+ export function compareItems(sorceItems, destinationItems, fieldToCompare){
137
+ const src = JSON.parse(JSON.stringify(sorceItems));
138
+ const dst = JSON.parse(JSON.stringify(destinationItems));
139
+ let result = {
140
+ is_items_diff: false,
141
+ new_src_items:[],
142
+ diff_src_items:[],
143
+ same_items:[]
144
+ };
145
+
146
+ const differentSrcItemFn = function(item){
147
+ result.diff_src_items.push(item);
148
+ }
149
+
150
+ const theSameSrcItemFn = function(item){
151
+ result.same_items.push(item);
152
+ }
153
+
154
+ const newSrcItemFn = function(item){
155
+ result.new_src_items.push(item);
156
+ }
157
+
158
+
159
+ //--------- Compearing Src & Dst Items by item_id ---------//
160
+ if(fieldToCompare){
161
+ compareItemsByFieldId(src, dst, fieldToCompare, differentSrcItemFn, theSameSrcItemFn, newSrcItemFn)
162
+ }else compareItemsByItemId(src, dst, differentSrcItemFn, theSameSrcItemFn, newSrcItemFn)
163
+
164
+
165
+ //--------- Final Report ---------//
166
+ result.is_items_diff = result.new_src_items.length > 0 || result.diff_src_items.length > 0;
167
+ return result;
168
+ }
169
+
170
+
171
+
172
+
173
+ function mergeTwoItems (src, dst){
174
+ src.fields.forEach(srcField =>{
175
+ let destField = getFieldById(dst, srcField.field_id);
176
+
177
+ if(destField){
178
+ destField.field_value = srcField.field_value;
179
+
180
+ // if we work with chanked items then we merge history
181
+ if(srcField.history && destField.history){
182
+ destField.history = srcField.history.concat(destField.history);
183
+ }
184
+
185
+ }else{//-- if we didn't find field with item then we add it
186
+ dst.fields.push(srcField);
187
+ }
188
+ })
189
+
190
+ return dst;
191
+ }
192
+
193
+
194
+
195
+ function compareItemsByFieldId(src, dst, fieldToCompare, differentSrcItemFn, theSameSrcItemFn, newSrcItemFn){
196
+ src.forEach(srcItem =>{
197
+ let notFoundDestItemforSrc = true;
198
+ let srcVal = getFieldById(srcItem, fieldToCompare).field_value;
199
+
200
+ dst.forEach(dstItem =>{
201
+ let dstVal = getFieldById(dstItem, fieldToCompare).field_value;
202
+ if (srcVal == dstVal){
203
+ notFoundDestItemforSrc = false;
204
+ compareTwoItems(srcItem, dstItem, differentSrcItemFn, theSameSrcItemFn);
205
+ }
206
+ });
207
+
208
+ //-- If there no destination item with the same item_id then it means that item is new
209
+ if(notFoundDestItemforSrc){
210
+ newSrcItemFn(srcItem);
211
+ }
212
+ });
213
+ }
214
+
215
+
216
+
217
+ function compareItemsByItemId(src, dst, differentSrcItemFn, theSameSrcItemFn, newSrcItemFn, uniqDestItemFn){
218
+ let dstItemsMap = new ItemsMapper(dst);
219
+
220
+ src.forEach(srcItem => {
221
+ let destIndex = dstItemsMap.pullItemIndex(srcItem.item_id);
222
+
223
+ if(destIndex != undefined){
224
+ compareTwoItems(srcItem, dst[destIndex], differentSrcItemFn, theSameSrcItemFn);
225
+ }else{
226
+ newSrcItemFn(srcItem);
227
+ };
228
+ });
229
+
230
+ //-- In case if we have destination items which are new then we
231
+ if(uniqDestItemFn)
232
+ for (const [key, value] of Object.entries(dstItemsMap.itemsMap)) {
233
+ uniqDestItemFn(dst[value]);
234
+ }
235
+ }
236
+
237
+
238
+
239
+ function compareTwoItems (src, dst, differentSrcItemFn, theSameSrcItemFn ){
240
+ let sameItem = true;
241
+
242
+ for(let i=0; i<src.fields.length; i++){
243
+ let destField = getFieldById(dst, src.fields[i].field_id);
244
+
245
+ if(destField){
246
+ //-- if value of some field of the item is different then item is different too
247
+ if(destField.field_value != src.fields[i].field_value){
248
+ sameItem = sameItem && false;
249
+ }
250
+ }else{//-- if we didn't find field with item then item is different
251
+ sameItem = sameItem && false;
252
+ }
253
+ }
254
+
255
+ //-- Sending Compearing Result
256
+ if (sameItem){
257
+ theSameSrcItemFn(src, dst);
258
+ }else differentSrcItemFn(src, dst);
259
+ }
260
+
261
+
262
+
263
+ function compareTwoItemsByFieldId (srcItem, dstItem, srcFieldId, dstFieldId, theSameSrcItemFn ){
264
+ let srcFieldVal = getFieldById(srcItem, srcFieldId).field_value;
265
+ let dstFieldIdVal = getFieldById(dstItem, dstFieldId).field_value;
266
+
267
+ if(srcFieldVal == dstFieldIdVal){
268
+ theSameSrcItemFn(srcItem, dstItem);
269
+ }
270
+ }
271
+
272
+
273
+
274
+
275
+
276
+
277
+ function getFieldById (item, field_id){
278
+ let result = null;
279
+
280
+ for(let i=0; i<item.fields.length; i++){
281
+ if (field_id == item.fields[i].field_id){
282
+ result = item.fields[i];
283
+ }
284
+ };
285
+
286
+ return result;
287
+ }
288
+
289
+
290
+ class ItemsMapper {
291
+ constructor(items) {
292
+ this._itemsMap = {};
293
+
294
+ items.forEach((item,key) => {
295
+ this._itemsMap[item.item_id] = key;
296
+ });
297
+
298
+ }
299
+
300
+ pullItemIndex(item_id){
301
+ let index = this._itemsMap[item_id];
302
+ delete this._itemsMap[item_id];
303
+ return index;
304
+ }
305
+
306
+ getItemIndex(item_id) {
307
+ return this._itemsMap[item_id];
308
+ }
309
+
310
+ get itemsMap() {
311
+ return this._itemsMap;
312
+ }
313
+ }
314
+
315
+
316
+