From 57149aab96c0c8c16212262ad3f6c321b4c8d9e6 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 8 Jun 2023 11:31:00 -0400 Subject: [PATCH] [8.8] [ResponseOps] optimize building ecsFieldMap (#159251) (#159313) # Backport This will backport the following commits from `main` to `8.8`: - [[ResponseOps] optimize building ecsFieldMap (#159251)](https://github.com/elastic/kibana/pull/159251) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Patrick Mueller --- .../src/field_maps/ecs_field_map.ts | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/packages/kbn-alerts-as-data-utils/src/field_maps/ecs_field_map.ts b/packages/kbn-alerts-as-data-utils/src/field_maps/ecs_field_map.ts index 81c95d213001..3704edee7270 100644 --- a/packages/kbn-alerts-as-data-utils/src/field_maps/ecs_field_map.ts +++ b/packages/kbn-alerts-as-data-utils/src/field_maps/ecs_field_map.ts @@ -11,25 +11,23 @@ import { EcsMetadata, FieldMap } from './types'; const EXCLUDED_TYPES = ['constant_keyword']; -export const ecsFieldMap: FieldMap = Object.keys(EcsFlat).reduce((acc, currKey) => { - const value: EcsMetadata = EcsFlat[currKey as keyof typeof EcsFlat]; - - // Exclude excluded types - if (EXCLUDED_TYPES.includes(value.type)) { - return acc; - } - - return { - ...acc, - [currKey]: { - type: value.type, - array: value.normalize.includes('array'), - required: !!value.required, - ...(value.scaling_factor ? { scaling_factor: value.scaling_factor } : {}), - ...(value.ignore_above ? { ignore_above: value.ignore_above } : {}), - ...(value.multi_fields ? { multi_fields: value.multi_fields } : {}), - }, - }; -}, {}); +export const ecsFieldMap: FieldMap = Object.fromEntries( + Object.entries(EcsFlat) + .filter(([_, value]) => !EXCLUDED_TYPES.includes(value.type)) + .map(([key, _]) => { + const value: EcsMetadata = EcsFlat[key as keyof typeof EcsFlat]; + return [ + key, + { + type: value.type, + array: value.normalize.includes('array'), + required: !!value.required, + ...(value.scaling_factor ? { scaling_factor: value.scaling_factor } : {}), + ...(value.ignore_above ? { ignore_above: value.ignore_above } : {}), + ...(value.multi_fields ? { multi_fields: value.multi_fields } : {}), + }, + ]; + }) +); export type EcsFieldMap = typeof ecsFieldMap;