All files / domain change.builder.ts

100% Statements 14/14
100% Branches 0/0
100% Functions 7/7
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38    2x   2x 5x         5x 5x       5x       1x 1x       1x 1x       1x   1x       5x    
import { Transform } from "../types/transform.type"
import { Transformation } from "../types/transformation.type"
import { Change } from "./change.dto"
 
export class ChangeBuilder {
  private _transforms: Transform[] = []
  private _outputPath: string
  private readonly _sourcePath: string
 
  private constructor(source: string) {
    this._outputPath = source
    this._sourcePath = source
  }
 
  static forSourceFile(path: string): ChangeBuilder {
    return new ChangeBuilder(path)
  }
 
  withOutputPath(path: string): Omit<this, 'withOutputPath'> {
    this._outputPath = path
    return this
  }
 
  transformations(transformations: Transformation[]): Omit<this, 'transformations'> {
    this._transforms.push(...transformations.map(t => t.transform.bind(t)))
    return this
  }
 
  transform(fn: Transform): Omit<this, 'transform'> {
    this._transforms.push(fn)
 
    return this
  }
 
  build(): Change {
    return new Change(this._transforms, this._sourcePath, this._outputPath)
  }
}