@minimonolith/lib
v0.14.10
Published
[![codecov](https://codecov.io/gh/DeepHackDev/minimonolith-lib/branch/master/graph/badge.svg?token=AH4L7MY7DA)](https://codecov.io/gh/DeepHackDev/minimonolith-lib)
Downloads
59
Readme
@minimonolith/lib
@minimonolith/lib
is a library engine for achieving modularity and validation
Example Project
Here's an example library using @minimonolith/lib
:
.
├── package.json
├── .gitignore
├── index.js // Root of library
└── todo
├── services.js // Module 'todo' exported service handlers are declared here
└── get
├── handler.js // Module 'todo' service 'get' handler
├── in.js // Optional: Service 'get' handler in validation, if body not empty
└── out.js // Optional: Service 'get' handler out validation, if return not empty
index.js
This file exports the developed services of the library:
// index.js
'use strict';
import { getNewLib } from '@minimonolith/lib';
const LIB = await getNewLib();
await LIB.postModule('todo');
export default { ...LIB.SERVICES };
todo/index.js
Here, we declare the service handlers for the todo
module:
// todo/services.js
export default ['get', 'getOne', 'post', 'patch', 'delete'];
todo/getOne/handler.js
This file contains the get
service handler for the todo
module. It retrieves a todo item by its ID:
// todo/get/index.js
export default async ({ body }) => {
return { id: body.id, name: 'todo' };
}
todo/getOne/in.js
// todo/get/in.js
import { z } from '@minimonolith/lib';
export default () => ({
id: z.number()
});
todo/getOne/out.js
// todo/get/in.js
import { z } from '@minimonolith/lib';
export default () => ({
id: z.number(),
name: z.string(),
});