AshCommanded.Commanded.Middleware.CommandMiddlewareProcessor (AshCommanded v0.1.0)

View Source

Processes command middleware for AshCommanded.

This module is responsible for:

  1. Collecting middleware from configuration, resources, and commands
  2. Building the middleware chain
  3. 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

apply_middleware(command, resource, context, final_handler)

@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 process
  • resource - The resource the command belongs to
  • context - The context for the command dispatch
  • final_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_middleware_chain(command, resource)

@spec get_middleware_chain(
  struct(),
  module()
) :: [module()]

Get the complete middleware chain for a command.

This collects middleware from:

  1. Global application config
  2. Resource-level middleware
  3. Command-specific middleware

Parameters

  • command - The command struct
  • resource - The resource module

Returns

A list of middleware modules with their configuration.