From bbb2e96dd5d0683628be7c4ad3fede2fa462acd8 Mon Sep 17 00:00:00 2001 From: Matthew Kime Date: Mon, 4 Oct 2021 12:05:22 -0500 Subject: [PATCH] [data views] Move data views api from data plugin and into its own (#113497) * initial pass at moving data views into own plugin * require expressions plugin, fix META_FIELDS reference * bundle limits and localization * fix integration test * update plugin list and jest config * type fixes * search fixes * fix localization * fix mocks * fix mocks * fix stub * type fixes * fix import on test file * path fixes * remove shorted dotted from data plugin * more todo removal * eslint fixes * eslint fix * simplify data views server plugin * simplify data views server plugin * simplify data views server plugin * fix imports on api routes * fix imports on api routes * update plugin list * ts fixes * ts fixes * add deprecation notice * fix circular dependency and api integration test * fix circular dependency and api integration test * rename types for better clarity * path fixes * jest.config and tsconfig cleanup Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .github/CODEOWNERS | 1 + .i18nrc.json | 1 + docs/developer/plugin-list.asciidoc | 6 + packages/kbn-optimizer/limits.yml | 1 + src/plugins/data/README.mdx | 9 -- src/plugins/data/common/constants.ts | 9 -- src/plugins/data/common/data_views/index.ts | 21 ---- src/plugins/data/common/index.ts | 70 ++++++++++-- src/plugins/data/common/mocks.ts | 2 +- .../common/search/aggs/param_types/field.ts | 2 +- .../search/expressions/esaggs/esaggs_fn.ts | 2 +- .../search_source/extract_references.ts | 6 +- src/plugins/data/common/stubs.ts | 4 +- src/plugins/data/common/types.ts | 1 - src/plugins/data/kibana.json | 4 +- src/plugins/data/public/data_views/index.ts | 23 +--- src/plugins/data/public/index.ts | 4 +- src/plugins/data/public/plugin.ts | 40 ++----- src/plugins/data/public/stubs.ts | 3 +- src/plugins/data/public/types.ts | 2 + src/plugins/data/server/data_views/index.ts | 10 +- .../data_views/index_patterns_service.ts | 108 ------------------ src/plugins/data/server/data_views/mocks.ts | 6 +- src/plugins/data/server/index.ts | 2 +- src/plugins/data/server/plugin.ts | 22 +--- .../data/server/saved_objects/index.ts | 1 - src/plugins/data/tsconfig.json | 3 +- src/plugins/data_views/README.mdx | 19 +++ .../common}/constants.ts | 11 ++ .../common}/data_view.stub.ts | 4 +- .../__snapshots__/data_view.test.ts.snap | 0 .../__snapshots__/data_views.test.ts.snap | 0 .../common}/data_views/_pattern_cache.ts | 0 .../common}/data_views/data_view.stub.ts | 4 +- .../common}/data_views/data_view.test.ts | 6 +- .../common}/data_views/data_view.ts | 12 +- .../common}/data_views/data_views.test.ts | 2 +- .../common}/data_views/data_views.ts | 22 ++-- .../data_views/ensure_default_data_view.ts | 0 .../common}/data_views/flatten_hit.test.ts | 2 +- .../common}/data_views/flatten_hit.ts | 0 .../common}/data_views/format_hit.ts | 2 +- .../common}/data_views/index.ts | 0 .../errors/data_view_saved_object_conflict.ts | 0 .../common}/errors/duplicate_index_pattern.ts | 0 .../common}/errors/index.ts | 0 .../common}/expressions/index.ts | 0 .../common}/expressions/load_index_pattern.ts | 6 +- .../common}/field.stub.ts | 0 .../data_view_field.test.ts.snap | 0 .../common}/fields/data_view_field.test.ts | 4 +- .../common}/fields/data_view_field.ts | 6 +- .../common}/fields/field_list.ts | 0 .../common}/fields/fields.mocks.ts | 0 .../common}/fields/index.ts | 0 .../common}/fields/types.ts | 2 +- .../common/fields/utils.test.ts} | 2 +- .../common}/fields/utils.ts | 12 ++ src/plugins/data_views/common/index.ts | 62 ++++++++++ .../common}/lib/errors.ts | 2 +- .../common}/lib/get_title.ts | 4 +- .../common}/lib/index.ts | 0 .../common}/lib/types.ts | 0 .../common}/lib/validate_data_view.test.ts | 0 .../common}/lib/validate_data_view.ts | 0 .../data_views => data_views/common}/mocks.ts | 0 src/plugins/data_views/common/stubs.ts | 10 ++ .../data_views => data_views/common}/types.ts | 7 +- .../common}/utils.test.ts | 0 .../data_views => data_views/common}/utils.ts | 4 +- src/plugins/data_views/jest.config.js | 16 +++ src/plugins/data_views/kibana.json | 15 +++ .../public}/data_views/data_view.stub.ts | 10 +- .../data_views_api_client.test.mock.ts | 2 +- .../data_views/data_views_api_client.test.ts | 0 .../data_views/data_views_api_client.ts | 8 +- .../public}/data_views/index.ts | 2 +- .../data_views/redirect_no_index_pattern.tsx | 13 +-- .../public}/expressions/index.ts | 0 .../expressions/load_index_pattern.test.ts | 2 +- .../public}/expressions/load_index_pattern.ts | 11 +- src/plugins/data_views/public/index.ts | 45 ++++++++ src/plugins/data_views/public/plugin.ts | 68 +++++++++++ .../saved_objects_client_wrapper.test.ts | 2 +- .../public}/saved_objects_client_wrapper.ts | 2 +- src/plugins/data_views/public/types.ts | 32 ++++++ .../public}/ui_settings_wrapper.ts | 2 +- .../server}/capabilities_provider.ts | 0 .../server/data_views_service_factory.ts | 50 ++++++++ .../server}/deprecations/index.ts | 0 .../deprecations/scripted_fields.test.ts | 0 .../server}/deprecations/scripted_fields.ts | 10 +- .../data_views => data_views/server}/error.ts | 0 .../server}/expressions/index.ts | 0 .../expressions/load_index_pattern.test.ts | 2 +- .../server}/expressions/load_index_pattern.ts | 16 ++- .../server}/fetcher/index.ts | 0 .../fetcher/index_not_found_exception.json | 21 ++++ .../fetcher/index_patterns_fetcher.test.ts | 2 +- .../server}/fetcher/index_patterns_fetcher.ts | 0 .../server}/fetcher/lib/errors.ts | 0 .../server}/fetcher/lib/es_api.test.js | 0 .../server}/fetcher/lib/es_api.ts | 0 .../__fixtures__/es_field_caps_response.json | 0 .../field_capabilities.test.js | 0 .../field_capabilities/field_capabilities.ts | 0 .../field_caps_response.test.js | 2 +- .../field_capabilities/field_caps_response.ts | 2 +- .../fetcher/lib/field_capabilities/index.ts | 0 .../lib/field_capabilities/overrides.ts | 0 .../should_read_field_from_doc_values.test.ts | 0 .../should_read_field_from_doc_values.ts | 0 .../server}/fetcher/lib/index.ts | 0 .../fetcher/lib/jobs_compatibility.test.js | 0 .../server}/fetcher/lib/jobs_compatibility.ts | 0 .../server}/fetcher/lib/map_capabilities.ts | 0 .../lib/merge_capabilities_with_fields.ts | 0 .../fetcher/lib/resolve_time_pattern.test.js | 0 .../fetcher/lib/resolve_time_pattern.ts | 0 .../lib/time_pattern_to_wildcard.test.ts | 0 .../fetcher/lib/time_pattern_to_wildcard.ts | 0 .../server}/has_user_index_pattern.test.ts | 2 +- .../server}/has_user_index_pattern.ts | 6 +- src/plugins/data_views/server/index.ts | 37 ++++++ .../server}/index_patterns_api_client.ts | 4 +- src/plugins/data_views/server/mocks.ts | 15 +++ src/plugins/data_views/server/plugin.ts | 74 ++++++++++++ ...ter_index_pattern_usage_collection.test.ts | 4 +- ...register_index_pattern_usage_collection.ts | 18 +-- .../server}/routes.ts | 7 +- .../server}/routes/create_index_pattern.ts | 15 ++- .../server}/routes/default_index_pattern.ts | 17 +-- .../server}/routes/delete_index_pattern.ts | 13 ++- .../server}/routes/fields/update_fields.ts | 16 ++- .../server}/routes/get_index_pattern.ts | 13 ++- .../server}/routes/has_user_index_pattern.ts | 13 ++- .../runtime_fields/create_runtime_field.ts | 16 ++- .../runtime_fields/delete_runtime_field.ts | 16 ++- .../runtime_fields/get_runtime_field.ts | 16 ++- .../runtime_fields/put_runtime_field.ts | 16 ++- .../runtime_fields/update_runtime_field.ts | 18 ++- .../scripted_fields/create_scripted_field.ts | 16 ++- .../scripted_fields/delete_scripted_field.ts | 16 ++- .../scripted_fields/get_scripted_field.ts | 16 ++- .../scripted_fields/put_scripted_field.ts | 16 ++- .../scripted_fields/update_scripted_field.ts | 18 ++- .../server}/routes/update_index_pattern.ts | 13 ++- .../server}/routes/util/handle_errors.ts | 0 .../server}/routes/util/schemas.ts | 2 +- .../server/saved_objects/data_views.ts} | 6 +- .../server/saved_objects}/index.ts | 3 +- .../index_pattern_migrations.test.ts | 0 .../saved_objects/index_pattern_migrations.ts | 0 .../saved_objects/migrations/to_v7_12_0.ts} | 14 +-- .../saved_objects_client_wrapper.test.ts | 2 +- .../server}/saved_objects_client_wrapper.ts | 2 +- src/plugins/data_views/server/types.ts | 51 +++++++++ .../server}/ui_settings_wrapper.ts | 2 +- .../data_views => data_views/server}/utils.ts | 6 +- src/plugins/data_views/tsconfig.json | 26 +++++ .../server/services/new_instance_status.ts | 3 +- .../controls_references.ts | 2 +- .../timeseries_references.ts | 2 +- .../deprecations/scripted_fields.ts | 8 +- .../apis/index_patterns/es_errors/errors.js | 2 +- .../components/top_values/top_values.tsx | 2 +- .../utils/saved_search_utils.test.ts | 2 +- .../translations/translations/ja-JP.json | 12 +- .../translations/translations/zh-CN.json | 12 +- 169 files changed, 996 insertions(+), 497 deletions(-) delete mode 100644 src/plugins/data/common/data_views/index.ts delete mode 100644 src/plugins/data/server/data_views/index_patterns_service.ts create mode 100644 src/plugins/data_views/README.mdx rename src/plugins/{data/common/data_views => data_views/common}/constants.ts (81%) rename src/plugins/{data/common/data_views => data_views/common}/data_view.stub.ts (94%) rename src/plugins/{data/common/data_views => data_views/common}/data_views/__snapshots__/data_view.test.ts.snap (100%) rename src/plugins/{data/common/data_views => data_views/common}/data_views/__snapshots__/data_views.test.ts.snap (100%) rename src/plugins/{data/common/data_views => data_views/common}/data_views/_pattern_cache.ts (100%) rename src/plugins/{data/common/data_views => data_views/common}/data_views/data_view.stub.ts (91%) rename src/plugins/{data/common/data_views => data_views/common}/data_views/data_view.test.ts (98%) rename src/plugins/{data/common/data_views => data_views/common}/data_views/data_view.ts (97%) rename src/plugins/{data/common/data_views => data_views/common}/data_views/data_views.test.ts (99%) rename src/plugins/{data/common/data_views => data_views/common}/data_views/data_views.ts (96%) rename src/plugins/{data/common/data_views => data_views/common}/data_views/ensure_default_data_view.ts (100%) rename src/plugins/{data/common/data_views => data_views/common}/data_views/flatten_hit.test.ts (96%) rename src/plugins/{data/common/data_views => data_views/common}/data_views/flatten_hit.ts (100%) rename src/plugins/{data/common/data_views => data_views/common}/data_views/format_hit.ts (97%) rename src/plugins/{data/common/data_views => data_views/common}/data_views/index.ts (100%) rename src/plugins/{data/common/data_views => data_views/common}/errors/data_view_saved_object_conflict.ts (100%) rename src/plugins/{data/common/data_views => data_views/common}/errors/duplicate_index_pattern.ts (100%) rename src/plugins/{data/common/data_views => data_views/common}/errors/index.ts (100%) rename src/plugins/{data/common/data_views => data_views/common}/expressions/index.ts (100%) rename src/plugins/{data/common/data_views => data_views/common}/expressions/load_index_pattern.ts (90%) rename src/plugins/{data/common/data_views => data_views/common}/field.stub.ts (100%) rename src/plugins/{data/common/data_views => data_views/common}/fields/__snapshots__/data_view_field.test.ts.snap (100%) rename src/plugins/{data/common/data_views => data_views/common}/fields/data_view_field.test.ts (97%) rename src/plugins/{data/common/data_views => data_views/common}/fields/data_view_field.ts (97%) rename src/plugins/{data/common/data_views => data_views/common}/fields/field_list.ts (100%) rename src/plugins/{data/common/data_views => data_views/common}/fields/fields.mocks.ts (100%) rename src/plugins/{data/common/data_views => data_views/common}/fields/index.ts (100%) rename src/plugins/{data/common/data_views => data_views/common}/fields/types.ts (95%) rename src/plugins/{data/common/utils/shorten_dotted_string.test.ts => data_views/common/fields/utils.test.ts} (92%) rename src/plugins/{data/common/data_views => data_views/common}/fields/utils.ts (75%) create mode 100644 src/plugins/data_views/common/index.ts rename src/plugins/{data/common/data_views => data_views/common}/lib/errors.ts (93%) rename src/plugins/{data/common/data_views => data_views/common}/lib/get_title.ts (85%) rename src/plugins/{data/common/data_views => data_views/common}/lib/index.ts (100%) rename src/plugins/{data/common/data_views => data_views/common}/lib/types.ts (100%) rename src/plugins/{data/common/data_views => data_views/common}/lib/validate_data_view.test.ts (100%) rename src/plugins/{data/common/data_views => data_views/common}/lib/validate_data_view.ts (100%) rename src/plugins/{data/common/data_views => data_views/common}/mocks.ts (100%) create mode 100644 src/plugins/data_views/common/stubs.ts rename src/plugins/{data/common/data_views => data_views/common}/types.ts (96%) rename src/plugins/{data/common/data_views => data_views/common}/utils.test.ts (100%) rename src/plugins/{data/common/data_views => data_views/common}/utils.ts (89%) create mode 100644 src/plugins/data_views/jest.config.js create mode 100644 src/plugins/data_views/kibana.json rename src/plugins/{data/public/data_views => data_views/public}/data_views/data_view.stub.ts (84%) rename src/plugins/{data/public/data_views => data_views/public}/data_views/data_views_api_client.test.mock.ts (86%) rename src/plugins/{data/public/data_views => data_views/public}/data_views/data_views_api_client.test.ts (100%) rename src/plugins/{data/public/data_views => data_views/public}/data_views/data_views_api_client.ts (90%) rename src/plugins/{data/public/data_views => data_views/public}/data_views/index.ts (88%) rename src/plugins/{data/public/data_views => data_views/public}/data_views/redirect_no_index_pattern.tsx (84%) rename src/plugins/{data/public/data_views => data_views/public}/expressions/index.ts (100%) rename src/plugins/{data/public/data_views => data_views/public}/expressions/load_index_pattern.test.ts (92%) rename src/plugins/{data/public/data_views => data_views/public}/expressions/load_index_pattern.ts (88%) create mode 100644 src/plugins/data_views/public/index.ts create mode 100644 src/plugins/data_views/public/plugin.ts rename src/plugins/{data/public/data_views => data_views/public}/saved_objects_client_wrapper.test.ts (96%) rename src/plugins/{data/public/data_views => data_views/public}/saved_objects_client_wrapper.ts (98%) create mode 100644 src/plugins/data_views/public/types.ts rename src/plugins/{data/public/data_views => data_views/public}/ui_settings_wrapper.ts (95%) rename src/plugins/{data/server/data_views => data_views/server}/capabilities_provider.ts (100%) create mode 100644 src/plugins/data_views/server/data_views_service_factory.ts rename src/plugins/{data/server/data_views => data_views/server}/deprecations/index.ts (100%) rename src/plugins/{data/server/data_views => data_views/server}/deprecations/scripted_fields.test.ts (100%) rename src/plugins/{data/server/data_views => data_views/server}/deprecations/scripted_fields.ts (89%) rename src/plugins/{data/server/data_views => data_views/server}/error.ts (100%) rename src/plugins/{data/server/data_views => data_views/server}/expressions/index.ts (100%) rename src/plugins/{data/server/data_views => data_views/server}/expressions/load_index_pattern.test.ts (94%) rename src/plugins/{data/server/data_views => data_views/server}/expressions/load_index_pattern.ts (85%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/index.ts (100%) create mode 100644 src/plugins/data_views/server/fetcher/index_not_found_exception.json rename src/plugins/{data/server/data_views => data_views/server}/fetcher/index_patterns_fetcher.test.ts (95%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/index_patterns_fetcher.ts (100%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/lib/errors.ts (100%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/lib/es_api.test.js (100%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/lib/es_api.ts (100%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/lib/field_capabilities/__fixtures__/es_field_caps_response.json (100%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/lib/field_capabilities/field_capabilities.test.js (100%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/lib/field_capabilities/field_capabilities.ts (100%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/lib/field_capabilities/field_caps_response.test.js (99%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/lib/field_capabilities/field_caps_response.ts (98%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/lib/field_capabilities/index.ts (100%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/lib/field_capabilities/overrides.ts (100%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/lib/field_capabilities/should_read_field_from_doc_values.test.ts (100%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/lib/field_capabilities/should_read_field_from_doc_values.ts (100%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/lib/index.ts (100%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/lib/jobs_compatibility.test.js (100%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/lib/jobs_compatibility.ts (100%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/lib/map_capabilities.ts (100%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/lib/merge_capabilities_with_fields.ts (100%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/lib/resolve_time_pattern.test.js (100%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/lib/resolve_time_pattern.ts (100%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/lib/time_pattern_to_wildcard.test.ts (100%) rename src/plugins/{data/server/data_views => data_views/server}/fetcher/lib/time_pattern_to_wildcard.ts (100%) rename src/plugins/{data/server/data_views => data_views/server}/has_user_index_pattern.test.ts (99%) rename src/plugins/{data/server/data_views => data_views/server}/has_user_index_pattern.ts (91%) create mode 100644 src/plugins/data_views/server/index.ts rename src/plugins/{data/server/data_views => data_views/server}/index_patterns_api_client.ts (94%) create mode 100644 src/plugins/data_views/server/mocks.ts create mode 100644 src/plugins/data_views/server/plugin.ts rename src/plugins/{data/server/data_views => data_views/server}/register_index_pattern_usage_collection.test.ts (98%) rename src/plugins/{data/server/data_views => data_views/server}/register_index_pattern_usage_collection.ts (90%) rename src/plugins/{data/server/data_views => data_views/server}/routes.ts (96%) rename src/plugins/{data/server/data_views => data_views/server}/routes/create_index_pattern.ts (84%) rename src/plugins/{data/server/data_views => data_views/server}/routes/default_index_pattern.ts (76%) rename src/plugins/{data/server/data_views => data_views/server}/routes/delete_index_pattern.ts (75%) rename src/plugins/{data/server/data_views => data_views/server}/routes/fields/update_fields.ts (87%) rename src/plugins/{data/server/data_views => data_views/server}/routes/get_index_pattern.ts (76%) rename src/plugins/{data/server/data_views => data_views/server}/routes/has_user_index_pattern.ts (69%) rename src/plugins/{data/server/data_views => data_views/server}/routes/runtime_fields/create_runtime_field.ts (82%) rename src/plugins/{data/server/data_views => data_views/server}/routes/runtime_fields/delete_runtime_field.ts (79%) rename src/plugins/{data/server/data_views => data_views/server}/routes/runtime_fields/get_runtime_field.ts (79%) rename src/plugins/{data/server/data_views => data_views/server}/routes/runtime_fields/put_runtime_field.ts (82%) rename src/plugins/{data/server/data_views => data_views/server}/routes/runtime_fields/update_runtime_field.ts (83%) rename src/plugins/{data/server/data_views => data_views/server}/routes/scripted_fields/create_scripted_field.ts (83%) rename src/plugins/{data/server/data_views => data_views/server}/routes/scripted_fields/delete_scripted_field.ts (81%) rename src/plugins/{data/server/data_views => data_views/server}/routes/scripted_fields/get_scripted_field.ts (81%) rename src/plugins/{data/server/data_views => data_views/server}/routes/scripted_fields/put_scripted_field.ts (83%) rename src/plugins/{data/server/data_views => data_views/server}/routes/scripted_fields/update_scripted_field.ts (86%) rename src/plugins/{data/server/data_views => data_views/server}/routes/update_index_pattern.ts (91%) rename src/plugins/{data/server/data_views => data_views/server}/routes/util/handle_errors.ts (100%) rename src/plugins/{data/server/data_views => data_views/server}/routes/util/schemas.ts (96%) rename src/plugins/{data/server/saved_objects/index_patterns.ts => data_views/server/saved_objects/data_views.ts} (88%) rename src/plugins/{data/common/utils => data_views/server/saved_objects}/index.ts (81%) rename src/plugins/{data => data_views}/server/saved_objects/index_pattern_migrations.test.ts (100%) rename src/plugins/{data => data_views}/server/saved_objects/index_pattern_migrations.ts (100%) rename src/plugins/{data/common/utils/shorten_dotted_string.ts => data_views/server/saved_objects/migrations/to_v7_12_0.ts} (57%) rename src/plugins/{data/server/data_views => data_views/server}/saved_objects_client_wrapper.test.ts (96%) rename src/plugins/{data/server/data_views => data_views/server}/saved_objects_client_wrapper.ts (98%) create mode 100644 src/plugins/data_views/server/types.ts rename src/plugins/{data/server/data_views => data_views/server}/ui_settings_wrapper.ts (95%) rename src/plugins/{data/server/data_views => data_views/server}/utils.ts (92%) create mode 100644 src/plugins/data_views/tsconfig.json diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 90f88de7d1104..9aa308c0dc58d 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -62,6 +62,7 @@ /packages/kbn-interpreter/ @elastic/kibana-app-services /src/plugins/bfetch/ @elastic/kibana-app-services /src/plugins/data/ @elastic/kibana-app-services +/src/plugins/data-views/ @elastic/kibana-app-services /src/plugins/embeddable/ @elastic/kibana-app-services /src/plugins/expressions/ @elastic/kibana-app-services /src/plugins/field_formats/ @elastic/kibana-app-services diff --git a/.i18nrc.json b/.i18nrc.json index 4107772e421ca..45016edc38dcd 100644 --- a/.i18nrc.json +++ b/.i18nrc.json @@ -9,6 +9,7 @@ "bfetch": "src/plugins/bfetch", "dashboard": "src/plugins/dashboard", "data": "src/plugins/data", + "dataViews": "src/plugins/data_views", "embeddableApi": "src/plugins/embeddable", "embeddableExamples": "examples/embeddable_examples", "fieldFormats": "src/plugins/field_formats", diff --git a/docs/developer/plugin-list.asciidoc b/docs/developer/plugin-list.asciidoc index edc1821f3b223..7f7041f7815cd 100644 --- a/docs/developer/plugin-list.asciidoc +++ b/docs/developer/plugin-list.asciidoc @@ -57,6 +57,12 @@ as uiSettings within the code. |The data plugin provides common data access services, such as search and query, for solutions and application developers. +|{kib-repo}blob/{branch}/src/plugins/data_views/README.mdx[dataViews] +|The data views API provides a consistent method of structuring and formatting documents +and field lists across the various Kibana apps. Its typically used in conjunction with + for composing queries. + + |{kib-repo}blob/{branch}/src/plugins/dev_tools/README.md[devTools] |The ui/registry/dev_tools is removed in favor of the devTools plugin which exposes a register method in the setup contract. Registering app works mostly the same as registering apps in core.application.register. diff --git a/packages/kbn-optimizer/limits.yml b/packages/kbn-optimizer/limits.yml index 8fb31b36f39d5..a0ca88e4e04bd 100644 --- a/packages/kbn-optimizer/limits.yml +++ b/packages/kbn-optimizer/limits.yml @@ -116,3 +116,4 @@ pageLoadAssetSize: expressions: 239290 securitySolution: 231753 customIntegrations: 28810 + dataViews: 42000 diff --git a/src/plugins/data/README.mdx b/src/plugins/data/README.mdx index 40e82d3034ee2..18b755275b4aa 100644 --- a/src/plugins/data/README.mdx +++ b/src/plugins/data/README.mdx @@ -49,15 +49,6 @@ This is helpful when you want to provide a user with options, for example when c ``` -## Data Views - -The data views API provides a consistent method of structuring and formatting documents -and field lists across the various Kibana apps. Its typically used in conjunction with - for composing queries. - -*Note: Kibana index patterns are currently being renamed to data views. There will be some naming inconsistencies until the transition is complete.* - - ## Query The query service is responsible for managing the configuration of a search query (`QueryState`): filters, time range, query string, and settings such as the auto refresh behavior and saved queries. diff --git a/src/plugins/data/common/constants.ts b/src/plugins/data/common/constants.ts index 2c339d1408237..c236be18a8e41 100644 --- a/src/plugins/data/common/constants.ts +++ b/src/plugins/data/common/constants.ts @@ -9,15 +9,6 @@ export const DEFAULT_QUERY_LANGUAGE = 'kuery'; export const KIBANA_USER_QUERY_LANGUAGE_KEY = 'kibana.userQueryLanguage'; -/** @public **/ -export const DATA_VIEW_SAVED_OBJECT_TYPE = 'index-pattern'; - -/** - * @deprecated Use DATA_VIEW_SAVED_OBJECT_TYPE. All index pattern interfaces were renamed. - */ - -export const INDEX_PATTERN_SAVED_OBJECT_TYPE = DATA_VIEW_SAVED_OBJECT_TYPE; - export type ValueSuggestionsMethod = 'terms_enum' | 'terms_agg'; export const UI_SETTINGS = { diff --git a/src/plugins/data/common/data_views/index.ts b/src/plugins/data/common/data_views/index.ts deleted file mode 100644 index fd1df0336815a..0000000000000 --- a/src/plugins/data/common/data_views/index.ts +++ /dev/null @@ -1,21 +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 - * 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. - */ - -export * from './constants'; -export * from './fields'; -export * from './types'; -export { - IndexPatternsService, - IndexPatternsContract, - DataViewsService, - DataViewsContract, -} from './data_views'; -// todo was trying to export this as type but wasn't working -export { IndexPattern, IndexPatternListItem, DataView, DataViewListItem } from './data_views'; -export * from './errors'; -export * from './expressions'; diff --git a/src/plugins/data/common/index.ts b/src/plugins/data/common/index.ts index 8a9a93f96b68b..195cb9d475314 100644 --- a/src/plugins/data/common/index.ts +++ b/src/plugins/data/common/index.ts @@ -11,18 +11,68 @@ export * from './constants'; export * from './es_query'; -export * from './data_views'; export * from './kbn_field_types'; export * from './query'; export * from './search'; export * from './types'; -export * from './utils'; export * from './exports'; - -/** - * - * @deprecated Use data plugin interface instead - * @removeBy 8.1 - */ - -export { IndexPatternAttributes } from './types'; +export type { + IFieldType, + IIndexPatternFieldList, + FieldFormatMap, + RuntimeType, + RuntimeField, + IIndexPattern, + DataViewAttributes, + IndexPatternAttributes, + FieldAttrs, + FieldAttrSet, + OnNotification, + OnError, + UiSettingsCommon, + SavedObjectsClientCommonFindArgs, + SavedObjectsClientCommon, + GetFieldsOptions, + GetFieldsOptionsTimePattern, + IDataViewsApiClient, + IIndexPatternsApiClient, + SavedObject, + AggregationRestrictions, + TypeMeta, + FieldSpecConflictDescriptions, + FieldSpecExportFmt, + FieldSpec, + DataViewFieldMap, + IndexPatternFieldMap, + DataViewSpec, + IndexPatternSpec, + SourceFilter, + IndexPatternExpressionType, + IndexPatternLoadStartDependencies, + IndexPatternLoadExpressionFunctionDefinition, +} from '../../data_views/common'; +export { + RUNTIME_FIELD_TYPES, + FLEET_ASSETS_TO_IGNORE, + META_FIELDS, + DATA_VIEW_SAVED_OBJECT_TYPE, + INDEX_PATTERN_SAVED_OBJECT_TYPE, + isFilterable, + isNestedField, + fieldList, + DataViewField, + IndexPatternField, + DataViewType, + IndexPatternType, + IndexPatternsService, + IndexPatternsContract, + DataViewsService, + DataViewsContract, + IndexPattern, + IndexPatternListItem, + DataView, + DataViewListItem, + DuplicateDataViewError, + DataViewSavedObjectConflictError, + getIndexPatternLoadMeta, +} from '../../data_views/common'; diff --git a/src/plugins/data/common/mocks.ts b/src/plugins/data/common/mocks.ts index 66ad3b695d24c..c656d9d21346e 100644 --- a/src/plugins/data/common/mocks.ts +++ b/src/plugins/data/common/mocks.ts @@ -6,4 +6,4 @@ * Side Public License, v 1. */ -export * from './data_views/fields/fields.mocks'; +export * from '../../data_views/common/fields/fields.mocks'; diff --git a/src/plugins/data/common/search/aggs/param_types/field.ts b/src/plugins/data/common/search/aggs/param_types/field.ts index e1c872ac16701..05e1302475d04 100644 --- a/src/plugins/data/common/search/aggs/param_types/field.ts +++ b/src/plugins/data/common/search/aggs/param_types/field.ts @@ -15,7 +15,7 @@ import { import { BaseParamType } from './base'; import { propFilter } from '../utils'; import { KBN_FIELD_TYPES } from '../../../kbn_field_types/types'; -import { isNestedField, IndexPatternField } from '../../../data_views/fields'; +import { isNestedField, IndexPatternField } from '../../../../../data_views/common'; const filterByType = propFilter('type'); diff --git a/src/plugins/data/common/search/expressions/esaggs/esaggs_fn.ts b/src/plugins/data/common/search/expressions/esaggs/esaggs_fn.ts index a9078d6042db8..09d68177c3ec3 100644 --- a/src/plugins/data/common/search/expressions/esaggs/esaggs_fn.ts +++ b/src/plugins/data/common/search/expressions/esaggs/esaggs_fn.ts @@ -12,7 +12,7 @@ import { Observable } from 'rxjs'; import type { Datatable, ExpressionFunctionDefinition } from 'src/plugins/expressions/common'; import { buildExpressionFunction } from '../../../../../../plugins/expressions/common'; -import { IndexPatternExpressionType } from '../../../data_views/expressions'; +import { IndexPatternExpressionType } from '../../../../../data_views/common/expressions'; import { IndexPatternsContract } from '../../..'; import { AggsStart, AggExpressionType, aggCountFnName } from '../../aggs'; diff --git a/src/plugins/data/common/search/search_source/extract_references.ts b/src/plugins/data/common/search/search_source/extract_references.ts index c7f6c53d0f5f7..dfcd1b12cb62f 100644 --- a/src/plugins/data/common/search/search_source/extract_references.ts +++ b/src/plugins/data/common/search/search_source/extract_references.ts @@ -10,7 +10,7 @@ import { SavedObjectReference } from 'src/core/types'; import { Filter } from '@kbn/es-query'; import { SearchSourceFields } from './types'; -import { INDEX_PATTERN_SAVED_OBJECT_TYPE } from '../../constants'; +import { DATA_VIEW_SAVED_OBJECT_TYPE } from '../../../../data/common'; export const extractReferences = ( state: SearchSourceFields @@ -22,7 +22,7 @@ export const extractReferences = ( const refName = 'kibanaSavedObjectMeta.searchSourceJSON.index'; references.push({ name: refName, - type: INDEX_PATTERN_SAVED_OBJECT_TYPE, + type: DATA_VIEW_SAVED_OBJECT_TYPE, id: indexId, }); searchSourceFields = { @@ -42,7 +42,7 @@ export const extractReferences = ( const refName = `kibanaSavedObjectMeta.searchSourceJSON.filter[${i}].meta.index`; references.push({ name: refName, - type: INDEX_PATTERN_SAVED_OBJECT_TYPE, + type: DATA_VIEW_SAVED_OBJECT_TYPE, id: filterRow.meta.index, }); return { diff --git a/src/plugins/data/common/stubs.ts b/src/plugins/data/common/stubs.ts index 5cddcf397f442..ec53b20f6ff3d 100644 --- a/src/plugins/data/common/stubs.ts +++ b/src/plugins/data/common/stubs.ts @@ -6,6 +6,6 @@ * Side Public License, v 1. */ -export * from './data_views/field.stub'; -export * from './data_views/data_view.stub'; +export * from '../../data_views/common/field.stub'; +export * from '../../data_views/common/data_view.stub'; export * from './es_query/stubs'; diff --git a/src/plugins/data/common/types.ts b/src/plugins/data/common/types.ts index c574d4854cfd6..81b47735d8fe2 100644 --- a/src/plugins/data/common/types.ts +++ b/src/plugins/data/common/types.ts @@ -8,7 +8,6 @@ export * from './query/types'; export * from './kbn_field_types/types'; -export * from './data_views/types'; /** * If a service is being shared on both the client and the server, and diff --git a/src/plugins/data/kibana.json b/src/plugins/data/kibana.json index c21955501787d..3d70d138d80ed 100644 --- a/src/plugins/data/kibana.json +++ b/src/plugins/data/kibana.json @@ -3,8 +3,8 @@ "version": "kibana", "server": true, "ui": true, - "requiredPlugins": ["bfetch", "expressions", "uiActions", "share", "inspector", "fieldFormats"], - "serviceFolders": ["search", "data_views", "query", "autocomplete", "ui"], + "requiredPlugins": ["bfetch", "expressions", "uiActions", "share", "inspector", "fieldFormats", "dataViews"], + "serviceFolders": ["search", "query", "autocomplete", "ui"], "optionalPlugins": ["usageCollection"], "extraPublicDirs": ["common"], "requiredBundles": ["kibanaUtils", "kibanaReact", "inspector"], diff --git a/src/plugins/data/public/data_views/index.ts b/src/plugins/data/public/data_views/index.ts index 0125b173989fb..4fb2bbaf08503 100644 --- a/src/plugins/data/public/data_views/index.ts +++ b/src/plugins/data/public/data_views/index.ts @@ -6,25 +6,4 @@ * Side Public License, v 1. */ -export { - ILLEGAL_CHARACTERS_KEY, - CONTAINS_SPACES_KEY, - ILLEGAL_CHARACTERS_VISIBLE, - ILLEGAL_CHARACTERS, - validateDataView, -} from '../../common/data_views/lib'; -export { flattenHitWrapper, formatHitProvider, onRedirectNoIndexPattern } from './data_views'; - -export { IndexPatternField, IIndexPatternFieldList, TypeMeta } from '../../common/data_views'; - -export { - IndexPatternsService, - IndexPatternsContract, - IndexPattern, - DataViewsApiClient, - DataViewsService, - DataViewsContract, - DataView, -} from './data_views'; -export { UiSettingsPublicToCommon } from './ui_settings_wrapper'; -export { SavedObjectsClientPublicToCommon } from './saved_objects_client_wrapper'; +export * from '../../../data_views/public'; diff --git a/src/plugins/data/public/index.ts b/src/plugins/data/public/index.ts index e1f5b98baca9c..4b6d184f807a4 100644 --- a/src/plugins/data/public/index.ts +++ b/src/plugins/data/public/index.ts @@ -83,14 +83,12 @@ export { IndexPatternLoadExpressionFunctionDefinition, fieldList, GetFieldsOptions, - INDEX_PATTERN_SAVED_OBJECT_TYPE, AggregationRestrictions, IndexPatternType, IndexPatternListItem, + DuplicateDataViewError, } from '../common'; -export { DuplicateDataViewError } from '../common/data_views/errors'; - /* * Autocomplete query suggestions: */ diff --git a/src/plugins/data/public/plugin.ts b/src/plugins/data/public/plugin.ts index aa766f78a5ecb..4a55cc2a0d511 100644 --- a/src/plugins/data/public/plugin.ts +++ b/src/plugins/data/public/plugin.ts @@ -21,12 +21,6 @@ import { AutocompleteService } from './autocomplete'; import { SearchService } from './search/search_service'; import { QueryService } from './query'; import { createIndexPatternSelect } from './ui/index_pattern_select'; -import { - DataViewsService, - onRedirectNoIndexPattern, - DataViewsApiClient, - UiSettingsPublicToCommon, -} from './data_views'; import { setIndexPatterns, setNotifications, @@ -44,8 +38,6 @@ import { createSelectRangeAction, } from './actions'; import { APPLY_FILTER_TRIGGER, applyFilterTrigger } from './triggers'; -import { SavedObjectsClientPublicToCommon } from './data_views'; -import { getIndexPatternLoad } from './data_views/expressions'; import { UsageCollectionSetup } from '../../usage_collection/public'; import { getTableViewDescription } from './utils/table_inspector_view'; import { NowProvider, NowProviderInternalContract } from './now_provider'; @@ -89,8 +81,6 @@ export class DataPublicPlugin ): DataPublicPluginSetup { const startServices = createStartServicesGetter(core.getStartServices); - expressions.registerFunction(getIndexPatternLoad({ getStartServices: core.getStartServices })); - this.usageCollection = usageCollection; const searchService = this.searchService.setup(core, { @@ -138,29 +128,13 @@ export class DataPublicPlugin public start( core: CoreStart, - { uiActions, fieldFormats }: DataStartDependencies + { uiActions, fieldFormats, dataViews }: DataStartDependencies ): DataPublicPluginStart { - const { uiSettings, http, notifications, savedObjects, overlays, application } = core; + const { uiSettings, notifications, savedObjects, overlays } = core; setNotifications(notifications); setOverlays(overlays); setUiSettings(uiSettings); - - const indexPatterns = new DataViewsService({ - uiSettings: new UiSettingsPublicToCommon(uiSettings), - savedObjectsClient: new SavedObjectsClientPublicToCommon(savedObjects.client), - apiClient: new DataViewsApiClient(http), - fieldFormats, - onNotification: (toastInputFields) => { - notifications.toasts.add(toastInputFields); - }, - onError: notifications.toasts.addError.bind(notifications.toasts), - onRedirectNoIndexPattern: onRedirectNoIndexPattern( - application.capabilities, - application.navigateToApp, - overlays - ), - }); - setIndexPatterns(indexPatterns); + setIndexPatterns(dataViews); const query = this.queryService.start({ storage: this.storage, @@ -168,7 +142,7 @@ export class DataPublicPlugin uiSettings, }); - const search = this.searchService.start(core, { fieldFormats, indexPatterns }); + const search = this.searchService.start(core, { fieldFormats, indexPatterns: dataViews }); setSearchService(search); uiActions.addTriggerAction( @@ -197,8 +171,8 @@ export class DataPublicPlugin }, autocomplete: this.autocomplete.start(), fieldFormats, - indexPatterns, - dataViews: indexPatterns, + indexPatterns: dataViews, + dataViews, query, search, nowProvider: this.nowProvider, @@ -214,7 +188,7 @@ export class DataPublicPlugin return { ...dataServices, ui: { - IndexPatternSelect: createIndexPatternSelect(indexPatterns), + IndexPatternSelect: createIndexPatternSelect(dataViews), SearchBar, }, }; diff --git a/src/plugins/data/public/stubs.ts b/src/plugins/data/public/stubs.ts index 3d160a56bd8cf..b81d9c4cc78e4 100644 --- a/src/plugins/data/public/stubs.ts +++ b/src/plugins/data/public/stubs.ts @@ -7,4 +7,5 @@ */ export * from '../common/stubs'; -export { createStubDataView } from './data_views/data_views/data_view.stub'; +// eslint-disable-next-line +export { createStubDataView } from '../../data_views/public/data_views/data_view.stub'; diff --git a/src/plugins/data/public/types.ts b/src/plugins/data/public/types.ts index 7ed13c2096515..9b16ee39f5c80 100644 --- a/src/plugins/data/public/types.ts +++ b/src/plugins/data/public/types.ts @@ -11,6 +11,7 @@ import { CoreStart } from 'src/core/public'; import { BfetchPublicSetup } from 'src/plugins/bfetch/public'; import { IStorageWrapper } from 'src/plugins/kibana_utils/public'; import { ExpressionsSetup } from 'src/plugins/expressions/public'; +import { DataViewsPublicPluginStart } from 'src/plugins/data_views/public'; import { UiActionsSetup, UiActionsStart } from 'src/plugins/ui_actions/public'; import { FieldFormatsSetup, FieldFormatsStart } from 'src/plugins/field_formats/public'; import { AutocompleteSetup, AutocompleteStart } from './autocomplete'; @@ -35,6 +36,7 @@ export interface DataSetupDependencies { export interface DataStartDependencies { uiActions: UiActionsStart; fieldFormats: FieldFormatsStart; + dataViews: DataViewsPublicPluginStart; } /** diff --git a/src/plugins/data/server/data_views/index.ts b/src/plugins/data/server/data_views/index.ts index 7226d6f015cf8..91a61f4bcb7db 100644 --- a/src/plugins/data/server/data_views/index.ts +++ b/src/plugins/data/server/data_views/index.ts @@ -6,12 +6,4 @@ * Side Public License, v 1. */ -export * from './utils'; -export { - IndexPatternsFetcher, - FieldDescriptor, - shouldReadFieldFromDocValues, - mergeCapabilitiesWithFields, - getCapabilitiesForRollupIndices, -} from './fetcher'; -export { IndexPatternsServiceProvider, IndexPatternsServiceStart } from './index_patterns_service'; +export * from '../../../data_views/server'; diff --git a/src/plugins/data/server/data_views/index_patterns_service.ts b/src/plugins/data/server/data_views/index_patterns_service.ts deleted file mode 100644 index 5286d1d64794b..0000000000000 --- a/src/plugins/data/server/data_views/index_patterns_service.ts +++ /dev/null @@ -1,108 +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 - * 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. - */ - -import { - CoreSetup, - CoreStart, - Plugin, - Logger, - SavedObjectsClientContract, - ElasticsearchClient, - UiSettingsServiceStart, -} from 'kibana/server'; -import { ExpressionsServerSetup } from 'src/plugins/expressions/server'; -import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; -import { DataPluginStart } from '../plugin'; -import { registerRoutes } from './routes'; -import { indexPatternSavedObjectType } from '../saved_objects'; -import { capabilitiesProvider } from './capabilities_provider'; -import { IndexPatternsCommonService } from '../'; -import { FieldFormatsStart } from '../../../field_formats/server'; -import { getIndexPatternLoad } from './expressions'; -import { UiSettingsServerToCommon } from './ui_settings_wrapper'; -import { IndexPatternsApiServer } from './index_patterns_api_client'; -import { SavedObjectsClientServerToCommon } from './saved_objects_client_wrapper'; -import { registerIndexPatternsUsageCollector } from './register_index_pattern_usage_collection'; -import { createScriptedFieldsDeprecationsConfig } from './deprecations'; - -export interface IndexPatternsServiceStart { - indexPatternsServiceFactory: ( - savedObjectsClient: SavedObjectsClientContract, - elasticsearchClient: ElasticsearchClient - ) => Promise; -} - -export interface IndexPatternsServiceSetupDeps { - expressions: ExpressionsServerSetup; - logger: Logger; - usageCollection?: UsageCollectionSetup; -} - -export interface IndexPatternsServiceStartDeps { - fieldFormats: FieldFormatsStart; - logger: Logger; -} - -export const indexPatternsServiceFactory = - ({ - logger, - uiSettings, - fieldFormats, - }: { - logger: Logger; - uiSettings: UiSettingsServiceStart; - fieldFormats: FieldFormatsStart; - }) => - async ( - savedObjectsClient: SavedObjectsClientContract, - elasticsearchClient: ElasticsearchClient - ) => { - const uiSettingsClient = uiSettings.asScopedToClient(savedObjectsClient); - const formats = await fieldFormats.fieldFormatServiceFactory(uiSettingsClient); - - return new IndexPatternsCommonService({ - uiSettings: new UiSettingsServerToCommon(uiSettingsClient), - savedObjectsClient: new SavedObjectsClientServerToCommon(savedObjectsClient), - apiClient: new IndexPatternsApiServer(elasticsearchClient, savedObjectsClient), - fieldFormats: formats, - onError: (error) => { - logger.error(error); - }, - onNotification: ({ title, text }) => { - logger.warn(`${title}${text ? ` : ${text}` : ''}`); - }, - }); - }; - -export class IndexPatternsServiceProvider implements Plugin { - public setup( - core: CoreSetup, - { expressions, usageCollection }: IndexPatternsServiceSetupDeps - ) { - core.savedObjects.registerType(indexPatternSavedObjectType); - core.capabilities.registerProvider(capabilitiesProvider); - - registerRoutes(core.http, core.getStartServices); - - expressions.registerFunction(getIndexPatternLoad({ getStartServices: core.getStartServices })); - registerIndexPatternsUsageCollector(core.getStartServices, usageCollection); - core.deprecations.registerDeprecations(createScriptedFieldsDeprecationsConfig(core)); - } - - public start(core: CoreStart, { fieldFormats, logger }: IndexPatternsServiceStartDeps) { - const { uiSettings } = core; - - return { - indexPatternsServiceFactory: indexPatternsServiceFactory({ - logger, - uiSettings, - fieldFormats, - }), - }; - } -} diff --git a/src/plugins/data/server/data_views/mocks.ts b/src/plugins/data/server/data_views/mocks.ts index 6435c09cb7ec9..69b57ed079127 100644 --- a/src/plugins/data/server/data_views/mocks.ts +++ b/src/plugins/data/server/data_views/mocks.ts @@ -6,8 +6,4 @@ * Side Public License, v 1. */ -export function createIndexPatternsStartMock() { - return { - indexPatternsServiceFactory: jest.fn().mockResolvedValue({ get: jest.fn() }), - }; -} +export * from '../../../data_views/server/mocks'; diff --git a/src/plugins/data/server/index.ts b/src/plugins/data/server/index.ts index a17c66c694b2d..fce73e65dc699 100644 --- a/src/plugins/data/server/index.ts +++ b/src/plugins/data/server/index.ts @@ -30,7 +30,7 @@ export const exporters = { * Field Formats: */ -export { INDEX_PATTERN_SAVED_OBJECT_TYPE } from '../common'; +export { DATA_VIEW_SAVED_OBJECT_TYPE } from '../common'; /* * Index patterns: diff --git a/src/plugins/data/server/plugin.ts b/src/plugins/data/server/plugin.ts index 3342519782d7a..cb52500e78f94 100644 --- a/src/plugins/data/server/plugin.ts +++ b/src/plugins/data/server/plugin.ts @@ -9,8 +9,8 @@ import { CoreSetup, CoreStart, Logger, Plugin, PluginInitializerContext } from 'src/core/server'; import { ExpressionsServerSetup } from 'src/plugins/expressions/server'; import { BfetchServerSetup } from 'src/plugins/bfetch/server'; +import { PluginStart as DataViewsServerPluginStart } from 'src/plugins/data_views/server'; import { ConfigSchema } from '../config'; -import { IndexPatternsServiceProvider, IndexPatternsServiceStart } from './data_views'; import { ISearchSetup, ISearchStart, SearchEnhancements } from './search'; import { SearchService } from './search/search_service'; import { QueryService } from './query/query_service'; @@ -43,7 +43,7 @@ export interface DataPluginStart { * @deprecated - use "fieldFormats" plugin directly instead */ fieldFormats: FieldFormatsStart; - indexPatterns: IndexPatternsServiceStart; + indexPatterns: DataViewsServerPluginStart; } export interface DataPluginSetupDependencies { @@ -56,6 +56,7 @@ export interface DataPluginSetupDependencies { export interface DataPluginStartDependencies { fieldFormats: FieldFormatsStart; logger: Logger; + dataViews: DataViewsServerPluginStart; } export class DataServerPlugin @@ -71,7 +72,6 @@ export class DataServerPlugin private readonly scriptsService: ScriptsService; private readonly kqlTelemetryService: KqlTelemetryService; private readonly autocompleteService: AutocompleteService; - private readonly indexPatterns = new IndexPatternsServiceProvider(); private readonly queryService = new QueryService(); private readonly logger: Logger; @@ -91,11 +91,6 @@ export class DataServerPlugin this.queryService.setup(core); this.autocompleteService.setup(core); this.kqlTelemetryService.setup(core, { usageCollection }); - this.indexPatterns.setup(core, { - expressions, - logger: this.logger.get('indexPatterns'), - usageCollection, - }); core.uiSettings.register(getUiSettings()); @@ -114,16 +109,11 @@ export class DataServerPlugin }; } - public start(core: CoreStart, { fieldFormats }: DataPluginStartDependencies) { - const indexPatterns = this.indexPatterns.start(core, { - fieldFormats, - logger: this.logger.get('indexPatterns'), - }); - + public start(core: CoreStart, { fieldFormats, dataViews }: DataPluginStartDependencies) { return { fieldFormats, - indexPatterns, - search: this.searchService.start(core, { fieldFormats, indexPatterns }), + indexPatterns: dataViews, + search: this.searchService.start(core, { fieldFormats, indexPatterns: dataViews }), }; } diff --git a/src/plugins/data/server/saved_objects/index.ts b/src/plugins/data/server/saved_objects/index.ts index 53d4360782b5b..8bfce1a4d3696 100644 --- a/src/plugins/data/server/saved_objects/index.ts +++ b/src/plugins/data/server/saved_objects/index.ts @@ -7,6 +7,5 @@ */ export { querySavedObjectType } from './query'; -export { indexPatternSavedObjectType } from './index_patterns'; export { kqlTelemetry } from './kql_telemetry'; export { searchTelemetry } from './search_telemetry'; diff --git a/src/plugins/data/tsconfig.json b/src/plugins/data/tsconfig.json index 3687604e05e2b..92f80f47eca64 100644 --- a/src/plugins/data/tsconfig.json +++ b/src/plugins/data/tsconfig.json @@ -23,6 +23,7 @@ { "path": "../usage_collection/tsconfig.json" }, { "path": "../kibana_utils/tsconfig.json" }, { "path": "../kibana_react/tsconfig.json" }, - { "path": "../field_formats/tsconfig.json" } + { "path": "../field_formats/tsconfig.json" }, + { "path": "../data_views/tsconfig.json" } ] } diff --git a/src/plugins/data_views/README.mdx b/src/plugins/data_views/README.mdx new file mode 100644 index 0000000000000..90efdc18d8fdb --- /dev/null +++ b/src/plugins/data_views/README.mdx @@ -0,0 +1,19 @@ +--- +id: kibDataPlugin +slug: /kibana-dev-docs/services/data-plugin +title: Data services +image: https://source.unsplash.com/400x175/?Search +summary: The data plugin contains services for searching, querying and filtering. +date: 2020-12-02 +tags: ['kibana', 'dev', 'contributor', 'api docs'] +--- + +# Data Views + +The data views API provides a consistent method of structuring and formatting documents +and field lists across the various Kibana apps. Its typically used in conjunction with + for composing queries. + +*Note: Kibana index patterns are currently being renamed to data views. There will be some naming inconsistencies until the transition is complete.* + + diff --git a/src/plugins/data/common/data_views/constants.ts b/src/plugins/data_views/common/constants.ts similarity index 81% rename from src/plugins/data/common/data_views/constants.ts rename to src/plugins/data_views/common/constants.ts index 67e266dbd84a2..ca42221806b2e 100644 --- a/src/plugins/data/common/data_views/constants.ts +++ b/src/plugins/data_views/common/constants.ts @@ -29,3 +29,14 @@ export const FLEET_ASSETS_TO_IGNORE = { METRICS_DATA_STREAM_TO_IGNORE: 'metrics-elastic_agent', // ignore ds created by Fleet server itself METRICS_ENDPOINT_INDEX_TO_IGNORE: 'metrics-endpoint.metadata_current_default', // ignore index created by Fleet endpoint package installed by default in Cloud }; + +export const META_FIELDS = 'metaFields'; + +/** @public **/ +export const DATA_VIEW_SAVED_OBJECT_TYPE = 'index-pattern'; + +/** + * @deprecated Use DATA_VIEW_SAVED_OBJECT_TYPE. All index pattern interfaces were renamed. + */ + +export const INDEX_PATTERN_SAVED_OBJECT_TYPE = DATA_VIEW_SAVED_OBJECT_TYPE; diff --git a/src/plugins/data/common/data_views/data_view.stub.ts b/src/plugins/data_views/common/data_view.stub.ts similarity index 94% rename from src/plugins/data/common/data_views/data_view.stub.ts rename to src/plugins/data_views/common/data_view.stub.ts index a3279434c7a0b..2eb6d4f5d7813 100644 --- a/src/plugins/data/common/data_views/data_view.stub.ts +++ b/src/plugins/data_views/common/data_view.stub.ts @@ -12,8 +12,8 @@ export { createStubDataView, createStubDataView as createStubIndexPattern, } from './data_views/data_view.stub'; -import { SavedObject } from '../../../../core/types'; -import { DataViewAttributes } from '../types'; +import { SavedObject } from '../../../core/types'; +import { DataViewAttributes } from './types'; export const stubDataView = createStubDataView({ spec: { diff --git a/src/plugins/data/common/data_views/data_views/__snapshots__/data_view.test.ts.snap b/src/plugins/data_views/common/data_views/__snapshots__/data_view.test.ts.snap similarity index 100% rename from src/plugins/data/common/data_views/data_views/__snapshots__/data_view.test.ts.snap rename to src/plugins/data_views/common/data_views/__snapshots__/data_view.test.ts.snap diff --git a/src/plugins/data/common/data_views/data_views/__snapshots__/data_views.test.ts.snap b/src/plugins/data_views/common/data_views/__snapshots__/data_views.test.ts.snap similarity index 100% rename from src/plugins/data/common/data_views/data_views/__snapshots__/data_views.test.ts.snap rename to src/plugins/data_views/common/data_views/__snapshots__/data_views.test.ts.snap diff --git a/src/plugins/data/common/data_views/data_views/_pattern_cache.ts b/src/plugins/data_views/common/data_views/_pattern_cache.ts similarity index 100% rename from src/plugins/data/common/data_views/data_views/_pattern_cache.ts rename to src/plugins/data_views/common/data_views/_pattern_cache.ts diff --git a/src/plugins/data/common/data_views/data_views/data_view.stub.ts b/src/plugins/data_views/common/data_views/data_view.stub.ts similarity index 91% rename from src/plugins/data/common/data_views/data_views/data_view.stub.ts rename to src/plugins/data_views/common/data_views/data_view.stub.ts index 5ff2d077812a8..bb7696b0e1262 100644 --- a/src/plugins/data/common/data_views/data_views/data_view.stub.ts +++ b/src/plugins/data_views/common/data_views/data_view.stub.ts @@ -8,8 +8,8 @@ import { DataView } from './data_view'; import { DataViewSpec } from '../types'; -import { FieldFormatsStartCommon } from '../../../../field_formats/common'; -import { fieldFormatsMock } from '../../../../field_formats/common/mocks'; +import { FieldFormatsStartCommon } from '../../../field_formats/common'; +import { fieldFormatsMock } from '../../../field_formats/common/mocks'; /** * Create a custom stub index pattern. Use it in your unit tests where an {@link DataView} expected. diff --git a/src/plugins/data/common/data_views/data_views/data_view.test.ts b/src/plugins/data_views/common/data_views/data_view.test.ts similarity index 98% rename from src/plugins/data/common/data_views/data_views/data_view.test.ts rename to src/plugins/data_views/common/data_views/data_view.test.ts index 6aea86a7adae7..990b8fa4d5f35 100644 --- a/src/plugins/data/common/data_views/data_views/data_view.test.ts +++ b/src/plugins/data_views/common/data_views/data_view.test.ts @@ -10,12 +10,12 @@ import { map, last } from 'lodash'; import { IndexPattern } from './data_view'; -import { DuplicateField } from '../../../../kibana_utils/common'; +import { DuplicateField } from '../../../kibana_utils/common'; import { IndexPatternField } from '../fields'; -import { fieldFormatsMock } from '../../../../field_formats/common/mocks'; -import { FieldFormat } from '../../../../field_formats/common'; +import { fieldFormatsMock } from '../../../field_formats/common/mocks'; +import { FieldFormat } from '../../../field_formats/common'; import { RuntimeField } from '../types'; import { stubLogstashFields } from '../field.stub'; import { stubbedSavedObjectIndexPattern } from '../data_view.stub'; diff --git a/src/plugins/data/common/data_views/data_views/data_view.ts b/src/plugins/data_views/common/data_views/data_view.ts similarity index 97% rename from src/plugins/data/common/data_views/data_views/data_view.ts rename to src/plugins/data_views/common/data_views/data_view.ts index 18d301d2f9ea7..00b96cda32ad7 100644 --- a/src/plugins/data/common/data_views/data_views/data_view.ts +++ b/src/plugins/data_views/common/data_views/data_view.ts @@ -9,19 +9,19 @@ /* eslint-disable max-classes-per-file */ import _, { each, reject } from 'lodash'; -import { castEsToKbnFieldTypeName } from '@kbn/field-types'; +import { castEsToKbnFieldTypeName, ES_FIELD_TYPES, KBN_FIELD_TYPES } from '@kbn/field-types'; import type { estypes } from '@elastic/elasticsearch'; -import { FieldAttrs, FieldAttrSet, DataViewAttributes } from '../..'; +import { FieldAttrs, FieldAttrSet, DataViewAttributes } from '..'; import type { RuntimeField } from '../types'; -import { DuplicateField } from '../../../../kibana_utils/common'; +import { DuplicateField } from '../../../kibana_utils/common'; -import { ES_FIELD_TYPES, KBN_FIELD_TYPES, IIndexPattern, IFieldType } from '../../../common'; +import { IIndexPattern, IFieldType } from '../../common'; import { DataViewField, IIndexPatternFieldList, fieldList } from '../fields'; import { formatHitProvider } from './format_hit'; import { flattenHitWrapper } from './flatten_hit'; -import { FieldFormatsStartCommon, FieldFormat } from '../../../../field_formats/common'; +import { FieldFormatsStartCommon, FieldFormat } from '../../../field_formats/common'; import { DataViewSpec, TypeMeta, SourceFilter, DataViewFieldMap } from '../types'; -import { SerializedFieldFormat } from '../../../../expressions/common'; +import { SerializedFieldFormat } from '../../../expressions/common'; interface DataViewDeps { spec?: DataViewSpec; diff --git a/src/plugins/data/common/data_views/data_views/data_views.test.ts b/src/plugins/data_views/common/data_views/data_views.test.ts similarity index 99% rename from src/plugins/data/common/data_views/data_views/data_views.test.ts rename to src/plugins/data_views/common/data_views/data_views.test.ts index ef9381f16d934..9a01e52ce48e2 100644 --- a/src/plugins/data/common/data_views/data_views/data_views.test.ts +++ b/src/plugins/data_views/common/data_views/data_views.test.ts @@ -8,7 +8,7 @@ import { defaults } from 'lodash'; import { DataViewsService, DataView } from '.'; -import { fieldFormatsMock } from '../../../../field_formats/common/mocks'; +import { fieldFormatsMock } from '../../../field_formats/common/mocks'; import { UiSettingsCommon, SavedObjectsClientCommon, SavedObject } from '../types'; import { stubbedSavedObjectIndexPattern } from '../data_view.stub'; diff --git a/src/plugins/data/common/data_views/data_views/data_views.ts b/src/plugins/data_views/common/data_views/data_views.ts similarity index 96% rename from src/plugins/data/common/data_views/data_views/data_views.ts rename to src/plugins/data_views/common/data_views/data_views.ts index f9b193d154770..77ce1caaaad84 100644 --- a/src/plugins/data/common/data_views/data_views/data_views.ts +++ b/src/plugins/data_views/common/data_views/data_views.ts @@ -11,7 +11,7 @@ import { i18n } from '@kbn/i18n'; import { PublicMethodsOf } from '@kbn/utility-types'; import { castEsToKbnFieldTypeName } from '@kbn/field-types'; -import { DATA_VIEW_SAVED_OBJECT_TYPE, SavedObjectsClientCommon } from '../..'; +import { DATA_VIEW_SAVED_OBJECT_TYPE, SavedObjectsClientCommon } from '..'; import { createDataViewCache } from '.'; import type { RuntimeField } from '../types'; @@ -30,9 +30,9 @@ import { DataViewFieldMap, TypeMeta, } from '../types'; -import { FieldFormatsStartCommon, FORMATS_UI_SETTINGS } from '../../../../field_formats/common/'; -import { UI_SETTINGS, SavedObject } from '../../../common'; -import { SavedObjectNotFound } from '../../../../kibana_utils/common'; +import { FieldFormatsStartCommon, FORMATS_UI_SETTINGS } from '../../../field_formats/common/'; +import { META_FIELDS, SavedObject } from '../../common'; +import { SavedObjectNotFound } from '../../../kibana_utils/common'; import { DataViewMissingIndices } from '../lib'; import { findByTitle } from '../utils'; import { DuplicateDataViewError } from '../errors'; @@ -244,7 +244,7 @@ export class DataViewsService { * @returns FieldSpec[] */ getFieldsForWildcard = async (options: GetFieldsOptions) => { - const metaFields = await this.config.get(UI_SETTINGS.META_FIELDS); + const metaFields = await this.config.get(META_FIELDS); return this.apiClient.getFieldsForWildcard({ pattern: options.pattern, metaFields, @@ -290,7 +290,7 @@ export class DataViewsService { } this.onError(err, { - title: i18n.translate('data.indexPatterns.fetchFieldErrorTitle', { + title: i18n.translate('dataViews.fetchFieldErrorTitle', { defaultMessage: 'Error fetching fields for index pattern {title} (ID: {id})', values: { id: indexPattern.id, title: indexPattern.title }, }), @@ -336,7 +336,7 @@ export class DataViewsService { } this.onError(err, { - title: i18n.translate('data.indexPatterns.fetchFieldErrorTitle', { + title: i18n.translate('dataViews.fetchFieldErrorTitle', { defaultMessage: 'Error fetching fields for index pattern {title} (ID: {id})', values: { id, title }, }), @@ -445,7 +445,7 @@ export class DataViewsService { spec.title as string, { pattern: title as string, - metaFields: await this.config.get(UI_SETTINGS.META_FIELDS), + metaFields: await this.config.get(META_FIELDS), type, rollupIndex: typeMeta?.params?.rollup_index, allowNoIndex: spec.allowNoIndex, @@ -478,7 +478,7 @@ export class DataViewsService { }); } else { this.onError(err, { - title: i18n.translate('data.indexPatterns.fetchFieldErrorTitle', { + title: i18n.translate('dataViews.fetchFieldErrorTitle', { defaultMessage: 'Error fetching fields for index pattern {title} (ID: {id})', values: { id: savedObject.id, title }, }), @@ -520,7 +520,7 @@ export class DataViewsService { */ async create(spec: DataViewSpec, skipFetchFields = false): Promise { const shortDotsEnable = await this.config.get(FORMATS_UI_SETTINGS.SHORT_DOTS_ENABLE); - const metaFields = await this.config.get(UI_SETTINGS.META_FIELDS); + const metaFields = await this.config.get(META_FIELDS); const indexPattern = new DataView({ spec, @@ -648,7 +648,7 @@ export class DataViewsService { if (ignoreErrors) { return; } - const title = i18n.translate('data.indexPatterns.unableWriteLabel', { + const title = i18n.translate('dataViews.unableWriteLabel', { defaultMessage: 'Unable to write index pattern! Refresh the page to get the most up to date changes for this index pattern.', }); diff --git a/src/plugins/data/common/data_views/data_views/ensure_default_data_view.ts b/src/plugins/data_views/common/data_views/ensure_default_data_view.ts similarity index 100% rename from src/plugins/data/common/data_views/data_views/ensure_default_data_view.ts rename to src/plugins/data_views/common/data_views/ensure_default_data_view.ts diff --git a/src/plugins/data/common/data_views/data_views/flatten_hit.test.ts b/src/plugins/data_views/common/data_views/flatten_hit.test.ts similarity index 96% rename from src/plugins/data/common/data_views/data_views/flatten_hit.test.ts rename to src/plugins/data_views/common/data_views/flatten_hit.test.ts index 73232a65b6b72..0946f30b85e39 100644 --- a/src/plugins/data/common/data_views/data_views/flatten_hit.test.ts +++ b/src/plugins/data_views/common/data_views/flatten_hit.test.ts @@ -8,7 +8,7 @@ import { DataView } from './data_view'; -import { fieldFormatsMock } from '../../../../field_formats/common/mocks'; +import { fieldFormatsMock } from '../../../field_formats/common/mocks'; import { flattenHitWrapper } from './flatten_hit'; import { stubbedSavedObjectIndexPattern } from '../data_view.stub'; diff --git a/src/plugins/data/common/data_views/data_views/flatten_hit.ts b/src/plugins/data_views/common/data_views/flatten_hit.ts similarity index 100% rename from src/plugins/data/common/data_views/data_views/flatten_hit.ts rename to src/plugins/data_views/common/data_views/flatten_hit.ts diff --git a/src/plugins/data/common/data_views/data_views/format_hit.ts b/src/plugins/data_views/common/data_views/format_hit.ts similarity index 97% rename from src/plugins/data/common/data_views/data_views/format_hit.ts rename to src/plugins/data_views/common/data_views/format_hit.ts index 39f7fef564eb0..30daf7768c4dc 100644 --- a/src/plugins/data/common/data_views/data_views/format_hit.ts +++ b/src/plugins/data_views/common/data_views/format_hit.ts @@ -8,7 +8,7 @@ import _ from 'lodash'; import { DataView } from './data_view'; -import { FieldFormatsContentType } from '../../../../field_formats/common'; +import { FieldFormatsContentType } from '../../../field_formats/common'; const formattedCache = new WeakMap(); const partialFormattedCache = new WeakMap(); diff --git a/src/plugins/data/common/data_views/data_views/index.ts b/src/plugins/data_views/common/data_views/index.ts similarity index 100% rename from src/plugins/data/common/data_views/data_views/index.ts rename to src/plugins/data_views/common/data_views/index.ts diff --git a/src/plugins/data/common/data_views/errors/data_view_saved_object_conflict.ts b/src/plugins/data_views/common/errors/data_view_saved_object_conflict.ts similarity index 100% rename from src/plugins/data/common/data_views/errors/data_view_saved_object_conflict.ts rename to src/plugins/data_views/common/errors/data_view_saved_object_conflict.ts diff --git a/src/plugins/data/common/data_views/errors/duplicate_index_pattern.ts b/src/plugins/data_views/common/errors/duplicate_index_pattern.ts similarity index 100% rename from src/plugins/data/common/data_views/errors/duplicate_index_pattern.ts rename to src/plugins/data_views/common/errors/duplicate_index_pattern.ts diff --git a/src/plugins/data/common/data_views/errors/index.ts b/src/plugins/data_views/common/errors/index.ts similarity index 100% rename from src/plugins/data/common/data_views/errors/index.ts rename to src/plugins/data_views/common/errors/index.ts diff --git a/src/plugins/data/common/data_views/expressions/index.ts b/src/plugins/data_views/common/expressions/index.ts similarity index 100% rename from src/plugins/data/common/data_views/expressions/index.ts rename to src/plugins/data_views/common/expressions/index.ts diff --git a/src/plugins/data/common/data_views/expressions/load_index_pattern.ts b/src/plugins/data_views/common/expressions/load_index_pattern.ts similarity index 90% rename from src/plugins/data/common/data_views/expressions/load_index_pattern.ts rename to src/plugins/data_views/common/expressions/load_index_pattern.ts index dd47a9fc0dfb4..ca0c1090ceea8 100644 --- a/src/plugins/data/common/data_views/expressions/load_index_pattern.ts +++ b/src/plugins/data_views/common/expressions/load_index_pattern.ts @@ -10,7 +10,7 @@ import { i18n } from '@kbn/i18n'; import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common'; import { DataViewsContract } from '../data_views'; import { DataViewSpec } from '..'; -import { SavedObjectReference } from '../../../../../core/types'; +import { SavedObjectReference } from '../../../../core/types'; const name = 'indexPatternLoad'; const type = 'index_pattern'; @@ -46,14 +46,14 @@ export const getIndexPatternLoadMeta = (): Omit< name, type, inputTypes: ['null'], - help: i18n.translate('data.functions.indexPatternLoad.help', { + help: i18n.translate('dataViews.indexPatternLoad.help', { defaultMessage: 'Loads an index pattern', }), args: { id: { types: ['string'], required: true, - help: i18n.translate('data.functions.indexPatternLoad.id.help', { + help: i18n.translate('dataViews.functions.indexPatternLoad.id.help', { defaultMessage: 'index pattern id to load', }), }, diff --git a/src/plugins/data/common/data_views/field.stub.ts b/src/plugins/data_views/common/field.stub.ts similarity index 100% rename from src/plugins/data/common/data_views/field.stub.ts rename to src/plugins/data_views/common/field.stub.ts diff --git a/src/plugins/data/common/data_views/fields/__snapshots__/data_view_field.test.ts.snap b/src/plugins/data_views/common/fields/__snapshots__/data_view_field.test.ts.snap similarity index 100% rename from src/plugins/data/common/data_views/fields/__snapshots__/data_view_field.test.ts.snap rename to src/plugins/data_views/common/fields/__snapshots__/data_view_field.test.ts.snap diff --git a/src/plugins/data/common/data_views/fields/data_view_field.test.ts b/src/plugins/data_views/common/fields/data_view_field.test.ts similarity index 97% rename from src/plugins/data/common/data_views/fields/data_view_field.test.ts rename to src/plugins/data_views/common/fields/data_view_field.test.ts index 9107036c15c1a..9c611354683c2 100644 --- a/src/plugins/data/common/data_views/fields/data_view_field.test.ts +++ b/src/plugins/data_views/common/fields/data_view_field.test.ts @@ -8,9 +8,9 @@ import { IndexPatternField } from './data_view_field'; import { IndexPattern } from '..'; -import { KBN_FIELD_TYPES } from '../../../common'; +import { KBN_FIELD_TYPES } from '@kbn/field-types'; import { FieldSpec, RuntimeField } from '../types'; -import { FieldFormat } from '../../../../field_formats/common'; +import { FieldFormat } from '../../../field_formats/common'; describe('Field', function () { function flatten(obj: Record) { diff --git a/src/plugins/data/common/data_views/fields/data_view_field.ts b/src/plugins/data_views/common/fields/data_view_field.ts similarity index 97% rename from src/plugins/data/common/data_views/fields/data_view_field.ts rename to src/plugins/data_views/common/fields/data_view_field.ts index fae0e14b95c05..3ad92a3a7e53d 100644 --- a/src/plugins/data/common/data_views/fields/data_view_field.ts +++ b/src/plugins/data_views/common/fields/data_view_field.ts @@ -9,11 +9,11 @@ /* eslint-disable max-classes-per-file */ import { KbnFieldType, getKbnFieldType, castEsToKbnFieldTypeName } from '@kbn/field-types'; +import { KBN_FIELD_TYPES } from '@kbn/field-types'; import type { RuntimeField } from '../types'; -import { KBN_FIELD_TYPES } from '../../kbn_field_types/types'; import type { IFieldType } from './types'; -import { FieldSpec, DataView } from '../..'; -import { shortenDottedString } from '../../utils'; +import { FieldSpec, DataView } from '..'; +import { shortenDottedString } from './utils'; /** @public */ export class DataViewField implements IFieldType { diff --git a/src/plugins/data/common/data_views/fields/field_list.ts b/src/plugins/data_views/common/fields/field_list.ts similarity index 100% rename from src/plugins/data/common/data_views/fields/field_list.ts rename to src/plugins/data_views/common/fields/field_list.ts diff --git a/src/plugins/data/common/data_views/fields/fields.mocks.ts b/src/plugins/data_views/common/fields/fields.mocks.ts similarity index 100% rename from src/plugins/data/common/data_views/fields/fields.mocks.ts rename to src/plugins/data_views/common/fields/fields.mocks.ts diff --git a/src/plugins/data/common/data_views/fields/index.ts b/src/plugins/data_views/common/fields/index.ts similarity index 100% rename from src/plugins/data/common/data_views/fields/index.ts rename to src/plugins/data_views/common/fields/index.ts diff --git a/src/plugins/data/common/data_views/fields/types.ts b/src/plugins/data_views/common/fields/types.ts similarity index 95% rename from src/plugins/data/common/data_views/fields/types.ts rename to src/plugins/data_views/common/fields/types.ts index 2c5934a8e7b3f..2bd1cf5834548 100644 --- a/src/plugins/data/common/data_views/fields/types.ts +++ b/src/plugins/data_views/common/fields/types.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ import { DataViewFieldBase } from '@kbn/es-query'; -import { FieldSpec, DataView } from '../..'; +import { FieldSpec, DataView } from '..'; /** * @deprecated Use {@link IndexPatternField} diff --git a/src/plugins/data/common/utils/shorten_dotted_string.test.ts b/src/plugins/data_views/common/fields/utils.test.ts similarity index 92% rename from src/plugins/data/common/utils/shorten_dotted_string.test.ts rename to src/plugins/data_views/common/fields/utils.test.ts index 33a44925982ec..0f2ff280eb61b 100644 --- a/src/plugins/data/common/utils/shorten_dotted_string.test.ts +++ b/src/plugins/data_views/common/fields/utils.test.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { shortenDottedString } from './shorten_dotted_string'; +import { shortenDottedString } from './utils'; describe('shortenDottedString', () => { test('should convert a dot.notated.string into a short string', () => { diff --git a/src/plugins/data/common/data_views/fields/utils.ts b/src/plugins/data_views/common/fields/utils.ts similarity index 75% rename from src/plugins/data/common/data_views/fields/utils.ts rename to src/plugins/data_views/common/fields/utils.ts index 9e05bebc746f0..8344a32d78556 100644 --- a/src/plugins/data/common/data_views/fields/utils.ts +++ b/src/plugins/data_views/common/fields/utils.ts @@ -22,3 +22,15 @@ export function isFilterable(field: IFieldType): boolean { export function isNestedField(field: IFieldType): boolean { return !!field.subType?.nested; } + +const DOT_PREFIX_RE = /(.).+?\./g; + +/** + * Convert a dot.notated.string into a short + * version (d.n.string) + * + * @return {any} + */ +export function shortenDottedString(input: any) { + return typeof input !== 'string' ? input : input.replace(DOT_PREFIX_RE, '$1.'); +} diff --git a/src/plugins/data_views/common/index.ts b/src/plugins/data_views/common/index.ts new file mode 100644 index 0000000000000..e8b36ab3e8fc1 --- /dev/null +++ b/src/plugins/data_views/common/index.ts @@ -0,0 +1,62 @@ +/* + * 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. + */ + +export { + RUNTIME_FIELD_TYPES, + FLEET_ASSETS_TO_IGNORE, + META_FIELDS, + DATA_VIEW_SAVED_OBJECT_TYPE, + INDEX_PATTERN_SAVED_OBJECT_TYPE, +} from './constants'; +export type { IFieldType, IIndexPatternFieldList } from './fields'; +export { isFilterable, isNestedField, fieldList, DataViewField, IndexPatternField } from './fields'; +export type { + FieldFormatMap, + RuntimeType, + RuntimeField, + IIndexPattern, + DataViewAttributes, + IndexPatternAttributes, + FieldAttrs, + FieldAttrSet, + OnNotification, + OnError, + UiSettingsCommon, + SavedObjectsClientCommonFindArgs, + SavedObjectsClientCommon, + GetFieldsOptions, + GetFieldsOptionsTimePattern, + IDataViewsApiClient, + IIndexPatternsApiClient, + SavedObject, + AggregationRestrictions, + TypeMeta, + FieldSpecConflictDescriptions, + FieldSpecExportFmt, + FieldSpec, + DataViewFieldMap, + IndexPatternFieldMap, + DataViewSpec, + IndexPatternSpec, + SourceFilter, +} from './types'; +export { DataViewType, IndexPatternType } from './types'; +export { + IndexPatternsService, + IndexPatternsContract, + DataViewsService, + DataViewsContract, +} from './data_views'; +export { IndexPattern, IndexPatternListItem, DataView, DataViewListItem } from './data_views'; +export { DuplicateDataViewError, DataViewSavedObjectConflictError } from './errors'; +export type { + IndexPatternExpressionType, + IndexPatternLoadStartDependencies, + IndexPatternLoadExpressionFunctionDefinition, +} from './expressions'; +export { getIndexPatternLoadMeta } from './expressions'; diff --git a/src/plugins/data/common/data_views/lib/errors.ts b/src/plugins/data_views/common/lib/errors.ts similarity index 93% rename from src/plugins/data/common/data_views/lib/errors.ts rename to src/plugins/data_views/common/lib/errors.ts index 83cc7ea56d020..f8422a6e5dd0d 100644 --- a/src/plugins/data/common/data_views/lib/errors.ts +++ b/src/plugins/data_views/common/lib/errors.ts @@ -8,7 +8,7 @@ /* eslint-disable */ -import { KbnError } from '../../../../kibana_utils/common/'; +import { KbnError } from '../../../kibana_utils/common'; /** * Tried to call a method that relies on SearchSource having an indexPattern assigned diff --git a/src/plugins/data/common/data_views/lib/get_title.ts b/src/plugins/data_views/common/lib/get_title.ts similarity index 85% rename from src/plugins/data/common/data_views/lib/get_title.ts rename to src/plugins/data_views/common/lib/get_title.ts index 94185eae46893..69471583f139c 100644 --- a/src/plugins/data/common/data_views/lib/get_title.ts +++ b/src/plugins/data_views/common/lib/get_title.ts @@ -6,8 +6,8 @@ * Side Public License, v 1. */ -import { SavedObjectsClientContract } from '../../../../../core/public'; -import { DATA_VIEW_SAVED_OBJECT_TYPE } from '../../constants'; +import { SavedObjectsClientContract } from '../../../../core/public'; +import { DATA_VIEW_SAVED_OBJECT_TYPE } from '../constants'; import { DataViewAttributes } from '../types'; export async function getTitle( diff --git a/src/plugins/data/common/data_views/lib/index.ts b/src/plugins/data_views/common/lib/index.ts similarity index 100% rename from src/plugins/data/common/data_views/lib/index.ts rename to src/plugins/data_views/common/lib/index.ts diff --git a/src/plugins/data/common/data_views/lib/types.ts b/src/plugins/data_views/common/lib/types.ts similarity index 100% rename from src/plugins/data/common/data_views/lib/types.ts rename to src/plugins/data_views/common/lib/types.ts diff --git a/src/plugins/data/common/data_views/lib/validate_data_view.test.ts b/src/plugins/data_views/common/lib/validate_data_view.test.ts similarity index 100% rename from src/plugins/data/common/data_views/lib/validate_data_view.test.ts rename to src/plugins/data_views/common/lib/validate_data_view.test.ts diff --git a/src/plugins/data/common/data_views/lib/validate_data_view.ts b/src/plugins/data_views/common/lib/validate_data_view.ts similarity index 100% rename from src/plugins/data/common/data_views/lib/validate_data_view.ts rename to src/plugins/data_views/common/lib/validate_data_view.ts diff --git a/src/plugins/data/common/data_views/mocks.ts b/src/plugins/data_views/common/mocks.ts similarity index 100% rename from src/plugins/data/common/data_views/mocks.ts rename to src/plugins/data_views/common/mocks.ts diff --git a/src/plugins/data_views/common/stubs.ts b/src/plugins/data_views/common/stubs.ts new file mode 100644 index 0000000000000..c6895da9bfb3a --- /dev/null +++ b/src/plugins/data_views/common/stubs.ts @@ -0,0 +1,10 @@ +/* + * 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. + */ + +export * from './field.stub'; +export * from './data_views/data_view.stub'; diff --git a/src/plugins/data/common/data_views/types.ts b/src/plugins/data_views/common/types.ts similarity index 96% rename from src/plugins/data/common/data_views/types.ts rename to src/plugins/data_views/common/types.ts index 85fe98fbcfeb7..2b184bc1ef2a4 100644 --- a/src/plugins/data/common/data_views/types.ts +++ b/src/plugins/data_views/common/types.ts @@ -10,11 +10,12 @@ import type { DataViewFieldBase, IFieldSubType, DataViewBase } from '@kbn/es-que import { ToastInputFields, ErrorToastOptions } from 'src/core/public/notifications'; // eslint-disable-next-line import type { SavedObject } from 'src/core/server'; +import { KBN_FIELD_TYPES } from '@kbn/field-types'; import { IFieldType } from './fields'; import { RUNTIME_FIELD_TYPES } from './constants'; -import { SerializedFieldFormat } from '../../../expressions/common'; -import { KBN_FIELD_TYPES, DataViewField } from '..'; -import { FieldFormat } from '../../../field_formats/common'; +import { SerializedFieldFormat } from '../../expressions/common'; +import { DataViewField } from './fields'; +import { FieldFormat } from '../../field_formats/common'; export type FieldFormatMap = Record; diff --git a/src/plugins/data/common/data_views/utils.test.ts b/src/plugins/data_views/common/utils.test.ts similarity index 100% rename from src/plugins/data/common/data_views/utils.test.ts rename to src/plugins/data_views/common/utils.test.ts diff --git a/src/plugins/data/common/data_views/utils.ts b/src/plugins/data_views/common/utils.ts similarity index 89% rename from src/plugins/data/common/data_views/utils.ts rename to src/plugins/data_views/common/utils.ts index 2d36ab6c72225..77e9bd76b869c 100644 --- a/src/plugins/data/common/data_views/utils.ts +++ b/src/plugins/data_views/common/utils.ts @@ -7,9 +7,9 @@ */ import type { IndexPatternSavedObjectAttrs } from './data_views'; -import type { SavedObjectsClientCommon } from '../types'; +import type { SavedObjectsClientCommon } from './types'; -import { DATA_VIEW_SAVED_OBJECT_TYPE } from '../constants'; +import { DATA_VIEW_SAVED_OBJECT_TYPE } from './constants'; /** * Returns an object matching a given title diff --git a/src/plugins/data_views/jest.config.js b/src/plugins/data_views/jest.config.js new file mode 100644 index 0000000000000..4c1f067835630 --- /dev/null +++ b/src/plugins/data_views/jest.config.js @@ -0,0 +1,16 @@ +/* + * 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. + */ + +module.exports = { + preset: '@kbn/test', + rootDir: '../../..', + roots: ['/src/plugins/data_views'], + coverageDirectory: '/target/kibana-coverage/jest/src/plugins/data_views', + coverageReporters: ['text', 'html'], + collectCoverageFrom: ['/src/plugins/data_views/{common,public,server}/**/*.{ts,tsx}'], +}; diff --git a/src/plugins/data_views/kibana.json b/src/plugins/data_views/kibana.json new file mode 100644 index 0000000000000..27bf536ef8040 --- /dev/null +++ b/src/plugins/data_views/kibana.json @@ -0,0 +1,15 @@ +{ + "id": "dataViews", + "version": "kibana", + "server": true, + "ui": true, + "requiredPlugins": ["fieldFormats","expressions"], + "optionalPlugins": ["usageCollection"], + "extraPublicDirs": ["common"], + "requiredBundles": ["kibanaUtils","kibanaReact"], + "owner": { + "name": "App Services", + "githubTeam": "kibana-app-services" + }, + "description": "Data services are useful for searching and querying data from Elasticsearch. Helpful utilities include: a re-usable react query bar, KQL autocomplete, async search, Data Views (Index Patterns) and field formatters." +} diff --git a/src/plugins/data/public/data_views/data_views/data_view.stub.ts b/src/plugins/data_views/public/data_views/data_view.stub.ts similarity index 84% rename from src/plugins/data/public/data_views/data_views/data_view.stub.ts rename to src/plugins/data_views/public/data_views/data_view.stub.ts index b3d8448064c65..f37a8a78b234b 100644 --- a/src/plugins/data/public/data_views/data_views/data_view.stub.ts +++ b/src/plugins/data_views/public/data_views/data_view.stub.ts @@ -7,11 +7,11 @@ */ import { CoreSetup } from 'kibana/public'; -import { FieldFormatsStartCommon } from '../../../../field_formats/common'; -import { getFieldFormatsRegistry } from '../../../../field_formats/public/mocks'; -import * as commonStubs from '../../../common/stubs'; -import { DataView, DataViewSpec } from '../../../common'; -import { coreMock } from '../../../../../core/public/mocks'; +import { FieldFormatsStartCommon } from '../../../field_formats/common'; +import { getFieldFormatsRegistry } from '../../../field_formats/public/mocks'; +import * as commonStubs from '../../common/stubs'; +import { DataView, DataViewSpec } from '../../common'; +import { coreMock } from '../../../../core/public/mocks'; /** * Create a custom stub index pattern. Use it in your unit tests where an {@link DataView} expected. * @param spec - Serialized index pattern object diff --git a/src/plugins/data/public/data_views/data_views/data_views_api_client.test.mock.ts b/src/plugins/data_views/public/data_views/data_views_api_client.test.mock.ts similarity index 86% rename from src/plugins/data/public/data_views/data_views/data_views_api_client.test.mock.ts rename to src/plugins/data_views/public/data_views/data_views_api_client.test.mock.ts index c53ca7ad89aa9..2fd17b98f7498 100644 --- a/src/plugins/data/public/data_views/data_views/data_views_api_client.test.mock.ts +++ b/src/plugins/data_views/public/data_views/data_views_api_client.test.mock.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { setup } from '../../../../../core/test_helpers/http_test_setup'; +import { setup } from '../../../../core/test_helpers/http_test_setup'; export const { http } = setup((injectedMetadata) => { injectedMetadata.getBasePath.mockReturnValue('/hola/daro/'); diff --git a/src/plugins/data/public/data_views/data_views/data_views_api_client.test.ts b/src/plugins/data_views/public/data_views/data_views_api_client.test.ts similarity index 100% rename from src/plugins/data/public/data_views/data_views/data_views_api_client.test.ts rename to src/plugins/data_views/public/data_views/data_views_api_client.test.ts diff --git a/src/plugins/data/public/data_views/data_views/data_views_api_client.ts b/src/plugins/data_views/public/data_views/data_views_api_client.ts similarity index 90% rename from src/plugins/data/public/data_views/data_views/data_views_api_client.ts rename to src/plugins/data_views/public/data_views/data_views_api_client.ts index d11ec7cfa003d..d4da9a55c25d1 100644 --- a/src/plugins/data/public/data_views/data_views/data_views_api_client.ts +++ b/src/plugins/data_views/public/data_views/data_views_api_client.ts @@ -7,12 +7,8 @@ */ import { HttpSetup } from 'src/core/public'; -import { DataViewMissingIndices } from '../../../common/data_views/lib'; -import { - GetFieldsOptions, - IDataViewsApiClient, - GetFieldsOptionsTimePattern, -} from '../../../common/data_views/types'; +import { DataViewMissingIndices } from '../../common/lib'; +import { GetFieldsOptions, IDataViewsApiClient, GetFieldsOptionsTimePattern } from '../../common'; const API_BASE_URL: string = `/api/index_patterns/`; diff --git a/src/plugins/data/public/data_views/data_views/index.ts b/src/plugins/data_views/public/data_views/index.ts similarity index 88% rename from src/plugins/data/public/data_views/data_views/index.ts rename to src/plugins/data_views/public/data_views/index.ts index e0d18d47f39db..e476d62774f17 100644 --- a/src/plugins/data/public/data_views/data_views/index.ts +++ b/src/plugins/data_views/public/data_views/index.ts @@ -6,6 +6,6 @@ * Side Public License, v 1. */ -export * from '../../../common/data_views/data_views'; +export * from '../../common/data_views'; export * from './redirect_no_index_pattern'; export * from './data_views_api_client'; diff --git a/src/plugins/data/public/data_views/data_views/redirect_no_index_pattern.tsx b/src/plugins/data_views/public/data_views/redirect_no_index_pattern.tsx similarity index 84% rename from src/plugins/data/public/data_views/data_views/redirect_no_index_pattern.tsx rename to src/plugins/data_views/public/data_views/redirect_no_index_pattern.tsx index 88e18060c4d11..456af90a3c6dd 100644 --- a/src/plugins/data/public/data_views/data_views/redirect_no_index_pattern.tsx +++ b/src/plugins/data_views/public/data_views/redirect_no_index_pattern.tsx @@ -10,7 +10,7 @@ import { EuiCallOut } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import React from 'react'; import { CoreStart } from 'kibana/public'; -import { toMountPoint } from '../../../../kibana_react/public'; +import { toMountPoint } from '../../../kibana_react/public'; let bannerId: string; @@ -29,13 +29,10 @@ export const onRedirectNoIndexPattern = clearTimeout(timeoutId); } - const bannerMessage = i18n.translate( - 'data.indexPatterns.ensureDefaultIndexPattern.bannerLabel', - { - defaultMessage: - 'To visualize and explore data in Kibana, you must create an index pattern to retrieve data from Elasticsearch.', - } - ); + const bannerMessage = i18n.translate('dataViews.ensureDefaultIndexPattern.bannerLabel', { + defaultMessage: + 'To visualize and explore data in Kibana, you must create an index pattern to retrieve data from Elasticsearch.', + }); // Avoid being hostile to new users who don't have an index pattern setup yet // give them a friendly info message instead of a terse error message diff --git a/src/plugins/data/public/data_views/expressions/index.ts b/src/plugins/data_views/public/expressions/index.ts similarity index 100% rename from src/plugins/data/public/data_views/expressions/index.ts rename to src/plugins/data_views/public/expressions/index.ts diff --git a/src/plugins/data/public/data_views/expressions/load_index_pattern.test.ts b/src/plugins/data_views/public/expressions/load_index_pattern.test.ts similarity index 92% rename from src/plugins/data/public/data_views/expressions/load_index_pattern.test.ts rename to src/plugins/data_views/public/expressions/load_index_pattern.test.ts index befa78c398984..02a530712e80a 100644 --- a/src/plugins/data/public/data_views/expressions/load_index_pattern.test.ts +++ b/src/plugins/data_views/public/expressions/load_index_pattern.test.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { IndexPatternLoadStartDependencies } from '../../../common/data_views/expressions'; +import { IndexPatternLoadStartDependencies } from '../../common/expressions'; import { getFunctionDefinition } from './load_index_pattern'; describe('indexPattern expression function', () => { diff --git a/src/plugins/data/public/data_views/expressions/load_index_pattern.ts b/src/plugins/data_views/public/expressions/load_index_pattern.ts similarity index 88% rename from src/plugins/data/public/data_views/expressions/load_index_pattern.ts rename to src/plugins/data_views/public/expressions/load_index_pattern.ts index 979861c7da38e..76119f3e50a45 100644 --- a/src/plugins/data/public/data_views/expressions/load_index_pattern.ts +++ b/src/plugins/data_views/public/expressions/load_index_pattern.ts @@ -11,8 +11,8 @@ import { getIndexPatternLoadMeta, IndexPatternLoadExpressionFunctionDefinition, IndexPatternLoadStartDependencies, -} from '../../../common/data_views/expressions'; -import { DataPublicPluginStart, DataStartDependencies } from '../../types'; +} from '../../common/expressions'; +import { DataViewsPublicPluginStart, DataViewsPublicStartDependencies } from '../types'; /** * Returns the expression function definition. Any stateful dependencies are accessed @@ -60,11 +60,14 @@ export function getFunctionDefinition({ export function getIndexPatternLoad({ getStartServices, }: { - getStartServices: StartServicesAccessor; + getStartServices: StartServicesAccessor< + DataViewsPublicStartDependencies, + DataViewsPublicPluginStart + >; }) { return getFunctionDefinition({ getStartDependencies: async () => { - const [, , { indexPatterns }] = await getStartServices(); + const [, , indexPatterns] = await getStartServices(); return { indexPatterns }; }, }); diff --git a/src/plugins/data_views/public/index.ts b/src/plugins/data_views/public/index.ts new file mode 100644 index 0000000000000..572806df11fa3 --- /dev/null +++ b/src/plugins/data_views/public/index.ts @@ -0,0 +1,45 @@ +/* + * 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. + */ + +export { + ILLEGAL_CHARACTERS_KEY, + CONTAINS_SPACES_KEY, + ILLEGAL_CHARACTERS_VISIBLE, + ILLEGAL_CHARACTERS, + validateDataView, +} from '../common/lib'; +export { flattenHitWrapper, formatHitProvider, onRedirectNoIndexPattern } from './data_views'; + +export { IndexPatternField, IIndexPatternFieldList, TypeMeta } from '../common'; + +export { + IndexPatternsService, + IndexPatternsContract, + IndexPattern, + DataViewsApiClient, + DataViewsService, + DataViewsContract, + DataView, +} from './data_views'; +export { UiSettingsPublicToCommon } from './ui_settings_wrapper'; +export { SavedObjectsClientPublicToCommon } from './saved_objects_client_wrapper'; + +/* + * Plugin setup + */ + +import { DataViewsPublicPlugin } from './plugin'; + +export function plugin() { + return new DataViewsPublicPlugin(); +} + +export type { DataViewsPublicPluginSetup, DataViewsPublicPluginStart } from './types'; + +// Export plugin after all other imports +export type { DataViewsPublicPlugin as DataPlugin }; diff --git a/src/plugins/data_views/public/plugin.ts b/src/plugins/data_views/public/plugin.ts new file mode 100644 index 0000000000000..58f66623b64ab --- /dev/null +++ b/src/plugins/data_views/public/plugin.ts @@ -0,0 +1,68 @@ +/* + * 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. + */ + +import { CoreSetup, CoreStart, Plugin } from 'src/core/public'; +import { getIndexPatternLoad } from './expressions'; +import { + DataViewsPublicPluginSetup, + DataViewsPublicPluginStart, + DataViewsPublicSetupDependencies, + DataViewsPublicStartDependencies, +} from './types'; + +import { + DataViewsService, + onRedirectNoIndexPattern, + DataViewsApiClient, + UiSettingsPublicToCommon, + SavedObjectsClientPublicToCommon, +} from '.'; + +export class DataViewsPublicPlugin + implements + Plugin< + DataViewsPublicPluginSetup, + DataViewsPublicPluginStart, + DataViewsPublicSetupDependencies, + DataViewsPublicStartDependencies + > +{ + public setup( + core: CoreSetup, + { expressions }: DataViewsPublicSetupDependencies + ): DataViewsPublicPluginSetup { + expressions.registerFunction(getIndexPatternLoad({ getStartServices: core.getStartServices })); + + return {}; + } + + public start( + core: CoreStart, + { fieldFormats }: DataViewsPublicStartDependencies + ): DataViewsPublicPluginStart { + const { uiSettings, http, notifications, savedObjects, overlays, application } = core; + + return new DataViewsService({ + uiSettings: new UiSettingsPublicToCommon(uiSettings), + savedObjectsClient: new SavedObjectsClientPublicToCommon(savedObjects.client), + apiClient: new DataViewsApiClient(http), + fieldFormats, + onNotification: (toastInputFields) => { + notifications.toasts.add(toastInputFields); + }, + onError: notifications.toasts.addError.bind(notifications.toasts), + onRedirectNoIndexPattern: onRedirectNoIndexPattern( + application.capabilities, + application.navigateToApp, + overlays + ), + }); + } + + public stop() {} +} diff --git a/src/plugins/data/public/data_views/saved_objects_client_wrapper.test.ts b/src/plugins/data_views/public/saved_objects_client_wrapper.test.ts similarity index 96% rename from src/plugins/data/public/data_views/saved_objects_client_wrapper.test.ts rename to src/plugins/data_views/public/saved_objects_client_wrapper.test.ts index 221a18ac7fab7..124a66eba57f2 100644 --- a/src/plugins/data/public/data_views/saved_objects_client_wrapper.test.ts +++ b/src/plugins/data_views/public/saved_objects_client_wrapper.test.ts @@ -9,7 +9,7 @@ import { SavedObjectsClientPublicToCommon } from './saved_objects_client_wrapper'; import { savedObjectsServiceMock } from 'src/core/public/mocks'; -import { DataViewSavedObjectConflictError } from '../../common/data_views'; +import { DataViewSavedObjectConflictError } from '../common'; describe('SavedObjectsClientPublicToCommon', () => { const soClient = savedObjectsServiceMock.createStartContract().client; diff --git a/src/plugins/data/public/data_views/saved_objects_client_wrapper.ts b/src/plugins/data_views/public/saved_objects_client_wrapper.ts similarity index 98% rename from src/plugins/data/public/data_views/saved_objects_client_wrapper.ts rename to src/plugins/data_views/public/saved_objects_client_wrapper.ts index 1db4e3b1ccd24..beaae6ac3fc21 100644 --- a/src/plugins/data/public/data_views/saved_objects_client_wrapper.ts +++ b/src/plugins/data_views/public/saved_objects_client_wrapper.ts @@ -13,7 +13,7 @@ import { SavedObjectsClientCommonFindArgs, SavedObject, DataViewSavedObjectConflictError, -} from '../../common/data_views'; +} from '../common'; type SOClient = Pick; diff --git a/src/plugins/data_views/public/types.ts b/src/plugins/data_views/public/types.ts new file mode 100644 index 0000000000000..20b1cbaf090fa --- /dev/null +++ b/src/plugins/data_views/public/types.ts @@ -0,0 +1,32 @@ +/* + * 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. + */ + +import { ExpressionsSetup } from 'src/plugins/expressions/public'; +import { FieldFormatsSetup, FieldFormatsStart } from 'src/plugins/field_formats/public'; +import { PublicMethodsOf } from '@kbn/utility-types'; +import { DataViewsService } from './data_views'; + +export interface DataViewsPublicSetupDependencies { + expressions: ExpressionsSetup; + fieldFormats: FieldFormatsSetup; +} + +export interface DataViewsPublicStartDependencies { + fieldFormats: FieldFormatsStart; +} + +/** + * Data plugin public Setup contract + */ +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface DataViewsPublicPluginSetup {} + +/** + * Data plugin public Start contract + */ +export type DataViewsPublicPluginStart = PublicMethodsOf; diff --git a/src/plugins/data/public/data_views/ui_settings_wrapper.ts b/src/plugins/data_views/public/ui_settings_wrapper.ts similarity index 95% rename from src/plugins/data/public/data_views/ui_settings_wrapper.ts rename to src/plugins/data_views/public/ui_settings_wrapper.ts index f8ae317391fa3..91806867b6730 100644 --- a/src/plugins/data/public/data_views/ui_settings_wrapper.ts +++ b/src/plugins/data_views/public/ui_settings_wrapper.ts @@ -7,7 +7,7 @@ */ import { IUiSettingsClient, PublicUiSettingsParams, UserProvidedValues } from 'src/core/public'; -import { UiSettingsCommon } from '../../common'; +import { UiSettingsCommon } from '../common'; export class UiSettingsPublicToCommon implements UiSettingsCommon { private uiSettings: IUiSettingsClient; diff --git a/src/plugins/data/server/data_views/capabilities_provider.ts b/src/plugins/data_views/server/capabilities_provider.ts similarity index 100% rename from src/plugins/data/server/data_views/capabilities_provider.ts rename to src/plugins/data_views/server/capabilities_provider.ts diff --git a/src/plugins/data_views/server/data_views_service_factory.ts b/src/plugins/data_views/server/data_views_service_factory.ts new file mode 100644 index 0000000000000..2f720cd7388f4 --- /dev/null +++ b/src/plugins/data_views/server/data_views_service_factory.ts @@ -0,0 +1,50 @@ +/* + * 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. + */ + +import { + Logger, + SavedObjectsClientContract, + ElasticsearchClient, + UiSettingsServiceStart, +} from 'kibana/server'; +import { DataViewsService } from '../common'; +import { FieldFormatsStart } from '../../field_formats/server'; +import { UiSettingsServerToCommon } from './ui_settings_wrapper'; +import { IndexPatternsApiServer } from './index_patterns_api_client'; +import { SavedObjectsClientServerToCommon } from './saved_objects_client_wrapper'; + +export const dataViewsServiceFactory = + ({ + logger, + uiSettings, + fieldFormats, + }: { + logger: Logger; + uiSettings: UiSettingsServiceStart; + fieldFormats: FieldFormatsStart; + }) => + async ( + savedObjectsClient: SavedObjectsClientContract, + elasticsearchClient: ElasticsearchClient + ) => { + const uiSettingsClient = uiSettings.asScopedToClient(savedObjectsClient); + const formats = await fieldFormats.fieldFormatServiceFactory(uiSettingsClient); + + return new DataViewsService({ + uiSettings: new UiSettingsServerToCommon(uiSettingsClient), + savedObjectsClient: new SavedObjectsClientServerToCommon(savedObjectsClient), + apiClient: new IndexPatternsApiServer(elasticsearchClient, savedObjectsClient), + fieldFormats: formats, + onError: (error) => { + logger.error(error); + }, + onNotification: ({ title, text }) => { + logger.warn(`${title}${text ? ` : ${text}` : ''}`); + }, + }); + }; diff --git a/src/plugins/data/server/data_views/deprecations/index.ts b/src/plugins/data_views/server/deprecations/index.ts similarity index 100% rename from src/plugins/data/server/data_views/deprecations/index.ts rename to src/plugins/data_views/server/deprecations/index.ts diff --git a/src/plugins/data/server/data_views/deprecations/scripted_fields.test.ts b/src/plugins/data_views/server/deprecations/scripted_fields.test.ts similarity index 100% rename from src/plugins/data/server/data_views/deprecations/scripted_fields.test.ts rename to src/plugins/data_views/server/deprecations/scripted_fields.test.ts diff --git a/src/plugins/data/server/data_views/deprecations/scripted_fields.ts b/src/plugins/data_views/server/deprecations/scripted_fields.ts similarity index 89% rename from src/plugins/data/server/data_views/deprecations/scripted_fields.ts rename to src/plugins/data_views/server/deprecations/scripted_fields.ts index 65cb962196805..9ee2d64e25cb5 100644 --- a/src/plugins/data/server/data_views/deprecations/scripted_fields.ts +++ b/src/plugins/data_views/server/deprecations/scripted_fields.ts @@ -13,7 +13,7 @@ import { RegisterDeprecationsConfig, } from 'kibana/server'; import { i18n } from '@kbn/i18n'; -import { IndexPatternAttributes } from '../../../common'; +import { IndexPatternAttributes } from '../../common'; type IndexPatternAttributesWithFields = Pick; @@ -41,10 +41,10 @@ export const createScriptedFieldsDeprecationsConfig: ( return [ { - title: i18n.translate('data.deprecations.scriptedFieldsTitle', { + title: i18n.translate('dataViews.deprecations.scriptedFieldsTitle', { defaultMessage: 'Found index patterns using scripted fields', }), - message: i18n.translate('data.deprecations.scriptedFieldsMessage', { + message: i18n.translate('dataViews.deprecations.scriptedFieldsMessage', { defaultMessage: `You have {numberOfIndexPatternsWithScriptedFields} index patterns ({titlesPreview}...) that use scripted fields. Scripted fields are deprecated and will be removed in future. Use runtime fields instead.`, values: { titlesPreview: indexPatternTitles.slice(0, PREVIEW_LIMIT).join('; '), @@ -56,10 +56,10 @@ export const createScriptedFieldsDeprecationsConfig: ( level: 'warning', // warning because it is not set in stone WHEN we remove scripted fields, hence this deprecation is not a blocker for 8.0 upgrade correctiveActions: { manualSteps: [ - i18n.translate('data.deprecations.scriptedFields.manualStepOneMessage', { + i18n.translate('dataViews.deprecations.scriptedFields.manualStepOneMessage', { defaultMessage: 'Navigate to Stack Management > Kibana > Index Patterns.', }), - i18n.translate('data.deprecations.scriptedFields.manualStepTwoMessage', { + i18n.translate('dataViews.deprecations.scriptedFields.manualStepTwoMessage', { defaultMessage: 'Update {numberOfIndexPatternsWithScriptedFields} index patterns that have scripted fields to use runtime fields instead. In most cases, to migrate existing scripts, you will need to change "return ;" to "emit();". Index patterns with at least one scripted field: {allTitles}', values: { diff --git a/src/plugins/data/server/data_views/error.ts b/src/plugins/data_views/server/error.ts similarity index 100% rename from src/plugins/data/server/data_views/error.ts rename to src/plugins/data_views/server/error.ts diff --git a/src/plugins/data/server/data_views/expressions/index.ts b/src/plugins/data_views/server/expressions/index.ts similarity index 100% rename from src/plugins/data/server/data_views/expressions/index.ts rename to src/plugins/data_views/server/expressions/index.ts diff --git a/src/plugins/data/server/data_views/expressions/load_index_pattern.test.ts b/src/plugins/data_views/server/expressions/load_index_pattern.test.ts similarity index 94% rename from src/plugins/data/server/data_views/expressions/load_index_pattern.test.ts rename to src/plugins/data_views/server/expressions/load_index_pattern.test.ts index 370d7dcfd7eba..94bd854e6734c 100644 --- a/src/plugins/data/server/data_views/expressions/load_index_pattern.test.ts +++ b/src/plugins/data_views/server/expressions/load_index_pattern.test.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { IndexPatternLoadStartDependencies } from '../../../common/data_views/expressions'; +import { IndexPatternLoadStartDependencies } from '../../common/expressions'; import { getFunctionDefinition } from './load_index_pattern'; describe('indexPattern expression function', () => { diff --git a/src/plugins/data/server/data_views/expressions/load_index_pattern.ts b/src/plugins/data_views/server/expressions/load_index_pattern.ts similarity index 85% rename from src/plugins/data/server/data_views/expressions/load_index_pattern.ts rename to src/plugins/data_views/server/expressions/load_index_pattern.ts index 4585101f2812c..8ade41132e144 100644 --- a/src/plugins/data/server/data_views/expressions/load_index_pattern.ts +++ b/src/plugins/data_views/server/expressions/load_index_pattern.ts @@ -13,8 +13,8 @@ import { getIndexPatternLoadMeta, IndexPatternLoadExpressionFunctionDefinition, IndexPatternLoadStartDependencies, -} from '../../../common/data_views/expressions'; -import { DataPluginStartDependencies, DataPluginStart } from '../../plugin'; +} from '../../common/expressions'; +import { DataViewsServerPluginStartDependencies, DataViewsServerPluginStart } from '../types'; /** * Returns the expression function definition. Any stateful dependencies are accessed @@ -39,7 +39,7 @@ export function getFunctionDefinition({ const kibanaRequest = getKibanaRequest ? getKibanaRequest() : null; if (!kibanaRequest) { throw new Error( - i18n.translate('data.indexPatterns.indexPatternLoad.error.kibanaRequest', { + i18n.translate('dataViews.indexPatternLoad.error.kibanaRequest', { defaultMessage: 'A KibanaRequest is required to execute this search on the server. ' + 'Please provide a request object to the expression execution params.', @@ -73,13 +73,17 @@ export function getFunctionDefinition({ export function getIndexPatternLoad({ getStartServices, }: { - getStartServices: StartServicesAccessor; + getStartServices: StartServicesAccessor< + DataViewsServerPluginStartDependencies, + DataViewsServerPluginStart + >; }) { return getFunctionDefinition({ getStartDependencies: async (request: KibanaRequest) => { - const [{ elasticsearch, savedObjects }, , { indexPatterns }] = await getStartServices(); + const [{ elasticsearch, savedObjects }, , { indexPatternsServiceFactory }] = + await getStartServices(); return { - indexPatterns: await indexPatterns.indexPatternsServiceFactory( + indexPatterns: await indexPatternsServiceFactory( savedObjects.getScopedClient(request), elasticsearch.client.asScoped(request).asCurrentUser ), diff --git a/src/plugins/data/server/data_views/fetcher/index.ts b/src/plugins/data_views/server/fetcher/index.ts similarity index 100% rename from src/plugins/data/server/data_views/fetcher/index.ts rename to src/plugins/data_views/server/fetcher/index.ts diff --git a/src/plugins/data_views/server/fetcher/index_not_found_exception.json b/src/plugins/data_views/server/fetcher/index_not_found_exception.json new file mode 100644 index 0000000000000..dc892d95ae397 --- /dev/null +++ b/src/plugins/data_views/server/fetcher/index_not_found_exception.json @@ -0,0 +1,21 @@ +{ + "error" : { + "root_cause" : [ + { + "type" : "index_not_found_exception", + "reason" : "no such index [poop]", + "resource.type" : "index_or_alias", + "resource.id" : "poop", + "index_uuid" : "_na_", + "index" : "poop" + } + ], + "type" : "index_not_found_exception", + "reason" : "no such index [poop]", + "resource.type" : "index_or_alias", + "resource.id" : "poop", + "index_uuid" : "_na_", + "index" : "poop" + }, + "status" : 404 +} diff --git a/src/plugins/data/server/data_views/fetcher/index_patterns_fetcher.test.ts b/src/plugins/data_views/server/fetcher/index_patterns_fetcher.test.ts similarity index 95% rename from src/plugins/data/server/data_views/fetcher/index_patterns_fetcher.test.ts rename to src/plugins/data_views/server/fetcher/index_patterns_fetcher.test.ts index 4bd21fb3a1820..a65d4d551cf7c 100644 --- a/src/plugins/data/server/data_views/fetcher/index_patterns_fetcher.test.ts +++ b/src/plugins/data_views/server/fetcher/index_patterns_fetcher.test.ts @@ -8,7 +8,7 @@ import { IndexPatternsFetcher } from '.'; import { ElasticsearchClient } from 'kibana/server'; -import * as indexNotFoundException from '../../../common/search/test_data/index_not_found_exception.json'; +import * as indexNotFoundException from './index_not_found_exception.json'; describe('Index Pattern Fetcher - server', () => { let indexPatterns: IndexPatternsFetcher; diff --git a/src/plugins/data/server/data_views/fetcher/index_patterns_fetcher.ts b/src/plugins/data_views/server/fetcher/index_patterns_fetcher.ts similarity index 100% rename from src/plugins/data/server/data_views/fetcher/index_patterns_fetcher.ts rename to src/plugins/data_views/server/fetcher/index_patterns_fetcher.ts diff --git a/src/plugins/data/server/data_views/fetcher/lib/errors.ts b/src/plugins/data_views/server/fetcher/lib/errors.ts similarity index 100% rename from src/plugins/data/server/data_views/fetcher/lib/errors.ts rename to src/plugins/data_views/server/fetcher/lib/errors.ts diff --git a/src/plugins/data/server/data_views/fetcher/lib/es_api.test.js b/src/plugins/data_views/server/fetcher/lib/es_api.test.js similarity index 100% rename from src/plugins/data/server/data_views/fetcher/lib/es_api.test.js rename to src/plugins/data_views/server/fetcher/lib/es_api.test.js diff --git a/src/plugins/data/server/data_views/fetcher/lib/es_api.ts b/src/plugins/data_views/server/fetcher/lib/es_api.ts similarity index 100% rename from src/plugins/data/server/data_views/fetcher/lib/es_api.ts rename to src/plugins/data_views/server/fetcher/lib/es_api.ts diff --git a/src/plugins/data/server/data_views/fetcher/lib/field_capabilities/__fixtures__/es_field_caps_response.json b/src/plugins/data_views/server/fetcher/lib/field_capabilities/__fixtures__/es_field_caps_response.json similarity index 100% rename from src/plugins/data/server/data_views/fetcher/lib/field_capabilities/__fixtures__/es_field_caps_response.json rename to src/plugins/data_views/server/fetcher/lib/field_capabilities/__fixtures__/es_field_caps_response.json diff --git a/src/plugins/data/server/data_views/fetcher/lib/field_capabilities/field_capabilities.test.js b/src/plugins/data_views/server/fetcher/lib/field_capabilities/field_capabilities.test.js similarity index 100% rename from src/plugins/data/server/data_views/fetcher/lib/field_capabilities/field_capabilities.test.js rename to src/plugins/data_views/server/fetcher/lib/field_capabilities/field_capabilities.test.js diff --git a/src/plugins/data/server/data_views/fetcher/lib/field_capabilities/field_capabilities.ts b/src/plugins/data_views/server/fetcher/lib/field_capabilities/field_capabilities.ts similarity index 100% rename from src/plugins/data/server/data_views/fetcher/lib/field_capabilities/field_capabilities.ts rename to src/plugins/data_views/server/fetcher/lib/field_capabilities/field_capabilities.ts diff --git a/src/plugins/data/server/data_views/fetcher/lib/field_capabilities/field_caps_response.test.js b/src/plugins/data_views/server/fetcher/lib/field_capabilities/field_caps_response.test.js similarity index 99% rename from src/plugins/data/server/data_views/fetcher/lib/field_capabilities/field_caps_response.test.js rename to src/plugins/data_views/server/fetcher/lib/field_capabilities/field_caps_response.test.js index c12eff1b5a377..f1e3f314351de 100644 --- a/src/plugins/data/server/data_views/fetcher/lib/field_capabilities/field_caps_response.test.js +++ b/src/plugins/data_views/server/fetcher/lib/field_capabilities/field_caps_response.test.js @@ -13,7 +13,7 @@ import sinon from 'sinon'; import * as shouldReadFieldFromDocValuesNS from './should_read_field_from_doc_values'; import { shouldReadFieldFromDocValues } from './should_read_field_from_doc_values'; -import { getKbnFieldType } from '../../../../../common'; +import { getKbnFieldType } from '@kbn/field-types'; import { readFieldCapsResponse } from './field_caps_response'; import esResponse from './__fixtures__/es_field_caps_response.json'; diff --git a/src/plugins/data/server/data_views/fetcher/lib/field_capabilities/field_caps_response.ts b/src/plugins/data_views/server/fetcher/lib/field_capabilities/field_caps_response.ts similarity index 98% rename from src/plugins/data/server/data_views/fetcher/lib/field_capabilities/field_caps_response.ts rename to src/plugins/data_views/server/fetcher/lib/field_capabilities/field_caps_response.ts index 3f83fd71b74e4..6dff343f9e00e 100644 --- a/src/plugins/data/server/data_views/fetcher/lib/field_capabilities/field_caps_response.ts +++ b/src/plugins/data_views/server/fetcher/lib/field_capabilities/field_caps_response.ts @@ -8,7 +8,7 @@ import { uniq } from 'lodash'; import type { estypes } from '@elastic/elasticsearch'; -import { castEsToKbnFieldTypeName } from '../../../../../common'; +import { castEsToKbnFieldTypeName } from '@kbn/field-types'; import { shouldReadFieldFromDocValues } from './should_read_field_from_doc_values'; import { FieldDescriptor } from '../../../fetcher'; diff --git a/src/plugins/data/server/data_views/fetcher/lib/field_capabilities/index.ts b/src/plugins/data_views/server/fetcher/lib/field_capabilities/index.ts similarity index 100% rename from src/plugins/data/server/data_views/fetcher/lib/field_capabilities/index.ts rename to src/plugins/data_views/server/fetcher/lib/field_capabilities/index.ts diff --git a/src/plugins/data/server/data_views/fetcher/lib/field_capabilities/overrides.ts b/src/plugins/data_views/server/fetcher/lib/field_capabilities/overrides.ts similarity index 100% rename from src/plugins/data/server/data_views/fetcher/lib/field_capabilities/overrides.ts rename to src/plugins/data_views/server/fetcher/lib/field_capabilities/overrides.ts diff --git a/src/plugins/data/server/data_views/fetcher/lib/field_capabilities/should_read_field_from_doc_values.test.ts b/src/plugins/data_views/server/fetcher/lib/field_capabilities/should_read_field_from_doc_values.test.ts similarity index 100% rename from src/plugins/data/server/data_views/fetcher/lib/field_capabilities/should_read_field_from_doc_values.test.ts rename to src/plugins/data_views/server/fetcher/lib/field_capabilities/should_read_field_from_doc_values.test.ts diff --git a/src/plugins/data/server/data_views/fetcher/lib/field_capabilities/should_read_field_from_doc_values.ts b/src/plugins/data_views/server/fetcher/lib/field_capabilities/should_read_field_from_doc_values.ts similarity index 100% rename from src/plugins/data/server/data_views/fetcher/lib/field_capabilities/should_read_field_from_doc_values.ts rename to src/plugins/data_views/server/fetcher/lib/field_capabilities/should_read_field_from_doc_values.ts diff --git a/src/plugins/data/server/data_views/fetcher/lib/index.ts b/src/plugins/data_views/server/fetcher/lib/index.ts similarity index 100% rename from src/plugins/data/server/data_views/fetcher/lib/index.ts rename to src/plugins/data_views/server/fetcher/lib/index.ts diff --git a/src/plugins/data/server/data_views/fetcher/lib/jobs_compatibility.test.js b/src/plugins/data_views/server/fetcher/lib/jobs_compatibility.test.js similarity index 100% rename from src/plugins/data/server/data_views/fetcher/lib/jobs_compatibility.test.js rename to src/plugins/data_views/server/fetcher/lib/jobs_compatibility.test.js diff --git a/src/plugins/data/server/data_views/fetcher/lib/jobs_compatibility.ts b/src/plugins/data_views/server/fetcher/lib/jobs_compatibility.ts similarity index 100% rename from src/plugins/data/server/data_views/fetcher/lib/jobs_compatibility.ts rename to src/plugins/data_views/server/fetcher/lib/jobs_compatibility.ts diff --git a/src/plugins/data/server/data_views/fetcher/lib/map_capabilities.ts b/src/plugins/data_views/server/fetcher/lib/map_capabilities.ts similarity index 100% rename from src/plugins/data/server/data_views/fetcher/lib/map_capabilities.ts rename to src/plugins/data_views/server/fetcher/lib/map_capabilities.ts diff --git a/src/plugins/data/server/data_views/fetcher/lib/merge_capabilities_with_fields.ts b/src/plugins/data_views/server/fetcher/lib/merge_capabilities_with_fields.ts similarity index 100% rename from src/plugins/data/server/data_views/fetcher/lib/merge_capabilities_with_fields.ts rename to src/plugins/data_views/server/fetcher/lib/merge_capabilities_with_fields.ts diff --git a/src/plugins/data/server/data_views/fetcher/lib/resolve_time_pattern.test.js b/src/plugins/data_views/server/fetcher/lib/resolve_time_pattern.test.js similarity index 100% rename from src/plugins/data/server/data_views/fetcher/lib/resolve_time_pattern.test.js rename to src/plugins/data_views/server/fetcher/lib/resolve_time_pattern.test.js diff --git a/src/plugins/data/server/data_views/fetcher/lib/resolve_time_pattern.ts b/src/plugins/data_views/server/fetcher/lib/resolve_time_pattern.ts similarity index 100% rename from src/plugins/data/server/data_views/fetcher/lib/resolve_time_pattern.ts rename to src/plugins/data_views/server/fetcher/lib/resolve_time_pattern.ts diff --git a/src/plugins/data/server/data_views/fetcher/lib/time_pattern_to_wildcard.test.ts b/src/plugins/data_views/server/fetcher/lib/time_pattern_to_wildcard.test.ts similarity index 100% rename from src/plugins/data/server/data_views/fetcher/lib/time_pattern_to_wildcard.test.ts rename to src/plugins/data_views/server/fetcher/lib/time_pattern_to_wildcard.test.ts diff --git a/src/plugins/data/server/data_views/fetcher/lib/time_pattern_to_wildcard.ts b/src/plugins/data_views/server/fetcher/lib/time_pattern_to_wildcard.ts similarity index 100% rename from src/plugins/data/server/data_views/fetcher/lib/time_pattern_to_wildcard.ts rename to src/plugins/data_views/server/fetcher/lib/time_pattern_to_wildcard.ts diff --git a/src/plugins/data/server/data_views/has_user_index_pattern.test.ts b/src/plugins/data_views/server/has_user_index_pattern.test.ts similarity index 99% rename from src/plugins/data/server/data_views/has_user_index_pattern.test.ts rename to src/plugins/data_views/server/has_user_index_pattern.test.ts index efc149b409375..aeaa64b949dbc 100644 --- a/src/plugins/data/server/data_views/has_user_index_pattern.test.ts +++ b/src/plugins/data_views/server/has_user_index_pattern.test.ts @@ -7,7 +7,7 @@ */ import { hasUserIndexPattern } from './has_user_index_pattern'; -import { elasticsearchServiceMock, savedObjectsClientMock } from '../../../../core/server/mocks'; +import { elasticsearchServiceMock, savedObjectsClientMock } from '../../../core/server/mocks'; describe('hasUserIndexPattern', () => { const esClient = elasticsearchServiceMock.createScopedClusterClient().asCurrentUser; diff --git a/src/plugins/data/server/data_views/has_user_index_pattern.ts b/src/plugins/data_views/server/has_user_index_pattern.ts similarity index 91% rename from src/plugins/data/server/data_views/has_user_index_pattern.ts rename to src/plugins/data_views/server/has_user_index_pattern.ts index 97abd0892b836..6566f75ebc52e 100644 --- a/src/plugins/data/server/data_views/has_user_index_pattern.ts +++ b/src/plugins/data_views/server/has_user_index_pattern.ts @@ -6,9 +6,9 @@ * Side Public License, v 1. */ -import { ElasticsearchClient, SavedObjectsClientContract } from '../../../../core/server'; -import { IndexPatternSavedObjectAttrs } from '../../common/data_views/data_views'; -import { FLEET_ASSETS_TO_IGNORE } from '../../common/data_views/constants'; +import { ElasticsearchClient, SavedObjectsClientContract } from '../../../core/server'; +import { IndexPatternSavedObjectAttrs } from '../common/data_views'; +import { FLEET_ASSETS_TO_IGNORE } from '../common/constants'; interface Deps { esClient: ElasticsearchClient; diff --git a/src/plugins/data_views/server/index.ts b/src/plugins/data_views/server/index.ts new file mode 100644 index 0000000000000..1c7eeb073bbe2 --- /dev/null +++ b/src/plugins/data_views/server/index.ts @@ -0,0 +1,37 @@ +/* + * 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. + */ + +export { getFieldByName, findIndexPatternById } from './utils'; +export { + IndexPatternsFetcher, + FieldDescriptor, + shouldReadFieldFromDocValues, + mergeCapabilitiesWithFields, + getCapabilitiesForRollupIndices, +} from './fetcher'; +export { IndexPatternsServiceStart } from './types'; + +import { PluginInitializerContext } from 'src/core/server'; +import { DataViewsServerPlugin } from './plugin'; +import { DataViewsServerPluginSetup, DataViewsServerPluginStart } from './types'; +export type { dataViewsServiceFactory } from './data_views_service_factory'; + +/** + * Static code to be shared externally + * @public + */ + +export function plugin(initializerContext: PluginInitializerContext) { + return new DataViewsServerPlugin(initializerContext); +} + +export { + DataViewsServerPlugin as Plugin, + DataViewsServerPluginSetup as PluginSetup, + DataViewsServerPluginStart as PluginStart, +}; diff --git a/src/plugins/data/server/data_views/index_patterns_api_client.ts b/src/plugins/data_views/server/index_patterns_api_client.ts similarity index 94% rename from src/plugins/data/server/data_views/index_patterns_api_client.ts rename to src/plugins/data_views/server/index_patterns_api_client.ts index 4f71bf218dd4d..26ccdd7e02b4c 100644 --- a/src/plugins/data/server/data_views/index_patterns_api_client.ts +++ b/src/plugins/data_views/server/index_patterns_api_client.ts @@ -11,8 +11,8 @@ import { GetFieldsOptions, IIndexPatternsApiClient, GetFieldsOptionsTimePattern, -} from '../../common/data_views/types'; -import { DataViewMissingIndices } from '../../common/data_views/lib'; +} from '../common/types'; +import { DataViewMissingIndices } from '../common/lib'; import { IndexPatternsFetcher } from './fetcher'; import { hasUserIndexPattern } from './has_user_index_pattern'; diff --git a/src/plugins/data_views/server/mocks.ts b/src/plugins/data_views/server/mocks.ts new file mode 100644 index 0000000000000..70a582810a1e2 --- /dev/null +++ b/src/plugins/data_views/server/mocks.ts @@ -0,0 +1,15 @@ +/* + * 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. + */ + +export function createIndexPatternsStartMock() { + const dataViewsServiceFactory = jest.fn().mockResolvedValue({ get: jest.fn() }); + return { + indexPatternsServiceFactory: dataViewsServiceFactory, + dataViewsServiceFactory, + }; +} diff --git a/src/plugins/data_views/server/plugin.ts b/src/plugins/data_views/server/plugin.ts new file mode 100644 index 0000000000000..7285e74847e58 --- /dev/null +++ b/src/plugins/data_views/server/plugin.ts @@ -0,0 +1,74 @@ +/* + * 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. + */ + +import { CoreSetup, CoreStart, Logger, Plugin, PluginInitializerContext } from 'src/core/server'; +import { dataViewsServiceFactory } from './data_views_service_factory'; +import { registerRoutes } from './routes'; +import { dataViewSavedObjectType } from './saved_objects'; +import { capabilitiesProvider } from './capabilities_provider'; +import { getIndexPatternLoad } from './expressions'; +import { registerIndexPatternsUsageCollector } from './register_index_pattern_usage_collection'; +import { createScriptedFieldsDeprecationsConfig } from './deprecations'; +import { + DataViewsServerPluginSetup, + DataViewsServerPluginStart, + DataViewsServerPluginSetupDependencies, + DataViewsServerPluginStartDependencies, +} from './types'; + +export class DataViewsServerPlugin + implements + Plugin< + DataViewsServerPluginSetup, + DataViewsServerPluginStart, + DataViewsServerPluginSetupDependencies, + DataViewsServerPluginStartDependencies + > +{ + private readonly logger: Logger; + + constructor(initializerContext: PluginInitializerContext) { + this.logger = initializerContext.logger.get('dataView'); + } + + public setup( + core: CoreSetup, + { expressions, usageCollection }: DataViewsServerPluginSetupDependencies + ) { + core.savedObjects.registerType(dataViewSavedObjectType); + core.capabilities.registerProvider(capabilitiesProvider); + + registerRoutes(core.http, core.getStartServices); + + expressions.registerFunction(getIndexPatternLoad({ getStartServices: core.getStartServices })); + registerIndexPatternsUsageCollector(core.getStartServices, usageCollection); + core.deprecations.registerDeprecations(createScriptedFieldsDeprecationsConfig(core)); + + return {}; + } + + public start( + { uiSettings }: CoreStart, + { fieldFormats }: DataViewsServerPluginStartDependencies + ) { + const serviceFactory = dataViewsServiceFactory({ + logger: this.logger.get('indexPatterns'), + uiSettings, + fieldFormats, + }); + + return { + indexPatternsServiceFactory: serviceFactory, + dataViewsServiceFactory: serviceFactory, + }; + } + + public stop() {} +} + +export { DataViewsServerPlugin as Plugin }; diff --git a/src/plugins/data/server/data_views/register_index_pattern_usage_collection.test.ts b/src/plugins/data_views/server/register_index_pattern_usage_collection.test.ts similarity index 98% rename from src/plugins/data/server/data_views/register_index_pattern_usage_collection.test.ts rename to src/plugins/data_views/server/register_index_pattern_usage_collection.test.ts index 2c826185757d6..01d3a574a58cb 100644 --- a/src/plugins/data/server/data_views/register_index_pattern_usage_collection.test.ts +++ b/src/plugins/data_views/server/register_index_pattern_usage_collection.test.ts @@ -12,7 +12,7 @@ import { updateMax, getIndexPatternTelemetry, } from './register_index_pattern_usage_collection'; -import { IndexPatternsCommonService } from '..'; +import { DataViewsService } from '../common'; const scriptA = 'emit(0);'; const scriptB = 'emit(1);\nemit(2);'; @@ -32,7 +32,7 @@ const indexPatterns = { getScriptedFields: () => [], fields: [], }), -} as any as IndexPatternsCommonService; +} as any as DataViewsService; describe('index pattern usage collection', () => { it('minMaxAvgLoC calculates min, max, and average ', () => { diff --git a/src/plugins/data/server/data_views/register_index_pattern_usage_collection.ts b/src/plugins/data_views/server/register_index_pattern_usage_collection.ts similarity index 90% rename from src/plugins/data/server/data_views/register_index_pattern_usage_collection.ts rename to src/plugins/data_views/server/register_index_pattern_usage_collection.ts index 36c2a59ce2753..6af2f6df6725e 100644 --- a/src/plugins/data/server/data_views/register_index_pattern_usage_collection.ts +++ b/src/plugins/data_views/server/register_index_pattern_usage_collection.ts @@ -8,9 +8,9 @@ import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; import { StartServicesAccessor } from 'src/core/server'; -import { IndexPatternsCommonService } from '..'; -import { SavedObjectsClient } from '../../../../core/server'; -import { DataPluginStartDependencies, DataPluginStart } from '../plugin'; +import { DataViewsService } from '../common'; +import { SavedObjectsClient } from '../../../core/server'; +import { DataViewsServerPluginStartDependencies, DataViewsServerPluginStart } from './types'; interface CountSummary { min?: number; @@ -57,7 +57,7 @@ export const updateMax = (currentMax: number | undefined, newVal: number): numbe } }; -export async function getIndexPatternTelemetry(indexPatterns: IndexPatternsCommonService) { +export async function getIndexPatternTelemetry(indexPatterns: DataViewsService) { const ids = await indexPatterns.getIds(); const countSummaryDefaults: CountSummary = { @@ -139,7 +139,10 @@ export async function getIndexPatternTelemetry(indexPatterns: IndexPatternsCommo } export function registerIndexPatternsUsageCollector( - getStartServices: StartServicesAccessor, + getStartServices: StartServicesAccessor< + DataViewsServerPluginStartDependencies, + DataViewsServerPluginStart + >, usageCollection?: UsageCollectionSetup ): void { if (!usageCollection) { @@ -150,8 +153,9 @@ export function registerIndexPatternsUsageCollector( type: 'index-patterns', isReady: () => true, fetch: async () => { - const [{ savedObjects, elasticsearch }, , { indexPatterns }] = await getStartServices(); - const indexPatternService = await indexPatterns.indexPatternsServiceFactory( + const [{ savedObjects, elasticsearch }, , { indexPatternsServiceFactory }] = + await getStartServices(); + const indexPatternService = await indexPatternsServiceFactory( new SavedObjectsClient(savedObjects.createInternalRepository()), elasticsearch.client.asInternalUser ); diff --git a/src/plugins/data/server/data_views/routes.ts b/src/plugins/data_views/server/routes.ts similarity index 96% rename from src/plugins/data/server/data_views/routes.ts rename to src/plugins/data_views/server/routes.ts index 9488285fc7e2c..48c359cd9d852 100644 --- a/src/plugins/data/server/data_views/routes.ts +++ b/src/plugins/data_views/server/routes.ts @@ -19,7 +19,7 @@ import { registerPutScriptedFieldRoute } from './routes/scripted_fields/put_scri import { registerGetScriptedFieldRoute } from './routes/scripted_fields/get_scripted_field'; import { registerDeleteScriptedFieldRoute } from './routes/scripted_fields/delete_scripted_field'; import { registerUpdateScriptedFieldRoute } from './routes/scripted_fields/update_scripted_field'; -import type { DataPluginStart, DataPluginStartDependencies } from '../plugin'; +import type { DataViewsServerPluginStart, DataViewsServerPluginStartDependencies } from './types'; import { registerManageDefaultIndexPatternRoutes } from './routes/default_index_pattern'; import { registerCreateRuntimeFieldRoute } from './routes/runtime_fields/create_runtime_field'; import { registerGetRuntimeFieldRoute } from './routes/runtime_fields/get_runtime_field'; @@ -30,7 +30,10 @@ import { registerHasUserIndexPatternRoute } from './routes/has_user_index_patter export function registerRoutes( http: HttpServiceSetup, - getStartServices: StartServicesAccessor + getStartServices: StartServicesAccessor< + DataViewsServerPluginStartDependencies, + DataViewsServerPluginStart + > ) { const parseMetaFields = (metaFields: string | string[]) => { let parsedFields: string[] = []; diff --git a/src/plugins/data/server/data_views/routes/create_index_pattern.ts b/src/plugins/data_views/server/routes/create_index_pattern.ts similarity index 84% rename from src/plugins/data/server/data_views/routes/create_index_pattern.ts rename to src/plugins/data_views/server/routes/create_index_pattern.ts index 7049903f84e8c..b87b03f8bd4a1 100644 --- a/src/plugins/data/server/data_views/routes/create_index_pattern.ts +++ b/src/plugins/data_views/server/routes/create_index_pattern.ts @@ -7,15 +7,15 @@ */ import { schema } from '@kbn/config-schema'; -import { IndexPatternSpec } from 'src/plugins/data/common'; +import { IndexPatternSpec } from 'src/plugins/data_views/common'; import { handleErrors } from './util/handle_errors'; import { fieldSpecSchema, runtimeFieldSpecSchema, serializedFieldFormatSchema, } from './util/schemas'; -import { IRouter, StartServicesAccessor } from '../../../../../core/server'; -import type { DataPluginStart, DataPluginStartDependencies } from '../../plugin'; +import { IRouter, StartServicesAccessor } from '../../../../core/server'; +import type { DataViewsServerPluginStart, DataViewsServerPluginStartDependencies } from '../types'; const indexPatternSpecSchema = schema.object({ title: schema.string(), @@ -48,7 +48,10 @@ const indexPatternSpecSchema = schema.object({ export const registerCreateIndexPatternRoute = ( router: IRouter, - getStartServices: StartServicesAccessor + getStartServices: StartServicesAccessor< + DataViewsServerPluginStartDependencies, + DataViewsServerPluginStart + > ) => { router.post( { @@ -65,8 +68,8 @@ export const registerCreateIndexPatternRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const [, , { indexPatterns }] = await getStartServices(); - const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( + const [, , { indexPatternsServiceFactory }] = await getStartServices(); + const indexPatternsService = await indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/data_views/routes/default_index_pattern.ts b/src/plugins/data_views/server/routes/default_index_pattern.ts similarity index 76% rename from src/plugins/data/server/data_views/routes/default_index_pattern.ts rename to src/plugins/data_views/server/routes/default_index_pattern.ts index cf5986943eb37..620e201a4850d 100644 --- a/src/plugins/data/server/data_views/routes/default_index_pattern.ts +++ b/src/plugins/data_views/server/routes/default_index_pattern.ts @@ -7,13 +7,16 @@ */ import { schema } from '@kbn/config-schema'; -import { IRouter, StartServicesAccessor } from '../../../../../core/server'; -import type { DataPluginStart, DataPluginStartDependencies } from '../../plugin'; +import { IRouter, StartServicesAccessor } from '../../../../core/server'; +import type { DataViewsServerPluginStart, DataViewsServerPluginStartDependencies } from '../types'; import { handleErrors } from './util/handle_errors'; export const registerManageDefaultIndexPatternRoutes = ( router: IRouter, - getStartServices: StartServicesAccessor + getStartServices: StartServicesAccessor< + DataViewsServerPluginStartDependencies, + DataViewsServerPluginStart + > ) => { router.get( { @@ -23,8 +26,8 @@ export const registerManageDefaultIndexPatternRoutes = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const [, , { indexPatterns }] = await getStartServices(); - const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( + const [, , { indexPatternsServiceFactory }] = await getStartServices(); + const indexPatternsService = await indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); @@ -57,8 +60,8 @@ export const registerManageDefaultIndexPatternRoutes = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const [, , { indexPatterns }] = await getStartServices(); - const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( + const [, , { indexPatternsServiceFactory }] = await getStartServices(); + const indexPatternsService = await indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/data_views/routes/delete_index_pattern.ts b/src/plugins/data_views/server/routes/delete_index_pattern.ts similarity index 75% rename from src/plugins/data/server/data_views/routes/delete_index_pattern.ts rename to src/plugins/data_views/server/routes/delete_index_pattern.ts index 14de079470dcb..0d3f929cdccc3 100644 --- a/src/plugins/data/server/data_views/routes/delete_index_pattern.ts +++ b/src/plugins/data_views/server/routes/delete_index_pattern.ts @@ -8,12 +8,15 @@ import { schema } from '@kbn/config-schema'; import { handleErrors } from './util/handle_errors'; -import { IRouter, StartServicesAccessor } from '../../../../../core/server'; -import type { DataPluginStart, DataPluginStartDependencies } from '../../plugin'; +import { IRouter, StartServicesAccessor } from '../../../../core/server'; +import type { DataViewsServerPluginStart, DataViewsServerPluginStartDependencies } from '../types'; export const registerDeleteIndexPatternRoute = ( router: IRouter, - getStartServices: StartServicesAccessor + getStartServices: StartServicesAccessor< + DataViewsServerPluginStartDependencies, + DataViewsServerPluginStart + > ) => { router.delete( { @@ -34,8 +37,8 @@ export const registerDeleteIndexPatternRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const [, , { indexPatterns }] = await getStartServices(); - const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( + const [, , { indexPatternsServiceFactory }] = await getStartServices(); + const indexPatternsService = await indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/data_views/routes/fields/update_fields.ts b/src/plugins/data_views/server/routes/fields/update_fields.ts similarity index 87% rename from src/plugins/data/server/data_views/routes/fields/update_fields.ts rename to src/plugins/data_views/server/routes/fields/update_fields.ts index a510fdaa6e1d8..3e45ee46f2bb7 100644 --- a/src/plugins/data/server/data_views/routes/fields/update_fields.ts +++ b/src/plugins/data_views/server/routes/fields/update_fields.ts @@ -9,12 +9,18 @@ import { schema } from '@kbn/config-schema'; import { handleErrors } from '../util/handle_errors'; import { serializedFieldFormatSchema } from '../util/schemas'; -import { IRouter, StartServicesAccessor } from '../../../../../../core/server'; -import type { DataPluginStart, DataPluginStartDependencies } from '../../../plugin'; +import { IRouter, StartServicesAccessor } from '../../../../../core/server'; +import type { + DataViewsServerPluginStart, + DataViewsServerPluginStartDependencies, +} from '../../types'; export const registerUpdateFieldsRoute = ( router: IRouter, - getStartServices: StartServicesAccessor + getStartServices: StartServicesAccessor< + DataViewsServerPluginStartDependencies, + DataViewsServerPluginStart + > ) => { router.post( { @@ -55,8 +61,8 @@ export const registerUpdateFieldsRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const [, , { indexPatterns }] = await getStartServices(); - const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( + const [, , { indexPatternsServiceFactory }] = await getStartServices(); + const indexPatternsService = await indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/data_views/routes/get_index_pattern.ts b/src/plugins/data_views/server/routes/get_index_pattern.ts similarity index 76% rename from src/plugins/data/server/data_views/routes/get_index_pattern.ts rename to src/plugins/data_views/server/routes/get_index_pattern.ts index 268fd3da8cd6a..7fea748ca3389 100644 --- a/src/plugins/data/server/data_views/routes/get_index_pattern.ts +++ b/src/plugins/data_views/server/routes/get_index_pattern.ts @@ -8,12 +8,15 @@ import { schema } from '@kbn/config-schema'; import { handleErrors } from './util/handle_errors'; -import { IRouter, StartServicesAccessor } from '../../../../../core/server'; -import type { DataPluginStart, DataPluginStartDependencies } from '../../plugin'; +import { IRouter, StartServicesAccessor } from '../../../../core/server'; +import type { DataViewsServerPluginStart, DataViewsServerPluginStartDependencies } from '../types'; export const registerGetIndexPatternRoute = ( router: IRouter, - getStartServices: StartServicesAccessor + getStartServices: StartServicesAccessor< + DataViewsServerPluginStartDependencies, + DataViewsServerPluginStart + > ) => { router.get( { @@ -34,8 +37,8 @@ export const registerGetIndexPatternRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const [, , { indexPatterns }] = await getStartServices(); - const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( + const [, , { indexPatternsServiceFactory }] = await getStartServices(); + const indexPatternsService = await indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/data_views/routes/has_user_index_pattern.ts b/src/plugins/data_views/server/routes/has_user_index_pattern.ts similarity index 69% rename from src/plugins/data/server/data_views/routes/has_user_index_pattern.ts rename to src/plugins/data_views/server/routes/has_user_index_pattern.ts index 7d67e96f39f6e..af0ad1cc88d2e 100644 --- a/src/plugins/data/server/data_views/routes/has_user_index_pattern.ts +++ b/src/plugins/data_views/server/routes/has_user_index_pattern.ts @@ -7,12 +7,15 @@ */ import { handleErrors } from './util/handle_errors'; -import { IRouter, StartServicesAccessor } from '../../../../../core/server'; -import type { DataPluginStart, DataPluginStartDependencies } from '../../plugin'; +import { IRouter, StartServicesAccessor } from '../../../../core/server'; +import type { DataViewsServerPluginStart, DataViewsServerPluginStartDependencies } from '../types'; export const registerHasUserIndexPatternRoute = ( router: IRouter, - getStartServices: StartServicesAccessor + getStartServices: StartServicesAccessor< + DataViewsServerPluginStartDependencies, + DataViewsServerPluginStart + > ) => { router.get( { @@ -23,8 +26,8 @@ export const registerHasUserIndexPatternRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const [, , { indexPatterns }] = await getStartServices(); - const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( + const [, , { indexPatternsServiceFactory }] = await getStartServices(); + const indexPatternsService = await indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/data_views/routes/runtime_fields/create_runtime_field.ts b/src/plugins/data_views/server/routes/runtime_fields/create_runtime_field.ts similarity index 82% rename from src/plugins/data/server/data_views/routes/runtime_fields/create_runtime_field.ts rename to src/plugins/data_views/server/routes/runtime_fields/create_runtime_field.ts index faf6d87b6d10b..04b661d14732f 100644 --- a/src/plugins/data/server/data_views/routes/runtime_fields/create_runtime_field.ts +++ b/src/plugins/data_views/server/routes/runtime_fields/create_runtime_field.ts @@ -9,12 +9,18 @@ import { schema } from '@kbn/config-schema'; import { handleErrors } from '../util/handle_errors'; import { runtimeFieldSpecSchema } from '../util/schemas'; -import { IRouter, StartServicesAccessor } from '../../../../../../core/server'; -import type { DataPluginStart, DataPluginStartDependencies } from '../../../plugin'; +import { IRouter, StartServicesAccessor } from '../../../../../core/server'; +import type { + DataViewsServerPluginStart, + DataViewsServerPluginStartDependencies, +} from '../../types'; export const registerCreateRuntimeFieldRoute = ( router: IRouter, - getStartServices: StartServicesAccessor + getStartServices: StartServicesAccessor< + DataViewsServerPluginStartDependencies, + DataViewsServerPluginStart + > ) => { router.post( { @@ -39,8 +45,8 @@ export const registerCreateRuntimeFieldRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const [, , { indexPatterns }] = await getStartServices(); - const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( + const [, , { indexPatternsServiceFactory }] = await getStartServices(); + const indexPatternsService = await indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/data_views/routes/runtime_fields/delete_runtime_field.ts b/src/plugins/data_views/server/routes/runtime_fields/delete_runtime_field.ts similarity index 79% rename from src/plugins/data/server/data_views/routes/runtime_fields/delete_runtime_field.ts rename to src/plugins/data_views/server/routes/runtime_fields/delete_runtime_field.ts index 58b8529d7cf5a..e5c6b03a64224 100644 --- a/src/plugins/data/server/data_views/routes/runtime_fields/delete_runtime_field.ts +++ b/src/plugins/data_views/server/routes/runtime_fields/delete_runtime_field.ts @@ -9,12 +9,18 @@ import { schema } from '@kbn/config-schema'; import { ErrorIndexPatternFieldNotFound } from '../../error'; import { handleErrors } from '../util/handle_errors'; -import { IRouter, StartServicesAccessor } from '../../../../../../core/server'; -import type { DataPluginStart, DataPluginStartDependencies } from '../../../plugin'; +import { IRouter, StartServicesAccessor } from '../../../../../core/server'; +import type { + DataViewsServerPluginStart, + DataViewsServerPluginStartDependencies, +} from '../../types'; export const registerDeleteRuntimeFieldRoute = ( router: IRouter, - getStartServices: StartServicesAccessor + getStartServices: StartServicesAccessor< + DataViewsServerPluginStartDependencies, + DataViewsServerPluginStart + > ) => { router.delete( { @@ -35,8 +41,8 @@ export const registerDeleteRuntimeFieldRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const [, , { indexPatterns }] = await getStartServices(); - const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( + const [, , { indexPatternsServiceFactory }] = await getStartServices(); + const indexPatternsService = await indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/data_views/routes/runtime_fields/get_runtime_field.ts b/src/plugins/data_views/server/routes/runtime_fields/get_runtime_field.ts similarity index 79% rename from src/plugins/data/server/data_views/routes/runtime_fields/get_runtime_field.ts rename to src/plugins/data_views/server/routes/runtime_fields/get_runtime_field.ts index 6bc2bf396c0b4..b457ae6b0159b 100644 --- a/src/plugins/data/server/data_views/routes/runtime_fields/get_runtime_field.ts +++ b/src/plugins/data_views/server/routes/runtime_fields/get_runtime_field.ts @@ -9,12 +9,18 @@ import { schema } from '@kbn/config-schema'; import { ErrorIndexPatternFieldNotFound } from '../../error'; import { handleErrors } from '../util/handle_errors'; -import { IRouter, StartServicesAccessor } from '../../../../../../core/server'; -import type { DataPluginStart, DataPluginStartDependencies } from '../../../plugin'; +import { IRouter, StartServicesAccessor } from '../../../../../core/server'; +import type { + DataViewsServerPluginStart, + DataViewsServerPluginStartDependencies, +} from '../../types'; export const registerGetRuntimeFieldRoute = ( router: IRouter, - getStartServices: StartServicesAccessor + getStartServices: StartServicesAccessor< + DataViewsServerPluginStartDependencies, + DataViewsServerPluginStart + > ) => { router.get( { @@ -36,8 +42,8 @@ export const registerGetRuntimeFieldRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const [, , { indexPatterns }] = await getStartServices(); - const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( + const [, , { indexPatternsServiceFactory }] = await getStartServices(); + const indexPatternsService = await indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/data_views/routes/runtime_fields/put_runtime_field.ts b/src/plugins/data_views/server/routes/runtime_fields/put_runtime_field.ts similarity index 82% rename from src/plugins/data/server/data_views/routes/runtime_fields/put_runtime_field.ts rename to src/plugins/data_views/server/routes/runtime_fields/put_runtime_field.ts index a5e92fa5a36ec..1c3ed99fdf67e 100644 --- a/src/plugins/data/server/data_views/routes/runtime_fields/put_runtime_field.ts +++ b/src/plugins/data_views/server/routes/runtime_fields/put_runtime_field.ts @@ -9,12 +9,18 @@ import { schema } from '@kbn/config-schema'; import { handleErrors } from '../util/handle_errors'; import { runtimeFieldSpecSchema } from '../util/schemas'; -import { IRouter, StartServicesAccessor } from '../../../../../../core/server'; -import type { DataPluginStart, DataPluginStartDependencies } from '../../../plugin'; +import { IRouter, StartServicesAccessor } from '../../../../../core/server'; +import type { + DataViewsServerPluginStart, + DataViewsServerPluginStartDependencies, +} from '../../types'; export const registerPutRuntimeFieldRoute = ( router: IRouter, - getStartServices: StartServicesAccessor + getStartServices: StartServicesAccessor< + DataViewsServerPluginStartDependencies, + DataViewsServerPluginStart + > ) => { router.put( { @@ -38,8 +44,8 @@ export const registerPutRuntimeFieldRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const [, , { indexPatterns }] = await getStartServices(); - const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( + const [, , { indexPatternsServiceFactory }] = await getStartServices(); + const indexPatternsService = await indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/data_views/routes/runtime_fields/update_runtime_field.ts b/src/plugins/data_views/server/routes/runtime_fields/update_runtime_field.ts similarity index 83% rename from src/plugins/data/server/data_views/routes/runtime_fields/update_runtime_field.ts rename to src/plugins/data_views/server/routes/runtime_fields/update_runtime_field.ts index 3f3aae46c4388..ca92f310ff281 100644 --- a/src/plugins/data/server/data_views/routes/runtime_fields/update_runtime_field.ts +++ b/src/plugins/data_views/server/routes/runtime_fields/update_runtime_field.ts @@ -7,16 +7,22 @@ */ import { schema } from '@kbn/config-schema'; -import { RuntimeField } from 'src/plugins/data/common'; +import { RuntimeField } from 'src/plugins/data_views/common'; import { ErrorIndexPatternFieldNotFound } from '../../error'; import { handleErrors } from '../util/handle_errors'; import { runtimeFieldSpec, runtimeFieldSpecTypeSchema } from '../util/schemas'; -import { IRouter, StartServicesAccessor } from '../../../../../../core/server'; -import type { DataPluginStart, DataPluginStartDependencies } from '../../../plugin'; +import { IRouter, StartServicesAccessor } from '../../../../../core/server'; +import type { + DataViewsServerPluginStart, + DataViewsServerPluginStartDependencies, +} from '../../types'; export const registerUpdateRuntimeFieldRoute = ( router: IRouter, - getStartServices: StartServicesAccessor + getStartServices: StartServicesAccessor< + DataViewsServerPluginStartDependencies, + DataViewsServerPluginStart + > ) => { router.post( { @@ -46,8 +52,8 @@ export const registerUpdateRuntimeFieldRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const [, , { indexPatterns }] = await getStartServices(); - const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( + const [, , { indexPatternsServiceFactory }] = await getStartServices(); + const indexPatternsService = await indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/data_views/routes/scripted_fields/create_scripted_field.ts b/src/plugins/data_views/server/routes/scripted_fields/create_scripted_field.ts similarity index 83% rename from src/plugins/data/server/data_views/routes/scripted_fields/create_scripted_field.ts rename to src/plugins/data_views/server/routes/scripted_fields/create_scripted_field.ts index 4d7b1d87cd9eb..e620960afbe13 100644 --- a/src/plugins/data/server/data_views/routes/scripted_fields/create_scripted_field.ts +++ b/src/plugins/data_views/server/routes/scripted_fields/create_scripted_field.ts @@ -9,12 +9,18 @@ import { schema } from '@kbn/config-schema'; import { handleErrors } from '../util/handle_errors'; import { fieldSpecSchema } from '../util/schemas'; -import { IRouter, StartServicesAccessor } from '../../../../../../core/server'; -import type { DataPluginStart, DataPluginStartDependencies } from '../../../plugin'; +import { IRouter, StartServicesAccessor } from '../../../../../core/server'; +import type { + DataViewsServerPluginStart, + DataViewsServerPluginStartDependencies, +} from '../../types'; export const registerCreateScriptedFieldRoute = ( router: IRouter, - getStartServices: StartServicesAccessor + getStartServices: StartServicesAccessor< + DataViewsServerPluginStartDependencies, + DataViewsServerPluginStart + > ) => { router.post( { @@ -38,8 +44,8 @@ export const registerCreateScriptedFieldRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const [, , { indexPatterns }] = await getStartServices(); - const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( + const [, , { indexPatternsServiceFactory }] = await getStartServices(); + const indexPatternsService = await indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/data_views/routes/scripted_fields/delete_scripted_field.ts b/src/plugins/data_views/server/routes/scripted_fields/delete_scripted_field.ts similarity index 81% rename from src/plugins/data/server/data_views/routes/scripted_fields/delete_scripted_field.ts rename to src/plugins/data_views/server/routes/scripted_fields/delete_scripted_field.ts index 169351c220ecf..bd1bfe0ec4e25 100644 --- a/src/plugins/data/server/data_views/routes/scripted_fields/delete_scripted_field.ts +++ b/src/plugins/data_views/server/routes/scripted_fields/delete_scripted_field.ts @@ -9,12 +9,18 @@ import { schema } from '@kbn/config-schema'; import { ErrorIndexPatternFieldNotFound } from '../../error'; import { handleErrors } from '../util/handle_errors'; -import { IRouter, StartServicesAccessor } from '../../../../../../core/server'; -import type { DataPluginStart, DataPluginStartDependencies } from '../../../plugin'; +import { IRouter, StartServicesAccessor } from '../../../../../core/server'; +import type { + DataViewsServerPluginStart, + DataViewsServerPluginStartDependencies, +} from '../../types'; export const registerDeleteScriptedFieldRoute = ( router: IRouter, - getStartServices: StartServicesAccessor + getStartServices: StartServicesAccessor< + DataViewsServerPluginStartDependencies, + DataViewsServerPluginStart + > ) => { router.delete( { @@ -39,8 +45,8 @@ export const registerDeleteScriptedFieldRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const [, , { indexPatterns }] = await getStartServices(); - const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( + const [, , { indexPatternsServiceFactory }] = await getStartServices(); + const indexPatternsService = await indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/data_views/routes/scripted_fields/get_scripted_field.ts b/src/plugins/data_views/server/routes/scripted_fields/get_scripted_field.ts similarity index 81% rename from src/plugins/data/server/data_views/routes/scripted_fields/get_scripted_field.ts rename to src/plugins/data_views/server/routes/scripted_fields/get_scripted_field.ts index 28f3f75a7aa1b..ae9cca2c79b48 100644 --- a/src/plugins/data/server/data_views/routes/scripted_fields/get_scripted_field.ts +++ b/src/plugins/data_views/server/routes/scripted_fields/get_scripted_field.ts @@ -9,12 +9,18 @@ import { schema } from '@kbn/config-schema'; import { ErrorIndexPatternFieldNotFound } from '../../error'; import { handleErrors } from '../util/handle_errors'; -import { IRouter, StartServicesAccessor } from '../../../../../../core/server'; -import type { DataPluginStart, DataPluginStartDependencies } from '../../../plugin'; +import { IRouter, StartServicesAccessor } from '../../../../../core/server'; +import type { + DataViewsServerPluginStart, + DataViewsServerPluginStartDependencies, +} from '../../types'; export const registerGetScriptedFieldRoute = ( router: IRouter, - getStartServices: StartServicesAccessor + getStartServices: StartServicesAccessor< + DataViewsServerPluginStartDependencies, + DataViewsServerPluginStart + > ) => { router.get( { @@ -39,8 +45,8 @@ export const registerGetScriptedFieldRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const [, , { indexPatterns }] = await getStartServices(); - const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( + const [, , { indexPatternsServiceFactory }] = await getStartServices(); + const indexPatternsService = await indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/data_views/routes/scripted_fields/put_scripted_field.ts b/src/plugins/data_views/server/routes/scripted_fields/put_scripted_field.ts similarity index 83% rename from src/plugins/data/server/data_views/routes/scripted_fields/put_scripted_field.ts rename to src/plugins/data_views/server/routes/scripted_fields/put_scripted_field.ts index 368ad53eb2258..a6cee3762513e 100644 --- a/src/plugins/data/server/data_views/routes/scripted_fields/put_scripted_field.ts +++ b/src/plugins/data_views/server/routes/scripted_fields/put_scripted_field.ts @@ -9,12 +9,18 @@ import { schema } from '@kbn/config-schema'; import { handleErrors } from '../util/handle_errors'; import { fieldSpecSchema } from '../util/schemas'; -import { IRouter, StartServicesAccessor } from '../../../../../../core/server'; -import type { DataPluginStart, DataPluginStartDependencies } from '../../../plugin'; +import { IRouter, StartServicesAccessor } from '../../../../../core/server'; +import type { + DataViewsServerPluginStart, + DataViewsServerPluginStartDependencies, +} from '../../types'; export const registerPutScriptedFieldRoute = ( router: IRouter, - getStartServices: StartServicesAccessor + getStartServices: StartServicesAccessor< + DataViewsServerPluginStartDependencies, + DataViewsServerPluginStart + > ) => { router.put( { @@ -38,8 +44,8 @@ export const registerPutScriptedFieldRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const [, , { indexPatterns }] = await getStartServices(); - const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( + const [, , { indexPatternsServiceFactory }] = await getStartServices(); + const indexPatternsService = await indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/data_views/routes/scripted_fields/update_scripted_field.ts b/src/plugins/data_views/server/routes/scripted_fields/update_scripted_field.ts similarity index 86% rename from src/plugins/data/server/data_views/routes/scripted_fields/update_scripted_field.ts rename to src/plugins/data_views/server/routes/scripted_fields/update_scripted_field.ts index bf10a3ee6389e..2917838293ec8 100644 --- a/src/plugins/data/server/data_views/routes/scripted_fields/update_scripted_field.ts +++ b/src/plugins/data_views/server/routes/scripted_fields/update_scripted_field.ts @@ -7,16 +7,22 @@ */ import { schema } from '@kbn/config-schema'; -import { FieldSpec } from 'src/plugins/data/common'; +import { FieldSpec } from 'src/plugins/data_views/common'; import { ErrorIndexPatternFieldNotFound } from '../../error'; import { handleErrors } from '../util/handle_errors'; import { fieldSpecSchemaFields } from '../util/schemas'; -import { IRouter, StartServicesAccessor } from '../../../../../../core/server'; -import type { DataPluginStart, DataPluginStartDependencies } from '../../../plugin'; +import { IRouter, StartServicesAccessor } from '../../../../../core/server'; +import type { + DataViewsServerPluginStart, + DataViewsServerPluginStartDependencies, +} from '../../types'; export const registerUpdateScriptedFieldRoute = ( router: IRouter, - getStartServices: StartServicesAccessor + getStartServices: StartServicesAccessor< + DataViewsServerPluginStartDependencies, + DataViewsServerPluginStart + > ) => { router.post( { @@ -59,8 +65,8 @@ export const registerUpdateScriptedFieldRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const [, , { indexPatterns }] = await getStartServices(); - const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( + const [, , { indexPatternsServiceFactory }] = await getStartServices(); + const indexPatternsService = await indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/data_views/routes/update_index_pattern.ts b/src/plugins/data_views/server/routes/update_index_pattern.ts similarity index 91% rename from src/plugins/data/server/data_views/routes/update_index_pattern.ts rename to src/plugins/data_views/server/routes/update_index_pattern.ts index 1c88550c154c5..1421057d65d26 100644 --- a/src/plugins/data/server/data_views/routes/update_index_pattern.ts +++ b/src/plugins/data_views/server/routes/update_index_pattern.ts @@ -13,8 +13,8 @@ import { runtimeFieldSpecSchema, serializedFieldFormatSchema, } from './util/schemas'; -import { IRouter, StartServicesAccessor } from '../../../../../core/server'; -import type { DataPluginStart, DataPluginStartDependencies } from '../../plugin'; +import { IRouter, StartServicesAccessor } from '../../../../core/server'; +import type { DataViewsServerPluginStart, DataViewsServerPluginStartDependencies } from '../types'; const indexPatternUpdateSchema = schema.object({ title: schema.maybe(schema.string()), @@ -37,7 +37,10 @@ const indexPatternUpdateSchema = schema.object({ export const registerUpdateIndexPatternRoute = ( router: IRouter, - getStartServices: StartServicesAccessor + getStartServices: StartServicesAccessor< + DataViewsServerPluginStartDependencies, + DataViewsServerPluginStart + > ) => { router.post( { @@ -62,8 +65,8 @@ export const registerUpdateIndexPatternRoute = ( handleErrors(async (ctx, req, res) => { const savedObjectsClient = ctx.core.savedObjects.client; const elasticsearchClient = ctx.core.elasticsearch.client.asCurrentUser; - const [, , { indexPatterns }] = await getStartServices(); - const indexPatternsService = await indexPatterns.indexPatternsServiceFactory( + const [, , { indexPatternsServiceFactory }] = await getStartServices(); + const indexPatternsService = await indexPatternsServiceFactory( savedObjectsClient, elasticsearchClient ); diff --git a/src/plugins/data/server/data_views/routes/util/handle_errors.ts b/src/plugins/data_views/server/routes/util/handle_errors.ts similarity index 100% rename from src/plugins/data/server/data_views/routes/util/handle_errors.ts rename to src/plugins/data_views/server/routes/util/handle_errors.ts diff --git a/src/plugins/data/server/data_views/routes/util/schemas.ts b/src/plugins/data_views/server/routes/util/schemas.ts similarity index 96% rename from src/plugins/data/server/data_views/routes/util/schemas.ts rename to src/plugins/data_views/server/routes/util/schemas.ts index 79ee1ffa1ab97..79f493f303801 100644 --- a/src/plugins/data/server/data_views/routes/util/schemas.ts +++ b/src/plugins/data_views/server/routes/util/schemas.ts @@ -7,7 +7,7 @@ */ import { schema, Type } from '@kbn/config-schema'; -import { RUNTIME_FIELD_TYPES, RuntimeType } from '../../../../common'; +import { RUNTIME_FIELD_TYPES, RuntimeType } from '../../../common'; export const serializedFieldFormatSchema = schema.object({ id: schema.maybe(schema.string()), diff --git a/src/plugins/data/server/saved_objects/index_patterns.ts b/src/plugins/data_views/server/saved_objects/data_views.ts similarity index 88% rename from src/plugins/data/server/saved_objects/index_patterns.ts rename to src/plugins/data_views/server/saved_objects/data_views.ts index a809f2ce73e1b..d340732873235 100644 --- a/src/plugins/data/server/saved_objects/index_patterns.ts +++ b/src/plugins/data_views/server/saved_objects/data_views.ts @@ -8,10 +8,10 @@ import type { SavedObjectsType } from 'kibana/server'; import { indexPatternSavedObjectTypeMigrations } from './index_pattern_migrations'; -import { INDEX_PATTERN_SAVED_OBJECT_TYPE } from '../../common'; +import { DATA_VIEW_SAVED_OBJECT_TYPE } from '../../common'; -export const indexPatternSavedObjectType: SavedObjectsType = { - name: INDEX_PATTERN_SAVED_OBJECT_TYPE, +export const dataViewSavedObjectType: SavedObjectsType = { + name: DATA_VIEW_SAVED_OBJECT_TYPE, hidden: false, namespaceType: 'single', management: { diff --git a/src/plugins/data/common/utils/index.ts b/src/plugins/data_views/server/saved_objects/index.ts similarity index 81% rename from src/plugins/data/common/utils/index.ts rename to src/plugins/data_views/server/saved_objects/index.ts index e07fd18594471..ff0f524ae961c 100644 --- a/src/plugins/data/common/utils/index.ts +++ b/src/plugins/data_views/server/saved_objects/index.ts @@ -6,5 +6,4 @@ * Side Public License, v 1. */ -/** @internal */ -export { shortenDottedString } from './shorten_dotted_string'; +export { dataViewSavedObjectType } from './data_views'; diff --git a/src/plugins/data/server/saved_objects/index_pattern_migrations.test.ts b/src/plugins/data_views/server/saved_objects/index_pattern_migrations.test.ts similarity index 100% rename from src/plugins/data/server/saved_objects/index_pattern_migrations.test.ts rename to src/plugins/data_views/server/saved_objects/index_pattern_migrations.test.ts diff --git a/src/plugins/data/server/saved_objects/index_pattern_migrations.ts b/src/plugins/data_views/server/saved_objects/index_pattern_migrations.ts similarity index 100% rename from src/plugins/data/server/saved_objects/index_pattern_migrations.ts rename to src/plugins/data_views/server/saved_objects/index_pattern_migrations.ts diff --git a/src/plugins/data/common/utils/shorten_dotted_string.ts b/src/plugins/data_views/server/saved_objects/migrations/to_v7_12_0.ts similarity index 57% rename from src/plugins/data/common/utils/shorten_dotted_string.ts rename to src/plugins/data_views/server/saved_objects/migrations/to_v7_12_0.ts index 53f7471913dc3..955028c0f9bf2 100644 --- a/src/plugins/data/common/utils/shorten_dotted_string.ts +++ b/src/plugins/data_views/server/saved_objects/migrations/to_v7_12_0.ts @@ -6,14 +6,12 @@ * Side Public License, v 1. */ -const DOT_PREFIX_RE = /(.).+?\./g; +import type { SavedObjectMigrationFn } from 'kibana/server'; /** - * Convert a dot.notated.string into a short - * version (d.n.string) - * - * @return {any} + * Drop the previous document's attributes, which report `averageDuration` incorrectly. + * @param doc */ -export function shortenDottedString(input: any) { - return typeof input !== 'string' ? input : input.replace(DOT_PREFIX_RE, '$1.'); -} +export const migrate712: SavedObjectMigrationFn = (doc) => { + return { ...doc, attributes: {} }; +}; diff --git a/src/plugins/data/server/data_views/saved_objects_client_wrapper.test.ts b/src/plugins/data_views/server/saved_objects_client_wrapper.test.ts similarity index 96% rename from src/plugins/data/server/data_views/saved_objects_client_wrapper.test.ts rename to src/plugins/data_views/server/saved_objects_client_wrapper.test.ts index bbe857894b3f0..b03532421ecab 100644 --- a/src/plugins/data/server/data_views/saved_objects_client_wrapper.test.ts +++ b/src/plugins/data_views/server/saved_objects_client_wrapper.test.ts @@ -9,7 +9,7 @@ import { SavedObjectsClientServerToCommon } from './saved_objects_client_wrapper'; import { SavedObjectsClientContract } from 'src/core/server'; -import { DataViewSavedObjectConflictError } from '../../common/data_views'; +import { DataViewSavedObjectConflictError } from '../common'; describe('SavedObjectsClientPublicToCommon', () => { const soClient = { resolve: jest.fn() } as unknown as SavedObjectsClientContract; diff --git a/src/plugins/data/server/data_views/saved_objects_client_wrapper.ts b/src/plugins/data_views/server/saved_objects_client_wrapper.ts similarity index 98% rename from src/plugins/data/server/data_views/saved_objects_client_wrapper.ts rename to src/plugins/data_views/server/saved_objects_client_wrapper.ts index b37648a3f038e..dc7163c405d4f 100644 --- a/src/plugins/data/server/data_views/saved_objects_client_wrapper.ts +++ b/src/plugins/data_views/server/saved_objects_client_wrapper.ts @@ -11,7 +11,7 @@ import { SavedObjectsClientCommon, SavedObjectsClientCommonFindArgs, DataViewSavedObjectConflictError, -} from '../../common/data_views'; +} from '../common'; export class SavedObjectsClientServerToCommon implements SavedObjectsClientCommon { private savedObjectClient: SavedObjectsClientContract; diff --git a/src/plugins/data_views/server/types.ts b/src/plugins/data_views/server/types.ts new file mode 100644 index 0000000000000..4a57a1d01b9c3 --- /dev/null +++ b/src/plugins/data_views/server/types.ts @@ -0,0 +1,51 @@ +/* + * 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. + */ + +import { Logger, SavedObjectsClientContract, ElasticsearchClient } from 'kibana/server'; +import { ExpressionsServerSetup } from 'src/plugins/expressions/server'; +import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; +import { DataViewsService } from '../common'; +import { FieldFormatsSetup, FieldFormatsStart } from '../../field_formats/server'; + +type ServiceFactory = ( + savedObjectsClient: SavedObjectsClientContract, + elasticsearchClient: ElasticsearchClient +) => Promise; +export interface DataViewsServerPluginStart { + dataViewsServiceFactory: ServiceFactory; + /** + * @deprecated Renamed to dataViewsServiceFactory + */ + indexPatternsServiceFactory: ServiceFactory; +} + +export interface IndexPatternsServiceSetupDeps { + expressions: ExpressionsServerSetup; + usageCollection?: UsageCollectionSetup; +} + +export interface IndexPatternsServiceStartDeps { + fieldFormats: FieldFormatsStart; + logger: Logger; +} + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface DataViewsServerPluginSetup {} + +export type IndexPatternsServiceStart = DataViewsServerPluginStart; + +export interface DataViewsServerPluginSetupDependencies { + fieldFormats: FieldFormatsSetup; + expressions: ExpressionsServerSetup; + usageCollection?: UsageCollectionSetup; +} + +export interface DataViewsServerPluginStartDependencies { + fieldFormats: FieldFormatsStart; + logger: Logger; +} diff --git a/src/plugins/data/server/data_views/ui_settings_wrapper.ts b/src/plugins/data_views/server/ui_settings_wrapper.ts similarity index 95% rename from src/plugins/data/server/data_views/ui_settings_wrapper.ts rename to src/plugins/data_views/server/ui_settings_wrapper.ts index dce552205db2e..f42d43c1c24f4 100644 --- a/src/plugins/data/server/data_views/ui_settings_wrapper.ts +++ b/src/plugins/data_views/server/ui_settings_wrapper.ts @@ -7,7 +7,7 @@ */ import { IUiSettingsClient } from 'src/core/server'; -import { UiSettingsCommon } from '../../common'; +import { UiSettingsCommon } from '../common'; export class UiSettingsServerToCommon implements UiSettingsCommon { private uiSettings: IUiSettingsClient; diff --git a/src/plugins/data/server/data_views/utils.ts b/src/plugins/data_views/server/utils.ts similarity index 92% rename from src/plugins/data/server/data_views/utils.ts rename to src/plugins/data_views/server/utils.ts index 7f1a953c482d0..bb7d23f832233 100644 --- a/src/plugins/data/server/data_views/utils.ts +++ b/src/plugins/data_views/server/utils.ts @@ -9,10 +9,10 @@ import { SavedObjectsClientContract } from 'kibana/server'; import { IFieldType, - INDEX_PATTERN_SAVED_OBJECT_TYPE, + DATA_VIEW_SAVED_OBJECT_TYPE, IndexPatternAttributes, SavedObject, -} from '../../common'; +} from '../common'; export const getFieldByName = ( fieldName: string, @@ -29,7 +29,7 @@ export const findIndexPatternById = async ( index: string ): Promise | undefined> => { const savedObjectsResponse = await savedObjectsClient.find({ - type: INDEX_PATTERN_SAVED_OBJECT_TYPE, + type: DATA_VIEW_SAVED_OBJECT_TYPE, fields: ['fields'], search: `"${index}"`, searchFields: ['title'], diff --git a/src/plugins/data_views/tsconfig.json b/src/plugins/data_views/tsconfig.json new file mode 100644 index 0000000000000..f5c80ce30cce0 --- /dev/null +++ b/src/plugins/data_views/tsconfig.json @@ -0,0 +1,26 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./target/types", + "emitDeclarationOnly": true, + "declaration": true, + "declarationMap": true + }, + "include": [ + "common/**/*", + "public/**/*", + "server/**/*", + "config.ts", + "common/**/*.json", + "public/**/*.json", + "server/**/*.json" + ], + "references": [ + { "path": "../../core/tsconfig.json" }, + { "path": "../usage_collection/tsconfig.json" }, + { "path": "../kibana_utils/tsconfig.json" }, + { "path": "../kibana_react/tsconfig.json" }, + { "path": "../field_formats/tsconfig.json" }, + { "path": "../expressions/tsconfig.json" } + ] +} diff --git a/src/plugins/home/server/services/new_instance_status.ts b/src/plugins/home/server/services/new_instance_status.ts index b72ada27ecbad..e19380e928822 100644 --- a/src/plugins/home/server/services/new_instance_status.ts +++ b/src/plugins/home/server/services/new_instance_status.ts @@ -7,7 +7,6 @@ */ import type { IScopedClusterClient, SavedObjectsClientContract } from '../../../../core/server'; -import type { IndexPatternSavedObjectAttrs } from '../../../data/common/data_views/data_views'; const LOGS_INDEX_PATTERN = 'logs-*'; const METRICS_INDEX_PATTERN = 'metrics-*'; @@ -23,7 +22,7 @@ interface Deps { } export const isNewInstance = async ({ esClient, soClient }: Deps): Promise => { - const indexPatterns = await soClient.find({ + const indexPatterns = await soClient.find<{ title: string }>({ type: 'index-pattern', fields: ['title'], search: `*`, diff --git a/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/controls_references.ts b/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/controls_references.ts index 7a0bb4584e83a..31713d8ad7d5e 100644 --- a/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/controls_references.ts +++ b/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/controls_references.ts @@ -8,7 +8,7 @@ import { SavedObjectReference } from '../../../../../core/types'; import { VisParams } from '../../../common'; -import { INDEX_PATTERN_SAVED_OBJECT_TYPE } from '../../../../data/public'; +import { INDEX_PATTERN_SAVED_OBJECT_TYPE } from '../../../../data/common'; const isControlsVis = (visType: string) => visType === 'input_control_vis'; diff --git a/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/timeseries_references.ts b/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/timeseries_references.ts index 98970a0127c71..a3917699fcab3 100644 --- a/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/timeseries_references.ts +++ b/src/plugins/visualizations/public/saved_visualizations/saved_visualization_references/timeseries_references.ts @@ -8,7 +8,7 @@ import { SavedObjectReference } from '../../../../../core/types'; import { VisParams } from '../../../common'; -import { INDEX_PATTERN_SAVED_OBJECT_TYPE } from '../../../../data/public'; +import { INDEX_PATTERN_SAVED_OBJECT_TYPE } from '../../../../data/common'; /** @internal **/ const REF_NAME_POSTFIX = '_ref_name'; diff --git a/test/api_integration/apis/index_patterns/deprecations/scripted_fields.ts b/test/api_integration/apis/index_patterns/deprecations/scripted_fields.ts index 168c2b005d80d..c32b9b4241206 100644 --- a/test/api_integration/apis/index_patterns/deprecations/scripted_fields.ts +++ b/test/api_integration/apis/index_patterns/deprecations/scripted_fields.ts @@ -30,7 +30,9 @@ export default function ({ getService }: FtrProviderContext) { const { body } = await supertest.get('/api/deprecations/'); const { deprecations } = body as DeprecationsGetResponse; - const dataPluginDeprecations = deprecations.filter(({ domainId }) => domainId === 'data'); + const dataPluginDeprecations = deprecations.filter( + ({ domainId }) => domainId === 'dataViews' + ); expect(dataPluginDeprecations.length).to.be(0); }); @@ -59,7 +61,9 @@ export default function ({ getService }: FtrProviderContext) { const { body } = await supertest.get('/api/deprecations/'); const { deprecations } = body as DeprecationsGetResponse; - const dataPluginDeprecations = deprecations.filter(({ domainId }) => domainId === 'data'); + const dataPluginDeprecations = deprecations.filter( + ({ domainId }) => domainId === 'dataViews' + ); expect(dataPluginDeprecations.length).to.be(1); expect(dataPluginDeprecations[0].message).to.contain(title); diff --git a/test/api_integration/apis/index_patterns/es_errors/errors.js b/test/api_integration/apis/index_patterns/es_errors/errors.js index ac656e487323d..d5ca92c371617 100644 --- a/test/api_integration/apis/index_patterns/es_errors/errors.js +++ b/test/api_integration/apis/index_patterns/es_errors/errors.js @@ -15,7 +15,7 @@ import { createNoMatchingIndicesError, isNoMatchingIndicesError, convertEsError, -} from '../../../../../src/plugins/data/server/data_views/fetcher/lib/errors'; +} from '../../../../../src/plugins/data_views/server/fetcher/lib/errors'; import { getIndexNotFoundError, getDocNotFoundError } from './lib'; diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/top_values/top_values.tsx b/x-pack/plugins/data_visualizer/public/application/common/components/top_values/top_values.tsx index 45e8944c7c667..e2793512e23df 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/top_values/top_values.tsx +++ b/x-pack/plugins/data_visualizer/public/application/common/components/top_values/top_values.tsx @@ -23,7 +23,7 @@ import { roundToDecimalPlace, kibanaFieldFormat } from '../utils'; import { ExpandedRowFieldHeader } from '../stats_table/components/expanded_row_field_header'; import { FieldVisStats } from '../../../../../common/types'; import { ExpandedRowPanel } from '../stats_table/components/field_data_expanded_row/expanded_row_panel'; -import { IndexPatternField } from '../../../../../../../../src/plugins/data/common/data_views/fields'; +import { IndexPatternField } from '../../../../../../../../src/plugins/data_views/common'; interface Props { stats: FieldVisStats | undefined; diff --git a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/utils/saved_search_utils.test.ts b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/utils/saved_search_utils.test.ts index 4fb50aecc1062..3dd81015393b4 100644 --- a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/utils/saved_search_utils.test.ts +++ b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/utils/saved_search_utils.test.ts @@ -13,7 +13,7 @@ import { import type { SavedSearchSavedObject } from '../../../../common'; import type { SavedSearch } from '../../../../../../../src/plugins/discover/public'; import type { Filter, FilterStateStore } from '@kbn/es-query'; -import { stubbedSavedObjectIndexPattern } from '../../../../../../../src/plugins/data/common/data_views/data_view.stub'; +import { stubbedSavedObjectIndexPattern } from '../../../../../../../src/plugins/data_views/common/data_view.stub'; import { IndexPattern } from '../../../../../../../src/plugins/data/common'; import { fieldFormatsMock } from '../../../../../../../src/plugins/field_formats/common/mocks'; import { uiSettingsServiceMock } from 'src/core/public/mocks'; diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 5da17d8a746a0..53932d381dfdd 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -1653,12 +1653,12 @@ "data.functions.esaggs.help": "AggConfig 集約を実行します", "data.functions.esaggs.inspector.dataRequest.description": "このリクエストはElasticsearchにクエリし、ビジュアライゼーション用のデータを取得します。", "data.functions.esaggs.inspector.dataRequest.title": "データ", - "data.functions.indexPatternLoad.help": "インデックスパターンを読み込みます", - "data.functions.indexPatternLoad.id.help": "読み込むインデックスパターンID", - "data.indexPatterns.ensureDefaultIndexPattern.bannerLabel": "Kibanaでデータの可視化と閲覧を行うには、Elasticsearchからデータを取得するためのインデックスパターンの作成が必要です。", - "data.indexPatterns.fetchFieldErrorTitle": "インデックスパターンのフィールド取得中にエラーが発生 {title}(ID:{id})", - "data.indexPatterns.indexPatternLoad.error.kibanaRequest": "サーバーでこの検索を実行するには、KibanaRequest が必要です。式実行パラメーターに要求オブジェクトを渡してください。", - "data.indexPatterns.unableWriteLabel": "インデックスパターンを書き込めません。このインデックスパターンへの最新の変更を取得するには、ページを更新してください。", + "dataViews.indexPatternLoad.help": "インデックスパターンを読み込みます", + "dataViews.functions.indexPatternLoad.id.help": "読み込むインデックスパターンID", + "dataViews.ensureDefaultIndexPattern.bannerLabel": "Kibanaでデータの可視化と閲覧を行うには、Elasticsearchからデータを取得するためのインデックスパターンの作成が必要です。", + "dataViews.fetchFieldErrorTitle": "インデックスパターンのフィールド取得中にエラーが発生 {title}(ID:{id})", + "dataViews.indexPatternLoad.error.kibanaRequest": "サーバーでこの検索を実行するには、KibanaRequest が必要です。式実行パラメーターに要求オブジェクトを渡してください。", + "dataViews.unableWriteLabel": "インデックスパターンを書き込めません。このインデックスパターンへの最新の変更を取得するには、ページを更新してください。", "data.inspector.table..dataDescriptionTooltip": "ビジュアライゼーションの元のデータを表示", "data.inspector.table.dataTitle": "データ", "data.inspector.table.downloadCSVToggleButtonLabel": "CSV をダウンロード", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 6d5b94f49cb6f..1f00b1c910190 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -1669,12 +1669,12 @@ "data.functions.esaggs.help": "运行 AggConfig 聚合", "data.functions.esaggs.inspector.dataRequest.description": "此请求查询 Elasticsearch,以获取可视化的数据。", "data.functions.esaggs.inspector.dataRequest.title": "数据", - "data.functions.indexPatternLoad.help": "加载索引模式", - "data.functions.indexPatternLoad.id.help": "要加载的索引模式 id", - "data.indexPatterns.ensureDefaultIndexPattern.bannerLabel": "要在 Kibana 中可视化和浏览数据,必须创建索引模式,以从 Elasticsearch 中检索数据。", - "data.indexPatterns.fetchFieldErrorTitle": "提取索引模式 {title} (ID: {id}) 的字段时出错", - "data.indexPatterns.indexPatternLoad.error.kibanaRequest": "在服务器上执行此搜索时需要 Kibana 请求。请向表达式执行模式参数提供请求对象。", - "data.indexPatterns.unableWriteLabel": "无法写入索引模式!请刷新页面以获取此索引模式的最新更改。", + "dataViews.indexPatternLoad.help": "加载索引模式", + "dataViews.functions.indexPatternLoad.id.help": "要加载的索引模式 id", + "dataViews.ensureDefaultIndexPattern.bannerLabel": "要在 Kibana 中可视化和浏览数据,必须创建索引模式,以从 Elasticsearch 中检索数据。", + "dataViews.fetchFieldErrorTitle": "提取索引模式 {title} (ID: {id}) 的字段时出错", + "dataViews.indexPatternLoad.error.kibanaRequest": "在服务器上执行此搜索时需要 Kibana 请求。请向表达式执行模式参数提供请求对象。", + "dataViews.unableWriteLabel": "无法写入索引模式!请刷新页面以获取此索引模式的最新更改。", "data.inspector.table..dataDescriptionTooltip": "查看可视化后面的数据", "data.inspector.table.dataTitle": "数据", "data.inspector.table.downloadCSVToggleButtonLabel": "下载 CSV",