0.7.0 • Published 6 years ago
backend-store v0.7.0
backend-store
Backend store manages business logic functions in Node.js backend application.
- It allows to define functions and to call them each other through the store
- It allows to use custom middleware executed before/after each function call
- It has built-in set of business logic error classes
- It has built-in few simple yet powerful plugins
What it's trying to solve:
- Simplifies code organisation
- Simplifies code testing
- Simplifies error handling
- Simplifies logging and error tracking
Install
$ yarn add backend-store
Usage
import { Store } from 'backend-store'
import logger from 'backend-store/plugins/logger'
// create store
const store = new Store()
// use logger plugin (see console output what it can do)
store.plugin(logger)
// define method that calls other method
store.define('api/users/create', async (payload = {}, { context, errors, dispatch }) {
if (!context || !context.user || context.user.role !== 'admin') {
throw new errors.AuthorizationError('Only admin can create posts')
}
const post = await dispatch('database/users/insert', {
title: payload.title,
userId: context.user.id
})
return post
})
// define another method
store.define('database/users/insert', async ({ title, userId }) {
return {
id: 1,
title,
userId
}
})
// call (dispatch) method in store; pass payload and context
store.dispatch('api/users/create', { title: 'hello!' }, {
user: { role: 'admin' }
}).then(post => {
console.log(post)
})
More examples in docs
Docs
https://alekbarszczewski.github.io/backend-store.
TODO
- ow - label arguments (waiting for ow package to be updated)
- test plugin
0.7.0
6 years ago
0.6.0
6 years ago
0.5.0
6 years ago
0.4.0
6 years ago
0.3.0
6 years ago
0.2.7
6 years ago
0.2.6
6 years ago
0.2.4
6 years ago
0.2.3
6 years ago
0.2.2
6 years ago
0.2.1
6 years ago
0.2.0
6 years ago
0.1.0
6 years ago
0.0.9
6 years ago
0.0.8
6 years ago
0.0.7
6 years ago
0.0.6
6 years ago
0.0.5
6 years ago
0.0.4
6 years ago
0.0.3
6 years ago
0.0.2
6 years ago
0.0.1
6 years ago