All files / src/aws target.ts

86.36% Statements 19/22
50% Branches 1/2
66.67% Functions 2/3
86.36% Lines 19/22
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52  2x 2x     2x 2x 2x 2x 2x 2x 2x 2x 2x             2x 2x     2x 2x 2x 2x 2x                               2x              
import * as names from './names'
 
export default class Target {
  private dependencies: string[] = []
  private type: string = 'AWS::ApplicationAutoScaling::ScalableTarget'
 
  constructor (
    private service: string,
    private table: string,
    private min: number,
    private max: number,
    private read: boolean,
    private index?: string,
    private stage?: string
  ) { }

  public setDependencies(list: string[]): Target {
    this.dependencies = list
 
    return this
  }
I
  public toJSON(): any {
    const resource = [ 'table/', { Ref: this.table } ]
 
    if (this.index) {
      resource.push('/index/', this.index)
    }
 
    const nameTarget = names.target(this.service, this.table, this.read, this.index, this.stage)
    const nameRole = names.role(this.service, this.table, this.index, this.stage)
    const nameDimension = names.dimension(this.read, !!this.index)
 
    const dependencies = [ this.table, nameRole ].concat(this.dependencies)
 
    return {
      [nameTarget]: {
        DependsOn: dependencies,
        Properties: {
          MaxCapacity: this.max,
          MinCapacity: this.min,
          ResourceId: { 'Fn::Join': [ '', resource ] },
          RoleARN: { 'Fn::GetAtt': [ nameRole, 'Arn' ] },
          ScalableDimension: nameDimension,
          ServiceNamespace: 'dynamodb'
        },
        Type: this.type
      }
    }
  }
}