Overview
Middleware builders provide a fluent interface for creating reusable logic that wraps task execution or resource initialization. Middleware can modify inputs, handle errors, add cross-cutting concerns like retry, timeout, caching, and more.Task Middleware
Task middleware wraps task execution and can modify inputs, outputs, or behavior.Methods
configSchema() / schema()
Defines the validation schema for middleware configuration.Validation schema for middleware configuration.
run()
Defines the middleware execution logic.The middleware function. Receives a context object with:
task- The task definition being executedinput- The validated task inputconfig- The middleware configurationdeps- Resolved middleware dependenciesruntime- Runtime instancelogger- Scoped loggerjournal- Execution journal for middleware communicationnext()- Function to call the next middleware or task
build())
dependencies()
Defines dependencies to inject into the middleware.Object mapping dependency keys to resources.
everywhere()
Configures whether this middleware applies to all tasks automatically.When
true, applies to all tasks. Can also be a predicate function to filter tasks.tags(), meta(), throws()
Same as task builder. See Task Builder for details.build()
Builds and returns the final middleware definition.Task Middleware Type Signature
Task Middleware Examples
Simple Logging Middleware
Retry Middleware with Config
Timeout Middleware
Middleware with Dependencies
Middleware Applied Everywhere
Resource Middleware
Resource middleware wraps resource initialization and disposal.Methods
Resource middleware has similar methods to task middleware:configSchema()/schema()run()dependencies()everywhere()tags(),meta(),throws()build()
run() context: