cqrs library

A library for convenient communication with CQRS-compatible backends, using queries and commands.

Example:

final apiUri = Uri.parse('https://flowers.garden/api/');

final cqrs = Cqrs(
  loginClient,
  apiUri,
);

// Fetching first page of flowers
final flowers = await cqrs.get(AllFlowers(page: 1));

// Handling query result
if (flowers case QuerySuccess(:final data)) {
  print(data);
} else if (flowers case QueryFailure(:final error)) {
  print('Something failed with error $error');
}

// Adding a new flower
final result = await cqrs.run(
  AddFlower(
    name: 'Daisy',
    pretty: true,
  ),
);

// Handling command result
if (result case CommandSuccess()) {
  print('Flower added succefully');
} else if (result case CommandFailure(isInvalid: true, :final validationErrors)) {
  print('Validation errors occured');
  handleValidationErrors(validationErrors);
} else if (result case CommandFailure(:final error)) {
  print('Something failed with error ${error}');
}

See also:

Classes

Command
Command carrying data related to performing a certain action on the backend.
CommandFailure
Class which represents a result of unsuccesful command execution.
CommandResult
Result class for CQRS command result. Can be either CommandSuccess or CommandFailure.
CommandSuccess
Class which represents a result of succesful command execution.
Cqrs
Class used for communicating with the backend via queries and commands.
CqrsMethod
An interface for contracts that can be serialized and sent to the backend.
CqrsMiddleware
Abstract class for CQRS result handlers. Can be used to specify certain behaviors that will be triggered for given errors i.e. showing snackbar on network error or logging out on authetication error etc.
Operation<T>
Operation describing a criteria for a query, a command, and the results it returns.
OperationFailure<T>
Generic class which represents a result of unsuccesful operation execution.
OperationResult<T>
Generic result for CQRS operation result. Can be either OperationSuccess or OperationFailure.
OperationSuccess<T>
Generic class which represents a result of succesful operation execution.
Query<T>
Query describing a criteria for a query and the results it returns.
QueryFailure<T>
Generic class which represents a result of unsuccesful query execution.
QueryResult<T>
Generic result for CQRS query result. Can be either QuerySuccess or QueryFailure.
QuerySuccess<T>
Generic class which represents a result of succesful query execution.
ValidationError
A validation error.

Enums

CommandError
Error types of command failure.
OperationError
Error types of operation failure.
QueryError
Error types of query failure.