Executes an ordered sequence of named transformations over a rule array, with optional lifecycle hooks, exclusion/inclusion pattern filtering, and event emission.
Execution order
Requested transformation types are always sorted into a fixed canonical
order (see getOrderedTransformations) regardless of the order in which
they appear in the configuration. This guarantees consistent, reproducible
output.
Hook integration
The pipeline holds an optional TransformationHookManager. On each iteration the following sequence occurs:
emitProgress(…) hookManager.executeBeforeHooks(beforeContext) ← before transformation try { rules = await transformation.execute(rules, ctx) } catch (e) { await hookManager.executeErrorHooks(errorContext) throw e } hookManager.executeAfterHooks(afterContext) ← after transformation
When no hooks are registered (hookManager.hasHooks() === false) the three
execute calls are skipped entirely. The default is a NoOpHookManager
so hook overhead is zero unless you pass a real hook manager.
Event emission
ICompilerEvents.onTransformationStart / onTransformationComplete events
are now emitted through the hook system rather than by direct calls
inside the loop. FilterCompiler and WorkerCompiler achieve this by
automatically registering a createEventBridgeHook on the hook
manager when ICompilerEvents listeners are present.
TransformationPipeline(registry?: TransformationRegistry,logger?: ILogger,eventEmitter?: CompilerEventEmitter,hookManager?: TransformationHookManager,)
Creates a new TransformationPipeline.
All parameters are optional; sane defaults are used when omitted:
registrydefaults to a newTransformationRegistrywith all built-in transformations pre-registered.loggerdefaults to the module-level default logger.eventEmitterdefaults to aNoOpEventEmitter(no-overhead singleton).hookManagerdefaults to aNoOpHookManager(no-overhead, skips all hook code paths).
In practice you will rarely construct this directly — FilterCompiler
and WorkerCompiler build and configure the pipeline for you.
eventEmitter: CompilerEventEmitter
filterService: FilterService
hookManager: TransformationHookManager
registry: TransformationRegistry
applyExclusions(rules: string[],configuration: IConfiguration | ISource,): Promise<string[]>
Applies exclusion patterns. Optimized to partition patterns by type for faster matching.
applyInclusions(rules: string[],configuration: IConfiguration | ISource,): Promise<string[]>
Applies inclusion patterns. Optimized to partition patterns by type for faster matching.
applyPatternFilter(rules: string[],patterns?: string[],patternSources?: string[],mode?: "exclude" | "include",): Promise<string[]>
Common pattern matching logic for exclusions and inclusions. Partitions patterns by type for optimized matching. Uses combined regex for better performance with many patterns.
getOrderedTransformations(requested: TransformationType[]): TransformationType[]
Gets transformations in the correct execution order.
transform(): Promise<string[]>
Apply exclusion/inclusion pattern filters and then execute the requested transformations in canonical order.
The method follows a three-phase approach:
- Exclusions — rules matching any exclusion pattern are removed.
- Inclusions — if inclusion patterns are configured, only rules matching at least one pattern are kept.
- Transformations — each requested transformation is executed in the fixed canonical order, with before/after/error hooks invoked around each execution.
The method uses a readonly string[] internally during the
transformation loop to avoid unnecessary array copies; it only
materialises a mutable copy at the very end.