abstractContextPipeline <TContextBase, TCrawlingContext>
Index
Constructors
Methods
Constructors
constructor
Returns ContextPipeline<TContextBase, TCrawlingContext>
Methods
abstractcall
Executes the middleware pipeline and passes the final context to a consumer function.
This method runs the crawling context through the entire middleware chain, enhancing it at each step, and then passes the final enhanced context to the provided consumer function. Proper cleanup is performed even if exceptions occur during processing.
Parameters
crawlingContext: TContextBase
The initial context to process through the pipeline
finalContextConsumer: (finalContext) => unknown
The function that will receive the final enhanced context
onError: (error) => Awaitable<void>
Receives a middleware failure wrapped in a ContextPipelineInitializationError, or a consumer failure wrapped in a RequestHandlerError, with the original in
cause. After a middleware failure, the rest of the chain and the consumer are skipped. Runs before the cleanups, so it still sees whatever the middlewares set up.
Returns Promise<void>
Throws - When cleanup operations fail
Throws - Whatever
onErrorthrows
abstractchain
Chains another pipeline onto this one. The other pipeline's base context must match this pipeline's output context. Returns a new pipeline that runs this pipeline's middlewares first, then the other pipeline's middlewares.
Parameters
other: ContextPipeline<TCrawlingContext, TFinalContext>
The pipeline to append after this one
Returns ContextPipeline<TContextBase, TFinalContext>
A new ContextPipeline combining both pipelines' middlewares
abstractcompose
Adds a middleware to the pipeline, creating a new pipeline instance.
This method provides a fluent interface for building context transformation pipelines. Each middleware can enhance the context with additional properties or utilities.
Parameters
middleware: ContextMiddleware<TCrawlingContext, TCrawlingContextExtension>
The middleware to add to the pipeline
Returns ContextPipeline<TContextBase, TCrawlingContext & TCrawlingContextExtension>
A new ContextPipeline instance with the added middleware
staticcreate
Creates a new empty context pipeline.
Returns ContextPipeline<TContextBase, TContextBase>
A new ContextPipeline instance with no transformations
Encapsulates the logic of gradually enhancing the crawling context with additional information and utilities.
The enhancement is done by a chain of middlewares that are added to the pipeline after its creation. This class provides a type-safe way to build a pipeline of context transformations where each step can enhance the context with additional properties or utilities.