docs(arch): add documentation

This commit is contained in:
2023-04-13 23:29:27 +02:00
parent 7a3de79e36
commit e5e0550017
19 changed files with 90 additions and 30 deletions
@@ -16,8 +16,13 @@
import 'package:wyatt_type_utils/wyatt_type_utils.dart';
/// {@template app_exception}
/// [AppException] is a base class for all exceptions in the wyatt architecture.
/// {@endtemplate}
abstract class AppException implements Exception {
AppException([this.message]);
/// {@macro app_exception}
const AppException([this.message]);
final String? message;
@override
@@ -30,10 +35,20 @@ abstract class AppException implements Exception {
}
}
/// {@template client_exception}
/// [ClientException] is a base class for all client exceptions in the wyatt
/// architecture.
/// {@endtemplate}
class ClientException extends AppException {
ClientException([super.message]);
/// {@macro client_exception}
const ClientException([super.message]);
}
/// {@template server_exception}
/// [ServerException] is a base class for all server exceptions in the wyatt
/// architecture.
/// {@endtemplate}
class ServerException extends AppException {
ServerException([super.message]);
/// {@macro server_exception}
const ServerException([super.message]);
}
@@ -14,6 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
/// {@template base_data_source}
/// [BaseDataSource] is a base class for all data sources in the wyatt
/// architecture.
/// {@endtemplate}
abstract class BaseDataSource {
/// {@macro base_data_source}
const BaseDataSource();
}
@@ -16,6 +16,11 @@
import 'package:wyatt_architecture/src/domain/data_sources/base_data_source.dart';
/// {@template base_local_data_source}
/// [BaseLocalDataSource] is a base class for all local data sources in the
/// wyatt architecture.
/// {@endtemplate}
abstract class BaseLocalDataSource extends BaseDataSource {
/// {@macro base_local_data_source}
const BaseLocalDataSource();
}
@@ -16,6 +16,11 @@
import 'package:wyatt_architecture/src/domain/data_sources/base_data_source.dart';
/// {@template base_remote_data_source}
/// [BaseRemoteDataSource] is a base class for all remote data sources in the
/// wyatt architecture.
/// {@endtemplate}
abstract class BaseRemoteDataSource extends BaseDataSource {
/// {@macro base_remote_data_source}
const BaseRemoteDataSource();
}
@@ -14,6 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
/// {@template entity}
/// [Entity] is a base class for all entities in the domain layer.
/// {@endtemplate}
abstract class Entity {
/// {@macro entity}
const Entity();
}
@@ -14,6 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
/// {@template base_repository}
/// [BaseRepository] is a base class for all repositories in the domain layer.
/// {@endtemplate}
abstract class BaseRepository {
/// {@macro base_repository}
const BaseRepository();
}
@@ -16,6 +16,11 @@
import 'package:wyatt_architecture/src/domain/entities/entity.dart';
/// {@template no_param}
/// [NoParam] is a class that is used when a use case does not require any
/// parameters.
/// {@endtemplate}
class NoParam extends Entity {
/// {@macro no_param}
const NoParam();
}
@@ -21,16 +21,17 @@ import 'package:wyatt_architecture/wyatt_architecture.dart';
/// Usecase observers
mixin Observer<Parameters, ReturnType> {
/// Called before usecase is runned.
/// Usefull to check the preconditions
/// Useful to check the preconditions
FutureOr<void> onStart(Parameters? params) {}
/// Called when error occures during main scenario
/// Usefull to run alternative scenario
/// Useful to run alternative scenario
FutureOr<void> onError(AppException? error) {}
}
/// Specific observer for classic usecase
mixin AsyncObserver<ReturnType> {
/// Called when usecase is completed
FutureOr<void> onComplete(ReturnType? data) {}
}
@@ -39,6 +40,6 @@ mixin StreamObserver<ReturnType> {
/// Replaces the data event handler of this subscription.
void onDone() {}
/// Replaces the done event handler of this subscription.
/// Replaces the done event handler of this subscription.
void onData(ReturnType? data) {}
}
@@ -23,8 +23,13 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart';
typedef FutureOrResult<T> = FutureOr<Result<T, AppException>>;
typedef StreamResult<T> = Stream<Result<T, AppException>>;
/// Abstract class of a use case
/// {@template base_usecase}
/// Abstract class of any use case.
/// {@endtemplate}
abstract class BaseUseCase<Parameters, ReturnType> {
/// {@macro base_usecase}
const BaseUseCase();
/// Run use case scenarios
ReturnType call(Parameters parameters);
@@ -33,11 +38,16 @@ abstract class BaseUseCase<Parameters, ReturnType> {
ReturnType execute(Parameters params);
}
/// {@template usecase}
/// Abstract class of a use case that deals specifically
/// with the response and its state.
/// {@endtemplate}
abstract class UseCase<Parameters, ReturnType>
extends BaseUseCase<Parameters?, FutureOrResult<ReturnType>>
with Observer<Parameters, ReturnType> {
/// {@macro usecase}
const UseCase();
FutureOr<void> _onSuccess(ReturnType data);
/// Supports the result of the main scenario and integrates
@@ -59,17 +69,27 @@ abstract class UseCase<Parameters, ReturnType>
}
}
/// Abtstract classic usecase.
/// {@template async_usecase}
/// Abtstract classic usecase bases on futures
/// {@endtemplate}
abstract class AsyncUseCase<Parameters, ReturnType>
extends UseCase<Parameters?, ReturnType> with AsyncObserver<ReturnType> {
/// {@macro async_usecase}
const AsyncUseCase();
@override
FutureOr<void> _onSuccess(ReturnType data) => onComplete(data);
}
/// {@template stream_usecase}
/// Abstract specific usecase bases on streams
/// {@endtemplate}
abstract class StreamUseCase<Parameters, ReturnType>
extends UseCase<Parameters?, Stream<ReturnType>>
with StreamObserver<ReturnType> {
/// {@macro stream_usecase}
const StreamUseCase();
@override
FutureOr<void> _onSuccess(Stream<ReturnType> data) {
data.listen(
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
/// Architecture
/// Wyatt Architecture for Flutter
library wyatt_architecture;
export 'src/src.dart';