1.0.36 • Published 2 years ago

@gudhub/gudhub v1.0.36

Weekly downloads
-
License
ISC
Repository
bitbucket
Last release
2 years ago

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:

  1. Change vertsion in package.json
  2. Commit your chagnes into repository to the master branch
  3. 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:

  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
  2. Then you have to add @gudhub/gudhub to your package.json as a dependency.
  3. Then package will be downloaded from your local computer after you run npm run dev or npm 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 NameDescriptionDefault Value
server_urlAll request will send to this urlhttps://gudhub.com/GudHub
wss_urlurl to setup websoket connectionwss://gudhub.com/GudHub/ws/app/
initWebsockethere we can turn off websoket connectionfalse

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 NameTypeDescription
jsonobjectjson that is going to be converted to gudhub items
fieldsMapobjectand 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 NameTypeDescription
sorceItemsRefitemsitems which will be used as referense for item_ref
srcFieldIdToComparefield_idwe use value from this field to find the similar items in source and destimation items array
destinationItemsitemsitems those will be used to save item_ref to sorceItemsRef
destFieldIdToComparefield_idwe use value from this field to find the similar items in source and destimation items array
destFieldForReffield_idfield where we save value of item_ref
appIdapp_idwe 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:

  1. Compering items by item_id (if fieldToCompare is undefined)
  2. 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 NameTypeDescription
sorceItemsitemsarray of items that is going to be used as a sorce for comperison
destinationItemsitemsarray of items that is gong to be compared with sorceItems
srcFieldIdToComparefield_idfield 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 NamespacesDescription
nowwill return current date
next_dayshould return current day + 24hours
next_weekit adds one week(7 days) to current date
two_days_afterit adds two days(24hours) to current date
three_days_afterit adds three days(24hours) to current date
four_days_afterit adds four days(24hours) to current date
two_weeks_afterit adds two weeks(7 days) to current date
three_weeks_afterit adds three weeks(7 days) to current date
this_sundaywill return date for sunday, with current utc time if it's a monday then it will return sunday from the next week
this_mondaywill return date for monday, with current utc time if it's a saturday then it will return monday from the next week
this_tuesdaywill return date for tuesday, with current utc time if it's a saturday then it will return tuesday from the next week
this_wednesdaywill return date for wednesday, with current utc time if it's a saturday then it will return wednesday from the next week
this_thursdaywill return date for thursday, with current utc time if it's a saturday then it will return thursday from the next week
this_fridaywill return date for friday, with current utc time if it's a saturday then it will return friday from the next week
this_saturdaywill 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 NameTypeDescription
arrayarrayArray from which nested list will be generated
idstringParent property name
parent_idstringChild property name
children_propertystring(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 NameTypeDescription
appIdapp_idwe 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 NameTypeDescription
appIdapp_idwe 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 nameAddress 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}

1.0.36

2 years ago

1.0.35

2 years ago

1.0.34

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.29

3 years ago

1.0.30

3 years ago

1.0.27

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago