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 node has a name: the tree rejects a creation or an update that leaves one blank, whether or not the host validates commands. 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 node must have a name, the parent must exist and the node must not be deeper than maxLevel.