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

currentrequest

v2.2.3

Published

Request handling engine for handling server or small task. for more visit : readme.md

Downloads

5

Readme

CurrentRequest

CurrentRequest is engine which can execute any given batch of method's or function's which you want to execute small or big task based on your need. with some inbuilt functionality which are pretty much help full for developing application's in javascript.

Use case's :

  1. Creating REST Api's
  2. Creating javascript application's
  3. Request Handler

Below are considiration what CurrentRequest is about:

  1. Dry Code
  2. Scalable Project Structuring
  3. Pauseable Server
  4. Multiple dataBase or without database.
  5. Machine Learing support
  6. Smart Cache
  7. Integration [AWS, Sentry, Ejs and Pug].

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Documentation : comming soon

Prerequisites

1. Enviornment Variable's.

Details: CurrentRequest need some environment variable which will going to be needed for handling project. below are all environment variable's on which currentRequest depend's on. you can change them if your project folder location's are different.

NAME ='CurrentRequest' // projectname : used as Database name and Server name
DMDir = 'dyna_modules' // directory: directory name containg your method's.
MLDir = 'ml_modules' // directory: machine learning directory name module's directory.
GUIDir = 'GUI' // directory : directory name containg view in following languages [pug, ejs]
ENVIRONMENT=development // debug: used when debuging error and return's by method.
CR_RETURN_TYPE=configuration // output : current request process your request and can return output [single object] or internal configuration containg every information form who runned and when.
AWS_SECRET_ACCESS_KEY="Your AWS sceret accesskey" // AWS : used when connect's with AWS account.
AWS_ACCESS_KEY="access_key" // AWS : used when connect's with AWS account.
SENTRY_DSN="dsn_key" // ERROR : useful for handling any error occured internally in queue.

2. Database Driver

Details: Each batch of task output return's [array] containg output of each method.now you can store these output to database for that just run your database server currentRequest currentlly support's mongoDB[stable] and mySql[comming soon] or if you want to see just output no database run than just pass _noDatabase key in configuration.

Note 1: Query will be auto generated so in database you will going to see structure to your every collection > document

Note 2: By default mongoDB is used is database option for other database's pass { _connectTo : "databaseName" } in configuration.

Structure :

_RAW: {
    _method1 : "methodOutput",
    _method2 : "methodOutput",
    _method3 : "methodOutput"
}

Installing

CurrentRequest can installed with following flavour's.

Npm :

npm i currentrequest --save

Yarn :

yarn add currentrequest

Clone :

git clone https://gitlab.com/rootandleaves/currentrequest.git

Configuration

CurrentRequest require's configuration in-order to run. each configuration key relates to special work in engine.

  1. whichDoc : whichDoc defines on which document or table name you want to work on in database.
  2. hooks : hooks object can contain for way's or all way's { _onLoad: {}, _onExecute: {}, _onReturn: {}, _onError: {} } to execute external method's..
  3. RAWInclude : allowed method's name which will be going to stored in database.
  4. FileManager_Config, : file manager for handling buffer or stream in request.
  5. _POST: request payload [form-data etc..] need to be JSON format.
  6. _POST_SCHEMA : schema for handling POST any key which is not defined in schema will result in delete POST[key] for safe POST.
  7. returnFormat : currentRequest can return data in two format's either 'data' || 'configuration'
  8. task : which curd operation you wan't to perform [read, create, drop, update, optimizedCreate]

Please note : This is not complete list of configuration for that please read doc's

X-Header

CurrentRequest has special method named xHeader which allow's currentrequest to validate user's or client's based on interaction. these is done as follow's :

Step's

  1. When xHeader is called by engine it check's for header key : "y" which contain unique identifier [of your choice..]
  2. Check's if y belong's to someone or if it does than it check's what "masterEmail" you provided with that fail's it will start counting for blocking given "ip" address after 3 max trie's. if not than it continue's to step 3.
  3. if "masterEmail" and it's "y" key match's than it continue's execution..skipping step 4
  4. It Take's "y" key value from header and than generate new unique key based on "y" and pair them together.
  5. Re-update request with two new key's : "x" and "y"
  6. Continue request as usual.

