Skip to content

Commit

Permalink
fix: minor typing fixes & lint
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagozf committed Apr 15, 2020
1 parent de0db84 commit a4cabb5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/core/Entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Object } from './Object'
import { EntityId } from './EntityId'
import { cloneDeep } from 'lodash'

const isEntity = (v: unknown): v is Entity<any> => {
return v instanceof Entity
Expand Down Expand Up @@ -38,7 +39,7 @@ export abstract class Entity<T> implements Object {

constructor(props: T, id: EntityId = new EntityId()) {
this._id = id
this.props = props
this.props = cloneDeep(props)
}

get id(): EntityId {
Expand Down
16 changes: 8 additions & 8 deletions src/repository/CrudRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ export interface CrudRepository<T extends Entity<any>, ID extends EntityId>
* @param id of the entity.
* @return the entity with the given ID or `undefined` if none found.
*/
findById: <E extends Error>(id: ID) => Promise<T | undefined>
findById: (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<boolean>
existsById: (id: ID) => Promise<boolean>

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

/**
* Returns all instances of the type `T` with the given IDs.
Expand All @@ -62,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<T[]>
findAllById: (ids: ID[]) => Promise<T[]>

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

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

/**
* Deletes a given entity.
*
* @param entity to delete.
*/
delete: <E extends Error>(entity: T) => Promise<void>
delete: (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<void>
deleteAll: (entities?: T[]) => Promise<void>
}
2 changes: 1 addition & 1 deletion test/command/CommandRunner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('CommandRunner test', () => {

it('should notify subscribers', async () => {
const input = CreateUserInput.populate({ email: 'hi+github@thiagozf.com' })
const output = await runner.run(CreateUserCommand, input)
await runner.run(CreateUserCommand, input)
expect(watchers.before).toStrictEqual([2, 1, 0])
expect(watchers.after).toHaveLength(1)
})
Expand Down

0 comments on commit a4cabb5

Please sign in to comment.