AshCommanded.Commanded.Middleware.CommandMiddlewareProcessor (AshCommanded v0.1.0)
View SourceProcesses command middleware for AshCommanded.
This module is responsible for:
- Collecting middleware from configuration, resources, and commands
- Building the middleware chain
- Applying middleware to commands
It's used internally by command handlers to ensure consistent middleware application across the system.
Summary
Functions
Apply all applicable middleware to a command.
Get the complete middleware chain for a command.
Functions
@spec apply_middleware( command :: struct(), resource :: module(), context :: map(), final_handler :: (struct(), map() -> {:ok, any()} | {:error, any()}) ) :: {:ok, any()} | {:error, any()}
Apply all applicable middleware to a command.
Parameters
command
- The command to processresource
- The resource the command belongs tocontext
- The context for the command dispatchfinal_handler
- Function to call after all middleware has been applied
Examples
apply_middleware(
%MyApp.Commands.RegisterUser{},
MyApp.User,
%{},
fn cmd, ctx -> {:ok, process_command(cmd)} end
)
Get the complete middleware chain for a command.
This collects middleware from:
- Global application config
- Resource-level middleware
- Command-specific middleware
Parameters
command
- The command structresource
- The resource module
Returns
A list of middleware modules with their configuration.