From f957f55eafb94198c3e4745dd7f464e2a19c4bae Mon Sep 17 00:00:00 2001 From: Yara Tercero Date: Tue, 15 Dec 2020 18:16:52 -0500 Subject: [PATCH] trying do decrease load bundle size --- x-pack/plugins/lists/common/utils.ts | 35 ------------------- .../plugins/lists/public/exceptions/utils.ts | 30 ++++++++++++++-- .../exception_lists/create_endpoint_list.ts | 3 +- .../create_endpoint_trusted_apps_list.ts | 3 +- .../exception_lists/create_exception_list.ts | 3 +- .../create_exception_list_item.ts | 2 +- .../exception_lists/delete_exception_list.ts | 2 +- .../delete_exception_list_item.ts | 2 +- .../delete_exception_list_items_by_list.ts | 2 +- .../exception_lists/find_exception_list.ts | 3 +- .../find_exception_list_items.ts | 3 +- .../exception_lists/get_exception_list.ts | 3 +- .../get_exception_list_item.ts | 3 +- .../exception_lists/update_exception_list.ts | 3 +- .../update_exception_list_item.ts | 2 +- .../server/services/exception_lists/utils.ts | 29 ++++++++++++++- 16 files changed, 69 insertions(+), 59 deletions(-) delete mode 100644 x-pack/plugins/lists/common/utils.ts diff --git a/x-pack/plugins/lists/common/utils.ts b/x-pack/plugins/lists/common/utils.ts deleted file mode 100644 index eb6eb718c90d0..0000000000000 --- a/x-pack/plugins/lists/common/utils.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { NamespaceType } from './schemas/types'; -import { NamespaceTypeArray } from './schemas/types/default_namespace_array'; -import { - SavedObjectType, - exceptionListAgnosticSavedObjectType, - exceptionListSavedObjectType, -} from './types'; - -export const getSavedObjectType = ({ - namespaceType, -}: { - namespaceType: NamespaceType; -}): SavedObjectType => { - if (namespaceType === 'agnostic') { - return exceptionListAgnosticSavedObjectType; - } else { - return exceptionListSavedObjectType; - } -}; - -export const getSavedObjectTypes = ({ - namespaceType, -}: { - namespaceType: NamespaceTypeArray; -}): SavedObjectType[] => { - return namespaceType.map((singleNamespaceType) => - getSavedObjectType({ namespaceType: singleNamespaceType }) - ); -}; diff --git a/x-pack/plugins/lists/public/exceptions/utils.ts b/x-pack/plugins/lists/public/exceptions/utils.ts index 946027a322e5f..dc50a89e91a2e 100644 --- a/x-pack/plugins/lists/public/exceptions/utils.ts +++ b/x-pack/plugins/lists/public/exceptions/utils.ts @@ -8,11 +8,37 @@ import { get } from 'lodash/fp'; import { ENDPOINT_TRUSTED_APPS_LIST_ID } from '../../common/constants'; import { NamespaceType } from '../../common/schemas'; -import { SavedObjectType } from '../../common/types'; -import { getSavedObjectTypes } from '../../common/utils'; +import { NamespaceTypeArray } from '../../common/schemas/types/default_namespace_array'; +import { + SavedObjectType, + exceptionListAgnosticSavedObjectType, + exceptionListSavedObjectType, +} from '../../common/types'; import { ExceptionListFilter, ExceptionListIdentifiers } from './types'; +export const getSavedObjectType = ({ + namespaceType, +}: { + namespaceType: NamespaceType; +}): SavedObjectType => { + if (namespaceType === 'agnostic') { + return exceptionListAgnosticSavedObjectType; + } else { + return exceptionListSavedObjectType; + } +}; + +export const getSavedObjectTypes = ({ + namespaceType, +}: { + namespaceType: NamespaceTypeArray; +}): SavedObjectType[] => { + return namespaceType.map((singleNamespaceType) => + getSavedObjectType({ namespaceType: singleNamespaceType }) + ); +}; + export const getIdsAndNamespaces = ({ lists, showDetection, diff --git a/x-pack/plugins/lists/server/services/exception_lists/create_endpoint_list.ts b/x-pack/plugins/lists/server/services/exception_lists/create_endpoint_list.ts index 401d67b450cc8..fb2b637657bb6 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/create_endpoint_list.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/create_endpoint_list.ts @@ -7,7 +7,6 @@ import { SavedObjectsClientContract } from 'kibana/server'; import uuid from 'uuid'; -import { getSavedObjectType } from '../../../common/utils'; import { ENDPOINT_LIST_DESCRIPTION, ENDPOINT_LIST_ID, @@ -15,7 +14,7 @@ import { } from '../../../common/constants'; import { ExceptionListSchema, ExceptionListSoSchema, Version } from '../../../common/schemas'; -import { transformSavedObjectToExceptionList } from './utils'; +import { getSavedObjectType, transformSavedObjectToExceptionList } from './utils'; interface CreateEndpointListOptions { savedObjectsClient: SavedObjectsClientContract; diff --git a/x-pack/plugins/lists/server/services/exception_lists/create_endpoint_trusted_apps_list.ts b/x-pack/plugins/lists/server/services/exception_lists/create_endpoint_trusted_apps_list.ts index 9cc3565578116..d9eedb0af4e77 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/create_endpoint_trusted_apps_list.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/create_endpoint_trusted_apps_list.ts @@ -7,7 +7,6 @@ import { SavedObjectsClientContract } from 'kibana/server'; import uuid from 'uuid'; -import { getSavedObjectType } from '../../../common/utils'; import { ENDPOINT_TRUSTED_APPS_LIST_DESCRIPTION, ENDPOINT_TRUSTED_APPS_LIST_ID, @@ -15,7 +14,7 @@ import { } from '../../../common/constants'; import { ExceptionListSchema, ExceptionListSoSchema, Version } from '../../../common/schemas'; -import { transformSavedObjectToExceptionList } from './utils'; +import { getSavedObjectType, transformSavedObjectToExceptionList } from './utils'; interface CreateEndpointListOptions { savedObjectsClient: SavedObjectsClientContract; diff --git a/x-pack/plugins/lists/server/services/exception_lists/create_exception_list.ts b/x-pack/plugins/lists/server/services/exception_lists/create_exception_list.ts index 801c6a6c44e7f..91a0506ad06e3 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/create_exception_list.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/create_exception_list.ts @@ -7,7 +7,6 @@ import { SavedObjectsClientContract } from 'kibana/server'; import uuid from 'uuid'; -import { getSavedObjectType } from '../../../common/utils'; import { Description, ExceptionListSchema, @@ -22,7 +21,7 @@ import { Version, } from '../../../common/schemas'; -import { transformSavedObjectToExceptionList } from './utils'; +import { getSavedObjectType, transformSavedObjectToExceptionList } from './utils'; interface CreateExceptionListOptions { listId: ListId; diff --git a/x-pack/plugins/lists/server/services/exception_lists/create_exception_list_item.ts b/x-pack/plugins/lists/server/services/exception_lists/create_exception_list_item.ts index 4021c58910b93..9f331362cdd44 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/create_exception_list_item.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/create_exception_list_item.ts @@ -7,7 +7,6 @@ import { SavedObjectsClientContract } from 'kibana/server'; import uuid from 'uuid'; -import { getSavedObjectType } from '../../../common/utils'; import { CreateCommentsArray, Description, @@ -25,6 +24,7 @@ import { } from '../../../common/schemas'; import { + getSavedObjectType, transformCreateCommentsToComments, transformSavedObjectToExceptionListItem, } from './utils'; diff --git a/x-pack/plugins/lists/server/services/exception_lists/delete_exception_list.ts b/x-pack/plugins/lists/server/services/exception_lists/delete_exception_list.ts index 4251170ef0f77..afeed6b5e2cde 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/delete_exception_list.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/delete_exception_list.ts @@ -6,7 +6,6 @@ import { SavedObjectsClientContract } from 'kibana/server'; -import { getSavedObjectType } from '../../../common/utils'; import { ExceptionListSchema, IdOrUndefined, @@ -14,6 +13,7 @@ import { NamespaceType, } from '../../../common/schemas'; +import { getSavedObjectType } from './utils'; import { getExceptionList } from './get_exception_list'; import { deleteExceptionListItemByList } from './delete_exception_list_items_by_list'; diff --git a/x-pack/plugins/lists/server/services/exception_lists/delete_exception_list_item.ts b/x-pack/plugins/lists/server/services/exception_lists/delete_exception_list_item.ts index f09ac02f8bcbd..ee85cf36a48b5 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/delete_exception_list_item.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/delete_exception_list_item.ts @@ -6,7 +6,6 @@ import { SavedObjectsClientContract } from 'kibana/server'; -import { getSavedObjectType } from '../../../common/utils'; import { ExceptionListItemSchema, Id, @@ -15,6 +14,7 @@ import { NamespaceType, } from '../../../common/schemas'; +import { getSavedObjectType } from './utils'; import { getExceptionListItem } from './get_exception_list_item'; interface DeleteExceptionListItemOptions { diff --git a/x-pack/plugins/lists/server/services/exception_lists/delete_exception_list_items_by_list.ts b/x-pack/plugins/lists/server/services/exception_lists/delete_exception_list_items_by_list.ts index 3bf7d1aea451a..e835ffae02c9e 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/delete_exception_list_items_by_list.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/delete_exception_list_items_by_list.ts @@ -4,11 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import { getSavedObjectType } from '../../../common/utils'; import { SavedObjectsClientContract } from '../../../../../../src/core/server/'; import { ListId, NamespaceType } from '../../../common/schemas'; import { findExceptionListItem } from './find_exception_list_item'; +import { getSavedObjectType } from './utils'; const PER_PAGE = 100; diff --git a/x-pack/plugins/lists/server/services/exception_lists/find_exception_list.ts b/x-pack/plugins/lists/server/services/exception_lists/find_exception_list.ts index 2f03b2d01ca06..fc9f01312cb7a 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/find_exception_list.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/find_exception_list.ts @@ -12,7 +12,6 @@ import { exceptionListAgnosticSavedObjectType, exceptionListSavedObjectType, } from '../../../common/types'; -import { getSavedObjectTypes } from '../../../common/utils'; import { ExceptionListSoSchema, FilterOrUndefined, @@ -23,7 +22,7 @@ import { SortOrderOrUndefined, } from '../../../common/schemas'; -import { transformSavedObjectsToFoundExceptionList } from './utils'; +import { getSavedObjectTypes, transformSavedObjectsToFoundExceptionList } from './utils'; interface FindExceptionListOptions { namespaceType: NamespaceTypeArray; diff --git a/x-pack/plugins/lists/server/services/exception_lists/find_exception_list_items.ts b/x-pack/plugins/lists/server/services/exception_lists/find_exception_list_items.ts index ef6d5d7ad358b..306a6a19107fc 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/find_exception_list_items.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/find_exception_list_items.ts @@ -5,7 +5,6 @@ */ import { SavedObjectsClientContract } from 'kibana/server'; -import { getSavedObjectTypes } from '../../../common/utils'; import { SavedObjectType } from '../../../common/types'; import { EmptyStringArrayDecoded } from '../../../common/schemas/types/empty_string_array'; import { NamespaceTypeArray } from '../../../common/schemas/types/default_namespace_array'; @@ -19,7 +18,7 @@ import { SortOrderOrUndefined, } from '../../../common/schemas'; -import { transformSavedObjectsToFoundExceptionListItem } from './utils'; +import { getSavedObjectTypes, transformSavedObjectsToFoundExceptionListItem } from './utils'; import { getExceptionList } from './get_exception_list'; interface FindExceptionListItemsOptions { diff --git a/x-pack/plugins/lists/server/services/exception_lists/get_exception_list.ts b/x-pack/plugins/lists/server/services/exception_lists/get_exception_list.ts index c98f861392030..a5c1e2e5c6bc9 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/get_exception_list.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/get_exception_list.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { getSavedObjectType } from '../../../common/utils'; import { SavedObjectsClientContract, SavedObjectsErrorHelpers, @@ -17,7 +16,7 @@ import { NamespaceType, } from '../../../common/schemas'; -import { transformSavedObjectToExceptionList } from './utils'; +import { getSavedObjectType, transformSavedObjectToExceptionList } from './utils'; interface GetExceptionListOptions { id: IdOrUndefined; diff --git a/x-pack/plugins/lists/server/services/exception_lists/get_exception_list_item.ts b/x-pack/plugins/lists/server/services/exception_lists/get_exception_list_item.ts index 98500df6d3ece..d68863c02148f 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/get_exception_list_item.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/get_exception_list_item.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { getSavedObjectType } from '../../../common/utils'; import { SavedObjectsClientContract, SavedObjectsErrorHelpers, @@ -17,7 +16,7 @@ import { NamespaceType, } from '../../../common/schemas'; -import { transformSavedObjectToExceptionListItem } from './utils'; +import { getSavedObjectType, transformSavedObjectToExceptionListItem } from './utils'; interface GetExceptionListItemOptions { id: IdOrUndefined; diff --git a/x-pack/plugins/lists/server/services/exception_lists/update_exception_list.ts b/x-pack/plugins/lists/server/services/exception_lists/update_exception_list.ts index ccd7e289cb79c..a9a666672d7bb 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/update_exception_list.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/update_exception_list.ts @@ -6,7 +6,6 @@ import { SavedObjectsClientContract } from 'kibana/server'; -import { getSavedObjectType } from '../../../common/utils'; import { DescriptionOrUndefined, ExceptionListSchema, @@ -23,7 +22,7 @@ import { _VersionOrUndefined, } from '../../../common/schemas'; -import { transformSavedObjectUpdateToExceptionList } from './utils'; +import { getSavedObjectType, transformSavedObjectUpdateToExceptionList } from './utils'; import { getExceptionList } from './get_exception_list'; interface UpdateExceptionListOptions { diff --git a/x-pack/plugins/lists/server/services/exception_lists/update_exception_list_item.ts b/x-pack/plugins/lists/server/services/exception_lists/update_exception_list_item.ts index 851006ff37053..9c3399b7509a5 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/update_exception_list_item.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/update_exception_list_item.ts @@ -6,7 +6,6 @@ import { SavedObjectsClientContract } from 'kibana/server'; -import { getSavedObjectType } from '../../../common/utils'; import { DescriptionOrUndefined, EntriesArray, @@ -25,6 +24,7 @@ import { } from '../../../common/schemas'; import { + getSavedObjectType, transformSavedObjectUpdateToExceptionListItem, transformUpdateCommentsToComments, } from './utils'; diff --git a/x-pack/plugins/lists/server/services/exception_lists/utils.ts b/x-pack/plugins/lists/server/services/exception_lists/utils.ts index efe994b72c175..53ac48d1ea63e 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/utils.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/utils.ts @@ -6,7 +6,12 @@ import uuid from 'uuid'; import { SavedObject, SavedObjectsFindResponse, SavedObjectsUpdateResponse } from 'kibana/server'; -import { exceptionListAgnosticSavedObjectType } from '../../../common/types'; +import { + SavedObjectType, + exceptionListAgnosticSavedObjectType, + exceptionListSavedObjectType, +} from '../../../common/types'; +import { NamespaceTypeArray } from '../../../common/schemas/types/default_namespace_array'; import { CommentsArray, CreateComment, @@ -22,6 +27,18 @@ import { exceptionListType, } from '../../../common/schemas'; +export const getSavedObjectType = ({ + namespaceType, +}: { + namespaceType: NamespaceType; +}): SavedObjectType => { + if (namespaceType === 'agnostic') { + return exceptionListAgnosticSavedObjectType; + } else { + return exceptionListSavedObjectType; + } +}; + export const getExceptionListType = ({ savedObjectType, }: { @@ -34,6 +51,16 @@ export const getExceptionListType = ({ } }; +export const getSavedObjectTypes = ({ + namespaceType, +}: { + namespaceType: NamespaceTypeArray; +}): SavedObjectType[] => { + return namespaceType.map((singleNamespaceType) => + getSavedObjectType({ namespaceType: singleNamespaceType }) + ); +}; + export const transformSavedObjectToExceptionList = ({ savedObject, }: {