@gudhub/gudhub v1.0.36
GUDHUB
I't a Library to simplify work with GudHub API. Also this Library cantains utilites for beter aperation with items
, fields
and apps
!
npm Package
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.
Publishing gudhub lib to npm
In order to publish new version of the GudHub Lib you have to:
- Change vertsion in
package.json
- Commit your chagnes into repository to the
master
branch - Run
npm publish
command which will publish new version to npm
Development gudhub lib
If you'd like to develop GudHub Lib in another enviroment, let's say in GudHubClient you have to do the falowing things:
- You should go to the
gudhub
folder and run therenpm init @gudhub/gudhub
command, it will install the @gudhub/gudhub package in to your global enviroment - Then you have to add
@gudhub/gudhub
to yourpackage.json
as a dependency. - Then package will be downloaded from your local computer after you run
npm run dev
ornpm install
command
Initialization
There are several ways to initialize GudHub. The most simple way is initializing gudhub without arguments. It this way will be available utils only
import {GudHub} from '@gudhub/gudhub';
const gudhub = new GudHub();
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.
In this case you will be able to operate with GudHub data and use all mothods those are listed here.
import {GudHub} from '@gudhub/gudhub';
const gudhub = new GudHub(auth_key);
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 )
import {GudHub} from '@gudhub/gudhub';
const gudhub = new GudHub(auth_key,{
server_url : "https://gudhub.com/GudHub",
wss_url : "wss://gudhub.com/GudHub/ws/app/",
initWebsocket : false
});
Param Name | Description | Default Value |
---|---|---|
server_url | All request will send to this url | https://gudhub.com/GudHub |
wss_url | url to setup websoket connection | wss://gudhub.com/GudHub/ws/app/ |
initWebsocket | here we can turn off websoket connection | false |
Utils:
jsonConstructor(scheme, items)
With this method you can get json according to the scheme.
import {GudHub} from '@gudhub/gudhub';
const gudhub = new GudHub();
gudhub.jsonConstructor(scheme);
Sheme Example:
{
"type": "array",
"id": 1,
"childs": [
{
"type": "property",
"id": 3,
"property_name": "name",
"property_type": "field_value",
"field_id": "254056"
},
{
"type": "property",
"id": 4,
"property_name": "state",
"property_type": "field_value",
"field_id": "270607"
}
],
"property_name": "fishtank",
"app_id": "16259",
"filter": []
}
jsonToItems(json, fieldsMap)
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.
import {GudHub} from '@gudhub/gudhub';
const gudhub = new GudHub();
gudhub.jsonToItems(json, fieldsMap);
Argument Name | Type | Description |
---|---|---|
json | object | json that is going to be converted to gudhub items |
fieldsMap | object | and object in json format which contains instructions of how to convert to items |
fieldsMap this map is an object array that contains field_id and jsonPath to get data from. We use jsonPath jsonpath to parse json.
[
{
field_id: 431,
json_path : "$..item_id"
}
]
The method returns items list:
[
{
fields:[
{
field_id: 12356,
field_value: "test value"
}
]
},
{
fields:[
{
field_id: 12356,
field_value: "test value2"
}
]
}
]
populateWithItemRef()
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.
import {GudHub} from '@gudhub/gudhub';
const gudhub = new GudHub();
gudhub.populateWithItemRef(sorceItemsRef, srcFieldIdToCompare, destinationItems, destFieldIdToCompare, destFieldForRef, appId);
Argument Name | Type | Description |
---|---|---|
sorceItemsRef | items | items which will be used as referense for item_ref |
srcFieldIdToCompare | field_id | we use value from this field to find the similar items in source and destimation items array |
destinationItems | items | items those will be used to save item_ref to sorceItemsRef |
destFieldIdToCompare | field_id | we use value from this field to find the similar items in source and destimation items array |
destFieldForRef | field_id | field where we save value of item_ref |
appId | app_id | we use app_id to generate value for item_ref |
mergeItems()
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.
import {GudHub} from '@gudhub/gudhub';
const gudhub = new GudHub();
gudhub.mergeItems(sorceItems, destinationItems);
compareItems()
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.
import {GudHub} from '@gudhub/gudhub';
const gudhub = new GudHub();
gudhub.compareItems (sorceItems, destinationItems, fieldToCompare) ;
There to ways how it works:
- Compering items by item_id (if fieldToCompare is undefined)
- Compering items by value of specific field_id (if fieldToCompare is defined)
compareItems() Return:
{
is_items_diff: false,
new_src_items:[],
diff_src_items:[],
same_items:[]
}
Argument Name | Type | Description |
---|---|---|
sorceItems | items | array of items that is going to be used as a sorce for comperison |
destinationItems | items | array of items that is gong to be compared with sorceItems |
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 |
getDate()
This method will return a date accorting to specified namespace. The name space should be in string format
import {GudHub} from '@gudhub/gudhub';
const gudhub = new GudHub();
gudhub.mergeItems(sorceItems, destinationItems);
getDate()
This method will return a date accorting to specified namespace. The name space should be in string format
import {GudHub} from '@gudhub/gudhub';
const gudhub = new GudHub();
gudhub.getDate('this_sunday');
The following namespaces are available now:
Date Namespaces | Description |
---|---|
now | will return current date |
next_day | should return current day + 24hours |
next_week | it adds one week(7 days) to current date |
two_days_after | it adds two days(24hours) to current date |
three_days_after | it adds three days(24hours) to current date |
four_days_after | it adds four days(24hours) to current date |
two_weeks_after | it adds two weeks(7 days) to current date |
three_weeks_after | it adds three weeks(7 days) to current date |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
prefilter()
filter()
group()
mergeItems(src, destn)
compareItems()
populateWithItemRef()
(target, source, optionsArgument)
It deeply merge two objects. We use this method two merge fields models
0 Value of properties for source object woun't be changed by target object
0 source of target hase unique properties they are going to be created in resulted object
makeNestedList ()
This method will return a new nested array from initial array.
import {GudHub} from '@gudhub/gudhub';
const gudhub = new GudHub();
let nestedList = gudhub.makeNestedList(array, id, parent_id, children_property);
Argument Name | Type | Description |
---|---|---|
array | array | Array from which nested list will be generated |
id | string | Parent property name |
parent_id | string | Child property name |
children_property | string | (Optional) Name of property, in which children items will be stored inside parent item. Default is 'children' |
Initial array example:
let input = [
{
name: "Article 1",
id: 1,
parent_id: 0
},
{
name: "Article 2",
id: 2,
parent_id: 1
},
{
name: "Article 3",
id: 3,
parent_id: 1
},
{
name: "Article 4",
id: 4,
parent_id: 0
}
]
Method call example:
let result = gudhub.makeNestedList(input, 'id', 'parent_id', 'custom_children_property')
Result example:
[
{
id: 1,
name: "Article 1",
parent_id: 0,
custom_child_property: [
{
id: 2,
name: "Article 2",
parent_id: 1
},
{
id: 3,
name: "Article 3",
parent_id: 1
}
]
},
{
id: 4,
name: "Article 4",
parent_id: 0
}
]
App Processor:
getAppInfo()
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
import {GudHub} from '@gudhub/gudhub';
const gudhub = new GudHub();
gudhub.getAppInfo(appId);
Argument Name | Type | Description |
---|---|---|
appId | app_id | we use app_id to generate value for item_ref |
getAppInfo() returns folowing object:
{
app_id: 13360,
app_name: "Contacts"
field_list: [],
file_list: [],
group_id: 13329,
icon: {id: 12762, icon_id: "user", icon_color: "ffffff", gradient_up: "ff758c", gradient_down: "ff7eb3"}
items_list: [],
keys_list: [],
last_update: 1608657765499,
permission: 4,
priority: 0,
privacy: 0,
show: true,
trash: false,
view_init: 281591,
views_list: []
}
getApp(app_id)
return app;
To Be Done
-> getAppList()
return List of Applications those are shared to users;
App Processor:
getAppInfo()
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
import {GudHub} from '@gudhub/gudhub';
const gudhub = new GudHub();
gudhub.getAppInfo(appId);
Argument Name | Type | Description |
---|---|---|
appId | app_id | we use app_id to generate value for item_ref |
It returns folowing object:
{
app_id: 13360,
app_name: "Contacts"
field_list: [],
file_list: [],
group_id: 13329,
icon: {id: 12762, icon_id: "user", icon_color: "ffffff", gradient_up: "ff758c", gradient_down: "ff7eb3"}
items_list: [],
keys_list: [],
last_update: 1608657765499,
permission: 4,
priority: 0,
privacy: 0,
show: true,
trash: false,
view_init: 281591,
views_list: []
}
getApp(app_id)
return app;
To Be Done
-> getAppList()
return List of Applications those are shared to users;
User:
login()
;(is not needed)
logout()
;
signup()
;(is not needed)
getUser()
;
getUsersList()
;
updateUser()
;
avatarUpload()
;
getVersion()
;
Sharing
getUsersWithPermision()
;
sharingAdd()
;
sharingUpdate()
;
sharingDelete()
;
Items Processor
itemsGet(app_id, items_id_array)
return items by item_id from the array;
filteredItemsGet(app_id, filter)
return items according to filter;
itemGet(app_id, item_id)
return item;
itemsAdd(app_id, items)
add items to app;
itemsUpdate(app_id, items)
update items in the app;
Field Processor
elementGet(element_id)
return element beta
;
fieldValueGet(app_id, item_id, field_id)
return field value;
valueUpdate(app_id, item_id, field_id, field_value)
update value in a field;
getModel(app_id, field_id)
return data_model of field;
getInterpretedValue(app_id, item_id, field_id)
return interpreted value of field;
File Processor
uploadFile(fileData, app_id, item_id)
create a file from data;
uploadFileFromString(data, file_name, app_id, item_id, extension, format)
create a file from string;
updateFileFromString(data, file_id, file_name, extension, format)
update file from string;
getFile(app_id, file_id)
get file by appId and fileId;
getFiles(app_id, [fileId, fileId])
get files by appId and arrays of filesId;
deleteFile(id)
delete file by fileId;
Document Processor
createDocument({app_id, item_id, element_id, data: Object})
create a document;
getDocument({app_id, item_id, element_id})
get a document;
getDocuments([{app_id, item_id, element_id}, {app_id, item_id, element_id}])
get documents;
deleteDocument({app_id, item_id, element_id})
delete a document;
PipeService
Methods
on(types, destination, fn)
emit(types, destination, address, params)
destroy(types, destination, fn)
Examples
on("gh_items_update", {app_id: 1, item_id: 1}, function getItems(event, address, params){})
emit("gh_items_update", {app_id: 1, item_id: 1}, items, params)
destroy("gh_items_update", {app_id: 1, item_id: 1}, function getItems(event, address, params){})
Events
Event name | Address example |
---|---|
gh_items_update | {app_id: 1, item_id: 1} |
gh_app_update | {app_id: 1} |
gh_item_update | {app_id: 1, item_id: 1} |
gh_value_update | {app_id: 1, item_id: 1, field_id: 1} |
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago