Skip to main content

made_core/entities/ceremony_instance/decisions/
mod.rs

1//! Deciding: what a command would do to this session, as events.
2//!
3//! Every invariant, lease, idempotency, authorization and
4//! terminal-state rule the aggregate holds is checked here, against
5//! the definition and the current state, and nothing is written. A
6//! refused command returns the same error the mutator it replaces
7//! returned; an accepted one returns the events whose fold is exactly
8//! that mutator's effect. One file per command family.
9
10use crate::entities::{CeremonyCommand, CeremonyDefinition, CeremonyEvent, CeremonyInstance};
11use crate::error::DomainError;
12
13mod budget_admission;
14mod children;
15mod execution_receipts;
16mod guard_decisions;
17mod host_handoff;
18mod interventions;
19mod lease_renewal;
20mod lifecycle;
21mod participant_bindings;
22mod reasons;
23mod start;
24mod step_execution;
25mod succession;
26mod transitions;
27
28impl CeremonyInstance {
29    /// Decide a command against this session and its definition.
30    ///
31    /// Pure: reads the session, writes nothing, and returns the events
32    /// that would change it — usually one; two where one act has two
33    /// facts to record, as a transition into a terminal state also
34    /// completes the ceremony. Fold them with [`Self::apply`] to get
35    /// the state the corresponding mutator would have left.
36    pub fn decide(
37        &self,
38        command: &CeremonyCommand,
39        definition: &CeremonyDefinition,
40    ) -> Result<Vec<CeremonyEvent>, DomainError> {
41        match command {
42            CeremonyCommand::RecordHostHandoff(command) => {
43                self.decide_record_host_handoff(command, definition)
44            }
45            CeremonyCommand::BindParticipant(command) => {
46                self.decide_bind_participant(command, definition)
47            }
48            CeremonyCommand::StartStep(command) => self.decide_start_step(command, definition),
49            CeremonyCommand::RenewStepLease(command) => {
50                self.decide_renew_step_lease(command, definition)
51            }
52            CeremonyCommand::ApplyStepResult(command) => {
53                self.decide_apply_step_result(command, definition)
54            }
55            CeremonyCommand::ApplyExecutionReceiptResult(command) => {
56                self.decide_apply_execution_receipt_result(command, definition)
57            }
58            CeremonyCommand::ApplyTransition(command) => {
59                self.decide_apply_transition(command, definition)
60            }
61            CeremonyCommand::ApproveGuard(command) => {
62                self.decide_approve_guard(command, definition)
63            }
64            CeremonyCommand::DeferGuard(command) => self.decide_defer_guard(command, definition),
65            CeremonyCommand::RequestIntervention(command) => {
66                self.decide_request_intervention(command, definition)
67            }
68            CeremonyCommand::RespondToIntervention(command) => {
69                self.decide_respond_to_intervention(command, definition)
70            }
71            CeremonyCommand::RespondToInterventionWithEvidence(command) => {
72                self.decide_respond_to_intervention_with_evidence(command, definition)
73            }
74            CeremonyCommand::AcknowledgeInterventionDelivery(command) => {
75                self.decide_acknowledge_intervention_delivery(command, definition)
76            }
77            CeremonyCommand::AssertReason(command) => {
78                self.decide_assert_reason(command, definition)
79            }
80            CeremonyCommand::CloseIntervention(command) => {
81                self.decide_close_intervention(command, definition)
82            }
83            CeremonyCommand::PlanCeremonyChildren(command) => {
84                self.decide_plan_children(command, definition)
85            }
86            CeremonyCommand::PlanSuccessor(command) => {
87                self.decide_plan_successor(command, definition)
88            }
89            CeremonyCommand::AdoptChildSpawnPlan(command) => {
90                self.decide_adopt_child_plan(command, definition)
91            }
92            CeremonyCommand::AcceptChildCompletion(command) => {
93                self.decide_accept_child_completion(command, definition)
94            }
95            CeremonyCommand::PauseCeremony(command) => self.decide_pause(command, definition),
96            CeremonyCommand::ResumeCeremony(command) => self.decide_resume(command, definition),
97            CeremonyCommand::CancelCeremony(command) => self.decide_cancel(command, definition),
98            CeremonyCommand::EnforceCeremonyDeadlines(command) => {
99                self.decide_enforce_deadlines(command, definition)
100            }
101        }
102    }
103}