1.0.21 • Published 2 years ago
ts-clean-architecture v1.0.21
Typescript - Clean architecture
This is a light and simple type abstraction for clean architecture, domain driven design (DDD), command and query responsibility segregation (CQRS) and event sourcing.
Dir
Installation
Use the npm to install it.
npm install ts-clean-architecture
Or yarn.
yarn add ts-clean-architecture
Usage (How to make..)
A value object (UuID is a implementation of ValueObject and it is in the package):
class UserId extends UuID {
readonly _tag: string = "UserId";
}
An aggregate:
class User implements Aggregate<UserId> {
readonly _tag: string = "User";
constructor(
public readonly userId: UserId,
public readonly userName: string,
public readonly email: string
) {}
id() {
return this.userId;
}
}
A repository:
interface UserRepository extends Repository<User> {
findAllByEmail(email: string): Promise<User[]>;
}
A service:
// Create output object
class NewUserName extends StringValueObject {
readonly _tag: string = "NewUserName";
}
// create service
class GenerateUserNameService implements Service<void, Promise<NewUserName>> {
readonly _tag: string = "GenerateUserNameService";
execute(input: void): Promise<NewUserName> {
return Promise.resolve(new NewUserName("jdgonzalez907"));
}
}
A query responsability:
// Input
class GetUserNamesByEmailQueryInput implements QueryInput {
readonly _tag: string = "GetUserNamesByEmail";
constructor(public readonly email: string) {}
}
// Output
class GetUserNamesByEmailQueryOutput implements QueryOutput {
readonly _tag: string = "GetUserNamesByEmailQueryOutput";
constructor(public readonly names: string[]) {}
}
// Handler
class GetUserNamesByEmailQueryHandler
implements
QueryHandler<
GetUserNamesByEmailQueryInput,
Promise<GetUserNamesByEmailQueryOutput>
>
{
readonly _tag: string = "GetUserNamesByEmailQueryHandler";
constructor(private readonly userRepository: UserRepository) {}
execute(
input: GetUserNamesByEmailQueryInput
): Promise<GetUserNamesByEmailQueryOutput> {
return this.userRepository.findAllByEmail(input.email).then((users) => {
return new GetUserNamesByEmailQueryOutput(
users.map((user) => user.userName)
);
});
}
}
Contributing
Welcome fully.
License
1.0.21
2 years ago
1.0.20
2 years ago
1.0.19
2 years ago
1.0.18
2 years ago
1.0.17
2 years ago
1.0.16
2 years ago
1.0.15
2 years ago
1.0.14
2 years ago
1.0.13
2 years ago
1.0.12
2 years ago
1.0.11
2 years ago
1.0.10
2 years ago
1.0.9
2 years ago
1.0.8
2 years ago
1.0.7
2 years ago
1.0.6
2 years ago
1.0.5
2 years ago
1.0.4
2 years ago
1.0.3
2 years ago
1.0.2
2 years ago
1.0.1
2 years ago
1.0.0
2 years ago
0.1.9
2 years ago
0.1.8
2 years ago
0.1.7
2 years ago
0.1.6
2 years ago
0.1.5
2 years ago
0.1.4
2 years ago
0.1.3
2 years ago
0.1.2
2 years ago
0.1.1
2 years ago
0.1.0
2 years ago
0.0.1
2 years ago