PuduLangMediator.md
PuduLangMediator
type: module path: "@root/src/PuduLangMediator.pudu" fidelity: Active grammar: "[[grammar/pudu]]" depth_score: 0.8 depth_status: DEEP tags: [module, backbone] aliases: [PuduLangMediator]
Purpose
The package root and its vocabulary: the Failure a mediated message answers instead of a value, the Outcome every handler, behavior, and processor answers, the Violation a validation failure lists, and the helpers that build, combine, inspect, and describe them.
Interface
Signatures
export type Violation = { property: Str, message: Str, code: Str }
export type Failure[E]
= Raised(E)
| Unhandled(Str)
| Mismatched(Str)
| Refused(Str)
| Invalid(Array[Violation])
| Cancelled(Str)
| Crashed(Str)
| Aggregate(Array[Failure[E]])
export type Outcome[T, E] = Result[T, Failure[E]]
export fn succeed[T, E](value: T) -> Outcome[T, E]
export fn raise[T, E](problem: E) -> Outcome[T, E]
export fn refuse[T, E](reason: Str) -> Outcome[T, E]
export fn lift[T, E](result: Result[T, E]) -> Outcome[T, E]
export fn raised[E](failure: &Failure[E]) -> Option[E]
export fn isCancellation[E](failure: &Failure[E]) -> Bool
export fn violations[E](failure: &Failure[E]) -> Array[Violation]
export fn combine[E](failures: Array[Failure[E]]) -> Option[Failure[E]]
export fn describe[E](failure: &Failure[E]) -> Str
export fn summarize[T, E](outcome: &Outcome[T, E]) -> StrLinkage
- Requires: [[src/PuduLangMediator/Constants/Messages]], [[src/PuduLangMediator/Utils/Template]].
- Consumed by: [[src/PuduLangMediator/Behaviors/Logging]], [[src/PuduLangMediator/Behaviors/Resilient]], [[src/PuduLangMediator/Behaviors/Validation]], [[src/PuduLangMediator/Compose]], [[src/PuduLangMediator/Context]], [[src/PuduLangMediator/Mediator]], [[src/PuduLangMediator/Message]], [[src/PuduLangMediator/Notification]], [[src/PuduLangMediator/Open]], [[src/PuduLangMediator/Publisher]], [[src/PuduLangMediator/Publishing]], [[src/PuduLangMediator/Reader]], [[src/PuduLangMediator/Request]], [[src/PuduLangMediator/Sender]], [[src/PuduLangMediator/Stream]].
Algorithm
liftmaps a plainResultonto an outcome:Okstays,Err(e)becomesRaised(e).refuseis how an open component fails: it cannot name the kind'sE, so it answersRefusedwith a reason.combineflattens nestedAggregates: no failure isNone, one is itself, several are one flatAggregatein order.violationsreads the violations of anInvalid, including everyInvalidinside anAggregate.describefills one sentence per variant from [[src/PuduLangMediator/Constants/Messages]];summarizerenders a value asOk(<value>)and a failure as its description.
Negative Logic (Prohibited Paths)
- No wording is written inline; every sentence comes from the message constants.
combinenever nests anAggregateinside another, so a caller matches one level.
Edge Cases
- An
Aggregateof one is never built:combineanswers that one failure. Raisedshows its error withshow, so text errors appear quoted.
Depth
DEPTH 0.8 (DEEP). Tested by the suite mirroring this module under test/.
Grill Log
- Q: Why one generic
Failure[E]instead of the handler's own error type? A: Behaviors, processors, and the mediator itself must add their own failures (no handler, a refusal, an invalid message, a cancellation, a crash) without knowingE; one sum carries both and stays exhaustively matchable. _Rejected:_ a trait object of errors (loses exhaustive matching); one error type per layer (callers would unwrap one per layer). - Q: Why
RefusedandInvalidas separate variants? A:Invalidcarries structured violations a caller renders per field;Refusedis the one failure an open component can build for anyE. Folding either into the other loses the structure or the generality. _Rejected:_ a text-onlyInvalid(callers would parse messages back into fields). - Q: Why
Aggregate? A: Parallel, bounded, and continuing publication run every handler and must report every failure, not the first. _Rejected:_ answering only the first failure (hides the rest of a failed publication).
Referenced by
[[CHANGELOG]] · [[decisions/ADR-0001-outcomes-not-exceptions]] · [[domain/Outcome]] · [[src/PuduLangMediator/Behaviors/Logging]] · [[src/PuduLangMediator/Behaviors/Resilient]] · [[src/PuduLangMediator/Behaviors/Validation]] · [[src/PuduLangMediator/Compose]] · [[src/PuduLangMediator/Constants/Messages]] · [[src/PuduLangMediator/Context]] · [[src/PuduLangMediator/Mediator]] · [[src/PuduLangMediator/Message]] · [[src/PuduLangMediator/Notification]] · [[src/PuduLangMediator/Open]] · [[src/PuduLangMediator/Publisher]] · [[src/PuduLangMediator/Publishing]] · [[src/PuduLangMediator/Reader]] · [[src/PuduLangMediator/Request]] · [[src/PuduLangMediator/Sender]] · [[src/PuduLangMediator/Stream]] · [[src/PuduLangMediator/Utils/Template]] · [[src/_MOC]]
