From 6e2367f987b5efb8aab09f2abf376dc9c14c99fd Mon Sep 17 00:00:00 2001 From: Luke Elmers Date: Thu, 13 Aug 2020 13:38:16 -0600 Subject: [PATCH] Make data.search.aggs available on the server. (#74472) --- ...lugins-data-public.baseformatterspublic.md | 2 +- ...ibana-plugin-plugins-data-public.search.md | 8 +- ...in-plugins-data-server.aggconfigoptions.md | 13 + ...ugin-plugins-data-server.agggrouplabels.md | 15 + ...plugin-plugins-data-server.agggroupname.md | 11 + ...lugin-plugins-data-server.agggroupnames.md | 15 + ...ana-plugin-plugins-data-server.aggparam.md | 11 + ...gins-data-server.aggparamoption.display.md | 11 + ...gins-data-server.aggparamoption.enabled.md | 22 ++ ...ugin-plugins-data-server.aggparamoption.md | 25 ++ ...-plugins-data-server.aggparamoption.val.md | 11 + ...-data-server.aggparamtype._constructor_.md | 20 ++ ...ns-data-server.aggparamtype.allowedaggs.md | 11 + ...lugins-data-server.aggparamtype.makeagg.md | 11 + ...plugin-plugins-data-server.aggparamtype.md | 25 ++ ...plugin-plugins-data-server.bucket_types.md | 28 ++ ...a-plugin-plugins-data-server.iaggconfig.md | 15 + ...ana-plugin-plugins-data-server.iaggtype.md | 11 + ...gin-plugins-data-server.ifieldparamtype.md | 11 + ...ugin-plugins-data-server.imetricaggtype.md | 11 + ...n-plugins-data-server.isearchsetup.aggs.md | 11 + ...plugin-plugins-data-server.isearchsetup.md | 1 + ...n-plugins-data-server.isearchstart.aggs.md | 11 + ...plugin-plugins-data-server.isearchstart.md | 1 + .../kibana-plugin-plugins-data-server.md | 18 + ...plugin-plugins-data-server.metric_types.md | 38 +++ ...-server.optionedparamtype._constructor_.md | 20 ++ ...n-plugins-data-server.optionedparamtype.md | 24 ++ ...s-data-server.optionedparamtype.options.md | 11 + ...-data-server.optionedvalueprop.disabled.md | 11 + ...a-server.optionedvalueprop.iscompatible.md | 11 + ...n-plugins-data-server.optionedvalueprop.md | 21 ++ ...gins-data-server.optionedvalueprop.text.md | 11 + ...ins-data-server.optionedvalueprop.value.md | 11 + ...plugin-plugins-data-server.plugin.setup.md | 10 +- ...ibana-plugin-plugins-data-server.search.md | 20 ++ ...s-data-server.tabbedaggcolumn.aggconfig.md | 11 + ...-plugins-data-server.tabbedaggcolumn.id.md | 11 + ...gin-plugins-data-server.tabbedaggcolumn.md | 22 ++ ...lugins-data-server.tabbedaggcolumn.name.md | 11 + ...plugin-plugins-data-server.tabbedaggrow.md | 13 + ...plugins-data-server.tabbedtable.columns.md | 11 + ...-plugin-plugins-data-server.tabbedtable.md | 21 ++ ...in-plugins-data-server.tabbedtable.rows.md | 11 + .../new_platform/new_platform.karma_mock.js | 14 +- .../common/field_formats/converters/source.ts | 2 +- .../field_formats/field_formats_registry.ts | 2 +- .../data/common/field_formats/mocks.ts | 1 + src/plugins/data/common/index.ts | 2 - .../index_patterns/fields/field_list.ts | 3 +- .../fields/index_pattern_field.ts | 11 +- .../search/aggs/agg_config.test.ts | 5 +- .../search/aggs/agg_config.ts | 5 +- .../search/aggs/agg_configs.test.ts | 5 +- .../search/aggs/agg_configs.ts | 5 +- .../search/aggs/agg_groups.ts | 0 .../search/aggs/agg_params.test.ts | 0 .../search/aggs/agg_params.ts | 0 .../search/aggs/agg_type.test.ts | 0 .../search/aggs/agg_type.ts | 2 +- .../search/aggs/agg_types.ts | 86 +++-- .../search/aggs/agg_types_registry.test.ts | 60 ++-- .../search/aggs/agg_types_registry.ts | 46 ++- .../common/search/aggs/aggs_service.test.ts | 217 ++++++++++++ .../data/common/search/aggs/aggs_service.ts | 92 ++++++ .../search/aggs/buckets/_interval_options.ts | 0 .../_terms_other_bucket_helper.test.ts | 0 .../buckets/_terms_other_bucket_helper.ts | 0 .../search/aggs/buckets/bucket_agg_type.ts | 0 .../search/aggs/buckets/bucket_agg_types.ts | 0 .../create_filter/date_histogram.test.ts | 19 +- .../buckets/create_filter/date_histogram.ts | 0 .../buckets/create_filter/date_range.test.ts | 17 +- .../aggs/buckets/create_filter/date_range.ts | 0 .../buckets/create_filter/filters.test.ts | 12 +- .../aggs/buckets/create_filter/filters.ts | 0 .../buckets/create_filter/histogram.test.ts | 21 +- .../aggs/buckets/create_filter/histogram.ts | 12 +- .../buckets/create_filter/ip_range.test.ts | 3 +- .../aggs/buckets/create_filter/ip_range.ts | 0 .../aggs/buckets/create_filter/range.test.ts | 30 +- .../aggs/buckets/create_filter/range.ts | 12 +- .../aggs/buckets/create_filter/terms.test.ts | 3 +- .../aggs/buckets/create_filter/terms.ts | 0 .../search/aggs/buckets/date_histogram.ts | 41 ++- .../aggs/buckets/date_histogram_fn.test.ts | 0 .../search/aggs/buckets/date_histogram_fn.ts | 0 .../search/aggs/buckets/date_range.test.ts | 22 +- .../search/aggs/buckets/date_range.ts | 14 +- .../search/aggs/buckets/date_range_fn.test.ts | 0 .../search/aggs/buckets/date_range_fn.ts | 0 .../search/aggs/buckets/filter.ts | 0 .../search/aggs/buckets/filter_fn.test.ts | 0 .../search/aggs/buckets/filter_fn.ts | 0 .../search/aggs/buckets/filters.test.ts | 18 +- .../search/aggs/buckets/filters.ts | 11 +- .../search/aggs/buckets/filters_fn.test.ts | 0 .../search/aggs/buckets/filters_fn.ts | 0 .../search/aggs/buckets/geo_hash.test.ts | 0 .../search/aggs/buckets/geo_hash.ts | 0 .../search/aggs/buckets/geo_hash_fn.test.ts | 0 .../search/aggs/buckets/geo_hash_fn.ts | 0 .../search/aggs/buckets/geo_tile.ts | 0 .../search/aggs/buckets/geo_tile_fn.test.ts | 0 .../search/aggs/buckets/geo_tile_fn.ts | 0 .../search/aggs/buckets/histogram.test.ts | 32 +- .../search/aggs/buckets/histogram.ts | 22 +- .../search/aggs/buckets/histogram_fn.test.ts | 0 .../search/aggs/buckets/histogram_fn.ts | 0 .../search/aggs/buckets/index.ts | 1 + .../search/aggs/buckets/ip_range.ts | 0 .../search/aggs/buckets/ip_range_fn.test.ts | 0 .../search/aggs/buckets/ip_range_fn.ts | 0 .../search/aggs/buckets/lib/cidr_mask.test.ts | 0 .../search/aggs/buckets/lib/cidr_mask.ts | 2 +- .../search/aggs/buckets/lib/date_range.ts | 0 .../aggs/buckets/lib/extended_bounds.ts | 0 .../search/aggs/buckets/lib/geo_point.ts | 0 .../search/aggs/buckets/lib/ip_range.ts | 0 .../time_buckets/calc_auto_interval.test.ts | 0 .../lib/time_buckets/calc_auto_interval.ts | 0 .../lib/time_buckets/calc_es_interval.ts | 2 +- .../aggs/buckets/lib/time_buckets/index.ts | 0 .../lib/time_buckets/time_buckets.test.ts | 0 .../buckets/lib/time_buckets/time_buckets.ts | 2 +- .../buckets/migrate_include_exclude_format.ts | 0 .../search/aggs/buckets/range.test.ts | 18 +- .../search/aggs/buckets/range.ts | 14 +- .../search/aggs/buckets/range_fn.test.ts | 0 .../search/aggs/buckets/range_fn.ts | 0 .../search/aggs/buckets/range_key.ts | 0 .../aggs/buckets/significant_terms.test.ts | 3 +- .../search/aggs/buckets/significant_terms.ts | 0 .../aggs/buckets/significant_terms_fn.test.ts | 0 .../aggs/buckets/significant_terms_fn.ts | 0 .../search/aggs/buckets/terms.test.ts | 0 .../search/aggs/buckets/terms.ts | 0 .../search/aggs/buckets/terms_fn.test.ts | 0 .../search/aggs/buckets/terms_fn.ts | 0 .../search/aggs/index.test.ts | 32 +- src/plugins/data/common/search/aggs/index.ts | 14 +- .../search/aggs/metrics/avg.ts | 0 .../search/aggs/metrics/avg_fn.test.ts | 0 .../search/aggs/metrics/avg_fn.ts | 0 .../search/aggs/metrics/bucket_avg.ts | 0 .../search/aggs/metrics/bucket_avg_fn.test.ts | 0 .../search/aggs/metrics/bucket_avg_fn.ts | 0 .../search/aggs/metrics/bucket_max.ts | 0 .../search/aggs/metrics/bucket_max_fn.test.ts | 0 .../search/aggs/metrics/bucket_max_fn.ts | 0 .../search/aggs/metrics/bucket_min.ts | 0 .../search/aggs/metrics/bucket_min_fn.test.ts | 0 .../search/aggs/metrics/bucket_min_fn.ts | 0 .../search/aggs/metrics/bucket_sum.ts | 0 .../search/aggs/metrics/bucket_sum_fn.test.ts | 0 .../search/aggs/metrics/bucket_sum_fn.ts | 0 .../search/aggs/metrics/cardinality.ts | 0 .../aggs/metrics/cardinality_fn.test.ts | 0 .../search/aggs/metrics/cardinality_fn.ts | 0 .../search/aggs/metrics/count.ts | 0 .../search/aggs/metrics/count_fn.test.ts | 0 .../search/aggs/metrics/count_fn.ts | 0 .../search/aggs/metrics/cumulative_sum.ts | 0 .../aggs/metrics/cumulative_sum_fn.test.ts | 0 .../search/aggs/metrics/cumulative_sum_fn.ts | 0 .../search/aggs/metrics/derivative.ts | 0 .../search/aggs/metrics/derivative_fn.test.ts | 0 .../search/aggs/metrics/derivative_fn.ts | 0 .../search/aggs/metrics/geo_bounds.ts | 0 .../search/aggs/metrics/geo_bounds_fn.test.ts | 0 .../search/aggs/metrics/geo_bounds_fn.ts | 0 .../search/aggs/metrics/geo_centroid.ts | 0 .../aggs/metrics/geo_centroid_fn.test.ts | 0 .../search/aggs/metrics/geo_centroid_fn.ts | 0 .../search/aggs/metrics/index.ts | 0 .../lib/get_response_agg_config_class.ts | 0 .../metrics/lib/make_nested_label.test.ts | 0 .../aggs/metrics/lib/make_nested_label.ts | 0 .../aggs/metrics/lib/nested_agg_helpers.ts | 0 .../aggs/metrics/lib/ordinal_suffix.test.ts | 0 .../search/aggs/metrics/lib/ordinal_suffix.ts | 0 .../metrics/lib/parent_pipeline_agg_helper.ts | 0 .../metrics/lib/parent_pipeline_agg_writer.ts | 0 .../lib/sibling_pipeline_agg_helper.ts | 0 .../lib/sibling_pipeline_agg_writer.ts | 0 .../search/aggs/metrics/max.ts | 0 .../search/aggs/metrics/max_fn.test.ts | 0 .../search/aggs/metrics/max_fn.ts | 0 .../search/aggs/metrics/median.test.ts | 3 +- .../search/aggs/metrics/median.ts | 0 .../search/aggs/metrics/median_fn.test.ts | 0 .../search/aggs/metrics/median_fn.ts | 0 .../search/aggs/metrics/metric_agg_type.ts | 0 .../search/aggs/metrics/metric_agg_types.ts | 0 .../search/aggs/metrics/min.ts | 0 .../search/aggs/metrics/min_fn.test.ts | 0 .../search/aggs/metrics/min_fn.ts | 0 .../search/aggs/metrics/moving_avg.ts | 0 .../search/aggs/metrics/moving_avg_fn.test.ts | 0 .../search/aggs/metrics/moving_avg_fn.ts | 0 .../aggs/metrics/parent_pipeline.test.ts | 0 .../aggs/metrics/percentile_ranks.test.ts | 19 +- .../search/aggs/metrics/percentile_ranks.ts | 26 +- .../aggs/metrics/percentile_ranks_fn.test.ts | 0 .../aggs/metrics/percentile_ranks_fn.ts | 0 .../search/aggs/metrics/percentiles.test.ts | 2 +- .../search/aggs/metrics/percentiles.ts | 0 .../aggs/metrics/percentiles_fn.test.ts | 0 .../search/aggs/metrics/percentiles_fn.ts | 0 .../aggs/metrics/percentiles_get_value.ts | 0 .../search/aggs/metrics/serial_diff.ts | 0 .../aggs/metrics/serial_diff_fn.test.ts | 0 .../search/aggs/metrics/serial_diff_fn.ts | 0 .../aggs/metrics/sibling_pipeline.test.ts | 0 .../search/aggs/metrics/std_deviation.test.ts | 2 +- .../search/aggs/metrics/std_deviation.ts | 0 .../aggs/metrics/std_deviation_fn.test.ts | 0 .../search/aggs/metrics/std_deviation_fn.ts | 0 .../search/aggs/metrics/sum.ts | 0 .../search/aggs/metrics/sum_fn.test.ts | 0 .../search/aggs/metrics/sum_fn.ts | 0 .../search/aggs/metrics/top_hit.test.ts | 2 +- .../search/aggs/metrics/top_hit.ts | 0 .../search/aggs/metrics/top_hit_fn.test.ts | 0 .../search/aggs/metrics/top_hit_fn.ts | 0 .../search/aggs/param_types/agg.ts | 0 .../search/aggs/param_types/base.ts | 3 +- .../search/aggs/param_types/field.test.ts | 0 .../search/aggs/param_types/field.ts | 4 +- .../search/aggs/param_types/index.ts | 0 .../search/aggs/param_types/json.test.ts | 0 .../search/aggs/param_types/json.ts | 0 .../search/aggs/param_types/optioned.test.ts | 0 .../search/aggs/param_types/optioned.ts | 0 .../search/aggs/param_types/string.test.ts | 0 .../search/aggs/param_types/string.ts | 0 .../aggs/test_helpers/function_wrapper.ts | 0 .../search/aggs/test_helpers/index.ts | 4 +- .../test_helpers/mock_agg_types_registry.ts | 81 +++-- src/plugins/data/common/search/aggs/types.ts | 157 +++++++++ .../utils/calculate_auto_time_expression.ts | 15 +- .../date_histogram_interval.test.ts | 0 .../date_histogram_interval.ts | 0 .../{ => utils}/date_interval_utils/index.ts | 0 .../invalid_es_calendar_interval_error.ts | 0 .../invalid_es_interval_format_error.ts | 0 .../is_valid_es_interval.ts | 0 .../date_interval_utils/is_valid_interval.ts | 0 .../least_common_interval.test.ts | 0 .../least_common_interval.ts | 0 .../least_common_multiple.test.ts | 0 .../least_common_multiple.ts | 0 .../parse_es_interval.test.ts | 0 .../date_interval_utils/parse_es_interval.ts | 0 .../parse_interval.test.ts | 0 .../date_interval_utils/parse_interval.ts | 0 .../date_interval_utils/to_absolute_dates.ts | 2 +- .../aggs/utils/get_format_with_aggs.test.ts | 5 +- .../search/aggs/utils/get_format_with_aggs.ts | 9 +- .../search/aggs/utils/get_parsed_value.ts | 0 .../search/aggs/utils/index.ts | 2 + .../aggs/{ => utils}/ipv4_address.test.ts | 0 .../search/aggs/{ => utils}/ipv4_address.ts | 0 .../search/aggs/utils/prop_filter.test.ts | 0 .../search/aggs/utils/prop_filter.ts | 0 .../search/aggs/utils/to_angular_json.ts | 0 .../data/common/search/expressions/index.ts | 1 + .../utils/courier_inspector_stats.ts | 2 +- .../common/search/expressions/utils/index.ts | 20 ++ src/plugins/data/common/search/index.ts | 9 +- .../search/tabify/buckets.test.ts | 0 .../search/tabify/buckets.ts | 0 .../search/tabify/get_columns.test.ts | 0 .../search/tabify/get_columns.ts | 0 .../{public => common}/search/tabify/index.ts | 0 .../search/tabify/response_writer.test.ts | 0 .../search/tabify/response_writer.ts | 0 .../search/tabify/tabify.test.ts | 2 +- .../search/tabify/tabify.ts | 0 .../{public => common}/search/tabify/types.ts | 0 .../public/field_formats/utils/deserialize.ts | 2 +- src/plugins/data/public/index.ts | 62 ++-- src/plugins/data/public/mocks.ts | 2 +- src/plugins/data/public/plugin.ts | 19 +- src/plugins/data/public/public.api.md | 14 +- .../public/search/aggs/aggs_service.test.ts | 182 +++++++++++ .../data/public/search/aggs/aggs_service.ts | 152 +++++++++ src/plugins/data/public/search/aggs/index.ts | 11 +- src/plugins/data/public/search/aggs/mocks.ts | 19 +- src/plugins/data/public/search/aggs/types.ts | 130 +------- .../build_tabular_inspector_data.ts | 2 +- .../search/expressions/create_filter.test.ts | 14 +- .../search/expressions/create_filter.ts | 4 +- .../data/public/search/expressions/esaggs.ts | 14 +- .../public/search/expressions/utils/index.ts | 1 - .../expressions/utils/serialize_agg_config.ts | 2 +- src/plugins/data/public/search/index.ts | 2 - .../data/public/search/search_service.test.ts | 11 +- .../data/public/search/search_service.ts | 94 ++---- src/plugins/data/public/search/types.ts | 16 +- src/plugins/data/public/types.ts | 12 - src/plugins/data/server/index.ts | 51 +++ src/plugins/data/server/plugin.ts | 37 ++- .../server/search/aggs/aggs_service.test.ts | 113 +++++++ .../data/server/search/aggs/aggs_service.ts | 122 +++++++ src/plugins/data/server/search/aggs/index.ts | 21 ++ src/plugins/data/server/search/aggs/mocks.ts | 81 +++++ src/plugins/data/server/search/aggs/types.ts | 27 ++ src/plugins/data/server/search/index.ts | 2 + src/plugins/data/server/search/mocks.ts | 9 +- .../data/server/search/search_service.test.ts | 21 +- .../data/server/search/search_service.ts | 39 ++- src/plugins/data/server/search/types.ts | 3 + src/plugins/data/server/server.api.md | 309 ++++++++++++++++-- .../definitions/date_histogram.test.tsx | 10 +- 315 files changed, 2712 insertions(+), 831 deletions(-) create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggconfigoptions.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.agggrouplabels.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.agggroupname.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.agggroupnames.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparam.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamoption.display.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamoption.enabled.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamoption.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamoption.val.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamtype._constructor_.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamtype.allowedaggs.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamtype.makeagg.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamtype.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.bucket_types.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iaggconfig.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iaggtype.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.ifieldparamtype.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.imetricaggtype.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.aggs.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.aggs.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.metric_types.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedparamtype._constructor_.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedparamtype.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedparamtype.options.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedvalueprop.disabled.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedvalueprop.iscompatible.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedvalueprop.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedvalueprop.text.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedvalueprop.value.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedaggcolumn.aggconfig.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedaggcolumn.id.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedaggcolumn.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedaggcolumn.name.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedaggrow.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedtable.columns.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedtable.md create mode 100644 docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedtable.rows.md rename src/plugins/data/{public => common}/search/aggs/agg_config.test.ts (98%) rename src/plugins/data/{public => common}/search/aggs/agg_config.ts (99%) rename src/plugins/data/{public => common}/search/aggs/agg_configs.test.ts (98%) rename src/plugins/data/{public => common}/search/aggs/agg_configs.ts (98%) rename src/plugins/data/{public => common}/search/aggs/agg_groups.ts (100%) rename src/plugins/data/{public => common}/search/aggs/agg_params.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/agg_params.ts (100%) rename src/plugins/data/{public => common}/search/aggs/agg_type.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/agg_type.ts (99%) rename src/plugins/data/{public => common}/search/aggs/agg_types.ts (66%) rename src/plugins/data/{public => common}/search/aggs/agg_types_registry.test.ts (54%) rename src/plugins/data/{public => common}/search/aggs/agg_types_registry.ts (57%) create mode 100644 src/plugins/data/common/search/aggs/aggs_service.test.ts create mode 100644 src/plugins/data/common/search/aggs/aggs_service.ts rename src/plugins/data/{public => common}/search/aggs/buckets/_interval_options.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/_terms_other_bucket_helper.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/_terms_other_bucket_helper.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/bucket_agg_type.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/bucket_agg_types.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/create_filter/date_histogram.test.ts (87%) rename src/plugins/data/{public => common}/search/aggs/buckets/create_filter/date_histogram.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/create_filter/date_range.test.ts (78%) rename src/plugins/data/{public => common}/search/aggs/buckets/create_filter/date_range.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/create_filter/filters.test.ts (83%) rename src/plugins/data/{public => common}/search/aggs/buckets/create_filter/filters.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/create_filter/histogram.test.ts (77%) rename src/plugins/data/{public => common}/search/aggs/buckets/create_filter/histogram.ts (80%) rename src/plugins/data/{public => common}/search/aggs/buckets/create_filter/ip_range.test.ts (96%) rename src/plugins/data/{public => common}/search/aggs/buckets/create_filter/ip_range.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/create_filter/range.test.ts (73%) rename src/plugins/data/{public => common}/search/aggs/buckets/create_filter/range.ts (78%) rename src/plugins/data/{public => common}/search/aggs/buckets/create_filter/terms.test.ts (97%) rename src/plugins/data/{public => common}/search/aggs/buckets/create_filter/terms.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/date_histogram.ts (92%) rename src/plugins/data/{public => common}/search/aggs/buckets/date_histogram_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/date_histogram_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/date_range.test.ts (84%) rename src/plugins/data/{public => common}/search/aggs/buckets/date_range.ts (88%) rename src/plugins/data/{public => common}/search/aggs/buckets/date_range_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/date_range_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/filter.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/filter_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/filter_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/filters.test.ts (93%) rename src/plugins/data/{public => common}/search/aggs/buckets/filters.ts (90%) rename src/plugins/data/{public => common}/search/aggs/buckets/filters_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/filters_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/geo_hash.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/geo_hash.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/geo_hash_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/geo_hash_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/geo_tile.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/geo_tile_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/geo_tile_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/histogram.test.ts (90%) rename src/plugins/data/{public => common}/search/aggs/buckets/histogram.ts (93%) rename src/plugins/data/{public => common}/search/aggs/buckets/histogram_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/histogram_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/index.ts (97%) rename src/plugins/data/{public => common}/search/aggs/buckets/ip_range.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/ip_range_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/ip_range_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/lib/cidr_mask.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/lib/cidr_mask.ts (97%) rename src/plugins/data/{public => common}/search/aggs/buckets/lib/date_range.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/lib/extended_bounds.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/lib/geo_point.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/lib/ip_range.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/lib/time_buckets/calc_auto_interval.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/lib/time_buckets/calc_auto_interval.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/lib/time_buckets/calc_es_interval.ts (97%) rename src/plugins/data/{public => common}/search/aggs/buckets/lib/time_buckets/index.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/lib/time_buckets/time_buckets.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/lib/time_buckets/time_buckets.ts (99%) rename src/plugins/data/{public => common}/search/aggs/buckets/migrate_include_exclude_format.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/range.test.ts (79%) rename src/plugins/data/{public => common}/search/aggs/buckets/range.ts (90%) rename src/plugins/data/{public => common}/search/aggs/buckets/range_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/range_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/range_key.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/significant_terms.test.ts (95%) rename src/plugins/data/{public => common}/search/aggs/buckets/significant_terms.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/significant_terms_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/significant_terms_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/terms.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/terms.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/terms_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/buckets/terms_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/index.test.ts (63%) rename src/plugins/data/{public => common}/search/aggs/metrics/avg.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/avg_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/avg_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/bucket_avg.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/bucket_avg_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/bucket_avg_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/bucket_max.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/bucket_max_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/bucket_max_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/bucket_min.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/bucket_min_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/bucket_min_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/bucket_sum.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/bucket_sum_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/bucket_sum_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/cardinality.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/cardinality_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/cardinality_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/count.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/count_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/count_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/cumulative_sum.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/cumulative_sum_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/cumulative_sum_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/derivative.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/derivative_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/derivative_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/geo_bounds.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/geo_bounds_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/geo_bounds_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/geo_centroid.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/geo_centroid_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/geo_centroid_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/index.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/lib/get_response_agg_config_class.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/lib/make_nested_label.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/lib/make_nested_label.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/lib/nested_agg_helpers.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/lib/ordinal_suffix.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/lib/ordinal_suffix.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/lib/parent_pipeline_agg_helper.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/lib/parent_pipeline_agg_writer.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/lib/sibling_pipeline_agg_helper.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/lib/sibling_pipeline_agg_writer.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/max.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/max_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/max_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/median.test.ts (94%) rename src/plugins/data/{public => common}/search/aggs/metrics/median.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/median_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/median_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/metric_agg_type.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/metric_agg_types.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/min.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/min_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/min_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/moving_avg.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/moving_avg_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/moving_avg_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/parent_pipeline.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/percentile_ranks.test.ts (77%) rename src/plugins/data/{public => common}/search/aggs/metrics/percentile_ranks.ts (86%) rename src/plugins/data/{public => common}/search/aggs/metrics/percentile_ranks_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/percentile_ranks_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/percentiles.test.ts (96%) rename src/plugins/data/{public => common}/search/aggs/metrics/percentiles.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/percentiles_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/percentiles_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/percentiles_get_value.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/serial_diff.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/serial_diff_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/serial_diff_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/sibling_pipeline.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/std_deviation.test.ts (97%) rename src/plugins/data/{public => common}/search/aggs/metrics/std_deviation.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/std_deviation_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/std_deviation_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/sum.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/sum_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/sum_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/top_hit.test.ts (99%) rename src/plugins/data/{public => common}/search/aggs/metrics/top_hit.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/top_hit_fn.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/metrics/top_hit_fn.ts (100%) rename src/plugins/data/{public => common}/search/aggs/param_types/agg.ts (100%) rename src/plugins/data/{public => common}/search/aggs/param_types/base.ts (96%) rename src/plugins/data/{public => common}/search/aggs/param_types/field.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/param_types/field.ts (96%) rename src/plugins/data/{public => common}/search/aggs/param_types/index.ts (100%) rename src/plugins/data/{public => common}/search/aggs/param_types/json.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/param_types/json.ts (100%) rename src/plugins/data/{public => common}/search/aggs/param_types/optioned.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/param_types/optioned.ts (100%) rename src/plugins/data/{public => common}/search/aggs/param_types/string.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/param_types/string.ts (100%) rename src/plugins/data/{public => common}/search/aggs/test_helpers/function_wrapper.ts (100%) rename src/plugins/data/{public => common}/search/aggs/test_helpers/index.ts (86%) rename src/plugins/data/{public => common}/search/aggs/test_helpers/mock_agg_types_registry.ts (52%) create mode 100644 src/plugins/data/common/search/aggs/types.ts rename src/plugins/data/{public => common}/search/aggs/utils/calculate_auto_time_expression.ts (71%) rename src/plugins/data/common/search/aggs/{ => utils}/date_interval_utils/date_histogram_interval.test.ts (100%) rename src/plugins/data/common/search/aggs/{ => utils}/date_interval_utils/date_histogram_interval.ts (100%) rename src/plugins/data/common/search/aggs/{ => utils}/date_interval_utils/index.ts (100%) rename src/plugins/data/common/search/aggs/{ => utils}/date_interval_utils/invalid_es_calendar_interval_error.ts (100%) rename src/plugins/data/common/search/aggs/{ => utils}/date_interval_utils/invalid_es_interval_format_error.ts (100%) rename src/plugins/data/common/search/aggs/{ => utils}/date_interval_utils/is_valid_es_interval.ts (100%) rename src/plugins/data/common/search/aggs/{ => utils}/date_interval_utils/is_valid_interval.ts (100%) rename src/plugins/data/common/search/aggs/{ => utils}/date_interval_utils/least_common_interval.test.ts (100%) rename src/plugins/data/common/search/aggs/{ => utils}/date_interval_utils/least_common_interval.ts (100%) rename src/plugins/data/common/search/aggs/{ => utils}/date_interval_utils/least_common_multiple.test.ts (100%) rename src/plugins/data/common/search/aggs/{ => utils}/date_interval_utils/least_common_multiple.ts (100%) rename src/plugins/data/common/search/aggs/{ => utils}/date_interval_utils/parse_es_interval.test.ts (100%) rename src/plugins/data/common/search/aggs/{ => utils}/date_interval_utils/parse_es_interval.ts (100%) rename src/plugins/data/common/search/aggs/{ => utils}/date_interval_utils/parse_interval.test.ts (100%) rename src/plugins/data/common/search/aggs/{ => utils}/date_interval_utils/parse_interval.ts (100%) rename src/plugins/data/common/search/aggs/{ => utils}/date_interval_utils/to_absolute_dates.ts (95%) rename src/plugins/data/{public => common}/search/aggs/utils/get_format_with_aggs.test.ts (95%) rename src/plugins/data/{public => common}/search/aggs/utils/get_format_with_aggs.ts (95%) rename src/plugins/data/{public => common}/search/aggs/utils/get_parsed_value.ts (100%) rename src/plugins/data/{public => common}/search/aggs/utils/index.ts (93%) rename src/plugins/data/common/search/aggs/{ => utils}/ipv4_address.test.ts (100%) rename src/plugins/data/common/search/aggs/{ => utils}/ipv4_address.ts (100%) rename src/plugins/data/{public => common}/search/aggs/utils/prop_filter.test.ts (100%) rename src/plugins/data/{public => common}/search/aggs/utils/prop_filter.ts (100%) rename src/plugins/data/{public => common}/search/aggs/utils/to_angular_json.ts (100%) rename src/plugins/data/{public => common}/search/expressions/utils/courier_inspector_stats.ts (98%) create mode 100644 src/plugins/data/common/search/expressions/utils/index.ts rename src/plugins/data/{public => common}/search/tabify/buckets.test.ts (100%) rename src/plugins/data/{public => common}/search/tabify/buckets.ts (100%) rename src/plugins/data/{public => common}/search/tabify/get_columns.test.ts (100%) rename src/plugins/data/{public => common}/search/tabify/get_columns.ts (100%) rename src/plugins/data/{public => common}/search/tabify/index.ts (100%) rename src/plugins/data/{public => common}/search/tabify/response_writer.test.ts (100%) rename src/plugins/data/{public => common}/search/tabify/response_writer.ts (100%) rename src/plugins/data/{public => common}/search/tabify/tabify.test.ts (98%) rename src/plugins/data/{public => common}/search/tabify/tabify.ts (100%) rename src/plugins/data/{public => common}/search/tabify/types.ts (100%) create mode 100644 src/plugins/data/public/search/aggs/aggs_service.test.ts create mode 100644 src/plugins/data/public/search/aggs/aggs_service.ts create mode 100644 src/plugins/data/server/search/aggs/aggs_service.test.ts create mode 100644 src/plugins/data/server/search/aggs/aggs_service.ts create mode 100644 src/plugins/data/server/search/aggs/index.ts create mode 100644 src/plugins/data/server/search/aggs/mocks.ts create mode 100644 src/plugins/data/server/search/aggs/types.ts diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.baseformatterspublic.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.baseformatterspublic.md index 25f046983cbce..1aa9f460c4fac 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.baseformatterspublic.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.baseformatterspublic.md @@ -7,5 +7,5 @@ Signature: ```typescript -baseFormattersPublic: (import("../../common").FieldFormatInstanceType | typeof DateNanosFormat | typeof DateFormat)[] +baseFormattersPublic: (import("../../common").FieldFormatInstanceType | typeof DateFormat | typeof DateNanosFormat)[] ``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.search.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.search.md index 6c8f7fbdb170b..22dc92c275670 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.search.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.search.md @@ -14,7 +14,7 @@ search: { intervalOptions: ({ display: string; val: string; - enabled(agg: import("./search/aggs/buckets/bucket_agg_type").IBucketAggConfig): boolean | "" | undefined; + enabled(agg: import("../common").IBucketAggConfig): boolean | "" | undefined; } | { display: string; val: string; @@ -23,9 +23,9 @@ search: { InvalidEsIntervalFormatError: typeof InvalidEsIntervalFormatError; Ipv4Address: typeof Ipv4Address; isDateHistogramBucketAggConfig: typeof isDateHistogramBucketAggConfig; - isNumberType: (agg: import("./search").AggConfig) => boolean; - isStringType: (agg: import("./search").AggConfig) => boolean; - isType: (...types: string[]) => (agg: import("./search").AggConfig) => boolean; + isNumberType: (agg: import("../common").AggConfig) => boolean; + isStringType: (agg: import("../common").AggConfig) => boolean; + isType: (...types: string[]) => (agg: import("../common").AggConfig) => boolean; isValidEsInterval: typeof isValidEsInterval; isValidInterval: typeof isValidInterval; parentPipelineType: string; diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggconfigoptions.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggconfigoptions.md new file mode 100644 index 0000000000000..effb2e798ad6f --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggconfigoptions.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [AggConfigOptions](./kibana-plugin-plugins-data-server.aggconfigoptions.md) + +## AggConfigOptions type + +Signature: + +```typescript +export declare type AggConfigOptions = Assign; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.agggrouplabels.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.agggrouplabels.md new file mode 100644 index 0000000000000..cf0caee6ac33e --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.agggrouplabels.md @@ -0,0 +1,15 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [AggGroupLabels](./kibana-plugin-plugins-data-server.agggrouplabels.md) + +## AggGroupLabels variable + +Signature: + +```typescript +AggGroupLabels: { + buckets: string; + metrics: string; + none: string; +} +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.agggroupname.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.agggroupname.md new file mode 100644 index 0000000000000..403294eba1367 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.agggroupname.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [AggGroupName](./kibana-plugin-plugins-data-server.agggroupname.md) + +## AggGroupName type + +Signature: + +```typescript +export declare type AggGroupName = $Values; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.agggroupnames.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.agggroupnames.md new file mode 100644 index 0000000000000..11d194723c521 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.agggroupnames.md @@ -0,0 +1,15 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [AggGroupNames](./kibana-plugin-plugins-data-server.agggroupnames.md) + +## AggGroupNames variable + +Signature: + +```typescript +AggGroupNames: Readonly<{ + Buckets: "buckets"; + Metrics: "metrics"; + None: "none"; +}> +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparam.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparam.md new file mode 100644 index 0000000000000..893501666b9a0 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparam.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [AggParam](./kibana-plugin-plugins-data-server.aggparam.md) + +## AggParam type + +Signature: + +```typescript +export declare type AggParam = BaseParamType; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamoption.display.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamoption.display.md new file mode 100644 index 0000000000000..1030056e16afe --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamoption.display.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [AggParamOption](./kibana-plugin-plugins-data-server.aggparamoption.md) > [display](./kibana-plugin-plugins-data-server.aggparamoption.display.md) + +## AggParamOption.display property + +Signature: + +```typescript +display: string; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamoption.enabled.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamoption.enabled.md new file mode 100644 index 0000000000000..8b1fcc4a1bbd0 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamoption.enabled.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [AggParamOption](./kibana-plugin-plugins-data-server.aggparamoption.md) > [enabled](./kibana-plugin-plugins-data-server.aggparamoption.enabled.md) + +## AggParamOption.enabled() method + +Signature: + +```typescript +enabled?(agg: AggConfig): boolean; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| agg | AggConfig | | + +Returns: + +`boolean` + diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamoption.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamoption.md new file mode 100644 index 0000000000000..a7ddcf395cab4 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamoption.md @@ -0,0 +1,25 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [AggParamOption](./kibana-plugin-plugins-data-server.aggparamoption.md) + +## AggParamOption interface + +Signature: + +```typescript +export interface AggParamOption +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [display](./kibana-plugin-plugins-data-server.aggparamoption.display.md) | string | | +| [val](./kibana-plugin-plugins-data-server.aggparamoption.val.md) | string | | + +## Methods + +| Method | Description | +| --- | --- | +| [enabled(agg)](./kibana-plugin-plugins-data-server.aggparamoption.enabled.md) | | + diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamoption.val.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamoption.val.md new file mode 100644 index 0000000000000..2c87c91c294d9 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamoption.val.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [AggParamOption](./kibana-plugin-plugins-data-server.aggparamoption.md) > [val](./kibana-plugin-plugins-data-server.aggparamoption.val.md) + +## AggParamOption.val property + +Signature: + +```typescript +val: string; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamtype._constructor_.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamtype._constructor_.md new file mode 100644 index 0000000000000..2e1b16855987e --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamtype._constructor_.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [AggParamType](./kibana-plugin-plugins-data-server.aggparamtype.md) > [(constructor)](./kibana-plugin-plugins-data-server.aggparamtype._constructor_.md) + +## AggParamType.(constructor) + +Constructs a new instance of the `AggParamType` class + +Signature: + +```typescript +constructor(config: Record); +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| config | Record<string, any> | | + diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamtype.allowedaggs.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamtype.allowedaggs.md new file mode 100644 index 0000000000000..36179a9ce3569 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamtype.allowedaggs.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [AggParamType](./kibana-plugin-plugins-data-server.aggparamtype.md) > [allowedAggs](./kibana-plugin-plugins-data-server.aggparamtype.allowedaggs.md) + +## AggParamType.allowedAggs property + +Signature: + +```typescript +allowedAggs: string[]; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamtype.makeagg.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamtype.makeagg.md new file mode 100644 index 0000000000000..bd5d2fca77659 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamtype.makeagg.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [AggParamType](./kibana-plugin-plugins-data-server.aggparamtype.md) > [makeAgg](./kibana-plugin-plugins-data-server.aggparamtype.makeagg.md) + +## AggParamType.makeAgg property + +Signature: + +```typescript +makeAgg: (agg: TAggConfig, state?: AggConfigSerialized) => TAggConfig; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamtype.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamtype.md new file mode 100644 index 0000000000000..00c1906dd880b --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.aggparamtype.md @@ -0,0 +1,25 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [AggParamType](./kibana-plugin-plugins-data-server.aggparamtype.md) + +## AggParamType class + +Signature: + +```typescript +export declare class AggParamType extends BaseParamType +``` + +## Constructors + +| Constructor | Modifiers | Description | +| --- | --- | --- | +| [(constructor)(config)](./kibana-plugin-plugins-data-server.aggparamtype._constructor_.md) | | Constructs a new instance of the AggParamType class | + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [allowedAggs](./kibana-plugin-plugins-data-server.aggparamtype.allowedaggs.md) | | string[] | | +| [makeAgg](./kibana-plugin-plugins-data-server.aggparamtype.makeagg.md) | | (agg: TAggConfig, state?: AggConfigSerialized) => TAggConfig | | + diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.bucket_types.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.bucket_types.md new file mode 100644 index 0000000000000..568e435754545 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.bucket_types.md @@ -0,0 +1,28 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [BUCKET\_TYPES](./kibana-plugin-plugins-data-server.bucket_types.md) + +## BUCKET\_TYPES enum + +Signature: + +```typescript +export declare enum BUCKET_TYPES +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| DATE\_HISTOGRAM | "date_histogram" | | +| DATE\_RANGE | "date_range" | | +| FILTER | "filter" | | +| FILTERS | "filters" | | +| GEOHASH\_GRID | "geohash_grid" | | +| GEOTILE\_GRID | "geotile_grid" | | +| HISTOGRAM | "histogram" | | +| IP\_RANGE | "ip_range" | | +| RANGE | "range" | | +| SIGNIFICANT\_TERMS | "significant_terms" | | +| TERMS | "terms" | | + diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iaggconfig.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iaggconfig.md new file mode 100644 index 0000000000000..261b6e0b3bac1 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iaggconfig.md @@ -0,0 +1,15 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IAggConfig](./kibana-plugin-plugins-data-server.iaggconfig.md) + +## IAggConfig type + + AggConfig + + This class represents an aggregation, which is displayed in the left-hand nav of the Visualize app. + +Signature: + +```typescript +export declare type IAggConfig = AggConfig; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iaggtype.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iaggtype.md new file mode 100644 index 0000000000000..d5868e1b0917e --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iaggtype.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IAggType](./kibana-plugin-plugins-data-server.iaggtype.md) + +## IAggType type + +Signature: + +```typescript +export declare type IAggType = AggType; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.ifieldparamtype.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.ifieldparamtype.md new file mode 100644 index 0000000000000..4937245647f4e --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.ifieldparamtype.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IFieldParamType](./kibana-plugin-plugins-data-server.ifieldparamtype.md) + +## IFieldParamType type + +Signature: + +```typescript +export declare type IFieldParamType = FieldParamType; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.imetricaggtype.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.imetricaggtype.md new file mode 100644 index 0000000000000..ae779c2b1510f --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.imetricaggtype.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IMetricAggType](./kibana-plugin-plugins-data-server.imetricaggtype.md) + +## IMetricAggType type + +Signature: + +```typescript +export declare type IMetricAggType = MetricAggType; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.aggs.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.aggs.md new file mode 100644 index 0000000000000..86bd4ab694e11 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.aggs.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISearchSetup](./kibana-plugin-plugins-data-server.isearchsetup.md) > [aggs](./kibana-plugin-plugins-data-server.isearchsetup.aggs.md) + +## ISearchSetup.aggs property + +Signature: + +```typescript +aggs: AggsSetup; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.md index d9749bc44f45a..e5b11a0b997ea 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsetup.md @@ -14,6 +14,7 @@ export interface ISearchSetup | Property | Type | Description | | --- | --- | --- | +| [aggs](./kibana-plugin-plugins-data-server.isearchsetup.aggs.md) | AggsSetup | | | [registerSearchStrategy](./kibana-plugin-plugins-data-server.isearchsetup.registersearchstrategy.md) | (name: string, strategy: ISearchStrategy) => void | Extension point exposed for other plugins to register their own search strategies. | | [usage](./kibana-plugin-plugins-data-server.isearchsetup.usage.md) | SearchUsage | Used internally for telemetry | diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.aggs.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.aggs.md new file mode 100644 index 0000000000000..8da429a07708c --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.aggs.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISearchStart](./kibana-plugin-plugins-data-server.isearchstart.md) > [aggs](./kibana-plugin-plugins-data-server.isearchstart.aggs.md) + +## ISearchStart.aggs property + +Signature: + +```typescript +aggs: AggsStart; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.md index 308ce3cb568bc..3762da963d4d9 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.md @@ -14,6 +14,7 @@ export interface ISearchStart | Property | Type | Description | | --- | --- | --- | +| [aggs](./kibana-plugin-plugins-data-server.isearchstart.aggs.md) | AggsStart | | | [getSearchStrategy](./kibana-plugin-plugins-data-server.isearchstart.getsearchstrategy.md) | (name: string) => ISearchStrategy | Get other registered search strategies. For example, if a new strategy needs to use the already-registered ES search strategy, it can use this function to accomplish that. | | [search](./kibana-plugin-plugins-data-server.isearchstart.search.md) | (context: RequestHandlerContext, request: IKibanaSearchRequest, options: ISearchOptions) => Promise<IKibanaSearchResponse> | | diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md index f472064c87755..0292e08063fbb 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md @@ -8,15 +8,19 @@ | Class | Description | | --- | --- | +| [AggParamType](./kibana-plugin-plugins-data-server.aggparamtype.md) | | | [IndexPatternsFetcher](./kibana-plugin-plugins-data-server.indexpatternsfetcher.md) | | +| [OptionedParamType](./kibana-plugin-plugins-data-server.optionedparamtype.md) | | | [Plugin](./kibana-plugin-plugins-data-server.plugin.md) | | ## Enumerations | Enumeration | Description | | --- | --- | +| [BUCKET\_TYPES](./kibana-plugin-plugins-data-server.bucket_types.md) | | | [ES\_FIELD\_TYPES](./kibana-plugin-plugins-data-server.es_field_types.md) | \* | | [KBN\_FIELD\_TYPES](./kibana-plugin-plugins-data-server.kbn_field_types.md) | \* | +| [METRIC\_TYPES](./kibana-plugin-plugins-data-server.metric_types.md) | | ## Functions @@ -33,6 +37,7 @@ | Interface | Description | | --- | --- | +| [AggParamOption](./kibana-plugin-plugins-data-server.aggparamoption.md) | | | [EsQueryConfig](./kibana-plugin-plugins-data-server.esqueryconfig.md) | | | [FieldFormatConfig](./kibana-plugin-plugins-data-server.fieldformatconfig.md) | | | [Filter](./kibana-plugin-plugins-data-server.filter.md) | | @@ -48,17 +53,22 @@ | [ISearchStart](./kibana-plugin-plugins-data-server.isearchstart.md) | | | [ISearchStrategy](./kibana-plugin-plugins-data-server.isearchstrategy.md) | Search strategy interface contains a search method that takes in a request and returns a promise that resolves to a response. | | [KueryNode](./kibana-plugin-plugins-data-server.kuerynode.md) | | +| [OptionedValueProp](./kibana-plugin-plugins-data-server.optionedvalueprop.md) | | | [PluginSetup](./kibana-plugin-plugins-data-server.pluginsetup.md) | | | [PluginStart](./kibana-plugin-plugins-data-server.pluginstart.md) | | | [Query](./kibana-plugin-plugins-data-server.query.md) | | | [RefreshInterval](./kibana-plugin-plugins-data-server.refreshinterval.md) | | | [SearchUsage](./kibana-plugin-plugins-data-server.searchusage.md) | | +| [TabbedAggColumn](./kibana-plugin-plugins-data-server.tabbedaggcolumn.md) | \* | +| [TabbedTable](./kibana-plugin-plugins-data-server.tabbedtable.md) | \* | | [TimeRange](./kibana-plugin-plugins-data-server.timerange.md) | | ## Variables | Variable | Description | | --- | --- | +| [AggGroupLabels](./kibana-plugin-plugins-data-server.agggrouplabels.md) | | +| [AggGroupNames](./kibana-plugin-plugins-data-server.agggroupnames.md) | | | [castEsToKbnFieldTypeName](./kibana-plugin-plugins-data-server.castestokbnfieldtypename.md) | Get the KbnFieldType name for an esType string | | [config](./kibana-plugin-plugins-data-server.config.md) | | | [esFilters](./kibana-plugin-plugins-data-server.esfilters.md) | | @@ -73,8 +83,16 @@ | Type Alias | Description | | --- | --- | +| [AggConfigOptions](./kibana-plugin-plugins-data-server.aggconfigoptions.md) | | +| [AggGroupName](./kibana-plugin-plugins-data-server.agggroupname.md) | | +| [AggParam](./kibana-plugin-plugins-data-server.aggparam.md) | | | [EsaggsExpressionFunctionDefinition](./kibana-plugin-plugins-data-server.esaggsexpressionfunctiondefinition.md) | | | [FieldFormatsGetConfigFn](./kibana-plugin-plugins-data-server.fieldformatsgetconfigfn.md) | | +| [IAggConfig](./kibana-plugin-plugins-data-server.iaggconfig.md) | AggConfig This class represents an aggregation, which is displayed in the left-hand nav of the Visualize app. | +| [IAggType](./kibana-plugin-plugins-data-server.iaggtype.md) | | | [IFieldFormatsRegistry](./kibana-plugin-plugins-data-server.ifieldformatsregistry.md) | | +| [IFieldParamType](./kibana-plugin-plugins-data-server.ifieldparamtype.md) | | +| [IMetricAggType](./kibana-plugin-plugins-data-server.imetricaggtype.md) | | | [ParsedInterval](./kibana-plugin-plugins-data-server.parsedinterval.md) | | +| [TabbedAggRow](./kibana-plugin-plugins-data-server.tabbedaggrow.md) | \* | diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.metric_types.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.metric_types.md new file mode 100644 index 0000000000000..49df98b6d70a1 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.metric_types.md @@ -0,0 +1,38 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [METRIC\_TYPES](./kibana-plugin-plugins-data-server.metric_types.md) + +## METRIC\_TYPES enum + +Signature: + +```typescript +export declare enum METRIC_TYPES +``` + +## Enumeration Members + +| Member | Value | Description | +| --- | --- | --- | +| AVG | "avg" | | +| AVG\_BUCKET | "avg_bucket" | | +| CARDINALITY | "cardinality" | | +| COUNT | "count" | | +| CUMULATIVE\_SUM | "cumulative_sum" | | +| DERIVATIVE | "derivative" | | +| GEO\_BOUNDS | "geo_bounds" | | +| GEO\_CENTROID | "geo_centroid" | | +| MAX | "max" | | +| MAX\_BUCKET | "max_bucket" | | +| MEDIAN | "median" | | +| MIN | "min" | | +| MIN\_BUCKET | "min_bucket" | | +| MOVING\_FN | "moving_avg" | | +| PERCENTILE\_RANKS | "percentile_ranks" | | +| PERCENTILES | "percentiles" | | +| SERIAL\_DIFF | "serial_diff" | | +| STD\_DEV | "std_dev" | | +| SUM | "sum" | | +| SUM\_BUCKET | "sum_bucket" | | +| TOP\_HITS | "top_hits" | | + diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedparamtype._constructor_.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedparamtype._constructor_.md new file mode 100644 index 0000000000000..3b2fd2218709a --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedparamtype._constructor_.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [OptionedParamType](./kibana-plugin-plugins-data-server.optionedparamtype.md) > [(constructor)](./kibana-plugin-plugins-data-server.optionedparamtype._constructor_.md) + +## OptionedParamType.(constructor) + +Constructs a new instance of the `OptionedParamType` class + +Signature: + +```typescript +constructor(config: Record); +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| config | Record<string, any> | | + diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedparamtype.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedparamtype.md new file mode 100644 index 0000000000000..6bf2ef4baa915 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedparamtype.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [OptionedParamType](./kibana-plugin-plugins-data-server.optionedparamtype.md) + +## OptionedParamType class + +Signature: + +```typescript +export declare class OptionedParamType extends BaseParamType +``` + +## Constructors + +| Constructor | Modifiers | Description | +| --- | --- | --- | +| [(constructor)(config)](./kibana-plugin-plugins-data-server.optionedparamtype._constructor_.md) | | Constructs a new instance of the OptionedParamType class | + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [options](./kibana-plugin-plugins-data-server.optionedparamtype.options.md) | | OptionedValueProp[] | | + diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedparamtype.options.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedparamtype.options.md new file mode 100644 index 0000000000000..868619ad5a9e0 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedparamtype.options.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [OptionedParamType](./kibana-plugin-plugins-data-server.optionedparamtype.md) > [options](./kibana-plugin-plugins-data-server.optionedparamtype.options.md) + +## OptionedParamType.options property + +Signature: + +```typescript +options: OptionedValueProp[]; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedvalueprop.disabled.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedvalueprop.disabled.md new file mode 100644 index 0000000000000..e0a21a8727614 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedvalueprop.disabled.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [OptionedValueProp](./kibana-plugin-plugins-data-server.optionedvalueprop.md) > [disabled](./kibana-plugin-plugins-data-server.optionedvalueprop.disabled.md) + +## OptionedValueProp.disabled property + +Signature: + +```typescript +disabled?: boolean; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedvalueprop.iscompatible.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedvalueprop.iscompatible.md new file mode 100644 index 0000000000000..de3ecc0b97a64 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedvalueprop.iscompatible.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [OptionedValueProp](./kibana-plugin-plugins-data-server.optionedvalueprop.md) > [isCompatible](./kibana-plugin-plugins-data-server.optionedvalueprop.iscompatible.md) + +## OptionedValueProp.isCompatible property + +Signature: + +```typescript +isCompatible: (agg: IAggConfig) => boolean; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedvalueprop.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedvalueprop.md new file mode 100644 index 0000000000000..ef2440035c83b --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedvalueprop.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [OptionedValueProp](./kibana-plugin-plugins-data-server.optionedvalueprop.md) + +## OptionedValueProp interface + +Signature: + +```typescript +export interface OptionedValueProp +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [disabled](./kibana-plugin-plugins-data-server.optionedvalueprop.disabled.md) | boolean | | +| [isCompatible](./kibana-plugin-plugins-data-server.optionedvalueprop.iscompatible.md) | (agg: IAggConfig) => boolean | | +| [text](./kibana-plugin-plugins-data-server.optionedvalueprop.text.md) | string | | +| [value](./kibana-plugin-plugins-data-server.optionedvalueprop.value.md) | string | | + diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedvalueprop.text.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedvalueprop.text.md new file mode 100644 index 0000000000000..0a2b3ac708038 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedvalueprop.text.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [OptionedValueProp](./kibana-plugin-plugins-data-server.optionedvalueprop.md) > [text](./kibana-plugin-plugins-data-server.optionedvalueprop.text.md) + +## OptionedValueProp.text property + +Signature: + +```typescript +text: string; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedvalueprop.value.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedvalueprop.value.md new file mode 100644 index 0000000000000..76618558d0479 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.optionedvalueprop.value.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [OptionedValueProp](./kibana-plugin-plugins-data-server.optionedvalueprop.md) > [value](./kibana-plugin-plugins-data-server.optionedvalueprop.value.md) + +## OptionedValueProp.value property + +Signature: + +```typescript +value: string; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.setup.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.setup.md index a6fdfdf6891c8..18fca3d2c8a66 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.setup.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.setup.md @@ -7,10 +7,10 @@ Signature: ```typescript -setup(core: CoreSetup, { usageCollection }: DataPluginSetupDependencies): { +setup(core: CoreSetup, { expressions, usageCollection }: DataPluginSetupDependencies): { search: ISearchSetup; fieldFormats: { - register: (customFieldFormat: import("../common").FieldFormatInstanceType) => number; + register: (customFieldFormat: import("../public").FieldFormatInstanceType) => number; }; }; ``` @@ -19,15 +19,15 @@ setup(core: CoreSetup, { usageCollection }: DataPluginS | Parameter | Type | Description | | --- | --- | --- | -| core | CoreSetup<object, DataPluginStart> | | -| { usageCollection } | DataPluginSetupDependencies | | +| core | CoreSetup<DataPluginStartDependencies, DataPluginStart> | | +| { expressions, usageCollection } | DataPluginSetupDependencies | | Returns: `{ search: ISearchSetup; fieldFormats: { - register: (customFieldFormat: import("../common").FieldFormatInstanceType) => number; + register: (customFieldFormat: import("../public").FieldFormatInstanceType) => number; }; }` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.search.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.search.md index 09563358100b3..9e38ce3f64f38 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.search.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.search.md @@ -9,15 +9,35 @@ ```typescript search: { aggs: { + CidrMask: typeof CidrMask; dateHistogramInterval: typeof dateHistogramInterval; + intervalOptions: ({ + display: string; + val: string; + enabled(agg: import("../common").IBucketAggConfig): boolean | "" | undefined; + } | { + display: string; + val: string; + })[]; InvalidEsCalendarIntervalError: typeof InvalidEsCalendarIntervalError; InvalidEsIntervalFormatError: typeof InvalidEsIntervalFormatError; Ipv4Address: typeof Ipv4Address; + isNumberType: (agg: import("../common").AggConfig) => boolean; + isStringType: (agg: import("../common").AggConfig) => boolean; + isType: (...types: string[]) => (agg: import("../common").AggConfig) => boolean; isValidEsInterval: typeof isValidEsInterval; isValidInterval: typeof isValidInterval; + parentPipelineType: string; parseEsInterval: typeof parseEsInterval; parseInterval: typeof parseInterval; + propFilter: typeof propFilter; + siblingPipelineType: string; + termsAggFilter: string[]; toAbsoluteDates: typeof toAbsoluteDates; }; + getRequestInspectorStats: typeof getRequestInspectorStats; + getResponseInspectorStats: typeof getResponseInspectorStats; + tabifyAggResponse: typeof tabifyAggResponse; + tabifyGetColumns: typeof tabifyGetColumns; } ``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedaggcolumn.aggconfig.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedaggcolumn.aggconfig.md new file mode 100644 index 0000000000000..9870f7380e16a --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedaggcolumn.aggconfig.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [TabbedAggColumn](./kibana-plugin-plugins-data-server.tabbedaggcolumn.md) > [aggConfig](./kibana-plugin-plugins-data-server.tabbedaggcolumn.aggconfig.md) + +## TabbedAggColumn.aggConfig property + +Signature: + +```typescript +aggConfig: IAggConfig; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedaggcolumn.id.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedaggcolumn.id.md new file mode 100644 index 0000000000000..4f5a964a07a0c --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedaggcolumn.id.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [TabbedAggColumn](./kibana-plugin-plugins-data-server.tabbedaggcolumn.md) > [id](./kibana-plugin-plugins-data-server.tabbedaggcolumn.id.md) + +## TabbedAggColumn.id property + +Signature: + +```typescript +id: string; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedaggcolumn.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedaggcolumn.md new file mode 100644 index 0000000000000..5e47f745fa17a --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedaggcolumn.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [TabbedAggColumn](./kibana-plugin-plugins-data-server.tabbedaggcolumn.md) + +## TabbedAggColumn interface + +\* + +Signature: + +```typescript +export interface TabbedAggColumn +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [aggConfig](./kibana-plugin-plugins-data-server.tabbedaggcolumn.aggconfig.md) | IAggConfig | | +| [id](./kibana-plugin-plugins-data-server.tabbedaggcolumn.id.md) | string | | +| [name](./kibana-plugin-plugins-data-server.tabbedaggcolumn.name.md) | string | | + diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedaggcolumn.name.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedaggcolumn.name.md new file mode 100644 index 0000000000000..8a07e2708066f --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedaggcolumn.name.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [TabbedAggColumn](./kibana-plugin-plugins-data-server.tabbedaggcolumn.md) > [name](./kibana-plugin-plugins-data-server.tabbedaggcolumn.name.md) + +## TabbedAggColumn.name property + +Signature: + +```typescript +name: string; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedaggrow.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedaggrow.md new file mode 100644 index 0000000000000..d592aeff89639 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedaggrow.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [TabbedAggRow](./kibana-plugin-plugins-data-server.tabbedaggrow.md) + +## TabbedAggRow type + +\* + +Signature: + +```typescript +export declare type TabbedAggRow = Record; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedtable.columns.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedtable.columns.md new file mode 100644 index 0000000000000..55f079c581c8b --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedtable.columns.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [TabbedTable](./kibana-plugin-plugins-data-server.tabbedtable.md) > [columns](./kibana-plugin-plugins-data-server.tabbedtable.columns.md) + +## TabbedTable.columns property + +Signature: + +```typescript +columns: TabbedAggColumn[]; +``` diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedtable.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedtable.md new file mode 100644 index 0000000000000..1bb055a2a3ce9 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedtable.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [TabbedTable](./kibana-plugin-plugins-data-server.tabbedtable.md) + +## TabbedTable interface + +\* + +Signature: + +```typescript +export interface TabbedTable +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [columns](./kibana-plugin-plugins-data-server.tabbedtable.columns.md) | TabbedAggColumn[] | | +| [rows](./kibana-plugin-plugins-data-server.tabbedtable.rows.md) | TabbedAggRow[] | | + diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedtable.rows.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedtable.rows.md new file mode 100644 index 0000000000000..b783919a26573 --- /dev/null +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.tabbedtable.rows.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [TabbedTable](./kibana-plugin-plugins-data-server.tabbedtable.md) > [rows](./kibana-plugin-plugins-data-server.tabbedtable.rows.md) + +## TabbedTable.rows property + +Signature: + +```typescript +rows: TabbedAggRow[]; +``` diff --git a/src/legacy/ui/public/new_platform/new_platform.karma_mock.js b/src/legacy/ui/public/new_platform/new_platform.karma_mock.js index 35380ada51a0a..5ef1149146afe 100644 --- a/src/legacy/ui/public/new_platform/new_platform.karma_mock.js +++ b/src/legacy/ui/public/new_platform/new_platform.karma_mock.js @@ -26,7 +26,7 @@ import { getAggTypes, AggConfigs, // eslint-disable-next-line @kbn/eslint/no-restricted-paths -} from '../../../../../src/plugins/data/public/search/aggs'; +} from '../../../../../src/plugins/data/common/search/aggs'; import { ComponentRegistry } from '../../../../../src/plugins/advanced_settings/public/'; import { UI_SETTINGS } from '../../../../../src/plugins/data/public/'; import { @@ -184,12 +184,13 @@ const mockAggTypesRegistry = () => { const registry = new AggTypesRegistry(); const registrySetup = registry.setup(); const aggTypes = getAggTypes({ - uiSettings: mockCoreSetup.uiSettings, - query: querySetup, - getInternalStartServices: () => ({ - fieldFormats: getFieldFormatsRegistry(mockCoreStart), - notifications: mockCoreStart.notifications, + calculateBounds: sinon.fake(), + getConfig: sinon.fake(), + getFieldFormatsStart: () => ({ + deserialize: sinon.fake(), + getDefaultInstance: sinon.fake(), }), + isDefaultTimezone: () => true, }); aggTypes.buckets.forEach((type) => registrySetup.registerBucket(type)); aggTypes.metrics.forEach((type) => registrySetup.registerMetric(type)); @@ -240,7 +241,6 @@ export const npSetup = { query: querySetup, search: { aggs: { - calculateAutoTimeExpression: sinon.fake(), types: aggTypesRegistry.setup(), }, __LEGACY: { diff --git a/src/plugins/data/common/field_formats/converters/source.ts b/src/plugins/data/common/field_formats/converters/source.ts index f00261e00971a..9c81bb011e127 100644 --- a/src/plugins/data/common/field_formats/converters/source.ts +++ b/src/plugins/data/common/field_formats/converters/source.ts @@ -22,7 +22,7 @@ import { shortenDottedString } from '../../utils'; import { KBN_FIELD_TYPES } from '../../kbn_field_types/types'; import { FieldFormat } from '../field_format'; import { TextContextTypeConvert, HtmlContextTypeConvert, FIELD_FORMAT_IDS } from '../types'; -import { UI_SETTINGS } from '../../'; +import { UI_SETTINGS } from '../../constants'; /** * Remove all of the whitespace between html tags diff --git a/src/plugins/data/common/field_formats/field_formats_registry.ts b/src/plugins/data/common/field_formats/field_formats_registry.ts index 84bedd2f9dee0..4b847ebc358d7 100644 --- a/src/plugins/data/common/field_formats/field_formats_registry.ts +++ b/src/plugins/data/common/field_formats/field_formats_registry.ts @@ -33,7 +33,7 @@ import { baseFormatters } from './constants/base_formatters'; import { FieldFormat } from './field_format'; import { SerializedFieldFormat } from '../../../expressions/common/types'; import { ES_FIELD_TYPES, KBN_FIELD_TYPES } from '../types'; -import { UI_SETTINGS } from '../'; +import { UI_SETTINGS } from '../constants'; export class FieldFormatsRegistry { protected fieldFormats: Map = new Map(); diff --git a/src/plugins/data/common/field_formats/mocks.ts b/src/plugins/data/common/field_formats/mocks.ts index 9bbaefe2d146a..ddf9cf246ec7d 100644 --- a/src/plugins/data/common/field_formats/mocks.ts +++ b/src/plugins/data/common/field_formats/mocks.ts @@ -24,6 +24,7 @@ export const fieldFormatsMock: IFieldFormatsRegistry = { getByFieldType: jest.fn(), getDefaultConfig: jest.fn(), getDefaultInstance: jest.fn().mockImplementation(() => ({ + convert: jest.fn().mockImplementation((t: string) => t), getConverterFor: jest.fn().mockImplementation(() => (t: string) => t), })) as any, getDefaultInstanceCacheResolver: jest.fn(), diff --git a/src/plugins/data/common/index.ts b/src/plugins/data/common/index.ts index ca6bc965d48c5..bc7080e7d450b 100644 --- a/src/plugins/data/common/index.ts +++ b/src/plugins/data/common/index.ts @@ -25,7 +25,5 @@ export * from './index_patterns'; export * from './kbn_field_types'; export * from './query'; export * from './search'; -export * from './search/aggs'; -export * from './search/expressions'; export * from './types'; export * from './utils'; diff --git a/src/plugins/data/common/index_patterns/fields/field_list.ts b/src/plugins/data/common/index_patterns/fields/field_list.ts index 172da9f9ca43f..34bd69230a2e4 100644 --- a/src/plugins/data/common/index_patterns/fields/field_list.ts +++ b/src/plugins/data/common/index_patterns/fields/field_list.ts @@ -18,10 +18,11 @@ */ import { findIndex } from 'lodash'; -import { IFieldType, shortenDottedString } from '../../../common'; +import { IFieldType } from './types'; import { IndexPatternField } from './index_pattern_field'; import { OnNotification, FieldSpec } from '../types'; import { IndexPattern } from '../index_patterns'; +import { shortenDottedString } from '../../utils'; type FieldMap = Map; diff --git a/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts b/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts index 679de103f8019..965f1a7f63065 100644 --- a/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts +++ b/src/plugins/data/common/index_patterns/fields/index_pattern_field.ts @@ -18,13 +18,10 @@ */ import { i18n } from '@kbn/i18n'; -import { - IFieldType, - KbnFieldType, - getKbnFieldType, - KBN_FIELD_TYPES, - FieldFormat, -} from '../../../common'; +import { KbnFieldType, getKbnFieldType } from '../../kbn_field_types'; +import { KBN_FIELD_TYPES } from '../../kbn_field_types/types'; +import { FieldFormat } from '../../field_formats'; +import { IFieldType } from './types'; import { OnNotification, FieldSpec } from '../types'; import { IndexPattern } from '../index_patterns'; diff --git a/src/plugins/data/public/search/aggs/agg_config.test.ts b/src/plugins/data/common/search/aggs/agg_config.test.ts similarity index 98% rename from src/plugins/data/public/search/aggs/agg_config.test.ts rename to src/plugins/data/common/search/aggs/agg_config.test.ts index f9279e06d14a9..a443eacee731c 100644 --- a/src/plugins/data/public/search/aggs/agg_config.test.ts +++ b/src/plugins/data/common/search/aggs/agg_config.test.ts @@ -25,7 +25,8 @@ import { AggType } from './agg_type'; import { AggTypesRegistryStart } from './agg_types_registry'; import { mockAggTypesRegistry } from './test_helpers'; import { MetricAggType } from './metrics/metric_agg_type'; -import { IndexPattern, IIndexPatternFieldList } from '../../index_patterns'; +import { IndexPattern } from '../../index_patterns/index_patterns/index_pattern'; +import { IIndexPatternFieldList } from '../../index_patterns/fields'; describe('AggConfig', () => { let indexPattern: IndexPattern; @@ -622,7 +623,7 @@ describe('AggConfig', () => { it('creates a subexpression for param types other than "agg" which have specified toExpressionAst', () => { // Overwrite the `ranges` param in the `range` agg with a mock toExpressionAst function - const range: MetricAggType = typesRegistry.get('range'); + const range = typesRegistry.get('range') as MetricAggType; range.expressionName = 'aggRange'; const rangesParam = range.params.find((p) => p.name === 'ranges'); rangesParam!.toExpressionAst = (val: any) => ({ diff --git a/src/plugins/data/public/search/aggs/agg_config.ts b/src/plugins/data/common/search/aggs/agg_config.ts similarity index 99% rename from src/plugins/data/public/search/aggs/agg_config.ts rename to src/plugins/data/common/search/aggs/agg_config.ts index 31618eac18e98..b5747ce7bb9bd 100644 --- a/src/plugins/data/public/search/aggs/agg_config.ts +++ b/src/plugins/data/common/search/aggs/agg_config.ts @@ -20,16 +20,17 @@ import _ from 'lodash'; import { i18n } from '@kbn/i18n'; import { Assign, Ensure } from '@kbn/utility-types'; + +import { FetchOptions, ISearchSource } from 'src/plugins/data/public'; import { ExpressionAstFunction, ExpressionAstArgument, SerializedFieldFormat, } from 'src/plugins/expressions/common'; + import { IAggType } from './agg_type'; import { writeParams } from './agg_params'; import { IAggConfigs } from './agg_configs'; -import { FetchOptions } from '../fetch'; -import { ISearchSource } from '../search_source'; type State = string | number | boolean | null | undefined | SerializableState; diff --git a/src/plugins/data/public/search/aggs/agg_configs.test.ts b/src/plugins/data/common/search/aggs/agg_configs.test.ts similarity index 98% rename from src/plugins/data/public/search/aggs/agg_configs.test.ts rename to src/plugins/data/common/search/aggs/agg_configs.test.ts index ff0cc3341929e..803ccc70b98a7 100644 --- a/src/plugins/data/public/search/aggs/agg_configs.test.ts +++ b/src/plugins/data/common/search/aggs/agg_configs.test.ts @@ -22,8 +22,9 @@ import { AggConfig } from './agg_config'; import { AggConfigs } from './agg_configs'; import { AggTypesRegistryStart } from './agg_types_registry'; import { mockAggTypesRegistry } from './test_helpers'; -import { IndexPatternField, IndexPattern } from '../../index_patterns'; -import { stubIndexPattern, stubIndexPatternWithFields } from '../../../public/stubs'; +import type { IndexPatternField } from '../../index_patterns'; +import { IndexPattern } from '../../index_patterns/index_patterns/index_pattern'; +import { stubIndexPattern, stubIndexPatternWithFields } from '../../../common/stubs'; describe('AggConfigs', () => { let indexPattern: IndexPattern; diff --git a/src/plugins/data/public/search/aggs/agg_configs.ts b/src/plugins/data/common/search/aggs/agg_configs.ts similarity index 98% rename from src/plugins/data/public/search/aggs/agg_configs.ts rename to src/plugins/data/common/search/aggs/agg_configs.ts index b272dfd3c7468..203eda3a907ee 100644 --- a/src/plugins/data/public/search/aggs/agg_configs.ts +++ b/src/plugins/data/common/search/aggs/agg_configs.ts @@ -20,13 +20,12 @@ import _ from 'lodash'; import { Assign } from '@kbn/utility-types'; +import { FetchOptions, ISearchSource } from 'src/plugins/data/public'; import { AggConfig, AggConfigSerialized, IAggConfig } from './agg_config'; import { IAggType } from './agg_type'; import { AggTypesRegistryStart } from './agg_types_registry'; import { AggGroupNames } from './agg_groups'; -import { IndexPattern } from '../../index_patterns'; -import { ISearchSource } from '../search_source'; -import { FetchOptions } from '../fetch'; +import { IndexPattern } from '../../index_patterns/index_patterns/index_pattern'; import { TimeRange } from '../../../common'; function removeParentAggs(obj: any) { diff --git a/src/plugins/data/public/search/aggs/agg_groups.ts b/src/plugins/data/common/search/aggs/agg_groups.ts similarity index 100% rename from src/plugins/data/public/search/aggs/agg_groups.ts rename to src/plugins/data/common/search/aggs/agg_groups.ts diff --git a/src/plugins/data/public/search/aggs/agg_params.test.ts b/src/plugins/data/common/search/aggs/agg_params.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/agg_params.test.ts rename to src/plugins/data/common/search/aggs/agg_params.test.ts diff --git a/src/plugins/data/public/search/aggs/agg_params.ts b/src/plugins/data/common/search/aggs/agg_params.ts similarity index 100% rename from src/plugins/data/public/search/aggs/agg_params.ts rename to src/plugins/data/common/search/aggs/agg_params.ts diff --git a/src/plugins/data/public/search/aggs/agg_type.test.ts b/src/plugins/data/common/search/aggs/agg_type.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/agg_type.test.ts rename to src/plugins/data/common/search/aggs/agg_type.test.ts diff --git a/src/plugins/data/public/search/aggs/agg_type.ts b/src/plugins/data/common/search/aggs/agg_type.ts similarity index 99% rename from src/plugins/data/public/search/aggs/agg_type.ts rename to src/plugins/data/common/search/aggs/agg_type.ts index de7ca48e71d57..0ba2bb66e7758 100644 --- a/src/plugins/data/public/search/aggs/agg_type.ts +++ b/src/plugins/data/common/search/aggs/agg_type.ts @@ -20,6 +20,7 @@ import { constant, noop, identity } from 'lodash'; import { i18n } from '@kbn/i18n'; +import { ISearchSource } from 'src/plugins/data/public'; import { SerializedFieldFormat } from 'src/plugins/expressions/common'; import type { RequestAdapter } from 'src/plugins/inspector/common'; @@ -28,7 +29,6 @@ import { AggConfig } from './agg_config'; import { IAggConfigs } from './agg_configs'; import { BaseParamType } from './param_types/base'; import { AggParamType } from './param_types/agg'; -import { ISearchSource } from '../search_source'; export interface AggTypeConfig< TAggConfig extends AggConfig = AggConfig, diff --git a/src/plugins/data/public/search/aggs/agg_types.ts b/src/plugins/data/common/search/aggs/agg_types.ts similarity index 66% rename from src/plugins/data/public/search/aggs/agg_types.ts rename to src/plugins/data/common/search/aggs/agg_types.ts index 2820ae495f318..8565de13aed5b 100644 --- a/src/plugins/data/public/search/aggs/agg_types.ts +++ b/src/plugins/data/common/search/aggs/agg_types.ts @@ -17,9 +17,9 @@ * under the License. */ -import { IUiSettingsClient } from 'src/core/public'; -import { TimeRange, TimeRangeBounds } from '../../../common'; -import { GetInternalStartServicesFn } from '../../types'; +import { FieldFormatsStartCommon } from '../../field_formats'; +import { BUCKET_TYPES } from './buckets'; +import { METRIC_TYPES } from './metrics'; import { getCountMetricAgg } from './metrics/count'; import { getAvgMetricAgg } from './metrics/avg'; @@ -39,7 +39,7 @@ import { getCumulativeSumMetricAgg } from './metrics/cumulative_sum'; import { getMovingAvgMetricAgg } from './metrics/moving_avg'; import { getSerialDiffMetricAgg } from './metrics/serial_diff'; -import { getDateHistogramBucketAgg } from './buckets/date_histogram'; +import { getDateHistogramBucketAgg, CalculateBoundsFn } from './buckets/date_histogram'; import { getHistogramBucketAgg } from './buckets/histogram'; import { getRangeBucketAgg } from './buckets/range'; import { getDateRangeBucketAgg } from './buckets/date_range'; @@ -55,52 +55,50 @@ import { getBucketAvgMetricAgg } from './metrics/bucket_avg'; import { getBucketMinMetricAgg } from './metrics/bucket_min'; import { getBucketMaxMetricAgg } from './metrics/bucket_max'; +/** @internal */ export interface AggTypesDependencies { - calculateBounds: (timeRange: TimeRange) => TimeRangeBounds; - getInternalStartServices: GetInternalStartServicesFn; - uiSettings: IUiSettingsClient; + calculateBounds: CalculateBoundsFn; + getConfig: (key: string) => T; + getFieldFormatsStart: () => Pick; + isDefaultTimezone: () => boolean; } -export const getAggTypes = ({ - calculateBounds, - getInternalStartServices, - uiSettings, -}: AggTypesDependencies) => ({ +export const getAggTypes = () => ({ metrics: [ - getCountMetricAgg(), - getAvgMetricAgg(), - getSumMetricAgg(), - getMedianMetricAgg(), - getMinMetricAgg(), - getMaxMetricAgg(), - getStdDeviationMetricAgg(), - getCardinalityMetricAgg(), - getPercentilesMetricAgg(), - getPercentileRanksMetricAgg({ getInternalStartServices }), - getTopHitMetricAgg(), - getDerivativeMetricAgg(), - getCumulativeSumMetricAgg(), - getMovingAvgMetricAgg(), - getSerialDiffMetricAgg(), - getBucketAvgMetricAgg(), - getBucketSumMetricAgg(), - getBucketMinMetricAgg(), - getBucketMaxMetricAgg(), - getGeoBoundsMetricAgg(), - getGeoCentroidMetricAgg(), + { name: METRIC_TYPES.COUNT, fn: getCountMetricAgg }, + { name: METRIC_TYPES.AVG, fn: getAvgMetricAgg }, + { name: METRIC_TYPES.SUM, fn: getSumMetricAgg }, + { name: METRIC_TYPES.MEDIAN, fn: getMedianMetricAgg }, + { name: METRIC_TYPES.MIN, fn: getMinMetricAgg }, + { name: METRIC_TYPES.MAX, fn: getMaxMetricAgg }, + { name: METRIC_TYPES.STD_DEV, fn: getStdDeviationMetricAgg }, + { name: METRIC_TYPES.CARDINALITY, fn: getCardinalityMetricAgg }, + { name: METRIC_TYPES.PERCENTILES, fn: getPercentilesMetricAgg }, + { name: METRIC_TYPES.PERCENTILE_RANKS, fn: getPercentileRanksMetricAgg }, + { name: METRIC_TYPES.TOP_HITS, fn: getTopHitMetricAgg }, + { name: METRIC_TYPES.DERIVATIVE, fn: getDerivativeMetricAgg }, + { name: METRIC_TYPES.CUMULATIVE_SUM, fn: getCumulativeSumMetricAgg }, + { name: METRIC_TYPES.MOVING_FN, fn: getMovingAvgMetricAgg }, + { name: METRIC_TYPES.SERIAL_DIFF, fn: getSerialDiffMetricAgg }, + { name: METRIC_TYPES.AVG_BUCKET, fn: getBucketAvgMetricAgg }, + { name: METRIC_TYPES.SUM_BUCKET, fn: getBucketSumMetricAgg }, + { name: METRIC_TYPES.MIN_BUCKET, fn: getBucketMinMetricAgg }, + { name: METRIC_TYPES.MAX_BUCKET, fn: getBucketMaxMetricAgg }, + { name: METRIC_TYPES.GEO_BOUNDS, fn: getGeoBoundsMetricAgg }, + { name: METRIC_TYPES.GEO_CENTROID, fn: getGeoCentroidMetricAgg }, ], buckets: [ - getDateHistogramBucketAgg({ calculateBounds, uiSettings }), - getHistogramBucketAgg({ uiSettings, getInternalStartServices }), - getRangeBucketAgg({ getInternalStartServices }), - getDateRangeBucketAgg({ uiSettings }), - getIpRangeBucketAgg(), - getTermsBucketAgg(), - getFilterBucketAgg(), - getFiltersBucketAgg({ uiSettings }), - getSignificantTermsBucketAgg(), - getGeoHashBucketAgg(), - getGeoTitleBucketAgg(), + { name: BUCKET_TYPES.DATE_HISTOGRAM, fn: getDateHistogramBucketAgg }, + { name: BUCKET_TYPES.HISTOGRAM, fn: getHistogramBucketAgg }, + { name: BUCKET_TYPES.RANGE, fn: getRangeBucketAgg }, + { name: BUCKET_TYPES.DATE_RANGE, fn: getDateRangeBucketAgg }, + { name: BUCKET_TYPES.IP_RANGE, fn: getIpRangeBucketAgg }, + { name: BUCKET_TYPES.TERMS, fn: getTermsBucketAgg }, + { name: BUCKET_TYPES.FILTER, fn: getFilterBucketAgg }, + { name: BUCKET_TYPES.FILTERS, fn: getFiltersBucketAgg }, + { name: BUCKET_TYPES.SIGNIFICANT_TERMS, fn: getSignificantTermsBucketAgg }, + { name: BUCKET_TYPES.GEOHASH_GRID, fn: getGeoHashBucketAgg }, + { name: BUCKET_TYPES.GEOTILE_GRID, fn: getGeoTitleBucketAgg }, ], }); diff --git a/src/plugins/data/public/search/aggs/agg_types_registry.test.ts b/src/plugins/data/common/search/aggs/agg_types_registry.test.ts similarity index 54% rename from src/plugins/data/public/search/aggs/agg_types_registry.test.ts rename to src/plugins/data/common/search/aggs/agg_types_registry.test.ts index 58d1a07d965e2..df3dddfcd9c6f 100644 --- a/src/plugins/data/public/search/aggs/agg_types_registry.test.ts +++ b/src/plugins/data/common/search/aggs/agg_types_registry.test.ts @@ -17,21 +17,17 @@ * under the License. */ -import { - AggTypesRegistry, - AggTypesRegistrySetup, - AggTypesRegistryStart, -} from './agg_types_registry'; +import { AggTypesRegistry, AggTypesRegistrySetup } from './agg_types_registry'; import { BucketAggType } from './buckets/bucket_agg_type'; import { MetricAggType } from './metrics/metric_agg_type'; -const bucketType = { name: 'terms', type: 'bucket' } as BucketAggType; -const metricType = { name: 'count', type: 'metric' } as MetricAggType; +const bucketType = () => ({ name: 'terms', type: 'buckets' } as BucketAggType); +const metricType = () => ({ name: 'count', type: 'metrics' } as MetricAggType); describe('AggTypesRegistry', () => { let registry: AggTypesRegistry; let setup: AggTypesRegistrySetup; - let start: AggTypesRegistryStart; + let start: ReturnType; beforeEach(() => { registry = new AggTypesRegistry(); @@ -40,49 +36,53 @@ describe('AggTypesRegistry', () => { }); it('registerBucket adds new buckets', () => { - setup.registerBucket(bucketType); - expect(start.getBuckets()).toEqual([bucketType]); + setup.registerBucket('terms', bucketType); + expect(start.getAll().buckets).toEqual([bucketType]); }); it('registerBucket throws error when registering duplicate bucket', () => { expect(() => { - setup.registerBucket(bucketType); - setup.registerBucket(bucketType); + setup.registerBucket('terms', bucketType); + setup.registerBucket('terms', bucketType); }).toThrow(/already been registered with name: terms/); + + const fooBucket = () => ({ name: 'foo', type: 'buckets' } as BucketAggType); + const fooMetric = () => ({ name: 'foo', type: 'metrics' } as MetricAggType); + expect(() => { + setup.registerBucket('foo', fooBucket); + setup.registerMetric('foo', fooMetric); + }).toThrow(/already been registered with name: foo/); }); it('registerMetric adds new metrics', () => { - setup.registerMetric(metricType); - expect(start.getMetrics()).toEqual([metricType]); + setup.registerMetric('count', metricType); + expect(start.getAll().metrics).toEqual([metricType]); }); it('registerMetric throws error when registering duplicate metric', () => { expect(() => { - setup.registerMetric(metricType); - setup.registerMetric(metricType); + setup.registerMetric('count', metricType); + setup.registerMetric('count', metricType); }).toThrow(/already been registered with name: count/); + + const fooBucket = () => ({ name: 'foo', type: 'buckets' } as BucketAggType); + const fooMetric = () => ({ name: 'foo', type: 'metrics' } as MetricAggType); + expect(() => { + setup.registerMetric('foo', fooMetric); + setup.registerBucket('foo', fooBucket); + }).toThrow(/already been registered with name: foo/); }); it('gets either buckets or metrics by id', () => { - setup.registerBucket(bucketType); - setup.registerMetric(metricType); + setup.registerBucket('terms', bucketType); + setup.registerMetric('count', metricType); expect(start.get('terms')).toEqual(bucketType); expect(start.get('count')).toEqual(metricType); }); - it('getBuckets retrieves only buckets', () => { - setup.registerBucket(bucketType); - expect(start.getBuckets()).toEqual([bucketType]); - }); - - it('getMetrics retrieves only metrics', () => { - setup.registerMetric(metricType); - expect(start.getMetrics()).toEqual([metricType]); - }); - it('getAll returns all buckets and metrics', () => { - setup.registerBucket(bucketType); - setup.registerMetric(metricType); + setup.registerBucket('terms', bucketType); + setup.registerMetric('count', metricType); expect(start.getAll()).toEqual({ buckets: [bucketType], metrics: [metricType], diff --git a/src/plugins/data/public/search/aggs/agg_types_registry.ts b/src/plugins/data/common/search/aggs/agg_types_registry.ts similarity index 57% rename from src/plugins/data/public/search/aggs/agg_types_registry.ts rename to src/plugins/data/common/search/aggs/agg_types_registry.ts index 5a0c58120d810..ce22fa840bafa 100644 --- a/src/plugins/data/public/search/aggs/agg_types_registry.ts +++ b/src/plugins/data/common/search/aggs/agg_types_registry.ts @@ -19,9 +19,21 @@ import { BucketAggType } from './buckets/bucket_agg_type'; import { MetricAggType } from './metrics/metric_agg_type'; +import { AggTypesDependencies } from './agg_types'; export type AggTypesRegistrySetup = ReturnType; -export type AggTypesRegistryStart = ReturnType; +/** + * AggsCommonStart returns the _unitialized_ agg type providers, but in our + * real start contract we will need to return the initialized versions. + * So we need to provide the correct typings so they can be overwritten + * on client/server. + * + * @internal + */ +export interface AggTypesRegistryStart { + get: (id: string) => BucketAggType | MetricAggType; + getAll: () => { buckets: Array>; metrics: Array> }; +} export class AggTypesRegistry { private readonly bucketAggs = new Map(); @@ -29,17 +41,27 @@ export class AggTypesRegistry { setup = () => { return { - registerBucket: >(type: T): void => { - const { name } = type; - if (this.bucketAggs.get(name)) { - throw new Error(`Bucket agg has already been registered with name: ${name}`); + registerBucket: < + N extends string, + T extends (deps: AggTypesDependencies) => BucketAggType + >( + name: N, + type: T + ): void => { + if (this.bucketAggs.get(name) || this.metricAggs.get(name)) { + throw new Error(`Agg has already been registered with name: ${name}`); } this.bucketAggs.set(name, type); }, - registerMetric: >(type: T): void => { - const { name } = type; - if (this.metricAggs.get(name)) { - throw new Error(`Metric agg has already been registered with name: ${name}`); + registerMetric: < + N extends string, + T extends (deps: AggTypesDependencies) => MetricAggType + >( + name: N, + type: T + ): void => { + if (this.bucketAggs.get(name) || this.metricAggs.get(name)) { + throw new Error(`Agg has already been registered with name: ${name}`); } this.metricAggs.set(name, type); }, @@ -51,12 +73,6 @@ export class AggTypesRegistry { get: (name: string) => { return this.bucketAggs.get(name) || this.metricAggs.get(name); }, - getBuckets: () => { - return Array.from(this.bucketAggs.values()); - }, - getMetrics: () => { - return Array.from(this.metricAggs.values()); - }, getAll: () => { return { buckets: Array.from(this.bucketAggs.values()), diff --git a/src/plugins/data/common/search/aggs/aggs_service.test.ts b/src/plugins/data/common/search/aggs/aggs_service.test.ts new file mode 100644 index 0000000000000..bcf2101704c80 --- /dev/null +++ b/src/plugins/data/common/search/aggs/aggs_service.test.ts @@ -0,0 +1,217 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { + AggsCommonService, + AggsCommonSetupDependencies, + AggsCommonStartDependencies, +} from './aggs_service'; +import { AggTypesDependencies, getAggTypes } from './agg_types'; +import { BucketAggType } from './buckets/bucket_agg_type'; +import { MetricAggType } from './metrics/metric_agg_type'; + +describe('Aggs service', () => { + let service: AggsCommonService; + let setupDeps: AggsCommonSetupDependencies; + let startDeps: AggsCommonStartDependencies; + const aggTypesDependencies: AggTypesDependencies = { + calculateBounds: jest.fn(), + getFieldFormatsStart: jest.fn(), + getConfig: jest.fn(), + isDefaultTimezone: () => true, + }; + + beforeEach(() => { + service = new AggsCommonService(); + setupDeps = { + registerFunction: jest.fn(), + }; + startDeps = { + getConfig: jest.fn(), + }; + }); + + describe('setup()', () => { + test('exposes proper contract', () => { + const setup = service.setup(setupDeps); + expect(Object.keys(setup).length).toBe(1); + expect(setup).toHaveProperty('types'); + }); + + test('instantiates a new registry', () => { + const a = new AggsCommonService(); + const b = new AggsCommonService(); + const bSetupDeps = { + registerFunction: jest.fn(), + }; + + const aSetup = a.setup(setupDeps); + aSetup.types.registerBucket( + 'foo', + () => ({ name: 'foo', type: 'buckets' } as BucketAggType) + ); + const aStart = a.start(startDeps); + expect(aStart.types.getAll().buckets.map((t) => t(aggTypesDependencies).name)) + .toMatchInlineSnapshot(` + Array [ + "date_histogram", + "histogram", + "range", + "date_range", + "ip_range", + "terms", + "filter", + "filters", + "significant_terms", + "geohash_grid", + "geotile_grid", + "foo", + ] + `); + expect(aStart.types.getAll().metrics.map((t) => t(aggTypesDependencies).name)) + .toMatchInlineSnapshot(` + Array [ + "count", + "avg", + "sum", + "median", + "min", + "max", + "std_dev", + "cardinality", + "percentiles", + "percentile_ranks", + "top_hits", + "derivative", + "cumulative_sum", + "moving_avg", + "serial_diff", + "avg_bucket", + "sum_bucket", + "min_bucket", + "max_bucket", + "geo_bounds", + "geo_centroid", + ] + `); + + b.setup(bSetupDeps); + const bStart = b.start(startDeps); + expect(bStart.types.getAll().buckets.map((t) => t(aggTypesDependencies).name)) + .toMatchInlineSnapshot(` + Array [ + "date_histogram", + "histogram", + "range", + "date_range", + "ip_range", + "terms", + "filter", + "filters", + "significant_terms", + "geohash_grid", + "geotile_grid", + ] + `); + expect(bStart.types.getAll().metrics.map((t) => t(aggTypesDependencies).name)) + .toMatchInlineSnapshot(` + Array [ + "count", + "avg", + "sum", + "median", + "min", + "max", + "std_dev", + "cardinality", + "percentiles", + "percentile_ranks", + "top_hits", + "derivative", + "cumulative_sum", + "moving_avg", + "serial_diff", + "avg_bucket", + "sum_bucket", + "min_bucket", + "max_bucket", + "geo_bounds", + "geo_centroid", + ] + `); + }); + + test('registers default agg types', () => { + service.setup(setupDeps); + const start = service.start(startDeps); + + const aggTypes = getAggTypes(); + expect(start.types.getAll().buckets.length).toBe(aggTypes.buckets.length); + expect(start.types.getAll().metrics.length).toBe(aggTypes.metrics.length); + }); + + test('merges default agg types with types registered during setup', () => { + const setup = service.setup(setupDeps); + setup.types.registerBucket( + 'foo', + () => ({ name: 'foo', type: 'buckets' } as BucketAggType) + ); + setup.types.registerMetric( + 'bar', + () => ({ name: 'bar', type: 'metrics' } as MetricAggType) + ); + const start = service.start(startDeps); + + const aggTypes = getAggTypes(); + expect(start.types.getAll().buckets.length).toBe(aggTypes.buckets.length + 1); + expect(start.types.getAll().buckets.some((t) => t(aggTypesDependencies).name === 'foo')).toBe( + true + ); + expect(start.types.getAll().metrics.length).toBe(aggTypes.metrics.length + 1); + expect(start.types.getAll().metrics.some((t) => t(aggTypesDependencies).name === 'bar')).toBe( + true + ); + }); + + test('registers all agg type expression functions', () => { + service.setup(setupDeps); + const aggTypes = getAggTypes(); + expect(setupDeps.registerFunction).toHaveBeenCalledTimes( + aggTypes.buckets.length + aggTypes.metrics.length + ); + }); + }); + + describe('start()', () => { + test('exposes proper contract', () => { + const start = service.start(startDeps); + expect(Object.keys(start).length).toBe(3); + expect(start).toHaveProperty('calculateAutoTimeExpression'); + expect(start).toHaveProperty('createAggConfigs'); + expect(start).toHaveProperty('types'); + }); + + test('types registry returns uninitialized type providers', () => { + service.setup(setupDeps); + const start = service.start(startDeps); + expect(typeof start.types.get('terms')).toBe('function'); + expect(start.types.get('terms')(aggTypesDependencies).name).toBe('terms'); + }); + }); +}); diff --git a/src/plugins/data/common/search/aggs/aggs_service.ts b/src/plugins/data/common/search/aggs/aggs_service.ts new file mode 100644 index 0000000000000..59c54fcce6838 --- /dev/null +++ b/src/plugins/data/common/search/aggs/aggs_service.ts @@ -0,0 +1,92 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { ExpressionsServiceSetup } from 'src/plugins/expressions/common'; +import { UI_SETTINGS } from '../../../common'; +import { + AggConfigs, + AggTypesRegistry, + getAggTypes, + getAggTypesFunctions, + getCalculateAutoTimeExpression, +} from './'; +import { AggsCommonSetup, AggsCommonStart } from './types'; + +/** @internal */ +export const aggsRequiredUiSettings = [ + 'dateFormat', + 'dateFormat:scaled', + 'dateFormat:tz', + UI_SETTINGS.HISTOGRAM_BAR_TARGET, + UI_SETTINGS.HISTOGRAM_MAX_BARS, + UI_SETTINGS.SEARCH_QUERY_LANGUAGE, + UI_SETTINGS.QUERY_ALLOW_LEADING_WILDCARDS, + UI_SETTINGS.QUERY_STRING_OPTIONS, + UI_SETTINGS.COURIER_IGNORE_FILTER_IF_FIELD_NOT_IN_INDEX, +]; + +/** @internal */ +export interface AggsCommonSetupDependencies { + registerFunction: ExpressionsServiceSetup['registerFunction']; +} + +/** @internal */ +export interface AggsCommonStartDependencies { + getConfig: (key: string) => T; +} + +/** + * The aggs service provides a means of modeling and manipulating the various + * Elasticsearch aggregations supported by Kibana, providing the ability to + * output the correct DSL when you are ready to send your request to ES. + */ +export class AggsCommonService { + private readonly aggTypesRegistry = new AggTypesRegistry(); + + public setup({ registerFunction }: AggsCommonSetupDependencies): AggsCommonSetup { + const aggTypesSetup = this.aggTypesRegistry.setup(); + + // register each agg type + const aggTypes = getAggTypes(); + aggTypes.buckets.forEach(({ name, fn }) => aggTypesSetup.registerBucket(name, fn)); + aggTypes.metrics.forEach(({ name, fn }) => aggTypesSetup.registerMetric(name, fn)); + + // register expression functions for each agg type + const aggFunctions = getAggTypesFunctions(); + aggFunctions.forEach((fn) => registerFunction(fn)); + + return { + types: aggTypesSetup, + }; + } + + public start({ getConfig }: AggsCommonStartDependencies): AggsCommonStart { + const aggTypesStart = this.aggTypesRegistry.start(); + + return { + calculateAutoTimeExpression: getCalculateAutoTimeExpression(getConfig), + createAggConfigs: (indexPattern, configStates = [], schemas) => { + return new AggConfigs(indexPattern, configStates, { + typesRegistry: aggTypesStart, + }); + }, + types: aggTypesStart, + }; + } +} diff --git a/src/plugins/data/public/search/aggs/buckets/_interval_options.ts b/src/plugins/data/common/search/aggs/buckets/_interval_options.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/_interval_options.ts rename to src/plugins/data/common/search/aggs/buckets/_interval_options.ts diff --git a/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.test.ts b/src/plugins/data/common/search/aggs/buckets/_terms_other_bucket_helper.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.test.ts rename to src/plugins/data/common/search/aggs/buckets/_terms_other_bucket_helper.test.ts diff --git a/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.ts b/src/plugins/data/common/search/aggs/buckets/_terms_other_bucket_helper.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.ts rename to src/plugins/data/common/search/aggs/buckets/_terms_other_bucket_helper.ts diff --git a/src/plugins/data/public/search/aggs/buckets/bucket_agg_type.ts b/src/plugins/data/common/search/aggs/buckets/bucket_agg_type.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/bucket_agg_type.ts rename to src/plugins/data/common/search/aggs/buckets/bucket_agg_type.ts diff --git a/src/plugins/data/public/search/aggs/buckets/bucket_agg_types.ts b/src/plugins/data/common/search/aggs/buckets/bucket_agg_types.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/bucket_agg_types.ts rename to src/plugins/data/common/search/aggs/buckets/bucket_agg_types.ts diff --git a/src/plugins/data/public/search/aggs/buckets/create_filter/date_histogram.test.ts b/src/plugins/data/common/search/aggs/buckets/create_filter/date_histogram.test.ts similarity index 87% rename from src/plugins/data/public/search/aggs/buckets/create_filter/date_histogram.test.ts rename to src/plugins/data/common/search/aggs/buckets/create_filter/date_histogram.test.ts index 24a17b60566cc..143d549836900 100644 --- a/src/plugins/data/public/search/aggs/buckets/create_filter/date_histogram.test.ts +++ b/src/plugins/data/common/search/aggs/buckets/create_filter/date_histogram.test.ts @@ -22,32 +22,17 @@ import { createFilterDateHistogram } from './date_histogram'; import { intervalOptions } from '../_interval_options'; import { AggConfigs } from '../../agg_configs'; import { mockAggTypesRegistry } from '../../test_helpers'; -import { - getDateHistogramBucketAgg, - DateHistogramBucketAggDependencies, - IBucketDateHistogramAggConfig, -} from '../date_histogram'; +import { IBucketDateHistogramAggConfig } from '../date_histogram'; import { BUCKET_TYPES } from '../bucket_agg_types'; import { RangeFilter } from '../../../../../common'; -import { coreMock } from '../../../../../../../core/public/mocks'; describe('AggConfig Filters', () => { describe('date_histogram', () => { - let aggTypesDependencies: DateHistogramBucketAggDependencies; let agg: IBucketDateHistogramAggConfig; let filter: RangeFilter; let bucketStart: any; let field: any; - beforeEach(() => { - const { uiSettings } = coreMock.createSetup(); - - aggTypesDependencies = { - calculateBounds: jest.fn(), - uiSettings, - }; - }); - const init = (interval: string = 'auto', duration: any = moment.duration(15, 'minutes')) => { field = { name: 'date', @@ -71,7 +56,7 @@ describe('AggConfig Filters', () => { }, ], { - typesRegistry: mockAggTypesRegistry([getDateHistogramBucketAgg(aggTypesDependencies)]), + typesRegistry: mockAggTypesRegistry(), } ); const bucketKey = 1422579600000; diff --git a/src/plugins/data/public/search/aggs/buckets/create_filter/date_histogram.ts b/src/plugins/data/common/search/aggs/buckets/create_filter/date_histogram.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/create_filter/date_histogram.ts rename to src/plugins/data/common/search/aggs/buckets/create_filter/date_histogram.ts diff --git a/src/plugins/data/public/search/aggs/buckets/create_filter/date_range.test.ts b/src/plugins/data/common/search/aggs/buckets/create_filter/date_range.test.ts similarity index 78% rename from src/plugins/data/public/search/aggs/buckets/create_filter/date_range.test.ts rename to src/plugins/data/common/search/aggs/buckets/create_filter/date_range.test.ts index c272c037c5927..8def27f1d8ee5 100644 --- a/src/plugins/data/public/search/aggs/buckets/create_filter/date_range.test.ts +++ b/src/plugins/data/common/search/aggs/buckets/create_filter/date_range.test.ts @@ -18,31 +18,18 @@ */ import moment from 'moment'; -import { getDateRangeBucketAgg, DateRangeBucketAggDependencies } from '../date_range'; import { createFilterDateRange } from './date_range'; -import { FieldFormatsGetConfigFn } from '../../../../../common'; -import { DateFormat } from '../../../../field_formats'; import { AggConfigs } from '../../agg_configs'; import { mockAggTypesRegistry } from '../../test_helpers'; import { BUCKET_TYPES } from '../bucket_agg_types'; import { IBucketAggConfig } from '../bucket_agg_type'; -import { coreMock } from '../../../../../../../core/public/mocks'; describe('AggConfig Filters', () => { describe('Date range', () => { - let aggTypesDependencies: DateRangeBucketAggDependencies; - - beforeEach(() => { - const { uiSettings } = coreMock.createSetup(); - - aggTypesDependencies = { uiSettings }; - }); - - const getConfig = (() => {}) as FieldFormatsGetConfigFn; const getAggConfigs = () => { const field = { name: '@timestamp', - format: new DateFormat({}, getConfig), + format: {}, }; const indexPattern = { @@ -66,7 +53,7 @@ describe('AggConfig Filters', () => { }, ], { - typesRegistry: mockAggTypesRegistry([getDateRangeBucketAgg(aggTypesDependencies)]), + typesRegistry: mockAggTypesRegistry(), } ); }; diff --git a/src/plugins/data/public/search/aggs/buckets/create_filter/date_range.ts b/src/plugins/data/common/search/aggs/buckets/create_filter/date_range.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/create_filter/date_range.ts rename to src/plugins/data/common/search/aggs/buckets/create_filter/date_range.ts diff --git a/src/plugins/data/public/search/aggs/buckets/create_filter/filters.test.ts b/src/plugins/data/common/search/aggs/buckets/create_filter/filters.test.ts similarity index 83% rename from src/plugins/data/public/search/aggs/buckets/create_filter/filters.test.ts rename to src/plugins/data/common/search/aggs/buckets/create_filter/filters.test.ts index ff66d80c6d8d0..aec99bd00af55 100644 --- a/src/plugins/data/public/search/aggs/buckets/create_filter/filters.test.ts +++ b/src/plugins/data/common/search/aggs/buckets/create_filter/filters.test.ts @@ -17,23 +17,13 @@ * under the License. */ -import { getFiltersBucketAgg, FiltersBucketAggDependencies } from '../filters'; import { createFilterFilters } from './filters'; import { AggConfigs } from '../../agg_configs'; import { mockAggTypesRegistry } from '../../test_helpers'; import { IBucketAggConfig } from '../bucket_agg_type'; -import { coreMock } from '../../../../../../../core/public/mocks'; describe('AggConfig Filters', () => { describe('filters', () => { - let aggTypesDependencies: FiltersBucketAggDependencies; - - beforeEach(() => { - const { uiSettings } = coreMock.createSetup(); - - aggTypesDependencies = { uiSettings }; - }); - const getAggConfigs = () => { const field = { name: 'bytes', @@ -63,7 +53,7 @@ describe('AggConfig Filters', () => { }, ], { - typesRegistry: mockAggTypesRegistry([getFiltersBucketAgg(aggTypesDependencies)]), + typesRegistry: mockAggTypesRegistry(), } ); }; diff --git a/src/plugins/data/public/search/aggs/buckets/create_filter/filters.ts b/src/plugins/data/common/search/aggs/buckets/create_filter/filters.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/create_filter/filters.ts rename to src/plugins/data/common/search/aggs/buckets/create_filter/filters.ts diff --git a/src/plugins/data/public/search/aggs/buckets/create_filter/histogram.test.ts b/src/plugins/data/common/search/aggs/buckets/create_filter/histogram.test.ts similarity index 77% rename from src/plugins/data/public/search/aggs/buckets/create_filter/histogram.test.ts rename to src/plugins/data/common/search/aggs/buckets/create_filter/histogram.test.ts index 3f9f5dd5672f0..b57d530ef40e8 100644 --- a/src/plugins/data/public/search/aggs/buckets/create_filter/histogram.test.ts +++ b/src/plugins/data/common/search/aggs/buckets/create_filter/histogram.test.ts @@ -17,25 +17,14 @@ * under the License. */ -import { createFilterHistogram } from './histogram'; +import { BytesFormat, FieldFormatsGetConfigFn } from '../../../../../common/field_formats'; import { AggConfigs } from '../../agg_configs'; -import { mockAggTypesRegistry } from '../../test_helpers'; +import { mockAggTypesRegistry, mockGetFieldFormatsStart } from '../../test_helpers'; import { BUCKET_TYPES } from '../bucket_agg_types'; import { IBucketAggConfig } from '../bucket_agg_type'; -import { BytesFormat, FieldFormatsGetConfigFn } from '../../../../../common'; -import { GetInternalStartServicesFn, InternalStartServices } from '../../../../types'; -import { FieldFormatsStart } from '../../../../field_formats'; -import { fieldFormatsServiceMock } from '../../../../field_formats/mocks'; +import { createFilterHistogram } from './histogram'; describe('AggConfig Filters', () => { - let getInternalStartServices: GetInternalStartServicesFn; - let fieldFormats: FieldFormatsStart; - - beforeEach(() => { - fieldFormats = fieldFormatsServiceMock.createStartContract(); - getInternalStartServices = () => (({ fieldFormats } as unknown) as InternalStartServices); - }); - describe('histogram', () => { const getConfig = (() => {}) as FieldFormatsGetConfigFn; const getAggConfigs = () => { @@ -72,12 +61,12 @@ describe('AggConfig Filters', () => { test('should return an range filter for histogram', () => { const aggConfigs = getAggConfigs(); - const filter = createFilterHistogram(getInternalStartServices)( + const filter = createFilterHistogram(mockGetFieldFormatsStart)( aggConfigs.aggs[0] as IBucketAggConfig, '2048' ); - expect(fieldFormats.deserialize).toHaveBeenCalledTimes(1); + expect(mockGetFieldFormatsStart().deserialize).toHaveBeenCalledTimes(1); expect(filter).toHaveProperty('meta'); expect(filter.meta).toHaveProperty('index', '1234'); expect(filter).toHaveProperty('range'); diff --git a/src/plugins/data/public/search/aggs/buckets/create_filter/histogram.ts b/src/plugins/data/common/search/aggs/buckets/create_filter/histogram.ts similarity index 80% rename from src/plugins/data/public/search/aggs/buckets/create_filter/histogram.ts rename to src/plugins/data/common/search/aggs/buckets/create_filter/histogram.ts index f3626bc9130ad..4684b1640cd82 100644 --- a/src/plugins/data/public/search/aggs/buckets/create_filter/histogram.ts +++ b/src/plugins/data/common/search/aggs/buckets/create_filter/histogram.ts @@ -17,14 +17,16 @@ * under the License. */ -import { IBucketAggConfig } from '../bucket_agg_type'; import { buildRangeFilter, RangeFilterParams } from '../../../../../common'; -import { GetInternalStartServicesFn } from '../../../../types'; +import { AggTypesDependencies } from '../../agg_types'; +import { IBucketAggConfig } from '../bucket_agg_type'; /** @internal */ -export const createFilterHistogram = (getInternalStartServices: GetInternalStartServicesFn) => { +export const createFilterHistogram = ( + getFieldFormatsStart: AggTypesDependencies['getFieldFormatsStart'] +) => { return (aggConfig: IBucketAggConfig, key: string) => { - const { fieldFormats } = getInternalStartServices(); + const { deserialize } = getFieldFormatsStart(); const value = parseInt(key, 10); const params: RangeFilterParams = { gte: value, lt: value + aggConfig.params.interval }; @@ -32,7 +34,7 @@ export const createFilterHistogram = (getInternalStartServices: GetInternalStart aggConfig.params.field, params, aggConfig.getIndexPattern(), - fieldFormats.deserialize(aggConfig.toSerializedFieldFormat()).convert(key) + deserialize(aggConfig.toSerializedFieldFormat()).convert(key) ); }; }; diff --git a/src/plugins/data/public/search/aggs/buckets/create_filter/ip_range.test.ts b/src/plugins/data/common/search/aggs/buckets/create_filter/ip_range.test.ts similarity index 96% rename from src/plugins/data/public/search/aggs/buckets/create_filter/ip_range.test.ts rename to src/plugins/data/common/search/aggs/buckets/create_filter/ip_range.test.ts index 852685a505afd..9f823001aac8c 100644 --- a/src/plugins/data/public/search/aggs/buckets/create_filter/ip_range.test.ts +++ b/src/plugins/data/common/search/aggs/buckets/create_filter/ip_range.test.ts @@ -17,7 +17,6 @@ * under the License. */ -import { getIpRangeBucketAgg } from '../ip_range'; import { createFilterIpRange } from './ip_range'; import { AggConfigs, CreateAggConfigParams } from '../../agg_configs'; import { mockAggTypesRegistry } from '../../test_helpers'; @@ -27,7 +26,7 @@ import { IBucketAggConfig } from '../bucket_agg_type'; describe('AggConfig Filters', () => { describe('IP range', () => { - const typesRegistry = mockAggTypesRegistry([getIpRangeBucketAgg()]); + const typesRegistry = mockAggTypesRegistry(); const getAggConfigs = (aggs: CreateAggConfigParams[]) => { const field = { name: 'ip', diff --git a/src/plugins/data/public/search/aggs/buckets/create_filter/ip_range.ts b/src/plugins/data/common/search/aggs/buckets/create_filter/ip_range.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/create_filter/ip_range.ts rename to src/plugins/data/common/search/aggs/buckets/create_filter/ip_range.ts diff --git a/src/plugins/data/public/search/aggs/buckets/create_filter/range.test.ts b/src/plugins/data/common/search/aggs/buckets/create_filter/range.test.ts similarity index 73% rename from src/plugins/data/public/search/aggs/buckets/create_filter/range.test.ts rename to src/plugins/data/common/search/aggs/buckets/create_filter/range.test.ts index faffad3beb8c1..30af970f55aa9 100644 --- a/src/plugins/data/public/search/aggs/buckets/create_filter/range.test.ts +++ b/src/plugins/data/common/search/aggs/buckets/create_filter/range.test.ts @@ -17,31 +17,15 @@ * under the License. */ -import { getRangeBucketAgg } from '../range'; -import { createFilterRange } from './range'; -import { BytesFormat, FieldFormatsGetConfigFn } from '../../../../../common'; +import { BytesFormat, FieldFormatsGetConfigFn } from '../../../../../common/field_formats'; import { AggConfigs } from '../../agg_configs'; -import { mockAggTypesRegistry } from '../../test_helpers'; -import { BUCKET_TYPES } from '../bucket_agg_types'; +import { mockAggTypesRegistry, mockGetFieldFormatsStart } from '../../test_helpers'; import { IBucketAggConfig } from '../bucket_agg_type'; -import { FieldFormatsStart } from '../../../../field_formats'; -import { fieldFormatsServiceMock } from '../../../../field_formats/mocks'; -import { GetInternalStartServicesFn, InternalStartServices } from '../../../../types'; +import { BUCKET_TYPES } from '../bucket_agg_types'; +import { createFilterRange } from './range'; describe('AggConfig Filters', () => { describe('range', () => { - let getInternalStartServices: GetInternalStartServicesFn; - let fieldFormats: FieldFormatsStart; - - beforeEach(() => { - fieldFormats = fieldFormatsServiceMock.createStartContract(); - - getInternalStartServices = () => - (({ - fieldFormats, - } as unknown) as InternalStartServices); - }); - const getConfig = (() => {}) as FieldFormatsGetConfigFn; const getAggConfigs = () => { const field = { @@ -72,14 +56,14 @@ describe('AggConfig Filters', () => { }, ], { - typesRegistry: mockAggTypesRegistry([getRangeBucketAgg({ getInternalStartServices })]), + typesRegistry: mockAggTypesRegistry(), } ); }; test('should return a range filter for range agg', () => { const aggConfigs = getAggConfigs(); - const filter = createFilterRange(getInternalStartServices)( + const filter = createFilterRange(mockGetFieldFormatsStart)( aggConfigs.aggs[0] as IBucketAggConfig, { gte: 1024, @@ -87,7 +71,7 @@ describe('AggConfig Filters', () => { } ); - expect(fieldFormats.deserialize).toHaveBeenCalledTimes(1); + expect(mockGetFieldFormatsStart().deserialize).toHaveBeenCalledTimes(1); expect(filter).toHaveProperty('range'); expect(filter).toHaveProperty('meta'); expect(filter.meta).toHaveProperty('index', '1234'); diff --git a/src/plugins/data/public/search/aggs/buckets/create_filter/range.ts b/src/plugins/data/common/search/aggs/buckets/create_filter/range.ts similarity index 78% rename from src/plugins/data/public/search/aggs/buckets/create_filter/range.ts rename to src/plugins/data/common/search/aggs/buckets/create_filter/range.ts index f9db2973af136..8dea33a450c5d 100644 --- a/src/plugins/data/public/search/aggs/buckets/create_filter/range.ts +++ b/src/plugins/data/common/search/aggs/buckets/create_filter/range.ts @@ -17,19 +17,21 @@ * under the License. */ -import { IBucketAggConfig } from '../bucket_agg_type'; import { buildRangeFilter } from '../../../../../common'; -import { GetInternalStartServicesFn } from '../../../../types'; +import { AggTypesDependencies } from '../../agg_types'; +import { IBucketAggConfig } from '../bucket_agg_type'; /** @internal */ -export const createFilterRange = (getInternalStartServices: GetInternalStartServicesFn) => { +export const createFilterRange = ( + getFieldFormatsStart: AggTypesDependencies['getFieldFormatsStart'] +) => { return (aggConfig: IBucketAggConfig, params: any) => { - const { fieldFormats } = getInternalStartServices(); + const { deserialize } = getFieldFormatsStart(); return buildRangeFilter( aggConfig.params.field, params, aggConfig.getIndexPattern(), - fieldFormats.deserialize(aggConfig.toSerializedFieldFormat()).convert(params) + deserialize(aggConfig.toSerializedFieldFormat()).convert(params) ); }; }; diff --git a/src/plugins/data/public/search/aggs/buckets/create_filter/terms.test.ts b/src/plugins/data/common/search/aggs/buckets/create_filter/terms.test.ts similarity index 97% rename from src/plugins/data/public/search/aggs/buckets/create_filter/terms.test.ts rename to src/plugins/data/common/search/aggs/buckets/create_filter/terms.test.ts index 1c165f0d29ab6..c3c661296e1cf 100644 --- a/src/plugins/data/public/search/aggs/buckets/create_filter/terms.test.ts +++ b/src/plugins/data/common/search/aggs/buckets/create_filter/terms.test.ts @@ -17,7 +17,6 @@ * under the License. */ -import { getTermsBucketAgg } from '../terms'; import { createFilterTerms } from './terms'; import { AggConfigs, CreateAggConfigParams } from '../../agg_configs'; import { mockAggTypesRegistry } from '../../test_helpers'; @@ -43,7 +42,7 @@ describe('AggConfig Filters', () => { }; return new AggConfigs(indexPattern, aggs, { - typesRegistry: mockAggTypesRegistry([getTermsBucketAgg()]), + typesRegistry: mockAggTypesRegistry(), }); }; diff --git a/src/plugins/data/public/search/aggs/buckets/create_filter/terms.ts b/src/plugins/data/common/search/aggs/buckets/create_filter/terms.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/create_filter/terms.ts rename to src/plugins/data/common/search/aggs/buckets/create_filter/terms.ts diff --git a/src/plugins/data/public/search/aggs/buckets/date_histogram.ts b/src/plugins/data/common/search/aggs/buckets/date_histogram.ts similarity index 92% rename from src/plugins/data/public/search/aggs/buckets/date_histogram.ts rename to src/plugins/data/common/search/aggs/buckets/date_histogram.ts index fa1725eccbd28..fdf9c456b3876 100644 --- a/src/plugins/data/public/search/aggs/buckets/date_histogram.ts +++ b/src/plugins/data/common/search/aggs/buckets/date_histogram.ts @@ -20,27 +20,23 @@ import { get, noop, find, every } from 'lodash'; import moment from 'moment-timezone'; import { i18n } from '@kbn/i18n'; -import { IUiSettingsClient } from 'src/core/public'; -import { TimeBuckets } from './lib/time_buckets'; +import { KBN_FIELD_TYPES, TimeRange, TimeRangeBounds, UI_SETTINGS } from '../../../../common'; + +import { intervalOptions } from './_interval_options'; +import { createFilterDateHistogram } from './create_filter/date_histogram'; import { BucketAggType, IBucketAggConfig } from './bucket_agg_type'; import { BUCKET_TYPES } from './bucket_agg_types'; -import { createFilterDateHistogram } from './create_filter/date_histogram'; -import { intervalOptions } from './_interval_options'; +import { ExtendedBounds } from './lib/extended_bounds'; +import { TimeBuckets } from './lib/time_buckets'; + import { writeParams } from '../agg_params'; import { isMetricAggType } from '../metrics/metric_agg_type'; - -import { - dateHistogramInterval, - KBN_FIELD_TYPES, - TimeRange, - TimeRangeBounds, - UI_SETTINGS, -} from '../../../../common'; import { BaseAggParams } from '../types'; -import { ExtendedBounds } from './lib/extended_bounds'; +import { dateHistogramInterval } from '../utils'; -type CalculateBoundsFn = (timeRange: TimeRange) => TimeRangeBounds; +/** @internal */ +export type CalculateBoundsFn = (timeRange: TimeRange) => TimeRangeBounds; const updateTimeBuckets = ( agg: IBucketDateHistogramAggConfig, @@ -58,7 +54,8 @@ const updateTimeBuckets = ( export interface DateHistogramBucketAggDependencies { calculateBounds: CalculateBoundsFn; - uiSettings: IUiSettingsClient; + isDefaultTimezone: () => boolean; + getConfig: (key: string) => T; } export interface IBucketDateHistogramAggConfig extends IBucketAggConfig { @@ -84,7 +81,8 @@ export interface AggParamsDateHistogram extends BaseAggParams { export const getDateHistogramBucketAgg = ({ calculateBounds, - uiSettings, + isDefaultTimezone, + getConfig, }: DateHistogramBucketAggDependencies) => new BucketAggType({ name: BUCKET_TYPES.DATE_HISTOGRAM, @@ -122,10 +120,10 @@ export const getDateHistogramBucketAgg = ({ if (buckets) return buckets; buckets = new TimeBuckets({ - 'histogram:maxBars': uiSettings.get(UI_SETTINGS.HISTOGRAM_MAX_BARS), - 'histogram:barTarget': uiSettings.get(UI_SETTINGS.HISTOGRAM_BAR_TARGET), - dateFormat: uiSettings.get('dateFormat'), - 'dateFormat:scaled': uiSettings.get('dateFormat:scaled'), + 'histogram:maxBars': getConfig(UI_SETTINGS.HISTOGRAM_MAX_BARS), + 'histogram:barTarget': getConfig(UI_SETTINGS.HISTOGRAM_BAR_TARGET), + dateFormat: getConfig('dateFormat'), + 'dateFormat:scaled': getConfig('dateFormat:scaled'), }); updateTimeBuckets(this, calculateBounds, buckets); @@ -252,10 +250,9 @@ export const getDateHistogramBucketAgg = ({ } if (!tz) { // If the index pattern typeMeta data, didn't had a time zone assigned for the selected field use the configured tz - const isDefaultTimezone = uiSettings.isDefault('dateFormat:tz'); const detectedTimezone = moment.tz.guess(); const tzOffset = moment().format('Z'); - tz = isDefaultTimezone ? detectedTimezone || tzOffset : uiSettings.get('dateFormat:tz'); + tz = isDefaultTimezone() ? detectedTimezone || tzOffset : getConfig('dateFormat:tz'); } output.params.time_zone = tz; }, diff --git a/src/plugins/data/public/search/aggs/buckets/date_histogram_fn.test.ts b/src/plugins/data/common/search/aggs/buckets/date_histogram_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/date_histogram_fn.test.ts rename to src/plugins/data/common/search/aggs/buckets/date_histogram_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/buckets/date_histogram_fn.ts b/src/plugins/data/common/search/aggs/buckets/date_histogram_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/date_histogram_fn.ts rename to src/plugins/data/common/search/aggs/buckets/date_histogram_fn.ts diff --git a/src/plugins/data/public/search/aggs/buckets/date_range.test.ts b/src/plugins/data/common/search/aggs/buckets/date_range.test.ts similarity index 84% rename from src/plugins/data/public/search/aggs/buckets/date_range.test.ts rename to src/plugins/data/common/search/aggs/buckets/date_range.test.ts index 69515dfee87fe..66f8e269cd38d 100644 --- a/src/plugins/data/public/search/aggs/buckets/date_range.test.ts +++ b/src/plugins/data/common/search/aggs/buckets/date_range.test.ts @@ -17,19 +17,20 @@ * under the License. */ -import { coreMock } from '../../../../../../../src/core/public/mocks'; -import { getDateRangeBucketAgg, DateRangeBucketAggDependencies } from './date_range'; import { AggConfigs } from '../agg_configs'; -import { mockAggTypesRegistry } from '../test_helpers'; +import { AggTypesDependencies } from '../agg_types'; +import { mockAggTypesRegistry, mockAggTypesDependencies } from '../test_helpers'; import { BUCKET_TYPES } from './bucket_agg_types'; describe('date_range params', () => { - let aggTypesDependencies: DateRangeBucketAggDependencies; + let aggTypesDependencies: AggTypesDependencies; beforeEach(() => { - const { uiSettings } = coreMock.createSetup(); - - aggTypesDependencies = { uiSettings }; + aggTypesDependencies = { + ...mockAggTypesDependencies, + getConfig: jest.fn(), + isDefaultTimezone: jest.fn().mockReturnValue(false), + }; }); const getAggConfigs = (params: Record = {}, hasIncludeTypeMeta: boolean = true) => { @@ -68,7 +69,7 @@ describe('date_range params', () => { }, ], { - typesRegistry: mockAggTypesRegistry([getDateRangeBucketAgg(aggTypesDependencies)]), + typesRegistry: mockAggTypesRegistry(aggTypesDependencies), } ); }; @@ -108,10 +109,7 @@ describe('date_range params', () => { test('should use the Kibana time_zone if no parameter specified', () => { aggTypesDependencies = { ...aggTypesDependencies, - uiSettings: { - ...aggTypesDependencies.uiSettings, - get: () => 'kibanaTimeZone' as any, - }, + getConfig: () => 'kibanaTimeZone' as any, }; const aggConfigs = getAggConfigs( diff --git a/src/plugins/data/public/search/aggs/buckets/date_range.ts b/src/plugins/data/common/search/aggs/buckets/date_range.ts similarity index 88% rename from src/plugins/data/public/search/aggs/buckets/date_range.ts rename to src/plugins/data/common/search/aggs/buckets/date_range.ts index 8c576023f0239..eda35a77afa5f 100644 --- a/src/plugins/data/public/search/aggs/buckets/date_range.ts +++ b/src/plugins/data/common/search/aggs/buckets/date_range.ts @@ -20,14 +20,13 @@ import { get } from 'lodash'; import moment from 'moment-timezone'; import { i18n } from '@kbn/i18n'; -import { IUiSettingsClient } from 'src/core/public'; import { BUCKET_TYPES } from './bucket_agg_types'; import { BucketAggType, IBucketAggConfig } from './bucket_agg_type'; import { createFilterDateRange } from './create_filter/date_range'; import { DateRangeKey } from './lib/date_range'; -import { KBN_FIELD_TYPES } from '../../../../common'; +import { KBN_FIELD_TYPES } from '../../../../common/kbn_field_types/types'; import { BaseAggParams } from '../types'; const dateRangeTitle = i18n.translate('data.search.aggs.buckets.dateRangeTitle', { @@ -35,7 +34,8 @@ const dateRangeTitle = i18n.translate('data.search.aggs.buckets.dateRangeTitle', }); export interface DateRangeBucketAggDependencies { - uiSettings: IUiSettingsClient; + isDefaultTimezone: () => boolean; + getConfig: (key: string) => T; } export interface AggParamsDateRange extends BaseAggParams { @@ -44,7 +44,10 @@ export interface AggParamsDateRange extends BaseAggParams { time_zone?: string; } -export const getDateRangeBucketAgg = ({ uiSettings }: DateRangeBucketAggDependencies) => +export const getDateRangeBucketAgg = ({ + isDefaultTimezone, + getConfig, +}: DateRangeBucketAggDependencies) => new BucketAggType({ name: BUCKET_TYPES.DATE_RANGE, title: dateRangeTitle, @@ -100,9 +103,8 @@ export const getDateRangeBucketAgg = ({ uiSettings }: DateRangeBucketAggDependen if (!tz) { const detectedTimezone = moment.tz.guess(); const tzOffset = moment().format('Z'); - const isDefaultTimezone = uiSettings.isDefault('dateFormat:tz'); - tz = isDefaultTimezone ? detectedTimezone || tzOffset : uiSettings.get('dateFormat:tz'); + tz = isDefaultTimezone() ? detectedTimezone || tzOffset : getConfig('dateFormat:tz'); } output.params.time_zone = tz; }, diff --git a/src/plugins/data/public/search/aggs/buckets/date_range_fn.test.ts b/src/plugins/data/common/search/aggs/buckets/date_range_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/date_range_fn.test.ts rename to src/plugins/data/common/search/aggs/buckets/date_range_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/buckets/date_range_fn.ts b/src/plugins/data/common/search/aggs/buckets/date_range_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/date_range_fn.ts rename to src/plugins/data/common/search/aggs/buckets/date_range_fn.ts diff --git a/src/plugins/data/public/search/aggs/buckets/filter.ts b/src/plugins/data/common/search/aggs/buckets/filter.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/filter.ts rename to src/plugins/data/common/search/aggs/buckets/filter.ts diff --git a/src/plugins/data/public/search/aggs/buckets/filter_fn.test.ts b/src/plugins/data/common/search/aggs/buckets/filter_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/filter_fn.test.ts rename to src/plugins/data/common/search/aggs/buckets/filter_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/buckets/filter_fn.ts b/src/plugins/data/common/search/aggs/buckets/filter_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/filter_fn.ts rename to src/plugins/data/common/search/aggs/buckets/filter_fn.ts diff --git a/src/plugins/data/public/search/aggs/buckets/filters.test.ts b/src/plugins/data/common/search/aggs/buckets/filters.test.ts similarity index 93% rename from src/plugins/data/public/search/aggs/buckets/filters.test.ts rename to src/plugins/data/common/search/aggs/buckets/filters.test.ts index bcb82b5f99649..f745b4537131a 100644 --- a/src/plugins/data/public/search/aggs/buckets/filters.test.ts +++ b/src/plugins/data/common/search/aggs/buckets/filters.test.ts @@ -18,20 +18,20 @@ */ import { Query } from '../../../../common'; -import { coreMock } from '../../../../../../../src/core/public/mocks'; import { AggConfigs } from '../agg_configs'; -import { mockAggTypesRegistry } from '../test_helpers'; +import { AggTypesDependencies } from '../agg_types'; +import { mockAggTypesRegistry, mockAggTypesDependencies } from '../test_helpers'; import { BUCKET_TYPES } from './bucket_agg_types'; -import { getFiltersBucketAgg, FiltersBucketAggDependencies } from './filters'; describe('Filters Agg', () => { - let aggTypesDependencies: FiltersBucketAggDependencies; + let aggTypesDependencies: AggTypesDependencies; beforeEach(() => { jest.resetAllMocks(); - const { uiSettings } = coreMock.createSetup(); - - aggTypesDependencies = { uiSettings }; + aggTypesDependencies = { + ...mockAggTypesDependencies, + getConfig: jest.fn(), + }; }); describe('order agg editor UI', () => { @@ -61,7 +61,7 @@ describe('Filters Agg', () => { }, ], { - typesRegistry: mockAggTypesRegistry([getFiltersBucketAgg(aggTypesDependencies)]), + typesRegistry: mockAggTypesRegistry(aggTypesDependencies), } ); }; @@ -218,7 +218,7 @@ describe('Filters Agg', () => { }); test('works with leading wildcards if allowed', () => { - aggTypesDependencies.uiSettings.get = (s: any) => + aggTypesDependencies.getConfig = (s: any) => s === 'query:allowLeadingWildcards' ? true : s; const aggConfigs = getAggConfigs({ diff --git a/src/plugins/data/public/search/aggs/buckets/filters.ts b/src/plugins/data/common/search/aggs/buckets/filters.ts similarity index 90% rename from src/plugins/data/public/search/aggs/buckets/filters.ts rename to src/plugins/data/common/search/aggs/buckets/filters.ts index cd4ed721fda77..7310fa08b68e0 100644 --- a/src/plugins/data/public/search/aggs/buckets/filters.ts +++ b/src/plugins/data/common/search/aggs/buckets/filters.ts @@ -19,7 +19,6 @@ import { i18n } from '@kbn/i18n'; import { size, transform, cloneDeep } from 'lodash'; -import { IUiSettingsClient } from 'src/core/public'; import { createFilterFilters } from './create_filter/filters'; import { toAngularJSON } from '../utils'; @@ -41,7 +40,7 @@ interface FilterValue { } export interface FiltersBucketAggDependencies { - uiSettings: IUiSettingsClient; + getConfig: (key: string) => any; } export interface AggParamsFilters extends Omit { @@ -51,7 +50,7 @@ export interface AggParamsFilters extends Omit { }>; } -export const getFiltersBucketAgg = ({ uiSettings }: FiltersBucketAggDependencies) => +export const getFiltersBucketAgg = ({ getConfig }: FiltersBucketAggDependencies) => new BucketAggType({ name: BUCKET_TYPES.FILTERS, title: filtersTitle, @@ -60,9 +59,9 @@ export const getFiltersBucketAgg = ({ uiSettings }: FiltersBucketAggDependencies params: [ { name: 'filters', - default: [ + default: () => [ { - input: { query: '', language: uiSettings.get(UI_SETTINGS.SEARCH_QUERY_LANGUAGE) }, + input: { query: '', language: getConfig(UI_SETTINGS.SEARCH_QUERY_LANGUAGE) }, label: '', }, ], @@ -80,7 +79,7 @@ export const getFiltersBucketAgg = ({ uiSettings }: FiltersBucketAggDependencies return; } - const esQueryConfigs = getEsQueryConfig(uiSettings); + const esQueryConfigs = getEsQueryConfig({ get: getConfig }); const query = buildEsQuery(aggConfig.getIndexPattern(), [input], [], esQueryConfigs); if (!query) { diff --git a/src/plugins/data/public/search/aggs/buckets/filters_fn.test.ts b/src/plugins/data/common/search/aggs/buckets/filters_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/filters_fn.test.ts rename to src/plugins/data/common/search/aggs/buckets/filters_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/buckets/filters_fn.ts b/src/plugins/data/common/search/aggs/buckets/filters_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/filters_fn.ts rename to src/plugins/data/common/search/aggs/buckets/filters_fn.ts diff --git a/src/plugins/data/public/search/aggs/buckets/geo_hash.test.ts b/src/plugins/data/common/search/aggs/buckets/geo_hash.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/geo_hash.test.ts rename to src/plugins/data/common/search/aggs/buckets/geo_hash.test.ts diff --git a/src/plugins/data/public/search/aggs/buckets/geo_hash.ts b/src/plugins/data/common/search/aggs/buckets/geo_hash.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/geo_hash.ts rename to src/plugins/data/common/search/aggs/buckets/geo_hash.ts diff --git a/src/plugins/data/public/search/aggs/buckets/geo_hash_fn.test.ts b/src/plugins/data/common/search/aggs/buckets/geo_hash_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/geo_hash_fn.test.ts rename to src/plugins/data/common/search/aggs/buckets/geo_hash_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/buckets/geo_hash_fn.ts b/src/plugins/data/common/search/aggs/buckets/geo_hash_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/geo_hash_fn.ts rename to src/plugins/data/common/search/aggs/buckets/geo_hash_fn.ts diff --git a/src/plugins/data/public/search/aggs/buckets/geo_tile.ts b/src/plugins/data/common/search/aggs/buckets/geo_tile.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/geo_tile.ts rename to src/plugins/data/common/search/aggs/buckets/geo_tile.ts diff --git a/src/plugins/data/public/search/aggs/buckets/geo_tile_fn.test.ts b/src/plugins/data/common/search/aggs/buckets/geo_tile_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/geo_tile_fn.test.ts rename to src/plugins/data/common/search/aggs/buckets/geo_tile_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/buckets/geo_tile_fn.ts b/src/plugins/data/common/search/aggs/buckets/geo_tile_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/geo_tile_fn.ts rename to src/plugins/data/common/search/aggs/buckets/geo_tile_fn.ts diff --git a/src/plugins/data/public/search/aggs/buckets/histogram.test.ts b/src/plugins/data/common/search/aggs/buckets/histogram.test.ts similarity index 90% rename from src/plugins/data/public/search/aggs/buckets/histogram.test.ts rename to src/plugins/data/common/search/aggs/buckets/histogram.test.ts index 6ac77f207d9ce..3727747984d3e 100644 --- a/src/plugins/data/public/search/aggs/buckets/histogram.test.ts +++ b/src/plugins/data/common/search/aggs/buckets/histogram.test.ts @@ -17,33 +17,18 @@ * under the License. */ -import { coreMock } from '../../../../../../../src/core/public/mocks'; import { AggConfigs } from '../agg_configs'; -import { mockAggTypesRegistry } from '../test_helpers'; +import { mockAggTypesRegistry, mockAggTypesDependencies } from '../test_helpers'; +import { AggTypesDependencies } from '../agg_types'; import { BUCKET_TYPES } from './bucket_agg_types'; -import { - IBucketHistogramAggConfig, - getHistogramBucketAgg, - AutoBounds, - HistogramBucketAggDependencies, -} from './histogram'; +import { IBucketHistogramAggConfig, getHistogramBucketAgg, AutoBounds } from './histogram'; import { BucketAggType } from './bucket_agg_type'; -import { fieldFormatsServiceMock } from '../../../field_formats/mocks'; -import { InternalStartServices } from '../../../types'; describe('Histogram Agg', () => { - let aggTypesDependencies: HistogramBucketAggDependencies; + let aggTypesDependencies: AggTypesDependencies; beforeEach(() => { - const { uiSettings } = coreMock.createSetup(); - - aggTypesDependencies = { - uiSettings, - getInternalStartServices: () => - (({ - fieldFormats: fieldFormatsServiceMock.createStartContract(), - } as unknown) as InternalStartServices), - }; + aggTypesDependencies = { ...mockAggTypesDependencies }; }); const getAggConfigs = (params: Record) => { @@ -72,7 +57,7 @@ describe('Histogram Agg', () => { }, ], { - typesRegistry: mockAggTypesRegistry([getHistogramBucketAgg(aggTypesDependencies)]), + typesRegistry: mockAggTypesRegistry(aggTypesDependencies), } ); }; @@ -167,10 +152,7 @@ describe('Histogram Agg', () => { ) => { aggTypesDependencies = { ...aggTypesDependencies, - uiSettings: { - ...aggTypesDependencies.uiSettings, - get: () => maxBars as any, - }, + getConfig: () => maxBars as any, }; const aggConfigs = getAggConfigs({ diff --git a/src/plugins/data/public/search/aggs/buckets/histogram.ts b/src/plugins/data/common/search/aggs/buckets/histogram.ts similarity index 93% rename from src/plugins/data/public/search/aggs/buckets/histogram.ts rename to src/plugins/data/common/search/aggs/buckets/histogram.ts index 500b6eab75d77..2b263013e55a2 100644 --- a/src/plugins/data/public/search/aggs/buckets/histogram.ts +++ b/src/plugins/data/common/search/aggs/buckets/histogram.ts @@ -19,14 +19,14 @@ import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; -import { IUiSettingsClient } from 'src/core/public'; + +import { KBN_FIELD_TYPES, UI_SETTINGS } from '../../../../common'; +import { AggTypesDependencies } from '../agg_types'; +import { BaseAggParams } from '../types'; import { BucketAggType, IBucketAggConfig } from './bucket_agg_type'; import { createFilterHistogram } from './create_filter/histogram'; import { BUCKET_TYPES } from './bucket_agg_types'; -import { KBN_FIELD_TYPES, UI_SETTINGS } from '../../../../common'; -import { GetInternalStartServicesFn } from '../../../types'; -import { BaseAggParams } from '../types'; import { ExtendedBounds } from './lib/extended_bounds'; export interface AutoBounds { @@ -35,8 +35,8 @@ export interface AutoBounds { } export interface HistogramBucketAggDependencies { - uiSettings: IUiSettingsClient; - getInternalStartServices: GetInternalStartServicesFn; + getConfig: (key: string) => T; + getFieldFormatsStart: AggTypesDependencies['getFieldFormatsStart']; } export interface IBucketHistogramAggConfig extends IBucketAggConfig { @@ -54,8 +54,8 @@ export interface AggParamsHistogram extends BaseAggParams { } export const getHistogramBucketAgg = ({ - uiSettings, - getInternalStartServices, + getConfig, + getFieldFormatsStart, }: HistogramBucketAggDependencies) => new BucketAggType({ name: BUCKET_TYPES.HISTOGRAM, @@ -66,7 +66,7 @@ export const getHistogramBucketAgg = ({ makeLabel(aggConfig) { return aggConfig.getFieldDisplayName(); }, - createFilter: createFilterHistogram(getInternalStartServices), + createFilter: createFilterHistogram(getFieldFormatsStart), decorateAggConfig() { let autoBounds: AutoBounds; @@ -154,8 +154,8 @@ export const getHistogramBucketAgg = ({ const range = autoBounds.max - autoBounds.min; const bars = range / interval; - if (bars > uiSettings.get(UI_SETTINGS.HISTOGRAM_MAX_BARS)) { - const minInterval = range / uiSettings.get(UI_SETTINGS.HISTOGRAM_MAX_BARS); + if (bars > getConfig(UI_SETTINGS.HISTOGRAM_MAX_BARS)) { + const minInterval = range / getConfig(UI_SETTINGS.HISTOGRAM_MAX_BARS); // Round interval by order of magnitude to provide clean intervals // Always round interval up so there will always be less buckets than histogram:maxBars diff --git a/src/plugins/data/public/search/aggs/buckets/histogram_fn.test.ts b/src/plugins/data/common/search/aggs/buckets/histogram_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/histogram_fn.test.ts rename to src/plugins/data/common/search/aggs/buckets/histogram_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/buckets/histogram_fn.ts b/src/plugins/data/common/search/aggs/buckets/histogram_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/histogram_fn.ts rename to src/plugins/data/common/search/aggs/buckets/histogram_fn.ts diff --git a/src/plugins/data/public/search/aggs/buckets/index.ts b/src/plugins/data/common/search/aggs/buckets/index.ts similarity index 97% rename from src/plugins/data/public/search/aggs/buckets/index.ts rename to src/plugins/data/common/search/aggs/buckets/index.ts index 7036cc7785db7..b16242e519872 100644 --- a/src/plugins/data/public/search/aggs/buckets/index.ts +++ b/src/plugins/data/common/search/aggs/buckets/index.ts @@ -18,6 +18,7 @@ */ export * from './_interval_options'; +export * from './bucket_agg_type'; export * from './bucket_agg_types'; export * from './histogram'; export * from './date_histogram'; diff --git a/src/plugins/data/public/search/aggs/buckets/ip_range.ts b/src/plugins/data/common/search/aggs/buckets/ip_range.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/ip_range.ts rename to src/plugins/data/common/search/aggs/buckets/ip_range.ts diff --git a/src/plugins/data/public/search/aggs/buckets/ip_range_fn.test.ts b/src/plugins/data/common/search/aggs/buckets/ip_range_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/ip_range_fn.test.ts rename to src/plugins/data/common/search/aggs/buckets/ip_range_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/buckets/ip_range_fn.ts b/src/plugins/data/common/search/aggs/buckets/ip_range_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/ip_range_fn.ts rename to src/plugins/data/common/search/aggs/buckets/ip_range_fn.ts diff --git a/src/plugins/data/public/search/aggs/buckets/lib/cidr_mask.test.ts b/src/plugins/data/common/search/aggs/buckets/lib/cidr_mask.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/lib/cidr_mask.test.ts rename to src/plugins/data/common/search/aggs/buckets/lib/cidr_mask.test.ts diff --git a/src/plugins/data/public/search/aggs/buckets/lib/cidr_mask.ts b/src/plugins/data/common/search/aggs/buckets/lib/cidr_mask.ts similarity index 97% rename from src/plugins/data/public/search/aggs/buckets/lib/cidr_mask.ts rename to src/plugins/data/common/search/aggs/buckets/lib/cidr_mask.ts index 57a7b378f305f..e4f6ab1e8da3c 100644 --- a/src/plugins/data/public/search/aggs/buckets/lib/cidr_mask.ts +++ b/src/plugins/data/common/search/aggs/buckets/lib/cidr_mask.ts @@ -17,7 +17,7 @@ * under the License. */ -import { Ipv4Address } from '../../../../../common'; +import { Ipv4Address } from '../../utils'; const NUM_BITS = 32; diff --git a/src/plugins/data/public/search/aggs/buckets/lib/date_range.ts b/src/plugins/data/common/search/aggs/buckets/lib/date_range.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/lib/date_range.ts rename to src/plugins/data/common/search/aggs/buckets/lib/date_range.ts diff --git a/src/plugins/data/public/search/aggs/buckets/lib/extended_bounds.ts b/src/plugins/data/common/search/aggs/buckets/lib/extended_bounds.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/lib/extended_bounds.ts rename to src/plugins/data/common/search/aggs/buckets/lib/extended_bounds.ts diff --git a/src/plugins/data/public/search/aggs/buckets/lib/geo_point.ts b/src/plugins/data/common/search/aggs/buckets/lib/geo_point.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/lib/geo_point.ts rename to src/plugins/data/common/search/aggs/buckets/lib/geo_point.ts diff --git a/src/plugins/data/public/search/aggs/buckets/lib/ip_range.ts b/src/plugins/data/common/search/aggs/buckets/lib/ip_range.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/lib/ip_range.ts rename to src/plugins/data/common/search/aggs/buckets/lib/ip_range.ts diff --git a/src/plugins/data/public/search/aggs/buckets/lib/time_buckets/calc_auto_interval.test.ts b/src/plugins/data/common/search/aggs/buckets/lib/time_buckets/calc_auto_interval.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/lib/time_buckets/calc_auto_interval.test.ts rename to src/plugins/data/common/search/aggs/buckets/lib/time_buckets/calc_auto_interval.test.ts diff --git a/src/plugins/data/public/search/aggs/buckets/lib/time_buckets/calc_auto_interval.ts b/src/plugins/data/common/search/aggs/buckets/lib/time_buckets/calc_auto_interval.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/lib/time_buckets/calc_auto_interval.ts rename to src/plugins/data/common/search/aggs/buckets/lib/time_buckets/calc_auto_interval.ts diff --git a/src/plugins/data/public/search/aggs/buckets/lib/time_buckets/calc_es_interval.ts b/src/plugins/data/common/search/aggs/buckets/lib/time_buckets/calc_es_interval.ts similarity index 97% rename from src/plugins/data/public/search/aggs/buckets/lib/time_buckets/calc_es_interval.ts rename to src/plugins/data/common/search/aggs/buckets/lib/time_buckets/calc_es_interval.ts index 3e7d315a0a42a..0ef2c571ca8fa 100644 --- a/src/plugins/data/public/search/aggs/buckets/lib/time_buckets/calc_es_interval.ts +++ b/src/plugins/data/common/search/aggs/buckets/lib/time_buckets/calc_es_interval.ts @@ -20,7 +20,7 @@ import moment from 'moment'; import dateMath, { Unit } from '@elastic/datemath'; -import { parseEsInterval } from '../../../../../../common'; +import { parseEsInterval } from '../../../utils'; const unitsDesc = dateMath.unitsDesc; const largeMax = unitsDesc.indexOf('M'); diff --git a/src/plugins/data/public/search/aggs/buckets/lib/time_buckets/index.ts b/src/plugins/data/common/search/aggs/buckets/lib/time_buckets/index.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/lib/time_buckets/index.ts rename to src/plugins/data/common/search/aggs/buckets/lib/time_buckets/index.ts diff --git a/src/plugins/data/public/search/aggs/buckets/lib/time_buckets/time_buckets.test.ts b/src/plugins/data/common/search/aggs/buckets/lib/time_buckets/time_buckets.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/lib/time_buckets/time_buckets.test.ts rename to src/plugins/data/common/search/aggs/buckets/lib/time_buckets/time_buckets.test.ts diff --git a/src/plugins/data/public/search/aggs/buckets/lib/time_buckets/time_buckets.ts b/src/plugins/data/common/search/aggs/buckets/lib/time_buckets/time_buckets.ts similarity index 99% rename from src/plugins/data/public/search/aggs/buckets/lib/time_buckets/time_buckets.ts rename to src/plugins/data/common/search/aggs/buckets/lib/time_buckets/time_buckets.ts index 017f646258c01..6402a6e83ead9 100644 --- a/src/plugins/data/public/search/aggs/buckets/lib/time_buckets/time_buckets.ts +++ b/src/plugins/data/common/search/aggs/buckets/lib/time_buckets/time_buckets.ts @@ -20,7 +20,7 @@ import { isString, isObject as isObjectLodash, isPlainObject, sortBy } from 'lodash'; import moment, { Moment } from 'moment'; -import { parseInterval } from '../../../../../../common'; +import { parseInterval } from '../../../utils'; import { TimeRangeBounds } from '../../../../../query'; import { calcAutoIntervalLessThan, calcAutoIntervalNear } from './calc_auto_interval'; import { diff --git a/src/plugins/data/public/search/aggs/buckets/migrate_include_exclude_format.ts b/src/plugins/data/common/search/aggs/buckets/migrate_include_exclude_format.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/migrate_include_exclude_format.ts rename to src/plugins/data/common/search/aggs/buckets/migrate_include_exclude_format.ts diff --git a/src/plugins/data/public/search/aggs/buckets/range.test.ts b/src/plugins/data/common/search/aggs/buckets/range.test.ts similarity index 79% rename from src/plugins/data/public/search/aggs/buckets/range.test.ts rename to src/plugins/data/common/search/aggs/buckets/range.test.ts index f7c61a638158c..b23b03db6a9ec 100644 --- a/src/plugins/data/public/search/aggs/buckets/range.test.ts +++ b/src/plugins/data/common/search/aggs/buckets/range.test.ts @@ -17,26 +17,12 @@ * under the License. */ -import { getRangeBucketAgg, RangeBucketAggDependencies } from './range'; import { AggConfigs } from '../agg_configs'; import { mockAggTypesRegistry } from '../test_helpers'; import { BUCKET_TYPES } from './bucket_agg_types'; -import { FieldFormatsGetConfigFn, NumberFormat } from '../../../../common'; -import { fieldFormatsServiceMock } from '../../../field_formats/mocks'; -import { InternalStartServices } from '../../../types'; +import { FieldFormatsGetConfigFn, NumberFormat } from '../../../../common/field_formats'; describe('Range Agg', () => { - let aggTypesDependencies: RangeBucketAggDependencies; - - beforeEach(() => { - aggTypesDependencies = { - getInternalStartServices: () => - (({ - fieldFormats: fieldFormatsServiceMock.createStartContract(), - } as unknown) as InternalStartServices), - }; - }); - const getConfig = (() => {}) as FieldFormatsGetConfigFn; const getAggConfigs = () => { const field = { @@ -74,7 +60,7 @@ describe('Range Agg', () => { }, ], { - typesRegistry: mockAggTypesRegistry([getRangeBucketAgg(aggTypesDependencies)]), + typesRegistry: mockAggTypesRegistry(), } ); }; diff --git a/src/plugins/data/public/search/aggs/buckets/range.ts b/src/plugins/data/common/search/aggs/buckets/range.ts similarity index 90% rename from src/plugins/data/public/search/aggs/buckets/range.ts rename to src/plugins/data/common/search/aggs/buckets/range.ts index 9f54f9fd0704e..91a357b635950 100644 --- a/src/plugins/data/public/search/aggs/buckets/range.ts +++ b/src/plugins/data/common/search/aggs/buckets/range.ts @@ -18,20 +18,22 @@ */ import { i18n } from '@kbn/i18n'; -import { BucketAggType } from './bucket_agg_type'; + import { KBN_FIELD_TYPES } from '../../../../common'; +import { AggTypesDependencies } from '../agg_types'; +import { BaseAggParams } from '../types'; + +import { BucketAggType } from './bucket_agg_type'; import { RangeKey } from './range_key'; import { createFilterRange } from './create_filter/range'; import { BUCKET_TYPES } from './bucket_agg_types'; -import { GetInternalStartServicesFn } from '../../../types'; -import { BaseAggParams } from '../types'; const rangeTitle = i18n.translate('data.search.aggs.buckets.rangeTitle', { defaultMessage: 'Range', }); export interface RangeBucketAggDependencies { - getInternalStartServices: GetInternalStartServicesFn; + getFieldFormatsStart: AggTypesDependencies['getFieldFormatsStart']; } export interface AggParamsRange extends BaseAggParams { @@ -42,13 +44,13 @@ export interface AggParamsRange extends BaseAggParams { }>; } -export const getRangeBucketAgg = ({ getInternalStartServices }: RangeBucketAggDependencies) => { +export const getRangeBucketAgg = ({ getFieldFormatsStart }: RangeBucketAggDependencies) => { const keyCaches = new WeakMap(); return new BucketAggType({ name: BUCKET_TYPES.RANGE, title: rangeTitle, - createFilter: createFilterRange(getInternalStartServices), + createFilter: createFilterRange(getFieldFormatsStart), makeLabel(aggConfig) { return i18n.translate('data.search.aggs.aggTypesLabel', { defaultMessage: '{fieldName} ranges', diff --git a/src/plugins/data/public/search/aggs/buckets/range_fn.test.ts b/src/plugins/data/common/search/aggs/buckets/range_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/range_fn.test.ts rename to src/plugins/data/common/search/aggs/buckets/range_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/buckets/range_fn.ts b/src/plugins/data/common/search/aggs/buckets/range_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/range_fn.ts rename to src/plugins/data/common/search/aggs/buckets/range_fn.ts diff --git a/src/plugins/data/public/search/aggs/buckets/range_key.ts b/src/plugins/data/common/search/aggs/buckets/range_key.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/range_key.ts rename to src/plugins/data/common/search/aggs/buckets/range_key.ts diff --git a/src/plugins/data/public/search/aggs/buckets/significant_terms.test.ts b/src/plugins/data/common/search/aggs/buckets/significant_terms.test.ts similarity index 95% rename from src/plugins/data/public/search/aggs/buckets/significant_terms.test.ts rename to src/plugins/data/common/search/aggs/buckets/significant_terms.test.ts index f13fafc2b17e6..e6c7bbee72a72 100644 --- a/src/plugins/data/public/search/aggs/buckets/significant_terms.test.ts +++ b/src/plugins/data/common/search/aggs/buckets/significant_terms.test.ts @@ -20,7 +20,6 @@ import { AggConfigs, IAggConfigs } from '../agg_configs'; import { mockAggTypesRegistry } from '../test_helpers'; import { BUCKET_TYPES } from './bucket_agg_types'; -import { getSignificantTermsBucketAgg } from './significant_terms'; describe('Significant Terms Agg', () => { describe('order agg editor UI', () => { @@ -51,7 +50,7 @@ describe('Significant Terms Agg', () => { }, ], { - typesRegistry: mockAggTypesRegistry([getSignificantTermsBucketAgg()]), + typesRegistry: mockAggTypesRegistry(), } ); }; diff --git a/src/plugins/data/public/search/aggs/buckets/significant_terms.ts b/src/plugins/data/common/search/aggs/buckets/significant_terms.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/significant_terms.ts rename to src/plugins/data/common/search/aggs/buckets/significant_terms.ts diff --git a/src/plugins/data/public/search/aggs/buckets/significant_terms_fn.test.ts b/src/plugins/data/common/search/aggs/buckets/significant_terms_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/significant_terms_fn.test.ts rename to src/plugins/data/common/search/aggs/buckets/significant_terms_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/buckets/significant_terms_fn.ts b/src/plugins/data/common/search/aggs/buckets/significant_terms_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/significant_terms_fn.ts rename to src/plugins/data/common/search/aggs/buckets/significant_terms_fn.ts diff --git a/src/plugins/data/public/search/aggs/buckets/terms.test.ts b/src/plugins/data/common/search/aggs/buckets/terms.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/terms.test.ts rename to src/plugins/data/common/search/aggs/buckets/terms.test.ts diff --git a/src/plugins/data/public/search/aggs/buckets/terms.ts b/src/plugins/data/common/search/aggs/buckets/terms.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/terms.ts rename to src/plugins/data/common/search/aggs/buckets/terms.ts diff --git a/src/plugins/data/public/search/aggs/buckets/terms_fn.test.ts b/src/plugins/data/common/search/aggs/buckets/terms_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/terms_fn.test.ts rename to src/plugins/data/common/search/aggs/buckets/terms_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/buckets/terms_fn.ts b/src/plugins/data/common/search/aggs/buckets/terms_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/buckets/terms_fn.ts rename to src/plugins/data/common/search/aggs/buckets/terms_fn.ts diff --git a/src/plugins/data/public/search/aggs/index.test.ts b/src/plugins/data/common/search/aggs/index.test.ts similarity index 63% rename from src/plugins/data/public/search/aggs/index.test.ts rename to src/plugins/data/common/search/aggs/index.test.ts index 73068326ca97e..1fdc28d1c7839 100644 --- a/src/plugins/data/public/search/aggs/index.test.ts +++ b/src/plugins/data/common/search/aggs/index.test.ts @@ -17,42 +17,34 @@ * under the License. */ -import { coreMock } from '../../../../../../src/core/public/mocks'; import { getAggTypes } from './index'; +import { mockGetFieldFormatsStart } from './test_helpers'; import { isBucketAggType } from './buckets/bucket_agg_type'; import { isMetricAggType } from './metrics/metric_agg_type'; -import { FieldFormatsStart } from '../../field_formats'; -import { InternalStartServices } from '../../types'; describe('AggTypesComponent', () => { - const coreSetup = coreMock.createSetup(); - const coreStart = coreMock.createSetup(); - - const aggTypes = getAggTypes({ - calculateBounds: jest.fn(), - getInternalStartServices: () => - (({ - notifications: coreStart.notifications, - fieldFormats: {} as FieldFormatsStart, - } as unknown) as InternalStartServices), - uiSettings: coreSetup.uiSettings, - }); - + const aggTypes = getAggTypes(); const { buckets, metrics } = aggTypes; + const aggTypesDependencies = { + calculateBounds: jest.fn(), + getConfig: jest.fn(), + getFieldFormatsStart: mockGetFieldFormatsStart, + isDefaultTimezone: jest.fn().mockReturnValue(true), + }; describe('bucket aggs', () => { test('all extend BucketAggType', () => { - buckets.forEach((bucketAgg) => { - expect(isBucketAggType(bucketAgg)).toBeTruthy(); + buckets.forEach(({ fn }) => { + expect(isBucketAggType(fn(aggTypesDependencies))).toBeTruthy(); }); }); }); describe('metric aggs', () => { test('all extend MetricAggType', () => { - metrics.forEach((metricAgg) => { - expect(isMetricAggType(metricAgg)).toBeTruthy(); + metrics.forEach(({ fn }) => { + expect(isMetricAggType(fn(aggTypesDependencies))).toBeTruthy(); }); }); }); diff --git a/src/plugins/data/common/search/aggs/index.ts b/src/plugins/data/common/search/aggs/index.ts index 7a5b7d509c940..1c4ae27e49530 100644 --- a/src/plugins/data/common/search/aggs/index.ts +++ b/src/plugins/data/common/search/aggs/index.ts @@ -17,5 +17,15 @@ * under the License. */ -export * from './date_interval_utils'; -export * from './ipv4_address'; +export * from './agg_config'; +export * from './agg_configs'; +export * from './agg_groups'; +export * from './agg_type'; +export * from './agg_types'; +export * from './agg_types_registry'; +export * from './aggs_service'; +export * from './buckets'; +export * from './metrics'; +export * from './param_types'; +export * from './types'; +export * from './utils'; diff --git a/src/plugins/data/public/search/aggs/metrics/avg.ts b/src/plugins/data/common/search/aggs/metrics/avg.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/avg.ts rename to src/plugins/data/common/search/aggs/metrics/avg.ts diff --git a/src/plugins/data/public/search/aggs/metrics/avg_fn.test.ts b/src/plugins/data/common/search/aggs/metrics/avg_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/avg_fn.test.ts rename to src/plugins/data/common/search/aggs/metrics/avg_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/avg_fn.ts b/src/plugins/data/common/search/aggs/metrics/avg_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/avg_fn.ts rename to src/plugins/data/common/search/aggs/metrics/avg_fn.ts diff --git a/src/plugins/data/public/search/aggs/metrics/bucket_avg.ts b/src/plugins/data/common/search/aggs/metrics/bucket_avg.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/bucket_avg.ts rename to src/plugins/data/common/search/aggs/metrics/bucket_avg.ts diff --git a/src/plugins/data/public/search/aggs/metrics/bucket_avg_fn.test.ts b/src/plugins/data/common/search/aggs/metrics/bucket_avg_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/bucket_avg_fn.test.ts rename to src/plugins/data/common/search/aggs/metrics/bucket_avg_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/bucket_avg_fn.ts b/src/plugins/data/common/search/aggs/metrics/bucket_avg_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/bucket_avg_fn.ts rename to src/plugins/data/common/search/aggs/metrics/bucket_avg_fn.ts diff --git a/src/plugins/data/public/search/aggs/metrics/bucket_max.ts b/src/plugins/data/common/search/aggs/metrics/bucket_max.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/bucket_max.ts rename to src/plugins/data/common/search/aggs/metrics/bucket_max.ts diff --git a/src/plugins/data/public/search/aggs/metrics/bucket_max_fn.test.ts b/src/plugins/data/common/search/aggs/metrics/bucket_max_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/bucket_max_fn.test.ts rename to src/plugins/data/common/search/aggs/metrics/bucket_max_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/bucket_max_fn.ts b/src/plugins/data/common/search/aggs/metrics/bucket_max_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/bucket_max_fn.ts rename to src/plugins/data/common/search/aggs/metrics/bucket_max_fn.ts diff --git a/src/plugins/data/public/search/aggs/metrics/bucket_min.ts b/src/plugins/data/common/search/aggs/metrics/bucket_min.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/bucket_min.ts rename to src/plugins/data/common/search/aggs/metrics/bucket_min.ts diff --git a/src/plugins/data/public/search/aggs/metrics/bucket_min_fn.test.ts b/src/plugins/data/common/search/aggs/metrics/bucket_min_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/bucket_min_fn.test.ts rename to src/plugins/data/common/search/aggs/metrics/bucket_min_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/bucket_min_fn.ts b/src/plugins/data/common/search/aggs/metrics/bucket_min_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/bucket_min_fn.ts rename to src/plugins/data/common/search/aggs/metrics/bucket_min_fn.ts diff --git a/src/plugins/data/public/search/aggs/metrics/bucket_sum.ts b/src/plugins/data/common/search/aggs/metrics/bucket_sum.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/bucket_sum.ts rename to src/plugins/data/common/search/aggs/metrics/bucket_sum.ts diff --git a/src/plugins/data/public/search/aggs/metrics/bucket_sum_fn.test.ts b/src/plugins/data/common/search/aggs/metrics/bucket_sum_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/bucket_sum_fn.test.ts rename to src/plugins/data/common/search/aggs/metrics/bucket_sum_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/bucket_sum_fn.ts b/src/plugins/data/common/search/aggs/metrics/bucket_sum_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/bucket_sum_fn.ts rename to src/plugins/data/common/search/aggs/metrics/bucket_sum_fn.ts diff --git a/src/plugins/data/public/search/aggs/metrics/cardinality.ts b/src/plugins/data/common/search/aggs/metrics/cardinality.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/cardinality.ts rename to src/plugins/data/common/search/aggs/metrics/cardinality.ts diff --git a/src/plugins/data/public/search/aggs/metrics/cardinality_fn.test.ts b/src/plugins/data/common/search/aggs/metrics/cardinality_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/cardinality_fn.test.ts rename to src/plugins/data/common/search/aggs/metrics/cardinality_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/cardinality_fn.ts b/src/plugins/data/common/search/aggs/metrics/cardinality_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/cardinality_fn.ts rename to src/plugins/data/common/search/aggs/metrics/cardinality_fn.ts diff --git a/src/plugins/data/public/search/aggs/metrics/count.ts b/src/plugins/data/common/search/aggs/metrics/count.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/count.ts rename to src/plugins/data/common/search/aggs/metrics/count.ts diff --git a/src/plugins/data/public/search/aggs/metrics/count_fn.test.ts b/src/plugins/data/common/search/aggs/metrics/count_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/count_fn.test.ts rename to src/plugins/data/common/search/aggs/metrics/count_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/count_fn.ts b/src/plugins/data/common/search/aggs/metrics/count_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/count_fn.ts rename to src/plugins/data/common/search/aggs/metrics/count_fn.ts diff --git a/src/plugins/data/public/search/aggs/metrics/cumulative_sum.ts b/src/plugins/data/common/search/aggs/metrics/cumulative_sum.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/cumulative_sum.ts rename to src/plugins/data/common/search/aggs/metrics/cumulative_sum.ts diff --git a/src/plugins/data/public/search/aggs/metrics/cumulative_sum_fn.test.ts b/src/plugins/data/common/search/aggs/metrics/cumulative_sum_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/cumulative_sum_fn.test.ts rename to src/plugins/data/common/search/aggs/metrics/cumulative_sum_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/cumulative_sum_fn.ts b/src/plugins/data/common/search/aggs/metrics/cumulative_sum_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/cumulative_sum_fn.ts rename to src/plugins/data/common/search/aggs/metrics/cumulative_sum_fn.ts diff --git a/src/plugins/data/public/search/aggs/metrics/derivative.ts b/src/plugins/data/common/search/aggs/metrics/derivative.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/derivative.ts rename to src/plugins/data/common/search/aggs/metrics/derivative.ts diff --git a/src/plugins/data/public/search/aggs/metrics/derivative_fn.test.ts b/src/plugins/data/common/search/aggs/metrics/derivative_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/derivative_fn.test.ts rename to src/plugins/data/common/search/aggs/metrics/derivative_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/derivative_fn.ts b/src/plugins/data/common/search/aggs/metrics/derivative_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/derivative_fn.ts rename to src/plugins/data/common/search/aggs/metrics/derivative_fn.ts diff --git a/src/plugins/data/public/search/aggs/metrics/geo_bounds.ts b/src/plugins/data/common/search/aggs/metrics/geo_bounds.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/geo_bounds.ts rename to src/plugins/data/common/search/aggs/metrics/geo_bounds.ts diff --git a/src/plugins/data/public/search/aggs/metrics/geo_bounds_fn.test.ts b/src/plugins/data/common/search/aggs/metrics/geo_bounds_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/geo_bounds_fn.test.ts rename to src/plugins/data/common/search/aggs/metrics/geo_bounds_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/geo_bounds_fn.ts b/src/plugins/data/common/search/aggs/metrics/geo_bounds_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/geo_bounds_fn.ts rename to src/plugins/data/common/search/aggs/metrics/geo_bounds_fn.ts diff --git a/src/plugins/data/public/search/aggs/metrics/geo_centroid.ts b/src/plugins/data/common/search/aggs/metrics/geo_centroid.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/geo_centroid.ts rename to src/plugins/data/common/search/aggs/metrics/geo_centroid.ts diff --git a/src/plugins/data/public/search/aggs/metrics/geo_centroid_fn.test.ts b/src/plugins/data/common/search/aggs/metrics/geo_centroid_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/geo_centroid_fn.test.ts rename to src/plugins/data/common/search/aggs/metrics/geo_centroid_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/geo_centroid_fn.ts b/src/plugins/data/common/search/aggs/metrics/geo_centroid_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/geo_centroid_fn.ts rename to src/plugins/data/common/search/aggs/metrics/geo_centroid_fn.ts diff --git a/src/plugins/data/public/search/aggs/metrics/index.ts b/src/plugins/data/common/search/aggs/metrics/index.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/index.ts rename to src/plugins/data/common/search/aggs/metrics/index.ts diff --git a/src/plugins/data/public/search/aggs/metrics/lib/get_response_agg_config_class.ts b/src/plugins/data/common/search/aggs/metrics/lib/get_response_agg_config_class.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/lib/get_response_agg_config_class.ts rename to src/plugins/data/common/search/aggs/metrics/lib/get_response_agg_config_class.ts diff --git a/src/plugins/data/public/search/aggs/metrics/lib/make_nested_label.test.ts b/src/plugins/data/common/search/aggs/metrics/lib/make_nested_label.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/lib/make_nested_label.test.ts rename to src/plugins/data/common/search/aggs/metrics/lib/make_nested_label.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/lib/make_nested_label.ts b/src/plugins/data/common/search/aggs/metrics/lib/make_nested_label.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/lib/make_nested_label.ts rename to src/plugins/data/common/search/aggs/metrics/lib/make_nested_label.ts diff --git a/src/plugins/data/public/search/aggs/metrics/lib/nested_agg_helpers.ts b/src/plugins/data/common/search/aggs/metrics/lib/nested_agg_helpers.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/lib/nested_agg_helpers.ts rename to src/plugins/data/common/search/aggs/metrics/lib/nested_agg_helpers.ts diff --git a/src/plugins/data/public/search/aggs/metrics/lib/ordinal_suffix.test.ts b/src/plugins/data/common/search/aggs/metrics/lib/ordinal_suffix.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/lib/ordinal_suffix.test.ts rename to src/plugins/data/common/search/aggs/metrics/lib/ordinal_suffix.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/lib/ordinal_suffix.ts b/src/plugins/data/common/search/aggs/metrics/lib/ordinal_suffix.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/lib/ordinal_suffix.ts rename to src/plugins/data/common/search/aggs/metrics/lib/ordinal_suffix.ts diff --git a/src/plugins/data/public/search/aggs/metrics/lib/parent_pipeline_agg_helper.ts b/src/plugins/data/common/search/aggs/metrics/lib/parent_pipeline_agg_helper.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/lib/parent_pipeline_agg_helper.ts rename to src/plugins/data/common/search/aggs/metrics/lib/parent_pipeline_agg_helper.ts diff --git a/src/plugins/data/public/search/aggs/metrics/lib/parent_pipeline_agg_writer.ts b/src/plugins/data/common/search/aggs/metrics/lib/parent_pipeline_agg_writer.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/lib/parent_pipeline_agg_writer.ts rename to src/plugins/data/common/search/aggs/metrics/lib/parent_pipeline_agg_writer.ts diff --git a/src/plugins/data/public/search/aggs/metrics/lib/sibling_pipeline_agg_helper.ts b/src/plugins/data/common/search/aggs/metrics/lib/sibling_pipeline_agg_helper.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/lib/sibling_pipeline_agg_helper.ts rename to src/plugins/data/common/search/aggs/metrics/lib/sibling_pipeline_agg_helper.ts diff --git a/src/plugins/data/public/search/aggs/metrics/lib/sibling_pipeline_agg_writer.ts b/src/plugins/data/common/search/aggs/metrics/lib/sibling_pipeline_agg_writer.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/lib/sibling_pipeline_agg_writer.ts rename to src/plugins/data/common/search/aggs/metrics/lib/sibling_pipeline_agg_writer.ts diff --git a/src/plugins/data/public/search/aggs/metrics/max.ts b/src/plugins/data/common/search/aggs/metrics/max.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/max.ts rename to src/plugins/data/common/search/aggs/metrics/max.ts diff --git a/src/plugins/data/public/search/aggs/metrics/max_fn.test.ts b/src/plugins/data/common/search/aggs/metrics/max_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/max_fn.test.ts rename to src/plugins/data/common/search/aggs/metrics/max_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/max_fn.ts b/src/plugins/data/common/search/aggs/metrics/max_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/max_fn.ts rename to src/plugins/data/common/search/aggs/metrics/max_fn.ts diff --git a/src/plugins/data/public/search/aggs/metrics/median.test.ts b/src/plugins/data/common/search/aggs/metrics/median.test.ts similarity index 94% rename from src/plugins/data/public/search/aggs/metrics/median.test.ts rename to src/plugins/data/common/search/aggs/metrics/median.test.ts index 22d907330e2a3..f3f2d157ebafc 100644 --- a/src/plugins/data/public/search/aggs/metrics/median.test.ts +++ b/src/plugins/data/common/search/aggs/metrics/median.test.ts @@ -17,7 +17,6 @@ * under the License. */ -import { getMedianMetricAgg } from './median'; import { AggConfigs, IAggConfigs } from '../agg_configs'; import { mockAggTypesRegistry } from '../test_helpers'; import { METRIC_TYPES } from './metric_agg_types'; @@ -26,7 +25,7 @@ describe('AggTypeMetricMedianProvider class', () => { let aggConfigs: IAggConfigs; beforeEach(() => { - const typesRegistry = mockAggTypesRegistry([getMedianMetricAgg()]); + const typesRegistry = mockAggTypesRegistry(); const field = { name: 'bytes', }; diff --git a/src/plugins/data/public/search/aggs/metrics/median.ts b/src/plugins/data/common/search/aggs/metrics/median.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/median.ts rename to src/plugins/data/common/search/aggs/metrics/median.ts diff --git a/src/plugins/data/public/search/aggs/metrics/median_fn.test.ts b/src/plugins/data/common/search/aggs/metrics/median_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/median_fn.test.ts rename to src/plugins/data/common/search/aggs/metrics/median_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/median_fn.ts b/src/plugins/data/common/search/aggs/metrics/median_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/median_fn.ts rename to src/plugins/data/common/search/aggs/metrics/median_fn.ts diff --git a/src/plugins/data/public/search/aggs/metrics/metric_agg_type.ts b/src/plugins/data/common/search/aggs/metrics/metric_agg_type.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/metric_agg_type.ts rename to src/plugins/data/common/search/aggs/metrics/metric_agg_type.ts diff --git a/src/plugins/data/public/search/aggs/metrics/metric_agg_types.ts b/src/plugins/data/common/search/aggs/metrics/metric_agg_types.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/metric_agg_types.ts rename to src/plugins/data/common/search/aggs/metrics/metric_agg_types.ts diff --git a/src/plugins/data/public/search/aggs/metrics/min.ts b/src/plugins/data/common/search/aggs/metrics/min.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/min.ts rename to src/plugins/data/common/search/aggs/metrics/min.ts diff --git a/src/plugins/data/public/search/aggs/metrics/min_fn.test.ts b/src/plugins/data/common/search/aggs/metrics/min_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/min_fn.test.ts rename to src/plugins/data/common/search/aggs/metrics/min_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/min_fn.ts b/src/plugins/data/common/search/aggs/metrics/min_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/min_fn.ts rename to src/plugins/data/common/search/aggs/metrics/min_fn.ts diff --git a/src/plugins/data/public/search/aggs/metrics/moving_avg.ts b/src/plugins/data/common/search/aggs/metrics/moving_avg.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/moving_avg.ts rename to src/plugins/data/common/search/aggs/metrics/moving_avg.ts diff --git a/src/plugins/data/public/search/aggs/metrics/moving_avg_fn.test.ts b/src/plugins/data/common/search/aggs/metrics/moving_avg_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/moving_avg_fn.test.ts rename to src/plugins/data/common/search/aggs/metrics/moving_avg_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/moving_avg_fn.ts b/src/plugins/data/common/search/aggs/metrics/moving_avg_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/moving_avg_fn.ts rename to src/plugins/data/common/search/aggs/metrics/moving_avg_fn.ts diff --git a/src/plugins/data/public/search/aggs/metrics/parent_pipeline.test.ts b/src/plugins/data/common/search/aggs/metrics/parent_pipeline.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/parent_pipeline.test.ts rename to src/plugins/data/common/search/aggs/metrics/parent_pipeline.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/percentile_ranks.test.ts b/src/plugins/data/common/search/aggs/metrics/percentile_ranks.test.ts similarity index 77% rename from src/plugins/data/public/search/aggs/metrics/percentile_ranks.test.ts rename to src/plugins/data/common/search/aggs/metrics/percentile_ranks.test.ts index 348aecc23243a..970daf5b62458 100644 --- a/src/plugins/data/public/search/aggs/metrics/percentile_ranks.test.ts +++ b/src/plugins/data/common/search/aggs/metrics/percentile_ranks.test.ts @@ -23,29 +23,16 @@ import { PercentileRanksMetricAggDependencies, } from './percentile_ranks'; import { AggConfigs, IAggConfigs } from '../agg_configs'; -import { mockAggTypesRegistry } from '../test_helpers'; +import { mockAggTypesRegistry, mockGetFieldFormatsStart } from '../test_helpers'; import { METRIC_TYPES } from './metric_agg_types'; -import { FieldFormatsStart } from '../../../field_formats'; -import { fieldFormatsServiceMock } from '../../../field_formats/mocks'; -import { InternalStartServices } from '../../../types'; describe('AggTypesMetricsPercentileRanksProvider class', function () { let aggConfigs: IAggConfigs; - let fieldFormats: FieldFormatsStart; let aggTypesDependencies: PercentileRanksMetricAggDependencies; beforeEach(() => { - fieldFormats = fieldFormatsServiceMock.createStartContract(); - fieldFormats.getDefaultInstance = (() => ({ - convert: (t?: string) => t, - })) as any; - aggTypesDependencies = { - getInternalStartServices: () => - (({ - fieldFormats, - } as unknown) as InternalStartServices), - }; - const typesRegistry = mockAggTypesRegistry([getPercentileRanksMetricAgg(aggTypesDependencies)]); + aggTypesDependencies = { getFieldFormatsStart: mockGetFieldFormatsStart }; + const typesRegistry = mockAggTypesRegistry(); const field = { name: 'bytes', }; diff --git a/src/plugins/data/public/search/aggs/metrics/percentile_ranks.ts b/src/plugins/data/common/search/aggs/metrics/percentile_ranks.ts similarity index 86% rename from src/plugins/data/public/search/aggs/metrics/percentile_ranks.ts rename to src/plugins/data/common/search/aggs/metrics/percentile_ranks.ts index 3c0be229f1bbd..664cc1ad02ada 100644 --- a/src/plugins/data/public/search/aggs/metrics/percentile_ranks.ts +++ b/src/plugins/data/common/search/aggs/metrics/percentile_ranks.ts @@ -18,13 +18,15 @@ */ import { i18n } from '@kbn/i18n'; + +import { KBN_FIELD_TYPES } from '../../../../common'; +import { AggTypesDependencies } from '../agg_types'; +import { BaseAggParams } from '../types'; + import { MetricAggType } from './metric_agg_type'; import { getResponseAggConfigClass, IResponseAggConfig } from './lib/get_response_agg_config_class'; import { getPercentileValue } from './percentiles_get_value'; import { METRIC_TYPES } from './metric_agg_types'; -import { KBN_FIELD_TYPES } from '../../../../common'; -import { GetInternalStartServicesFn } from '../../../types'; -import { BaseAggParams } from '../types'; export interface AggParamsPercentileRanks extends BaseAggParams { field: string; @@ -35,16 +37,17 @@ export interface AggParamsPercentileRanks extends BaseAggParams { export type IPercentileRanksAggConfig = IResponseAggConfig; export interface PercentileRanksMetricAggDependencies { - getInternalStartServices: GetInternalStartServicesFn; + getFieldFormatsStart: AggTypesDependencies['getFieldFormatsStart']; } -const getValueProps = (getInternalStartServices: GetInternalStartServicesFn) => { +const getValueProps = ( + getFieldFormatsStart: PercentileRanksMetricAggDependencies['getFieldFormatsStart'] +) => { return { makeLabel(this: IPercentileRanksAggConfig) { - const { fieldFormats } = getInternalStartServices(); + const { getDefaultInstance } = getFieldFormatsStart(); const field = this.getField(); - const format = - (field && field.format) || fieldFormats.getDefaultInstance(KBN_FIELD_TYPES.NUMBER); + const format = (field && field.format) || getDefaultInstance(KBN_FIELD_TYPES.NUMBER); const customLabel = this.getParam('customLabel'); const label = customLabel || this.getFieldDisplayName(); @@ -57,7 +60,7 @@ const getValueProps = (getInternalStartServices: GetInternalStartServicesFn) => }; export const getPercentileRanksMetricAgg = ({ - getInternalStartServices, + getFieldFormatsStart, }: PercentileRanksMetricAggDependencies) => { return new MetricAggType({ name: METRIC_TYPES.PERCENTILE_RANKS, @@ -87,10 +90,7 @@ export const getPercentileRanksMetricAgg = ({ }, ], getResponseAggs(agg) { - const ValueAggConfig = getResponseAggConfigClass( - agg, - getValueProps(getInternalStartServices) - ); + const ValueAggConfig = getResponseAggConfigClass(agg, getValueProps(getFieldFormatsStart)); const values = agg.getParam('values'); return values.map((value: any) => new ValueAggConfig(value)); diff --git a/src/plugins/data/public/search/aggs/metrics/percentile_ranks_fn.test.ts b/src/plugins/data/common/search/aggs/metrics/percentile_ranks_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/percentile_ranks_fn.test.ts rename to src/plugins/data/common/search/aggs/metrics/percentile_ranks_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/percentile_ranks_fn.ts b/src/plugins/data/common/search/aggs/metrics/percentile_ranks_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/percentile_ranks_fn.ts rename to src/plugins/data/common/search/aggs/metrics/percentile_ranks_fn.ts diff --git a/src/plugins/data/public/search/aggs/metrics/percentiles.test.ts b/src/plugins/data/common/search/aggs/metrics/percentiles.test.ts similarity index 96% rename from src/plugins/data/public/search/aggs/metrics/percentiles.test.ts rename to src/plugins/data/common/search/aggs/metrics/percentiles.test.ts index a44c0e5075ef9..10e98df5a4eeb 100644 --- a/src/plugins/data/public/search/aggs/metrics/percentiles.test.ts +++ b/src/plugins/data/common/search/aggs/metrics/percentiles.test.ts @@ -26,7 +26,7 @@ describe('AggTypesMetricsPercentilesProvider class', () => { let aggConfigs: IAggConfigs; beforeEach(() => { - const typesRegistry = mockAggTypesRegistry([getPercentilesMetricAgg()]); + const typesRegistry = mockAggTypesRegistry(); const field = { name: 'bytes', }; diff --git a/src/plugins/data/public/search/aggs/metrics/percentiles.ts b/src/plugins/data/common/search/aggs/metrics/percentiles.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/percentiles.ts rename to src/plugins/data/common/search/aggs/metrics/percentiles.ts diff --git a/src/plugins/data/public/search/aggs/metrics/percentiles_fn.test.ts b/src/plugins/data/common/search/aggs/metrics/percentiles_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/percentiles_fn.test.ts rename to src/plugins/data/common/search/aggs/metrics/percentiles_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/percentiles_fn.ts b/src/plugins/data/common/search/aggs/metrics/percentiles_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/percentiles_fn.ts rename to src/plugins/data/common/search/aggs/metrics/percentiles_fn.ts diff --git a/src/plugins/data/public/search/aggs/metrics/percentiles_get_value.ts b/src/plugins/data/common/search/aggs/metrics/percentiles_get_value.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/percentiles_get_value.ts rename to src/plugins/data/common/search/aggs/metrics/percentiles_get_value.ts diff --git a/src/plugins/data/public/search/aggs/metrics/serial_diff.ts b/src/plugins/data/common/search/aggs/metrics/serial_diff.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/serial_diff.ts rename to src/plugins/data/common/search/aggs/metrics/serial_diff.ts diff --git a/src/plugins/data/public/search/aggs/metrics/serial_diff_fn.test.ts b/src/plugins/data/common/search/aggs/metrics/serial_diff_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/serial_diff_fn.test.ts rename to src/plugins/data/common/search/aggs/metrics/serial_diff_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/serial_diff_fn.ts b/src/plugins/data/common/search/aggs/metrics/serial_diff_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/serial_diff_fn.ts rename to src/plugins/data/common/search/aggs/metrics/serial_diff_fn.ts diff --git a/src/plugins/data/public/search/aggs/metrics/sibling_pipeline.test.ts b/src/plugins/data/common/search/aggs/metrics/sibling_pipeline.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/sibling_pipeline.test.ts rename to src/plugins/data/common/search/aggs/metrics/sibling_pipeline.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/std_deviation.test.ts b/src/plugins/data/common/search/aggs/metrics/std_deviation.test.ts similarity index 97% rename from src/plugins/data/public/search/aggs/metrics/std_deviation.test.ts rename to src/plugins/data/common/search/aggs/metrics/std_deviation.test.ts index c3efe95f44a56..f2f30fcde42eb 100644 --- a/src/plugins/data/public/search/aggs/metrics/std_deviation.test.ts +++ b/src/plugins/data/common/search/aggs/metrics/std_deviation.test.ts @@ -23,7 +23,7 @@ import { mockAggTypesRegistry } from '../test_helpers'; import { METRIC_TYPES } from './metric_agg_types'; describe('AggTypeMetricStandardDeviationProvider class', () => { - const typesRegistry = mockAggTypesRegistry([getStdDeviationMetricAgg()]); + const typesRegistry = mockAggTypesRegistry(); const getAggConfigs = (customLabel?: string) => { const field = { name: 'memory', diff --git a/src/plugins/data/public/search/aggs/metrics/std_deviation.ts b/src/plugins/data/common/search/aggs/metrics/std_deviation.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/std_deviation.ts rename to src/plugins/data/common/search/aggs/metrics/std_deviation.ts diff --git a/src/plugins/data/public/search/aggs/metrics/std_deviation_fn.test.ts b/src/plugins/data/common/search/aggs/metrics/std_deviation_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/std_deviation_fn.test.ts rename to src/plugins/data/common/search/aggs/metrics/std_deviation_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/std_deviation_fn.ts b/src/plugins/data/common/search/aggs/metrics/std_deviation_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/std_deviation_fn.ts rename to src/plugins/data/common/search/aggs/metrics/std_deviation_fn.ts diff --git a/src/plugins/data/public/search/aggs/metrics/sum.ts b/src/plugins/data/common/search/aggs/metrics/sum.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/sum.ts rename to src/plugins/data/common/search/aggs/metrics/sum.ts diff --git a/src/plugins/data/public/search/aggs/metrics/sum_fn.test.ts b/src/plugins/data/common/search/aggs/metrics/sum_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/sum_fn.test.ts rename to src/plugins/data/common/search/aggs/metrics/sum_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/sum_fn.ts b/src/plugins/data/common/search/aggs/metrics/sum_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/sum_fn.ts rename to src/plugins/data/common/search/aggs/metrics/sum_fn.ts diff --git a/src/plugins/data/public/search/aggs/metrics/top_hit.test.ts b/src/plugins/data/common/search/aggs/metrics/top_hit.test.ts similarity index 99% rename from src/plugins/data/public/search/aggs/metrics/top_hit.test.ts rename to src/plugins/data/common/search/aggs/metrics/top_hit.test.ts index c2434df3ae53c..c0cbfb33c842b 100644 --- a/src/plugins/data/public/search/aggs/metrics/top_hit.test.ts +++ b/src/plugins/data/common/search/aggs/metrics/top_hit.test.ts @@ -36,7 +36,7 @@ describe('Top hit metric', () => { fieldType = KBN_FIELD_TYPES.NUMBER, size = 1, }: any) => { - const typesRegistry = mockAggTypesRegistry([getTopHitMetricAgg()]); + const typesRegistry = mockAggTypesRegistry(); const field = { name: fieldName, displayName: fieldName, diff --git a/src/plugins/data/public/search/aggs/metrics/top_hit.ts b/src/plugins/data/common/search/aggs/metrics/top_hit.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/top_hit.ts rename to src/plugins/data/common/search/aggs/metrics/top_hit.ts diff --git a/src/plugins/data/public/search/aggs/metrics/top_hit_fn.test.ts b/src/plugins/data/common/search/aggs/metrics/top_hit_fn.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/top_hit_fn.test.ts rename to src/plugins/data/common/search/aggs/metrics/top_hit_fn.test.ts diff --git a/src/plugins/data/public/search/aggs/metrics/top_hit_fn.ts b/src/plugins/data/common/search/aggs/metrics/top_hit_fn.ts similarity index 100% rename from src/plugins/data/public/search/aggs/metrics/top_hit_fn.ts rename to src/plugins/data/common/search/aggs/metrics/top_hit_fn.ts diff --git a/src/plugins/data/public/search/aggs/param_types/agg.ts b/src/plugins/data/common/search/aggs/param_types/agg.ts similarity index 100% rename from src/plugins/data/public/search/aggs/param_types/agg.ts rename to src/plugins/data/common/search/aggs/param_types/agg.ts diff --git a/src/plugins/data/public/search/aggs/param_types/base.ts b/src/plugins/data/common/search/aggs/param_types/base.ts similarity index 96% rename from src/plugins/data/public/search/aggs/param_types/base.ts rename to src/plugins/data/common/search/aggs/param_types/base.ts index 1ba8a75e98cbe..3a12a9a54500f 100644 --- a/src/plugins/data/public/search/aggs/param_types/base.ts +++ b/src/plugins/data/common/search/aggs/param_types/base.ts @@ -17,11 +17,10 @@ * under the License. */ +import { FetchOptions, ISearchSource } from 'src/plugins/data/public'; import { ExpressionAstFunction } from 'src/plugins/expressions/common'; import { IAggConfigs } from '../agg_configs'; import { IAggConfig } from '../agg_config'; -import { FetchOptions } from '../../fetch'; -import { ISearchSource } from '../../search_source'; export class BaseParamType { name: string; diff --git a/src/plugins/data/public/search/aggs/param_types/field.test.ts b/src/plugins/data/common/search/aggs/param_types/field.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/param_types/field.test.ts rename to src/plugins/data/common/search/aggs/param_types/field.test.ts diff --git a/src/plugins/data/public/search/aggs/param_types/field.ts b/src/plugins/data/common/search/aggs/param_types/field.ts similarity index 96% rename from src/plugins/data/public/search/aggs/param_types/field.ts rename to src/plugins/data/common/search/aggs/param_types/field.ts index 7c00bc668a39f..492294bdf4e5f 100644 --- a/src/plugins/data/public/search/aggs/param_types/field.ts +++ b/src/plugins/data/common/search/aggs/param_types/field.ts @@ -22,8 +22,8 @@ import { IAggConfig } from '../agg_config'; import { SavedObjectNotFound } from '../../../../../../plugins/kibana_utils/common'; import { BaseParamType } from './base'; import { propFilter } from '../utils'; -import { isNestedField, KBN_FIELD_TYPES } from '../../../../common'; -import { IndexPatternField } from '../../../index_patterns'; +import { KBN_FIELD_TYPES } from '../../../kbn_field_types/types'; +import { isNestedField, IndexPatternField } from '../../../index_patterns/fields'; const filterByType = propFilter('type'); diff --git a/src/plugins/data/public/search/aggs/param_types/index.ts b/src/plugins/data/common/search/aggs/param_types/index.ts similarity index 100% rename from src/plugins/data/public/search/aggs/param_types/index.ts rename to src/plugins/data/common/search/aggs/param_types/index.ts diff --git a/src/plugins/data/public/search/aggs/param_types/json.test.ts b/src/plugins/data/common/search/aggs/param_types/json.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/param_types/json.test.ts rename to src/plugins/data/common/search/aggs/param_types/json.test.ts diff --git a/src/plugins/data/public/search/aggs/param_types/json.ts b/src/plugins/data/common/search/aggs/param_types/json.ts similarity index 100% rename from src/plugins/data/public/search/aggs/param_types/json.ts rename to src/plugins/data/common/search/aggs/param_types/json.ts diff --git a/src/plugins/data/public/search/aggs/param_types/optioned.test.ts b/src/plugins/data/common/search/aggs/param_types/optioned.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/param_types/optioned.test.ts rename to src/plugins/data/common/search/aggs/param_types/optioned.test.ts diff --git a/src/plugins/data/public/search/aggs/param_types/optioned.ts b/src/plugins/data/common/search/aggs/param_types/optioned.ts similarity index 100% rename from src/plugins/data/public/search/aggs/param_types/optioned.ts rename to src/plugins/data/common/search/aggs/param_types/optioned.ts diff --git a/src/plugins/data/public/search/aggs/param_types/string.test.ts b/src/plugins/data/common/search/aggs/param_types/string.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/param_types/string.test.ts rename to src/plugins/data/common/search/aggs/param_types/string.test.ts diff --git a/src/plugins/data/public/search/aggs/param_types/string.ts b/src/plugins/data/common/search/aggs/param_types/string.ts similarity index 100% rename from src/plugins/data/public/search/aggs/param_types/string.ts rename to src/plugins/data/common/search/aggs/param_types/string.ts diff --git a/src/plugins/data/public/search/aggs/test_helpers/function_wrapper.ts b/src/plugins/data/common/search/aggs/test_helpers/function_wrapper.ts similarity index 100% rename from src/plugins/data/public/search/aggs/test_helpers/function_wrapper.ts rename to src/plugins/data/common/search/aggs/test_helpers/function_wrapper.ts diff --git a/src/plugins/data/public/search/aggs/test_helpers/index.ts b/src/plugins/data/common/search/aggs/test_helpers/index.ts similarity index 86% rename from src/plugins/data/public/search/aggs/test_helpers/index.ts rename to src/plugins/data/common/search/aggs/test_helpers/index.ts index d47317d8b4725..30f315f276741 100644 --- a/src/plugins/data/public/search/aggs/test_helpers/index.ts +++ b/src/plugins/data/common/search/aggs/test_helpers/index.ts @@ -17,5 +17,5 @@ * under the License. */ -export { functionWrapper } from './function_wrapper'; -export { mockAggTypesRegistry } from './mock_agg_types_registry'; +export * from './function_wrapper'; +export * from './mock_agg_types_registry'; diff --git a/src/plugins/data/public/search/aggs/test_helpers/mock_agg_types_registry.ts b/src/plugins/data/common/search/aggs/test_helpers/mock_agg_types_registry.ts similarity index 52% rename from src/plugins/data/public/search/aggs/test_helpers/mock_agg_types_registry.ts rename to src/plugins/data/common/search/aggs/test_helpers/mock_agg_types_registry.ts index 4a0820c349b5f..14631a9d53055 100644 --- a/src/plugins/data/public/search/aggs/test_helpers/mock_agg_types_registry.ts +++ b/src/plugins/data/common/search/aggs/test_helpers/mock_agg_types_registry.ts @@ -17,17 +17,14 @@ * under the License. */ -import { coreMock } from '../../../../../../../src/core/public/mocks'; +import { fieldFormatsMock } from '../../../field_formats/mocks'; + import { AggTypesRegistry, AggTypesRegistryStart } from '../agg_types_registry'; -import { getAggTypes } from '../agg_types'; -import { BucketAggType } from '../buckets/bucket_agg_type'; -import { MetricAggType } from '../metrics/metric_agg_type'; -import { fieldFormatsServiceMock } from '../../../field_formats/mocks'; -import { InternalStartServices } from '../../../types'; +import { AggTypesDependencies, getAggTypes } from '../agg_types'; import { TimeBucketsConfig } from '../buckets/lib/time_buckets/time_buckets'; // Mocked uiSettings shared among aggs unit tests -const mockUiSettings = jest.fn().mockImplementation((key: string) => { +const mockGetConfig = jest.fn().mockImplementation((key: string) => { const config: TimeBucketsConfig = { 'histogram:maxBars': 4, 'histogram:barTarget': 3, @@ -44,6 +41,23 @@ const mockUiSettings = jest.fn().mockImplementation((key: string) => { return config[key] ?? key; }); +/** @internal */ +export function mockGetFieldFormatsStart() { + const { deserialize, getDefaultInstance } = fieldFormatsMock; + return { + deserialize, + getDefaultInstance, + }; +} + +/** @internal */ +export const mockAggTypesDependencies: AggTypesDependencies = { + calculateBounds: jest.fn(), + getFieldFormatsStart: mockGetFieldFormatsStart, + getConfig: mockGetConfig, + isDefaultTimezone: () => true, +}; + /** * Testing utility which creates a new instance of AggTypesRegistry, * registers the provided agg types, and returns AggTypesRegistry.start() @@ -56,36 +70,37 @@ const mockUiSettings = jest.fn().mockImplementation((key: string) => { * * @internal */ -export function mockAggTypesRegistry | MetricAggType>( - types?: T[] -): AggTypesRegistryStart { +export function mockAggTypesRegistry(deps?: AggTypesDependencies): AggTypesRegistryStart { const registry = new AggTypesRegistry(); + const initializedAggTypes = new Map(); const registrySetup = registry.setup(); - if (types) { - types.forEach((type) => { - if (type instanceof BucketAggType) { - registrySetup.registerBucket(type); - } else if (type instanceof MetricAggType) { - registrySetup.registerMetric(type); - } - }); - } else { - const coreSetup = coreMock.createSetup(); - coreSetup.uiSettings.get = mockUiSettings; + const aggTypes = getAggTypes(); + + aggTypes.buckets.forEach(({ name, fn }) => registrySetup.registerBucket(name, fn)); + aggTypes.metrics.forEach(({ name, fn }) => registrySetup.registerMetric(name, fn)); - const aggTypes = getAggTypes({ - calculateBounds: jest.fn(), - getInternalStartServices: () => - (({ - fieldFormats: fieldFormatsServiceMock.createStartContract(), - } as unknown) as InternalStartServices), - uiSettings: coreSetup.uiSettings, - }); + const registryStart = registry.start(); - aggTypes.buckets.forEach((type) => registrySetup.registerBucket(type)); - aggTypes.metrics.forEach((type) => registrySetup.registerMetric(type)); - } + // initialize each agg type and store in memory + registryStart.getAll().buckets.forEach((type) => { + const agg = type(deps ?? mockAggTypesDependencies); + initializedAggTypes.set(agg.name, agg); + }); + registryStart.getAll().metrics.forEach((type) => { + const agg = type(deps ?? mockAggTypesDependencies); + initializedAggTypes.set(agg.name, agg); + }); - return registry.start(); + return { + get: (name: string) => { + return initializedAggTypes.get(name); + }, + getAll: () => { + return { + buckets: Array.from(initializedAggTypes.values()).filter((agg) => agg.type === 'buckets'), + metrics: Array.from(initializedAggTypes.values()).filter((agg) => agg.type === 'metrics'), + }; + }, + }; } diff --git a/src/plugins/data/common/search/aggs/types.ts b/src/plugins/data/common/search/aggs/types.ts new file mode 100644 index 0000000000000..dabd653463d4f --- /dev/null +++ b/src/plugins/data/common/search/aggs/types.ts @@ -0,0 +1,157 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { Assign } from '@kbn/utility-types'; +import { IndexPattern } from '../../index_patterns/index_patterns/index_pattern'; +import { + AggConfigSerialized, + AggConfigs, + AggParamsRange, + AggParamsIpRange, + AggParamsDateRange, + AggParamsFilter, + AggParamsFilters, + AggParamsSignificantTerms, + AggParamsGeoTile, + AggParamsGeoHash, + AggParamsTerms, + AggParamsAvg, + AggParamsCardinality, + AggParamsGeoBounds, + AggParamsGeoCentroid, + AggParamsMax, + AggParamsMedian, + AggParamsMin, + AggParamsStdDeviation, + AggParamsSum, + AggParamsBucketAvg, + AggParamsBucketMax, + AggParamsBucketMin, + AggParamsBucketSum, + AggParamsCumulativeSum, + AggParamsDerivative, + AggParamsMovingAvg, + AggParamsPercentileRanks, + AggParamsPercentiles, + AggParamsSerialDiff, + AggParamsTopHit, + AggParamsHistogram, + AggParamsDateHistogram, + AggTypesRegistry, + AggTypesRegistrySetup, + AggTypesRegistryStart, + CreateAggConfigParams, + getCalculateAutoTimeExpression, + METRIC_TYPES, + BUCKET_TYPES, +} from './'; + +export { IAggConfig, AggConfigSerialized } from './agg_config'; +export { CreateAggConfigParams, IAggConfigs } from './agg_configs'; +export { IAggType } from './agg_type'; +export { AggParam, AggParamOption } from './agg_params'; +export { IFieldParamType } from './param_types'; +export { IMetricAggType } from './metrics/metric_agg_type'; +export { DateRangeKey } from './buckets/lib/date_range'; +export { IpRangeKey } from './buckets/lib/ip_range'; +export { OptionedValueProp } from './param_types/optioned'; + +/** @internal */ +export interface AggsCommonSetup { + types: AggTypesRegistrySetup; +} + +/** @internal */ +export interface AggsCommonStart { + calculateAutoTimeExpression: ReturnType; + createAggConfigs: ( + indexPattern: IndexPattern, + configStates?: CreateAggConfigParams[], + schemas?: Record + ) => InstanceType; + types: ReturnType; +} + +/** + * AggsStart represents the actual external contract as AggsCommonStart + * is only used internally. The difference is that AggsStart includes the + * typings for the registry with initialized agg types. + * + * @internal + */ +export type AggsStart = Assign; + +/** @internal */ +export interface BaseAggParams { + json?: string; + customLabel?: string; +} + +/** @internal */ +export interface AggExpressionType { + type: 'agg_type'; + value: AggConfigSerialized; +} + +/** @internal */ +export type AggExpressionFunctionArgs< + Name extends keyof AggParamsMapping +> = AggParamsMapping[Name] & Pick; + +/** + * A global list of the param interfaces for each agg type. + * For now this is internal, but eventually we will probably + * want to make it public. + * + * @internal + */ +export interface AggParamsMapping { + [BUCKET_TYPES.RANGE]: AggParamsRange; + [BUCKET_TYPES.IP_RANGE]: AggParamsIpRange; + [BUCKET_TYPES.DATE_RANGE]: AggParamsDateRange; + [BUCKET_TYPES.FILTER]: AggParamsFilter; + [BUCKET_TYPES.FILTERS]: AggParamsFilters; + [BUCKET_TYPES.SIGNIFICANT_TERMS]: AggParamsSignificantTerms; + [BUCKET_TYPES.GEOTILE_GRID]: AggParamsGeoTile; + [BUCKET_TYPES.GEOHASH_GRID]: AggParamsGeoHash; + [BUCKET_TYPES.HISTOGRAM]: AggParamsHistogram; + [BUCKET_TYPES.DATE_HISTOGRAM]: AggParamsDateHistogram; + [BUCKET_TYPES.TERMS]: AggParamsTerms; + [METRIC_TYPES.AVG]: AggParamsAvg; + [METRIC_TYPES.CARDINALITY]: AggParamsCardinality; + [METRIC_TYPES.COUNT]: BaseAggParams; + [METRIC_TYPES.GEO_BOUNDS]: AggParamsGeoBounds; + [METRIC_TYPES.GEO_CENTROID]: AggParamsGeoCentroid; + [METRIC_TYPES.MAX]: AggParamsMax; + [METRIC_TYPES.MEDIAN]: AggParamsMedian; + [METRIC_TYPES.MIN]: AggParamsMin; + [METRIC_TYPES.STD_DEV]: AggParamsStdDeviation; + [METRIC_TYPES.SUM]: AggParamsSum; + [METRIC_TYPES.AVG_BUCKET]: AggParamsBucketAvg; + [METRIC_TYPES.MAX_BUCKET]: AggParamsBucketMax; + [METRIC_TYPES.MIN_BUCKET]: AggParamsBucketMin; + [METRIC_TYPES.SUM_BUCKET]: AggParamsBucketSum; + [METRIC_TYPES.CUMULATIVE_SUM]: AggParamsCumulativeSum; + [METRIC_TYPES.DERIVATIVE]: AggParamsDerivative; + [METRIC_TYPES.MOVING_FN]: AggParamsMovingAvg; + [METRIC_TYPES.PERCENTILE_RANKS]: AggParamsPercentileRanks; + [METRIC_TYPES.PERCENTILES]: AggParamsPercentiles; + [METRIC_TYPES.SERIAL_DIFF]: AggParamsSerialDiff; + [METRIC_TYPES.TOP_HITS]: AggParamsTopHit; +} diff --git a/src/plugins/data/public/search/aggs/utils/calculate_auto_time_expression.ts b/src/plugins/data/common/search/aggs/utils/calculate_auto_time_expression.ts similarity index 71% rename from src/plugins/data/public/search/aggs/utils/calculate_auto_time_expression.ts rename to src/plugins/data/common/search/aggs/utils/calculate_auto_time_expression.ts index 30fcdd9d83a38..622e8101f34ab 100644 --- a/src/plugins/data/public/search/aggs/utils/calculate_auto_time_expression.ts +++ b/src/plugins/data/common/search/aggs/utils/calculate_auto_time_expression.ts @@ -17,11 +17,12 @@ * under the License. */ import moment from 'moment'; -import { IUiSettingsClient } from 'src/core/public'; +import { UI_SETTINGS } from '../../../../common/constants'; +import { TimeRange } from '../../../../common/query'; import { TimeBuckets } from '../buckets/lib/time_buckets'; -import { toAbsoluteDates, TimeRange, UI_SETTINGS } from '../../../../common'; +import { toAbsoluteDates } from './date_interval_utils'; -export function getCalculateAutoTimeExpression(uiSettings: IUiSettingsClient) { +export function getCalculateAutoTimeExpression(getConfig: (key: string) => any) { return function calculateAutoTimeExpression(range: TimeRange) { const dates = toAbsoluteDates(range); if (!dates) { @@ -29,10 +30,10 @@ export function getCalculateAutoTimeExpression(uiSettings: IUiSettingsClient) { } const buckets = new TimeBuckets({ - 'histogram:maxBars': uiSettings.get(UI_SETTINGS.HISTOGRAM_MAX_BARS), - 'histogram:barTarget': uiSettings.get(UI_SETTINGS.HISTOGRAM_BAR_TARGET), - dateFormat: uiSettings.get('dateFormat'), - 'dateFormat:scaled': uiSettings.get('dateFormat:scaled'), + 'histogram:maxBars': getConfig(UI_SETTINGS.HISTOGRAM_MAX_BARS), + 'histogram:barTarget': getConfig(UI_SETTINGS.HISTOGRAM_BAR_TARGET), + dateFormat: getConfig('dateFormat'), + 'dateFormat:scaled': getConfig('dateFormat:scaled'), }); buckets.setInterval('auto'); diff --git a/src/plugins/data/common/search/aggs/date_interval_utils/date_histogram_interval.test.ts b/src/plugins/data/common/search/aggs/utils/date_interval_utils/date_histogram_interval.test.ts similarity index 100% rename from src/plugins/data/common/search/aggs/date_interval_utils/date_histogram_interval.test.ts rename to src/plugins/data/common/search/aggs/utils/date_interval_utils/date_histogram_interval.test.ts diff --git a/src/plugins/data/common/search/aggs/date_interval_utils/date_histogram_interval.ts b/src/plugins/data/common/search/aggs/utils/date_interval_utils/date_histogram_interval.ts similarity index 100% rename from src/plugins/data/common/search/aggs/date_interval_utils/date_histogram_interval.ts rename to src/plugins/data/common/search/aggs/utils/date_interval_utils/date_histogram_interval.ts diff --git a/src/plugins/data/common/search/aggs/date_interval_utils/index.ts b/src/plugins/data/common/search/aggs/utils/date_interval_utils/index.ts similarity index 100% rename from src/plugins/data/common/search/aggs/date_interval_utils/index.ts rename to src/plugins/data/common/search/aggs/utils/date_interval_utils/index.ts diff --git a/src/plugins/data/common/search/aggs/date_interval_utils/invalid_es_calendar_interval_error.ts b/src/plugins/data/common/search/aggs/utils/date_interval_utils/invalid_es_calendar_interval_error.ts similarity index 100% rename from src/plugins/data/common/search/aggs/date_interval_utils/invalid_es_calendar_interval_error.ts rename to src/plugins/data/common/search/aggs/utils/date_interval_utils/invalid_es_calendar_interval_error.ts diff --git a/src/plugins/data/common/search/aggs/date_interval_utils/invalid_es_interval_format_error.ts b/src/plugins/data/common/search/aggs/utils/date_interval_utils/invalid_es_interval_format_error.ts similarity index 100% rename from src/plugins/data/common/search/aggs/date_interval_utils/invalid_es_interval_format_error.ts rename to src/plugins/data/common/search/aggs/utils/date_interval_utils/invalid_es_interval_format_error.ts diff --git a/src/plugins/data/common/search/aggs/date_interval_utils/is_valid_es_interval.ts b/src/plugins/data/common/search/aggs/utils/date_interval_utils/is_valid_es_interval.ts similarity index 100% rename from src/plugins/data/common/search/aggs/date_interval_utils/is_valid_es_interval.ts rename to src/plugins/data/common/search/aggs/utils/date_interval_utils/is_valid_es_interval.ts diff --git a/src/plugins/data/common/search/aggs/date_interval_utils/is_valid_interval.ts b/src/plugins/data/common/search/aggs/utils/date_interval_utils/is_valid_interval.ts similarity index 100% rename from src/plugins/data/common/search/aggs/date_interval_utils/is_valid_interval.ts rename to src/plugins/data/common/search/aggs/utils/date_interval_utils/is_valid_interval.ts diff --git a/src/plugins/data/common/search/aggs/date_interval_utils/least_common_interval.test.ts b/src/plugins/data/common/search/aggs/utils/date_interval_utils/least_common_interval.test.ts similarity index 100% rename from src/plugins/data/common/search/aggs/date_interval_utils/least_common_interval.test.ts rename to src/plugins/data/common/search/aggs/utils/date_interval_utils/least_common_interval.test.ts diff --git a/src/plugins/data/common/search/aggs/date_interval_utils/least_common_interval.ts b/src/plugins/data/common/search/aggs/utils/date_interval_utils/least_common_interval.ts similarity index 100% rename from src/plugins/data/common/search/aggs/date_interval_utils/least_common_interval.ts rename to src/plugins/data/common/search/aggs/utils/date_interval_utils/least_common_interval.ts diff --git a/src/plugins/data/common/search/aggs/date_interval_utils/least_common_multiple.test.ts b/src/plugins/data/common/search/aggs/utils/date_interval_utils/least_common_multiple.test.ts similarity index 100% rename from src/plugins/data/common/search/aggs/date_interval_utils/least_common_multiple.test.ts rename to src/plugins/data/common/search/aggs/utils/date_interval_utils/least_common_multiple.test.ts diff --git a/src/plugins/data/common/search/aggs/date_interval_utils/least_common_multiple.ts b/src/plugins/data/common/search/aggs/utils/date_interval_utils/least_common_multiple.ts similarity index 100% rename from src/plugins/data/common/search/aggs/date_interval_utils/least_common_multiple.ts rename to src/plugins/data/common/search/aggs/utils/date_interval_utils/least_common_multiple.ts diff --git a/src/plugins/data/common/search/aggs/date_interval_utils/parse_es_interval.test.ts b/src/plugins/data/common/search/aggs/utils/date_interval_utils/parse_es_interval.test.ts similarity index 100% rename from src/plugins/data/common/search/aggs/date_interval_utils/parse_es_interval.test.ts rename to src/plugins/data/common/search/aggs/utils/date_interval_utils/parse_es_interval.test.ts diff --git a/src/plugins/data/common/search/aggs/date_interval_utils/parse_es_interval.ts b/src/plugins/data/common/search/aggs/utils/date_interval_utils/parse_es_interval.ts similarity index 100% rename from src/plugins/data/common/search/aggs/date_interval_utils/parse_es_interval.ts rename to src/plugins/data/common/search/aggs/utils/date_interval_utils/parse_es_interval.ts diff --git a/src/plugins/data/common/search/aggs/date_interval_utils/parse_interval.test.ts b/src/plugins/data/common/search/aggs/utils/date_interval_utils/parse_interval.test.ts similarity index 100% rename from src/plugins/data/common/search/aggs/date_interval_utils/parse_interval.test.ts rename to src/plugins/data/common/search/aggs/utils/date_interval_utils/parse_interval.test.ts diff --git a/src/plugins/data/common/search/aggs/date_interval_utils/parse_interval.ts b/src/plugins/data/common/search/aggs/utils/date_interval_utils/parse_interval.ts similarity index 100% rename from src/plugins/data/common/search/aggs/date_interval_utils/parse_interval.ts rename to src/plugins/data/common/search/aggs/utils/date_interval_utils/parse_interval.ts diff --git a/src/plugins/data/common/search/aggs/date_interval_utils/to_absolute_dates.ts b/src/plugins/data/common/search/aggs/utils/date_interval_utils/to_absolute_dates.ts similarity index 95% rename from src/plugins/data/common/search/aggs/date_interval_utils/to_absolute_dates.ts rename to src/plugins/data/common/search/aggs/utils/date_interval_utils/to_absolute_dates.ts index 98d752a72e28a..99809e06df38f 100644 --- a/src/plugins/data/common/search/aggs/date_interval_utils/to_absolute_dates.ts +++ b/src/plugins/data/common/search/aggs/utils/date_interval_utils/to_absolute_dates.ts @@ -18,7 +18,7 @@ */ import dateMath from '@elastic/datemath'; -import { TimeRange } from '../../../../common'; +import { TimeRange } from '../../../../../common'; export function toAbsoluteDates(range: TimeRange) { const fromDate = dateMath.parse(range.from); diff --git a/src/plugins/data/public/search/aggs/utils/get_format_with_aggs.test.ts b/src/plugins/data/common/search/aggs/utils/get_format_with_aggs.test.ts similarity index 95% rename from src/plugins/data/public/search/aggs/utils/get_format_with_aggs.test.ts rename to src/plugins/data/common/search/aggs/utils/get_format_with_aggs.test.ts index 3b440bc50c93b..20d8cfc105e49 100644 --- a/src/plugins/data/public/search/aggs/utils/get_format_with_aggs.test.ts +++ b/src/plugins/data/common/search/aggs/utils/get_format_with_aggs.test.ts @@ -19,9 +19,8 @@ import { identity } from 'lodash'; -import { SerializedFieldFormat } from '../../../../../expressions/common/types'; -import { FieldFormat } from '../../../../common'; -import { IFieldFormat } from '../../../../public'; +import { SerializedFieldFormat } from 'src/plugins/expressions/common/types'; +import { FieldFormat, IFieldFormat } from '../../../../common'; import { getFormatWithAggs } from './get_format_with_aggs'; diff --git a/src/plugins/data/public/search/aggs/utils/get_format_with_aggs.ts b/src/plugins/data/common/search/aggs/utils/get_format_with_aggs.ts similarity index 95% rename from src/plugins/data/public/search/aggs/utils/get_format_with_aggs.ts rename to src/plugins/data/common/search/aggs/utils/get_format_with_aggs.ts index e0db249c7cf86..01369206ab3cf 100644 --- a/src/plugins/data/public/search/aggs/utils/get_format_with_aggs.ts +++ b/src/plugins/data/common/search/aggs/utils/get_format_with_aggs.ts @@ -19,9 +19,12 @@ import { i18n } from '@kbn/i18n'; -import { SerializedFieldFormat } from '../../../../../expressions/common/types'; -import { FieldFormat } from '../../../../common'; -import { FieldFormatsContentType, IFieldFormat } from '../../../../public'; +import { SerializedFieldFormat } from 'src/plugins/expressions/common/types'; +import { + FieldFormat, + FieldFormatsContentType, + IFieldFormat, +} from '../../../../common/field_formats'; import { convertDateRangeToString, DateRangeKey } from '../buckets/lib/date_range'; import { convertIPRangeToString, IpRangeKey } from '../buckets/lib/ip_range'; diff --git a/src/plugins/data/public/search/aggs/utils/get_parsed_value.ts b/src/plugins/data/common/search/aggs/utils/get_parsed_value.ts similarity index 100% rename from src/plugins/data/public/search/aggs/utils/get_parsed_value.ts rename to src/plugins/data/common/search/aggs/utils/get_parsed_value.ts diff --git a/src/plugins/data/public/search/aggs/utils/index.ts b/src/plugins/data/common/search/aggs/utils/index.ts similarity index 93% rename from src/plugins/data/public/search/aggs/utils/index.ts rename to src/plugins/data/common/search/aggs/utils/index.ts index 5a889ee9ead9d..99ce44207d80d 100644 --- a/src/plugins/data/public/search/aggs/utils/index.ts +++ b/src/plugins/data/common/search/aggs/utils/index.ts @@ -18,6 +18,8 @@ */ export * from './calculate_auto_time_expression'; +export * from './date_interval_utils'; export * from './get_format_with_aggs'; +export * from './ipv4_address'; export * from './prop_filter'; export * from './to_angular_json'; diff --git a/src/plugins/data/common/search/aggs/ipv4_address.test.ts b/src/plugins/data/common/search/aggs/utils/ipv4_address.test.ts similarity index 100% rename from src/plugins/data/common/search/aggs/ipv4_address.test.ts rename to src/plugins/data/common/search/aggs/utils/ipv4_address.test.ts diff --git a/src/plugins/data/common/search/aggs/ipv4_address.ts b/src/plugins/data/common/search/aggs/utils/ipv4_address.ts similarity index 100% rename from src/plugins/data/common/search/aggs/ipv4_address.ts rename to src/plugins/data/common/search/aggs/utils/ipv4_address.ts diff --git a/src/plugins/data/public/search/aggs/utils/prop_filter.test.ts b/src/plugins/data/common/search/aggs/utils/prop_filter.test.ts similarity index 100% rename from src/plugins/data/public/search/aggs/utils/prop_filter.test.ts rename to src/plugins/data/common/search/aggs/utils/prop_filter.test.ts diff --git a/src/plugins/data/public/search/aggs/utils/prop_filter.ts b/src/plugins/data/common/search/aggs/utils/prop_filter.ts similarity index 100% rename from src/plugins/data/public/search/aggs/utils/prop_filter.ts rename to src/plugins/data/common/search/aggs/utils/prop_filter.ts diff --git a/src/plugins/data/public/search/aggs/utils/to_angular_json.ts b/src/plugins/data/common/search/aggs/utils/to_angular_json.ts similarity index 100% rename from src/plugins/data/public/search/aggs/utils/to_angular_json.ts rename to src/plugins/data/common/search/aggs/utils/to_angular_json.ts diff --git a/src/plugins/data/common/search/expressions/index.ts b/src/plugins/data/common/search/expressions/index.ts index f1a39a8383629..25839a805d8c5 100644 --- a/src/plugins/data/common/search/expressions/index.ts +++ b/src/plugins/data/common/search/expressions/index.ts @@ -18,3 +18,4 @@ */ export * from './esaggs'; +export * from './utils'; diff --git a/src/plugins/data/public/search/expressions/utils/courier_inspector_stats.ts b/src/plugins/data/common/search/expressions/utils/courier_inspector_stats.ts similarity index 98% rename from src/plugins/data/public/search/expressions/utils/courier_inspector_stats.ts rename to src/plugins/data/common/search/expressions/utils/courier_inspector_stats.ts index c933e8cd3e961..d41f02d2728d5 100644 --- a/src/plugins/data/public/search/expressions/utils/courier_inspector_stats.ts +++ b/src/plugins/data/common/search/expressions/utils/courier_inspector_stats.ts @@ -26,8 +26,8 @@ import { i18n } from '@kbn/i18n'; import { SearchResponse } from 'elasticsearch'; +import { ISearchSource } from 'src/plugins/data/public'; import { RequestStatistics } from 'src/plugins/inspector/common'; -import { ISearchSource } from '../../search_source'; /** @public */ export function getRequestInspectorStats(searchSource: ISearchSource) { diff --git a/src/plugins/data/common/search/expressions/utils/index.ts b/src/plugins/data/common/search/expressions/utils/index.ts new file mode 100644 index 0000000000000..75c1809770c78 --- /dev/null +++ b/src/plugins/data/common/search/expressions/utils/index.ts @@ -0,0 +1,20 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export * from './courier_inspector_stats'; diff --git a/src/plugins/data/common/search/index.ts b/src/plugins/data/common/search/index.ts index 45daf16d10c6d..557ab64079d16 100644 --- a/src/plugins/data/common/search/index.ts +++ b/src/plugins/data/common/search/index.ts @@ -17,10 +17,13 @@ * under the License. */ -import { ES_SEARCH_STRATEGY } from './es_search'; - -export { IKibanaSearchResponse, IKibanaSearchRequest } from './types'; +export * from './aggs'; +export * from './es_search'; +export * from './expressions'; +export * from './tabify'; +export * from './types'; +import { ES_SEARCH_STRATEGY } from './es_search'; export const DEFAULT_SEARCH_STRATEGY = ES_SEARCH_STRATEGY; export { diff --git a/src/plugins/data/public/search/tabify/buckets.test.ts b/src/plugins/data/common/search/tabify/buckets.test.ts similarity index 100% rename from src/plugins/data/public/search/tabify/buckets.test.ts rename to src/plugins/data/common/search/tabify/buckets.test.ts diff --git a/src/plugins/data/public/search/tabify/buckets.ts b/src/plugins/data/common/search/tabify/buckets.ts similarity index 100% rename from src/plugins/data/public/search/tabify/buckets.ts rename to src/plugins/data/common/search/tabify/buckets.ts diff --git a/src/plugins/data/public/search/tabify/get_columns.test.ts b/src/plugins/data/common/search/tabify/get_columns.test.ts similarity index 100% rename from src/plugins/data/public/search/tabify/get_columns.test.ts rename to src/plugins/data/common/search/tabify/get_columns.test.ts diff --git a/src/plugins/data/public/search/tabify/get_columns.ts b/src/plugins/data/common/search/tabify/get_columns.ts similarity index 100% rename from src/plugins/data/public/search/tabify/get_columns.ts rename to src/plugins/data/common/search/tabify/get_columns.ts diff --git a/src/plugins/data/public/search/tabify/index.ts b/src/plugins/data/common/search/tabify/index.ts similarity index 100% rename from src/plugins/data/public/search/tabify/index.ts rename to src/plugins/data/common/search/tabify/index.ts diff --git a/src/plugins/data/public/search/tabify/response_writer.test.ts b/src/plugins/data/common/search/tabify/response_writer.test.ts similarity index 100% rename from src/plugins/data/public/search/tabify/response_writer.test.ts rename to src/plugins/data/common/search/tabify/response_writer.test.ts diff --git a/src/plugins/data/public/search/tabify/response_writer.ts b/src/plugins/data/common/search/tabify/response_writer.ts similarity index 100% rename from src/plugins/data/public/search/tabify/response_writer.ts rename to src/plugins/data/common/search/tabify/response_writer.ts diff --git a/src/plugins/data/public/search/tabify/tabify.test.ts b/src/plugins/data/common/search/tabify/tabify.test.ts similarity index 98% rename from src/plugins/data/public/search/tabify/tabify.test.ts rename to src/plugins/data/common/search/tabify/tabify.test.ts index 0a1e99c8bb200..6b9d520b11436 100644 --- a/src/plugins/data/public/search/tabify/tabify.test.ts +++ b/src/plugins/data/common/search/tabify/tabify.test.ts @@ -18,7 +18,7 @@ */ import { tabifyAggResponse } from './tabify'; -import { IndexPattern } from '../../index_patterns'; +import { IndexPattern } from '../../index_patterns/index_patterns/index_pattern'; import { AggConfigs, IAggConfig, IAggConfigs } from '../aggs'; import { mockAggTypesRegistry } from '../aggs/test_helpers'; import { metricOnly, threeTermBuckets } from 'fixtures/fake_hierarchical_data'; diff --git a/src/plugins/data/public/search/tabify/tabify.ts b/src/plugins/data/common/search/tabify/tabify.ts similarity index 100% rename from src/plugins/data/public/search/tabify/tabify.ts rename to src/plugins/data/common/search/tabify/tabify.ts diff --git a/src/plugins/data/public/search/tabify/types.ts b/src/plugins/data/common/search/tabify/types.ts similarity index 100% rename from src/plugins/data/public/search/tabify/types.ts rename to src/plugins/data/common/search/tabify/types.ts diff --git a/src/plugins/data/public/field_formats/utils/deserialize.ts b/src/plugins/data/public/field_formats/utils/deserialize.ts index 26baa5fdeb1e4..7595a443bf8f0 100644 --- a/src/plugins/data/public/field_formats/utils/deserialize.ts +++ b/src/plugins/data/public/field_formats/utils/deserialize.ts @@ -23,9 +23,9 @@ import { SerializedFieldFormat } from '../../../../expressions/common/types'; import { FieldFormat } from '../../../common'; import { FormatFactory } from '../../../common/field_formats/utils'; +import { getFormatWithAggs } from '../../../common/search/aggs'; import { DataPublicPluginStart, IFieldFormat } from '../../../public'; import { getUiSettings } from '../../../public/services'; -import { getFormatWithAggs } from '../../search/aggs/utils'; const getConfig = (key: string, defaultOverride?: any): any => getUiSettings().get(key, defaultOverride); diff --git a/src/plugins/data/public/index.ts b/src/plugins/data/public/index.ts index f036d5f30a0e2..d35069207ee84 100644 --- a/src/plugins/data/public/index.ts +++ b/src/plugins/data/public/index.ts @@ -294,15 +294,6 @@ import { propFilter, siblingPipelineType, termsAggFilter, - // expressions utils - getRequestInspectorStats, - getResponseInspectorStats, - // tabify - tabifyAggResponse, - tabifyGetColumns, -} from './search'; - -import { dateHistogramInterval, InvalidEsCalendarIntervalError, InvalidEsIntervalFormatError, @@ -312,10 +303,14 @@ import { parseEsInterval, parseInterval, toAbsoluteDates, + // expressions utils + getRequestInspectorStats, + getResponseInspectorStats, + // tabify + tabifyAggResponse, + tabifyGetColumns, } from '../common'; -export { EsaggsExpressionFunctionDefinition, ParsedInterval } from '../common'; - export { // aggs AggGroupLabels, @@ -326,6 +321,7 @@ export { AggParamType, AggConfigOptions, BUCKET_TYPES, + EsaggsExpressionFunctionDefinition, IAggConfig, IAggConfigs, IAggType, @@ -334,35 +330,39 @@ export { METRIC_TYPES, OptionedParamType, OptionedValueProp, + ParsedInterval, + // tabify + TabbedAggColumn, + TabbedAggRow, + TabbedTable, +} from '../common'; + +export { // search ES_SEARCH_STRATEGY, + EsQuerySortValue, + extractSearchSourceReferences, + FetchOptions, getEsPreference, - ISearch, - ISearchOptions, - ISearchGeneric, - IEsSearchResponse, + getSearchParamsFromRequest, IEsSearchRequest, - IKibanaSearchResponse, + IEsSearchResponse, IKibanaSearchRequest, - SearchRequest, - SearchResponse, - SearchError, + IKibanaSearchResponse, + injectSearchSourceReferences, + ISearch, + ISearchGeneric, + ISearchOptions, ISearchSource, parseSearchSourceJSON, - injectSearchSourceReferences, - getSearchParamsFromRequest, - extractSearchSourceReferences, - SearchSourceFields, - EsQuerySortValue, - SortDirection, - FetchOptions, - // tabify - TabbedAggColumn, - TabbedAggRow, - TabbedTable, + RequestTimeoutError, + SearchError, SearchInterceptor, SearchInterceptorDeps, - RequestTimeoutError, + SearchRequest, + SearchResponse, + SearchSourceFields, + SortDirection, } from './search'; // Search namespace diff --git a/src/plugins/data/public/mocks.ts b/src/plugins/data/public/mocks.ts index 3fc1e6454829d..78e40cfedd906 100644 --- a/src/plugins/data/public/mocks.ts +++ b/src/plugins/data/public/mocks.ts @@ -79,7 +79,7 @@ const createStartContract = (): Start => { }; export { createSearchSourceMock } from './search/mocks'; -export { getCalculateAutoTimeExpression } from './search/aggs'; +export { getCalculateAutoTimeExpression } from '../common/search/aggs'; export const dataPluginMock = { createSetupContract, diff --git a/src/plugins/data/public/plugin.ts b/src/plugins/data/public/plugin.ts index 2ef90c598007b..541f5b19db629 100644 --- a/src/plugins/data/public/plugin.ts +++ b/src/plugins/data/public/plugin.ts @@ -33,7 +33,6 @@ import { DataPublicPluginStart, DataSetupDependencies, DataStartDependencies, - InternalStartServices, DataPublicPluginEnhancements, } from './types'; import { AutocompleteService } from './autocomplete'; @@ -121,17 +120,6 @@ export class DataPublicPlugin ): DataPublicPluginSetup { const startServices = createStartServicesGetter(core.getStartServices); - const getInternalStartServices = (): InternalStartServices => { - const { core: coreStart, self } = startServices(); - return { - fieldFormats: self.fieldFormats, - notifications: coreStart.notifications, - uiSettings: coreStart.uiSettings, - searchService: self.search, - injectedMetadata: coreStart.injectedMetadata, - }; - }; - expressions.registerFunction(esaggs); expressions.registerFunction(indexPatternLoad); @@ -159,10 +147,9 @@ export class DataPublicPlugin ); const searchService = this.searchService.setup(core, { - expressions, usageCollection, - getInternalStartServices, packageInfo: this.packageInfo, + registerFunction: expressions.registerFunction, }); return { @@ -215,7 +202,7 @@ export class DataPublicPlugin }); setQueryService(query); - const search = this.searchService.start(core, { indexPatterns }); + const search = this.searchService.start(core, { fieldFormats, indexPatterns }); setSearchService(search); uiActions.addTriggerAction( @@ -252,5 +239,7 @@ export class DataPublicPlugin public stop() { this.autocomplete.clearProviders(); + this.queryService.stop(); + this.searchService.stop(); } } diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index 8ec45bc26913c..69af3e1f61a1d 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -26,10 +26,12 @@ import { EuiGlobalToastListToast } from '@elastic/eui'; import { ExclusiveUnion } from '@elastic/eui'; import { ExpressionAstFunction } from 'src/plugins/expressions/common'; import { ExpressionsSetup } from 'src/plugins/expressions/public'; +import { FetchOptions as FetchOptions_2 } from 'src/plugins/data/public'; import { History } from 'history'; import { Href } from 'history'; import { IconType } from '@elastic/eui'; import { InjectedIntl } from '@kbn/i18n/react'; +import { ISearchSource as ISearchSource_2 } from 'src/plugins/data/public'; import { IStorageWrapper } from 'src/plugins/kibana_utils/public'; import { IUiSettingsClient } from 'src/core/public'; import { IUiSettingsClient as IUiSettingsClient_3 } from 'kibana/public'; @@ -153,12 +155,12 @@ export interface ApplyGlobalFilterActionContext { timeFieldName?: string; } -// Warning: (ae-forgotten-export) The symbol "DateNanosFormat" needs to be exported by the entry point index.d.ts // Warning: (ae-forgotten-export) The symbol "DateFormat" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DateNanosFormat" needs to be exported by the entry point index.d.ts // Warning: (ae-missing-release-tag) "baseFormattersPublic" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export const baseFormattersPublic: (import("../../common").FieldFormatInstanceType | typeof DateNanosFormat | typeof DateFormat)[]; +export const baseFormattersPublic: (import("../../common").FieldFormatInstanceType | typeof DateFormat | typeof DateNanosFormat)[]; // Warning: (ae-missing-release-tag) "BUCKET_TYPES" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -1663,7 +1665,7 @@ export const search: { intervalOptions: ({ display: string; val: string; - enabled(agg: import("./search/aggs/buckets/bucket_agg_type").IBucketAggConfig): boolean | "" | undefined; + enabled(agg: import("../common").IBucketAggConfig): boolean | "" | undefined; } | { display: string; val: string; @@ -1672,9 +1674,9 @@ export const search: { InvalidEsIntervalFormatError: typeof InvalidEsIntervalFormatError; Ipv4Address: typeof Ipv4Address; isDateHistogramBucketAggConfig: typeof isDateHistogramBucketAggConfig; - isNumberType: (agg: import("./search").AggConfig) => boolean; - isStringType: (agg: import("./search").AggConfig) => boolean; - isType: (...types: string[]) => (agg: import("./search").AggConfig) => boolean; + isNumberType: (agg: import("../common").AggConfig) => boolean; + isStringType: (agg: import("../common").AggConfig) => boolean; + isType: (...types: string[]) => (agg: import("../common").AggConfig) => boolean; isValidEsInterval: typeof isValidEsInterval; isValidInterval: typeof isValidInterval; parentPipelineType: string; diff --git a/src/plugins/data/public/search/aggs/aggs_service.test.ts b/src/plugins/data/public/search/aggs/aggs_service.test.ts new file mode 100644 index 0000000000000..db25dfb300d11 --- /dev/null +++ b/src/plugins/data/public/search/aggs/aggs_service.test.ts @@ -0,0 +1,182 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { BehaviorSubject, Subscription } from 'rxjs'; + +import { coreMock } from '../../../../../core/public/mocks'; +import { expressionsPluginMock } from '../../../../../plugins/expressions/public/mocks'; +import { BucketAggType, getAggTypes, MetricAggType } from '../../../common'; +import { fieldFormatsServiceMock } from '../../field_formats/mocks'; + +import { + AggsService, + AggsSetupDependencies, + AggsStartDependencies, + createGetConfig, +} from './aggs_service'; + +const { uiSettings } = coreMock.createSetup(); + +describe('AggsService - public', () => { + let service: AggsService; + let setupDeps: AggsSetupDependencies; + let startDeps: AggsStartDependencies; + + beforeEach(() => { + service = new AggsService(); + setupDeps = { + registerFunction: expressionsPluginMock.createSetupContract().registerFunction, + uiSettings, + }; + startDeps = { + fieldFormats: fieldFormatsServiceMock.createStartContract(), + uiSettings, + }; + }); + + describe('setup()', () => { + test('exposes proper contract', () => { + const setup = service.setup(setupDeps); + expect(Object.keys(setup).length).toBe(1); + expect(setup).toHaveProperty('types'); + }); + + test('registers default agg types', () => { + service.setup(setupDeps); + const start = service.start(startDeps); + expect(start.types.getAll().buckets.length).toBe(11); + expect(start.types.getAll().metrics.length).toBe(21); + }); + + test('registers custom agg types', () => { + const setup = service.setup(setupDeps); + setup.types.registerBucket( + 'foo', + () => ({ name: 'foo', type: 'buckets' } as BucketAggType) + ); + setup.types.registerMetric( + 'bar', + () => ({ name: 'bar', type: 'metrics' } as MetricAggType) + ); + + const start = service.start(startDeps); + expect(start.types.getAll().buckets.length).toBe(12); + expect(start.types.getAll().buckets.some(({ name }) => name === 'foo')).toBe(true); + expect(start.types.getAll().metrics.length).toBe(22); + expect(start.types.getAll().metrics.some(({ name }) => name === 'bar')).toBe(true); + }); + }); + + describe('start()', () => { + test('exposes proper contract', () => { + const start = service.start(startDeps); + expect(Object.keys(start).length).toBe(3); + expect(start).toHaveProperty('calculateAutoTimeExpression'); + expect(start).toHaveProperty('createAggConfigs'); + expect(start).toHaveProperty('types'); + }); + + test('types registry returns initialized agg types', () => { + service.setup(setupDeps); + const start = service.start(startDeps); + + expect(start.types.get('terms').name).toBe('terms'); + }); + + test('registers default agg types', () => { + service.setup(setupDeps); + const start = service.start(startDeps); + + const aggTypes = getAggTypes(); + expect(start.types.getAll().buckets.length).toBe(aggTypes.buckets.length); + expect(start.types.getAll().metrics.length).toBe(aggTypes.metrics.length); + }); + + test('merges default agg types with types registered during setup', () => { + const setup = service.setup(setupDeps); + setup.types.registerBucket( + 'foo', + () => ({ name: 'foo', type: 'buckets' } as BucketAggType) + ); + setup.types.registerMetric( + 'bar', + () => ({ name: 'bar', type: 'metrics' } as MetricAggType) + ); + + const start = service.start(startDeps); + + const aggTypes = getAggTypes(); + expect(start.types.getAll().buckets.length).toBe(aggTypes.buckets.length + 1); + expect(start.types.getAll().buckets.some(({ name }) => name === 'foo')).toBe(true); + expect(start.types.getAll().metrics.length).toBe(aggTypes.metrics.length + 1); + expect(start.types.getAll().metrics.some(({ name }) => name === 'bar')).toBe(true); + }); + }); + + describe('createGetConfig()', () => { + let fooSubject$: BehaviorSubject; + let barSubject$: BehaviorSubject; + + beforeEach(() => { + jest.clearAllMocks(); + + fooSubject$ = new BehaviorSubject('fooVal'); + barSubject$ = new BehaviorSubject('barVal'); + + uiSettings.get$.mockImplementation((key: string) => { + const mockSettings: Record = { + foo: () => fooSubject$, + bar: () => barSubject$, + }; + return mockSettings[key] ? mockSettings[key]() : undefined; + }); + }); + + test('returns a function to get the value of the provided setting', () => { + const requiredSettings = ['foo', 'bar']; + const subscriptions: Subscription[] = []; + const getConfig = createGetConfig(uiSettings, requiredSettings, subscriptions); + + expect(getConfig('foo')).toBe('fooVal'); + expect(getConfig('bar')).toBe('barVal'); + }); + + test('does not return values for settings that are not explicitly declared', () => { + const requiredSettings = ['foo', 'bar']; + const subscriptions: Subscription[] = []; + const getConfig = createGetConfig(uiSettings, requiredSettings, subscriptions); + + expect(subscriptions.length).toBe(2); + expect(getConfig('baz')).toBe(undefined); + }); + + test('provides latest value for each setting', () => { + const requiredSettings = ['foo', 'bar']; + const subscriptions: Subscription[] = []; + const getConfig = createGetConfig(uiSettings, requiredSettings, subscriptions); + + expect(getConfig('foo')).toBe('fooVal'); + fooSubject$.next('fooVal2'); + expect(getConfig('foo')).toBe('fooVal2'); + expect(getConfig('foo')).toBe('fooVal2'); + fooSubject$.next('fooVal3'); + expect(getConfig('foo')).toBe('fooVal3'); + }); + }); +}); diff --git a/src/plugins/data/public/search/aggs/aggs_service.ts b/src/plugins/data/public/search/aggs/aggs_service.ts new file mode 100644 index 0000000000000..d535f97fefdf8 --- /dev/null +++ b/src/plugins/data/public/search/aggs/aggs_service.ts @@ -0,0 +1,152 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { Subscription } from 'rxjs'; + +import { IUiSettingsClient } from 'src/core/public'; +import { ExpressionsServiceSetup } from 'src/plugins/expressions/common'; +import { + aggsRequiredUiSettings, + AggsCommonStartDependencies, + AggsCommonService, + AggConfigs, + AggTypesDependencies, + calculateBounds, + TimeRange, +} from '../../../common'; +import { FieldFormatsStart } from '../../field_formats'; +import { getForceNow } from '../../query/timefilter/lib/get_force_now'; +import { AggsSetup, AggsStart } from './types'; + +/** + * Aggs needs synchronous access to specific uiSettings. Since settings can change + * without a page refresh, we create a cache that subscribes to changes from + * uiSettings.get$ and keeps everything up-to-date. + * + * @internal + */ +export function createGetConfig( + uiSettings: IUiSettingsClient, + requiredSettings: string[], + subscriptions: Subscription[] +): AggsCommonStartDependencies['getConfig'] { + const settingsCache: Record = {}; + + requiredSettings.forEach((setting) => { + subscriptions.push( + uiSettings.get$(setting).subscribe((value) => { + settingsCache[setting] = value; + }) + ); + }); + + return (key) => settingsCache[key]; +} + +/** @internal */ +export interface AggsSetupDependencies { + registerFunction: ExpressionsServiceSetup['registerFunction']; + uiSettings: IUiSettingsClient; +} + +/** @internal */ +export interface AggsStartDependencies { + fieldFormats: FieldFormatsStart; + uiSettings: IUiSettingsClient; +} + +/** + * The aggs service provides a means of modeling and manipulating the various + * Elasticsearch aggregations supported by Kibana, providing the ability to + * output the correct DSL when you are ready to send your request to ES. + */ +export class AggsService { + private readonly aggsCommonService = new AggsCommonService(); + private readonly initializedAggTypes = new Map(); + private getConfig?: AggsCommonStartDependencies['getConfig']; + private subscriptions: Subscription[] = []; + + /** + * getForceNow uses window.location, so we must have a separate implementation + * of calculateBounds on the client and the server. + */ + private calculateBounds = (timeRange: TimeRange) => + calculateBounds(timeRange, { forceNow: getForceNow() }); + + public setup({ registerFunction, uiSettings }: AggsSetupDependencies): AggsSetup { + this.getConfig = createGetConfig(uiSettings, aggsRequiredUiSettings, this.subscriptions); + + return this.aggsCommonService.setup({ registerFunction }); + } + + public start({ fieldFormats, uiSettings }: AggsStartDependencies): AggsStart { + const { calculateAutoTimeExpression, types } = this.aggsCommonService.start({ + getConfig: this.getConfig!, + }); + + const aggTypesDependencies: AggTypesDependencies = { + calculateBounds: this.calculateBounds, + getConfig: this.getConfig!, + getFieldFormatsStart: () => ({ + deserialize: fieldFormats.deserialize, + getDefaultInstance: fieldFormats.getDefaultInstance, + }), + isDefaultTimezone: () => uiSettings.isDefault('dateFormat:tz'), + }; + + // initialize each agg type and store in memory + types.getAll().buckets.forEach((type) => { + const agg = type(aggTypesDependencies); + this.initializedAggTypes.set(agg.name, agg); + }); + types.getAll().metrics.forEach((type) => { + const agg = type(aggTypesDependencies); + this.initializedAggTypes.set(agg.name, agg); + }); + + const typesRegistry = { + get: (name: string) => { + return this.initializedAggTypes.get(name); + }, + getAll: () => { + return { + buckets: Array.from(this.initializedAggTypes.values()).filter( + (agg) => agg.type === 'buckets' + ), + metrics: Array.from(this.initializedAggTypes.values()).filter( + (agg) => agg.type === 'metrics' + ), + }; + }, + }; + + return { + calculateAutoTimeExpression, + createAggConfigs: (indexPattern, configStates = [], schemas) => { + return new AggConfigs(indexPattern, configStates, { typesRegistry }); + }, + types: typesRegistry, + }; + } + + public stop() { + this.subscriptions.forEach((s) => s.unsubscribe()); + this.subscriptions = []; + } +} diff --git a/src/plugins/data/public/search/aggs/index.ts b/src/plugins/data/public/search/aggs/index.ts index 1139d9c7ff722..77d97c426260c 100644 --- a/src/plugins/data/public/search/aggs/index.ts +++ b/src/plugins/data/public/search/aggs/index.ts @@ -17,14 +17,5 @@ * under the License. */ -export * from './agg_config'; -export * from './agg_configs'; -export * from './agg_groups'; -export * from './agg_type'; -export * from './agg_types'; -export * from './agg_types_registry'; -export * from './buckets'; -export * from './metrics'; -export * from './param_types'; +export * from './aggs_service'; export * from './types'; -export * from './utils'; diff --git a/src/plugins/data/public/search/aggs/mocks.ts b/src/plugins/data/public/search/aggs/mocks.ts index 2cad646067292..ca13343777e63 100644 --- a/src/plugins/data/public/search/aggs/mocks.ts +++ b/src/plugins/data/public/search/aggs/mocks.ts @@ -17,15 +17,17 @@ * under the License. */ -import { coreMock } from '../../../../../../src/core/public/mocks'; import { AggConfigs, AggTypesRegistrySetup, AggTypesRegistryStart, getCalculateAutoTimeExpression, -} from './'; -import { SearchAggsSetup, SearchAggsStart } from './types'; -import { mockAggTypesRegistry } from './test_helpers'; +} from '../../../common'; +import { AggsSetup, AggsStart } from './types'; + +import { mockAggTypesRegistry } from '../../../common/search/aggs/test_helpers'; + +const getConfig = jest.fn(); const aggTypeBaseParamMock = () => ({ name: 'some_param', @@ -53,21 +55,18 @@ export const aggTypesRegistrySetupMock = (): AggTypesRegistrySetup => ({ export const aggTypesRegistryStartMock = (): AggTypesRegistryStart => ({ get: jest.fn().mockImplementation(aggTypeConfigMock), - getBuckets: jest.fn().mockImplementation(() => [aggTypeConfigMock()]), - getMetrics: jest.fn().mockImplementation(() => [aggTypeConfigMock()]), getAll: jest.fn().mockImplementation(() => ({ buckets: [aggTypeConfigMock()], metrics: [aggTypeConfigMock()], })), }); -export const searchAggsSetupMock = (): SearchAggsSetup => ({ - calculateAutoTimeExpression: getCalculateAutoTimeExpression(coreMock.createSetup().uiSettings), +export const searchAggsSetupMock = (): AggsSetup => ({ types: aggTypesRegistrySetupMock(), }); -export const searchAggsStartMock = (): SearchAggsStart => ({ - calculateAutoTimeExpression: getCalculateAutoTimeExpression(coreMock.createStart().uiSettings), +export const searchAggsStartMock = (): AggsStart => ({ + calculateAutoTimeExpression: getCalculateAutoTimeExpression(getConfig), createAggConfigs: jest.fn().mockImplementation((indexPattern, configStates = [], schemas) => { return new AggConfigs(indexPattern, configStates, { typesRegistry: mockAggTypesRegistry(), diff --git a/src/plugins/data/public/search/aggs/types.ts b/src/plugins/data/public/search/aggs/types.ts index a784bfaada4c7..38be541973ce9 100644 --- a/src/plugins/data/public/search/aggs/types.ts +++ b/src/plugins/data/public/search/aggs/types.ts @@ -17,131 +17,7 @@ * under the License. */ -import { IndexPattern } from '../../index_patterns'; -import { - AggConfigSerialized, - AggConfigs, - AggParamsRange, - AggParamsIpRange, - AggParamsDateRange, - AggParamsFilter, - AggParamsFilters, - AggParamsSignificantTerms, - AggParamsGeoTile, - AggParamsGeoHash, - AggParamsTerms, - AggParamsAvg, - AggParamsCardinality, - AggParamsGeoBounds, - AggParamsGeoCentroid, - AggParamsMax, - AggParamsMedian, - AggParamsMin, - AggParamsStdDeviation, - AggParamsSum, - AggParamsBucketAvg, - AggParamsBucketMax, - AggParamsBucketMin, - AggParamsBucketSum, - AggParamsCumulativeSum, - AggParamsDerivative, - AggParamsMovingAvg, - AggParamsPercentileRanks, - AggParamsPercentiles, - AggParamsSerialDiff, - AggParamsTopHit, - AggParamsHistogram, - AggParamsDateHistogram, - AggTypesRegistrySetup, - AggTypesRegistryStart, - CreateAggConfigParams, - getCalculateAutoTimeExpression, - METRIC_TYPES, - BUCKET_TYPES, -} from './'; +import { AggsCommonSetup } from '../../../common'; -export { IAggConfig, AggConfigSerialized } from './agg_config'; -export { CreateAggConfigParams, IAggConfigs } from './agg_configs'; -export { IAggType } from './agg_type'; -export { AggParam, AggParamOption } from './agg_params'; -export { IFieldParamType } from './param_types'; -export { IMetricAggType } from './metrics/metric_agg_type'; -export { DateRangeKey } from './buckets/lib/date_range'; -export { IpRangeKey } from './buckets/lib/ip_range'; -export { OptionedValueProp } from './param_types/optioned'; - -/** @internal */ -export interface SearchAggsSetup { - calculateAutoTimeExpression: ReturnType; - types: AggTypesRegistrySetup; -} - -/** @internal */ -export interface SearchAggsStart { - calculateAutoTimeExpression: ReturnType; - createAggConfigs: ( - indexPattern: IndexPattern, - configStates?: CreateAggConfigParams[], - schemas?: Record - ) => InstanceType; - types: AggTypesRegistryStart; -} - -/** @internal */ -export interface BaseAggParams { - json?: string; - customLabel?: string; -} - -/** @internal */ -export interface AggExpressionType { - type: 'agg_type'; - value: AggConfigSerialized; -} - -/** @internal */ -export type AggExpressionFunctionArgs< - Name extends keyof AggParamsMapping -> = AggParamsMapping[Name] & Pick; - -/** - * A global list of the param interfaces for each agg type. - * For now this is internal, but eventually we will probably - * want to make it public. - * - * @internal - */ -export interface AggParamsMapping { - [BUCKET_TYPES.RANGE]: AggParamsRange; - [BUCKET_TYPES.IP_RANGE]: AggParamsIpRange; - [BUCKET_TYPES.DATE_RANGE]: AggParamsDateRange; - [BUCKET_TYPES.FILTER]: AggParamsFilter; - [BUCKET_TYPES.FILTERS]: AggParamsFilters; - [BUCKET_TYPES.SIGNIFICANT_TERMS]: AggParamsSignificantTerms; - [BUCKET_TYPES.GEOTILE_GRID]: AggParamsGeoTile; - [BUCKET_TYPES.GEOHASH_GRID]: AggParamsGeoHash; - [BUCKET_TYPES.HISTOGRAM]: AggParamsHistogram; - [BUCKET_TYPES.DATE_HISTOGRAM]: AggParamsDateHistogram; - [BUCKET_TYPES.TERMS]: AggParamsTerms; - [METRIC_TYPES.AVG]: AggParamsAvg; - [METRIC_TYPES.CARDINALITY]: AggParamsCardinality; - [METRIC_TYPES.COUNT]: BaseAggParams; - [METRIC_TYPES.GEO_BOUNDS]: AggParamsGeoBounds; - [METRIC_TYPES.GEO_CENTROID]: AggParamsGeoCentroid; - [METRIC_TYPES.MAX]: AggParamsMax; - [METRIC_TYPES.MEDIAN]: AggParamsMedian; - [METRIC_TYPES.MIN]: AggParamsMin; - [METRIC_TYPES.STD_DEV]: AggParamsStdDeviation; - [METRIC_TYPES.SUM]: AggParamsSum; - [METRIC_TYPES.AVG_BUCKET]: AggParamsBucketAvg; - [METRIC_TYPES.MAX_BUCKET]: AggParamsBucketMax; - [METRIC_TYPES.MIN_BUCKET]: AggParamsBucketMin; - [METRIC_TYPES.SUM_BUCKET]: AggParamsBucketSum; - [METRIC_TYPES.CUMULATIVE_SUM]: AggParamsCumulativeSum; - [METRIC_TYPES.DERIVATIVE]: AggParamsDerivative; - [METRIC_TYPES.MOVING_FN]: AggParamsMovingAvg; - [METRIC_TYPES.PERCENTILE_RANKS]: AggParamsPercentileRanks; - [METRIC_TYPES.PERCENTILES]: AggParamsPercentiles; - [METRIC_TYPES.SERIAL_DIFF]: AggParamsSerialDiff; - [METRIC_TYPES.TOP_HITS]: AggParamsTopHit; -} +export type AggsSetup = AggsCommonSetup; +export { AggsStart } from '../../../common'; diff --git a/src/plugins/data/public/search/expressions/build_tabular_inspector_data.ts b/src/plugins/data/public/search/expressions/build_tabular_inspector_data.ts index 75a4464a8e61e..7eff6f25fd828 100644 --- a/src/plugins/data/public/search/expressions/build_tabular_inspector_data.ts +++ b/src/plugins/data/public/search/expressions/build_tabular_inspector_data.ts @@ -19,8 +19,8 @@ import { set } from '@elastic/safer-lodash-set'; import { FormattedData } from '../../../../../plugins/inspector/public'; +import { TabbedTable } from '../../../common'; import { FormatFactory } from '../../../common/field_formats/utils'; -import { TabbedTable } from '../tabify'; import { createFilter } from './create_filter'; /** diff --git a/src/plugins/data/public/search/expressions/create_filter.test.ts b/src/plugins/data/public/search/expressions/create_filter.test.ts index a7fd67983cb92..7968c80628531 100644 --- a/src/plugins/data/public/search/expressions/create_filter.test.ts +++ b/src/plugins/data/public/search/expressions/create_filter.test.ts @@ -17,11 +17,17 @@ * under the License. */ +import { + AggConfigs, + IAggConfig, + TabbedTable, + isRangeFilter, + BytesFormat, + FieldFormatsGetConfigFn, +} from '../../../common'; +import { mockAggTypesRegistry } from '../../../common/search/aggs/test_helpers'; + import { createFilter } from './create_filter'; -import { AggConfigs, IAggConfig } from '../aggs'; -import { TabbedTable } from '../tabify'; -import { isRangeFilter, BytesFormat, FieldFormatsGetConfigFn } from '../../../common'; -import { mockAggTypesRegistry } from '../aggs/test_helpers'; describe('createFilter', () => { let table: TabbedTable; diff --git a/src/plugins/data/public/search/expressions/create_filter.ts b/src/plugins/data/public/search/expressions/create_filter.ts index 94d84380e03df..09200c2e17b31 100644 --- a/src/plugins/data/public/search/expressions/create_filter.ts +++ b/src/plugins/data/public/search/expressions/create_filter.ts @@ -17,9 +17,7 @@ * under the License. */ -import { IAggConfig } from '../aggs'; -import { TabbedTable } from '../tabify'; -import { Filter } from '../../../common'; +import { Filter, IAggConfig, TabbedTable } from '../../../common'; const getOtherBucketFilterTerms = (table: TabbedTable, columnIndex: number, rowIndex: number) => { if (rowIndex === -1) { diff --git a/src/plugins/data/public/search/expressions/esaggs.ts b/src/plugins/data/public/search/expressions/esaggs.ts index 690f6b1df11c3..50fbb114b39fd 100644 --- a/src/plugins/data/public/search/expressions/esaggs.ts +++ b/src/plugins/data/public/search/expressions/esaggs.ts @@ -19,15 +19,11 @@ import { get, hasIn } from 'lodash'; import { i18n } from '@kbn/i18n'; - import { KibanaDatatable, KibanaDatatableColumn } from 'src/plugins/expressions/public'; import { calculateObjectHash } from '../../../../../plugins/kibana_utils/public'; import { PersistedState } from '../../../../../plugins/visualizations/public'; import { Adapters } from '../../../../../plugins/inspector/public'; -import { IAggConfigs } from '../aggs'; -import { ISearchSource } from '../search_source'; -import { tabifyAggResponse } from '../tabify'; import { calculateBounds, EsaggsExpressionFunctionDefinition, @@ -38,6 +34,13 @@ import { Query, TimeRange, } from '../../../common'; +import { + getRequestInspectorStats, + getResponseInspectorStats, + IAggConfigs, + tabifyAggResponse, +} from '../../../common/search'; + import { FilterManager } from '../../query'; import { getFieldFormats, @@ -45,8 +48,9 @@ import { getQueryService, getSearchService, } from '../../services'; +import { ISearchSource } from '../search_source'; import { buildTabularInspectorData } from './build_tabular_inspector_data'; -import { getRequestInspectorStats, getResponseInspectorStats, serializeAggConfig } from './utils'; +import { serializeAggConfig } from './utils'; export interface RequestHandlerParams { searchSource: ISearchSource; diff --git a/src/plugins/data/public/search/expressions/utils/index.ts b/src/plugins/data/public/search/expressions/utils/index.ts index 0fd51f3e158a6..094536fc18437 100644 --- a/src/plugins/data/public/search/expressions/utils/index.ts +++ b/src/plugins/data/public/search/expressions/utils/index.ts @@ -17,5 +17,4 @@ * under the License. */ -export * from './courier_inspector_stats'; export * from './serialize_agg_config'; diff --git a/src/plugins/data/public/search/expressions/utils/serialize_agg_config.ts b/src/plugins/data/public/search/expressions/utils/serialize_agg_config.ts index 78b4935077d10..6ba323b65783f 100644 --- a/src/plugins/data/public/search/expressions/utils/serialize_agg_config.ts +++ b/src/plugins/data/public/search/expressions/utils/serialize_agg_config.ts @@ -18,7 +18,7 @@ */ import { KibanaDatatableColumnMeta } from '../../../../../../plugins/expressions/public'; -import { IAggConfig } from '../../aggs'; +import { IAggConfig } from '../../../../common'; import { IndexPattern } from '../../../index_patterns'; import { getSearchService } from '../../../../public/services'; diff --git a/src/plugins/data/public/search/index.ts b/src/plugins/data/public/search/index.ts index ae028df31e401..32bcd8a279036 100644 --- a/src/plugins/data/public/search/index.ts +++ b/src/plugins/data/public/search/index.ts @@ -17,9 +17,7 @@ * under the License. */ -export * from './aggs'; export * from './expressions'; -export * from './tabify'; export { ISearch, diff --git a/src/plugins/data/public/search/search_service.test.ts b/src/plugins/data/public/search/search_service.test.ts index f0a017847e06a..e6897a16a353a 100644 --- a/src/plugins/data/public/search/search_service.test.ts +++ b/src/plugins/data/public/search/search_service.test.ts @@ -19,9 +19,8 @@ import { coreMock } from '../../../../core/public/mocks'; import { CoreSetup, CoreStart } from '../../../../core/public'; -import { expressionsPluginMock } from '../../../../plugins/expressions/public/mocks'; -import { SearchService } from './search_service'; +import { SearchService, SearchServiceSetupDependencies } from './search_service'; describe('Search service', () => { let searchService: SearchService; @@ -36,11 +35,12 @@ describe('Search service', () => { describe('setup()', () => { it('exposes proper contract', async () => { - const setup = searchService.setup(mockCoreSetup, { + const setup = searchService.setup(mockCoreSetup, ({ packageInfo: { version: '8' }, - expressions: expressionsPluginMock.createSetupContract(), - } as any); + registerFunction: jest.fn(), + } as unknown) as SearchServiceSetupDependencies); expect(setup).toHaveProperty('aggs'); + expect(setup).toHaveProperty('usageCollector'); expect(setup).toHaveProperty('__enhance'); }); }); @@ -50,6 +50,7 @@ describe('Search service', () => { const start = searchService.start(mockCoreStart, { indexPatterns: {}, } as any); + expect(start).toHaveProperty('aggs'); expect(start).toHaveProperty('search'); }); }); diff --git a/src/plugins/data/public/search/search_service.ts b/src/plugins/data/public/search/search_service.ts index 4c94925b66d6e..bd9c1b1253fe2 100644 --- a/src/plugins/data/public/search/search_service.ts +++ b/src/plugins/data/public/search/search_service.ts @@ -17,80 +17,43 @@ * under the License. */ -import { Plugin, CoreSetup, CoreStart, PackageInfo } from '../../../../core/public'; +import { Plugin, CoreSetup, CoreStart, PackageInfo } from 'src/core/public'; import { ISearchSetup, ISearchStart, SearchEnhancements } from './types'; -import { ExpressionsSetup } from '../../../../plugins/expressions/public'; import { createSearchSource, SearchSource, SearchSourceDependencies } from './search_source'; import { getEsClient, LegacyApiCaller } from './legacy'; -import { getForceNow } from '../query/timefilter/lib/get_force_now'; -import { calculateBounds, TimeRange } from '../../common/query'; - +import { AggsService, AggsSetupDependencies, AggsStartDependencies } from './aggs'; import { IndexPatternsContract } from '../index_patterns/index_patterns'; -import { GetInternalStartServicesFn } from '../types'; import { ISearchInterceptor, SearchInterceptor } from './search_interceptor'; -import { - getAggTypes, - getAggTypesFunctions, - AggTypesRegistry, - AggConfigs, - getCalculateAutoTimeExpression, -} from './aggs'; import { ISearchGeneric } from './types'; import { SearchUsageCollector, createUsageCollector } from './collectors'; import { UsageCollectionSetup } from '../../../usage_collection/public'; -interface SearchServiceSetupDependencies { - expressions: ExpressionsSetup; - usageCollection?: UsageCollectionSetup; - getInternalStartServices: GetInternalStartServicesFn; +/** @internal */ +export interface SearchServiceSetupDependencies { packageInfo: PackageInfo; + registerFunction: AggsSetupDependencies['registerFunction']; + usageCollection?: UsageCollectionSetup; } -interface SearchServiceStartDependencies { +/** @internal */ +export interface SearchServiceStartDependencies { + fieldFormats: AggsStartDependencies['fieldFormats']; indexPatterns: IndexPatternsContract; } export class SearchService implements Plugin { private esClient?: LegacyApiCaller; - private readonly aggTypesRegistry = new AggTypesRegistry(); + private readonly aggsService = new AggsService(); private searchInterceptor!: ISearchInterceptor; private usageCollector?: SearchUsageCollector; - /** - * getForceNow uses window.location, so we must have a separate implementation - * of calculateBounds on the client and the server. - */ - private calculateBounds = (timeRange: TimeRange) => - calculateBounds(timeRange, { forceNow: getForceNow() }); - public setup( core: CoreSetup, - { - expressions, - usageCollection, - packageInfo, - getInternalStartServices, - }: SearchServiceSetupDependencies + { packageInfo, registerFunction, usageCollection }: SearchServiceSetupDependencies ): ISearchSetup { this.usageCollector = createUsageCollector(core, usageCollection); this.esClient = getEsClient(core.injectedMetadata, core.http, packageInfo); - - const aggTypesSetup = this.aggTypesRegistry.setup(); - - // register each agg type - const aggTypes = getAggTypes({ - calculateBounds: this.calculateBounds, - getInternalStartServices, - uiSettings: core.uiSettings, - }); - aggTypes.buckets.forEach((b) => aggTypesSetup.registerBucket(b)); - aggTypes.metrics.forEach((m) => aggTypesSetup.registerMetric(m)); - - // register expression functions for each agg type - const aggFunctions = getAggTypesFunctions(); - aggFunctions.forEach((fn) => expressions.registerFunction(fn)); - /** * A global object that intercepts all searches and provides convenience methods for cancelling * all pending search requests, as well as getting the number of pending search requests. @@ -109,20 +72,21 @@ export class SearchService implements Plugin { ); return { + aggs: this.aggsService.setup({ + registerFunction, + uiSettings: core.uiSettings, + }), usageCollector: this.usageCollector!, __enhance: (enhancements: SearchEnhancements) => { this.searchInterceptor = enhancements.searchInterceptor; }, - aggs: { - calculateAutoTimeExpression: getCalculateAutoTimeExpression(core.uiSettings), - types: aggTypesSetup, - }, }; } - public start(core: CoreStart, dependencies: SearchServiceStartDependencies): ISearchStart { - const aggTypesStart = this.aggTypesRegistry.start(); - + public start( + { application, http, injectedMetadata, notifications, uiSettings }: CoreStart, + { fieldFormats, indexPatterns }: SearchServiceStartDependencies + ): ISearchStart { const search: ISearchGeneric = (request, options) => { return this.searchInterceptor.search(request, options); }; @@ -132,25 +96,17 @@ export class SearchService implements Plugin { }; const searchSourceDependencies: SearchSourceDependencies = { - uiSettings: core.uiSettings, - injectedMetadata: core.injectedMetadata, + uiSettings, + injectedMetadata, search, legacySearch, }; return { - aggs: { - calculateAutoTimeExpression: getCalculateAutoTimeExpression(core.uiSettings), - createAggConfigs: (indexPattern, configStates = [], schemas) => { - return new AggConfigs(indexPattern, configStates, { - typesRegistry: aggTypesStart, - }); - }, - types: aggTypesStart, - }, + aggs: this.aggsService.start({ fieldFormats, uiSettings }), search, searchSource: { - create: createSearchSource(dependencies.indexPatterns, searchSourceDependencies), + create: createSearchSource(indexPatterns, searchSourceDependencies), createEmpty: () => { return new SearchSource({}, searchSourceDependencies); }, @@ -159,5 +115,7 @@ export class SearchService implements Plugin { }; } - public stop() {} + public stop() { + this.aggsService.stop(); + } } diff --git a/src/plugins/data/public/search/types.ts b/src/plugins/data/public/search/types.ts index d85d4c4e5c935..d1a4437943402 100644 --- a/src/plugins/data/public/search/types.ts +++ b/src/plugins/data/public/search/types.ts @@ -19,11 +19,11 @@ import { Observable } from 'rxjs'; import { PackageInfo } from 'kibana/server'; -import { SearchAggsSetup, SearchAggsStart } from './aggs'; import { LegacyApiCaller } from './legacy/es_client'; import { ISearchInterceptor } from './search_interceptor'; import { ISearchSource, SearchSourceFields } from './search_source'; import { SearchUsageCollector } from './collectors'; +import { AggsSetup, AggsSetupDependencies, AggsStartDependencies, AggsStart } from './aggs'; import { IKibanaSearchRequest, IKibanaSearchResponse, @@ -31,9 +31,7 @@ import { IEsSearchResponse, } from '../../common/search'; import { IndexPatternsContract } from '../../common/index_patterns/index_patterns'; -import { ExpressionsSetup } from '../../../expressions/public'; import { UsageCollectionSetup } from '../../../usage_collection/public'; -import { GetInternalStartServicesFn } from '../types'; export interface ISearchOptions { signal?: AbortSignal; @@ -62,7 +60,7 @@ export interface SearchEnhancements { * point. */ export interface ISearchSetup { - aggs: SearchAggsSetup; + aggs: AggsSetup; usageCollector?: SearchUsageCollector; /** * @internal @@ -71,7 +69,7 @@ export interface ISearchSetup { } export interface ISearchStart { - aggs: SearchAggsStart; + aggs: AggsStart; search: ISearchGeneric; searchSource: { create: (fields?: SearchSourceFields) => Promise; @@ -86,13 +84,15 @@ export interface ISearchStart { export { SEARCH_EVENT_TYPE } from './collectors'; +/** @internal */ export interface SearchServiceSetupDependencies { - expressions: ExpressionsSetup; - usageCollection?: UsageCollectionSetup; - getInternalStartServices: GetInternalStartServicesFn; packageInfo: PackageInfo; + registerFunction: AggsSetupDependencies['registerFunction']; + usageCollection?: UsageCollectionSetup; } +/** @internal */ export interface SearchServiceStartDependencies { + fieldFormats: AggsStartDependencies['fieldFormats']; indexPatterns: IndexPatternsContract; } diff --git a/src/plugins/data/public/types.ts b/src/plugins/data/public/types.ts index c39b7d355d495..bffc10642eb47 100644 --- a/src/plugins/data/public/types.ts +++ b/src/plugins/data/public/types.ts @@ -82,15 +82,3 @@ export interface IDataPluginServices extends Partial { storage: IStorageWrapper; data: DataPublicPluginStart; } - -/** @internal **/ -export interface InternalStartServices { - readonly fieldFormats: FieldFormatsStart; - readonly notifications: CoreStart['notifications']; - readonly uiSettings: CoreStart['uiSettings']; - readonly searchService: DataPublicPluginStart['search']; - readonly injectedMetadata: CoreStart['injectedMetadata']; -} - -/** @internal **/ -export type GetInternalStartServicesFn = () => InternalStartServices; diff --git a/src/plugins/data/server/index.ts b/src/plugins/data/server/index.ts index 73ed88850d787..c3b06992dba0e 100644 --- a/src/plugins/data/server/index.ts +++ b/src/plugins/data/server/index.ts @@ -150,6 +150,16 @@ export { */ import { + // aggs + CidrMask, + intervalOptions, + isNumberType, + isStringType, + isType, + parentPipelineType, + propFilter, + siblingPipelineType, + termsAggFilter, dateHistogramInterval, InvalidEsCalendarIntervalError, InvalidEsIntervalFormatError, @@ -159,13 +169,41 @@ import { parseEsInterval, parseInterval, toAbsoluteDates, + // expressions utils + getRequestInspectorStats, + getResponseInspectorStats, + // tabify + tabifyAggResponse, + tabifyGetColumns, } from '../common'; export { + // aggs + AggGroupLabels, + AggGroupName, + AggGroupNames, + AggParam, + AggParamOption, + AggParamType, + AggConfigOptions, + BUCKET_TYPES, EsaggsExpressionFunctionDefinition, + IAggConfig, + IAggConfigs, + IAggType, + IFieldParamType, + IMetricAggType, + METRIC_TYPES, + OptionedParamType, + OptionedValueProp, ParsedInterval, + // search IEsSearchRequest, IEsSearchResponse, + // tabify + TabbedAggColumn, + TabbedAggRow, + TabbedTable, } from '../common'; export { @@ -182,16 +220,29 @@ export { // Search namespace export const search = { aggs: { + CidrMask, dateHistogramInterval, + intervalOptions, InvalidEsCalendarIntervalError, InvalidEsIntervalFormatError, Ipv4Address, + isNumberType, + isStringType, + isType, isValidEsInterval, isValidInterval, + parentPipelineType, parseEsInterval, parseInterval, + propFilter, + siblingPipelineType, + termsAggFilter, toAbsoluteDates, }, + getRequestInspectorStats, + getResponseInspectorStats, + tabifyAggResponse, + tabifyGetColumns, }; /** diff --git a/src/plugins/data/server/plugin.ts b/src/plugins/data/server/plugin.ts index 61d8e566d2d2b..5163bfcb17d40 100644 --- a/src/plugins/data/server/plugin.ts +++ b/src/plugins/data/server/plugin.ts @@ -17,13 +17,8 @@ * under the License. */ -import { - PluginInitializerContext, - CoreSetup, - CoreStart, - Plugin, - Logger, -} from '../../../core/server'; +import { PluginInitializerContext, CoreSetup, CoreStart, Plugin, Logger } from 'src/core/server'; +import { ExpressionsServerSetup } from 'src/plugins/expressions/server'; import { ConfigSchema } from '../config'; import { IndexPatternsService, IndexPatternsServiceStart } from './index_patterns'; import { ISearchSetup, ISearchStart } from './search'; @@ -48,10 +43,21 @@ export interface DataPluginStart { } export interface DataPluginSetupDependencies { + expressions: ExpressionsServerSetup; usageCollection?: UsageCollectionSetup; } -export class DataServerPlugin implements Plugin { +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface DataPluginStartDependencies {} + +export class DataServerPlugin + implements + Plugin< + DataPluginSetup, + DataPluginStart, + DataPluginSetupDependencies, + DataPluginStartDependencies + > { private readonly searchService: SearchService; private readonly scriptsService: ScriptsService; private readonly kqlTelemetryService: KqlTelemetryService; @@ -70,8 +76,8 @@ export class DataServerPlugin implements Plugin, - { usageCollection }: DataPluginSetupDependencies + core: CoreSetup, + { expressions, usageCollection }: DataPluginSetupDependencies ) { this.indexPatterns.setup(core); this.scriptsService.setup(core); @@ -82,7 +88,10 @@ export class DataServerPlugin implements Plugin { + let service: AggsService; + let setupDeps: AggsSetupDependencies; + let startDeps: AggsStartDependencies; + + beforeEach(() => { + service = new AggsService(); + setupDeps = { + registerFunction: expressionsPluginMock.createSetupContract().registerFunction, + }; + startDeps = { + fieldFormats: createFieldFormatsStartMock(), + uiSettings, + }; + }); + + describe('setup()', () => { + test('exposes proper contract', () => { + const setup = service.setup(setupDeps); + expect(Object.keys(setup).length).toBe(1); + expect(setup).toHaveProperty('types'); + }); + }); + + describe('start()', () => { + test('exposes proper contract', async () => { + service.setup(setupDeps); + const start = service.start(startDeps); + + expect(Object.keys(start).length).toBe(1); + expect(start).toHaveProperty('asScopedToClient'); + + const contract = await start.asScopedToClient( + savedObjects.getScopedClient({} as KibanaRequest) + ); + expect(contract).toHaveProperty('calculateAutoTimeExpression'); + expect(contract).toHaveProperty('createAggConfigs'); + expect(contract).toHaveProperty('types'); + }); + + test('types registry returns initialized agg types', async () => { + service.setup(setupDeps); + const start = await service + .start(startDeps) + .asScopedToClient(savedObjects.getScopedClient({} as KibanaRequest)); + + expect(start.types.get('terms').name).toBe('terms'); + }); + + test('registers default agg types', async () => { + service.setup(setupDeps); + const start = await service + .start(startDeps) + .asScopedToClient(savedObjects.getScopedClient({} as KibanaRequest)); + + const aggTypes = getAggTypes(); + expect(start.types.getAll().buckets.length).toBe(aggTypes.buckets.length); + expect(start.types.getAll().metrics.length).toBe(aggTypes.metrics.length); + }); + + test('merges default agg types with types registered during setup', async () => { + const setup = service.setup(setupDeps); + setup.types.registerBucket( + 'foo', + () => ({ name: 'foo', type: 'buckets' } as BucketAggType) + ); + setup.types.registerMetric( + 'bar', + () => ({ name: 'bar', type: 'metrics' } as MetricAggType) + ); + + const start = await service + .start(startDeps) + .asScopedToClient(savedObjects.getScopedClient({} as KibanaRequest)); + + const aggTypes = getAggTypes(); + expect(start.types.getAll().buckets.length).toBe(aggTypes.buckets.length + 1); + expect(start.types.getAll().buckets.some(({ name }) => name === 'foo')).toBe(true); + expect(start.types.getAll().metrics.length).toBe(aggTypes.metrics.length + 1); + expect(start.types.getAll().metrics.some(({ name }) => name === 'bar')).toBe(true); + }); + }); +}); diff --git a/src/plugins/data/server/search/aggs/aggs_service.ts b/src/plugins/data/server/search/aggs/aggs_service.ts new file mode 100644 index 0000000000000..3e5cd8adb44a6 --- /dev/null +++ b/src/plugins/data/server/search/aggs/aggs_service.ts @@ -0,0 +1,122 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { pick } from 'lodash'; + +import { UiSettingsServiceStart, SavedObjectsClientContract } from 'src/core/server'; +import { ExpressionsServiceSetup } from 'src/plugins/expressions/common'; +import { + AggsCommonService, + AggConfigs, + AggTypesDependencies, + aggsRequiredUiSettings, + calculateBounds, + TimeRange, +} from '../../../common'; +import { FieldFormatsStart } from '../../field_formats'; +import { AggsSetup, AggsStart } from './types'; + +/** @internal */ +export interface AggsSetupDependencies { + registerFunction: ExpressionsServiceSetup['registerFunction']; +} + +/** @internal */ +export interface AggsStartDependencies { + fieldFormats: FieldFormatsStart; + uiSettings: UiSettingsServiceStart; +} + +/** + * The aggs service provides a means of modeling and manipulating the various + * Elasticsearch aggregations supported by Kibana, providing the ability to + * output the correct DSL when you are ready to send your request to ES. + */ +export class AggsService { + private readonly aggsCommonService = new AggsCommonService(); + + /** + * getForceNow uses window.location on the client, so we must have a + * separate implementation of calculateBounds on the server. + */ + private calculateBounds = (timeRange: TimeRange) => calculateBounds(timeRange, {}); + + public setup({ registerFunction }: AggsSetupDependencies): AggsSetup { + return this.aggsCommonService.setup({ registerFunction }); + } + + public start({ fieldFormats, uiSettings }: AggsStartDependencies): AggsStart { + return { + asScopedToClient: async (savedObjectsClient: SavedObjectsClientContract) => { + const uiSettingsClient = uiSettings.asScopedToClient(savedObjectsClient); + const formats = await fieldFormats.fieldFormatServiceFactory(uiSettingsClient); + + // cache ui settings, only including items which are explicitly needed by aggs + const uiSettingsCache = pick(await uiSettingsClient.getAll(), aggsRequiredUiSettings); + const getConfig = (key: string): T => { + return uiSettingsCache[key]; + }; + + const { calculateAutoTimeExpression, types } = this.aggsCommonService.start({ getConfig }); + + const aggTypesDependencies: AggTypesDependencies = { + calculateBounds: this.calculateBounds, + getConfig, + getFieldFormatsStart: () => ({ + deserialize: formats.deserialize, + getDefaultInstance: formats.getDefaultInstance, + }), + /** + * Date histogram and date range need to know whether we are using the + * default timezone, but `isDefault` is not currently offered on the + * server, so we need to manually check for the default value. + */ + isDefaultTimezone: () => getConfig('dateFormat:tz') === 'Browser', + }; + + const typesRegistry = { + get: (name: string) => { + const type = types.get(name); + if (!type) { + return; + } + return type(aggTypesDependencies); + }, + getAll: () => { + return { + // initialize each agg type on the fly + buckets: types.getAll().buckets.map((type) => type(aggTypesDependencies)), + metrics: types.getAll().metrics.map((type) => type(aggTypesDependencies)), + }; + }, + }; + + return { + calculateAutoTimeExpression, + createAggConfigs: (indexPattern, configStates = [], schemas) => { + return new AggConfigs(indexPattern, configStates, { typesRegistry }); + }, + types: typesRegistry, + }; + }, + }; + } + + public stop() {} +} diff --git a/src/plugins/data/server/search/aggs/index.ts b/src/plugins/data/server/search/aggs/index.ts new file mode 100644 index 0000000000000..77d97c426260c --- /dev/null +++ b/src/plugins/data/server/search/aggs/index.ts @@ -0,0 +1,21 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export * from './aggs_service'; +export * from './types'; diff --git a/src/plugins/data/server/search/aggs/mocks.ts b/src/plugins/data/server/search/aggs/mocks.ts new file mode 100644 index 0000000000000..b50e22fe87b7c --- /dev/null +++ b/src/plugins/data/server/search/aggs/mocks.ts @@ -0,0 +1,81 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { + AggConfigs, + AggTypesRegistrySetup, + AggTypesRegistryStart, + AggsCommonStart, + getCalculateAutoTimeExpression, +} from '../../../common'; +import { AggsSetup, AggsStart } from './types'; + +import { mockAggTypesRegistry } from '../../../common/search/aggs/test_helpers'; + +const getConfig = jest.fn(); + +const aggTypeBaseParamMock = () => ({ + name: 'some_param', + type: 'some_param_type', + displayName: 'some_agg_type_param', + required: false, + advanced: false, + default: {}, + write: jest.fn(), + serialize: jest.fn().mockImplementation(() => {}), + deserialize: jest.fn().mockImplementation(() => {}), + options: [], +}); + +const aggTypeConfigMock = () => ({ + name: 'some_name', + title: 'some_title', + params: [aggTypeBaseParamMock()], +}); + +export const aggTypesRegistrySetupMock = (): AggTypesRegistrySetup => ({ + registerBucket: jest.fn(), + registerMetric: jest.fn(), +}); + +export const aggTypesRegistryStartMock = (): AggTypesRegistryStart => ({ + get: jest.fn().mockImplementation(aggTypeConfigMock), + getAll: jest.fn().mockImplementation(() => ({ + buckets: [aggTypeConfigMock()], + metrics: [aggTypeConfigMock()], + })), +}); + +export const searchAggsSetupMock = (): AggsSetup => ({ + types: aggTypesRegistrySetupMock(), +}); + +const commonStartMock = (): AggsCommonStart => ({ + calculateAutoTimeExpression: getCalculateAutoTimeExpression(getConfig), + createAggConfigs: jest.fn().mockImplementation((indexPattern, configStates = [], schemas) => { + return new AggConfigs(indexPattern, configStates, { + typesRegistry: mockAggTypesRegistry(), + }); + }), + types: mockAggTypesRegistry(), +}); + +export const searchAggsStartMock = (): AggsStart => ({ + asScopedToClient: jest.fn().mockResolvedValue(commonStartMock()), +}); diff --git a/src/plugins/data/server/search/aggs/types.ts b/src/plugins/data/server/search/aggs/types.ts new file mode 100644 index 0000000000000..1b21d948b25d9 --- /dev/null +++ b/src/plugins/data/server/search/aggs/types.ts @@ -0,0 +1,27 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { SavedObjectsClientContract } from 'src/core/server'; +import { AggsCommonSetup, AggsStart as Start } from '../../../common'; + +export type AggsSetup = AggsCommonSetup; + +export interface AggsStart { + asScopedToClient: (savedObjectsClient: SavedObjectsClientContract) => Promise; +} diff --git a/src/plugins/data/server/search/index.ts b/src/plugins/data/server/search/index.ts index cea2714671f0b..4a3990621ca39 100644 --- a/src/plugins/data/server/search/index.ts +++ b/src/plugins/data/server/search/index.ts @@ -22,3 +22,5 @@ export { ISearchStrategy, ISearchOptions, ISearchSetup, ISearchStart } from './t export { getDefaultSearchParams, getTotalLoaded } from './es_search'; export { usageProvider, SearchUsage } from './collectors'; + +export * from './aggs'; diff --git a/src/plugins/data/server/search/mocks.ts b/src/plugins/data/server/search/mocks.ts index b210df3c55db9..578a170f468bf 100644 --- a/src/plugins/data/server/search/mocks.ts +++ b/src/plugins/data/server/search/mocks.ts @@ -17,14 +17,19 @@ * under the License. */ -export function createSearchSetupMock() { +import { ISearchSetup, ISearchStart } from './types'; +import { searchAggsSetupMock, searchAggsStartMock } from './aggs/mocks'; + +export function createSearchSetupMock(): jest.Mocked { return { + aggs: searchAggsSetupMock(), registerSearchStrategy: jest.fn(), }; } -export function createSearchStartMock() { +export function createSearchStartMock(): jest.Mocked { return { + aggs: searchAggsStartMock(), getSearchStrategy: jest.fn(), search: jest.fn(), }; diff --git a/src/plugins/data/server/search/search_service.test.ts b/src/plugins/data/server/search/search_service.test.ts index be00b7409fe4a..030f37d0f7c46 100644 --- a/src/plugins/data/server/search/search_service.test.ts +++ b/src/plugins/data/server/search/search_service.test.ts @@ -17,15 +17,18 @@ * under the License. */ +import { CoreSetup, CoreStart } from '../../../../core/server'; import { coreMock } from '../../../../core/server/mocks'; -import { SearchService } from './search_service'; -import { CoreSetup } from '../../../../core/server'; import { DataPluginStart } from '../plugin'; +import { createFieldFormatsStartMock } from '../field_formats/mocks'; + +import { SearchService, SearchServiceSetupDependencies } from './search_service'; describe('Search service', () => { let plugin: SearchService; let mockCoreSetup: MockedKeys>; + let mockCoreStart: MockedKeys; beforeEach(() => { const mockLogger: any = { @@ -33,19 +36,27 @@ describe('Search service', () => { }; plugin = new SearchService(coreMock.createPluginInitializerContext({}), mockLogger); mockCoreSetup = coreMock.createSetup(); + mockCoreStart = coreMock.createStart(); }); describe('setup()', () => { it('exposes proper contract', async () => { - const setup = plugin.setup(mockCoreSetup, {}); + const setup = plugin.setup(mockCoreSetup, ({ + packageInfo: { version: '8' }, + registerFunction: jest.fn(), + } as unknown) as SearchServiceSetupDependencies); + expect(setup).toHaveProperty('aggs'); expect(setup).toHaveProperty('registerSearchStrategy'); }); }); describe('start()', () => { it('exposes proper contract', async () => { - const setup = plugin.start(); - expect(setup).toHaveProperty('getSearchStrategy'); + const start = plugin.start(mockCoreStart, { + fieldFormats: createFieldFormatsStartMock(), + }); + expect(start).toHaveProperty('aggs'); + expect(start).toHaveProperty('getSearchStrategy'); }); }); }); diff --git a/src/plugins/data/server/search/search_service.ts b/src/plugins/data/server/search/search_service.ts index 9dc47369567af..a8b1cdd608a84 100644 --- a/src/plugins/data/server/search/search_service.ts +++ b/src/plugins/data/server/search/search_service.ts @@ -18,13 +18,18 @@ */ import { + CoreSetup, + CoreStart, + Logger, Plugin, PluginInitializerContext, - CoreSetup, RequestHandlerContext, - Logger, } from '../../../../core/server'; import { ISearchSetup, ISearchStart, ISearchStrategy } from './types'; + +import { AggsService, AggsSetupDependencies } from './aggs'; + +import { FieldFormatsStart } from '../field_formats'; import { registerSearchRoute } from './routes'; import { ES_SEARCH_STRATEGY, esSearchStrategyProvider } from './es_search'; import { DataPluginStart } from '../plugin'; @@ -38,7 +43,19 @@ interface StrategyMap { [name: string]: ISearchStrategy; } +/** @internal */ +export interface SearchServiceSetupDependencies { + registerFunction: AggsSetupDependencies['registerFunction']; + usageCollection?: UsageCollectionSetup; +} + +/** @internal */ +export interface SearchServiceStartDependencies { + fieldFormats: FieldFormatsStart; +} + export class SearchService implements Plugin { + private readonly aggsService = new AggsService(); private searchStrategies: StrategyMap = {}; constructor( @@ -48,7 +65,7 @@ export class SearchService implements Plugin { public setup( core: CoreSetup, - { usageCollection }: { usageCollection?: UsageCollectionSetup } + { registerFunction, usageCollection }: SearchServiceSetupDependencies ): ISearchSetup { const usage = usageCollection ? usageProvider(core) : undefined; @@ -68,7 +85,11 @@ export class SearchService implements Plugin { registerSearchRoute(core); - return { registerSearchStrategy: this.registerSearchStrategy, usage }; + return { + aggs: this.aggsService.setup({ registerFunction }), + registerSearchStrategy: this.registerSearchStrategy, + usage, + }; } private search( @@ -83,8 +104,12 @@ export class SearchService implements Plugin { ); } - public start(): ISearchStart { + public start( + { uiSettings }: CoreStart, + { fieldFormats }: SearchServiceStartDependencies + ): ISearchStart { return { + aggs: this.aggsService.start({ fieldFormats, uiSettings }), getSearchStrategy: this.getSearchStrategy, search: ( context: RequestHandlerContext, @@ -96,7 +121,9 @@ export class SearchService implements Plugin { }; } - public stop() {} + public stop() { + this.aggsService.stop(); + } private registerSearchStrategy = (name: string, strategy: ISearchStrategy) => { this.logger.info(`Register strategy ${name}`); diff --git a/src/plugins/data/server/search/types.ts b/src/plugins/data/server/search/types.ts index 76afd7e8c951c..fe54975d76624 100644 --- a/src/plugins/data/server/search/types.ts +++ b/src/plugins/data/server/search/types.ts @@ -19,6 +19,7 @@ import { RequestHandlerContext } from '../../../../core/server'; import { IKibanaSearchResponse, IKibanaSearchRequest } from '../../common/search'; +import { AggsSetup, AggsStart } from './aggs'; import { SearchUsage } from './collectors/usage'; import { IEsSearchRequest, IEsSearchResponse } from './es_search'; @@ -31,6 +32,7 @@ export interface ISearchOptions { } export interface ISearchSetup { + aggs: AggsSetup; /** * Extension point exposed for other plugins to register their own search * strategies. @@ -44,6 +46,7 @@ export interface ISearchSetup { } export interface ISearchStart { + aggs: AggsStart; /** * Get other registered search strategies. For example, if a new strategy needs to use the * already-registered ES search strategy, it can use this function to accomplish that. diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index 7f26df5766620..f2932a93971fb 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -4,7 +4,9 @@ ```ts +import { $Values } from '@kbn/utility-types'; import { ApiResponse } from '@elastic/elasticsearch/lib/Transport'; +import { Assign } from '@kbn/utility-types'; import Boom from 'boom'; import { BulkIndexDocumentsParams } from 'elasticsearch'; import { CatAliasesParams } from 'elasticsearch'; @@ -22,7 +24,6 @@ import { CatTasksParams } from 'elasticsearch'; import { CatThreadPoolParams } from 'elasticsearch'; import { ClearScrollParams } from 'elasticsearch'; import { Client } from 'elasticsearch'; -import { ClientOptions } from '@elastic/elasticsearch'; import { ClusterAllocationExplainParams } from 'elasticsearch'; import { ClusterGetSettingsParams } from 'elasticsearch'; import { ClusterHealthParams } from 'elasticsearch'; @@ -31,19 +32,23 @@ import { ClusterPutSettingsParams } from 'elasticsearch'; import { ClusterRerouteParams } from 'elasticsearch'; import { ClusterStateParams } from 'elasticsearch'; import { ClusterStatsParams } from 'elasticsearch'; -import { ConfigOptions } from 'elasticsearch'; +import { CoreSetup } from 'src/core/server'; import { CoreSetup as CoreSetup_2 } from 'kibana/server'; +import { CoreStart } from 'src/core/server'; import { CountParams } from 'elasticsearch'; import { CreateDocumentParams } from 'elasticsearch'; import { DeleteDocumentByQueryParams } from 'elasticsearch'; import { DeleteDocumentParams } from 'elasticsearch'; import { DeleteScriptParams } from 'elasticsearch'; import { DeleteTemplateParams } from 'elasticsearch'; -import { DetailedPeerCertificate } from 'tls'; import { Duration } from 'moment'; +import { Ensure } from '@kbn/utility-types'; import { ErrorToastOptions } from 'src/core/public/notifications'; import { ExistsParams } from 'elasticsearch'; import { ExplainParams } from 'elasticsearch'; +import { ExpressionAstFunction } from 'src/plugins/expressions/common'; +import { ExpressionsServerSetup } from 'src/plugins/expressions/server'; +import { FetchOptions } from 'src/plugins/data/public'; import { FieldStatsParams } from 'elasticsearch'; import { GenericParams } from 'elasticsearch'; import { GetParams } from 'elasticsearch'; @@ -94,13 +99,15 @@ import { IngestDeletePipelineParams } from 'elasticsearch'; import { IngestGetPipelineParams } from 'elasticsearch'; import { IngestPutPipelineParams } from 'elasticsearch'; import { IngestSimulateParams } from 'elasticsearch'; +import { ISearchSource } from 'src/plugins/data/public'; import { KibanaClient } from '@elastic/elasticsearch/api/kibana'; import { KibanaConfigType as KibanaConfigType_2 } from 'src/core/server/kibana_config'; -import { KibanaRequest as KibanaRequest_2 } from 'kibana/server'; +import { KibanaRequest } from 'kibana/server'; import { LegacyAPICaller as LegacyAPICaller_2 } from 'kibana/server'; import { Logger as Logger_2 } from 'kibana/server'; import { MGetParams } from 'elasticsearch'; import { MGetResponse } from 'elasticsearch'; +import { Moment } from 'moment'; import moment from 'moment'; import { MSearchParams } from 'elasticsearch'; import { MSearchResponse } from 'elasticsearch'; @@ -109,27 +116,26 @@ import { MTermVectorsParams } from 'elasticsearch'; import { NodesHotThreadsParams } from 'elasticsearch'; import { NodesInfoParams } from 'elasticsearch'; import { NodesStatsParams } from 'elasticsearch'; -import { ObjectType } from '@kbn/config-schema'; import { Observable } from 'rxjs'; -import { PeerCertificate } from 'tls'; import { PingParams } from 'elasticsearch'; +import { Plugin as Plugin_2 } from 'src/core/server'; +import { PluginInitializerContext as PluginInitializerContext_2 } from 'src/core/server'; import { PutScriptParams } from 'elasticsearch'; import { PutTemplateParams } from 'elasticsearch'; import { RecursiveReadonly } from '@kbn/utility-types'; import { ReindexParams } from 'elasticsearch'; import { ReindexRethrottleParams } from 'elasticsearch'; import { RenderSearchTemplateParams } from 'elasticsearch'; -import { Request } from 'hapi'; -import { ResponseObject } from 'hapi'; -import { ResponseToolkit } from 'hapi'; -import { SavedObject as SavedObject_2 } from 'src/core/server'; -import { SchemaTypeError } from '@kbn/config-schema'; +import { RequestAdapter } from 'src/plugins/inspector/common'; +import { RequestStatistics } from 'src/plugins/inspector/common'; +import { SavedObject } from 'src/core/server'; +import { SavedObjectsClientContract as SavedObjectsClientContract_2 } from 'src/core/server'; import { ScrollParams } from 'elasticsearch'; import { SearchParams } from 'elasticsearch'; import { SearchResponse } from 'elasticsearch'; import { SearchShardsParams } from 'elasticsearch'; import { SearchTemplateParams } from 'elasticsearch'; -import { ShallowPromise } from '@kbn/utility-types'; +import { SerializedFieldFormat as SerializedFieldFormat_2 } from 'src/plugins/expressions/common'; import { ShardsResponse } from 'elasticsearch'; import { SnapshotCreateParams } from 'elasticsearch'; import { SnapshotCreateRepositoryParams } from 'elasticsearch'; @@ -140,7 +146,6 @@ import { SnapshotGetRepositoryParams } from 'elasticsearch'; import { SnapshotRestoreParams } from 'elasticsearch'; import { SnapshotStatusParams } from 'elasticsearch'; import { SnapshotVerifyRepositoryParams } from 'elasticsearch'; -import { Stream } from 'stream'; import { SuggestParams } from 'elasticsearch'; import { TasksCancelParams } from 'elasticsearch'; import { TasksGetParams } from 'elasticsearch'; @@ -156,7 +161,96 @@ import { Unit } from '@elastic/datemath'; import { UnwrapPromiseOrReturn } from '@kbn/utility-types'; import { UpdateDocumentByQueryParams } from 'elasticsearch'; import { UpdateDocumentParams } from 'elasticsearch'; -import { Url } from 'url'; + +// Warning: (ae-forgotten-export) The symbol "AggConfigSerialized" needs to be exported by the entry point index.d.ts +// Warning: (ae-missing-release-tag) "AggConfigOptions" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export type AggConfigOptions = Assign; + +// Warning: (ae-missing-release-tag) "AggGroupLabels" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export const AggGroupLabels: { + buckets: string; + metrics: string; + none: string; +}; + +// Warning: (ae-missing-release-tag) "AggGroupName" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export type AggGroupName = $Values; + +// Warning: (ae-missing-release-tag) "AggGroupNames" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export const AggGroupNames: Readonly<{ + Buckets: "buckets"; + Metrics: "metrics"; + None: "none"; +}>; + +// Warning: (ae-forgotten-export) The symbol "BaseParamType" needs to be exported by the entry point index.d.ts +// Warning: (ae-missing-release-tag) "AggParam" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export type AggParam = BaseParamType; + +// Warning: (ae-missing-release-tag) "AggParamOption" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export interface AggParamOption { + // (undocumented) + display: string; + // Warning: (ae-forgotten-export) The symbol "AggConfig" needs to be exported by the entry point index.d.ts + // + // (undocumented) + enabled?(agg: AggConfig): boolean; + // (undocumented) + val: string; +} + +// Warning: (ae-missing-release-tag) "AggParamType" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export class AggParamType extends BaseParamType { + constructor(config: Record); + // (undocumented) + allowedAggs: string[]; + // (undocumented) + makeAgg: (agg: TAggConfig, state?: AggConfigSerialized) => TAggConfig; +} + +// Warning: (ae-missing-release-tag) "BUCKET_TYPES" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export enum BUCKET_TYPES { + // (undocumented) + DATE_HISTOGRAM = "date_histogram", + // (undocumented) + DATE_RANGE = "date_range", + // (undocumented) + FILTER = "filter", + // (undocumented) + FILTERS = "filters", + // (undocumented) + GEOHASH_GRID = "geohash_grid", + // (undocumented) + GEOTILE_GRID = "geotile_grid", + // (undocumented) + HISTOGRAM = "histogram", + // (undocumented) + IP_RANGE = "ip_range", + // (undocumented) + RANGE = "range", + // (undocumented) + SIGNIFICANT_TERMS = "significant_terms", + // (undocumented) + TERMS = "terms" +} // Warning: (ae-missing-release-tag) "castEsToKbnFieldTypeName" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -369,6 +463,22 @@ export function getTotalLoaded({ total, failed, successful }: ShardsResponse): { loaded: number; }; +// Warning: (ae-missing-release-tag) "IAggConfig" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public +export type IAggConfig = AggConfig; + +// Warning: (ae-forgotten-export) The symbol "AggConfigs" needs to be exported by the entry point index.d.ts +// +// @internal +export type IAggConfigs = AggConfigs; + +// Warning: (ae-forgotten-export) The symbol "AggType" needs to be exported by the entry point index.d.ts +// Warning: (ae-missing-release-tag) "IAggType" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export type IAggType = AggType; + // Warning: (ae-forgotten-export) The symbol "IKibanaSearchRequest" needs to be exported by the entry point index.d.ts // Warning: (ae-missing-release-tag) "IEsSearchRequest" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -398,6 +508,12 @@ export interface IEsSearchResponse extends IKibanaSearchResponse { // @public (undocumented) export type IFieldFormatsRegistry = PublicMethodsOf; +// Warning: (ae-forgotten-export) The symbol "FieldParamType" needs to be exported by the entry point index.d.ts +// Warning: (ae-missing-release-tag) "IFieldParamType" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export type IFieldParamType = FieldParamType; + // Warning: (ae-missing-release-tag) "IFieldSubType" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) @@ -481,6 +597,12 @@ export interface IIndexPattern { type?: string; } +// Warning: (ae-forgotten-export) The symbol "MetricAggType" needs to be exported by the entry point index.d.ts +// Warning: (ae-missing-release-tag) "IMetricAggType" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export type IMetricAggType = MetricAggType; + // Warning: (ae-missing-release-tag) "IndexPatternAttributes" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public @deprecated @@ -563,6 +685,10 @@ export interface ISearchOptions { // // @public (undocumented) export interface ISearchSetup { + // Warning: (ae-forgotten-export) The symbol "AggsSetup" needs to be exported by the entry point index.d.ts + // + // (undocumented) + aggs: AggsSetup; registerSearchStrategy: (name: string, strategy: ISearchStrategy) => void; usage?: SearchUsage; } @@ -571,6 +697,10 @@ export interface ISearchSetup { // // @public (undocumented) export interface ISearchStart { + // Warning: (ae-forgotten-export) The symbol "AggsStart" needs to be exported by the entry point index.d.ts + // + // (undocumented) + aggs: AggsStart; getSearchStrategy: (name: string) => ISearchStrategy; // Warning: (ae-forgotten-export) The symbol "RequestHandlerContext" needs to be exported by the entry point index.d.ts // @@ -634,6 +764,77 @@ export interface KueryNode { type: keyof NodeTypes; } +// Warning: (ae-missing-release-tag) "METRIC_TYPES" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export enum METRIC_TYPES { + // (undocumented) + AVG = "avg", + // (undocumented) + AVG_BUCKET = "avg_bucket", + // (undocumented) + CARDINALITY = "cardinality", + // (undocumented) + COUNT = "count", + // (undocumented) + CUMULATIVE_SUM = "cumulative_sum", + // (undocumented) + DERIVATIVE = "derivative", + // (undocumented) + GEO_BOUNDS = "geo_bounds", + // (undocumented) + GEO_CENTROID = "geo_centroid", + // (undocumented) + MAX = "max", + // (undocumented) + MAX_BUCKET = "max_bucket", + // (undocumented) + MEDIAN = "median", + // (undocumented) + MIN = "min", + // (undocumented) + MIN_BUCKET = "min_bucket", + // (undocumented) + MOVING_FN = "moving_avg", + // (undocumented) + PERCENTILE_RANKS = "percentile_ranks", + // (undocumented) + PERCENTILES = "percentiles", + // (undocumented) + SERIAL_DIFF = "serial_diff", + // (undocumented) + STD_DEV = "std_dev", + // (undocumented) + SUM = "sum", + // (undocumented) + SUM_BUCKET = "sum_bucket", + // (undocumented) + TOP_HITS = "top_hits" +} + +// Warning: (ae-missing-release-tag) "OptionedParamType" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export class OptionedParamType extends BaseParamType { + constructor(config: Record); + // (undocumented) + options: OptionedValueProp[]; +} + +// Warning: (ae-missing-release-tag) "OptionedValueProp" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export interface OptionedValueProp { + // (undocumented) + disabled?: boolean; + // (undocumented) + isCompatible: (agg: IAggConfig) => boolean; + // (undocumented) + text: string; + // (undocumented) + value: string; +} + // Warning: (ae-forgotten-export) The symbol "parseEsInterval" needs to be exported by the entry point index.d.ts // Warning: (ae-missing-release-tag) "ParsedInterval" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -645,25 +846,20 @@ export type ParsedInterval = ReturnType; // @public (undocumented) export function parseInterval(interval: string): moment.Duration | null; -// Warning: (ae-forgotten-export) The symbol "Plugin" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DataPluginSetupDependencies" needs to be exported by the entry point index.d.ts +// Warning: (ae-forgotten-export) The symbol "DataPluginStartDependencies" needs to be exported by the entry point index.d.ts // Warning: (ae-missing-release-tag) "DataServerPlugin" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export class Plugin implements Plugin_2 { - // Warning: (ae-forgotten-export) The symbol "PluginInitializerContext" needs to be exported by the entry point index.d.ts - constructor(initializerContext: PluginInitializerContext); - // Warning: (ae-forgotten-export) The symbol "CoreSetup" needs to be exported by the entry point index.d.ts - // Warning: (ae-forgotten-export) The symbol "DataPluginSetupDependencies" needs to be exported by the entry point index.d.ts - // +export class Plugin implements Plugin_2 { + constructor(initializerContext: PluginInitializerContext_2); // (undocumented) - setup(core: CoreSetup, { usageCollection }: DataPluginSetupDependencies): { + setup(core: CoreSetup, { expressions, usageCollection }: DataPluginSetupDependencies): { search: ISearchSetup; fieldFormats: { - register: (customFieldFormat: import("../common").FieldFormatInstanceType) => number; + register: (customFieldFormat: import("../public").FieldFormatInstanceType) => number; }; }; - // Warning: (ae-forgotten-export) The symbol "CoreStart" needs to be exported by the entry point index.d.ts - // // (undocumented) start(core: CoreStart): { search: ISearchStart; @@ -678,6 +874,8 @@ export class Plugin implements Plugin_2 { stop(): void; } +// Warning: (ae-forgotten-export) The symbol "PluginInitializerContext" needs to be exported by the entry point index.d.ts +// // @public export function plugin(initializerContext: PluginInitializerContext): Plugin; @@ -736,16 +934,36 @@ export interface RefreshInterval { // @public (undocumented) export const search: { aggs: { + CidrMask: typeof CidrMask; dateHistogramInterval: typeof dateHistogramInterval; + intervalOptions: ({ + display: string; + val: string; + enabled(agg: import("../common").IBucketAggConfig): boolean | "" | undefined; + } | { + display: string; + val: string; + })[]; InvalidEsCalendarIntervalError: typeof InvalidEsCalendarIntervalError; InvalidEsIntervalFormatError: typeof InvalidEsIntervalFormatError; Ipv4Address: typeof Ipv4Address; + isNumberType: (agg: import("../common").AggConfig) => boolean; + isStringType: (agg: import("../common").AggConfig) => boolean; + isType: (...types: string[]) => (agg: import("../common").AggConfig) => boolean; isValidEsInterval: typeof isValidEsInterval; isValidInterval: typeof isValidInterval; + parentPipelineType: string; parseEsInterval: typeof parseEsInterval; parseInterval: typeof parseInterval; + propFilter: typeof propFilter; + siblingPipelineType: string; + termsAggFilter: string[]; toAbsoluteDates: typeof toAbsoluteDates; }; + getRequestInspectorStats: typeof getRequestInspectorStats; + getResponseInspectorStats: typeof getResponseInspectorStats; + tabifyAggResponse: typeof tabifyAggResponse; + tabifyGetColumns: typeof tabifyGetColumns; }; // Warning: (ae-missing-release-tag) "SearchUsage" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) @@ -763,6 +981,27 @@ export interface SearchUsage { // @public (undocumented) export function shouldReadFieldFromDocValues(aggregatable: boolean, esType: string): boolean; +// @public (undocumented) +export interface TabbedAggColumn { + // (undocumented) + aggConfig: IAggConfig; + // (undocumented) + id: string; + // (undocumented) + name: string; +} + +// @public (undocumented) +export type TabbedAggRow = Record; + +// @public (undocumented) +export interface TabbedTable { + // (undocumented) + columns: TabbedAggColumn[]; + // (undocumented) + rows: TabbedAggRow[]; +} + // Warning: (ae-missing-release-tag) "TimeRange" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) @@ -838,13 +1077,19 @@ export function usageProvider(core: CoreSetup_2): SearchUsage; // src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "TruncateFormat" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:127:27 - (ae-forgotten-export) The symbol "isFilterable" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:127:27 - (ae-forgotten-export) The symbol "isNestedField" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:185:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:186:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:187:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:188:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:189:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:190:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/index.ts:193:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:221:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:221:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:221:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:221:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:223:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:224:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:233:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:234:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:235:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:239:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:240:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:244:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/index.ts:247:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/date_histogram.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/date_histogram.test.tsx index 1a094a36f68e3..ebf8e09e86396 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/date_histogram.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/date_histogram.test.tsx @@ -10,7 +10,6 @@ import { dateHistogramOperation } from './index'; import { shallow } from 'enzyme'; import { EuiSwitch, EuiSwitchEvent } from '@elastic/eui'; import { IUiSettingsClient, SavedObjectsClientContract, HttpSetup } from 'kibana/public'; -import { coreMock } from 'src/core/public/mocks'; import { IStorageWrapper } from 'src/plugins/kibana_utils/public'; import { UI_SETTINGS } from '../../../../../../../src/plugins/data/public'; import { @@ -21,14 +20,13 @@ import { createMockedIndexPattern } from '../../mocks'; import { IndexPatternPrivateState } from '../../types'; const dataStart = dataPluginMock.createStartContract(); -dataStart.search.aggs.calculateAutoTimeExpression = getCalculateAutoTimeExpression({ - ...coreMock.createStart().uiSettings, - get: (path: string) => { +dataStart.search.aggs.calculateAutoTimeExpression = getCalculateAutoTimeExpression( + (path: string) => { if (path === UI_SETTINGS.HISTOGRAM_MAX_BARS) { return 10; } - }, -} as IUiSettingsClient); + } +); const defaultOptions = { storage: {} as IStorageWrapper,