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

hexin-core

v0.1.63

Published

Hexin Framework's core library

Downloads

73

Readme

HTTPeace Node Framework Core Library

A list of core libraries for the HTTPeace node framework

Table of contents

AppStart

AppStartBase

super(appConfig: Object) - pass appConfig into constructor getBaseConfig() - Function that returns base config set by AppStart setConfig(appConfig: Object) - Function that allows modification to appConfig before any handlers are called

setConfig(appConfig) {
    //    port
    appConfig.port = process.env.PORT || 8280;
    //    title of the app
    appConfig.title = 'Website API';
    //    base URL for all routes (ex. /api)
    appConfig.baseUrl = '/api';
}

setHandlers(appConfig: Object) - (Must Override) Function where all handles are declared

setHandlers(appConfig) {
    this.handle(new Auth(appConfig));
    this.handle(new Controllers(appConfig));
}

handle(handle: , addToBeginning: boolean = false) - declare a handle to call during build phrase

this.handle(new Controllers(appConfig));

AppStartConfig

AppStartConfig provides the basic lifecycle of the build phase in an app_start

preInit() - defines configurations before server starts. init() - defines configurations during server start. postInit() - defines configurations after server starts.

Controller

ControllerBase

This class provides methods to handle routes

constructor(app: Object) - app holds the router that represents api/. super(app[, controllerName[, service]])

  • app - app holds the router that represents api/.
  • controllerName - route url path api/{route}/.
  • service - service that manage majority of the data manipulation and persistence.

Scope-based variables and methods

this.a - Router that handles api/.

this.r - Router that handles api/{controllerName}/ (same as renderRoute's router argument).

this.controllerName - Variable that represents the controller name in the url path.

this.m - Service that was passed into the constructor.

renderRoute(router: Object): void - Developers will use this method to declare all their routes using the router object passed into the argument. all routes using router.{verb}({path}, ... will fall under api/{controllerName}/{path}

router.post('/', (req, res, next) {

authenticate - Middleware that checks if user is logged in

router.post('/', this.authenticate, (req, res, next)

authorize(...roles: Array<string>) - Middleware that checks if user consists any of the listed roles

router.post('/', this.authorize, (req, res, next) {
router.post('/', this.authorize(), (req, res, next) { (same as above)
router.post('/', this.authorize('user', 'admin'), (req, res, next) {

this.isVerb(verb: string, inVerbList: Array<string>|string): boolean - Function that returns true if first arg is in second argument. Useful for checking if req.method is equal to one of the verbs listed

this.isVerb(req.method, 'PUT|POST|DELETE')
this.isVerb(req.method, ['PUT', 'POST', 'DELETE'])

ControllerCrudBase

This class extends the ControllerBase and handles the basic CRUD methods based on the Service passed into the constructor

constructor(app: Object) - app holds the router that represents api/.

super(app[, controllerName[, service[, middlewares]]])

  • app - app holds the router that represents api/
  • controllerName - route url path api/{route}/
  • service - service that manage majority of the data manipulation and persistence
  • middlewares - list of middleware that governs all ControllerCrudBase calls
  constructor(app) {
    const baseMiddlewares = [
        (req, res, next) => {
            if (this.isVerb(req.method, 'PUT|POST|DELETE')) {
                this.authenticate(req, res, next);
            } else {
                next();
            }
        }
    ];
    super(app, 'auth', AuthService, baseMiddlewares);
  }

ControllerCrudBase automatically provides the following routes:

  • [GET] api/{route}/ - Get All
  • [GET] api/{route}/:_id - Get by _id
  • [POST] api/{route}/ - Create
  • [PUT] api/{route}/:_id - Update by _id
  • [DELETE] api/{route}/:_id - Delete by _id

Service

ServiceBase

This class provides the basic fields and method required for data manipulation, as well as the current scope of the request

Scope-based variables and methods

this.t(localeKey: string, args: Array<string>): string - Function for translating key into current locale

this.lang - Variable that displays current locale

this.context - The req from route(req, res, next)

this._model - The Model injected in the constructor

this.mapper - An object that handles DTO transformation

Data manipulation helpers

validate(obj: Object): void - Function that validates the object using indicative. Returns void but throws if invalid validation

sanitize(obj: Object): Object - Function that sanitize the object using indicative. Returns mutated obj

ServiceCrudBase

This class extends the ServiceBase and handles the basic CRUD methods based on the Model passed into the constructor

create(obj: Object): Object - Function that creates new data entry.

getAll(): Array<Object> - Function that returns all entries.

getById(_id): Object - Function that returns entry by _id

update(_id, obj): Object - Function that updates entry by _id

delete(_id): Object - Function that delete entry by _id

Mapper

Mapper handles the transition between client object to model object and vice versa. Since service is only responsible for handling model data, we use this function to handle the difference in model data and client-side data inside the controller layer. Mapper will be called on every controller method to mitigate the data being received and sent out.

Usage:

this.mapper.setMap(‘to’[, ‘from’])(function (obj) {
    // mutate here
    return obj;
});

this.mapper(‘to’[, ‘from’])(obj);

to is a name you give to what you want it to transform into (default to 'default'). from is optional, and would be safe to assume it is a model object unless to is 'model' (in which case from is 'default' client-side object)

Helpers

Plop

(Documentation coming soon)

Database

(Documentation coming soon)

BrainTree

(Documentation coming soon)

FiveBeans

(Documentation coming soon)

Error

(Documentation coming soon)

Locale

(Documentation coming soon)

Logger

(Documentation coming soon)

Redis

(Documentation coming soon)

Request

(Documentation coming soon)

Token

(Documentation coming soon)