1.1.0 • Published 7 years ago

nats-method-ex-utils v1.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Nats Method Ex Utils

Utils for nats-method-ex.

About Dependencies

  • the only explicit dependency is nats-method-ex.
  • if any util needs dependencies, it will receive them from builder args.

Usage

Install

npm install --save nats-method-ex nats-method-ex-utils

Import

const {xxx} = require('nats-method-ex-utils')

Utils

joiInputValidator

const joi = require('joi')
const {
  joiInputValidator: validateInput
} = require('nats-method-ex-utils')

methodEx.define('some.method', validateInput(
  joi.object({
    name: joi.string().required(),
    age: joi.number()
  }).required()
)(
  async (user) => {
    ...
  }
))

extractData

Extract data from response. If response.ok is false, error will be thrown.

const {extractData} = require('nats-method-ex-utils')

const response = await methodEx.call('xxx')
const data = extractData(response)

License

MIT