1.0.0 • Published 5 years ago

controller-handler v1.0.0

Weekly downloads
8
License
MIT
Repository
github
Last release
5 years ago

Controller Handler

npm Downloads Build Status Package Quality License

Controller handler for message queues.

Installation

npm install controller-handler --save

Examples

Basic Usage

The example below will require a file called hello.js and will invoke the world method into this file, passing to the the object the parameters {name: 'john'} and a callback.

'use strict';

const Controller = require('controller-handler'),
      controller = new Controller(__dirname + '/src/commands');

const message = {
    command: 'hello',
    action : 'world',
    params : {name: 'john'},
};

controller.handle(message, function(error, data)
{
    console.log(error); // In case of error
    console.log(data);  // In case of success
});

Message Validation

'use strict';

const Controller = require('controller-handler'),
      controller = new Controller(__dirname + '/src/commands');

const message = {
    command: 'hello',
    action : 'world',
    params : {name: 'john'},
};

const validation = controller.validate(message);

The validation object returned by validate() will looks like this:

{
    command: true, // "command" param is provided and file "./src/commands/hello.js" exists
    action : true, // "action" param is provided and method "world" exists
    params : true, // "params" param is provided and it is a valid object
}

Simple Message Validation

'use strict';

const Controller = require('controller-handler'),
      controller = new Controller(__dirname + '/src/commands');

const message = {
    command: 'hello',
    action : 'world',
    params : {name: 'john'},
};

const valid = controller.isValid(message); // TRUE

Test and development

  • Install external dependencies: npm install
  • Run the test suite without coverage: npm test
  • Run the test suite with coverage: npm run testdox

How to Contribute

  • Open a pull request or an issue about what you want to implement / change. We're glad for any help!
  • Please be aware that we'll only accept fully tested code.

Contributors

LICENSE

Copyright (c) 2019 Leonardo Thibes

The MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

1.0.0

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago