1.0.5 • Published 3 years ago

duck-storage-di v1.0.5

Weekly downloads
63
License
MIT
Repository
github
Last release
3 years ago

Installation

$ npm i duck-storage-di --save
# or
$ yarn add duck-storage-di

Features

Loads entities from directory

const { CustomerRack } = container
const customerData = {
  firstName: 'Martin',
  lastName: 'Gonzalez',
  email: 'tin@devtin.io',
  phoneNumber: 3051234567
}
const customer = await CustomerRack.create(customerData)
t.like(customer, customerData)
t.truthy(customer._id)
t.truthy(customer._v)

Loads methods

const { CustomerRack } = container

const doc = await CustomerRack.create({
  firstName: 'Martin',
  lastName: 'Gonzalez',
  email: 'tin@devtin.io',
  phoneNumber: 3051234567
})

let eventReceived

CustomerRack.on('method', (payload) => {
  eventReceived = payload
})

const newDoc = await CustomerRack.apply({ id: doc._id, _v: doc._v, method: 'addLog', payload: 'message' })
t.truthy(newDoc)
t.truthy(newDoc.entryResult)
t.truthy(newDoc.eventsDispatched)
t.like(eventReceived, newDoc.eventsDispatched[0])

duckStorageDi(directory, baseDir, modelPath, methodsPath, suffix, storageOptions) ⇒ Object

ParamTypeDefault
directoryString
baseDirStringprocess.cwd()
modelPathStringmodel
methodsPathStringmethods
suffixStringRack
storageOptionsObject

Returns: Object - container and storage


License

MIT

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