Why xHeader.

  1. it stop's abuse of server and queue execution. as validation fail's engine will not going to continue with given ip address.
  2. It allow's request to structure itself with engine as each request "y" is going to contain unqiue identifier. you can create anything you like ex: request.headers['y'] = 'SMARTAPP::uniqueString' for your application's.

How to use ?

Below is simple example of account registration api in less than 1 min.

MongoDB Server :

sudo mongod --master

Redis Server :

redis-server /usr/local/etc/redis.conf; sudo redis-server /usr/local/etc/redis.conf

Code Setup :

import CurrentRequest from 'currentRequest' // npm: modern code handler tool.
import Joi from 'joi' // npm: object validation libary.


/*
GLOBAL'S.
 */
let _ProceedLogin, _loginConfiguration

// ServerAccountRegistrationRequest is conceptual method describing
that this request handler for any given route let say /accountRegister.
ServerAccountRegistrationRequest(request, reply) => {

 // variable assignment
 _loginConfiguration = {
  name: 'SomeFancyRegistration'
  whichDoc: 'Users',
  hooks: {
   '_onLoad': {
    'registration': await (Context) => {
       // [Context](http://currentrequest.com/docs#Context) api as lot other feature's
       // out of them one is Configuration it allow's you
       // to load data or execution update's..here we are
       // loading our payload passed in configuration.
       // using configuration you can get any key written
       // in configuration you are passing.
       let { _POST } = await Context.Configuration.get()


       ...after your code...

       // return data to queue.if you want
       // to pause queue so that it don't execute
       // further than return queue with CR_Paused
       // options set to true. also not that
       // every method should return _RAW_SCHEMA
       // as this acts as return schema for this
       // method which is used while writing output's
       // to database.
       if(...JustStopExecution...) {
        // return _POST.
        return {
            ..._POST,
            'options': {
                '_RAW_SCHEMA': Joi.object(),
                'CR_Paused': true
            }
        }
       } else {
        // return _POST.
        return {
            ..._POST,
            'options': {
                '_RAW_SCHEMA': Joi.object()
            }
        }
       }
    }
   }
  },
  'FileManager_Config': {
    'whereToStore': 'local', // change to S3 and update your AWS credential's in enviornment it will start putting all update's to s3 bucket.
    'path': './userAccountPhotoDirectory' // auto create directory and store any file uploaded to this route.
  },
  '_POST': __request.payload, // request payload..
  '_POST_SCHEMA': { // Joi schema for validating payload's..only allow those whose name is present in _POST_SCHEMA else are removed..
    'email': Joi.string().email(),
    'username': Joi.string(),
    'password': Joi.string(),
    'profilePicture': Joi.object()
  },
  'returnFormat': 'data', // return only method's output stored in _RAW key..if you wan't to return configuration which you are reciving inside hook's than
  just change 'data' => 'configuration'
  'task': 'CREATE' // this task define's which crud operation will going to happen.
 }

 // Before execution please update request with "y" header
 // you can do this on client side and then send request
 // or you can just create and manage key here by itself
 // just by passing "y": "unqieue string"
 if(...ClientSideHeaderCreated...) {
  // run as normal request.
   _ProceedLogin = await new CurrentRequest({ request, 'options': _loginConfiguration })
 } else {
  // create new "y" key.
  request.headers['y'] = 'somefancyYKey'

  // continue normal execution.
  _ProceedLogin = await new CurrentRequest({ request, 'options': _loginConfiguration })
 }

 // if _ProceedLogin contain's error than report failure.
 // else return Output.
 if(!_.propertyOf(_ProceedLogin)) {
  // local variable.
  let _replyOutput

  ...do something with output...
  _replyOutput = ...did something with _ProceedLogin.Output...

  // return data.
  return _replyOutput
 } else {
  // report failure.
  return _ProceedLogin.error
 }
}

Built With

Versioning

We use Semanticversioning for versioning. For the versions available, see the tags on this repository.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments