Tree
A reusable aggregate of one tree, such as a tenant's categories or departments: subclass it with the concrete commands, annotate the subclass @AggregateRoot, and the compiler binds the command functions declared here, with the type arguments the subclass gives (its state T, and its commands C, U, D and M):
@AggregateRoot
class Category(state: CategoryState) :
Tree<CategoryState, CreateCategory, UpdateCategory, DeleteCategory, MoveCategory>(state) {
override fun maxLevel(): Int = 3
}A command that breaks a rule of the tree is rejected with a TreeRejections code, its message from the overridable ...ErrorMessage functions. The verify... hooks run after the tree's own rules and may reject too, after I/O if they need it (they suspend). Creating a node answers the caller with the node's code under the result key code (DecideScope.putResult).
Functions
Creates a node under its parent, after its siblings, with a generated code (generateCode); the parent must exist and the node must not be deeper than maxLevel.