"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getFlattenedObject = getFlattenedObject; /* * 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 and the Server Side Public License, v 1; you may not use this file except * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ function shouldReadKeys(value) { return typeof value === 'object' && value !== null && !Array.isArray(value); } /** * Flattens a deeply nested object to a map of dot-separated * paths pointing to all primitive values **and arrays** * from `rootValue`. * * example: * getFlattenedObject({ a: { b: 1, c: [2,3] } }) * // => { 'a.b': 1, 'a.c': [2,3] } * * @public */ function getFlattenedObject(rootValue) { if (!shouldReadKeys(rootValue)) { throw new TypeError(`Root value is not flatten-able, received ${rootValue}`); } const result = {}; (function flatten(prefix, object) { for (const [key, value] of Object.entries(object)) { const path = prefix ? `${prefix}.${key}` : key; if (shouldReadKeys(value)) { flatten(path, value); } else { result[path] = value; } } })('', rootValue); return result; }