<commit_before>import * as DynamoDB from 'aws-sdk/clients/dynamodb'
import { PropertyMetadata } from '../../metadata/property-metadata.model'
import { initOrUpdateProperty } from '../property/init-or-update-property.function'
import { KEY_PROPERTY } from '../property/key-property.const'
import { IndexType } from './index-type.enum'

export interface IndexData {
  name: string
  keyType: DynamoDB.KeyType
}

export function initOrUpdateIndex(indexType: IndexType, indexData: IndexData, target: any, propertyKey: string): void {
  const properties: Array<PropertyMetadata<any>> = Reflect.getMetadata(KEY_PROPERTY, target.constructor) || []
  const existingProperty = properties.find(property => property.name === propertyKey)

  let propertyMetadata: Partial<PropertyMetadata<any>>
  switch (indexType) {
    case IndexType.GSI:
      propertyMetadata = initOrUpdateGSI(
        existingProperty && existingProperty.keyForGSI ? existingProperty.keyForGSI : {},
        indexData,
      )
      break
    case IndexType.LSI:
      propertyMetadata = initOrUpdateLSI(
        existingProperty && existingProperty.sortKeyForLSI ? existingProperty.sortKeyForLSI : [],
        indexData,
      )
      break
    default:
      throw new Error(`unsupported index type ${indexType}`)
  }

  initOrUpdateProperty(propertyMetadata, target, propertyKey)
}

function initOrUpdateGSI(
  indexes: Record<string, DynamoDB.KeyType>,
  indexData: IndexData,
): Partial<PropertyMetadata<any>> {
  if (indexes[indexData.name]) {
    // TODO LOW:INVESTIGATE when we throw an error we have a problem where multiple different classes extend one base class, this will be executed by multiple times
    // throw new Error(
    //   'the property with name is already registered as key for index - one property can only define one key per index'
    // )
  } else {
    indexes[indexData.name] = indexData.keyType
  }

  return { keyForGSI: indexes }
}

function initOrUpdateLSI(indexes: string[], indexData: IndexData): Partial<PropertyMetadata<any>> {
  indexes.push(indexData.name)
  return { sortKeyForLSI: indexes }
}
<commit_msg>chore(util): reactivate error<commit_after>import * as DynamoDB from 'aws-sdk/clients/dynamodb'
import { PropertyMetadata } from '../../metadata/property-metadata.model'
import { initOrUpdateProperty } from '../property/init-or-update-property.function'
import { KEY_PROPERTY } from '../property/key-property.const'
import { IndexType } from './index-type.enum'

export interface IndexData {
  name: string
  keyType: DynamoDB.KeyType
}

export function initOrUpdateIndex(indexType: IndexType, indexData: IndexData, target: any, propertyKey: string): void {
  const properties: Array<PropertyMetadata<any>> = Reflect.getMetadata(KEY_PROPERTY, target.constructor) || []
  const existingProperty = properties.find(property => property.name === propertyKey)

  let propertyMetadata: Partial<PropertyMetadata<any>>
  switch (indexType) {
    case IndexType.GSI:
      propertyMetadata = initOrUpdateGSI(
        existingProperty && existingProperty.keyForGSI ? existingProperty.keyForGSI : {},
        indexData,
      )
      break
    case IndexType.LSI:
      propertyMetadata = initOrUpdateLSI(
        existingProperty && existingProperty.sortKeyForLSI ? existingProperty.sortKeyForLSI : [],
        indexData,
      )
      break
    default:
      throw new Error(`unsupported index type ${indexType}`)
  }

  initOrUpdateProperty(propertyMetadata, target, propertyKey)
}

function initOrUpdateGSI(
  indexes: Record<string, DynamoDB.KeyType>,
  indexData: IndexData,
): Partial<PropertyMetadata<any>> {
  if (indexes[indexData.name]) {
    throw new Error(
      'the property with name is already registered as key for index - one property can only define one key per index'
    )
  } else {
    indexes[indexData.name] = indexData.keyType
  }

  return { keyForGSI: indexes }
}

function initOrUpdateLSI(indexes: string[], indexData: IndexData): Partial<PropertyMetadata<any>> {
  indexes.push(indexData.name)
  return { sortKeyForLSI: indexes }
}

{'fraction_non_alphanumeric': 0.10403344810624693, 'fraction_numerical': 0.0, 'mean_word_length': 4.167725540025413, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4902253', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1159, 'n_words': 290}