Options
All
  • Public
  • Public/Protected
  • All
Menu
rimo banner
Build rich domain models with Rimo!
Rimo is a set of utilities that helps you to implement a clean architecture in TypeScript.

NPM Package Install Size Dependency Status devDependency Status styled with prettier

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!

Index

Type aliases

Either

Either<L, R>: Left<L> | Right<R>

Represents a value of one of two possible types (a disjoint union).

An instance of Either is either an instance of Left or Right.

A common use of Either is as an alternative to Optional for dealing with possible missing values. In this usage, Optional.empty is replaced with a Left, which can contain useful information. Right takes the place of Optional.map. Convention dictates that Left is used for failure and Right is used for success.

For example, Either<Error, number> could be used to detect whether a received input has the expected number type. If it doesn't, an Error is returned.

import { Either, left, right } from 'rimo'

const parse = (input: string): Either<Error, number> => {
  const n = parseInt(input, 10)
  return isNaN(n) ? left(new Error('not a number')) : right(n)
}

Type parameters

  • L

  • R

Mapper

Mapper<S, T>: (source: S) => T

An interface for mappers functions that converts a source type S to target type T.

Type parameters

  • S

    the source type

  • T

    the target type

Type declaration

    • (source: S): T
    • Parameters

      • source: S

      Returns T

PrimitiveIdentifier

PrimitiveIdentifier: string | number

Variables

global

global: { __rimo_metadata_storage?: MetadataStorage }

Type declaration

Const storage

storage: MetadataStorage = MetadataStorage.getInstance()

Functions

Const AfterCommand

Const BeforeCommand

Const Use

Const addSubscriber

Const isEntity

  • isEntity(v: unknown): v is Entity<any>

Const isLeft

  • isLeft<L, R>(ma: Either<L, R>): ma is Left<L>

Const isRight

  • isRight<L, R>(ma: Either<L, R>): ma is Right<R>

Const left

  • left<L, R>(left: L): Either<L, R>
  • Constructs a new Either holding a Left value. This usually represents a failure.

    Type parameters

    • L

    • R

    Parameters

    • left: L

    Returns Either<L, R>

Const right

  • right<L, R>(right: R): Either<L, R>
  • Constructs a new Either holding a Right value. This usually represents a successful value.

    Type parameters

    • L

    • R

    Parameters

    • right: R

    Returns Either<L, R>

Const sortByPriority

  • sortByPriority(arr: { priority: number }[]): void

Legend

  • Constructor
  • Property
  • Method
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Property
  • Method
  • Protected property
  • Private property
  • Static method

Generated using TypeDoc