<commit_before>import { decodeEvent } from 'resolve-storage-dynamo'

const handleGetAppConfigEvent = async (lambdaEvent, resolve) => {
  return {
    applicationName: resolve.applicationName,
    readModels: resolve.readModels.map(
      ({ name, projection, resolvers, invariantHash }) => ({
        name,
        eventTypes: Object.keys(projection || {}).filter(
          eventType => eventType !== 'Init'
        ),
        resolverNames: Object.keys(resolvers || {}),
        invariantHash
      })
    ),
    viewModels: resolve.viewModels.map(
      ({ name, projection, invariantHash }) => ({
        name,
        eventTypes: Object.keys(projection || {}).filter(
          eventType => eventType !== 'Init'
        ),
        invariantHash
      })
    ),
    aggregates: resolve.aggregates.map(({ name, commands, invariantHash }) => ({
      name,
      commandTypes: Object.keys(commands || {}),
      invariantHash
    }))
  }
}

const handleApplyEvents = async (lambdaEvent, resolve) => {
  const { events, listenerId } = lambdaEvent
  await resolve.executeQuery.updateByEvents(listenerId, events.map(decodeEvent))
  return true
}

const handleEventBusEvent = async (lambdaEvent, resolve) => {
  switch (lambdaEvent['detail-type']) {
    case 'GET_APP_CONFIG': {
      return await handleGetAppConfigEvent(lambdaEvent, resolve)
    }
    case 'APPLY_EVENTS_FROM_EVENT_BUS': {
      return await handleApplyEvents(lambdaEvent, resolve)
    }
    default: {
      return null
    }
  }
}

export default handleEventBusEvent<commit_msg>Improve bus event handler (#1053)<commit_after>import { decodeEvent } from 'resolve-storage-dynamo'

const handleApplyEvents = async (lambdaEvent, resolve) => {
  const { events, listenerId } = lambdaEvent
  const result = await resolve.executeQuery.updateByEvents(
    listenerId,
    events.map(decodeEvent)
  )
  return result
}

const handleEventBusEvent = async (lambdaEvent, resolve) => {
  switch (lambdaEvent['detail-type']) {
    case 'APPLY_EVENTS_FROM_EVENT_BUS': {
      return await handleApplyEvents(lambdaEvent, resolve)
    }
    default: {
      return null
    }
  }
}

export default handleEventBusEvent
{'fraction_non_alphanumeric': 0.11618257261410789, 'fraction_numerical': 0.0018441678192715537, 'mean_word_length': 3.2885375494071147, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '3112275', 'n_tokens_mistral': 625, 'n_tokens_neox': 619, 'n_words': 132}