0.3.4 • Published 10 months ago

robolt v0.3.4

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
10 months ago

robolt

Robolt is a frontend helper class for projects using Robogo and Axios. The aim is to provide an easy to use and flexible way to communicate with robogo.

Table of contents

Disclaimer

We take no responsibility for any demage done by this package.

If you find anything that isn't working or not up to the documentation, please open issue or a pull request over on github.

Thank You in advance!

Getting started

A very simple example:

import Robolt from 'robolt'
import axios from 'axios'

// configure axios here if needed (eg.: baseURL) before creating the robolt instance

const robolt = new Robolt(axios, 'api')

// robolt is ready to be used!

The constructor uses the following parameters:

ParameterTypeDescriptionDefault
axiosFunctionThe axios function preconfigured
prefixStringThe prefix that was used when the routes of robogo were registered to express.js
serveStaticPathStringThe path where the files are static hosted. Same as in the constructor of robogo'static'
defaultFilterObjectA MongoDB filter object. Every request's filter will be this object if no filter was provided{}

Methods

This section will describe the methods of robolt that are available to use. These are organized in seven categories: Create, Read, Update, Delete, Service, File and Special.

Create methods

Every create method returns a Promise that is resolved with the result or rejected with an error.

Create

Sends a POST request to the '/create/:model' route of robogo with the given data.

  • Method: POST
  • Resolves: Object (MongoDB document)
this.$API.Create(modelName, documentObject)
.then( document =>  ...  )
.catch( error =>  ...  )
Params:
keytypedescription
modelNameStringName of the model registered in robogo
documentObjectObjectObject matching the schema of the model

Read methods

Every read method returns a Promise that is resolved with the result or rejected with an error.

Read

Sends a GET request to the '/read/:model' route of robogo with the given data.

  • Method: GET
  • Resolves: Array<Object (MongoDB document)>
this.$API.Read(modelName[, optionsObject ])
.then( documents =>  ...  )
.catch( error =>  ...  )
optionsObject:
keytypedescriptionexample
filterObjectMongodb query{friends: 'Chandler'}
projectionArray\<String>Fields to include in results. Uses MongoDB projection.'username', 'friends'
sortObjectMongodb sort{ age : 1 }
skipNumberThe number of documents to skip in the results set.10
limitNumberThe number of documents to include in the results set.5

Get

Sends a GET request to the '/get/:model/:id' route of robogo with the given data.

  • Method: GET
  • Resolves: Object (MongoDB document)
this.$API.Get(modelName, documentId[, optionsObject ])
.then( document =>  ...  )
.catch( error =>  ...  )
optionsObject:
keytypedescriptionexample
projectionArray\<String>Fields to include in projection.'username', 'friends'

Search

Sends a GET request to the '/search/:model' route of robogo with the given data.

  • Method: GET
  • Resolves: Array<Object (MongoDB document)>
this.$API.Search(modelName[, optionsObject ])
.then( documents =>  ...  )
.catch( error =>  ...  )
optionsObject:
keytypedescriptionexample
filterObjectMongodb query{friends: 'Chandler'}
projectionArray\<String>Fields to include in results. Uses MongoDB projection.'username', 'friends'
thresholdNumberFuse.js threshold, defaults to 0.40.6
keysArray\<String>Keys of the document that are searched in. If no keys are provided all keys of the document will be used.'username'
depthNumberIf no keys are provided, we can limit the depth of the keys to be picked from the schema, starts from 0, defaults to Infinity2
termStringSearch term that is searched for'search term'

Update methods

Every update method returns a Promise that is resolved with the result or rejected with an error.

Update

Sends a PATCH request to the '/update/:model' route of robogo with the given data.

this.$API.Update(modelName, documentObject)
.then( result =>  ...  )
.catch( error =>  ...  )
documentObject:

An object with an _id field containing the ObjectId of the document we want to update and the fields we want to change with their new values.

Delete methods

Every delete method returns a Promise that is resolved with the result or rejected with an error.

Delete

Sends a DELETE request to the '/delete/:model/:id' route of robogo with the given document _id.

this.$API.Delete(modelName, documentId)
.then( result =>  ...  )
.catch( error =>  ...  )

Service methods

Every service method returns a Promise that is resolved with the result or rejected with an error.

RunService

Sends a POST request to the '/runner/:service/:function' route of robogo with the given data.

  • Method: POST
  • Resolves: Any
this.$API.RunService(serviceName, functionName, params)
.then( result =>  ...  )
.catch( error =>  ...  )
Params:
keytypedescription
serviceNameStringName of the service (.js file) registered in robogo
functionNameStringName of the function inside the service
paramsAnyThe parameters that the service awaits

GetService

Sends a GET request to the '/getter/:service/:function' route of robogo with the given data.

  • Method: GET
  • Resolves: Any
