https://github.com/devtin/duck-storage-di
loads duck-storage entities from a path to provide a pleasure-di container
https://github.com/devtin/duck-storage-di
Last synced: about 1 year ago
JSON representation
loads duck-storage entities from a path to provide a pleasure-di container
- Host: GitHub
- URL: https://github.com/devtin/duck-storage-di
- Owner: devtin
- Created: 2021-02-09T18:36:46.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-02-20T14:29:58.000Z (about 5 years ago)
- Last Synced: 2024-08-09T17:34:35.315Z (over 1 year ago)
- Language: JavaScript
- Size: 190 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
duck-storage-di
loads duck-storage entities from a path to provide a pleasure-di container
## Installation
```sh
$ npm i duck-storage-di --save
# or
$ yarn add duck-storage-di
```
## Features
- [Loads entities from directory](#loads-entities-from-directory)
- [Loads methods](#loads-methods)
## Loads entities from directory
```js
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
```js
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
| Param | Type | Default |
| --- | --- | --- |
| directory | String | |
| [baseDir] | String | process.cwd() |
| [modelPath] | String | model |
| [methodsPath] | String | methods |
| [suffix] | String | Rack |
| [storageOptions] | Object | |
**Returns**: Object - container and storage
* * *
### License
[MIT](https://opensource.org/licenses/MIT)
© 2020-present Martin Rafael Gonzalez