import { ChainHandler } from "../ChainHandler"; export abstract class BaseChainHandler implements ChainHandler { private nextHandler: ChainHandler | null = null; public setNext(handler: ChainHandler): ChainHandler { if (this.nextHandler === null) { this.nextHandler = handler; } else { this.nextHandler.setNext(handler); } return this; } public async handle(builder: T): Promise { await this.processInput(builder); if (this.nextHandler !== null) { await this.nextHandler.handle(builder); } } protected abstract processInput(builder: T): Promise; protected abort(): void { this.nextHandler = null; } }