this.$API.GetService(serviceName, functionName, params)
.then( result =>  ...  )
.catch( error =>  ...  )
Params:
keytypedescription
serviceNameStringName of the service (.js file) registered in robogo
functionNameStringName of the function inside the service
paramsAnyThe parameters that the service awaits

File methods

UploadFile

Sends a POST (multipart/form-data) request to the '/fileupload' route of robogo with the given file.

this.$API.UploadFile(file[, percentCallback])
.then( result =>  ...  )
.catch( error =>  ...  )
Params:
keytypedescription
fileFileFile instance, eg.: from a file input
percentCallbackFunctionCallback that will be called multiple times, while the file is uploading. Its parameter is a number between 0 and 100

GetFileURLs

Returns the file's absolute and relative URLs where it is static hosted by robogo. If a thumbnail was also created it also returns the thumbnail's URLs.

this.$API.GetFileURLs(file)
file:

RoboFile document to the file

GetFile

Downloads the file for a RoboFile document from robogo.

  • Method: GET
  • Returns: Promise\<File>
this.$API.GetFile(file[, percentCallback])
Params:
keytypedescription
fileString/ObjectEither the whole RoboFile document of the file or its _id
percentCallbackFunctionCallback that will be called multiple times, while the file is downloading. Its parameter is a number between 0 and 100

GetFileURL

Downloads the file for a RoboFile document from robogo and returns a local URL for it.

  • Method: GET
  • Returns: Promise\<String>
this.$API.GetFileURL(file[, percentCallback])
Params:
keytypedescription
fileString/ObjectEither the whole RoboFile document of the file or its _id value
percentCallbackFunctionCallback that will be called multiple times, while the file is downloading. Its parameter is a number between 0 and 100

GetThumbnail

Downloads the thumbnail file for a RoboFile document from robogo.

  • Method: GET
  • Returns: Promise\<File>
this.$API.GetThumbnail(file[, percentCallback])
Params:
keytypedescription
fileString/ObjectEither the whole RoboFile document of the file or its _id value
percentCallbackFunctionCallback that will be called multiple times, while the file is downloading. Its parameter is a number between 0 and 100

GetThumbnailURL

Downloads the thumbnail file for a RoboFile document from robogo and returns a local URL for it.

  • Method: GET
  • Returns: Promise\<String>
this.$API.GetThumbnailURL(file[, percentCallback])
Params:
keytypedescription
fileString/ObjectEither the whole RoboFile document of the file or its _id value
percentCallbackFunctionCallback that will be called multiple times, while the file is downloading. Its parameter is a number between 0 and 100

DeleteFile

Sends a DELETE request to the '/filedelete/:id' route of robogo with the given file id.

  • Method: DELETE
  • Returns: Promise\<Empty>
this.$API.DeleteFile(file)
.then( result =>  ...  )
.catch( error =>  ...  )
File:

Either the whole RoboFile document of the file or its _id.

Special methods

Every special method returns a Promise that is resolved with the result or rejected with an error.

Model

Sends a GET request to the '/model' or the 'model/:model' route of robogo, depending on wether the modelName parameter was given.

  • Method: GET
  • Resolves into: Array\<Object>|Object
this.$API.Model(modelName)
.then( model => ... )
.catch( error => ... )

Schema

Sends a GET request to the '/schema/:model' route of robogo.

  • Method: GET
  • Resolves into: Object
this.$API.Schema(modelName)
.then( schema => ... )
.catch( error => ... )

Fields

Sends a GET request to the '/fields/:model' route of robogo.

  • Methods: GET
  • Resolves into: Array of Objects
this.$API.Fields(modelName, depth)
.then( fields => ... )
.catch( error => ... )
depth:

Number that limits the depth of the fields to be returned. Starts from 0, defaults to Infinity.

RecycledSchema

Returns the same result as the Schema method, but reintroduces circular references, that were stripped out by Robogo before sending the data to the frontend.

  • Method: GET
  • Resolves into: Object
this.$API.RecycledSchema(modelName)
.then( schema => ... )
.catch( error => ... )

Count

Sends a GET request to the '/count/:model' route of robogo.

  • Methods: GET
  • Resolves into: Number
this.$API.Count(modelName[, filter])
.then( count => ... )
.catch( error => ... )
filter:

MongoDB filter object

SearchKeys

Sends a GET request to the '/searchkeys/:model' route of robogo.

  • Methods: GET
  • Resolves into: Array\<String>
this.$API.SearchKeys(modelName[, depth])
.then( keys => ... )
.catch( error => ... )
depth:

Number, that limits the depth of the keys to be picked from the model's schema

Contributing

Every contribution is more then welcomed. If you have an idea or made some changes to the code, please open an issue or a pull request at the package's github page.

Authors

  • Horváth Bálint
  • Zákány Balázs
0.3.4

10 months ago

0.3.3

1 year ago

0.2.3

2 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago