horpax

0.8.0 • Public • Published

HORPAX

Build Status Downloads Downloads NPM version

Core concepts

Framework on top of express node.js. Designed for rapid application development. It allows easy create CRUDs (create, read, update and delete) for any custom resource. They can be created even in runtime. It is very flexible in changing default behavior of any operations, allowing customization or giving access to raw express.js requests and responses. It has lot of pre made useful features like authorization.

Horpax

Instance of this class starts new node server. This is root object of application composition. It manages Stores and Resources


deprecated

Attribute

It is single attribute of model. Each of those: name, surname, age, bornData are attributes.

Attribute options

  • modelName - map model db key to attribute
  • allowFilter - property can be a filter in request query
  • filterName - map query param to attribute
  • allowBody - property can be in request body
  • bodyName - name property in body

AttributeType

Each attribute has some type like string, number, object. In our example name and surname are string attributeType. But age is number attributeType and bornDate is date.

Schema

Collection of attributes is Schema.

Model

It is object allowing communication with database. It need schema.

Action

It is single endpoint. For example when we want save user we use action post endpoint.

Controller

It is consist with related actions. Like we have user controller.

Adapter

In model we have different values. We may want to save them to different databases or do something different. Each target for source should have onw adapter. Adapter is responsible for converting value to aimed target. For example we have age which has AttributeType number. But it is possible that target database doesn't have number type and we need DatabaseNumberAdapter which will convert number to string and string to number.

Get started

  1. Create instance then start it
    const horpax = new Horpax();
    await horpax.start();
  1. Implement functionality
  • You can add inline controllers, actions ...
    const idAttribute = new Attribute("_id", { });
    const nameAttribute = new Attribute("name", { });

    const schema = new Schema();
    schema.addAttribute(idAttribute);
    schema.addAttribute(nameAttribute);

    const model = new Model("resources", Model.getStoreManager().getDefaultStore());
    model.setSchema(schema);

    const createAction = new CreateAction("resourceCreateAction");
    createAction.setModel(model);

    const controller = new Controller("manageResources", "/resources");
    controller.addAction(createAction);
    horpax.getControllerManager().addController(controller);
  • Create different components and pass Horpax instance
   export default class Resources {
     constructor(horpax) {
       const idAttribute = new Attribute("_id", { });
       const nameAttribute = new Attribute("name", { });
   
       const schema = new Schema();
       schema.addAttribute(idAttribute);
       schema.addAttribute(nameAttribute);
   
       const model = new Model("resources", Model.getStoreManager().getDefaultStore());
       model.setSchema(schema);
   
       const createAction = new CreateAction("resourceCreateAction");
       createAction.setModel(model);
   
       const controller = new Controller("manageResources", "/resources");
       controller.addAction(createAction);
       horpax.getControllerManager().addController(controller);
     }
   }

## Debugger

Each element has debug module. For getting all debug info

DEBUG=horpax:* <command to run>

For specific debug, for example controller:

DEBUG=horpax:controller:* <command to run>

For specific controller

DEBUG=horpax:controller:<controller name> <command to run>

Package Sidebar

Install

npm i horpax

Weekly Downloads

0

Version

0.8.0

License

MIT

Unpacked Size

274 kB

Total Files

85

Last publish

Collaborators

  • krzysztofsztompka