duckfficer-method-di

1.0.2 • Public • Published

duckfficer-method-di

Version

loads duckfficer-method entities from a path to provide a pleasure-di container

Installation

$ npm i duckfficer-method-di --save
# or
$ yarn add duckfficer-method-di

Features

builds an object appending all method found in given paths

const container = duckfficerMethodDi({
  Gateway: 'gateways',
  Service: 'services'
}, {
  baseDir: path.join(__dirname, './__tests__/fixtures')
})

const { OrderService } = container
t.deepEqual(await OrderService.payment({
  id: '123',
  amount: 99
}), {
  id: '123',
  result: 'paying 99$'
})

validates input

const container = duckfficerMethodDi({
  Gateway: 'gateways',
  Service: 'services'
}, {
  baseDir: path.join(__dirname, './__tests__/fixtures')
})

const { PayPalGateway } = container
const { originalError } = await t.throwsAsync(() => PayPalGateway.pay('100'), {
  message: 'Invalid input'
})
t.like(originalError, {
  message: 'Invalid number'
})

validates output

const container = duckfficerMethodDi({
  Gateway: 'gateways',
  Service: 'services'
}, {
  baseDir: path.join(__dirname, './__tests__/fixtures')
})

const { PayPalGateway } = container

const { originalError } = await t.throwsAsync(() => PayPalGateway.pay(0), {
  message: 'Invalid output'
})

t.like(originalError, {
  message: 'Invalid string'
})

emits events

const container = duckfficerMethodDi({
  Gateway: 'gateways',
  Service: 'services'
}, {
  baseDir: path.join(__dirname, './__tests__/fixtures')
})

const { PayPalGateway } = container

PayPalGateway.on('Paid', (payload) => {
  t.log(payload)
  t.pass()
})

return PayPalGateway.pay(100)


duckfficerMethodDi(pathResolvers, [baseDir], [methodsPath]) ⇒ Object

Param Type Default
pathResolvers Object
[baseDir] String process.cwd()
[methodsPath] String methods

Returns: Object - container


License

MIT

© 2020-present Martin Rafael Gonzalez tin@devtin.io

Package Sidebar

Install

npm i duckfficer-method-di

Weekly Downloads

3

Version

1.0.2

License

MIT

Unpacked Size

19.9 kB

Total Files

16

Last publish

Collaborators

  • tin_r