Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,40 @@ describe('unflattenObject', () => {
},
});
});

it('handles nested arrays', () => {
expect(
unflattenObject({
nested: [[{ 'first.second': 'foo' }, { 'first.second': 'bar' }]],
mixed: [[1, 2, { 'first.second': 'foo' }]],
})
).toEqual({
nested: [[{ first: { second: 'foo' } }, { first: { second: 'bar' } }]],
mixed: [[1, 2, { first: { second: 'foo' } }]],
});
});

it('unflattens nested flattened objects', () => {
expect(
unflattenObject({
'my.flattened.parent.key': {
'an.internal.key': 1,
},
})
).toEqual({
my: {
flattened: {
parent: {
key: {
an: {
internal: {
key: 1,
},
},
},
},
},
},
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ export function unflattenObject<T extends Record<string, any>>(
for (const key in source) {
const val = source[key as keyof typeof source];
if (Array.isArray(val)) {
const unflattenedArray = val.map((item: unknown) => {
if (item && typeof item === 'object' && !Array.isArray(item)) {
const unflattenedArray = val.map(function unflattenArray(item: unknown): unknown {
if (Array.isArray(item)) {
return item.map(unflattenArray);
}
if (item !== null && typeof item === 'object') {
return unflattenObject(item);
}
return item;
});
set(target, key, unflattenedArray);
} else if (val !== null && typeof val === 'object') {
set(target, key, unflattenObject(val));
} else {
set(target, key, val);
}
Expand Down
2 changes: 0 additions & 2 deletions x-pack/solutions/observability/packages/utils-common/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ project:
sourceRoot: x-pack/solutions/observability/packages/utils-common
dependsOn:
- '@kbn/es-query'
- '@kbn/safer-lodash-set'
- '@kbn/utility-types'
tags:
- shared-common
- package
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,5 @@
],
"kbn_references": [
"@kbn/es-query",
"@kbn/safer-lodash-set",
"@kbn/utility-types",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ dependsOn:
- '@kbn/zod'
- '@kbn/connector-schemas'
- '@kbn/onechat-plugin'
- '@kbn/object-utils'
tags:
- plugin
- prod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import path from 'path';
import fs from 'fs';
import yaml from 'js-yaml';
import { identity, pickBy } from 'lodash';
import { unflattenObject } from '@kbn/observability-utils-common/object/unflatten_object';
import { unflattenObject } from '@kbn/object-utils';

export type KibanaConfig = ReturnType<typeof readKibanaConfig>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@
"@kbn/utility-types-jest",
"@kbn/zod",
"@kbn/connector-schemas",
"@kbn/onechat-plugin"
"@kbn/onechat-plugin",
"@kbn/object-utils",
],
"exclude": ["target/**/*"]
}