app-service

0.4.0 • Public • Published

app-service

Compose transforming, validation and actual service methods in a strict pipeline

Installation

npm install app-service

Usage

Define transform, validate function and actual method and wire up it through app-service

var build = require('app-service');
 
function transformCreateUser (params) {
    console.log('transform', params);
 
    params.email = params.email.toLowerCase();
    return params;
}
 
function validateCreateUser (params) {
    console.log('validate', params):
 
    if (params.email.length > 100) {
        throw new Error('Email is toooo long');
    }
}
 
function createUser (params) {
    console.log(params);
    return 'got it!';
}
 
var service = build({
    methods: { createUser: createUser },
    validation: { createUser: validateCreateUser },
    transforms: { createUser: transformCreateUser }
});
 
service.createUser({ email: 'Johny.Dust@example.com' }).then(function (result) {
    console.log(result);
});

outputs:

transform { email: 'Johny.Dust@example.com' }
validate { email: 'johny.dust@example.com' }
{ email: 'johny.dust@example.com' }
got it!

LICENSE

MIT

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.4.00latest

Version History

VersionDownloads (Last 7 Days)Published
0.4.00
0.3.00
0.2.30
0.2.20
0.2.10
0.2.00
0.1.00

Package Sidebar

Install

npm i app-service

Weekly Downloads

0

Version

0.4.0

License

MIT

Last publish

Collaborators

  • boo1ean