Skip to content

Commit

Permalink
fix: remove monads from other type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagozf committed Apr 14, 2020
1 parent 268b34f commit 13acb24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
4 changes: 1 addition & 3 deletions src/mapper/Mapper.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Either } from '@rimo/monad'

/**
* An interface for mappers functions that converts a source type `S` to target type `T`.
*
* @typeParam S the source type
* @typeParam T the target type
*/
export type Mapper<S, T> = <E extends Error>(source: S) => Either<E, T>
export type Mapper<S, T> = (source: S) => T
21 changes: 10 additions & 11 deletions src/repository/CrudRepository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Entity, EntityId } from '@rimo/core'
import { Either } from '@rimo/monad'
import { Repository } from './Repository'

/**
Expand All @@ -20,38 +19,38 @@ export interface CrudRepository<T extends Entity<any>, ID extends EntityId>
* @param entity to save.
* @return the saved entity.
*/
save: <E extends Error, S extends T>(entity: S) => Promise<Either<E, S>>
save: <S extends T>(entity: S) => Promise<S>

/**
* Saves all given entities.
*
* @param entities to save.
* @return the saved entities.
*/
saveAll: <E extends Error, S extends T>(entities: S[]) => Promise<Either<E, S[]>>
saveAll: <S extends T>(entities: S[]) => Promise<S[]>

/**
* Retrieves an entity by its ID.
*
* @param id of the entity.
* @return the entity with the given ID or `undefined` if none found.
*/
findById: <E extends Error>(id: ID) => Promise<Either<E, T | undefined>>
findById: <E extends Error>(id: ID) => Promise<T | undefined>

/**
* Returns whether an entity with the given ID exists.
*
* @param id of the entity.
* @return `true` if an entity with the given id exists, `false` otherwise.
*/
existsById: <E extends Error>(id: ID) => Promise<Either<E, boolean>>
existsById: <E extends Error>(id: ID) => Promise<boolean>

/**
* Returns all instances of the type.
*
* @return all entities
*/
findAll: <E extends Error>() => Promise<Either<E, T[]>>
findAll: <E extends Error>() => Promise<T[]>

/**
* Returns all instances of the type `T` with the given IDs.
Expand All @@ -63,33 +62,33 @@ export interface CrudRepository<T extends Entity<any>, ID extends EntityId>
* @param ids of entities to be retuned.
* @return the entities.
*/
findAllById: <E extends Error>(ids: ID[]) => Promise<Either<E, T[]>>
findAllById: <E extends Error>(ids: ID[]) => Promise<T[]>

/**
* Returns the number of entities.
*
* @return the number of entities.
*/
count: <E extends Error>() => Promise<Either<E, number>>
count: <E extends Error>() => Promise<number>

/**
* Deletes the entity with the given id.
*
* @param id of entity to delete.
*/
deleteById: <E extends Error>(id: ID) => Promise<Either<E, void>>
deleteById: <E extends Error>(id: ID) => Promise<void>

/**
* Deletes a given entity.
*
* @param entity to delete.
*/
delete: <E extends Error>(entity: T) => Promise<Either<E, void>>
delete: <E extends Error>(entity: T) => Promise<void>

/**
* Deletes the given entities, or all when no arguments are provided.
*
* @param entities to delete or `undefined` to delete all.
*/
deleteAll: <E extends Error>(entities?: T[]) => Promise<Either<E, void>>
deleteAll: <E extends Error>(entities?: T[]) => Promise<void>
}

0 comments on commit 13acb24

Please sign in to comment.