Skip to main content
Version: Next

abstractContextPipeline <TContextBase, TCrawlingContext>

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.

Index

Constructors

constructor

  • new ContextPipeline<TContextBase, TCrawlingContext>(): ContextPipeline<TContextBase, TCrawlingContext>

Methods

abstractcall

  • call(crawlingContext, finalContextConsumer): Promise<void>
  • 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

      Returns Promise<void>

      Throws - When a middleware fails during initialization

      Throws - When the pipeline is intentionally interrupted during initialization

      Throws - When the final context consumer throws an exception

      Throws - When cleanup operations fail

      Throws - Session errors are re-thrown as-is for special handling

    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

    • compose<TCrawlingContextExtension>(middleware): ContextPipeline<TContextBase, TCrawlingContext & TCrawlingContextExtension>
    • 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

    Page Options