rimo
TypeScript icon, indicating that this package has built-in type declarations

1.2.6 • Public • Published
rimo banner
Build rich domain models with Rimo!
Rimo is a set of utilities that helps you to implement a clean architecture in TypeScript.


Created by Thiago Zanivan and maintained with ❤️ by an amazing community.

Usage

import { AggregageRoot } from 'rimo'
 
// Create an aggregate root
class User extends AggregateRoot<{ email: string }> {
  get email() {
    return this.props.email
  }
}
 
// Define inputs and/or outputs
class CreateUserInput {
  @IsNotEmpty()
  @IsEmail()
  email!: string
 
  static populate = (data: any) => {
    return Object.assign(new CreateUserInput(), data)
  }
}
 
// Create a use case
import { CommandHandler, Use } from 'rimo'
 
class CreateUserCommand implements CommandHandler<CreateUserInput, User> {
  @Use(ValidateCommand)
  async handle(input: CreateUserInput): Promise<User> {
    const user: User = new User(input)
    // persist user, do other stuff
    return user
  }
}
 
// Keep your use cases clean with the help of middlewares
// to do things like validation
import { Middleware } from 'rimo'
 
class ValidateCommand implements Middleware<CreateUserInput> {
  async use(event: CreateUserInput) {
    const errors = await validate(event)
    if (errors.length > 0) {
      throw new Error('validation error')
    }
  }
}
 
// Use the stupid simple, yet powerful, pub/sub mechanism that Rimo
// provides to keep your application components nicely decoupled!
import { AfterCommand, CommandRunner } from 'rimo'
 
class CreateUserSubscriber {
  @AfterCommand(CreateUserCommand)
  async afterCreateUser(user: User, runner: CommandRunner) {
    // SendWelcomeEmail is another use case
    await runner.run(SendWelcomeEmail, user)
  }
}

Credits

Thanks goes to these wonderful people (emoji key):


Thiago Zanivan

💻 🔧

This project follows the all-contributors specification. Contributions of any kind are welcome!

Package Sidebar

Install

npm i rimo

Weekly Downloads

10

Version

1.2.6

License

MIT

Unpacked Size

3.04 MB

Total Files

159

Last publish

Collaborators

  • thiagozf