"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.flattenObject = void 0; var _lodash = require("lodash"); /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ // Inspired by x-pack/plugins/apm/public/utils/flatten_object.ts // Slighly modified to have key/value exposed as Object. const flattenObject = (item, accDefault = {}, parentKey) => { if (item) { const isArrayWithSingleValue = Array.isArray(item) && item.length === 1; return Object.keys(item).sort().reduce((acc, key) => { const childKey = isArrayWithSingleValue ? '' : key; const currentKey = (0, _lodash.compact)([parentKey, childKey]).join('.'); // item[key] can be a primitive (string, number, boolean, null, undefined) or Object or Array if ((0, _lodash.isObject)(item[key])) { flattenObject(item[key], acc, currentKey); } else { acc[currentKey] = item[key]; } return acc; }, accDefault); } return {}; }; exports.flattenObject = flattenObject;