1.1.7 โ€ข Published 10 months ago

eensy v1.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

A ligthweight, opinionated, and easy to use typescript library for microservice backend applications based on express.

class UserController extends Controller {
  async index(req: Request) {
    await IndexValidator(req)
    const all = await userRepository.all()

    return { data: collection(UserTransform, all) }
  }

  async show(req: Request) {
    const validated = await ReferenceValidator(req)
    const user = await userRepository.show(validated.id)
    if (!user) throw ResourceNotFoundError()

    return { data: UserTransform(user) }
  }

  async store(req: Request) {
    const validated = await StoreValidator(req)
    const user = await userRepository.create(validated as User)
    return { status: 201, data: UserTransform(user) }
  }

  async update(req: Request) {
    const validated = await UpdateValidator(req)
    await ExistsValidator(req)

    const user = await userRepository.update(validated.id, validated.fields)
    return { status: 202, data: UserTransform(user) }
  }

  async destroy(req: Request) {
    const validated = await ReferenceValidator(req)
    await ExistsValidator(req)

    await userRepository.delete(validated.id)
    return { status: 202 }
  }
}

Install and use

This library comes with a built-in cli to help you get started.

npm i -g eensy
eensy.cli init

The CLI will promt some questions to generate the base project for you. Once the CLI command has finished, execute the following to start your project:

cd PROJECT_NAME
npm start

More information and guides are included on the generated project's README.md file.

Features

  • โš™๏ธ Built-in CLI: Uses templates and schematics to greatly speed up development.
  • ๐Ÿš€ Minimal setup: Requires minimal configuration to start developing features.
  • ๐ŸŽฏ Prisma integration: Built-in integration with Prisma for efficient database development.
  • ๐Ÿข Stable project structure: Provides a well-defined and stable structure for your project.
  • ๐Ÿ”Œ Microservice oriented: Encourages the development of microservice oriented applications, providing a simple and easy to use API for inter-service communication via HTTP and queues.
  • ๐Ÿ”’ JWT authentication: Built-in support for JWT authentication.
  • โœ… Validator pattern: Out-of-the-box usage of the validator pattern.
  • โžก๏ธ Functional syntax: Functional syntax for declaring routes and middlewar chains.
  • ๐Ÿงน Clean and simple syntax: Offers a clean and simple syntax for easy development.
  • โฐ Job scheduler: Built-in job scheduler for task management.
  • ๐Ÿฎ Bull queue integration: Integration with Bull queue for background jobs and distributed processing.
  • ๐Ÿ“ก Socket.io integration: High-level API for broadcasting with Socket.io, including built-in support for broadcast channels and personal channels.
  • ๐Ÿ’พ Repository pattern: Adoption of the repository pattern for efficient database access.
  • ๐Ÿ” Distributed transactions: Built-in support for 2PC (two-phase commit) distributed transactions with utilities for quickly implementing atomic operations.

CLI usage

You can ask for help with:

eensy.cli -h

The CLI currently has 3 generation features: project generation (aka. Init), service generation and resource generation (aka. RESTful entity generation).

Project generation

This command inits a project. Some promts will be shown so that the CLI knows how to generate the best base project.

eensy.cli init

Service generation

This command generates a service inside a project. It will generate all the folder and file structure that you need to start using a new service in your project.

eensy.cli generate:service

Resource generation

This command generates a RESTful resource inside a project. You can select the service that will serve the new resource. You can also choose which parts of the resource files you want to generate, by default the controller, the model, the repository, the REST validators, the routes file, the transform and the testing specs are generated.

eensy.cli generate:resource

About schematics

The built-in CLI of this project uses Angular schematics as the core of file system manipulation. Please show support to the awesome Angular.io community for making such reliable scaffolding library.

Author

๐Ÿ‘ค Joao Pinto @ neuralgeeks

Show your support

Give a โญ๏ธ if this project helped you!

๐Ÿค Contributing

Since eensy is a small library, we are not accepting any contributions at the moment. However, you can still contribute by reporting bugs, suggesting features, and sharing your ideas. Issues and pull requests are welcome!

๐Ÿ“ License

Copyright ยฉ 2020 neuralgeeks. This project is MIT licensed.