@gudhub/core 1.0.38 → 1.0.39

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.
package/Readme.md CHANGED
@@ -1,537 +1,537 @@
1
- # GUDHUB
2
-
3
- I't a Library to simplify work with GudHub API. Also this Library cantains utilites for beter aperation with `items`, `fields` and `apps`!
4
-
5
- # npm Package
6
-
7
- The package name is `@gudhub/gudhub` It a privet package, that is why `.npmrc` file should be in a root folder to download it from **npm**. It means that If you have `@gudhub/gudhub` in package.json for `GudHubClient` the `.npmrc` file should be in the root folder too.
8
-
9
- ## Publishing gudhub lib to npm
10
-
11
- In order to publish new version of the GudHub Lib you have to:
12
-
13
- 1. Change vertsion in `package.json`
14
- 1. Commit your chagnes into repository to the `master` branch
15
- 1. Run `npm publish` command which will publish new version to **npm**
16
-
17
- ## Development gudhub lib
18
-
19
- If you'd like to develop **GudHub Lib** in another enviroment, let's say in **GudHubClient** you have to do the falowing things:
20
-
21
- 1. You should go to the `gudhub` folder and run there `npm init @gudhub/gudhub` command, it will install the *@gudhub/gudhub* package in to your global enviroment
22
- 1. Then you have to add `@gudhub/gudhub` to your `package.json` as a dependency.
23
- 1. Then package will be downloaded from your local computer after you run `npm run dev` or `npm install` command
24
-
25
- # Initialization
26
-
27
- There are several ways to initialize GudHub. The most simple way is initializing gudhub without arguments. It this way will be available utils only
28
-
29
- ```js
30
- import {GudHub} from '@gudhub/gudhub';
31
- const gudhub = new GudHub();
32
- ```
33
-
34
- The second way is initialization GudHub with autorization key. It's the most comon way for using GudHub in your project. You just need to pass `auth_key` as argument.
35
- In this case you will be able to operate with GudHub data and use all mothods those are listed here.
36
-
37
- ```js
38
- import {GudHub} from '@gudhub/gudhub';
39
- const gudhub = new GudHub(auth_key);
40
- ```
41
-
42
- The third way is initialisation GudHub with aditionals parameters. It's usefull for development server app on Node.js and for testin on local server.At the exampe belw you can see how to initialize GudHub ( in the example you can see default params )
43
-
44
- ```js
45
- import {GudHub} from '@gudhub/gudhub';
46
- const gudhub = new GudHub(auth_key,{
47
- server_url : "https://gudhub.com/GudHub",
48
- wss_url : "wss://gudhub.com/GudHub/ws/app/",
49
- initWebsocket : false
50
- });
51
- ```
52
-
53
- Param Name|Description|Default Value
54
- ------------ | ------------- | -------------
55
- *server_url* |All request will send to this url |https://gudhub.com/GudHub
56
- *wss_url* | url to setup websoket connection |wss://gudhub.com/GudHub/ws/app/
57
- *initWebsocket* |here we can turn off websoket connection|false
58
-
59
- # Utils:
60
-
61
- ## jsonConstructor(scheme, items)
62
-
63
- With this method you can get json according to the scheme.
64
-
65
- ```js
66
- import {GudHub} from '@gudhub/gudhub';
67
- const gudhub = new GudHub();
68
- gudhub.jsonConstructor(scheme);
69
- ```
70
-
71
- **Sheme Example:**
72
-
73
- ```json
74
- {
75
- "type": "array",
76
- "id": 1,
77
- "childs": [
78
- {
79
- "type": "property",
80
- "id": 3,
81
- "property_name": "name",
82
- "property_type": "field_value",
83
- "field_id": "254056"
84
- },
85
- {
86
- "type": "property",
87
- "id": 4,
88
- "property_name": "state",
89
- "property_type": "field_value",
90
- "field_id": "270607"
91
- }
92
- ],
93
- "property_name": "fishtank",
94
- "app_id": "16259",
95
- "filter": []
96
- }
97
- ```
98
-
99
- ## jsonToItems(json, fieldsMap)
100
-
101
- This method converts json to gudhub items. the conversion is made based on `fieldMap`. After items generated You can send them to create new items.
102
-
103
- ```js
104
- import {GudHub} from '@gudhub/gudhub';
105
- const gudhub = new GudHub();
106
- gudhub.jsonToItems(json, fieldsMap);
107
- ```
108
-
109
- Argument Name|Type|Description
110
- ------------ | ------------- | -------------
111
- *json* | `object` | json that is going to be converted to gudhub items
112
- *fieldsMap* | `object` | and object in json format which contains instructions of how to convert to items
113
-
114
- fieldsMap this map is an object array that contains field_id and jsonPath to get data from. We use jsonPath [jsonpath](https://www.npmjs.com/package/jsonpath) to parse json.
115
-
116
- ```json
117
- [
118
- {
119
- field_id: 431,
120
- json_path : "$..item_id"
121
- }
122
- ]
123
- ```
124
-
125
- The method returns items list:
126
-
127
- ```json
128
- [
129
- {
130
- fields:[
131
- {
132
- field_id: 12356,
133
- field_value: "test value"
134
- }
135
- ]
136
- },
137
- {
138
- fields:[
139
- {
140
- field_id: 12356,
141
- field_value: "test value2"
142
- }
143
- ]
144
- }
145
- ]
146
- ```
147
-
148
- ## populateWithItemRef()
149
-
150
- We update destination Items with item_ref of sorce Items. Connectiontion between sorceItemsRef & srcFieldIdToCompare we are checking with help of srcFieldIdToCompare & destFieldIdToCompare. After connection is detected we save the item_ref into destFieldForRef.
151
-
152
- ```js
153
- import {GudHub} from '@gudhub/gudhub';
154
- const gudhub = new GudHub();
155
- gudhub.populateWithItemRef(sorceItemsRef, srcFieldIdToCompare, destinationItems, destFieldIdToCompare, destFieldForRef, appId);
156
- ```
157
-
158
- Argument Name|Type|Description
159
- ------------ | ------------- | -------------
160
- *sorceItemsRef* | `items` | items which will be used as referense for item_ref
161
- *srcFieldIdToCompare* | `field_id` | we use value from this field to find the similar items in source and destimation items array
162
- *destinationItems* | `items` | items those will be used to save item_ref to sorceItemsRef
163
- *destFieldIdToCompare* | `field_id` | we use value from this field to find the similar items in source and destimation items array
164
- *destFieldForRef* | `field_id` | field where we save value of item_ref
165
- *appId* | `app_id` | we use app_id to generate value for item_ref
166
-
167
- ## mergeItems()
168
-
169
- We replace all fields with values in destinationItems by values from sorceItems. If destinationItems doesn't have fields that sorceItems then we create them in destinationItems.
170
-
171
- ```js
172
- import {GudHub} from '@gudhub/gudhub';
173
- const gudhub = new GudHub();
174
- gudhub.mergeItems(sorceItems, destinationItems);
175
- ```
176
-
177
- ## compareItems()
178
-
179
- We compare fields of sorceItems with fields of destinationItems. It means that if sorceItems have the same fields with the same values as destinationItems thay will be described as 'same_items' even if destinationItems have additional fields those sorceItems doesn't have.
180
-
181
- ```js
182
- import {GudHub} from '@gudhub/gudhub';
183
- const gudhub = new GudHub();
184
- gudhub.compareItems (sorceItems, destinationItems, fieldToCompare) ;
185
- ```
186
-
187
- There to ways how it works:
188
-
189
- 1. Compering items by item_id (if fieldToCompare is undefined)
190
- 1. Compering items by value of specific field_id (if fieldToCompare is defined)
191
-
192
- **compareItems() Return:**
193
-
194
- ```json
195
- {
196
- is_items_diff: false,
197
- new_src_items:[],
198
- diff_src_items:[],
199
- same_items:[]
200
- }
201
- ```
202
-
203
- Argument Name|Type|Description
204
- ------------ | ------------- | -------------
205
- *sorceItems* | `items` | array of items that is going to be used as a sorce for comperison
206
- *destinationItems* | `items` | array of items that is gong to be compared with sorceItems
207
- *srcFieldIdToCompare* | `field_id` | field that we use to compare sorce items with destination items, if this is not specified then we compare items by item_id
208
-
209
- ## getDate()
210
-
211
- This method will return a date accorting to specified namespace. The name space should be in string format
212
-
213
- ```js
214
- import {GudHub} from '@gudhub/gudhub';
215
- const gudhub = new GudHub();
216
- gudhub.mergeItems(sorceItems, destinationItems);
217
- ```
218
-
219
- ## getDate()
220
-
221
- This method will return a date accorting to specified namespace. The name space should be in string format
222
-
223
- ```js
224
- import {GudHub} from '@gudhub/gudhub';
225
- const gudhub = new GudHub();
226
- gudhub.getDate('this_sunday');
227
- ```
228
-
229
- The following namespaces are available now:
230
-
231
- Date Namespaces | Description
232
- ------------ | -------------
233
- `now` | will return current date
234
- `next_day` | should return current day + 24hours
235
- `next_week` | it adds one week(7 days) to current date
236
- `two_days_after` | it adds two days(24hours) to current date
237
- `three_days_after` | it adds three days(24hours) to current date
238
- `four_days_after` | it adds four days(24hours) to current date
239
- `two_weeks_after` | it adds two weeks(7 days) to current date
240
- `three_weeks_after` | it adds three weeks(7 days) to current date
241
- `this_sunday` | will return date for sunday, with current utc time if it's a monday then it will return sunday from the next week
242
- `this_monday` | will return date for monday, with current utc time if it's a saturday then it will return monday from the next week
243
- `this_tuesday` | will return date for tuesday, with current utc time if it's a saturday then it will return tuesday from the next week
244
- `this_wednesday` | will return date for wednesday, with current utc time if it's a saturday then it will return wednesday from the next week
245
- `this_thursday` | will return date for thursday, with current utc time if it's a saturday then it will return thursday from the next week
246
- `this_friday` | will return date for friday, with current utc time if it's a saturday then it will return friday from the next week
247
- `this_saturday` | will return date for monday, with current utc time if it's a sunday then it will return saturday from the next week
248
-
249
- `prefilter()`
250
-
251
- `filter()`
252
-
253
- `group()`
254
-
255
- `mergeItems(src, destn)`
256
-
257
- `compareItems()`
258
-
259
- `populateWithItemRef()`
260
-
261
- `(target, source, optionsArgument)`
262
- It deeply merge two objects. We use this method two merge fields models
263
- 0 Value of properties for source object woun't be changed by target object
264
- 0 source of target hase unique properties they are going to be created in resulted object
265
-
266
- ## makeNestedList ()
267
-
268
- This method will return a new nested array from initial array.
269
-
270
- ```js
271
- import {GudHub} from '@gudhub/gudhub';
272
- const gudhub = new GudHub();
273
- let nestedList = gudhub.makeNestedList(array, id, parent_id, children_property);
274
- ```
275
-
276
- Argument Name | Type | Description
277
- --------------|--------------|--------------
278
- array | `array` | Array from which nested list will be generated
279
- id | `string` | Parent property name
280
- parent_id | `string` | Child property name
281
- children_property | `string` | `(Optional)` Name of property, in which children items will be stored inside parent item. <br> Default is 'children'
282
-
283
- Initial array example:
284
-
285
- ```js
286
- let input = [
287
- {
288
- name: "Article 1",
289
- id: 1,
290
- parent_id: 0
291
- },
292
- {
293
- name: "Article 2",
294
- id: 2,
295
- parent_id: 1
296
- },
297
- {
298
- name: "Article 3",
299
- id: 3,
300
- parent_id: 1
301
- },
302
- {
303
- name: "Article 4",
304
- id: 4,
305
- parent_id: 0
306
- }
307
- ]
308
- ```
309
-
310
- Method call example:
311
-
312
- ```js
313
- let result = gudhub.makeNestedList(input, 'id', 'parent_id', 'custom_children_property')
314
- ```
315
-
316
- Result example:
317
-
318
- ```js
319
- [
320
- {
321
- id: 1,
322
- name: "Article 1",
323
- parent_id: 0,
324
- custom_child_property: [
325
- {
326
- id: 2,
327
- name: "Article 2",
328
- parent_id: 1
329
- },
330
- {
331
- id: 3,
332
- name: "Article 3",
333
- parent_id: 1
334
- }
335
- ]
336
- },
337
- {
338
- id: 4,
339
- name: "Article 4",
340
- parent_id: 0
341
- }
342
- ]
343
- ```
344
-
345
- # App Processor:
346
-
347
- ## getAppInfo()
348
-
349
- it returs App with Empty `field_list:[]`, `items_list:[]`, `file_list:[]`, `views_list:[]`. Such simmple data needed to render App Icons, and do some simple updates in App like: updating App name icon permisions etc when full app data is not needed
350
-
351
- ```js
352
- import {GudHub} from '@gudhub/gudhub';
353
- const gudhub = new GudHub();
354
- gudhub.getAppInfo(appId);
355
- ```
356
-
357
- Argument Name|Type|Description
358
- ------------ | ------------- | -------------
359
- *appId* | `app_id` | we use app_id to generate value for item_ref
360
-
361
- **getAppInfo() returns folowing object:**
362
-
363
- ```json
364
- {
365
- app_id: 13360,
366
- app_name: "Contacts"
367
- field_list: [],
368
- file_list: [],
369
- group_id: 13329,
370
- icon: {id: 12762, icon_id: "user", icon_color: "ffffff", gradient_up: "ff758c", gradient_down: "ff7eb3"}
371
- items_list: [],
372
- keys_list: [],
373
- last_update: 1608657765499,
374
- permission: 4,
375
- priority: 0,
376
- privacy: 0,
377
- show: true,
378
- trash: false,
379
- view_init: 281591,
380
- views_list: []
381
- }
382
- ```
383
-
384
- `getApp(app_id)` return app;
385
-
386
- `To Be Done` -> `getAppList()` return List of Applications those are shared to users;
387
-
388
- # App Processor:
389
-
390
- ## getAppInfo()
391
-
392
- it returs App with Empty `field_list:[]`, `items_list:[]`, `file_list:[]`, `views_list:[]`. Such simmple data needed to render App Icons, and do some simple updates in App like: updating App name icon permisions etc when full app data is not needed
393
-
394
- ```js
395
- import {GudHub} from '@gudhub/gudhub';
396
- const gudhub = new GudHub();
397
- gudhub.getAppInfo(appId);
398
- ```
399
-
400
- Argument Name|Type|Description
401
- ------------ | ------------- | -------------
402
- *appId* | `app_id` | we use app_id to generate value for item_ref
403
-
404
- **It returns folowing object:**
405
-
406
- ```json
407
- {
408
- app_id: 13360,
409
- app_name: "Contacts"
410
- field_list: [],
411
- file_list: [],
412
- group_id: 13329,
413
- icon: {id: 12762, icon_id: "user", icon_color: "ffffff", gradient_up: "ff758c", gradient_down: "ff7eb3"}
414
- items_list: [],
415
- keys_list: [],
416
- last_update: 1608657765499,
417
- permission: 4,
418
- priority: 0,
419
- privacy: 0,
420
- show: true,
421
- trash: false,
422
- view_init: 281591,
423
- views_list: []
424
- }
425
- ```
426
-
427
- `getApp(app_id)` return app;
428
-
429
- `To Be Done` -> `getAppList()` return List of Applications those are shared to users;
430
-
431
-
432
- # User:
433
-
434
- `login()`;(is not needed)
435
-
436
- `logout()`;
437
-
438
- `signup()`;(is not needed)
439
-
440
- `getUser()`;
441
-
442
- `getUsersList()`;
443
-
444
- `updateUser()`;
445
-
446
- `avatarUpload()`;
447
-
448
- `getVersion()`;
449
-
450
- ## Sharing
451
-
452
- `getUsersWithPermision()`;
453
-
454
- `sharingAdd()`;
455
-
456
- `sharingUpdate()`;
457
-
458
- `sharingDelete()`;
459
-
460
- ## Items Processor
461
-
462
- `itemsGet(app_id, items_id_array)` return items by item_id from the array;
463
-
464
- `filteredItemsGet(app_id, filter)` return items according to filter;
465
-
466
- `itemGet(app_id, item_id)` return item;
467
-
468
- `itemsAdd(app_id, items)` add items to app;
469
-
470
- `itemsUpdate(app_id, items)` update items in the app;
471
-
472
- ## Field Processor
473
-
474
- `elementGet(element_id)` return element `beta`;
475
-
476
- `fieldValueGet(app_id, item_id, field_id)` return field value;
477
-
478
- `valueUpdate(app_id, item_id, field_id, field_value)` update value in a field;
479
-
480
- `getModel(app_id, field_id)` return data_model of field;
481
-
482
- `getInterpretedValue(app_id, item_id, field_id)` return interpreted value of field;
483
-
484
- ## File Processor
485
-
486
- `uploadFile(fileData, app_id, item_id)` create a file from data;
487
-
488
- `uploadFileFromString(data, file_name, app_id, item_id, extension, format)` create a file from string;
489
-
490
- `updateFileFromString(data, file_id, file_name, extension, format)` update file from string;
491
-
492
- `getFile(app_id, file_id)` get file by appId and fileId;
493
-
494
- `getFiles(app_id, [fileId, fileId])` get files by appId and arrays of filesId;
495
-
496
- `deleteFile(id)` delete file by fileId;
497
-
498
- ## Document Processor
499
-
500
- `createDocument({app_id, item_id, element_id, data: Object})` create a document;
501
-
502
- `getDocument({app_id, item_id, element_id})` get a document;
503
-
504
- `getDocuments([{app_id, item_id, element_id}, {app_id, item_id, element_id}])` get documents;
505
-
506
- `deleteDocument({app_id, item_id, element_id})` delete a document;
507
-
508
- ## PipeService
509
-
510
- ### Methods
511
-
512
- `on(types, destination, fn)`
513
-
514
- `emit(types, destination, address, params)`
515
-
516
- `destroy(types, destination, fn)`
517
-
518
- #### _Examples_
519
-
520
- ```js
521
- on("gh_items_update", {app_id: 1, item_id: 1}, function getItems(event, address, params){})
522
-
523
- emit("gh_items_update", {app_id: 1, item_id: 1}, items, params)
524
-
525
- destroy("gh_items_update", {app_id: 1, item_id: 1}, function getItems(event, address, params){})
526
- ```
527
-
528
- ### Events
529
-
530
- Event name|Address example
531
- ------------ | -------------
532
- `gh_items_update` |{app_id: 1, item_id: 1}
533
- `gh_app_update` |{app_id: 1}
534
- `gh_item_update` |{app_id: 1, item_id: 1}
535
- `gh_value_update` |{app_id: 1, item_id: 1, field_id: 1}
536
-
537
- ________
1
+ # GUDHUB
2
+
3
+ I't a Library to simplify work with GudHub API. Also this Library cantains utilites for beter aperation with `items`, `fields` and `apps`!
4
+
5
+ # npm Package
6
+
7
+ The package name is `@gudhub/gudhub` It a privet package, that is why `.npmrc` file should be in a root folder to download it from **npm**. It means that If you have `@gudhub/gudhub` in package.json for `GudHubClient` the `.npmrc` file should be in the root folder too.
8
+
9
+ ## Publishing gudhub lib to npm
10
+
11
+ In order to publish new version of the GudHub Lib you have to:
12
+
13
+ 1. Change vertsion in `package.json`
14
+ 1. Commit your chagnes into repository to the `master` branch
15
+ 1. Run `npm publish` command which will publish new version to **npm**
16
+
17
+ ## Development gudhub lib
18
+
19
+ If you'd like to develop **GudHub Lib** in another enviroment, let's say in **GudHubClient** you have to do the falowing things:
20
+
21
+ 1. You should go to the `gudhub` folder and run there `npm init @gudhub/gudhub` command, it will install the *@gudhub/gudhub* package in to your global enviroment
22
+ 1. Then you have to add `@gudhub/gudhub` to your `package.json` as a dependency.
23
+ 1. Then package will be downloaded from your local computer after you run `npm run dev` or `npm install` command
24
+
25
+ # Initialization
26
+
27
+ There are several ways to initialize GudHub. The most simple way is initializing gudhub without arguments. It this way will be available utils only
28
+
29
+ ```js
30
+ import {GudHub} from '@gudhub/gudhub';
31
+ const gudhub = new GudHub();
32
+ ```
33
+
34
+ The second way is initialization GudHub with autorization key. It's the most comon way for using GudHub in your project. You just need to pass `auth_key` as argument.
35
+ In this case you will be able to operate with GudHub data and use all mothods those are listed here.
36
+
37
+ ```js
38
+ import {GudHub} from '@gudhub/gudhub';
39
+ const gudhub = new GudHub(auth_key);
40
+ ```
41
+
42
+ The third way is initialisation GudHub with aditionals parameters. It's usefull for development server app on Node.js and for testin on local server.At the exampe belw you can see how to initialize GudHub ( in the example you can see default params )
43
+
44
+ ```js
45
+ import {GudHub} from '@gudhub/gudhub';
46
+ const gudhub = new GudHub(auth_key,{
47
+ server_url : "https://gudhub.com/GudHub",
48
+ wss_url : "wss://gudhub.com/GudHub/ws/app/",
49
+ initWebsocket : false
50
+ });
51
+ ```
52
+
53
+ Param Name|Description|Default Value
54
+ ------------ | ------------- | -------------
55
+ *server_url* |All request will send to this url |https://gudhub.com/GudHub
56
+ *wss_url* | url to setup websoket connection |wss://gudhub.com/GudHub/ws/app/
57
+ *initWebsocket* |here we can turn off websoket connection|false
58
+
59
+ # Utils:
60
+
61
+ ## jsonConstructor(scheme, items)
62
+
63
+ With this method you can get json according to the scheme.
64
+
65
+ ```js
66
+ import {GudHub} from '@gudhub/gudhub';
67
+ const gudhub = new GudHub();
68
+ gudhub.jsonConstructor(scheme);
69
+ ```
70
+
71
+ **Sheme Example:**
72
+
73
+ ```json
74
+ {
75
+ "type": "array",
76
+ "id": 1,
77
+ "childs": [
78
+ {
79
+ "type": "property",
80
+ "id": 3,
81
+ "property_name": "name",
82
+ "property_type": "field_value",
83
+ "field_id": "254056"
84
+ },
85
+ {
86
+ "type": "property",
87
+ "id": 4,
88
+ "property_name": "state",
89
+ "property_type": "field_value",
90
+ "field_id": "270607"
91
+ }
92
+ ],
93
+ "property_name": "fishtank",
94
+ "app_id": "16259",
95
+ "filter": []
96
+ }
97
+ ```
98
+
99
+ ## jsonToItems(json, fieldsMap)
100
+
101
+ This method converts json to gudhub items. the conversion is made based on `fieldMap`. After items generated You can send them to create new items.
102
+
103
+ ```js
104
+ import {GudHub} from '@gudhub/gudhub';
105
+ const gudhub = new GudHub();
106
+ gudhub.jsonToItems(json, fieldsMap);
107
+ ```
108
+
109
+ Argument Name|Type|Description
110
+ ------------ | ------------- | -------------
111
+ *json* | `object` | json that is going to be converted to gudhub items
112
+ *fieldsMap* | `object` | and object in json format which contains instructions of how to convert to items
113
+
114
+ fieldsMap this map is an object array that contains field_id and jsonPath to get data from. We use jsonPath [jsonpath](https://www.npmjs.com/package/jsonpath) to parse json.
115
+
116
+ ```json
117
+ [
118
+ {
119
+ field_id: 431,
120
+ json_path : "$..item_id"
121
+ }
122
+ ]
123
+ ```
124
+
125
+ The method returns items list:
126
+
127
+ ```json
128
+ [
129
+ {
130
+ fields:[
131
+ {
132
+ field_id: 12356,
133
+ field_value: "test value"
134
+ }
135
+ ]
136
+ },
137
+ {
138
+ fields:[
139
+ {
140
+ field_id: 12356,
141
+ field_value: "test value2"
142
+ }
143
+ ]
144
+ }
145
+ ]
146
+ ```
147
+
148
+ ## populateWithItemRef()
149
+
150
+ We update destination Items with item_ref of sorce Items. Connectiontion between sorceItemsRef & srcFieldIdToCompare we are checking with help of srcFieldIdToCompare & destFieldIdToCompare. After connection is detected we save the item_ref into destFieldForRef.
151
+
152
+ ```js
153
+ import {GudHub} from '@gudhub/gudhub';
154
+ const gudhub = new GudHub();
155
+ gudhub.populateWithItemRef(sorceItemsRef, srcFieldIdToCompare, destinationItems, destFieldIdToCompare, destFieldForRef, appId);
156
+ ```
157
+
158
+ Argument Name|Type|Description
159
+ ------------ | ------------- | -------------
160
+ *sorceItemsRef* | `items` | items which will be used as referense for item_ref
161
+ *srcFieldIdToCompare* | `field_id` | we use value from this field to find the similar items in source and destimation items array
162
+ *destinationItems* | `items` | items those will be used to save item_ref to sorceItemsRef
163
+ *destFieldIdToCompare* | `field_id` | we use value from this field to find the similar items in source and destimation items array
164
+ *destFieldForRef* | `field_id` | field where we save value of item_ref
165
+ *appId* | `app_id` | we use app_id to generate value for item_ref
166
+
167
+ ## mergeItems()
168
+
169
+ We replace all fields with values in destinationItems by values from sorceItems. If destinationItems doesn't have fields that sorceItems then we create them in destinationItems.
170
+
171
+ ```js
172
+ import {GudHub} from '@gudhub/gudhub';
173
+ const gudhub = new GudHub();
174
+ gudhub.mergeItems(sorceItems, destinationItems);
175
+ ```
176
+
177
+ ## compareItems()
178
+
179
+ We compare fields of sorceItems with fields of destinationItems. It means that if sorceItems have the same fields with the same values as destinationItems thay will be described as 'same_items' even if destinationItems have additional fields those sorceItems doesn't have.
180
+
181
+ ```js
182
+ import {GudHub} from '@gudhub/gudhub';
183
+ const gudhub = new GudHub();
184
+ gudhub.compareItems (sorceItems, destinationItems, fieldToCompare) ;
185
+ ```
186
+
187
+ There to ways how it works:
188
+
189
+ 1. Compering items by item_id (if fieldToCompare is undefined)
190
+ 1. Compering items by value of specific field_id (if fieldToCompare is defined)
191
+
192
+ **compareItems() Return:**
193
+
194
+ ```json
195
+ {
196
+ is_items_diff: false,
197
+ new_src_items:[],
198
+ diff_src_items:[],
199
+ same_items:[]
200
+ }
201
+ ```
202
+
203
+ Argument Name|Type|Description
204
+ ------------ | ------------- | -------------
205
+ *sorceItems* | `items` | array of items that is going to be used as a sorce for comperison
206
+ *destinationItems* | `items` | array of items that is gong to be compared with sorceItems
207
+ *srcFieldIdToCompare* | `field_id` | field that we use to compare sorce items with destination items, if this is not specified then we compare items by item_id
208
+
209
+ ## getDate()
210
+
211
+ This method will return a date accorting to specified namespace. The name space should be in string format
212
+
213
+ ```js
214
+ import {GudHub} from '@gudhub/gudhub';
215
+ const gudhub = new GudHub();
216
+ gudhub.mergeItems(sorceItems, destinationItems);
217
+ ```
218
+
219
+ ## getDate()
220
+
221
+ This method will return a date accorting to specified namespace. The name space should be in string format
222
+
223
+ ```js
224
+ import {GudHub} from '@gudhub/gudhub';
225
+ const gudhub = new GudHub();
226
+ gudhub.getDate('this_sunday');
227
+ ```
228
+
229
+ The following namespaces are available now:
230
+
231
+ Date Namespaces | Description
232
+ ------------ | -------------
233
+ `now` | will return current date
234
+ `next_day` | should return current day + 24hours
235
+ `next_week` | it adds one week(7 days) to current date
236
+ `two_days_after` | it adds two days(24hours) to current date
237
+ `three_days_after` | it adds three days(24hours) to current date
238
+ `four_days_after` | it adds four days(24hours) to current date
239
+ `two_weeks_after` | it adds two weeks(7 days) to current date
240
+ `three_weeks_after` | it adds three weeks(7 days) to current date
241
+ `this_sunday` | will return date for sunday, with current utc time if it's a monday then it will return sunday from the next week
242
+ `this_monday` | will return date for monday, with current utc time if it's a saturday then it will return monday from the next week
243
+ `this_tuesday` | will return date for tuesday, with current utc time if it's a saturday then it will return tuesday from the next week
244
+ `this_wednesday` | will return date for wednesday, with current utc time if it's a saturday then it will return wednesday from the next week
245
+ `this_thursday` | will return date for thursday, with current utc time if it's a saturday then it will return thursday from the next week
246
+ `this_friday` | will return date for friday, with current utc time if it's a saturday then it will return friday from the next week
247
+ `this_saturday` | will return date for monday, with current utc time if it's a sunday then it will return saturday from the next week
248
+
249
+ `prefilter()`
250
+
251
+ `filter()`
252
+
253
+ `group()`
254
+
255
+ `mergeItems(src, destn)`
256
+
257
+ `compareItems()`
258
+
259
+ `populateWithItemRef()`
260
+
261
+ `(target, source, optionsArgument)`
262
+ It deeply merge two objects. We use this method two merge fields models
263
+ 0 Value of properties for source object woun't be changed by target object
264
+ 0 source of target hase unique properties they are going to be created in resulted object
265
+
266
+ ## makeNestedList ()
267
+
268
+ This method will return a new nested array from initial array.
269
+
270
+ ```js
271
+ import {GudHub} from '@gudhub/gudhub';
272
+ const gudhub = new GudHub();
273
+ let nestedList = gudhub.makeNestedList(array, id, parent_id, children_property);
274
+ ```
275
+
276
+ Argument Name | Type | Description
277
+ --------------|--------------|--------------
278
+ array | `array` | Array from which nested list will be generated
279
+ id | `string` | Parent property name
280
+ parent_id | `string` | Child property name
281
+ children_property | `string` | `(Optional)` Name of property, in which children items will be stored inside parent item. <br> Default is 'children'
282
+
283
+ Initial array example:
284
+
285
+ ```js
286
+ let input = [
287
+ {
288
+ name: "Article 1",
289
+ id: 1,
290
+ parent_id: 0
291
+ },
292
+ {
293
+ name: "Article 2",
294
+ id: 2,
295
+ parent_id: 1
296
+ },
297
+ {
298
+ name: "Article 3",
299
+ id: 3,
300
+ parent_id: 1
301
+ },
302
+ {
303
+ name: "Article 4",
304
+ id: 4,
305
+ parent_id: 0
306
+ }
307
+ ]
308
+ ```
309
+
310
+ Method call example:
311
+
312
+ ```js
313
+ let result = gudhub.makeNestedList(input, 'id', 'parent_id', 'custom_children_property')
314
+ ```
315
+
316
+ Result example:
317
+
318
+ ```js
319
+ [
320
+ {
321
+ id: 1,
322
+ name: "Article 1",
323
+ parent_id: 0,
324
+ custom_child_property: [
325
+ {
326
+ id: 2,
327
+ name: "Article 2",
328
+ parent_id: 1
329
+ },
330
+ {
331
+ id: 3,
332
+ name: "Article 3",
333
+ parent_id: 1
334
+ }
335
+ ]
336
+ },
337
+ {
338
+ id: 4,
339
+ name: "Article 4",
340
+ parent_id: 0
341
+ }
342
+ ]
343
+ ```
344
+
345
+ # App Processor:
346
+
347
+ ## getAppInfo()
348
+
349
+ it returs App with Empty `field_list:[]`, `items_list:[]`, `file_list:[]`, `views_list:[]`. Such simmple data needed to render App Icons, and do some simple updates in App like: updating App name icon permisions etc when full app data is not needed
350
+
351
+ ```js
352
+ import {GudHub} from '@gudhub/gudhub';
353
+ const gudhub = new GudHub();
354
+ gudhub.getAppInfo(appId);
355
+ ```
356
+
357
+ Argument Name|Type|Description
358
+ ------------ | ------------- | -------------
359
+ *appId* | `app_id` | we use app_id to generate value for item_ref
360
+
361
+ **getAppInfo() returns folowing object:**
362
+
363
+ ```json
364
+ {
365
+ app_id: 13360,
366
+ app_name: "Contacts"
367
+ field_list: [],
368
+ file_list: [],
369
+ group_id: 13329,
370
+ icon: {id: 12762, icon_id: "user", icon_color: "ffffff", gradient_up: "ff758c", gradient_down: "ff7eb3"}
371
+ items_list: [],
372
+ keys_list: [],
373
+ last_update: 1608657765499,
374
+ permission: 4,
375
+ priority: 0,
376
+ privacy: 0,
377
+ show: true,
378
+ trash: false,
379
+ view_init: 281591,
380
+ views_list: []
381
+ }
382
+ ```
383
+
384
+ `getApp(app_id)` return app;
385
+
386
+ `To Be Done` -> `getAppList()` return List of Applications those are shared to users;
387
+
388
+ # App Processor:
389
+
390
+ ## getAppInfo()
391
+
392
+ it returs App with Empty `field_list:[]`, `items_list:[]`, `file_list:[]`, `views_list:[]`. Such simmple data needed to render App Icons, and do some simple updates in App like: updating App name icon permisions etc when full app data is not needed
393
+
394
+ ```js
395
+ import {GudHub} from '@gudhub/gudhub';
396
+ const gudhub = new GudHub();
397
+ gudhub.getAppInfo(appId);
398
+ ```
399
+
400
+ Argument Name|Type|Description
401
+ ------------ | ------------- | -------------
402
+ *appId* | `app_id` | we use app_id to generate value for item_ref
403
+
404
+ **It returns folowing object:**
405
+
406
+ ```json
407
+ {
408
+ app_id: 13360,
409
+ app_name: "Contacts"
410
+ field_list: [],
411
+ file_list: [],
412
+ group_id: 13329,
413
+ icon: {id: 12762, icon_id: "user", icon_color: "ffffff", gradient_up: "ff758c", gradient_down: "ff7eb3"}
414
+ items_list: [],
415
+ keys_list: [],
416
+ last_update: 1608657765499,
417
+ permission: 4,
418
+ priority: 0,
419
+ privacy: 0,
420
+ show: true,
421
+ trash: false,
422
+ view_init: 281591,
423
+ views_list: []
424
+ }
425
+ ```
426
+
427
+ `getApp(app_id)` return app;
428
+
429
+ `To Be Done` -> `getAppList()` return List of Applications those are shared to users;
430
+
431
+
432
+ # User:
433
+
434
+ `login()`;(is not needed)
435
+
436
+ `logout()`;
437
+
438
+ `signup()`;(is not needed)
439
+
440
+ `getUser()`;
441
+
442
+ `getUsersList()`;
443
+
444
+ `updateUser()`;
445
+
446
+ `avatarUpload()`;
447
+
448
+ `getVersion()`;
449
+
450
+ ## Sharing
451
+
452
+ `getUsersWithPermision()`;
453
+
454
+ `sharingAdd()`;
455
+
456
+ `sharingUpdate()`;
457
+
458
+ `sharingDelete()`;
459
+
460
+ ## Items Processor
461
+
462
+ `itemsGet(app_id, items_id_array)` return items by item_id from the array;
463
+
464
+ `filteredItemsGet(app_id, filter)` return items according to filter;
465
+
466
+ `itemGet(app_id, item_id)` return item;
467
+
468
+ `itemsAdd(app_id, items)` add items to app;
469
+
470
+ `itemsUpdate(app_id, items)` update items in the app;
471
+
472
+ ## Field Processor
473
+
474
+ `elementGet(element_id)` return element `beta`;
475
+
476
+ `fieldValueGet(app_id, item_id, field_id)` return field value;
477
+
478
+ `valueUpdate(app_id, item_id, field_id, field_value)` update value in a field;
479
+
480
+ `getModel(app_id, field_id)` return data_model of field;
481
+
482
+ `getInterpretedValue(app_id, item_id, field_id)` return interpreted value of field;
483
+
484
+ ## File Processor
485
+
486
+ `uploadFile(fileData, app_id, item_id)` create a file from data;
487
+
488
+ `uploadFileFromString(data, file_name, app_id, item_id, extension, format)` create a file from string;
489
+
490
+ `updateFileFromString(data, file_id, file_name, extension, format)` update file from string;
491
+
492
+ `getFile(app_id, file_id)` get file by appId and fileId;
493
+
494
+ `getFiles(app_id, [fileId, fileId])` get files by appId and arrays of filesId;
495
+
496
+ `deleteFile(id)` delete file by fileId;
497
+
498
+ ## Document Processor
499
+
500
+ `createDocument({app_id, item_id, element_id, data: Object})` create a document;
501
+
502
+ `getDocument({app_id, item_id, element_id})` get a document;
503
+
504
+ `getDocuments([{app_id, item_id, element_id}, {app_id, item_id, element_id}])` get documents;
505
+
506
+ `deleteDocument({app_id, item_id, element_id})` delete a document;
507
+
508
+ ## PipeService
509
+
510
+ ### Methods
511
+
512
+ `on(types, destination, fn)`
513
+
514
+ `emit(types, destination, address, params)`
515
+
516
+ `destroy(types, destination, fn)`
517
+
518
+ #### _Examples_
519
+
520
+ ```js
521
+ on("gh_items_update", {app_id: 1, item_id: 1}, function getItems(event, address, params){})
522
+
523
+ emit("gh_items_update", {app_id: 1, item_id: 1}, items, params)
524
+
525
+ destroy("gh_items_update", {app_id: 1, item_id: 1}, function getItems(event, address, params){})
526
+ ```
527
+
528
+ ### Events
529
+
530
+ Event name|Address example
531
+ ------------ | -------------
532
+ `gh_items_update` |{app_id: 1, item_id: 1}
533
+ `gh_app_update` |{app_id: 1}
534
+ `gh_item_update` |{app_id: 1, item_id: 1}
535
+ `gh_value_update` |{app_id: 1, item_id: 1, field_id: 1}
536
+
537
+ ________