npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

robolt

v0.3.4

Published

a frontend helper class for projects using Robogo and Axios

Downloads

7

Readme

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:

| Parameter | Type | Description | Default | |:-|:-:|:-:|:-:| |axios|Function|The axios function preconfigured| |prefix|String|The prefix that was used when the routes of robogo were registered to express.js| |serveStaticPath|String|The path where the files are static hosted. Same as in the constructor of robogo|'static'| |defaultFilter|Object|A 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:

| key | type | description | |:-|:-:|:-:| | modelName | String | Name of the model registered in robogo| | documentObject | Object | Object 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:

| key | type | description | example | |:-|:-:|:-:|:-:| | filter | Object | Mongodb query | {friends: 'Chandler'} | | projection | Array<String> | Fields to include in results. Uses MongoDB projection. | ['username', 'friends'] | | sort | Object | Mongodb sort | { age : 1 } | | skip | Number | The number of documents to skip in the results set. | 10 | | limit | Number | The 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:

| key | type | description | example | |:-|:-:|:-:|:-:| | projection | Array<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:

| key | type | description | example | |:-|:-:|:-:|:-:| | filter | Object | Mongodb query | {friends: 'Chandler'} | | projection | Array<String> | Fields to include in results. Uses MongoDB projection. | ['username', 'friends'] | | threshold | Number | Fuse.js threshold, defaults to 0.4 | 0.6 | | keys | Array<String> | Keys of the document that are searched in. If no keys are provided all keys of the document will be used. | ['username'] | | depth | Number | If no keys are provided, we can limit the depth of the keys to be picked from the schema, starts from 0, defaults to Infinity | 2 | | term | String | Search 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:

| key | type | description | |:-|:-:|:-:| | serviceName | String | Name of the service (.js file) registered in robogo| | functionName | String | Name of the function inside the service | | params | Any | The 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:

| key | type | description | |:-|:-:|:-:| | serviceName | String | Name of the service (.js file) registered in robogo| | functionName | String | Name of the function inside the service | | params | Any | The 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:

| key | type | description | |:-|:-:|:-:| | file | File | File instance, eg.: from a file input | | percentCallback | Function | Callback 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.

  • Returns: {absolutePath, relativePath[, absoluteThumbnailPath, relativeThumbnailPath]}
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:

| key | type | description | |:-|:-:|:-:| | file | String/Object | Either the whole RoboFile document of the file or its _id| | percentCallback | Function | Callback 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:

| key | type | description | |:-|:-:|:-:| | file | String/Object | Either the whole RoboFile document of the file or its _id value| | percentCallback | Function | Callback 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:

| key | type | description | |:-|:-:|:-:| | file | String/Object | Either the whole RoboFile document of the file or its _id value| | percentCallback | Function | Callback 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:

| key | type | description | |:-|:-:|:-:| | file | String/Object | Either the whole RoboFile document of the file or its _id value| | percentCallback | Function | Callback 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