From 38fd963ed3916ccbe565ee22551ce0ff65182a85 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Thu, 23 Jan 2020 18:19:33 +0100 Subject: [PATCH] Timelion api migration (#53005) --- .i18nrc.json | 2 +- src/legacy/core_plugins/timelion/index.ts | 9 -- .../directives/timelion_expression_input.js | 2 +- .../public/lib/_tests_/calculate_interval.js | 65 -------- .../public/panels/timechart/schema.ts | 6 +- .../core_plugins/timelion/server/plugin.ts | 62 -------- .../timelion/server/routes/index.ts | 32 ---- .../timelion/server/routes/run.ts | 125 --------------- .../public/components/panel.tsx | 2 +- .../components/timelion_expression_input.tsx | 5 +- .../timelion_expression_input_helpers.test.ts | 2 +- .../timelion_expression_input_helpers.ts | 7 +- .../public/helpers/arg_value_suggestions.ts | 2 +- .../public/helpers/panel_utils.ts | 2 +- .../timelion/common}/chain.peg | 0 .../common/lib/calculate_interval.test.ts | 66 ++++++++ .../common/lib/calculate_interval.ts | 4 +- .../timelion}/common/lib/index.ts | 0 .../timelion}/common/lib/to_milliseconds.ts | 0 .../timelion}/common/types.ts | 0 src/plugins/timelion/server/config.ts | 1 + .../timelion/server/fit_functions/average.js | 0 .../server/fit_functions/average.test.js} | 2 +- .../timelion/server/fit_functions/carry.js | 0 .../server/fit_functions/carry.test.js} | 2 +- .../timelion/server/fit_functions/nearest.js | 0 .../timelion/server/fit_functions/none.js | 0 .../timelion/server/fit_functions/scale.js | 0 .../timelion/server/handlers/chain_runner.js | 8 +- .../timelion/server/handlers/lib/arg_type.js | 0 .../server/handlers/lib/index_arguments.js | 0 .../server/handlers/lib/parse_sheet.js | 5 +- .../server/handlers/lib/parse_sheet.test.js} | 2 +- .../server/handlers/lib/preprocess_chain.js | 2 +- .../handlers/lib/reposition_arguments.js | 0 .../timelion/server/handlers/lib/tl_config.js | 0 .../server/handlers/lib/validate_arg.js | 0 .../server/handlers/lib/validate_time.js | 2 +- .../timelion/server/lib/alter.js | 0 .../timelion/server/lib/as_sorted.js} | 2 +- .../timelion/server/lib/build_target.js | 0 .../timelion/server/lib/classes/chainable.js | 0 .../timelion/server/lib/classes/datasource.js | 0 .../server/lib/classes/timelion_function.d.ts | 2 +- .../server/lib/classes/timelion_function.js | 0 .../timelion/server/lib/config_manager.ts} | 26 +++- .../timelion/server/lib/functions_md.js | 0 .../server/lib/get_namespaced_settings.js | 2 +- .../timelion/server/lib/load_functions.d.ts | 0 .../timelion/server/lib/load_functions.js | 18 +-- .../server/lib/load_functions.test.js} | 2 +- .../timelion/server/lib/offset_time.js | 0 .../timelion/server/lib/offset_time.test.js | 0 .../server/lib/process_function_definition.js | 0 .../timelion/server/lib/reduce.js | 0 .../timelion/server/lib/split_interval.js | 0 .../timelion/server/lib/unzip_pairs.js} | 0 src/plugins/timelion/server/plugin.ts | 46 +++++- .../timelion/server/routes/functions.ts} | 22 +-- src/plugins/timelion/server/routes/run.ts | 144 ++++++++++++++++++ .../timelion/server/routes/validate_es.ts} | 47 +++--- .../timelion/server/series_functions/abs.js | 0 .../server/series_functions/abs.test.js} | 4 +- .../aggregate/aggregate.test.js} | 9 +- .../server/series_functions/aggregate/avg.js | 0 .../series_functions/aggregate/cardinality.js | 0 .../series_functions/aggregate/first.js | 0 .../series_functions/aggregate/index.js | 0 .../server/series_functions/aggregate/last.js | 0 .../server/series_functions/aggregate/max.js | 0 .../server/series_functions/aggregate/min.js | 0 .../server/series_functions/aggregate/sum.js | 0 .../timelion/server/series_functions/bars.js | 0 .../server/series_functions/bars.test.js} | 4 +- .../timelion/server/series_functions/color.js | 0 .../server/series_functions/color.test.js} | 4 +- .../server/series_functions/condition.js | 0 .../series_functions/condition.test.js} | 4 +- .../timelion/server/series_functions/cusum.js | 0 .../server/series_functions/cusum.test.js} | 4 +- .../server/series_functions/derivative.js | 0 .../series_functions/derivative.test.js} | 4 +- .../server/series_functions/divide.js | 0 .../server/series_functions/divide.test.js} | 4 +- .../server/series_functions/es/es.test.js} | 48 +++--- .../server/series_functions/es/index.js | 14 +- .../series_functions/es/lib/agg_body.js | 0 .../es/lib/agg_response_to_series_list.js | 0 .../series_functions/es/lib/build_request.js | 0 .../es/lib/create_date_agg.js | 0 .../timelion/server/series_functions/first.js | 0 .../server/series_functions/first.test.js} | 4 +- .../timelion/server/series_functions/fit.js | 0 .../server/series_functions/fit.test.js} | 2 +- .../series_functions/fixtures/bucket_list.js} | 0 .../series_functions}/fixtures/es_response.js | 2 + .../series_functions/fixtures/series_list.js} | 2 +- .../series_functions/fixtures/tl_config.js} | 49 ++---- .../server/series_functions/graphite.js | 2 +- .../server/series_functions/graphite.test.js} | 15 +- .../series_functions}/helpers/get_series.js | 0 .../helpers/get_series_list.js | 0 .../helpers/get_single_series_list.js | 4 +- .../helpers/invoke_series_fn.js | 4 +- .../timelion/server/series_functions/hide.js | 0 .../server/series_functions/hide.test.js} | 4 +- .../server/series_functions/holt/index.js | 2 +- .../server/series_functions/holt/lib/des.js | 0 .../server/series_functions/holt/lib/ses.js | 0 .../server/series_functions/holt/lib/tes.js | 0 .../timelion/server/series_functions/label.js | 0 .../server/series_functions/label.test.js} | 4 +- .../server/series_functions/legend.js | 2 +- .../server/series_functions/legend.test.js} | 4 +- .../timelion/server/series_functions/lines.js | 0 .../server/series_functions/lines.test.js} | 4 +- .../timelion/server/series_functions/log.js | 0 .../server/series_functions/log.test.js} | 4 +- .../timelion/server/series_functions/max.js | 0 .../server/series_functions/max.test.js} | 4 +- .../timelion/server/series_functions/min.js | 0 .../server/series_functions/min.test.js} | 4 +- .../server/series_functions/movingaverage.js | 2 +- .../series_functions/movingaverage.test.js} | 4 +- .../server/series_functions/movingstd.js | 0 .../series_functions/movingstd.test.js} | 2 +- .../server/series_functions/multiply.js | 0 .../server/series_functions/multiply.test.js} | 4 +- .../server/series_functions/points.js | 0 .../server/series_functions/points.test.js} | 4 +- .../server/series_functions/precision.js | 0 .../series_functions/precision.test.js} | 4 +- .../timelion/server/series_functions/props.js | 0 .../server/series_functions/quandl.js | 3 - .../server/series_functions/quandl.test.js} | 82 +++++----- .../timelion/server/series_functions/range.js | 0 .../server/series_functions/range.test.js} | 4 +- .../server/series_functions/scale_interval.js | 2 +- .../series_functions/scale_interval.test.js} | 4 +- .../server/series_functions/static.js | 0 .../server/series_functions/static.test.js} | 2 +- .../server/series_functions/subtract.js | 0 .../server/series_functions/subtract.test.js} | 4 +- .../timelion/server/series_functions/sum.js | 0 .../server/series_functions/sum.test.js} | 4 +- .../timelion/server/series_functions/title.js | 0 .../server/series_functions/title.test.js} | 4 +- .../server/series_functions/trend/index.js | 0 .../series_functions/trend/lib/regress.js | 0 .../timelion/server/series_functions/trim.js | 0 .../server/series_functions/trim.test.js} | 4 +- .../server/series_functions/worldbank.js | 6 +- .../series_functions/worldbank_indicators.js | 4 +- .../timelion/server/series_functions/yaxis.js | 0 .../server/series_functions/yaxis.test.js} | 4 +- .../timelion/server}/timelion.json | 0 .../timelion/server/types.ts | 0 157 files changed, 517 insertions(+), 573 deletions(-) delete mode 100644 src/legacy/core_plugins/timelion/public/lib/_tests_/calculate_interval.js delete mode 100644 src/legacy/core_plugins/timelion/server/plugin.ts delete mode 100644 src/legacy/core_plugins/timelion/server/routes/index.ts delete mode 100644 src/legacy/core_plugins/timelion/server/routes/run.ts rename src/{legacy/core_plugins/vis_type_timelion/public => plugins/timelion/common}/chain.peg (100%) create mode 100644 src/plugins/timelion/common/lib/calculate_interval.test.ts rename src/{legacy/core_plugins/vis_type_timelion => plugins/timelion}/common/lib/calculate_interval.ts (100%) rename src/{legacy/core_plugins/vis_type_timelion => plugins/timelion}/common/lib/index.ts (100%) rename src/{legacy/core_plugins/vis_type_timelion => plugins/timelion}/common/lib/to_milliseconds.ts (100%) rename src/{legacy/core_plugins/vis_type_timelion => plugins/timelion}/common/types.ts (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/fit_functions/average.js (100%) rename src/{legacy/core_plugins/timelion/server/fit_functions/__tests__/average.js => plugins/timelion/server/fit_functions/average.test.js} (99%) rename src/{legacy/core_plugins => plugins}/timelion/server/fit_functions/carry.js (100%) rename src/{legacy/core_plugins/timelion/server/fit_functions/__tests__/carry.js => plugins/timelion/server/fit_functions/carry.test.js} (98%) rename src/{legacy/core_plugins => plugins}/timelion/server/fit_functions/nearest.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/fit_functions/none.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/fit_functions/scale.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/handlers/chain_runner.js (95%) rename src/{legacy/core_plugins => plugins}/timelion/server/handlers/lib/arg_type.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/handlers/lib/index_arguments.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/handlers/lib/parse_sheet.js (93%) rename src/{legacy/core_plugins/timelion/server/handlers/__tests__/parse_sheet.js => plugins/timelion/server/handlers/lib/parse_sheet.test.js} (97%) rename src/{legacy/core_plugins => plugins}/timelion/server/handlers/lib/preprocess_chain.js (95%) rename src/{legacy/core_plugins => plugins}/timelion/server/handlers/lib/reposition_arguments.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/handlers/lib/tl_config.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/handlers/lib/validate_arg.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/handlers/lib/validate_time.js (96%) rename src/{legacy/core_plugins => plugins}/timelion/server/lib/alter.js (100%) rename src/{legacy/core_plugins/timelion/server/lib/asSorted.js => plugins/timelion/server/lib/as_sorted.js} (95%) rename src/{legacy/core_plugins => plugins}/timelion/server/lib/build_target.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/lib/classes/chainable.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/lib/classes/datasource.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/lib/classes/timelion_function.d.ts (93%) rename src/{legacy/core_plugins => plugins}/timelion/server/lib/classes/timelion_function.js (100%) rename src/{legacy/core_plugins/timelion/server/index.ts => plugins/timelion/server/lib/config_manager.ts} (56%) rename src/{legacy/core_plugins => plugins}/timelion/server/lib/functions_md.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/lib/get_namespaced_settings.js (97%) rename src/{legacy/core_plugins => plugins}/timelion/server/lib/load_functions.d.ts (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/lib/load_functions.js (84%) rename src/{legacy/core_plugins/timelion/server/lib/__tests__/load_functions.js => plugins/timelion/server/lib/load_functions.test.js} (95%) rename src/{legacy/core_plugins => plugins}/timelion/server/lib/offset_time.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/lib/offset_time.test.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/lib/process_function_definition.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/lib/reduce.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/lib/split_interval.js (100%) rename src/{legacy/core_plugins/timelion/server/lib/unzipPairs.js => plugins/timelion/server/lib/unzip_pairs.js} (100%) rename src/{legacy/core_plugins/timelion/server/routes/functions.js => plugins/timelion/server/routes/functions.ts} (68%) create mode 100644 src/plugins/timelion/server/routes/run.ts rename src/{legacy/core_plugins/timelion/server/routes/validate_es.js => plugins/timelion/server/routes/validate_es.ts} (65%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/abs.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/abs.js => plugins/timelion/server/series_functions/abs.test.js} (94%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/aggregate.js => plugins/timelion/server/series_functions/aggregate/aggregate.test.js} (89%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/aggregate/avg.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/aggregate/cardinality.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/aggregate/first.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/aggregate/index.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/aggregate/last.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/aggregate/max.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/aggregate/min.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/aggregate/sum.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/bars.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/bars.js => plugins/timelion/server/series_functions/bars.test.js} (95%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/color.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/color.js => plugins/timelion/server/series_functions/color.test.js} (96%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/condition.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/condition.js => plugins/timelion/server/series_functions/condition.test.js} (97%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/cusum.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/cusum.js => plugins/timelion/server/series_functions/cusum.test.js} (93%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/derivative.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/derivative.js => plugins/timelion/server/series_functions/derivative.test.js} (92%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/divide.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/divide.js => plugins/timelion/server/series_functions/divide.test.js} (92%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/es.js => plugins/timelion/server/series_functions/es/es.test.js} (94%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/es/index.js (91%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/es/lib/agg_body.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/es/lib/agg_response_to_series_list.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/es/lib/build_request.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/es/lib/create_date_agg.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/first.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/first.js => plugins/timelion/server/series_functions/first.test.js} (92%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/fit.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/fit.js => plugins/timelion/server/series_functions/fit.test.js} (98%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/bucketList.js => plugins/timelion/server/series_functions/fixtures/bucket_list.js} (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__ => plugins/timelion/server/series_functions}/fixtures/es_response.js (99%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/seriesList.js => plugins/timelion/server/series_functions/fixtures/series_list.js} (97%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/tlConfig.js => plugins/timelion/server/series_functions/fixtures/tl_config.js} (52%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/graphite.js (97%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/graphite.js => plugins/timelion/server/series_functions/graphite.test.js} (85%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__ => plugins/timelion/server/series_functions}/helpers/get_series.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__ => plugins/timelion/server/series_functions}/helpers/get_series_list.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__ => plugins/timelion/server/series_functions}/helpers/get_single_series_list.js (90%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__ => plugins/timelion/server/series_functions}/helpers/invoke_series_fn.js (89%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/hide.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/hide.js => plugins/timelion/server/series_functions/hide.test.js} (93%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/holt/index.js (98%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/holt/lib/des.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/holt/lib/ses.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/holt/lib/tes.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/label.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/label.js => plugins/timelion/server/series_functions/label.test.js} (94%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/legend.js (98%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/legend.js => plugins/timelion/server/series_functions/legend.test.js} (96%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/lines.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/lines.js => plugins/timelion/server/series_functions/lines.test.js} (95%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/log.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/log.js => plugins/timelion/server/series_functions/log.test.js} (93%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/max.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/max.js => plugins/timelion/server/series_functions/max.test.js} (93%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/min.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/min.js => plugins/timelion/server/series_functions/min.test.js} (93%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/movingaverage.js (98%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/movingaverage.js => plugins/timelion/server/series_functions/movingaverage.test.js} (96%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/movingstd.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/movingstd.js => plugins/timelion/server/series_functions/movingstd.test.js} (98%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/multiply.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/multiply.js => plugins/timelion/server/series_functions/multiply.test.js} (92%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/points.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/points.js => plugins/timelion/server/series_functions/points.test.js} (96%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/precision.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/precision.js => plugins/timelion/server/series_functions/precision.test.js} (93%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/props.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/quandl.js (98%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/quandl.js => plugins/timelion/server/series_functions/quandl.test.js} (55%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/range.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/range.js => plugins/timelion/server/series_functions/range.test.js} (93%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/scale_interval.js (96%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/scale_interval.js => plugins/timelion/server/series_functions/scale_interval.test.js} (92%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/static.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/static.js => plugins/timelion/server/series_functions/static.test.js} (97%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/subtract.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/subtract.js => plugins/timelion/server/series_functions/subtract.test.js} (97%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/sum.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/sum.js => plugins/timelion/server/series_functions/sum.test.js} (93%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/title.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/title.js => plugins/timelion/server/series_functions/title.test.js} (93%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/trend/index.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/trend/lib/regress.js (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/trim.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/trim.js => plugins/timelion/server/series_functions/trim.test.js} (95%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/worldbank.js (96%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/worldbank_indicators.js (95%) rename src/{legacy/core_plugins => plugins}/timelion/server/series_functions/yaxis.js (100%) rename src/{legacy/core_plugins/timelion/server/series_functions/__tests__/yaxis.js => plugins/timelion/server/series_functions/yaxis.test.js} (97%) rename src/{legacy/core_plugins/timelion => plugins/timelion/server}/timelion.json (100%) rename src/{legacy/core_plugins => plugins}/timelion/server/types.ts (100%) diff --git a/.i18nrc.json b/.i18nrc.json index 907310b32e35c..f03ced2b85093 100644 --- a/.i18nrc.json +++ b/.i18nrc.json @@ -32,7 +32,7 @@ "statusPage": "src/legacy/core_plugins/status_page", "telemetry": "src/legacy/core_plugins/telemetry", "tileMap": "src/legacy/core_plugins/tile_map", - "timelion": ["src/legacy/core_plugins/timelion", "src/legacy/core_plugins/vis_type_timelion"], + "timelion": ["src/legacy/core_plugins/timelion", "src/legacy/core_plugins/vis_type_timelion", "src/plugins/timelion"], "uiActions": "src/plugins/ui_actions", "visTypeMarkdown": "src/legacy/core_plugins/vis_type_markdown", "visTypeMetric": "src/legacy/core_plugins/vis_type_metric", diff --git a/src/legacy/core_plugins/timelion/index.ts b/src/legacy/core_plugins/timelion/index.ts index d725327e2365b..42d4e04184a25 100644 --- a/src/legacy/core_plugins/timelion/index.ts +++ b/src/legacy/core_plugins/timelion/index.ts @@ -21,10 +21,7 @@ import { resolve } from 'path'; import { i18n } from '@kbn/i18n'; import { Legacy } from 'kibana'; import { LegacyPluginApi, LegacyPluginInitializer } from 'src/legacy/plugin_discovery/types'; -import { CoreSetup, PluginInitializerContext } from 'src/core/server'; import { DEFAULT_APP_CATEGORIES } from '../../../core/utils'; -import { plugin } from './server'; -import { CustomCoreSetup } from './server/plugin'; const experimentalLabel = i18n.translate('timelion.uiSettings.experimentalLabel', { defaultMessage: 'experimental', @@ -195,12 +192,6 @@ const timelionPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPl }, }, }, - init: (server: Legacy.Server) => { - const initializerContext = {} as PluginInitializerContext; - const core = { http: { server } } as CoreSetup & CustomCoreSetup; - - plugin(initializerContext).setup(core); - }, }); // eslint-disable-next-line import/no-default-export diff --git a/src/legacy/core_plugins/timelion/public/directives/timelion_expression_input.js b/src/legacy/core_plugins/timelion/public/directives/timelion_expression_input.js index 1fec243a277f8..57262fda55e48 100644 --- a/src/legacy/core_plugins/timelion/public/directives/timelion_expression_input.js +++ b/src/legacy/core_plugins/timelion/public/directives/timelion_expression_input.js @@ -43,7 +43,7 @@ import _ from 'lodash'; import $ from 'jquery'; import PEG from 'pegjs'; -import grammar from 'raw-loader!../../../vis_type_timelion/public/chain.peg'; +import grammar from 'raw-loader!../../../../../plugins/timelion/common/chain.peg'; import timelionExpressionInputTemplate from './timelion_expression_input.html'; import { SUGGESTION_TYPE, diff --git a/src/legacy/core_plugins/timelion/public/lib/_tests_/calculate_interval.js b/src/legacy/core_plugins/timelion/public/lib/_tests_/calculate_interval.js deleted file mode 100644 index 77472dc89cd73..0000000000000 --- a/src/legacy/core_plugins/timelion/public/lib/_tests_/calculate_interval.js +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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. - */ - -const filename = require('path').basename(__filename); -const fn = require(`../calculate_interval`); -const moment = require('moment'); -const expect = require('chai').expect; - -const from = (count, unit) => - moment() - .subtract(count, unit) - .valueOf(); -const to = moment().valueOf(); -const size = 200; -const min = '1ms'; - -describe(filename, () => { - it('Exports a function', () => { - expect(fn).to.be.a('function'); - }); - - it('Only calculates when interval = auto', () => { - const partialFn = interval => fn(from(1, 'y'), to, size, interval, min); - expect(partialFn('1ms')).to.equal('1ms'); - expect(partialFn('bag_of_beans')).to.equal('bag_of_beans'); - expect(partialFn('auto')).to.not.equal('auto'); - }); - - it('Calculates nice round intervals', () => { - const partialFn = (count, unit) => fn(from(count, unit), to, size, 'auto', min); - expect(partialFn(15, 'm')).to.equal('1s'); - expect(partialFn(1, 'h')).to.equal('30s'); - expect(partialFn(3, 'd')).to.equal('30m'); - expect(partialFn(1, 'w')).to.equal('1h'); - expect(partialFn(1, 'y')).to.equal('24h'); - expect(partialFn(100, 'y')).to.equal('1y'); - }); - - it('Does not calculate an interval lower than the minimum', () => { - const partialFn = (count, unit) => fn(from(count, unit), to, size, 'auto', '1m'); - expect(partialFn(5, 's')).to.equal('1m'); - expect(partialFn(15, 'm')).to.equal('1m'); - expect(partialFn(1, 'h')).to.equal('1m'); - expect(partialFn(3, 'd')).to.equal('30m'); - expect(partialFn(1, 'w')).to.equal('1h'); - expect(partialFn(1, 'y')).to.equal('24h'); - expect(partialFn(100, 'y')).to.equal('1y'); - }); -}); diff --git a/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts b/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts index 57ee99f5268b0..cd40cbfa89ffe 100644 --- a/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts +++ b/src/legacy/core_plugins/timelion/public/panels/timechart/schema.ts @@ -24,7 +24,11 @@ import moment from 'moment-timezone'; import { timefilter } from 'ui/timefilter'; // @ts-ignore import observeResize from '../../lib/observe_resize'; -import { calculateInterval, DEFAULT_TIME_FORMAT } from '../../../../vis_type_timelion/common/lib'; +import { + calculateInterval, + DEFAULT_TIME_FORMAT, + // @ts-ignore +} from '../../../../../../plugins/timelion/common/lib'; import { tickFormatters } from '../../../../vis_type_timelion/public/helpers/tick_formatters'; import { TimelionVisualizationDependencies } from '../../plugin'; import { xaxisFormatterProvider } from '../../../../vis_type_timelion/public/helpers/xaxis_formatter'; diff --git a/src/legacy/core_plugins/timelion/server/plugin.ts b/src/legacy/core_plugins/timelion/server/plugin.ts deleted file mode 100644 index c94277ebc7adc..0000000000000 --- a/src/legacy/core_plugins/timelion/server/plugin.ts +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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 { Legacy } from 'kibana'; -import { i18n } from '@kbn/i18n'; -import { PluginInitializerContext, CoreSetup } from 'kibana/server'; - -import loadFunctions, { LoadFunctions } from './lib/load_functions'; -import { initRoutes } from './routes'; - -function getFunction(functions: LoadFunctions, name: string) { - if (functions[name]) { - return functions[name]; - } - - throw new Error( - i18n.translate('timelion.noFunctionErrorMessage', { - defaultMessage: 'No such function: {name}', - values: { name }, - }) - ); -} - -// TODO: Remove as CoreSetup is completed. -export interface CustomCoreSetup { - http: { - server: Legacy.Server; - }; -} - -export class TimelionServerPlugin { - public initializerContext: PluginInitializerContext; - - constructor(initializerContext: PluginInitializerContext) { - this.initializerContext = initializerContext; - } - - public setup(core: CoreSetup & CustomCoreSetup) { - const { server } = core.http; - const functions = loadFunctions('series_functions'); - - server.expose('functions', functions); - server.expose('getFunction', (name: string) => getFunction(functions, name)); - - initRoutes(server); - } -} diff --git a/src/legacy/core_plugins/timelion/server/routes/index.ts b/src/legacy/core_plugins/timelion/server/routes/index.ts deleted file mode 100644 index b6438c81ef002..0000000000000 --- a/src/legacy/core_plugins/timelion/server/routes/index.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 { Legacy } from 'kibana'; - -// @ts-ignore -import { runRoute } from './run'; -// @ts-ignore -import { functionsRoute } from './functions'; -// @ts-ignore -import { validateEsRoute } from './validate_es'; - -export function initRoutes(server: Legacy.Server) { - runRoute(server); - functionsRoute(server); - validateEsRoute(server); -} diff --git a/src/legacy/core_plugins/timelion/server/routes/run.ts b/src/legacy/core_plugins/timelion/server/routes/run.ts deleted file mode 100644 index 17f87825cd8b0..0000000000000 --- a/src/legacy/core_plugins/timelion/server/routes/run.ts +++ /dev/null @@ -1,125 +0,0 @@ -/* - * 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 Joi from 'joi'; -import Bluebird from 'bluebird'; -import _ from 'lodash'; -import { Legacy } from 'kibana'; -// @ts-ignore -import chainRunnerFn from '../handlers/chain_runner.js'; -// @ts-ignore -import getNamespacesSettings from '../lib/get_namespaced_settings'; -// @ts-ignore -import getTlConfig from '../handlers/lib/tl_config'; - -const timelionDefaults = getNamespacesSettings(); - -export interface TimelionRequestQuery { - payload: { - sheet: string[]; - extended?: { - es: { - filter: { - bool: { - filter: string[] | object; - must: string[]; - should: string[]; - must_not: string[]; - }; - }; - }; - }; - }; - time?: { - from?: string; - interval: string; - timezone: string; - to?: string; - }; -} - -function formatErrorResponse(e: Error, h: Legacy.ResponseToolkit) { - return h - .response({ - title: e.toString(), - message: e.toString(), - }) - .code(500); -} - -const requestPayload = { - payload: Joi.object({ - sheet: Joi.array() - .items(Joi.string()) - .required(), - extended: Joi.object({ - es: Joi.object({ - filter: Joi.object({ - bool: Joi.object({ - filter: Joi.array().allow(null), - must: Joi.array().allow(null), - should: Joi.array().allow(null), - must_not: Joi.array().allow(null), - }), - }), - }), - }).optional(), - time: Joi.object({ - from: Joi.string(), - interval: Joi.string().required(), - timezone: Joi.string().required(), - to: Joi.string(), - }).required(), - }), -}; - -export function runRoute(server: Legacy.Server) { - server.route({ - method: 'POST', - path: '/api/timelion/run', - options: { - validate: requestPayload, - }, - handler: async (request: Legacy.Request & TimelionRequestQuery, h: Legacy.ResponseToolkit) => { - try { - const uiSettings = await request.getUiSettingsService().getAll(); - - const tlConfig = getTlConfig({ - server, - request, - settings: _.defaults(uiSettings, timelionDefaults), // Just in case they delete some setting. - }); - const chainRunner = chainRunnerFn(tlConfig); - const sheet = await Bluebird.all(chainRunner.processRequest(request.payload)); - - return { - sheet, - stats: chainRunner.getStats(), - }; - } catch (err) { - server.log(['timelion', 'error'], `${err.toString()}: ${err.stack}`); - // TODO Maybe we should just replace everywhere we throw with Boom? Probably. - if (err.isBoom) { - return err; - } else { - return formatErrorResponse(err, h); - } - } - }, - }); -} diff --git a/src/legacy/core_plugins/vis_type_timelion/public/components/panel.tsx b/src/legacy/core_plugins/vis_type_timelion/public/components/panel.tsx index 6095ba28443b8..3b42fa7dfcbb8 100644 --- a/src/legacy/core_plugins/vis_type_timelion/public/components/panel.tsx +++ b/src/legacy/core_plugins/vis_type_timelion/public/components/panel.tsx @@ -24,7 +24,7 @@ import { debounce, compact, get, each, cloneDeep, last, map } from 'lodash'; import { useKibana } from '../../../../../plugins/kibana_react/public'; import '../flot'; -import { DEFAULT_TIME_FORMAT } from '../../common/lib'; +import { DEFAULT_TIME_FORMAT } from '../../../../../plugins/timelion/common/lib'; import { buildSeriesData, diff --git a/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input.tsx b/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input.tsx index fa79e4eb6871a..620bc26d9184d 100644 --- a/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input.tsx +++ b/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input.tsx @@ -24,8 +24,11 @@ import * as monacoEditor from 'monaco-editor/esm/vs/editor/editor.api'; import { CodeEditor, useKibana } from '../../../../../plugins/kibana_react/public'; import { suggest, getSuggestion } from './timelion_expression_input_helpers'; -import { ITimelionFunction, TimelionFunctionArgs } from '../../common/types'; import { getArgValueSuggestions } from '../helpers/arg_value_suggestions'; +import { + ITimelionFunction, + TimelionFunctionArgs, +} from '../../../../../plugins/timelion/common/types'; const LANGUAGE_ID = 'timelion_expression'; monacoEditor.languages.register({ id: LANGUAGE_ID }); diff --git a/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input_helpers.test.ts b/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input_helpers.test.ts index 18a0c0872dc03..cf40d2f791fc2 100644 --- a/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input_helpers.test.ts +++ b/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input_helpers.test.ts @@ -22,7 +22,7 @@ import { getArgValueSuggestions } from '../helpers/arg_value_suggestions'; import { setIndexPatterns, setSavedObjectsClient } from '../helpers/plugin_services'; import { IndexPatterns } from 'src/plugins/data/public'; import { SavedObjectsClient } from 'kibana/public'; -import { ITimelionFunction } from '../../common/types'; +import { ITimelionFunction } from '../../../../../plugins/timelion/common/types'; describe('Timelion expression suggestions', () => { setIndexPatterns({} as IndexPatterns); diff --git a/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input_helpers.ts b/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input_helpers.ts index d7818680c9543..93b6a0d463c01 100644 --- a/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input_helpers.ts +++ b/src/legacy/core_plugins/vis_type_timelion/public/components/timelion_expression_input_helpers.ts @@ -18,16 +18,19 @@ */ import { get, startsWith } from 'lodash'; +import { i18n } from '@kbn/i18n'; import * as monacoEditor from 'monaco-editor/esm/vs/editor/editor.api'; -import { i18n } from '@kbn/i18n'; import { Parser } from 'pegjs'; // @ts-ignore import { parse } from '../_generated_/chain'; -import { ITimelionFunction, TimelionFunctionArgs } from '../../common/types'; import { ArgValueSuggestions, FunctionArg, Location } from '../helpers/arg_value_suggestions'; +import { + ITimelionFunction, + TimelionFunctionArgs, +} from '../../../../../plugins/timelion/common/types'; export enum SUGGESTION_TYPE { ARGUMENTS = 'arguments', diff --git a/src/legacy/core_plugins/vis_type_timelion/public/helpers/arg_value_suggestions.ts b/src/legacy/core_plugins/vis_type_timelion/public/helpers/arg_value_suggestions.ts index 8d133de51f6d9..e293a662a4ed7 100644 --- a/src/legacy/core_plugins/vis_type_timelion/public/helpers/arg_value_suggestions.ts +++ b/src/legacy/core_plugins/vis_type_timelion/public/helpers/arg_value_suggestions.ts @@ -18,8 +18,8 @@ */ import { get } from 'lodash'; -import { TimelionFunctionArgs } from '../../common/types'; import { getIndexPatterns, getSavedObjectsClient } from './plugin_services'; +import { TimelionFunctionArgs } from '../../../../../plugins/timelion/common/types'; export interface Location { min: number; diff --git a/src/legacy/core_plugins/vis_type_timelion/public/helpers/panel_utils.ts b/src/legacy/core_plugins/vis_type_timelion/public/helpers/panel_utils.ts index db29d9112be8e..f932e5ee4b2f4 100644 --- a/src/legacy/core_plugins/vis_type_timelion/public/helpers/panel_utils.ts +++ b/src/legacy/core_plugins/vis_type_timelion/public/helpers/panel_utils.ts @@ -23,7 +23,7 @@ import moment, { Moment } from 'moment-timezone'; import { TimefilterContract } from 'src/plugins/data/public'; import { IUiSettingsClient } from 'kibana/public'; -import { calculateInterval } from '../../common/lib'; +import { calculateInterval } from '../../../../../plugins/timelion/common/lib'; import { xaxisFormatterProvider } from './xaxis_formatter'; import { Series } from './timelion_request_handler'; diff --git a/src/legacy/core_plugins/vis_type_timelion/public/chain.peg b/src/plugins/timelion/common/chain.peg similarity index 100% rename from src/legacy/core_plugins/vis_type_timelion/public/chain.peg rename to src/plugins/timelion/common/chain.peg diff --git a/src/plugins/timelion/common/lib/calculate_interval.test.ts b/src/plugins/timelion/common/lib/calculate_interval.test.ts new file mode 100644 index 0000000000000..17e8a01911071 --- /dev/null +++ b/src/plugins/timelion/common/lib/calculate_interval.test.ts @@ -0,0 +1,66 @@ +/* + * 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 { calculateInterval as fn } from './calculate_interval'; + +import moment, { unitOfTime } from 'moment'; + +const from = (count: number, unit: unitOfTime.DurationConstructor) => + moment() + .subtract(count, unit) + .valueOf(); +const to = moment().valueOf(); +const size = 200; +const min = '1ms'; + +describe('calculate_interval', () => { + it('Exports a function', () => { + expect(typeof fn).toBe('function'); + }); + + it('Only calculates when interval = auto', () => { + const partialFn = (interval: string) => fn(from(1, 'y'), to, size, interval, min); + expect(partialFn('1ms')).toEqual('1ms'); + expect(partialFn('bag_of_beans')).toEqual('bag_of_beans'); + expect(partialFn('auto')).not.toEqual('auto'); + }); + + it('Calculates nice round intervals', () => { + const partialFn = (count: number, unit: unitOfTime.DurationConstructor) => + fn(from(count, unit), to, size, 'auto', min); + expect(partialFn(15, 'm')).toEqual('1s'); + expect(partialFn(1, 'h')).toEqual('30s'); + expect(partialFn(3, 'd')).toEqual('30m'); + expect(partialFn(1, 'w')).toEqual('1h'); + expect(partialFn(1, 'y')).toEqual('24h'); + expect(partialFn(100, 'y')).toEqual('1y'); + }); + + it('Does not calculate an interval lower than the minimum', () => { + const partialFn = (count: number, unit: unitOfTime.DurationConstructor) => + fn(from(count, unit), to, size, 'auto', '1m'); + expect(partialFn(5, 's')).toEqual('1m'); + expect(partialFn(15, 'm')).toEqual('1m'); + expect(partialFn(1, 'h')).toEqual('1m'); + expect(partialFn(3, 'd')).toEqual('30m'); + expect(partialFn(1, 'w')).toEqual('1h'); + expect(partialFn(1, 'y')).toEqual('24h'); + expect(partialFn(100, 'y')).toEqual('1y'); + }); +}); diff --git a/src/legacy/core_plugins/vis_type_timelion/common/lib/calculate_interval.ts b/src/plugins/timelion/common/lib/calculate_interval.ts similarity index 100% rename from src/legacy/core_plugins/vis_type_timelion/common/lib/calculate_interval.ts rename to src/plugins/timelion/common/lib/calculate_interval.ts index 328c634ea5153..f724f4723a929 100644 --- a/src/legacy/core_plugins/vis_type_timelion/common/lib/calculate_interval.ts +++ b/src/plugins/timelion/common/lib/calculate_interval.ts @@ -17,10 +17,10 @@ * under the License. */ -import { toMS } from './to_milliseconds'; - // Totally cribbed this from Kibana 3. // I bet there's something similar in the Kibana 4 code. Somewhere. Somehow. +import { toMS } from './to_milliseconds'; + function roundInterval(interval: number) { switch (true) { case interval <= 500: // <= 0.5s diff --git a/src/legacy/core_plugins/vis_type_timelion/common/lib/index.ts b/src/plugins/timelion/common/lib/index.ts similarity index 100% rename from src/legacy/core_plugins/vis_type_timelion/common/lib/index.ts rename to src/plugins/timelion/common/lib/index.ts diff --git a/src/legacy/core_plugins/vis_type_timelion/common/lib/to_milliseconds.ts b/src/plugins/timelion/common/lib/to_milliseconds.ts similarity index 100% rename from src/legacy/core_plugins/vis_type_timelion/common/lib/to_milliseconds.ts rename to src/plugins/timelion/common/lib/to_milliseconds.ts diff --git a/src/legacy/core_plugins/vis_type_timelion/common/types.ts b/src/plugins/timelion/common/types.ts similarity index 100% rename from src/legacy/core_plugins/vis_type_timelion/common/types.ts rename to src/plugins/timelion/common/types.ts diff --git a/src/plugins/timelion/server/config.ts b/src/plugins/timelion/server/config.ts index a47d39beb7555..e76c878c0c6b1 100644 --- a/src/plugins/timelion/server/config.ts +++ b/src/plugins/timelion/server/config.ts @@ -22,6 +22,7 @@ import { schema } from '@kbn/config-schema'; export const ConfigSchema = schema.object( { ui: schema.object({ enabled: schema.boolean({ defaultValue: false }) }), + graphiteUrls: schema.maybe(schema.arrayOf(schema.string())), }, // This option should be removed as soon as we entirely migrate config from legacy Timelion plugin. { allowUnknowns: true } diff --git a/src/legacy/core_plugins/timelion/server/fit_functions/average.js b/src/plugins/timelion/server/fit_functions/average.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/fit_functions/average.js rename to src/plugins/timelion/server/fit_functions/average.js diff --git a/src/legacy/core_plugins/timelion/server/fit_functions/__tests__/average.js b/src/plugins/timelion/server/fit_functions/average.test.js similarity index 99% rename from src/legacy/core_plugins/timelion/server/fit_functions/__tests__/average.js rename to src/plugins/timelion/server/fit_functions/average.test.js index d30244610a124..2f61a29bc25b2 100644 --- a/src/legacy/core_plugins/timelion/server/fit_functions/__tests__/average.js +++ b/src/plugins/timelion/server/fit_functions/average.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../average`); +import fn from './average'; import moment from 'moment'; const expect = require('chai').expect; import _ from 'lodash'; diff --git a/src/legacy/core_plugins/timelion/server/fit_functions/carry.js b/src/plugins/timelion/server/fit_functions/carry.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/fit_functions/carry.js rename to src/plugins/timelion/server/fit_functions/carry.js diff --git a/src/legacy/core_plugins/timelion/server/fit_functions/__tests__/carry.js b/src/plugins/timelion/server/fit_functions/carry.test.js similarity index 98% rename from src/legacy/core_plugins/timelion/server/fit_functions/__tests__/carry.js rename to src/plugins/timelion/server/fit_functions/carry.test.js index 8e35d63618ae4..22608e0bf4988 100644 --- a/src/legacy/core_plugins/timelion/server/fit_functions/__tests__/carry.js +++ b/src/plugins/timelion/server/fit_functions/carry.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../carry`); +import fn from './carry'; import moment from 'moment'; const expect = require('chai').expect; import _ from 'lodash'; diff --git a/src/legacy/core_plugins/timelion/server/fit_functions/nearest.js b/src/plugins/timelion/server/fit_functions/nearest.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/fit_functions/nearest.js rename to src/plugins/timelion/server/fit_functions/nearest.js diff --git a/src/legacy/core_plugins/timelion/server/fit_functions/none.js b/src/plugins/timelion/server/fit_functions/none.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/fit_functions/none.js rename to src/plugins/timelion/server/fit_functions/none.js diff --git a/src/legacy/core_plugins/timelion/server/fit_functions/scale.js b/src/plugins/timelion/server/fit_functions/scale.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/fit_functions/scale.js rename to src/plugins/timelion/server/fit_functions/scale.js diff --git a/src/legacy/core_plugins/timelion/server/handlers/chain_runner.js b/src/plugins/timelion/server/handlers/chain_runner.js similarity index 95% rename from src/legacy/core_plugins/timelion/server/handlers/chain_runner.js rename to src/plugins/timelion/server/handlers/chain_runner.js index 9056362cb723a..9a87909b0a857 100644 --- a/src/legacy/core_plugins/timelion/server/handlers/chain_runner.js +++ b/src/plugins/timelion/server/handlers/chain_runner.js @@ -26,7 +26,7 @@ import parseSheet from './lib/parse_sheet.js'; import repositionArguments from './lib/reposition_arguments.js'; import indexArguments from './lib/index_arguments.js'; import validateTime from './lib/validate_time.js'; -import { calculateInterval } from '../../../vis_type_timelion/common/lib'; +import { calculateInterval } from '../../common/lib'; export default function chainRunner(tlConfig) { const preprocessChain = require('./lib/preprocess_chain')(tlConfig); @@ -41,7 +41,7 @@ export default function chainRunner(tlConfig) { // Invokes a modifier function, resolving arguments into series as needed function invoke(fnName, args) { - const functionDef = tlConfig.server.plugins.timelion.getFunction(fnName); + const functionDef = tlConfig.getFunction(fnName); function resolveArgument(item) { if (Array.isArray(item)) { @@ -51,7 +51,7 @@ export default function chainRunner(tlConfig) { if (_.isObject(item)) { switch (item.type) { case 'function': { - const itemFunctionDef = tlConfig.server.plugins.timelion.getFunction(item.function); + const itemFunctionDef = tlConfig.getFunction(item.function); if (itemFunctionDef.cacheKey && queryCache[itemFunctionDef.cacheKey(item)]) { stats.queryCount++; return Bluebird.resolve(_.cloneDeep(queryCache[itemFunctionDef.cacheKey(item)])); @@ -168,7 +168,7 @@ export default function chainRunner(tlConfig) { stats.queryTime = new Date().getTime(); _.each(queries, function(query, i) { - const functionDef = tlConfig.server.plugins.timelion.getFunction(query.function); + const functionDef = tlConfig.getFunction(query.function); const resolvedDatasource = resolvedDatasources[i]; if (resolvedDatasource.isRejected()) { diff --git a/src/legacy/core_plugins/timelion/server/handlers/lib/arg_type.js b/src/plugins/timelion/server/handlers/lib/arg_type.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/handlers/lib/arg_type.js rename to src/plugins/timelion/server/handlers/lib/arg_type.js diff --git a/src/legacy/core_plugins/timelion/server/handlers/lib/index_arguments.js b/src/plugins/timelion/server/handlers/lib/index_arguments.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/handlers/lib/index_arguments.js rename to src/plugins/timelion/server/handlers/lib/index_arguments.js diff --git a/src/legacy/core_plugins/timelion/server/handlers/lib/parse_sheet.js b/src/plugins/timelion/server/handlers/lib/parse_sheet.js similarity index 93% rename from src/legacy/core_plugins/timelion/server/handlers/lib/parse_sheet.js rename to src/plugins/timelion/server/handlers/lib/parse_sheet.js index 4957d3cb78b85..4880c73f42bb2 100644 --- a/src/legacy/core_plugins/timelion/server/handlers/lib/parse_sheet.js +++ b/src/plugins/timelion/server/handlers/lib/parse_sheet.js @@ -21,10 +21,7 @@ import { i18n } from '@kbn/i18n'; import fs from 'fs'; import path from 'path'; import _ from 'lodash'; -const grammar = fs.readFileSync( - path.resolve(__dirname, '../../../../vis_type_timelion/public/chain.peg'), - 'utf8' -); +const grammar = fs.readFileSync(path.resolve(__dirname, '../../../common/chain.peg'), 'utf8'); import PEG from 'pegjs'; const Parser = PEG.generate(grammar); diff --git a/src/legacy/core_plugins/timelion/server/handlers/__tests__/parse_sheet.js b/src/plugins/timelion/server/handlers/lib/parse_sheet.test.js similarity index 97% rename from src/legacy/core_plugins/timelion/server/handlers/__tests__/parse_sheet.js rename to src/plugins/timelion/server/handlers/lib/parse_sheet.test.js index 4ec2a88d3e68b..16d5f8b4a02bb 100644 --- a/src/legacy/core_plugins/timelion/server/handlers/__tests__/parse_sheet.js +++ b/src/plugins/timelion/server/handlers/lib/parse_sheet.test.js @@ -17,7 +17,7 @@ * under the License. */ -const parseSheet = require('../lib/parse_sheet'); +const parseSheet = require('./parse_sheet'); const expect = require('chai').expect; diff --git a/src/legacy/core_plugins/timelion/server/handlers/lib/preprocess_chain.js b/src/plugins/timelion/server/handlers/lib/preprocess_chain.js similarity index 95% rename from src/legacy/core_plugins/timelion/server/handlers/lib/preprocess_chain.js rename to src/plugins/timelion/server/handlers/lib/preprocess_chain.js index 5e5f274115ee2..6a667e36054ce 100644 --- a/src/legacy/core_plugins/timelion/server/handlers/lib/preprocess_chain.js +++ b/src/plugins/timelion/server/handlers/lib/preprocess_chain.js @@ -24,7 +24,7 @@ export default function preProcessChainFn(tlConfig) { queries = queries || {}; function validateAndStore(item) { if (_.isObject(item) && item.type === 'function') { - const functionDef = tlConfig.server.plugins.timelion.getFunction(item.function); + const functionDef = tlConfig.getFunction(item.function); if (functionDef.datasource) { queries[functionDef.cacheKey(item)] = item; diff --git a/src/legacy/core_plugins/timelion/server/handlers/lib/reposition_arguments.js b/src/plugins/timelion/server/handlers/lib/reposition_arguments.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/handlers/lib/reposition_arguments.js rename to src/plugins/timelion/server/handlers/lib/reposition_arguments.js diff --git a/src/legacy/core_plugins/timelion/server/handlers/lib/tl_config.js b/src/plugins/timelion/server/handlers/lib/tl_config.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/handlers/lib/tl_config.js rename to src/plugins/timelion/server/handlers/lib/tl_config.js diff --git a/src/legacy/core_plugins/timelion/server/handlers/lib/validate_arg.js b/src/plugins/timelion/server/handlers/lib/validate_arg.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/handlers/lib/validate_arg.js rename to src/plugins/timelion/server/handlers/lib/validate_arg.js diff --git a/src/legacy/core_plugins/timelion/server/handlers/lib/validate_time.js b/src/plugins/timelion/server/handlers/lib/validate_time.js similarity index 96% rename from src/legacy/core_plugins/timelion/server/handlers/lib/validate_time.js rename to src/plugins/timelion/server/handlers/lib/validate_time.js index db924e33be5e9..07157a9a8c6d9 100644 --- a/src/legacy/core_plugins/timelion/server/handlers/lib/validate_time.js +++ b/src/plugins/timelion/server/handlers/lib/validate_time.js @@ -20,7 +20,7 @@ import { i18n } from '@kbn/i18n'; import moment from 'moment'; -import { toMS } from '../../../../vis_type_timelion/common/lib'; +import { toMS } from '../../../common/lib/to_milliseconds'; export default function validateTime(time, tlConfig) { const span = moment.duration(moment(time.to).diff(moment(time.from))).asMilliseconds(); diff --git a/src/legacy/core_plugins/timelion/server/lib/alter.js b/src/plugins/timelion/server/lib/alter.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/alter.js rename to src/plugins/timelion/server/lib/alter.js diff --git a/src/legacy/core_plugins/timelion/server/lib/asSorted.js b/src/plugins/timelion/server/lib/as_sorted.js similarity index 95% rename from src/legacy/core_plugins/timelion/server/lib/asSorted.js rename to src/plugins/timelion/server/lib/as_sorted.js index ff20af78b4362..536145a6b8dcd 100644 --- a/src/legacy/core_plugins/timelion/server/lib/asSorted.js +++ b/src/plugins/timelion/server/lib/as_sorted.js @@ -18,7 +18,7 @@ */ import _ from 'lodash'; -import unzipPairs from './unzipPairs.js'; +import unzipPairs from './unzip_pairs.js'; export default function asSorted(timeValObject, fn) { const data = unzipPairs(timeValObject); diff --git a/src/legacy/core_plugins/timelion/server/lib/build_target.js b/src/plugins/timelion/server/lib/build_target.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/build_target.js rename to src/plugins/timelion/server/lib/build_target.js diff --git a/src/legacy/core_plugins/timelion/server/lib/classes/chainable.js b/src/plugins/timelion/server/lib/classes/chainable.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/classes/chainable.js rename to src/plugins/timelion/server/lib/classes/chainable.js diff --git a/src/legacy/core_plugins/timelion/server/lib/classes/datasource.js b/src/plugins/timelion/server/lib/classes/datasource.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/classes/datasource.js rename to src/plugins/timelion/server/lib/classes/datasource.js diff --git a/src/legacy/core_plugins/timelion/server/lib/classes/timelion_function.d.ts b/src/plugins/timelion/server/lib/classes/timelion_function.d.ts similarity index 93% rename from src/legacy/core_plugins/timelion/server/lib/classes/timelion_function.d.ts rename to src/plugins/timelion/server/lib/classes/timelion_function.d.ts index 08358b9d81f78..798902aa133de 100644 --- a/src/legacy/core_plugins/timelion/server/lib/classes/timelion_function.d.ts +++ b/src/plugins/timelion/server/lib/classes/timelion_function.d.ts @@ -17,7 +17,7 @@ * under the License. */ -import { TimelionFunctionArgs } from '../../../../vis_type_timelion/common/types'; +import { TimelionFunctionArgs } from '../../../common/types'; export interface TimelionFunctionInterface extends TimelionFunctionConfig { chainable: boolean; diff --git a/src/legacy/core_plugins/timelion/server/lib/classes/timelion_function.js b/src/plugins/timelion/server/lib/classes/timelion_function.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/classes/timelion_function.js rename to src/plugins/timelion/server/lib/classes/timelion_function.js diff --git a/src/legacy/core_plugins/timelion/server/index.ts b/src/plugins/timelion/server/lib/config_manager.ts similarity index 56% rename from src/legacy/core_plugins/timelion/server/index.ts rename to src/plugins/timelion/server/lib/config_manager.ts index 36af9ce7b85df..60d89f34a4c08 100644 --- a/src/legacy/core_plugins/timelion/server/index.ts +++ b/src/plugins/timelion/server/lib/config_manager.ts @@ -18,8 +18,28 @@ */ import { PluginInitializerContext } from 'kibana/server'; -import { TimelionServerPlugin as Plugin } from './plugin'; +import { TypeOf } from '@kbn/config-schema'; +import { ConfigSchema } from '../config'; -export function plugin(initializerContext: PluginInitializerContext) { - return new Plugin(initializerContext); +export class ConfigManager { + private esShardTimeout: number = 0; + private graphiteUrls: string[] = []; + + constructor(config: PluginInitializerContext['config']) { + config.create>().subscribe(configUpdate => { + this.graphiteUrls = configUpdate.graphiteUrls || []; + }); + + config.legacy.globalConfig$.subscribe(configUpdate => { + this.esShardTimeout = configUpdate.elasticsearch.shardTimeout.asMilliseconds(); + }); + } + + getEsShardTimeout() { + return this.esShardTimeout; + } + + getGraphiteUrls() { + return this.graphiteUrls; + } } diff --git a/src/legacy/core_plugins/timelion/server/lib/functions_md.js b/src/plugins/timelion/server/lib/functions_md.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/functions_md.js rename to src/plugins/timelion/server/lib/functions_md.js diff --git a/src/legacy/core_plugins/timelion/server/lib/get_namespaced_settings.js b/src/plugins/timelion/server/lib/get_namespaced_settings.js similarity index 97% rename from src/legacy/core_plugins/timelion/server/lib/get_namespaced_settings.js rename to src/plugins/timelion/server/lib/get_namespaced_settings.js index 5d18d87e8e054..31bd6b440f9b8 100644 --- a/src/legacy/core_plugins/timelion/server/lib/get_namespaced_settings.js +++ b/src/plugins/timelion/server/lib/get_namespaced_settings.js @@ -18,7 +18,7 @@ */ import _ from 'lodash'; -import configFile from '../../timelion.json'; +import configFile from '../timelion.json'; export default function() { function flattenWith(dot, nestedObj, flattenArrays) { diff --git a/src/legacy/core_plugins/timelion/server/lib/load_functions.d.ts b/src/plugins/timelion/server/lib/load_functions.d.ts similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/load_functions.d.ts rename to src/plugins/timelion/server/lib/load_functions.d.ts diff --git a/src/legacy/core_plugins/timelion/server/lib/load_functions.js b/src/plugins/timelion/server/lib/load_functions.js similarity index 84% rename from src/legacy/core_plugins/timelion/server/lib/load_functions.js rename to src/plugins/timelion/server/lib/load_functions.js index 11501ce3f102b..b7cec8f68faf2 100644 --- a/src/legacy/core_plugins/timelion/server/lib/load_functions.js +++ b/src/plugins/timelion/server/lib/load_functions.js @@ -28,18 +28,18 @@ export default function(directory) { } // Get a list of all files and use the filename as the object key - const files = _.map(glob.sync(path.resolve(__dirname, '../' + directory + '/*.js')), function( - file - ) { - const name = file.substring(file.lastIndexOf('/') + 1, file.lastIndexOf('.')); - return getTuple(directory, name); - }); + const files = _.map( + glob + .sync(path.resolve(__dirname, '../' + directory + '/*.js')) + .filter(filename => !filename.includes('.test')), + function(file) { + const name = file.substring(file.lastIndexOf('/') + 1, file.lastIndexOf('.')); + return getTuple(directory, name); + } + ); // Get a list of all directories with an index.js, use the directory name as the key in the object const directories = _.chain(glob.sync(path.resolve(__dirname, '../' + directory + '/*/index.js'))) - .filter(function(file) { - return file.match(/__test__/) == null; - }) .map(function(file) { const parts = file.split('/'); const name = parts[parts.length - 2]; diff --git a/src/legacy/core_plugins/timelion/server/lib/__tests__/load_functions.js b/src/plugins/timelion/server/lib/load_functions.test.js similarity index 95% rename from src/legacy/core_plugins/timelion/server/lib/__tests__/load_functions.js rename to src/plugins/timelion/server/lib/load_functions.test.js index 45dd436be6943..ebe1a04532e05 100644 --- a/src/legacy/core_plugins/timelion/server/lib/__tests__/load_functions.js +++ b/src/plugins/timelion/server/lib/load_functions.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../load_functions`); +const fn = require(`src/plugins/timelion/server/lib/load_functions`); const expect = require('chai').expect; diff --git a/src/legacy/core_plugins/timelion/server/lib/offset_time.js b/src/plugins/timelion/server/lib/offset_time.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/offset_time.js rename to src/plugins/timelion/server/lib/offset_time.js diff --git a/src/legacy/core_plugins/timelion/server/lib/offset_time.test.js b/src/plugins/timelion/server/lib/offset_time.test.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/offset_time.test.js rename to src/plugins/timelion/server/lib/offset_time.test.js diff --git a/src/legacy/core_plugins/timelion/server/lib/process_function_definition.js b/src/plugins/timelion/server/lib/process_function_definition.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/process_function_definition.js rename to src/plugins/timelion/server/lib/process_function_definition.js diff --git a/src/legacy/core_plugins/timelion/server/lib/reduce.js b/src/plugins/timelion/server/lib/reduce.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/reduce.js rename to src/plugins/timelion/server/lib/reduce.js diff --git a/src/legacy/core_plugins/timelion/server/lib/split_interval.js b/src/plugins/timelion/server/lib/split_interval.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/split_interval.js rename to src/plugins/timelion/server/lib/split_interval.js diff --git a/src/legacy/core_plugins/timelion/server/lib/unzipPairs.js b/src/plugins/timelion/server/lib/unzip_pairs.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/lib/unzipPairs.js rename to src/plugins/timelion/server/lib/unzip_pairs.js diff --git a/src/plugins/timelion/server/plugin.ts b/src/plugins/timelion/server/plugin.ts index 4436c1539fc5b..4330bc0ffb357 100644 --- a/src/plugins/timelion/server/plugin.ts +++ b/src/plugins/timelion/server/plugin.ts @@ -17,11 +17,21 @@ * under the License. */ +import { i18n } from '@kbn/i18n'; import { first } from 'rxjs/operators'; import { TypeOf } from '@kbn/config-schema'; -import { PluginInitializerContext, RecursiveReadonly } from '../../../../src/core/server'; +import { + CoreSetup, + PluginInitializerContext, + RecursiveReadonly, +} from '../../../../src/core/server'; import { deepFreeze } from '../../../../src/core/utils'; import { ConfigSchema } from './config'; +import loadFunctions from './lib/load_functions'; +import { functionsRoute } from './routes/functions'; +import { validateEsRoute } from './routes/validate_es'; +import { runRoute } from './routes/run'; +import { ConfigManager } from './lib/config_manager'; /** * Describes public Timelion plugin contract returned at the `setup` stage. @@ -36,12 +46,44 @@ export interface PluginSetupContract { export class Plugin { constructor(private readonly initializerContext: PluginInitializerContext) {} - public async setup(): Promise> { + public async setup(core: CoreSetup): Promise> { const config = await this.initializerContext.config .create>() .pipe(first()) .toPromise(); + const configManager = new ConfigManager(this.initializerContext.config); + + const functions = loadFunctions('series_functions'); + + const getFunction = (name: string) => { + if (functions[name]) { + return functions[name]; + } + + throw new Error( + i18n.translate('timelion.noFunctionErrorMessage', { + defaultMessage: 'No such function: {name}', + values: { name }, + }) + ); + }; + + const logger = this.initializerContext.logger.get('timelion'); + + const router = core.http.createRouter(); + + const deps = { + configManager, + functions, + getFunction, + logger, + }; + + functionsRoute(router, deps); + runRoute(router, deps); + validateEsRoute(router); + return deepFreeze({ uiEnabled: config.ui.enabled }); } diff --git a/src/legacy/core_plugins/timelion/server/routes/functions.js b/src/plugins/timelion/server/routes/functions.ts similarity index 68% rename from src/legacy/core_plugins/timelion/server/routes/functions.js rename to src/plugins/timelion/server/routes/functions.ts index 813d006225f43..a908fefa377eb 100644 --- a/src/legacy/core_plugins/timelion/server/routes/functions.js +++ b/src/plugins/timelion/server/routes/functions.ts @@ -18,18 +18,22 @@ */ import _ from 'lodash'; +import { IRouter } from 'kibana/server'; +import { LoadFunctions } from '../lib/load_functions'; -export function functionsRoute(server) { - server.route({ - method: 'GET', - path: '/api/timelion/functions', - handler: () => { - const functionArray = _.map(server.plugins.timelion.functions, function(val, key) { +export function functionsRoute(router: IRouter, { functions }: { functions: LoadFunctions }) { + router.get( + { + path: '/api/timelion/functions', + validate: false, + }, + async (context, request, response) => { + const functionArray = _.map(functions, function(val, key) { // TODO: This won't work on frozen objects, it should be removed when everything is converted to datasources and chainables return _.extend({}, val, { name: key }); }); - return _.sortBy(functionArray, 'name'); - }, - }); + return response.ok({ body: _.sortBy(functionArray, 'name') }); + } + ); } diff --git a/src/plugins/timelion/server/routes/run.ts b/src/plugins/timelion/server/routes/run.ts new file mode 100644 index 0000000000000..b7a4179da768e --- /dev/null +++ b/src/plugins/timelion/server/routes/run.ts @@ -0,0 +1,144 @@ +/* + * 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 { IRouter, Logger } from 'kibana/server'; +import { schema } from '@kbn/config-schema'; +import Bluebird from 'bluebird'; +import _ from 'lodash'; +// @ts-ignore +import chainRunnerFn from '../handlers/chain_runner.js'; +// @ts-ignore +import getNamespacesSettings from '../lib/get_namespaced_settings'; +// @ts-ignore +import getTlConfig from '../handlers/lib/tl_config'; +import { TimelionFunctionInterface } from '../types'; +import { ConfigManager } from '../lib/config_manager'; + +const timelionDefaults = getNamespacesSettings(); + +export interface TimelionRequestQuery { + payload: { + sheet: string[]; + extended?: { + es: { + filter: { + bool: { + filter: string[] | object; + must: string[]; + should: string[]; + must_not: string[]; + }; + }; + }; + }; + }; + time?: { + from?: string; + interval: string; + timezone: string; + to?: string; + }; +} + +export function runRoute( + router: IRouter, + { + logger, + getFunction, + configManager, + }: { + logger: Logger; + getFunction: (name: string) => TimelionFunctionInterface; + configManager: ConfigManager; + } +) { + router.post( + { + path: '/api/timelion/run', + validate: { + body: schema.object({ + sheet: schema.arrayOf(schema.string()), + extended: schema.maybe( + schema.object({ + es: schema.object({ + filter: schema.object({ + bool: schema.object({ + filter: schema.maybe( + schema.arrayOf(schema.object({}, { allowUnknowns: true })) + ), + must: schema.maybe(schema.arrayOf(schema.object({}, { allowUnknowns: true }))), + should: schema.maybe( + schema.arrayOf(schema.object({}, { allowUnknowns: true })) + ), + must_not: schema.maybe( + schema.arrayOf(schema.object({}, { allowUnknowns: true })) + ), + }), + }), + }), + }) + ), + time: schema.maybe( + schema.object({ + from: schema.maybe(schema.string()), + interval: schema.string(), + timezone: schema.string(), + to: schema.maybe(schema.string()), + }) + ), + }), + }, + }, + router.handleLegacyErrors(async (context, request, response) => { + try { + const uiSettings = await context.core.uiSettings.client.getAll(); + + const tlConfig = getTlConfig({ + request, + settings: _.defaults(uiSettings, timelionDefaults), // Just in case they delete some setting. + getFunction, + allowedGraphiteUrls: configManager.getGraphiteUrls(), + esShardTimeout: configManager.getEsShardTimeout(), + savedObjectsClient: context.core.savedObjects.client, + esDataClient: () => context.core.elasticsearch.dataClient, + }); + const chainRunner = chainRunnerFn(tlConfig); + const sheet = await Bluebird.all(chainRunner.processRequest(request.body)); + + return response.ok({ + body: { + sheet, + stats: chainRunner.getStats(), + }, + }); + } catch (err) { + logger.error(`${err.toString()}: ${err.stack}`); + // TODO Maybe we should just replace everywhere we throw with Boom? Probably. + if (err.isBoom) { + throw err; + } else { + return response.internalError({ + body: { + message: err.toString(), + }, + }); + } + } + }) + ); +} diff --git a/src/legacy/core_plugins/timelion/server/routes/validate_es.js b/src/plugins/timelion/server/routes/validate_es.ts similarity index 65% rename from src/legacy/core_plugins/timelion/server/routes/validate_es.js rename to src/plugins/timelion/server/routes/validate_es.ts index 5e39069f2a698..70d53b6b2c5e3 100644 --- a/src/legacy/core_plugins/timelion/server/routes/validate_es.js +++ b/src/plugins/timelion/server/routes/validate_es.ts @@ -18,15 +18,18 @@ */ import _ from 'lodash'; +import { IRouter } from 'kibana/server'; -export function validateEsRoute(server) { - server.route({ - method: 'GET', - path: '/api/timelion/validate/es', - handler: async function(request) { - const uiSettings = await request.getUiSettingsService().getAll(); +export function validateEsRoute(router: IRouter) { + router.get( + { + path: '/api/timelion/validate/es', + validate: false, + }, + async function(context, request, response) { + const uiSettings = await context.core.uiSettings.client.getAll(); - const { callWithRequest } = server.plugins.elasticsearch.getCluster('data'); + const { callAsCurrentUser } = context.core.elasticsearch.dataClient; const timefield = uiSettings['timelion:es.timefield']; @@ -51,24 +54,28 @@ export function validateEsRoute(server) { let resp = {}; try { - resp = await callWithRequest(request, 'search', body); + resp = await callAsCurrentUser('search', body); } catch (errResp) { resp = errResp; } if (_.has(resp, 'aggregations.maxAgg.value') && _.has(resp, 'aggregations.minAgg.value')) { - return { - ok: true, - field: timefield, - min: _.get(resp, 'aggregations.minAgg.value'), - max: _.get(resp, 'aggregations.maxAgg.value'), - }; + return response.ok({ + body: { + ok: true, + field: timefield, + min: _.get(resp, 'aggregations.minAgg.value'), + max: _.get(resp, 'aggregations.maxAgg.value'), + }, + }); } - return { - ok: false, - resp: resp, - }; - }, - }); + return response.ok({ + body: { + ok: false, + resp, + }, + }); + } + ); } diff --git a/src/legacy/core_plugins/timelion/server/series_functions/abs.js b/src/plugins/timelion/server/series_functions/abs.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/abs.js rename to src/plugins/timelion/server/series_functions/abs.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/abs.js b/src/plugins/timelion/server/series_functions/abs.test.js similarity index 94% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/abs.js rename to src/plugins/timelion/server/series_functions/abs.test.js index 28538d4da2f79..385fad7db739c 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/abs.js +++ b/src/plugins/timelion/server/series_functions/abs.test.js @@ -17,11 +17,11 @@ * under the License. */ -const fn = require(`../abs`); +import fn from './abs'; import _ from 'lodash'; const expect = require('chai').expect; -const seriesList = require('./fixtures/seriesList.js')(); +const seriesList = require('./fixtures/series_list.js')(); import invoke from './helpers/invoke_series_fn.js'; describe('abs.js', function() { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/aggregate.js b/src/plugins/timelion/server/series_functions/aggregate/aggregate.test.js similarity index 89% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/aggregate.js rename to src/plugins/timelion/server/series_functions/aggregate/aggregate.test.js index 6177f7cb7bac4..d2708a525b9c6 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/aggregate.js +++ b/src/plugins/timelion/server/series_functions/aggregate/aggregate.test.js @@ -17,17 +17,16 @@ * under the License. */ -const filename = require('path').basename(__filename); -const fn = require(`../aggregate/index.js`); +import fn from './index'; import _ from 'lodash'; const expect = require('chai').expect; -import invoke from './helpers/invoke_series_fn.js'; +import invoke from '../helpers/invoke_series_fn.js'; -describe(filename, () => { +describe('aggregate', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('../fixtures/series_list.js')(); }); it('first', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/aggregate/avg.js b/src/plugins/timelion/server/series_functions/aggregate/avg.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/aggregate/avg.js rename to src/plugins/timelion/server/series_functions/aggregate/avg.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/aggregate/cardinality.js b/src/plugins/timelion/server/series_functions/aggregate/cardinality.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/aggregate/cardinality.js rename to src/plugins/timelion/server/series_functions/aggregate/cardinality.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/aggregate/first.js b/src/plugins/timelion/server/series_functions/aggregate/first.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/aggregate/first.js rename to src/plugins/timelion/server/series_functions/aggregate/first.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/aggregate/index.js b/src/plugins/timelion/server/series_functions/aggregate/index.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/aggregate/index.js rename to src/plugins/timelion/server/series_functions/aggregate/index.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/aggregate/last.js b/src/plugins/timelion/server/series_functions/aggregate/last.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/aggregate/last.js rename to src/plugins/timelion/server/series_functions/aggregate/last.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/aggregate/max.js b/src/plugins/timelion/server/series_functions/aggregate/max.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/aggregate/max.js rename to src/plugins/timelion/server/series_functions/aggregate/max.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/aggregate/min.js b/src/plugins/timelion/server/series_functions/aggregate/min.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/aggregate/min.js rename to src/plugins/timelion/server/series_functions/aggregate/min.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/aggregate/sum.js b/src/plugins/timelion/server/series_functions/aggregate/sum.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/aggregate/sum.js rename to src/plugins/timelion/server/series_functions/aggregate/sum.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/bars.js b/src/plugins/timelion/server/series_functions/bars.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/bars.js rename to src/plugins/timelion/server/series_functions/bars.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/bars.js b/src/plugins/timelion/server/series_functions/bars.test.js similarity index 95% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/bars.js rename to src/plugins/timelion/server/series_functions/bars.test.js index 90b66759f7341..74105330e6053 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/bars.js +++ b/src/plugins/timelion/server/series_functions/bars.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../bars`); +import fn from './bars'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('bars.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('creates the bars property, with defaults, on all series', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/color.js b/src/plugins/timelion/server/series_functions/color.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/color.js rename to src/plugins/timelion/server/series_functions/color.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/color.js b/src/plugins/timelion/server/series_functions/color.test.js similarity index 96% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/color.js rename to src/plugins/timelion/server/series_functions/color.test.js index f333a39bec5ba..2dc8c6fbcb896 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/color.js +++ b/src/plugins/timelion/server/series_functions/color.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../color`); +import fn from './color'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('color.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('sets the color, on all series', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/condition.js b/src/plugins/timelion/server/series_functions/condition.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/condition.js rename to src/plugins/timelion/server/series_functions/condition.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/condition.js b/src/plugins/timelion/server/series_functions/condition.test.js similarity index 97% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/condition.js rename to src/plugins/timelion/server/series_functions/condition.test.js index 533c5adfd62ab..469f84344eb4f 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/condition.js +++ b/src/plugins/timelion/server/series_functions/condition.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../condition`); +import fn from './condition'; import moment from 'moment'; const expect = require('chai').expect; import invoke from './helpers/invoke_series_fn.js'; @@ -28,7 +28,7 @@ describe('condition.js', function() { let comparable; let seriesList; beforeEach(function() { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); comparable = getSeriesList('', [ [moment.utc('1980-01-01T00:00:00.000Z'), 12], [moment.utc('1981-01-01T00:00:00.000Z'), 33], diff --git a/src/legacy/core_plugins/timelion/server/series_functions/cusum.js b/src/plugins/timelion/server/series_functions/cusum.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/cusum.js rename to src/plugins/timelion/server/series_functions/cusum.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/cusum.js b/src/plugins/timelion/server/series_functions/cusum.test.js similarity index 93% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/cusum.js rename to src/plugins/timelion/server/series_functions/cusum.test.js index d9f534555b9d7..29927a8d0faf2 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/cusum.js +++ b/src/plugins/timelion/server/series_functions/cusum.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../cusum`); +import fn from './cusum'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('cusum.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('progressively adds the numbers in the list', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/derivative.js b/src/plugins/timelion/server/series_functions/derivative.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/derivative.js rename to src/plugins/timelion/server/series_functions/derivative.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/derivative.js b/src/plugins/timelion/server/series_functions/derivative.test.js similarity index 92% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/derivative.js rename to src/plugins/timelion/server/series_functions/derivative.test.js index 88ef4778ef2f1..296cf91711d02 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/derivative.js +++ b/src/plugins/timelion/server/series_functions/derivative.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../derivative`); +import fn from './derivative'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('derivative.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('gets the change in the set', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/divide.js b/src/plugins/timelion/server/series_functions/divide.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/divide.js rename to src/plugins/timelion/server/series_functions/divide.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/divide.js b/src/plugins/timelion/server/series_functions/divide.test.js similarity index 92% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/divide.js rename to src/plugins/timelion/server/series_functions/divide.test.js index afe531922522f..e24ec7d60541c 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/divide.js +++ b/src/plugins/timelion/server/series_functions/divide.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../divide`); +import fn from './divide'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('divide.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('divides by a single number', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/es.js b/src/plugins/timelion/server/series_functions/es/es.test.js similarity index 94% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/es.js rename to src/plugins/timelion/server/series_functions/es/es.test.js index f2b364afb723b..4bd37b03f01fe 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/es.js +++ b/src/plugins/timelion/server/series_functions/es/es.test.js @@ -17,52 +17,38 @@ * under the License. */ -const filename = require('path').basename(__filename); -import es from '../es'; +import es from './index'; -import tlConfigFn from './fixtures/tlConfig'; -import * as aggResponse from '../es/lib/agg_response_to_series_list'; -import buildRequest from '../es/lib/build_request'; -import createDateAgg from '../es/lib/create_date_agg'; -import esResponse from './fixtures/es_response'; +import tlConfigFn from '../fixtures/tl_config'; +import * as aggResponse from './lib/agg_response_to_series_list'; +import buildRequest from './lib/build_request'; +import createDateAgg from './lib/create_date_agg'; +import esResponse from '../fixtures/es_response'; import Bluebird from 'bluebird'; import _ from 'lodash'; import { expect } from 'chai'; import sinon from 'sinon'; -import invoke from './helpers/invoke_series_fn.js'; +import invoke from '../helpers/invoke_series_fn.js'; function stubRequestAndServer(response, indexPatternSavedObjects = []) { return { - server: { - plugins: { - elasticsearch: { - getCluster: sinon - .stub() - .withArgs('data') - .returns({ - callWithRequest: function() { - return Bluebird.resolve(response); - }, - }), - }, + esDataClient: sinon.stub().returns({ + callAsCurrentUser: function() { + return Bluebird.resolve(response); }, - }, - request: { - getSavedObjectsClient: function() { - return { - find: function() { - return Bluebird.resolve({ - saved_objects: indexPatternSavedObjects, - }); - }, - }; + }), + savedObjectsClient: { + find: function() { + return Bluebird.resolve({ + saved_objects: indexPatternSavedObjects, + }); }, }, }; } -describe(filename, () => { +describe('es', () => { let tlConfig; describe('seriesList processor', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/es/index.js b/src/plugins/timelion/server/series_functions/es/index.js similarity index 91% rename from src/legacy/core_plugins/timelion/server/series_functions/es/index.js rename to src/plugins/timelion/server/series_functions/es/index.js index 4ce2752fbf9be..eb41663b71cf7 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/es/index.js +++ b/src/plugins/timelion/server/series_functions/es/index.js @@ -17,7 +17,6 @@ * under the License. */ -import { first, map } from 'rxjs/operators'; import { i18n } from '@kbn/i18n'; import _ from 'lodash'; import Datasource from '../../lib/classes/datasource'; @@ -109,7 +108,7 @@ export default new Datasource('es', { fit: 'nearest', }); - const findResp = await tlConfig.request.getSavedObjectsClient().find({ + const findResp = await tlConfig.savedObjectsClient.find({ type: 'index-pattern', fields: ['title', 'fields'], search: `"${config.index}"`, @@ -126,17 +125,12 @@ export default new Datasource('es', { }); } - const esShardTimeout = await tlConfig.server.newPlatform.__internals.elasticsearch.legacy.config$ - .pipe( - first(), - map(config => config.shardTimeout.asMilliseconds()) - ) - .toPromise(); + const esShardTimeout = tlConfig.esShardTimeout; const body = buildRequest(config, tlConfig, scriptedFields, esShardTimeout); - const { callWithRequest } = tlConfig.server.plugins.elasticsearch.getCluster('data'); - const resp = await callWithRequest(tlConfig.request, 'search', body); + const { callAsCurrentUser: callWithRequest } = tlConfig.esDataClient(); + const resp = await callWithRequest('search', body); if (!resp._shards.total) { throw new Error( i18n.translate('timelion.serverSideErrors.esFunction.indexNotFoundErrorMessage', { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/es/lib/agg_body.js b/src/plugins/timelion/server/series_functions/es/lib/agg_body.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/es/lib/agg_body.js rename to src/plugins/timelion/server/series_functions/es/lib/agg_body.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/es/lib/agg_response_to_series_list.js b/src/plugins/timelion/server/series_functions/es/lib/agg_response_to_series_list.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/es/lib/agg_response_to_series_list.js rename to src/plugins/timelion/server/series_functions/es/lib/agg_response_to_series_list.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/es/lib/build_request.js b/src/plugins/timelion/server/series_functions/es/lib/build_request.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/es/lib/build_request.js rename to src/plugins/timelion/server/series_functions/es/lib/build_request.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/es/lib/create_date_agg.js b/src/plugins/timelion/server/series_functions/es/lib/create_date_agg.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/es/lib/create_date_agg.js rename to src/plugins/timelion/server/series_functions/es/lib/create_date_agg.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/first.js b/src/plugins/timelion/server/series_functions/first.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/first.js rename to src/plugins/timelion/server/series_functions/first.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/first.js b/src/plugins/timelion/server/series_functions/first.test.js similarity index 92% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/first.js rename to src/plugins/timelion/server/series_functions/first.test.js index 3e86554e843b0..96192b2b3903f 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/first.js +++ b/src/plugins/timelion/server/series_functions/first.test.js @@ -17,10 +17,10 @@ * under the License. */ -const fn = require(`../first`); +import fn from './first'; const expect = require('chai').expect; -const seriesList = require('./fixtures/seriesList.js')(); +const seriesList = require('./fixtures/series_list.js')(); import invoke from './helpers/invoke_series_fn.js'; describe('first.js', function() { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/fit.js b/src/plugins/timelion/server/series_functions/fit.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/fit.js rename to src/plugins/timelion/server/series_functions/fit.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/fit.js b/src/plugins/timelion/server/series_functions/fit.test.js similarity index 98% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/fit.js rename to src/plugins/timelion/server/series_functions/fit.test.js index db9360da3f592..75eaa2a50ea72 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/fit.js +++ b/src/plugins/timelion/server/series_functions/fit.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../fit`); +const fn = require(`src/plugins/timelion/server/series_functions/fit`); import moment from 'moment'; const expect = require('chai').expect; import invoke from './helpers/invoke_series_fn.js'; diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/bucketList.js b/src/plugins/timelion/server/series_functions/fixtures/bucket_list.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/bucketList.js rename to src/plugins/timelion/server/series_functions/fixtures/bucket_list.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/es_response.js b/src/plugins/timelion/server/series_functions/fixtures/es_response.js similarity index 99% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/es_response.js rename to src/plugins/timelion/server/series_functions/fixtures/es_response.js index 65aed311e232b..22352258b2f51 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/es_response.js +++ b/src/plugins/timelion/server/series_functions/fixtures/es_response.js @@ -17,6 +17,8 @@ * under the License. */ +/* eslint-disable quotes */ + /* Really didn't want to do this, but testing the agg flatten logic in units isn't really possible since the functions depend on each other diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/seriesList.js b/src/plugins/timelion/server/series_functions/fixtures/series_list.js similarity index 97% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/seriesList.js rename to src/plugins/timelion/server/series_functions/fixtures/series_list.js index 29b759af521ed..90d9bc8417ef7 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/seriesList.js +++ b/src/plugins/timelion/server/series_functions/fixtures/series_list.js @@ -17,7 +17,7 @@ * under the License. */ -import buckets from './bucketList'; +import buckets from './bucket_list'; import getSeries from '../helpers/get_series'; import getSeriesList from '../helpers/get_series_list'; diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/tlConfig.js b/src/plugins/timelion/server/series_functions/fixtures/tl_config.js similarity index 52% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/tlConfig.js rename to src/plugins/timelion/server/series_functions/fixtures/tl_config.js index 6eea99424c4ab..bf477110be379 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/fixtures/tlConfig.js +++ b/src/plugins/timelion/server/series_functions/fixtures/tl_config.js @@ -18,48 +18,25 @@ */ import moment from 'moment'; -import { of } from 'rxjs'; import sinon from 'sinon'; -import timelionDefaults from '../../../lib/get_namespaced_settings'; +import timelionDefaults from '../../lib/get_namespaced_settings'; import esResponse from './es_response'; export default function() { - const functions = require('../../../lib/load_functions')('series_functions'); - const kibanaServerConfigs = { - 'timelion.graphiteUrls': ['https://www.hostedgraphite.com/UID/ACCESS_KEY/graphite'], - }; - const server = { - plugins: { - timelion: { - getFunction: name => { - if (!functions[name]) throw new Error('No such function: ' + name); - return functions[name]; - }, - }, - elasticsearch: { - getCluster: sinon - .stub() - .withArgs('data') - .returns({ - callWithRequest: function() { - return Promise.resolve(esResponse); - }, - }), - }, + const functions = require('../../lib/load_functions')('series_functions'); + + const tlConfig = require('../../handlers/lib/tl_config.js')({ + getFunction: name => { + if (!functions[name]) throw new Error('No such function: ' + name); + return functions[name]; }, - newPlatform: { - __internals: { - elasticsearch: { - legacy: { config$: of({ shardTimeout: moment.duration(30000) }) }, - }, + esDataClient: sinon.stub().returns({ + callAsCurrentUser: function() { + return Promise.resolve(esResponse); }, - }, - config: () => ({ get: key => kibanaServerConfigs[key] }), - }; - - const tlConfig = require('../../../handlers/lib/tl_config.js')({ - server, - request: {}, + }), + esShardTimeout: moment.duration(30000), + allowedGraphiteUrls: ['https://www.hostedgraphite.com/UID/ACCESS_KEY/graphite'], }); tlConfig.time = { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/graphite.js b/src/plugins/timelion/server/series_functions/graphite.js similarity index 97% rename from src/legacy/core_plugins/timelion/server/series_functions/graphite.js rename to src/plugins/timelion/server/series_functions/graphite.js index a80dd2f3ff29e..7b7bb1541bea0 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/graphite.js +++ b/src/plugins/timelion/server/series_functions/graphite.js @@ -46,7 +46,7 @@ export default new Datasource('graphite', { min: moment(tlConfig.time.from).format('HH:mm[_]YYYYMMDD'), max: moment(tlConfig.time.to).format('HH:mm[_]YYYYMMDD'), }; - const allowedUrls = tlConfig.server.config().get('timelion.graphiteUrls'); + const allowedUrls = tlConfig.allowedGraphiteUrls; const configuredUrl = tlConfig.settings['timelion:graphite.url']; if (!allowedUrls.includes(configuredUrl)) { throw new Error( diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/graphite.js b/src/plugins/timelion/server/series_functions/graphite.test.js similarity index 85% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/graphite.js rename to src/plugins/timelion/server/series_functions/graphite.test.js index b7ee96ef77575..914e0a7aaa4a1 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/graphite.js +++ b/src/plugins/timelion/server/series_functions/graphite.test.js @@ -17,12 +17,12 @@ * under the License. */ -import proxyquire from 'proxyquire'; -import Bluebird from 'bluebird'; const expect = require('chai').expect; -const graphiteResponse = function() { - return Bluebird.resolve({ +import fn from './graphite'; + +jest.mock('node-fetch', () => () => { + return Promise.resolve({ json: function() { return [ { @@ -37,14 +37,11 @@ const graphiteResponse = function() { ]; }, }); -}; - -const filename = require('path').basename(__filename); -const fn = proxyquire(`../${filename}`, { 'node-fetch': graphiteResponse }); +}); import invoke from './helpers/invoke_series_fn.js'; -describe(filename, function() { +describe('graphite', function() { it('should wrap the graphite response up in a seriesList', function() { return invoke(fn, []).then(function(result) { expect(result.output.list[0].data[0][1]).to.eql(3); diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/helpers/get_series.js b/src/plugins/timelion/server/series_functions/helpers/get_series.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/helpers/get_series.js rename to src/plugins/timelion/server/series_functions/helpers/get_series.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/helpers/get_series_list.js b/src/plugins/timelion/server/series_functions/helpers/get_series_list.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/helpers/get_series_list.js rename to src/plugins/timelion/server/series_functions/helpers/get_series_list.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/helpers/get_single_series_list.js b/src/plugins/timelion/server/series_functions/helpers/get_single_series_list.js similarity index 90% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/helpers/get_single_series_list.js rename to src/plugins/timelion/server/series_functions/helpers/get_single_series_list.js index cef5bed5d3218..c9cd3393e62f0 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/helpers/get_single_series_list.js +++ b/src/plugins/timelion/server/series_functions/helpers/get_single_series_list.js @@ -17,8 +17,8 @@ * under the License. */ -import getSeries from '../helpers/get_series'; -import getSeriesList from '../helpers/get_series_list'; +import getSeries from './get_series'; +import getSeriesList from './get_series_list'; import _ from 'lodash'; export default function(name, data) { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/helpers/invoke_series_fn.js b/src/plugins/timelion/server/series_functions/helpers/invoke_series_fn.js similarity index 89% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/helpers/invoke_series_fn.js rename to src/plugins/timelion/server/series_functions/helpers/invoke_series_fn.js index 51ef4c61a95e8..3a8bb92a883f8 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/helpers/invoke_series_fn.js +++ b/src/plugins/timelion/server/series_functions/helpers/invoke_series_fn.js @@ -20,10 +20,10 @@ // invokes a series_function with the specified arguments import _ from 'lodash'; -import indexArguments from '../../../handlers/lib/index_arguments'; +import indexArguments from '../../handlers/lib/index_arguments'; export default function invokeSeriesFn(fnDef, args, tlConfigOverrides) { - const tlConfig = _.merge(require('../fixtures/tlConfig')(), tlConfigOverrides); + const tlConfig = _.merge(require('../fixtures/tl_config')(), tlConfigOverrides); return Promise.all(args).then(function(args) { args.byName = indexArguments(fnDef, args); diff --git a/src/legacy/core_plugins/timelion/server/series_functions/hide.js b/src/plugins/timelion/server/series_functions/hide.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/hide.js rename to src/plugins/timelion/server/series_functions/hide.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/hide.js b/src/plugins/timelion/server/series_functions/hide.test.js similarity index 93% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/hide.js rename to src/plugins/timelion/server/series_functions/hide.test.js index 5d4b624670847..5e71c1508e9e0 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/hide.js +++ b/src/plugins/timelion/server/series_functions/hide.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../hide`); +import fn from './hide'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('hide.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('hides a series', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/holt/index.js b/src/plugins/timelion/server/series_functions/holt/index.js similarity index 98% rename from src/legacy/core_plugins/timelion/server/series_functions/holt/index.js rename to src/plugins/timelion/server/series_functions/holt/index.js index 0cc41df933e8c..39cfe0bb3556d 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/holt/index.js +++ b/src/plugins/timelion/server/series_functions/holt/index.js @@ -23,7 +23,7 @@ import Chainable from '../../lib/classes/chainable'; import ses from './lib/ses'; import des from './lib/des'; import tes from './lib/tes'; -import { toMS } from '../../../../vis_type_timelion/common/lib'; +import { toMS } from '../../../common/lib/to_milliseconds'; export default new Chainable('holt', { args: [ diff --git a/src/legacy/core_plugins/timelion/server/series_functions/holt/lib/des.js b/src/plugins/timelion/server/series_functions/holt/lib/des.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/holt/lib/des.js rename to src/plugins/timelion/server/series_functions/holt/lib/des.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/holt/lib/ses.js b/src/plugins/timelion/server/series_functions/holt/lib/ses.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/holt/lib/ses.js rename to src/plugins/timelion/server/series_functions/holt/lib/ses.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/holt/lib/tes.js b/src/plugins/timelion/server/series_functions/holt/lib/tes.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/holt/lib/tes.js rename to src/plugins/timelion/server/series_functions/holt/lib/tes.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/label.js b/src/plugins/timelion/server/series_functions/label.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/label.js rename to src/plugins/timelion/server/series_functions/label.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/label.js b/src/plugins/timelion/server/series_functions/label.test.js similarity index 94% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/label.js rename to src/plugins/timelion/server/series_functions/label.test.js index 9e0a92b1e4004..8d97083769060 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/label.js +++ b/src/plugins/timelion/server/series_functions/label.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../label`); +import fn from './label'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('label.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('changes the label on the series', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/legend.js b/src/plugins/timelion/server/series_functions/legend.js similarity index 98% rename from src/legacy/core_plugins/timelion/server/series_functions/legend.js rename to src/plugins/timelion/server/series_functions/legend.js index fd9ff53a1391f..b467318686729 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/legend.js +++ b/src/plugins/timelion/server/series_functions/legend.js @@ -20,7 +20,7 @@ import { i18n } from '@kbn/i18n'; import alter from '../lib/alter.js'; import Chainable from '../lib/classes/chainable'; -import { DEFAULT_TIME_FORMAT } from '../../../vis_type_timelion/common/lib'; +import { DEFAULT_TIME_FORMAT } from '../../common/lib'; export default new Chainable('legend', { args: [ diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/legend.js b/src/plugins/timelion/server/series_functions/legend.test.js similarity index 96% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/legend.js rename to src/plugins/timelion/server/series_functions/legend.test.js index 205f0c4431fcc..10789555deac8 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/legend.js +++ b/src/plugins/timelion/server/series_functions/legend.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../legend`); +import fn from './legend'; const expect = require('chai').expect; import invoke from './helpers/invoke_series_fn.js'; @@ -25,7 +25,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('legend.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('should create the _global object if it does not exist', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/lines.js b/src/plugins/timelion/server/series_functions/lines.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/lines.js rename to src/plugins/timelion/server/series_functions/lines.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/lines.js b/src/plugins/timelion/server/series_functions/lines.test.js similarity index 95% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/lines.js rename to src/plugins/timelion/server/series_functions/lines.test.js index 32974495b40eb..c8985cd479150 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/lines.js +++ b/src/plugins/timelion/server/series_functions/lines.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../lines`); +import fn from './lines'; const expect = require('chai').expect; import invoke from './helpers/invoke_series_fn.js'; @@ -25,7 +25,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('lines.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('should simply set show, steps, stack and lineWidth', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/log.js b/src/plugins/timelion/server/series_functions/log.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/log.js rename to src/plugins/timelion/server/series_functions/log.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/log.js b/src/plugins/timelion/server/series_functions/log.test.js similarity index 93% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/log.js rename to src/plugins/timelion/server/series_functions/log.test.js index 8cd2e2caa2c47..f37553508bc8a 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/log.js +++ b/src/plugins/timelion/server/series_functions/log.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../log`); +import fn from './log'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('log.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('should return the log10 value of every value', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/max.js b/src/plugins/timelion/server/series_functions/max.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/max.js rename to src/plugins/timelion/server/series_functions/max.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/max.js b/src/plugins/timelion/server/series_functions/max.test.js similarity index 93% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/max.js rename to src/plugins/timelion/server/series_functions/max.test.js index 9cc4afffb22ba..7b3d819d0666b 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/max.js +++ b/src/plugins/timelion/server/series_functions/max.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../max`); +import fn from './max'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('max.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('keeps the max of a series vs a number', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/min.js b/src/plugins/timelion/server/series_functions/min.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/min.js rename to src/plugins/timelion/server/series_functions/min.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/min.js b/src/plugins/timelion/server/series_functions/min.test.js similarity index 93% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/min.js rename to src/plugins/timelion/server/series_functions/min.test.js index a89183ee90c6b..d30339d6218f8 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/min.js +++ b/src/plugins/timelion/server/series_functions/min.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../min`); +import fn from './min'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('min.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('keeps the min of a series vs a number', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/movingaverage.js b/src/plugins/timelion/server/series_functions/movingaverage.js similarity index 98% rename from src/legacy/core_plugins/timelion/server/series_functions/movingaverage.js rename to src/plugins/timelion/server/series_functions/movingaverage.js index a4b458991c1bc..be5f902770347 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/movingaverage.js +++ b/src/plugins/timelion/server/series_functions/movingaverage.js @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n'; import alter from '../lib/alter.js'; import _ from 'lodash'; import Chainable from '../lib/classes/chainable'; -import { toMS } from '../../../vis_type_timelion/common/lib'; +import { toMS } from '../../common/lib/to_milliseconds'; const validPositions = ['left', 'right', 'center']; const defaultPosition = 'center'; diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/movingaverage.js b/src/plugins/timelion/server/series_functions/movingaverage.test.js similarity index 96% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/movingaverage.js rename to src/plugins/timelion/server/series_functions/movingaverage.test.js index dceef96b1d166..760d5af92a1ef 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/movingaverage.js +++ b/src/plugins/timelion/server/series_functions/movingaverage.test.js @@ -17,12 +17,12 @@ * under the License. */ -const fn = require(`../movingaverage`); +import fn from './movingaverage'; const expect = require('chai').expect; import moment from 'moment'; import _ from 'lodash'; -import buckets from './fixtures/bucketList'; +import buckets from './fixtures/bucket_list'; import getSeries from './helpers/get_series'; import getSeriesList from './helpers/get_series_list'; import invoke from './helpers/invoke_series_fn.js'; diff --git a/src/legacy/core_plugins/timelion/server/series_functions/movingstd.js b/src/plugins/timelion/server/series_functions/movingstd.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/movingstd.js rename to src/plugins/timelion/server/series_functions/movingstd.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/movingstd.js b/src/plugins/timelion/server/series_functions/movingstd.test.js similarity index 98% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/movingstd.js rename to src/plugins/timelion/server/series_functions/movingstd.test.js index d2ef271293afc..bd165488687d4 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/movingstd.js +++ b/src/plugins/timelion/server/series_functions/movingstd.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../movingstd`); +import fn from './movingstd'; import moment from 'moment'; const expect = require('chai').expect; diff --git a/src/legacy/core_plugins/timelion/server/series_functions/multiply.js b/src/plugins/timelion/server/series_functions/multiply.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/multiply.js rename to src/plugins/timelion/server/series_functions/multiply.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/multiply.js b/src/plugins/timelion/server/series_functions/multiply.test.js similarity index 92% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/multiply.js rename to src/plugins/timelion/server/series_functions/multiply.test.js index 0cc5665fb919a..f460e5dd30731 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/multiply.js +++ b/src/plugins/timelion/server/series_functions/multiply.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../multiply`); +import fn from './multiply'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('multiply.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('multiplies by a number', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/points.js b/src/plugins/timelion/server/series_functions/points.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/points.js rename to src/plugins/timelion/server/series_functions/points.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/points.js b/src/plugins/timelion/server/series_functions/points.test.js similarity index 96% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/points.js rename to src/plugins/timelion/server/series_functions/points.test.js index 53831f0f6138d..c45d68a5e4550 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/points.js +++ b/src/plugins/timelion/server/series_functions/points.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../points`); +import fn from './points'; import _ from 'lodash'; import assert from 'chai'; @@ -27,7 +27,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('points.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('should set the point radius', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/precision.js b/src/plugins/timelion/server/series_functions/precision.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/precision.js rename to src/plugins/timelion/server/series_functions/precision.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/precision.js b/src/plugins/timelion/server/series_functions/precision.test.js similarity index 93% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/precision.js rename to src/plugins/timelion/server/series_functions/precision.test.js index 29e3bc1ab66f8..e8bd2c947c200 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/precision.js +++ b/src/plugins/timelion/server/series_functions/precision.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../precision`); +import fn from './precision'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('precision.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('keeps the min of a series vs a number', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/props.js b/src/plugins/timelion/server/series_functions/props.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/props.js rename to src/plugins/timelion/server/series_functions/props.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/quandl.js b/src/plugins/timelion/server/series_functions/quandl.js similarity index 98% rename from src/legacy/core_plugins/timelion/server/series_functions/quandl.js rename to src/plugins/timelion/server/series_functions/quandl.js index fd7de05464da3..40400ea44c7fc 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/quandl.js +++ b/src/plugins/timelion/server/series_functions/quandl.js @@ -127,9 +127,6 @@ export default new Datasource('quandl', { }, ], }; - }) - .catch(function(e) { - throw e; }); }, }); diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/quandl.js b/src/plugins/timelion/server/series_functions/quandl.test.js similarity index 55% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/quandl.js rename to src/plugins/timelion/server/series_functions/quandl.test.js index 009c0e4e025cd..fe5aab512370f 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/quandl.js +++ b/src/plugins/timelion/server/series_functions/quandl.test.js @@ -17,85 +17,79 @@ * under the License. */ -import proxyquire from 'proxyquire'; -import Bluebird from 'bluebird'; -import assert from 'chai'; -const expect = assert.expect; +import fn from './quandl'; const parseURL = require('url').parse; const parseQueryString = require('querystring').parse; -const tlConfig = require('./fixtures/tlConfig')(); +const tlConfig = require('./fixtures/tl_config')(); import moment from 'moment'; +import fetchMock from 'node-fetch'; + +function parseUrlParams(url) { + return parseQueryString(parseURL(url).query); +} + +jest.mock('node-fetch', () => + jest.fn(() => + Promise.resolve({ + json: function() { + return { + name: '__beer__', + data: [ + ['2015-01-01', 3], + ['2015-01-02', 14], + ['2015-01-03', 15.92], + ['2015-01-04', 65.35], + ], + }; + }, + }) + ) +); -const filename = require('path').basename(__filename); import invoke from './helpers/invoke_series_fn.js'; -let fn; -let response; -let calledWith; -describe(filename, function() { +describe('quandl', function() { beforeEach(function() { - response = function(url) { - calledWith = { - params: parseQueryString(parseURL(url).query), - code: url.match(/datasets\/(.*).json/)[1], - }; - return Bluebird.resolve({ - json: function() { - return { - name: '__beer__', - data: [ - ['2015-01-01', 3], - ['2015-01-02', 14], - ['2015-01-03', 15.92], - ['2015-01-04', 65.35], - ], - }; - }, - }); - }; - fn = proxyquire(`../${filename}`, { 'node-fetch': response }); + jest.clearAllMocks(); }); it('should wrap the quandl response up in a seriesList', function() { return invoke(fn, []).then(function(result) { - expect(result.output.list[0].data[0][1]).to.eql(3); - expect(result.output.list[0].data[1][1]).to.eql(14); + expect(result.output.list[0].data[0][1]).toEqual(3); + expect(result.output.list[0].data[1][1]).toEqual(14); }); }); it('should set the label to that of the quandl name', function() { return invoke(fn, []).then(function(result) { - expect(result.output.list[0].label).to.eql('__beer__'); + expect(result.output.list[0].label).toEqual('__beer__'); }); }); it('should call the quandl API with the quandl code that has been passed', function() { return invoke(fn, ['BEER/IS_GOOD']).then(function() { - expect(calledWith.code).to.eql('BEER/IS_GOOD'); + expect(fetchMock).toHaveBeenCalled(); + expect(fetchMock.mock.calls[0][0].match(/datasets\/(.*).json/)[1]).toEqual('BEER/IS_GOOD'); }); }); it('should limit the time span and interval to the stuff attached to tlConfig', function() { return invoke(fn, []).then(function() { - expect(calledWith.params.trim_start).to.eql( - moment.utc(tlConfig.time.from).format('YYYY-MM-DD') - ); - expect(calledWith.params.trim_end).to.eql(moment.utc(tlConfig.time.to).format('YYYY-MM-DD')); + const params = parseUrlParams(fetchMock.mock.calls[0][0]); + expect(params.trim_start).toEqual(moment.utc(tlConfig.time.from).format('YYYY-MM-DD')); + expect(params.trim_end).toEqual(moment.utc(tlConfig.time.to).format('YYYY-MM-DD')); }); }); it('should throw an error is passed an unsupported interval', function() { - return invoke(fn, [], { time: { interval: '2d' } }) - .then(expect.fail) - .catch(function(r) { - expect(r).to.be.an('error'); - }); + return expect(invoke(fn, [], { time: { interval: '2d' } })).rejects.toThrowError(); }); it('should use the configured API key when talking to quandl', function() { return invoke(fn, [], { settings: { 'timelion:quandl.key': 'bEeR' } }).then(function() { - expect(calledWith.params.auth_token).to.eql('bEeR'); + const params = parseUrlParams(fetchMock.mock.calls[0][0]); + expect(params.auth_token).toEqual('bEeR'); }); }); }); diff --git a/src/legacy/core_plugins/timelion/server/series_functions/range.js b/src/plugins/timelion/server/series_functions/range.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/range.js rename to src/plugins/timelion/server/series_functions/range.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/range.js b/src/plugins/timelion/server/series_functions/range.test.js similarity index 93% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/range.js rename to src/plugins/timelion/server/series_functions/range.test.js index 38bee7d45565e..f03488a6f2cf2 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/range.js +++ b/src/plugins/timelion/server/series_functions/range.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../range`); +import fn from './range'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('range.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); seriesList.list[0].data = [ [1000, 20], [2000, 10], diff --git a/src/legacy/core_plugins/timelion/server/series_functions/scale_interval.js b/src/plugins/timelion/server/series_functions/scale_interval.js similarity index 96% rename from src/legacy/core_plugins/timelion/server/series_functions/scale_interval.js rename to src/plugins/timelion/server/series_functions/scale_interval.js index b604015624dfd..821f2714631cc 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/scale_interval.js +++ b/src/plugins/timelion/server/series_functions/scale_interval.js @@ -19,7 +19,7 @@ import { i18n } from '@kbn/i18n'; import alter from '../lib/alter.js'; -import { toMS } from '../../../vis_type_timelion/common/lib'; +import { toMS } from '../../common/lib/to_milliseconds'; import _ from 'lodash'; import Chainable from '../lib/classes/chainable'; diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/scale_interval.js b/src/plugins/timelion/server/series_functions/scale_interval.test.js similarity index 92% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/scale_interval.js rename to src/plugins/timelion/server/series_functions/scale_interval.test.js index 12ad5503e69bf..dfd5fd349ea04 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/scale_interval.js +++ b/src/plugins/timelion/server/series_functions/scale_interval.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../scale_interval`); +import fn from './scale_interval'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('scale_interval.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('Can multiply to transform one interval to another', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/static.js b/src/plugins/timelion/server/series_functions/static.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/static.js rename to src/plugins/timelion/server/series_functions/static.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/static.js b/src/plugins/timelion/server/series_functions/static.test.js similarity index 97% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/static.js rename to src/plugins/timelion/server/series_functions/static.test.js index cea9525694ab3..f791009e9e2b4 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/static.js +++ b/src/plugins/timelion/server/series_functions/static.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../static`); +import fn from './static'; import _ from 'lodash'; const expect = require('chai').expect; diff --git a/src/legacy/core_plugins/timelion/server/series_functions/subtract.js b/src/plugins/timelion/server/series_functions/subtract.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/subtract.js rename to src/plugins/timelion/server/series_functions/subtract.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/subtract.js b/src/plugins/timelion/server/series_functions/subtract.test.js similarity index 97% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/subtract.js rename to src/plugins/timelion/server/series_functions/subtract.test.js index 55d661ea95485..7085e0baed023 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/subtract.js +++ b/src/plugins/timelion/server/series_functions/subtract.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../subtract`); +import fn from './subtract'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('subtract.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('it throws an error if first argument is not seriesList', async () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/sum.js b/src/plugins/timelion/server/series_functions/sum.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/sum.js rename to src/plugins/timelion/server/series_functions/sum.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/sum.js b/src/plugins/timelion/server/series_functions/sum.test.js similarity index 93% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/sum.js rename to src/plugins/timelion/server/series_functions/sum.test.js index 61e3a254d0b5d..d897d1a958460 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/sum.js +++ b/src/plugins/timelion/server/series_functions/sum.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../sum`); +import fn from './sum'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('sum.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('it adds a number', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/title.js b/src/plugins/timelion/server/series_functions/title.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/title.js rename to src/plugins/timelion/server/series_functions/title.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/title.js b/src/plugins/timelion/server/series_functions/title.test.js similarity index 93% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/title.js rename to src/plugins/timelion/server/series_functions/title.test.js index 973bb2ed0ea32..e2238bb740bcd 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/title.js +++ b/src/plugins/timelion/server/series_functions/title.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../title`); +import fn from './title'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('title.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('sets the title property', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/trend/index.js b/src/plugins/timelion/server/series_functions/trend/index.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/trend/index.js rename to src/plugins/timelion/server/series_functions/trend/index.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/trend/lib/regress.js b/src/plugins/timelion/server/series_functions/trend/lib/regress.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/trend/lib/regress.js rename to src/plugins/timelion/server/series_functions/trend/lib/regress.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/trim.js b/src/plugins/timelion/server/series_functions/trim.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/trim.js rename to src/plugins/timelion/server/series_functions/trim.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/trim.js b/src/plugins/timelion/server/series_functions/trim.test.js similarity index 95% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/trim.js rename to src/plugins/timelion/server/series_functions/trim.test.js index ed7a8999d706a..e2b88a52f0045 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/trim.js +++ b/src/plugins/timelion/server/series_functions/trim.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../trim`); +import fn from './trim'; import _ from 'lodash'; const expect = require('chai').expect; @@ -26,7 +26,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('trim.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('Sets the first and last values to null by default', () => { diff --git a/src/legacy/core_plugins/timelion/server/series_functions/worldbank.js b/src/plugins/timelion/server/series_functions/worldbank.js similarity index 96% rename from src/legacy/core_plugins/timelion/server/series_functions/worldbank.js rename to src/plugins/timelion/server/series_functions/worldbank.js index 3630d6c956b68..f19bfab01b0f9 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/worldbank.js +++ b/src/plugins/timelion/server/series_functions/worldbank.js @@ -45,7 +45,7 @@ export default new Datasource('worldbank', { The worldbank provides mostly yearly data, and often has no data for the current year. Try {offsetQuery} if you get no data for recent time ranges.`, values: { - worldbankUrl: 'http://data.worldbank.org/', + worldbankUrl: 'https://api.worldbank.org/v2/', offsetQuery: 'offset=-1y', }, }), @@ -53,7 +53,7 @@ export default new Datasource('worldbank', { // http://api.worldbank.org/en/countries/ind;chn/indicators/DPANUSSPF?date=2000:2006&MRV=5 const config = _.defaults(args.byName, { - code: 'countries/wld/indicators/SP.POP.TOTL', + code: 'country/all/indicator/SP.POP.TOTL', }); const time = { @@ -62,7 +62,7 @@ export default new Datasource('worldbank', { }; const URL = - 'http://api.worldbank.org/' + + 'https://api.worldbank.org/v2/' + config.code + '?date=' + time.min + diff --git a/src/legacy/core_plugins/timelion/server/series_functions/worldbank_indicators.js b/src/plugins/timelion/server/series_functions/worldbank_indicators.js similarity index 95% rename from src/legacy/core_plugins/timelion/server/series_functions/worldbank_indicators.js rename to src/plugins/timelion/server/series_functions/worldbank_indicators.js index dc9a3b4a67b33..7049eefb8f808 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/worldbank_indicators.js +++ b/src/plugins/timelion/server/series_functions/worldbank_indicators.js @@ -54,7 +54,7 @@ export default new Datasource('worldbank_indicators', { mostly yearly data, and often has no data for the current year. Try {offsetQuery} if you get no data for recent time ranges.`, values: { - worldbankUrl: 'http://data.worldbank.org/', + worldbankUrl: 'https://api.worldbank.org/v2/', offsetQuery: 'offset=-1y', }, }), @@ -66,7 +66,7 @@ export default new Datasource('worldbank_indicators', { const countries = config.country.split(':'); const seriesLists = _.map(countries, function(country) { - const code = 'countries/' + country + '/indicators/' + config.indicator; + const code = 'country/' + country + '/indicator/' + config.indicator; const wbArgs = [code]; wbArgs.byName = { code: code }; return worldbank.timelionFn(wbArgs, tlConfig); diff --git a/src/legacy/core_plugins/timelion/server/series_functions/yaxis.js b/src/plugins/timelion/server/series_functions/yaxis.js similarity index 100% rename from src/legacy/core_plugins/timelion/server/series_functions/yaxis.js rename to src/plugins/timelion/server/series_functions/yaxis.js diff --git a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/yaxis.js b/src/plugins/timelion/server/series_functions/yaxis.test.js similarity index 97% rename from src/legacy/core_plugins/timelion/server/series_functions/__tests__/yaxis.js rename to src/plugins/timelion/server/series_functions/yaxis.test.js index 9210a2cd300b0..87001ce45fd39 100644 --- a/src/legacy/core_plugins/timelion/server/series_functions/__tests__/yaxis.js +++ b/src/plugins/timelion/server/series_functions/yaxis.test.js @@ -17,7 +17,7 @@ * under the License. */ -const fn = require(`../yaxis`); +import fn from './yaxis'; import Bluebird from 'bluebird'; const expect = require('chai').expect; import invoke from './helpers/invoke_series_fn.js'; @@ -25,7 +25,7 @@ import invoke from './helpers/invoke_series_fn.js'; describe('yaxis.js', () => { let seriesList; beforeEach(() => { - seriesList = require('./fixtures/seriesList.js')(); + seriesList = require('./fixtures/series_list.js')(); }); it('creates the yaxes array', () => { diff --git a/src/legacy/core_plugins/timelion/timelion.json b/src/plugins/timelion/server/timelion.json similarity index 100% rename from src/legacy/core_plugins/timelion/timelion.json rename to src/plugins/timelion/server/timelion.json diff --git a/src/legacy/core_plugins/timelion/server/types.ts b/src/plugins/timelion/server/types.ts similarity index 100% rename from src/legacy/core_plugins/timelion/server/types.ts rename to src/plugins/timelion/server/types.ts