Skip to content

Commit

Permalink
chore(NA): upgrade data plugin to lodash4
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic committed Jun 24, 2020
1 parent f115f61 commit 88fdb07
Show file tree
Hide file tree
Showing 107 changed files with 161 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { groupBy, has } from 'lodash';
import { groupBy, has } from 'lodash4';
import { buildQueryFromKuery } from './from_kuery';
import { buildQueryFromFilters } from './from_filters';
import { buildQueryFromLucene } from './from_lucene';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { extend, defaults } from 'lodash';
import { extend, defaults } from 'lodash4';
import { getTimeZoneFromSettings } from '../utils';
import { DslQuery, isEsQueryString } from './es_query_dsl';

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/common/es_query/es_query/es_query_dsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { has } from 'lodash';
import { has } from 'lodash4';

export interface DslRangeQuery {
range: {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/common/es_query/es_query/from_filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { isUndefined } from 'lodash';
import { isUndefined } from 'lodash4';
import { migrateFilter } from './migrate_filter';
import { filterMatchesIndex } from './filter_matches_index';
import { Filter, cleanFilter, isFilterDisabled } from '../filters';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { get } from 'lodash';
import { get } from 'lodash4';
import { getEsQueryConfig } from './get_es_query_config';
import { IUiSettingsClient } from 'kibana/public';
import { UI_SETTINGS } from '../../';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { isString } from 'lodash';
import { isString } from 'lodash4';
import { DslQuery } from './es_query_dsl';

export function luceneStringToDsl(query: string | any): DslQuery {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { isEqual, clone } from 'lodash';
import { isEqual, cloneDeep } from 'lodash';
import { migrateFilter, DeprecatedMatchPhraseFilter } from './migrate_filter';
import { PhraseFilter, MatchAllFilter } from '../filters';

Expand Down Expand Up @@ -52,7 +52,7 @@ describe('migrateFilter', function () {
});

it('should not modify the original filter', function () {
const oldMatchPhraseFilterCopy = clone(oldMatchPhraseFilter, true);
const oldMatchPhraseFilterCopy = cloneDeep(oldMatchPhraseFilter);

migrateFilter(oldMatchPhraseFilter, undefined);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { get, omit } from 'lodash';
import { get, omit } from 'lodash4';
import { getConvertedValueForField } from '../filters';
import { Filter } from '../filters';
import { IIndexPattern } from '../../index_patterns';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { get } from 'lodash';
import { get } from 'lodash4';
import { i18n } from '@kbn/i18n';
import { IIndexPattern, IFieldType } from '../..';
import { getIndexPatternFromFilter } from './get_index_pattern_from_filter';
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/common/es_query/filters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { omit, get } from 'lodash';
import { omit, get } from 'lodash4';
import { Filter } from './meta_filter';

export * from './build_filters';
Expand All @@ -44,6 +44,6 @@ export * from './types';
* @param {object} filter The filter to clean
* @returns {object}
*/
export const cleanFilter = (filter: Filter): Filter => omit(filter, ['meta', '$state']);
export const cleanFilter = (filter: Filter): Filter => omit(filter, ['meta', '$state']) as Filter;

export const isFilterDisabled = (filter: Filter): boolean => get(filter, 'meta.disabled', false);
2 changes: 1 addition & 1 deletion src/plugins/data/common/es_query/filters/phrase_filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { get, isPlainObject } from 'lodash';
import { get, isPlainObject } from 'lodash4';
import { Filter, FilterMeta } from './meta_filter';
import { IIndexPattern, IFieldType } from '../../index_patterns';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { each } from 'lodash';
import { each } from 'lodash4';
import { buildRangeFilter, getRangeFilterField, RangeFilter } from './range_filter';
import { fields, getField } from '../../index_patterns/mocks';
import { IIndexPattern, IFieldType } from '../../index_patterns';
Expand Down
8 changes: 5 additions & 3 deletions src/plugins/data/common/es_query/filters/range_filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { map, reduce, mapValues, get, keys, pick } from 'lodash';
import { map, reduce, mapValues, get, keys, pickBy } from 'lodash4';
import { Filter, FilterMeta } from './meta_filter';
import { IIndexPattern, IFieldType } from '../../index_patterns';

Expand Down Expand Up @@ -112,7 +112,9 @@ export const buildRangeFilter = (
filter.meta.formattedValue = formattedValue;
}

params = mapValues(params, (value) => (field.type === 'number' ? parseFloat(value) : value));
params = mapValues(params, (value: string) =>
field.type === 'number' ? parseFloat(value) : value
) as RangeFilterParams;

if ('gte' in params && 'gt' in params) throw new Error('gte and gt are mutually exclusive');
if ('lte' in params && 'lt' in params) throw new Error('lte and lt are mutually exclusive');
Expand Down Expand Up @@ -148,7 +150,7 @@ export const buildRangeFilter = (
};

export const getRangeScript = (field: IFieldType, params: RangeFilterParams) => {
const knownParams = pick(params, (val, key: any) => key in operators);
const knownParams = pickBy(params, (val, key: any) => key in operators);
let script = map(
knownParams,
(val: any, key: string) => '(' + field.script + ')' + get(operators, key) + key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { get } from 'lodash';
import { get } from 'lodash4';
import { nodeTypes } from '../node_types';
import { fields } from '../../../index_patterns/mocks';
import { IIndexPattern } from '../../../index_patterns';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import _ from 'lodash';
import _ from 'lodash4';
import { nodeTypes } from '../node_types';
import * as ast from '../ast';
import { IIndexPattern, KueryNode, IFieldType, LatLon } from '../../..';
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/common/es_query/kuery/functions/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function toElasticsearchQuery(
});
}

const isExistsQuery = valueArg.type === 'wildcard' && value === '*';
const isExistsQuery = valueArg.type === 'wildcard' && (value as any) === '*';
const isAllFieldsQuery =
(fullFieldNameArg.type === 'wildcard' && ((fieldName as unknown) as string) === '*') ||
(fields && indexPattern && fields.length === indexPattern.fields.length);
Expand Down Expand Up @@ -135,7 +135,7 @@ export function toElasticsearchQuery(
...accumulator,
{
script: {
...getPhraseScript(field, value),
...getPhraseScript(field, value as any),
},
},
];
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/common/es_query/kuery/functions/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import _ from 'lodash';
import _ from 'lodash4';
import { nodeTypes } from '../node_types';
import * as ast from '../ast';
import { getRangeScript, RangeFilterParams } from '../../filters';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { repeat } from 'lodash';
import { repeat } from 'lodash4';
import { i18n } from '@kbn/i18n';

const endOfInputText = i18n.translate('data.common.kql.errors.endOfInputText', {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/common/field_formats/converters/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { i18n } from '@kbn/i18n';
import { findLast, cloneDeep, template, escape } from 'lodash';
import { findLast, cloneDeep, template, escape } from 'lodash4';
import { KBN_FIELD_TYPES } from '../../kbn_field_types/types';
import { FieldFormat } from '../field_format';
import { HtmlContextTypeConvert, FIELD_FORMAT_IDS } from '../types';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/common/field_formats/converters/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { template, escape, keys } from 'lodash';
import { template, escape, keys } from 'lodash4';
import { shortenDottedString } from '../../utils';
import { KBN_FIELD_TYPES } from '../../kbn_field_types/types';
import { FieldFormat } from '../field_format';
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/common/field_formats/converters/truncate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { i18n } from '@kbn/i18n';
import { trunc } from 'lodash';
import { truncate } from 'lodash';
import { KBN_FIELD_TYPES } from '../../kbn_field_types/types';
import { FieldFormat } from '../field_format';
import { TextContextTypeConvert, FIELD_FORMAT_IDS } from '../types';
Expand All @@ -35,7 +35,7 @@ export class TruncateFormat extends FieldFormat {
textConvert: TextContextTypeConvert = (val) => {
const length = this.param('fieldLength');
if (length > 0) {
return trunc(val, {
return truncate(val, {
length: length + omission.length,
omission,
});
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/common/field_formats/converters/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { i18n } from '@kbn/i18n';
import { escape, memoize } from 'lodash';
import { escape, memoize } from 'lodash4';
import { getHighlightHtml } from '../utils';
import { KBN_FIELD_TYPES } from '../../kbn_field_types/types';
import { FieldFormat } from '../field_format';
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/data/common/field_formats/field_format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { constant, trimRight, trimLeft, get } from 'lodash';
import { constant, trimEnd, trimStart, get } from 'lodash4';
import { FieldFormat } from './field_format';
import { asPrettyString } from './utils';

Expand Down Expand Up @@ -120,8 +120,8 @@ describe('FieldFormat class', () => {
test('does escape the output of the text converter if used in an html context', () => {
const f = getTestFormat(undefined, constant('<script>alert("xxs");</script>'));

const expected = trimRight(
trimLeft(f.convert('', 'html'), '<span ng-non-bindable>'),
const expected = trimEnd(
trimStart(f.convert('', 'html'), '<span ng-non-bindable>'),
'</span>'
);

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/common/field_formats/field_format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { transform, size, cloneDeep, get, defaults } from 'lodash';
import { transform, size, cloneDeep, get, defaults } from 'lodash4';
import { createCustomFieldFormat } from './converters/custom';
import {
FieldFormatsGetConfigFn,
Expand Down Expand Up @@ -185,7 +185,7 @@ export abstract class FieldFormat {

const params = transform(
this._params,
(uniqParams, val, param) => {
(uniqParams: any, val, param) => {
if (param && val !== get(defaultsParams, param)) {
uniqParams[param] = val;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

// eslint-disable-next-line max-classes-per-file
import { forOwn, isFunction, memoize, identity } from 'lodash';
import { forOwn, isFunction, memoize, identity } from 'lodash4';

import {
FieldFormatsGetConfigFn,
Expand Down Expand Up @@ -233,7 +233,7 @@ export class FieldFormatsRegistry {
parseDefaultTypeMap(value: any) {
this.defaultMap = value;
forOwn(this, (fn) => {
if (isFunction(fn) && fn.cache) {
if (isFunction(fn) && (fn as any).cache) {
// clear all memoize caches
// @ts-ignore
fn.cache = new memoize.Cache();
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/common/field_mapping/mapping_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type ShorthandFieldMapObject = FieldMappingSpec | ES_FIELD_TYPES | 'json';

/** @public */
export const expandShorthand = (sh: Record<string, ShorthandFieldMapObject>): MappingObject => {
return mapValues<Record<string, ShorthandFieldMapObject>>(sh, (val: ShorthandFieldMapObject) => {
return mapValues(sh, (val: ShorthandFieldMapObject) => {
const fieldMap = isString(val) ? { type: val } : val;
const json: FieldMappingSpec = {
type: ES_FIELD_TYPES.TEXT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { findIndex } from 'lodash';
import { findIndex } from 'lodash4';
import { IIndexPattern } from '../../types';
import { IFieldType } from '../../../common';
import { Field, FieldSpec } from './field';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import _ from 'lodash';
import _ from 'lodash4';

export function ObjDefine(defaults, prototype) {
this.obj; // created by this.create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { contains } from 'lodash';
import { includes } from 'lodash4';
import { CoreStart } from 'kibana/public';
import { IndexPatternsContract } from './index_patterns';

Expand All @@ -35,7 +35,7 @@ export const createEnsureDefaultIndexPattern = (
const patterns = await this.getIds();
let defaultId = uiSettings.get('defaultIndex');
let defined = !!defaultId;
const exists = contains(patterns, defaultId);
const exists = includes(patterns, defaultId);

if (defined && !exists) {
uiSettings.remove('defaultIndex');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import _ from 'lodash';
import _ from 'lodash4';
import { IndexPattern } from './index_pattern';

// Takes a hit, merges it with any stored/scripted fields, and with the metaFields
Expand Down Expand Up @@ -77,7 +77,7 @@ function decorateFlattenedWrapper(hit: Record<string, any>, metaFields: Record<s

// unwrap computed fields
_.forOwn(hit.fields, function (val, key: any) {
if (key[0] === '_' && !_.contains(metaFields, key)) return;
if (key[0] === '_' && !_.includes(metaFields, key)) return;
flattened[key] = Array.isArray(val) && val.length === 1 ? val[0] : val;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import _ from 'lodash';
import _ from 'lodash4';
import { IndexPattern } from './index_pattern';
import { FieldFormatsContentType } from '../../../common';

Expand Down
Loading

0 comments on commit 88fdb07

Please sign in to comment.