From 4f1ca7e07fbc16c1db99068f7c8025561d96f472 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Wed, 21 Nov 2018 16:25:12 -0700 Subject: [PATCH] Fix: revert and enable canvas tests (#26054) ## Summary CI was broken when enabling functional smoke tests via #25262. The problem is that the Kibana build is broken in master... I think #25711 broke it, which was merged in between #25262 passing and it being merged (and then CI breaking). So this PR reverts that PR and enabled canvas smoke tests again to see if CI will pass. - Revert #25711 - Revert 7ae0d28d87 --- .eslintignore | 3 +- package.json | 3 +- packages/kbn-interpreter/.babelrc | 3 - .../common/interpreter/create_error.js | 26 ----- packages/kbn-interpreter/common/lib/arg.js | 37 ------- .../kbn-interpreter/common/lib/arg.test.js | 35 ------ .../common/lib/functions_registry.js | 29 ----- .../common/lib/get_by_alias.js | 33 ------ .../common/lib/get_by_alias.test.js | 86 --------------- .../kbn-interpreter/common/lib/get_type.js | 28 ----- .../common/lib/paths_registry.js | 65 ------------ .../common/lib/paths_registry.test.js | 92 ---------------- .../kbn-interpreter/common/lib/serialize.js | 37 ------- .../common/lib/types_registry.js | 29 ----- packages/kbn-interpreter/package.json | 10 -- .../plugin_src/functions/common/clog.js | 27 ----- .../plugin_src/functions/common/index.js | 24 ----- .../plugin_src/functions/common/register.js | 23 ---- .../plugin_src/types/boolean.js | 42 -------- .../kbn-interpreter/plugin_src/types/error.js | 35 ------ .../plugin_src/types/filter.js | 33 ------ .../kbn-interpreter/plugin_src/types/image.js | 31 ------ .../kbn-interpreter/plugin_src/types/index.js | 46 -------- .../kbn-interpreter/plugin_src/types/null.js | 25 ----- .../plugin_src/types/number.js | 42 -------- .../plugin_src/types/pointseries.js | 44 -------- .../plugin_src/types/register.js | 24 ----- .../plugin_src/types/render.js | 29 ----- .../kbn-interpreter/plugin_src/types/shape.js | 31 ------ .../plugin_src/types/string.js | 41 ------- .../kbn-interpreter/plugin_src/types/style.js | 31 ------ .../public/browser_registries.js | 83 --------------- .../kbn-interpreter/public/create_handlers.js | 24 ----- .../server/get_plugin_paths.js | 55 ---------- .../server/server_registries.js | 78 -------------- packages/kbn-interpreter/tasks/build.js | 40 ------- .../kbn-interpreter/tasks/webpack.plugins.js | 100 ------------------ .../interpreter/common/constants.js | 21 ---- src/core_plugins/interpreter/index.js | 41 ------- src/core_plugins/interpreter/init.js | 41 ------- src/core_plugins/interpreter/package.json | 4 - src/core_plugins/interpreter/plugin_paths.js | 27 ----- .../public/load_browser_plugins.js | 30 ------ .../interpreter/server/lib/feature_check.js | 26 ----- .../server/lib/get_plugin_stream.js | 37 ------- .../interpreter/server/lib/get_request.js | 44 -------- .../server/lib/route_expression/server.js | 40 ------- .../lib/route_expression/thread/babeled.js | 32 ------ .../lib/route_expression/thread/polyfill.js | 31 ------ .../interpreter/server/routes/index.js | 28 ----- .../interpreter/server/routes/plugins.js | 35 ------ .../interpreter/server/routes/translate.js | 48 --------- src/optimize/base_optimizer.js | 5 +- src/setup_node_env/babel_register/register.js | 6 +- .../create_or_upgrade_integration.js | 2 +- x-pack/package.json | 1 - .../__tests__/fixtures/function_specs.js | 2 +- .../canvas_plugin_src/functions/common/as.js | 2 +- .../functions/common/clog.js | 14 +++ .../functions/common/index.js | 2 + .../functions/common/mapColumn.js | 2 +- .../common/plot/get_flot_axis_config.js | 2 +- .../functions/common/staticColumn.js | 2 +- .../renderers/dropdown_filter/index.js | 2 +- .../components/time_filter/time_filter.js | 2 +- .../renderers/time_filter/index.js | 2 +- .../canvas/canvas_plugin_src/types/boolean.js | 29 +++++ .../canvas_plugin_src}/types/datatable.js | 22 +--- .../canvas/canvas_plugin_src/types/error.js | 22 ++++ .../canvas/canvas_plugin_src/types/filter.js | 20 ++++ .../canvas/canvas_plugin_src/types/image.js | 18 ++++ .../canvas/canvas_plugin_src/types/index.js | 33 ++++++ .../canvas/canvas_plugin_src/types/null.js | 12 +++ .../canvas/canvas_plugin_src/types/number.js | 29 +++++ .../canvas_plugin_src/types/pointseries.js | 31 ++++++ .../canvas_plugin_src/types/register.js | 10 ++ .../canvas/canvas_plugin_src/types/render.js | 16 +++ .../canvas/canvas_plugin_src/types/shape.js | 18 ++++ .../canvas/canvas_plugin_src/types/string.js | 28 +++++ .../canvas/canvas_plugin_src/types/style.js | 18 ++++ .../uis/arguments/datacolumn/index.js | 2 +- .../uis/arguments/palette.js | 2 +- x-pack/plugins/canvas/common/functions/to.js | 2 +- .../canvas}/common/interpreter/cast.js | 22 +--- .../canvas/common/interpreter/create_error.js | 13 +++ .../canvas}/common/interpreter/interpret.js | 25 +---- .../common/interpreter/socket_interpret.js | 22 +--- .../canvas/common/lib/__tests__/arg.js | 23 ++++ .../lib/__tests__/ast.from_expression.js | 60 +++++------ .../common/lib/__tests__/ast.to_expression.js | 85 ++++++--------- .../common/lib/__tests__/get_by_alias.js | 74 +++++++++++++ .../canvas/common/lib/__tests__/registry.js | 71 ++++++------- x-pack/plugins/canvas/common/lib/arg.js | 24 +++++ .../plugins/canvas}/common/lib/ast.js | 24 +---- .../plugins/canvas/common/lib/autocomplete.js | 4 +- .../plugins/canvas}/common/lib/fn.js | 19 +--- .../canvas/common/lib/functions_registry.js | 16 +++ .../plugins/canvas/common/lib/get_by_alias.js | 20 ++++ x-pack/plugins/canvas/common/lib/get_type.js | 15 +++ .../plugins/canvas}/common/lib/grammar.js | 0 .../plugins/canvas}/common/lib/grammar.peg | 0 x-pack/plugins/canvas/common/lib/index.js | 11 ++ .../plugins/canvas}/common/lib/registry.js | 22 +--- x-pack/plugins/canvas/common/lib/serialize.js | 24 +++++ .../plugins/canvas}/common/lib/type.js | 27 ++--- .../canvas/common/lib/types_registry.js | 16 +++ x-pack/plugins/canvas/index.js | 5 - x-pack/plugins/canvas/init.js | 6 +- x-pack/plugins/canvas/plugin_paths.js | 21 ---- .../canvas/public/components/app/index.js | 31 +----- .../components/arg_form/advanced_failure.js | 2 +- .../datasource/datasource_preview/index.js | 2 +- .../element_content/element_content.js | 2 +- .../public/components/expression/index.js | 2 +- .../components/function_form_list/index.js | 4 +- .../public/expression_types/arg_type.js | 2 +- .../public/expression_types/datasource.js | 2 +- .../public/expression_types/function_form.js | 2 +- .../canvas/public/expression_types/model.js | 2 +- .../public/expression_types/transform.js | 2 +- .../canvas/public/expression_types/view.js | 2 +- .../canvas/public/functions/filters.js | 6 +- .../plugins/canvas/public/lib/arg_helpers.js | 2 +- .../canvas/public/lib/browser_registries.js | 74 +++++++++++++ .../canvas/public/lib/create_handlers.js | 11 ++ .../canvas/public/lib/elements_registry.js | 2 +- .../canvas/public/lib/function_definitions.js | 2 +- .../canvas/public/lib/functions_registry.js | 2 +- .../plugins/canvas/public/lib}/interpreter.js | 29 ++--- .../public/lib/parse_single_function_chain.js | 2 +- .../public/lib/render_functions_registry.js | 2 +- .../canvas/public/lib/run_interpreter.js | 6 +- .../canvas/public/lib/transitions_registry.js | 2 +- .../canvas/public/lib/types_registry.js | 2 +- .../plugins/canvas}/public/socket.js | 21 +--- .../canvas/public/state/actions/elements.js | 4 +- .../canvas/public/state/selectors/workpad.js | 2 +- .../server/lib/__tests__/create_handlers.js | 21 +--- .../canvas}/server/lib/create_handlers.js | 24 +---- .../canvas/server/lib/feature_check.js | 13 +++ .../canvas/server/lib/get_plugin_paths.js | 83 +++++++++++++++ .../canvas/server/lib/get_plugin_stream.js | 24 +++++ .../plugins/canvas/server/lib/get_request.js | 30 ++++++ .../plugins/canvas/server/lib/plugin_paths.js | 20 ++++ .../server/lib/route_expression/browser.js | 19 +--- .../server/lib/route_expression/index.js | 22 +--- .../server/lib/route_expression/server.js | 27 +++++ .../lib/route_expression/thread/babeled.js | 19 ++++ .../lib/route_expression/thread/index.js | 19 +--- .../lib/route_expression/thread/polyfill.js | 18 ++++ .../lib/route_expression/thread/worker.js | 28 ++--- .../canvas/server/lib/server_registries.js | 55 ++++++++++ x-pack/plugins/canvas/server/routes/index.js | 6 ++ .../plugins/canvas/server/routes/plugins.js | 25 +++++ .../plugins/canvas}/server/routes/socket.js | 31 ++---- .../plugins/canvas/server/routes/translate.js | 34 ++++++ .../plugins/canvas/server/usage/collector.js | 2 +- .../canvas/tasks/helpers/webpack.plugins.js | 1 + x-pack/test/functional/apps/canvas/index.js | 2 +- 159 files changed, 1205 insertions(+), 2458 deletions(-) delete mode 100644 packages/kbn-interpreter/.babelrc delete mode 100644 packages/kbn-interpreter/common/interpreter/create_error.js delete mode 100644 packages/kbn-interpreter/common/lib/arg.js delete mode 100644 packages/kbn-interpreter/common/lib/arg.test.js delete mode 100644 packages/kbn-interpreter/common/lib/functions_registry.js delete mode 100644 packages/kbn-interpreter/common/lib/get_by_alias.js delete mode 100644 packages/kbn-interpreter/common/lib/get_by_alias.test.js delete mode 100644 packages/kbn-interpreter/common/lib/get_type.js delete mode 100644 packages/kbn-interpreter/common/lib/paths_registry.js delete mode 100644 packages/kbn-interpreter/common/lib/paths_registry.test.js delete mode 100644 packages/kbn-interpreter/common/lib/serialize.js delete mode 100644 packages/kbn-interpreter/common/lib/types_registry.js delete mode 100644 packages/kbn-interpreter/package.json delete mode 100644 packages/kbn-interpreter/plugin_src/functions/common/clog.js delete mode 100644 packages/kbn-interpreter/plugin_src/functions/common/index.js delete mode 100644 packages/kbn-interpreter/plugin_src/functions/common/register.js delete mode 100644 packages/kbn-interpreter/plugin_src/types/boolean.js delete mode 100644 packages/kbn-interpreter/plugin_src/types/error.js delete mode 100644 packages/kbn-interpreter/plugin_src/types/filter.js delete mode 100644 packages/kbn-interpreter/plugin_src/types/image.js delete mode 100644 packages/kbn-interpreter/plugin_src/types/index.js delete mode 100644 packages/kbn-interpreter/plugin_src/types/null.js delete mode 100644 packages/kbn-interpreter/plugin_src/types/number.js delete mode 100644 packages/kbn-interpreter/plugin_src/types/pointseries.js delete mode 100644 packages/kbn-interpreter/plugin_src/types/register.js delete mode 100644 packages/kbn-interpreter/plugin_src/types/render.js delete mode 100644 packages/kbn-interpreter/plugin_src/types/shape.js delete mode 100644 packages/kbn-interpreter/plugin_src/types/string.js delete mode 100644 packages/kbn-interpreter/plugin_src/types/style.js delete mode 100644 packages/kbn-interpreter/public/browser_registries.js delete mode 100644 packages/kbn-interpreter/public/create_handlers.js delete mode 100644 packages/kbn-interpreter/server/get_plugin_paths.js delete mode 100644 packages/kbn-interpreter/server/server_registries.js delete mode 100644 packages/kbn-interpreter/tasks/build.js delete mode 100644 packages/kbn-interpreter/tasks/webpack.plugins.js delete mode 100644 src/core_plugins/interpreter/common/constants.js delete mode 100644 src/core_plugins/interpreter/index.js delete mode 100644 src/core_plugins/interpreter/init.js delete mode 100644 src/core_plugins/interpreter/package.json delete mode 100644 src/core_plugins/interpreter/plugin_paths.js delete mode 100644 src/core_plugins/interpreter/public/load_browser_plugins.js delete mode 100644 src/core_plugins/interpreter/server/lib/feature_check.js delete mode 100644 src/core_plugins/interpreter/server/lib/get_plugin_stream.js delete mode 100644 src/core_plugins/interpreter/server/lib/get_request.js delete mode 100644 src/core_plugins/interpreter/server/lib/route_expression/server.js delete mode 100644 src/core_plugins/interpreter/server/lib/route_expression/thread/babeled.js delete mode 100644 src/core_plugins/interpreter/server/lib/route_expression/thread/polyfill.js delete mode 100644 src/core_plugins/interpreter/server/routes/index.js delete mode 100644 src/core_plugins/interpreter/server/routes/plugins.js delete mode 100644 src/core_plugins/interpreter/server/routes/translate.js create mode 100644 x-pack/plugins/canvas/canvas_plugin_src/functions/common/clog.js create mode 100644 x-pack/plugins/canvas/canvas_plugin_src/types/boolean.js rename {packages/kbn-interpreter/plugin_src => x-pack/plugins/canvas/canvas_plugin_src}/types/datatable.js (63%) create mode 100644 x-pack/plugins/canvas/canvas_plugin_src/types/error.js create mode 100644 x-pack/plugins/canvas/canvas_plugin_src/types/filter.js create mode 100644 x-pack/plugins/canvas/canvas_plugin_src/types/image.js create mode 100644 x-pack/plugins/canvas/canvas_plugin_src/types/index.js create mode 100644 x-pack/plugins/canvas/canvas_plugin_src/types/null.js create mode 100644 x-pack/plugins/canvas/canvas_plugin_src/types/number.js create mode 100644 x-pack/plugins/canvas/canvas_plugin_src/types/pointseries.js create mode 100644 x-pack/plugins/canvas/canvas_plugin_src/types/register.js create mode 100644 x-pack/plugins/canvas/canvas_plugin_src/types/render.js create mode 100644 x-pack/plugins/canvas/canvas_plugin_src/types/shape.js create mode 100644 x-pack/plugins/canvas/canvas_plugin_src/types/string.js create mode 100644 x-pack/plugins/canvas/canvas_plugin_src/types/style.js rename {packages/kbn-interpreter => x-pack/plugins/canvas}/common/interpreter/cast.js (53%) create mode 100644 x-pack/plugins/canvas/common/interpreter/create_error.js rename {packages/kbn-interpreter => x-pack/plugins/canvas}/common/interpreter/interpret.js (88%) rename {packages/kbn-interpreter => x-pack/plugins/canvas}/common/interpreter/socket_interpret.js (72%) create mode 100644 x-pack/plugins/canvas/common/lib/__tests__/arg.js rename packages/kbn-interpreter/common/lib/ast.from_expression.test.js => x-pack/plugins/canvas/common/lib/__tests__/ast.from_expression.js (59%) rename packages/kbn-interpreter/common/lib/ast.to_expression.test.js => x-pack/plugins/canvas/common/lib/__tests__/ast.to_expression.js (83%) create mode 100644 x-pack/plugins/canvas/common/lib/__tests__/get_by_alias.js rename packages/kbn-interpreter/common/lib/registry.test.js => x-pack/plugins/canvas/common/lib/__tests__/registry.js (60%) create mode 100644 x-pack/plugins/canvas/common/lib/arg.js rename {packages/kbn-interpreter => x-pack/plugins/canvas}/common/lib/ast.js (81%) rename {packages/kbn-interpreter => x-pack/plugins/canvas}/common/lib/fn.js (54%) create mode 100644 x-pack/plugins/canvas/common/lib/functions_registry.js create mode 100644 x-pack/plugins/canvas/common/lib/get_by_alias.js create mode 100644 x-pack/plugins/canvas/common/lib/get_type.js rename {packages/kbn-interpreter => x-pack/plugins/canvas}/common/lib/grammar.js (100%) rename {packages/kbn-interpreter => x-pack/plugins/canvas}/common/lib/grammar.peg (100%) rename {packages/kbn-interpreter => x-pack/plugins/canvas}/common/lib/registry.js (56%) create mode 100644 x-pack/plugins/canvas/common/lib/serialize.js rename {packages/kbn-interpreter => x-pack/plugins/canvas}/common/lib/type.js (61%) create mode 100644 x-pack/plugins/canvas/common/lib/types_registry.js delete mode 100644 x-pack/plugins/canvas/plugin_paths.js create mode 100644 x-pack/plugins/canvas/public/lib/browser_registries.js create mode 100644 x-pack/plugins/canvas/public/lib/create_handlers.js rename {packages/kbn-interpreter/public => x-pack/plugins/canvas/public/lib}/interpreter.js (55%) rename {packages/kbn-interpreter => x-pack/plugins/canvas}/public/socket.js (64%) rename {src/core_plugins/interpreter => x-pack/plugins/canvas}/server/lib/__tests__/create_handlers.js (83%) rename {src/core_plugins/interpreter => x-pack/plugins/canvas}/server/lib/create_handlers.js (58%) create mode 100644 x-pack/plugins/canvas/server/lib/feature_check.js create mode 100644 x-pack/plugins/canvas/server/lib/get_plugin_paths.js create mode 100644 x-pack/plugins/canvas/server/lib/get_plugin_stream.js create mode 100644 x-pack/plugins/canvas/server/lib/get_request.js create mode 100644 x-pack/plugins/canvas/server/lib/plugin_paths.js rename {src/core_plugins/interpreter => x-pack/plugins/canvas}/server/lib/route_expression/browser.js (65%) rename {src/core_plugins/interpreter => x-pack/plugins/canvas}/server/lib/route_expression/index.js (51%) create mode 100644 x-pack/plugins/canvas/server/lib/route_expression/server.js create mode 100644 x-pack/plugins/canvas/server/lib/route_expression/thread/babeled.js rename {src/core_plugins/interpreter => x-pack/plugins/canvas}/server/lib/route_expression/thread/index.js (78%) create mode 100644 x-pack/plugins/canvas/server/lib/route_expression/thread/polyfill.js rename {src/core_plugins/interpreter => x-pack/plugins/canvas}/server/lib/route_expression/thread/worker.js (62%) create mode 100644 x-pack/plugins/canvas/server/lib/server_registries.js create mode 100644 x-pack/plugins/canvas/server/routes/plugins.js rename {src/core_plugins/interpreter => x-pack/plugins/canvas}/server/routes/socket.js (68%) create mode 100644 x-pack/plugins/canvas/server/routes/translate.js diff --git a/.eslintignore b/.eslintignore index 50901af5b9eeac..f697ad004caab3 100644 --- a/.eslintignore +++ b/.eslintignore @@ -27,8 +27,7 @@ bower_components /x-pack/coverage /x-pack/build /x-pack/plugins/**/__tests__/fixtures/** -/packages/kbn-interpreter/common/lib/grammar.js -/packages/kbn-interpreter/plugin +/x-pack/plugins/canvas/common/lib/grammar.js /x-pack/plugins/canvas/canvas_plugin /x-pack/plugins/canvas/canvas_plugin_src/lib/flot-charts **/*.js.snap diff --git a/package.json b/package.json index d4f63df304f9a2..b0555fad091e1e 100644 --- a/package.json +++ b/package.json @@ -92,7 +92,6 @@ "@kbn/pm": "1.0.0", "@kbn/test-subj-selector": "0.2.1", "@kbn/ui-framework": "1.0.0", - "@kbn/interpreter": "1.0.0", "JSONStream": "1.1.1", "abortcontroller-polyfill": "^1.1.9", "angular": "1.6.9", @@ -384,4 +383,4 @@ "node": "8.11.4", "yarn": "^1.10.1" } -} +} \ No newline at end of file diff --git a/packages/kbn-interpreter/.babelrc b/packages/kbn-interpreter/.babelrc deleted file mode 100644 index dc6a77bbe0bcd2..00000000000000 --- a/packages/kbn-interpreter/.babelrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "presets": ["@kbn/babel-preset/webpack_preset"] -} diff --git a/packages/kbn-interpreter/common/interpreter/create_error.js b/packages/kbn-interpreter/common/interpreter/create_error.js deleted file mode 100644 index 2740358b1c9605..00000000000000 --- a/packages/kbn-interpreter/common/interpreter/create_error.js +++ /dev/null @@ -1,26 +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. - */ - -export const createError = err => ({ - type: 'error', - error: { - stack: process.env.NODE_ENV === 'production' ? undefined : err.stack, - message: typeof err === 'string' ? err : err.message, - }, -}); diff --git a/packages/kbn-interpreter/common/lib/arg.js b/packages/kbn-interpreter/common/lib/arg.js deleted file mode 100644 index 0aa2b52e35acb0..00000000000000 --- a/packages/kbn-interpreter/common/lib/arg.js +++ /dev/null @@ -1,37 +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 { includes } from 'lodash'; - -export function Arg(config) { - if (config.name === '_') throw Error('Arg names must not be _. Use it in aliases instead.'); - this.name = config.name; - this.required = config.required || false; - this.help = config.help || ''; - this.types = config.types || []; - this.default = config.default; - this.aliases = config.aliases || []; - this.multi = config.multi == null ? false : config.multi; - this.resolve = config.resolve == null ? true : config.resolve; - this.options = config.options || []; - this.accepts = type => { - if (!this.types.length) return true; - return includes(config.types, type); - }; -} diff --git a/packages/kbn-interpreter/common/lib/arg.test.js b/packages/kbn-interpreter/common/lib/arg.test.js deleted file mode 100644 index 2edd65cd4af498..00000000000000 --- a/packages/kbn-interpreter/common/lib/arg.test.js +++ /dev/null @@ -1,35 +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 { Arg } from './arg'; - -describe('Arg', () => { - it('sets required to false by default', () => { - const isOptional = new Arg({ - name: 'optional_me', - }); - expect(isOptional.required).toBe(false); - - const isRequired = new Arg({ - name: 'require_me', - required: true, - }); - expect(isRequired.required).toBe(true); - }); -}); diff --git a/packages/kbn-interpreter/common/lib/functions_registry.js b/packages/kbn-interpreter/common/lib/functions_registry.js deleted file mode 100644 index 1c71707d84722f..00000000000000 --- a/packages/kbn-interpreter/common/lib/functions_registry.js +++ /dev/null @@ -1,29 +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 { Registry } from './registry'; -import { Fn } from './fn'; - -class FunctionsRegistry extends Registry { - wrapper(obj) { - return new Fn(obj); - } -} - -export const functionsRegistry = new FunctionsRegistry(); diff --git a/packages/kbn-interpreter/common/lib/get_by_alias.js b/packages/kbn-interpreter/common/lib/get_by_alias.js deleted file mode 100644 index d7bb1bbf9e79dc..00000000000000 --- a/packages/kbn-interpreter/common/lib/get_by_alias.js +++ /dev/null @@ -1,33 +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. - */ - -/** - * This is used for looking up function/argument definitions. It looks through - * the given object/array for a case-insensitive match, which could be either the - * `name` itself, or something under the `aliases` property. - */ -export function getByAlias(specs, name) { - const lowerCaseName = name.toLowerCase(); - return Object.values(specs).find(({ name, aliases }) => { - if (name.toLowerCase() === lowerCaseName) return true; - return (aliases || []).some(alias => { - return alias.toLowerCase() === lowerCaseName; - }); - }); -} diff --git a/packages/kbn-interpreter/common/lib/get_by_alias.test.js b/packages/kbn-interpreter/common/lib/get_by_alias.test.js deleted file mode 100644 index 9cfc37fd8f3041..00000000000000 --- a/packages/kbn-interpreter/common/lib/get_by_alias.test.js +++ /dev/null @@ -1,86 +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 { getByAlias } from './get_by_alias'; - -describe('getByAlias', () => { - const fnsObject = { - foo: { name: 'foo', aliases: ['f'] }, - bar: { name: 'bar', aliases: ['b'] }, - }; - - const fnsArray = [{ name: 'foo', aliases: ['f'] }, { name: 'bar', aliases: ['b'] }]; - - it('returns the function by name', () => { - expect(getByAlias(fnsObject, 'foo')).toBe(fnsObject.foo); - expect(getByAlias(fnsObject, 'bar')).toBe(fnsObject.bar); - expect(getByAlias(fnsArray, 'foo')).toBe(fnsArray[0]); - expect(getByAlias(fnsArray, 'bar')).toBe(fnsArray[1]); - }); - - it('returns the function by alias', () => { - expect(getByAlias(fnsObject, 'f')).toBe(fnsObject.foo); - expect(getByAlias(fnsObject, 'b')).toBe(fnsObject.bar); - expect(getByAlias(fnsArray, 'f')).toBe(fnsArray[0]); - expect(getByAlias(fnsArray, 'b')).toBe(fnsArray[1]); - }); - - it('returns the function by case-insensitive name', () => { - expect(getByAlias(fnsObject, 'FOO')).toBe(fnsObject.foo); - expect(getByAlias(fnsObject, 'BAR')).toBe(fnsObject.bar); - expect(getByAlias(fnsArray, 'FOO')).toBe(fnsArray[0]); - expect(getByAlias(fnsArray, 'BAR')).toBe(fnsArray[1]); - }); - - it('returns the function by case-insensitive alias', () => { - expect(getByAlias(fnsObject, 'F')).toBe(fnsObject.foo); - expect(getByAlias(fnsObject, 'B')).toBe(fnsObject.bar); - expect(getByAlias(fnsArray, 'F')).toBe(fnsArray[0]); - expect(getByAlias(fnsArray, 'B')).toBe(fnsArray[1]); - }); - - it('handles empty strings', () => { - const emptyStringFnsObject = { '': { name: '' } }; - const emptyStringAliasFnsObject = { foo: { name: 'foo', aliases: [''] } }; - expect(getByAlias(emptyStringFnsObject, '')).toBe(emptyStringFnsObject['']); - expect(getByAlias(emptyStringAliasFnsObject, '')).toBe(emptyStringAliasFnsObject.foo); - - const emptyStringFnsArray = [{ name: '' }]; - const emptyStringAliasFnsArray = [{ name: 'foo', aliases: [''] }]; - expect(getByAlias(emptyStringFnsArray, '')).toBe(emptyStringFnsArray[0]); - expect(getByAlias(emptyStringAliasFnsArray, '')).toBe(emptyStringAliasFnsArray[0]); - }); - - it('handles "undefined" strings', () => { - const undefinedFnsObject = { undefined: { name: 'undefined' } }; - const undefinedAliasFnsObject = { foo: { name: 'undefined', aliases: ['undefined'] } }; - expect(getByAlias(undefinedFnsObject, 'undefined')).toBe(undefinedFnsObject.undefined); - expect(getByAlias(undefinedAliasFnsObject, 'undefined')).toBe(undefinedAliasFnsObject.foo); - - const emptyStringFnsArray = [{ name: 'undefined' }]; - const emptyStringAliasFnsArray = [{ name: 'foo', aliases: ['undefined'] }]; - expect(getByAlias(emptyStringFnsArray, 'undefined')).toBe(emptyStringFnsArray[0]); - expect(getByAlias(emptyStringAliasFnsArray, 'undefined')).toBe(emptyStringAliasFnsArray[0]); - }); - - it('returns undefined if not found', () => { - expect(getByAlias(fnsObject, 'baz')).toBe(undefined); - expect(getByAlias(fnsArray, 'baz')).toBe(undefined); - }); -}); diff --git a/packages/kbn-interpreter/common/lib/get_type.js b/packages/kbn-interpreter/common/lib/get_type.js deleted file mode 100644 index ac440acf8da5dc..00000000000000 --- a/packages/kbn-interpreter/common/lib/get_type.js +++ /dev/null @@ -1,28 +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. - */ - -export function getType(node) { - if (node == null) return 'null'; - if (typeof node === 'object') { - if (!node.type) throw new Error('Objects must have a type property'); - return node.type; - } - - return typeof node; -} diff --git a/packages/kbn-interpreter/common/lib/paths_registry.js b/packages/kbn-interpreter/common/lib/paths_registry.js deleted file mode 100644 index 3ad2b5dddf82e1..00000000000000 --- a/packages/kbn-interpreter/common/lib/paths_registry.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. - */ - -class PathsRegistry { - - constructor() { - this.paths = new Map(); - } - - register = (type, paths) => { - if (!type) { - throw new Error(`Register requires a type`); - } - const lowerCaseType = type.toLowerCase(); - - const pathArray = Array.isArray(paths) ? paths : [paths]; - if (!this.paths.has(lowerCaseType)) { - this.paths.set(lowerCaseType, []); - } - - pathArray.forEach(p => { - this.paths.get(lowerCaseType).push(p); - }); - }; - - registerAll = (paths) => { - Object.keys(paths).forEach(type => { - this.register(type, paths[type]); - }); - }; - - toArray = () => { - return [...this.paths.values()]; - }; - - get = (type) => { - if (!type) { - return []; - } - const lowerCaseType = type.toLowerCase(); - return this.paths.has(lowerCaseType) ? this.paths.get(lowerCaseType) : []; - }; - - reset = () => { - this.paths.clear(); - }; -} - -export const pathsRegistry = new PathsRegistry(); diff --git a/packages/kbn-interpreter/common/lib/paths_registry.test.js b/packages/kbn-interpreter/common/lib/paths_registry.test.js deleted file mode 100644 index ad2b9d949deb3f..00000000000000 --- a/packages/kbn-interpreter/common/lib/paths_registry.test.js +++ /dev/null @@ -1,92 +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. - */ - -describe('pathsRegistry', () => { - let registry; - beforeEach(() => { - jest.resetModules(); - registry = require('./paths_registry').pathsRegistry; - }); - - const paths = { - foo: 'bar', - sometype: [ - 'Here', - 'be', - 'more', - 'paths!' - ], - anothertype: ['with just one lonely path'] - }; - - it('throws when no type is provided', () => { - const check = () => registry.register(null, paths.foo); - expect(check).toThrowError(/requires a type/); - }); - - it('accepts paths as a string', () => { - registry.register('foo', paths.foo); - expect(registry.get('foo')).toEqual([paths.foo]); - }); - - it('accepts paths as an array', () => { - registry.register('sometype', paths.sometype); - expect(registry.get('sometype')).toEqual(paths.sometype); - }); - - it('ignores case when setting items', () => { - registry.register('FOO', paths.foo); - expect(registry.get('foo')).toEqual([paths.foo]); - }); - - it('gets items by lookup property', () => { - registry.register('sometype', paths.sometype); - expect(registry.get('sometype')).toEqual(paths.sometype); - }); - - it('can register an object of `type: path` key-value pairs', () => { - registry.registerAll(paths); - expect(registry.get('foo')).toEqual([paths.foo]); - expect(registry.get('sometype')).toEqual(paths.sometype); - expect(registry.get('anothertype')).toEqual(paths.anothertype); - }); - - it('ignores case when getting items', () => { - registry.registerAll(paths); - expect(registry.get('FOO')).toEqual([paths.foo]); - expect(registry.get('SOmEType')).toEqual(paths.sometype); - expect(registry.get('anoThertYPE')).toEqual(paths.anothertype); - }); - - it('returns an empty array with no match', () => { - expect(registry.get('@@nope_nope')).toEqual([]); - }); - - it('returns an array of all path values', () => { - registry.registerAll(paths); - expect(registry.toArray()).toEqual([[paths.foo], paths.sometype, paths.anothertype]); - }); - - it('resets the registry', () => { - registry.registerAll(paths); - expect(registry.get('sometype')).toEqual(paths.sometype); - registry.reset(); - expect(registry.get('sometype')).toEqual([]); - }); -}); \ No newline at end of file diff --git a/packages/kbn-interpreter/common/lib/serialize.js b/packages/kbn-interpreter/common/lib/serialize.js deleted file mode 100644 index 2f881db3c77e0c..00000000000000 --- a/packages/kbn-interpreter/common/lib/serialize.js +++ /dev/null @@ -1,37 +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 { get, identity } from 'lodash'; -import { getType } from './get_type'; - -export function serializeProvider(types) { - return { - serialize: provider('serialize'), - deserialize: provider('deserialize'), - }; - - function provider(key) { - return context => { - const type = getType(context); - const typeDef = types[type]; - const fn = get(typeDef, key) || identity; - return fn(context); - }; - } -} diff --git a/packages/kbn-interpreter/common/lib/types_registry.js b/packages/kbn-interpreter/common/lib/types_registry.js deleted file mode 100644 index 97e28875d7e201..00000000000000 --- a/packages/kbn-interpreter/common/lib/types_registry.js +++ /dev/null @@ -1,29 +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 { Registry } from './registry'; -import { Type } from './type'; - -class TypesRegistry extends Registry { - wrapper(obj) { - return new Type(obj); - } -} - -export const typesRegistry = new TypesRegistry(); diff --git a/packages/kbn-interpreter/package.json b/packages/kbn-interpreter/package.json deleted file mode 100644 index 0178b9e2cfe327..00000000000000 --- a/packages/kbn-interpreter/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "@kbn/interpreter", - "version": "1.0.0", - "license": "Apache-2.0", - "scripts": { - "build": "node tasks/build.js", - "canvas:peg": "pegjs common/lib/grammar.peg", - "kbn:bootstrap": "yarn build" - } -} diff --git a/packages/kbn-interpreter/plugin_src/functions/common/clog.js b/packages/kbn-interpreter/plugin_src/functions/common/clog.js deleted file mode 100644 index 634d166f5f0bb5..00000000000000 --- a/packages/kbn-interpreter/plugin_src/functions/common/clog.js +++ /dev/null @@ -1,27 +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. - */ - -export const clog = () => ({ - name: 'clog', - help: 'Outputs the context to the console', - fn: context => { - console.log(context); //eslint-disable-line no-console - return context; - }, -}); diff --git a/packages/kbn-interpreter/plugin_src/functions/common/index.js b/packages/kbn-interpreter/plugin_src/functions/common/index.js deleted file mode 100644 index 2f5f91181faec4..00000000000000 --- a/packages/kbn-interpreter/plugin_src/functions/common/index.js +++ /dev/null @@ -1,24 +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 { clog } from './clog'; - -export const commonFunctions = [ - clog, -]; diff --git a/packages/kbn-interpreter/plugin_src/functions/common/register.js b/packages/kbn-interpreter/plugin_src/functions/common/register.js deleted file mode 100644 index 8b146b8f849c37..00000000000000 --- a/packages/kbn-interpreter/plugin_src/functions/common/register.js +++ /dev/null @@ -1,23 +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 { commonFunctions } from './index'; - -// eslint-disable-next-line no-undef -commonFunctions.forEach(canvas.register); diff --git a/packages/kbn-interpreter/plugin_src/types/boolean.js b/packages/kbn-interpreter/plugin_src/types/boolean.js deleted file mode 100644 index cc5f0a79e39a84..00000000000000 --- a/packages/kbn-interpreter/plugin_src/types/boolean.js +++ /dev/null @@ -1,42 +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. - */ - -export const boolean = () => ({ - name: 'boolean', - from: { - null: () => false, - number: n => Boolean(n), - string: s => Boolean(s), - }, - to: { - render: value => { - const text = `${value}`; - return { - type: 'render', - as: 'text', - value: { text }, - }; - }, - datatable: value => ({ - type: 'datatable', - columns: [{ name: 'value', type: 'boolean' }], - rows: [{ value }], - }), - }, -}); diff --git a/packages/kbn-interpreter/plugin_src/types/error.js b/packages/kbn-interpreter/plugin_src/types/error.js deleted file mode 100644 index 1415a065d810e8..00000000000000 --- a/packages/kbn-interpreter/plugin_src/types/error.js +++ /dev/null @@ -1,35 +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. - */ - -export const error = () => ({ - name: 'error', - to: { - render: input => { - const { error, info } = input; - return { - type: 'render', - as: 'error', - value: { - error, - info, - }, - }; - }, - }, -}); diff --git a/packages/kbn-interpreter/plugin_src/types/filter.js b/packages/kbn-interpreter/plugin_src/types/filter.js deleted file mode 100644 index 484050671b2f95..00000000000000 --- a/packages/kbn-interpreter/plugin_src/types/filter.js +++ /dev/null @@ -1,33 +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. - */ - -export const filter = () => ({ - name: 'filter', - from: { - null: () => { - return { - type: 'filter', - // Any meta data you wish to pass along. - meta: {}, - // And filters. If you need an "or", create a filter type for it. - and: [], - }; - }, - }, -}); diff --git a/packages/kbn-interpreter/plugin_src/types/image.js b/packages/kbn-interpreter/plugin_src/types/image.js deleted file mode 100644 index 7666451145f5d3..00000000000000 --- a/packages/kbn-interpreter/plugin_src/types/image.js +++ /dev/null @@ -1,31 +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. - */ - -export const image = () => ({ - name: 'image', - to: { - render: input => { - return { - type: 'render', - as: 'image', - value: input, - }; - }, - }, -}); diff --git a/packages/kbn-interpreter/plugin_src/types/index.js b/packages/kbn-interpreter/plugin_src/types/index.js deleted file mode 100644 index 1ae5f874835c30..00000000000000 --- a/packages/kbn-interpreter/plugin_src/types/index.js +++ /dev/null @@ -1,46 +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 { boolean } from './boolean'; -import { datatable } from './datatable'; -import { error } from './error'; -import { filter } from './filter'; -import { image } from './image'; -import { nullType } from './null'; -import { number } from './number'; -import { pointseries } from './pointseries'; -import { render } from './render'; -import { shape } from './shape'; -import { string } from './string'; -import { style } from './style'; - -export const typeSpecs = [ - boolean, - datatable, - error, - filter, - image, - number, - nullType, - pointseries, - render, - shape, - string, - style, -]; diff --git a/packages/kbn-interpreter/plugin_src/types/null.js b/packages/kbn-interpreter/plugin_src/types/null.js deleted file mode 100644 index 2789ce330ac6c4..00000000000000 --- a/packages/kbn-interpreter/plugin_src/types/null.js +++ /dev/null @@ -1,25 +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. - */ - -export const nullType = () => ({ - name: 'null', - from: { - '*': () => null, - }, -}); diff --git a/packages/kbn-interpreter/plugin_src/types/number.js b/packages/kbn-interpreter/plugin_src/types/number.js deleted file mode 100644 index 8f8f31ea8a2fb1..00000000000000 --- a/packages/kbn-interpreter/plugin_src/types/number.js +++ /dev/null @@ -1,42 +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. - */ - -export const number = () => ({ - name: 'number', - from: { - null: () => 0, - boolean: b => Number(b), - string: n => Number(n), - }, - to: { - render: value => { - const text = `${value}`; - return { - type: 'render', - as: 'text', - value: { text }, - }; - }, - datatable: value => ({ - type: 'datatable', - columns: [{ name: 'value', type: 'number' }], - rows: [{ value }], - }), - }, -}); diff --git a/packages/kbn-interpreter/plugin_src/types/pointseries.js b/packages/kbn-interpreter/plugin_src/types/pointseries.js deleted file mode 100644 index 2275ea9e040944..00000000000000 --- a/packages/kbn-interpreter/plugin_src/types/pointseries.js +++ /dev/null @@ -1,44 +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. - */ - -export const pointseries = () => ({ - name: 'pointseries', - from: { - null: () => { - return { - type: 'pointseries', - rows: [], - columns: [], - }; - }, - }, - to: { - render: (pointseries, types) => { - const datatable = types.datatable.from(pointseries, types); - return { - type: 'render', - as: 'table', - value: { - datatable, - showHeader: true, - }, - }; - }, - }, -}); diff --git a/packages/kbn-interpreter/plugin_src/types/register.js b/packages/kbn-interpreter/plugin_src/types/register.js deleted file mode 100644 index 17b03f0229672d..00000000000000 --- a/packages/kbn-interpreter/plugin_src/types/register.js +++ /dev/null @@ -1,24 +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 'babel-polyfill'; -import { typeSpecs } from './index'; - -// eslint-disable-next-line no-undef -typeSpecs.forEach(canvas.register); diff --git a/packages/kbn-interpreter/plugin_src/types/render.js b/packages/kbn-interpreter/plugin_src/types/render.js deleted file mode 100644 index 99ce3ca7d1cd7d..00000000000000 --- a/packages/kbn-interpreter/plugin_src/types/render.js +++ /dev/null @@ -1,29 +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. - */ - -export const render = () => ({ - name: 'render', - from: { - '*': v => ({ - type: 'render', - as: 'debug', - value: v, - }), - }, -}); diff --git a/packages/kbn-interpreter/plugin_src/types/shape.js b/packages/kbn-interpreter/plugin_src/types/shape.js deleted file mode 100644 index 1ed7a111268d1f..00000000000000 --- a/packages/kbn-interpreter/plugin_src/types/shape.js +++ /dev/null @@ -1,31 +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. - */ - -export const shape = () => ({ - name: 'shape', - to: { - render: input => { - return { - type: 'render', - as: 'shape', - value: input, - }; - }, - }, -}); diff --git a/packages/kbn-interpreter/plugin_src/types/string.js b/packages/kbn-interpreter/plugin_src/types/string.js deleted file mode 100644 index 90e6b17cc9dcf0..00000000000000 --- a/packages/kbn-interpreter/plugin_src/types/string.js +++ /dev/null @@ -1,41 +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. - */ - -export const string = () => ({ - name: 'string', - from: { - null: () => '', - boolean: b => String(b), - number: n => String(n), - }, - to: { - render: text => { - return { - type: 'render', - as: 'text', - value: { text }, - }; - }, - datatable: value => ({ - type: 'datatable', - columns: [{ name: 'value', type: 'string' }], - rows: [{ value }], - }), - }, -}); diff --git a/packages/kbn-interpreter/plugin_src/types/style.js b/packages/kbn-interpreter/plugin_src/types/style.js deleted file mode 100644 index 97057b415a4754..00000000000000 --- a/packages/kbn-interpreter/plugin_src/types/style.js +++ /dev/null @@ -1,31 +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. - */ - -export const style = () => ({ - name: 'style', - from: { - null: () => { - return { - type: 'style', - spec: {}, - css: '', - }; - }, - }, -}); diff --git a/packages/kbn-interpreter/public/browser_registries.js b/packages/kbn-interpreter/public/browser_registries.js deleted file mode 100644 index 778a0b03a76242..00000000000000 --- a/packages/kbn-interpreter/public/browser_registries.js +++ /dev/null @@ -1,83 +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 chrome from 'ui/chrome'; -import $script from 'scriptjs'; - -let resolvePromise = null; -let called = false; - -let populatePromise = new Promise(_resolve => { - resolvePromise = _resolve; -}); - -export const getBrowserRegistries = () => { - return populatePromise; -}; - -const loadBrowserRegistries = (registries) => { - const remainingTypes = Object.keys(registries); - const populatedTypes = {}; - - return new Promise(resolve => { - function loadType() { - if (!remainingTypes.length) { - resolve(populatedTypes); - return; - } - const type = remainingTypes.pop(); - window.canvas = window.canvas || {}; - window.canvas.register = d => registries[type].register(d); - - // Load plugins one at a time because each needs a different loader function - // $script will only load each of these once, we so can call this as many times as we need? - const pluginPath = chrome.addBasePath(`/api/canvas/plugins?type=${type}`); - $script(pluginPath, () => { - populatedTypes[type] = registries[type]; - loadType(); - }); - } - - loadType(); - }); -}; - -export const populateBrowserRegistries = (registries) => { - if (called) { - const oldPromise = populatePromise; - let newResolve; - populatePromise = new Promise(_resolve => { - newResolve = _resolve; - }); - oldPromise.then(oldTypes => { - loadBrowserRegistries(registries).then(newTypes => { - newResolve({ - ...oldTypes, - ...newTypes, - }); - }); - }); - return populatePromise; - } - called = true; - loadBrowserRegistries(registries).then(registries => { - resolvePromise(registries); - }); - return populatePromise; -}; diff --git a/packages/kbn-interpreter/public/create_handlers.js b/packages/kbn-interpreter/public/create_handlers.js deleted file mode 100644 index 3446a945ae76e3..00000000000000 --- a/packages/kbn-interpreter/public/create_handlers.js +++ /dev/null @@ -1,24 +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. - */ - -export function createHandlers(/*socket*/) { - return { - environment: 'client', - }; -} diff --git a/packages/kbn-interpreter/server/get_plugin_paths.js b/packages/kbn-interpreter/server/get_plugin_paths.js deleted file mode 100644 index f6520563c912ff..00000000000000 --- a/packages/kbn-interpreter/server/get_plugin_paths.js +++ /dev/null @@ -1,55 +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 fs from 'fs'; -import { resolve } from 'path'; -import { promisify } from 'util'; -import { flatten } from 'lodash'; -import { pathsRegistry } from '../common/lib/paths_registry'; - -const lstat = promisify(fs.lstat); -const readdir = promisify(fs.readdir); - -const isDirectory = path => - lstat(path) - .then(stat => stat.isDirectory()) - .catch(() => false); - -export const getPluginPaths = type => { - const typePaths = pathsRegistry.get(type); - if (!typePaths) { - throw new Error(`Unknown type: ${type}`); - } - - return Promise.all(typePaths.map(async path => { - const isDir = await isDirectory(path); - if (!isDir) { - return; - } - // Get the full path of all js files in the directory - return readdir(path).then(files => { - return files.reduce((acc, file) => { - if (file.endsWith('.js')) { - acc.push(resolve(path, file)); - } - return acc; - }, []); - }).catch(); - })).then(flatten); -}; diff --git a/packages/kbn-interpreter/server/server_registries.js b/packages/kbn-interpreter/server/server_registries.js deleted file mode 100644 index 3fbb957673e639..00000000000000 --- a/packages/kbn-interpreter/server/server_registries.js +++ /dev/null @@ -1,78 +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 { typesRegistry } from '../common/lib/types_registry'; -import { functionsRegistry as serverFunctions } from '../common/lib/functions_registry'; -import { getPluginPaths } from './get_plugin_paths'; - -const registries = { - serverFunctions: serverFunctions, - commonFunctions: serverFunctions, - types: typesRegistry, -}; - -let resolve = null; -let called = false; - -const populatePromise = new Promise(_resolve => { - resolve = _resolve; -}); - -export const getServerRegistries = () => { - return populatePromise; -}; - -export const populateServerRegistries = types => { - if (called) { - console.log('function should only be called once per process'); - return populatePromise; - } - called = true; - if (!types || !types.length) throw new Error('types is required'); - - const remainingTypes = types; - const populatedTypes = {}; - - const globalKeys = Object.keys(global); - - const loadType = () => { - const type = remainingTypes.pop(); - getPluginPaths(type).then(paths => { - global.canvas = global.canvas || {}; - global.canvas.register = d => registries[type].register(d); - - paths.forEach(path => { - require(path); - }); - - Object.keys(global).forEach(key => { - if (!globalKeys.includes(key)) { - delete global[key]; - } - }); - - populatedTypes[type] = registries[type]; - if (remainingTypes.length) loadType(); - else resolve(populatedTypes); - }); - }; - - if (remainingTypes.length) loadType(); - return populatePromise; -}; diff --git a/packages/kbn-interpreter/tasks/build.js b/packages/kbn-interpreter/tasks/build.js deleted file mode 100644 index 37776e8d74cca8..00000000000000 --- a/packages/kbn-interpreter/tasks/build.js +++ /dev/null @@ -1,40 +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 webpack = require('webpack'); -const webpackConfig = require('./webpack.plugins'); - -const devtool = 'inline-cheap-module-source-map'; - -const onComplete = function (done) { - return function (err, stats) { - if (err) { - done && done(err); - } else { - const seconds = ((stats.endTime - stats.startTime) / 1000).toFixed(2); - console.log(`Plugins built in ${seconds} seconds`); - done && done(); - } - }; -}; - -webpack({ ...webpackConfig, devtool }, onComplete(function () { - console.log('all done'); -})); - diff --git a/packages/kbn-interpreter/tasks/webpack.plugins.js b/packages/kbn-interpreter/tasks/webpack.plugins.js deleted file mode 100644 index 8b16edc5ad4622..00000000000000 --- a/packages/kbn-interpreter/tasks/webpack.plugins.js +++ /dev/null @@ -1,100 +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 path = require('path'); - -const sourceDir = path.resolve(__dirname, '../plugin_src'); -const buildDir = path.resolve(__dirname, '../plugin'); - -module.exports = { - entry: { - 'types/all': path.join(sourceDir, 'types/register.js'), - 'functions/common/all': path.join(sourceDir, 'functions/common/register.js'), - }, - target: 'webworker', - - output: { - path: buildDir, - filename: '[name].js', // Need long paths here. - libraryTarget: 'umd', - }, - - resolve: { - extensions: ['.js', '.json'], - mainFields: ['browser', 'main'], - }, - - plugins: [ - function loaderFailHandler() { - // bails on error, including loader errors - // see https://github.com/webpack/webpack/issues/708, which does not fix loader errors - let isWatch = true; - - this.plugin('run', function (compiler, callback) { - isWatch = false; - callback.call(compiler); - }); - - this.plugin('done', function (stats) { - if (!stats.hasErrors()) { - return; - } - const errorMessage = stats.toString('errors-only'); - if (isWatch) { - console.error(errorMessage); - } - else { - throw new Error(errorMessage); - } - }); - }, - ], - - module: { - rules: [ - { - test: /\.js$/, - exclude: [/node_modules/], - loaders: 'babel-loader', - options: { - babelrc: false, - presets: [require.resolve('@kbn/babel-preset/webpack_preset')], - }, - }, - { - test: /\.(png|jpg|gif|jpeg|svg)$/, - loaders: ['url-loader'], - }, - { - test: /\.(css|scss)$/, - loaders: ['style-loader', 'css-loader', 'sass-loader'], - }, - ], - }, - - node: { - // Don't replace built-in globals - __filename: false, - __dirname: false, - }, - - watchOptions: { - ignored: [/node_modules/], - }, -}; diff --git a/src/core_plugins/interpreter/common/constants.js b/src/core_plugins/interpreter/common/constants.js deleted file mode 100644 index a5751ee72e8265..00000000000000 --- a/src/core_plugins/interpreter/common/constants.js +++ /dev/null @@ -1,21 +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. - */ - -export const SECURITY_AUTH_MESSAGE = 'Authentication failed'; -export const API_ROUTE = '/api/canvas'; diff --git a/src/core_plugins/interpreter/index.js b/src/core_plugins/interpreter/index.js deleted file mode 100644 index 273c8b8c37957a..00000000000000 --- a/src/core_plugins/interpreter/index.js +++ /dev/null @@ -1,41 +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 { resolve } from 'path'; -import init from './init'; -import { pathsRegistry } from '@kbn/interpreter/common/lib/paths_registry'; -import { pluginPaths } from './plugin_paths'; - -export default function (kibana) { - return new kibana.Plugin({ - id: 'interpreter', - require: ['kibana', 'elasticsearch'], - publicDir: resolve(__dirname, 'public'), - uiExports: { - hacks: [ - 'plugins/interpreter/load_browser_plugins.js', - ], - }, - preInit: () => { - pathsRegistry.registerAll(pluginPaths); - }, - init, - }); -} - diff --git a/src/core_plugins/interpreter/init.js b/src/core_plugins/interpreter/init.js deleted file mode 100644 index 58385973ac9301..00000000000000 --- a/src/core_plugins/interpreter/init.js +++ /dev/null @@ -1,41 +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 { routes } from './server/routes'; -import { functionsRegistry } from '@kbn/interpreter/common/lib/functions_registry'; -import { populateServerRegistries } from '@kbn/interpreter/server/server_registries'; - -export default function (server /*options*/) { - server.injectUiAppVars('canvas', () => { - const config = server.config(); - const basePath = config.get('server.basePath'); - const reportingBrowserType = config.get('xpack.reporting.capture.browser.type'); - - return { - kbnIndex: config.get('kibana.index'), - esShardTimeout: config.get('elasticsearch.shardTimeout'), - esApiVersion: config.get('elasticsearch.apiVersion'), - serverFunctions: functionsRegistry.toArray(), - basePath, - reportingBrowserType, - }; - }); - - populateServerRegistries(['serverFunctions', 'types']).then(() => routes(server)); -} diff --git a/src/core_plugins/interpreter/package.json b/src/core_plugins/interpreter/package.json deleted file mode 100644 index 3265dadd7fbfc2..00000000000000 --- a/src/core_plugins/interpreter/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "interpreter", - "version": "kibana" -} diff --git a/src/core_plugins/interpreter/plugin_paths.js b/src/core_plugins/interpreter/plugin_paths.js deleted file mode 100644 index ca44ce1a1f7b29..00000000000000 --- a/src/core_plugins/interpreter/plugin_paths.js +++ /dev/null @@ -1,27 +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 { resolve } from 'path'; - -const dir = resolve(__dirname, '..', '..', '..'); - -export const pluginPaths = { - commonFunctions: resolve(dir, 'node_modules/@kbn/interpreter/plugin/functions/common'), - types: resolve(dir, 'node_modules/@kbn/interpreter/plugin/types'), -}; diff --git a/src/core_plugins/interpreter/public/load_browser_plugins.js b/src/core_plugins/interpreter/public/load_browser_plugins.js deleted file mode 100644 index 6322e8e340e451..00000000000000 --- a/src/core_plugins/interpreter/public/load_browser_plugins.js +++ /dev/null @@ -1,30 +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 { populateBrowserRegistries } from '@kbn/interpreter/public/browser_registries'; -import { typesRegistry } from '@kbn/interpreter/common/lib/types_registry'; -import { functionsRegistry } from '@kbn/interpreter/common/lib/functions_registry'; - -const types = { - commonFunctions: functionsRegistry, - browserFunctions: functionsRegistry, - types: typesRegistry -}; - -populateBrowserRegistries(types); diff --git a/src/core_plugins/interpreter/server/lib/feature_check.js b/src/core_plugins/interpreter/server/lib/feature_check.js deleted file mode 100644 index 9f7a8993fa3ff6..00000000000000 --- a/src/core_plugins/interpreter/server/lib/feature_check.js +++ /dev/null @@ -1,26 +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. - */ - -// TODO: replace this when we use the method exposed by security https://github.com/elastic/kibana/pull/24616 -export const isSecurityEnabled = server => { - const kibanaSecurity = server.plugins.security; - const esSecurity = server.plugins.xpack_main.info.feature('security'); - - return kibanaSecurity && esSecurity.isAvailable() && esSecurity.isEnabled(); -}; diff --git a/src/core_plugins/interpreter/server/lib/get_plugin_stream.js b/src/core_plugins/interpreter/server/lib/get_plugin_stream.js deleted file mode 100644 index d685d365d31a40..00000000000000 --- a/src/core_plugins/interpreter/server/lib/get_plugin_stream.js +++ /dev/null @@ -1,37 +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 fs from 'fs'; -import ss from 'stream-stream'; -import { getPluginPaths } from '@kbn/interpreter/server/get_plugin_paths'; - -export const getPluginStream = type => { - const stream = ss({ - separator: '\n', - }); - - getPluginPaths(type).then(files => { - files.forEach(file => { - stream.write(fs.createReadStream(file)); - }); - stream.end(); - }); - - return stream; -}; diff --git a/src/core_plugins/interpreter/server/lib/get_request.js b/src/core_plugins/interpreter/server/lib/get_request.js deleted file mode 100644 index 2b29b05fd07aab..00000000000000 --- a/src/core_plugins/interpreter/server/lib/get_request.js +++ /dev/null @@ -1,44 +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 boom from 'boom'; -import { API_ROUTE } from '../../common/constants'; - -export function getRequest(server, { headers }) { - const url = `${API_ROUTE}/ping`; - - return server - .inject({ - method: 'POST', - url, - headers, - }) - .then(res => { - if (res.statusCode !== 200) { - if (process.env.NODE_ENV !== 'production') { - console.error( - new Error(`Auth request failed: [${res.statusCode}] ${res.result.message}`) - ); - } - throw boom.unauthorized('Failed to authenticate socket connection'); - } - - return res.request; - }); -} diff --git a/src/core_plugins/interpreter/server/lib/route_expression/server.js b/src/core_plugins/interpreter/server/lib/route_expression/server.js deleted file mode 100644 index 50a80a1e0275a4..00000000000000 --- a/src/core_plugins/interpreter/server/lib/route_expression/server.js +++ /dev/null @@ -1,40 +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 { getServerRegistries } from '@kbn/interpreter/server/server_registries'; -import { interpretProvider } from '@kbn/interpreter/common/interpreter/interpret'; -import { createHandlers } from '../create_handlers'; - -export const server = async ({ onFunctionNotFound, server, request }) => { - const { serverFunctions, types } = await getServerRegistries(['serverFunctions', 'types']); - - return { - interpret: (ast, context) => { - const interpret = interpretProvider({ - types: types.toJS(), - functions: serverFunctions.toJS(), - handlers: createHandlers(request, server), - onFunctionNotFound, - }); - - return interpret(ast, context); - }, - getFunctions: () => Object.keys(serverFunctions.toJS()), - }; -}; diff --git a/src/core_plugins/interpreter/server/lib/route_expression/thread/babeled.js b/src/core_plugins/interpreter/server/lib/route_expression/thread/babeled.js deleted file mode 100644 index 2a19ef81d135e9..00000000000000 --- a/src/core_plugins/interpreter/server/lib/route_expression/thread/babeled.js +++ /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. - */ - -require('babel-register')({ - ignore: [ - // stolen from kibana/src/setup_node_env/babel_register/register.js - // ignore paths matching `/node_modules/{a}/{b}`, unless `a` - // is `x-pack` and `b` is not `node_modules` - /\/node_modules\/(?!x-pack\/(?!node_modules)([^\/]+))([^\/]+\/[^\/]+)/, - ], - babelrc: false, - presets: [require.resolve('@kbn/babel-preset/node_preset')], -}); - -require('./polyfill'); -require('./worker'); diff --git a/src/core_plugins/interpreter/server/lib/route_expression/thread/polyfill.js b/src/core_plugins/interpreter/server/lib/route_expression/thread/polyfill.js deleted file mode 100644 index 476777b4bc6932..00000000000000 --- a/src/core_plugins/interpreter/server/lib/route_expression/thread/polyfill.js +++ /dev/null @@ -1,31 +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. - */ - -// taken from kibana/src/setup_node_env/babel_register/polyfill.js -// ... -// `babel-preset-env` looks for and rewrites the following import -// statement into a list of import statements based on the polyfills -// necessary for our target environment (the current version of node) -// but since it does that during compilation, `import 'babel-polyfill'` -// must be in a file that is loaded with `require()` AFTER `babel-register` -// is configured. -// -// This is why we have this single statement in it's own file and require -// it from ./babeled.js -import 'babel-polyfill'; diff --git a/src/core_plugins/interpreter/server/routes/index.js b/src/core_plugins/interpreter/server/routes/index.js deleted file mode 100644 index f78baf4ad496d9..00000000000000 --- a/src/core_plugins/interpreter/server/routes/index.js +++ /dev/null @@ -1,28 +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 { socketApi } from './socket'; -import { translate } from './translate'; -import { plugins } from './plugins'; - -export function routes(server) { - plugins(server); - socketApi(server); - translate(server); -} diff --git a/src/core_plugins/interpreter/server/routes/plugins.js b/src/core_plugins/interpreter/server/routes/plugins.js deleted file mode 100644 index 3d8c8614cc1075..00000000000000 --- a/src/core_plugins/interpreter/server/routes/plugins.js +++ /dev/null @@ -1,35 +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 { getPluginStream } from '../lib/get_plugin_stream'; - -export function plugins(server) { - server.route({ - method: 'GET', - path: '/api/canvas/plugins', - handler: function (request) { - const { type } = request.query; - - return getPluginStream(type); - }, - config: { - auth: false, - }, - }); -} diff --git a/src/core_plugins/interpreter/server/routes/translate.js b/src/core_plugins/interpreter/server/routes/translate.js deleted file mode 100644 index 865c0da3e06171..00000000000000 --- a/src/core_plugins/interpreter/server/routes/translate.js +++ /dev/null @@ -1,48 +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 { fromExpression, toExpression } from '@kbn/interpreter/common/lib/ast'; - -export function translate(server) { - /* - Get AST from expression - */ - server.route({ - method: 'GET', - path: '/api/canvas/ast', - handler: function (request, h) { - if (!request.query.expression) { - return h.response({ error: '"expression" query is required' }).code(400); - } - return fromExpression(request.query.expression); - }, - }); - - server.route({ - method: 'POST', - path: '/api/canvas/expression', - handler: function (request, h) { - try { - return toExpression(request.payload); - } catch (e) { - return h.response({ error: e.message }).code(400); - } - }, - }); -} diff --git a/src/optimize/base_optimizer.js b/src/optimize/base_optimizer.js index 1bf29fbac1d9d7..b0fe947f569205 100644 --- a/src/optimize/base_optimizer.js +++ b/src/optimize/base_optimizer.js @@ -150,9 +150,8 @@ export default class BaseOptimizer { }, { test, - include: /[\/\\]node_modules[\/\\](x-pack|@kbn[\/\\]interpreter)[\/\\]/, - exclude: /[\/\\]node_modules[\/\\](x-pack|@kbn[\/\\]interpreter)[\/\\]node_modules[\/\\]/, - + include: /[\/\\]node_modules[\/\\]x-pack[\/\\]/, + exclude: /[\/\\]node_modules[\/\\]x-pack[\/\\](.+?[\/\\])*node_modules[\/\\]/, } ]; }; diff --git a/src/setup_node_env/babel_register/register.js b/src/setup_node_env/babel_register/register.js index 17dd7f0705df11..8c49c624f4894c 100644 --- a/src/setup_node_env/babel_register/register.js +++ b/src/setup_node_env/babel_register/register.js @@ -38,11 +38,11 @@ var ignore = [ // https://github.com/elastic/kibana/issues/14800#issuecomment-366130268 // ignore paths matching `/node_modules/{a}/{b}`, unless `a` - // is `x-pack` or `@kbn/interpreter` and `b` is not `node_modules` - /\/node_modules\/(?!(x-pack\/|@kbn\/interpreter\/)(?!node_modules)([^\/]+))([^\/]+\/[^\/]+)/, + // is `x-pack` or `b` is not `node_modules` + /\/node_modules\/(?!x-pack\/(?!node_modules)([^\/]+))([^\/]+\/[^\/]+)/, // ignore paths matching `/canvas/canvas_plugin/{a}/{b}` unless - // `a` is `functions` and `b` is `server` + // is `x-pack` and `b` is not `node_modules` /\/canvas\/canvas_plugin\/(?!functions\/server)([^\/]+\/[^\/]+)/, ]; diff --git a/src/ui/ui_settings/create_or_upgrade_saved_config/__tests__/create_or_upgrade_integration.js b/src/ui/ui_settings/create_or_upgrade_saved_config/__tests__/create_or_upgrade_integration.js index 1c8ade94456d0d..34415cb6aeef50 100644 --- a/src/ui/ui_settings/create_or_upgrade_saved_config/__tests__/create_or_upgrade_integration.js +++ b/src/ui/ui_settings/create_or_upgrade_saved_config/__tests__/create_or_upgrade_integration.js @@ -201,4 +201,4 @@ describe('createOrUpgradeSavedConfig()', () => { '5.4.0-rc1': true, }); }); -}); +}); \ No newline at end of file diff --git a/x-pack/package.json b/x-pack/package.json index ec99e4858af6b7..02a59ea7ff3bc2 100644 --- a/x-pack/package.json +++ b/x-pack/package.json @@ -126,7 +126,6 @@ "@kbn/datemath": "5.0.0", "@kbn/i18n": "1.0.0", "@kbn/ui-framework": "1.0.0", - "@kbn/interpreter": "1.0.0", "@samverschueren/stream-to-observable": "^0.3.0", "@scant/router": "^0.1.0", "@slack/client": "^4.2.2", diff --git a/x-pack/plugins/canvas/__tests__/fixtures/function_specs.js b/x-pack/plugins/canvas/__tests__/fixtures/function_specs.js index 6ca97f159a1d59..433b5ec64b753f 100644 --- a/x-pack/plugins/canvas/__tests__/fixtures/function_specs.js +++ b/x-pack/plugins/canvas/__tests__/fixtures/function_specs.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Fn } from '@kbn/interpreter/common/lib/fn'; +import { Fn } from '../../common/lib/fn'; import { functions as browserFns } from '../../canvas_plugin_src/functions/browser'; import { functions as commonFns } from '../../canvas_plugin_src/functions/common'; import { functions as serverFns } from '../../canvas_plugin_src/functions/server/src'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/as.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/as.js index fcda50653380cc..c85cc9e0d5bafa 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/as.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/as.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { getType } from '@kbn/interpreter/common/lib/get_type'; +import { getType } from '../../../common/lib/get_type'; export const asFn = () => ({ name: 'as', diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/clog.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/clog.js new file mode 100644 index 00000000000000..db4cc4179762fc --- /dev/null +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/clog.js @@ -0,0 +1,14 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const clog = () => ({ + name: 'clog', + help: 'Outputs the context to the console', + fn: context => { + console.log(context); //eslint-disable-line no-console + return context; + }, +}); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/index.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/index.js index f20c78bb1fa07c..410dbc60db9528 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/index.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/index.js @@ -11,6 +11,7 @@ import { asFn } from './as'; import { axisConfig } from './axisConfig'; import { compare } from './compare'; import { containerStyle } from './containerStyle'; +import { clog } from './clog'; import { context } from './context'; import { columns } from './columns'; import { csv } from './csv'; @@ -64,6 +65,7 @@ export const functions = [ any, asFn, axisConfig, + clog, columns, compare, containerStyle, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/mapColumn.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/mapColumn.js index c02c6a2d2691ba..db557802052960 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/mapColumn.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/mapColumn.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { getType } from '@kbn/interpreter/common/lib/get_type'; +import { getType } from '../../../common/lib/get_type'; export const mapColumn = () => ({ name: 'mapColumn', diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/get_flot_axis_config.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/get_flot_axis_config.js index ce4b9170d1710b..1a8ee7daf73704 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/get_flot_axis_config.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/get_flot_axis_config.js @@ -5,7 +5,7 @@ */ import { get, map } from 'lodash'; -import { getType } from '@kbn/interpreter/common/lib/get_type'; +import { getType } from '../../../../common/lib/get_type'; export const getFlotAxisConfig = (axis, argValue, { columns, ticks, font } = {}) => { if (!argValue || argValue.show === false) return { show: false }; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/staticColumn.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/staticColumn.js index b144cf179652d0..77580be49719a5 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/staticColumn.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/staticColumn.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { getType } from '@kbn/interpreter/common/lib/get_type'; +import { getType } from '../../../common/lib/get_type'; export const staticColumn = () => ({ name: 'staticColumn', diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/dropdown_filter/index.js b/x-pack/plugins/canvas/canvas_plugin_src/renderers/dropdown_filter/index.js index 04f92bc4752562..863fa41a90be51 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/dropdown_filter/index.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/dropdown_filter/index.js @@ -7,7 +7,7 @@ import ReactDOM from 'react-dom'; import React from 'react'; import { get } from 'lodash'; -import { fromExpression, toExpression } from '@kbn/interpreter/common/lib/ast'; +import { fromExpression, toExpression } from '../../../common/lib/ast'; import { DropdownFilter } from './component'; export const dropdownFilter = () => ({ diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/time_filter/components/time_filter/time_filter.js b/x-pack/plugins/canvas/canvas_plugin_src/renderers/time_filter/components/time_filter/time_filter.js index 7ace73bc430d51..d04a8f0b54d966 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/time_filter/components/time_filter/time_filter.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/time_filter/components/time_filter/time_filter.js @@ -7,7 +7,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { get } from 'lodash'; -import { fromExpression } from '@kbn/interpreter/common/lib/ast'; +import { fromExpression } from '../../../../../common/lib/ast'; import { TimePicker } from '../time_picker'; import { TimePickerMini } from '../time_picker_mini'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/time_filter/index.js b/x-pack/plugins/canvas/canvas_plugin_src/renderers/time_filter/index.js index 2ffc7bcf44208b..cdc4f563e1340b 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/time_filter/index.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/time_filter/index.js @@ -7,7 +7,7 @@ import ReactDOM from 'react-dom'; import React from 'react'; import { get, set } from 'lodash'; -import { fromExpression, toExpression } from '@kbn/interpreter/common/lib/ast'; +import { fromExpression, toExpression } from '../../../common/lib/ast'; import { TimeFilter } from './components/time_filter'; export const timeFilter = () => ({ diff --git a/x-pack/plugins/canvas/canvas_plugin_src/types/boolean.js b/x-pack/plugins/canvas/canvas_plugin_src/types/boolean.js new file mode 100644 index 00000000000000..697277a471feae --- /dev/null +++ b/x-pack/plugins/canvas/canvas_plugin_src/types/boolean.js @@ -0,0 +1,29 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const boolean = () => ({ + name: 'boolean', + from: { + null: () => false, + number: n => Boolean(n), + string: s => Boolean(s), + }, + to: { + render: value => { + const text = `${value}`; + return { + type: 'render', + as: 'text', + value: { text }, + }; + }, + datatable: value => ({ + type: 'datatable', + columns: [{ name: 'value', type: 'boolean' }], + rows: [{ value }], + }), + }, +}); diff --git a/packages/kbn-interpreter/plugin_src/types/datatable.js b/x-pack/plugins/canvas/canvas_plugin_src/types/datatable.js similarity index 63% rename from packages/kbn-interpreter/plugin_src/types/datatable.js rename to x-pack/plugins/canvas/canvas_plugin_src/types/datatable.js index 92bd2c9b1b59ec..cfe75605f1ebf2 100644 --- a/packages/kbn-interpreter/plugin_src/types/datatable.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/types/datatable.js @@ -1,20 +1,7 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import { map, zipObject } from 'lodash'; @@ -23,9 +10,8 @@ export const datatable = () => ({ name: 'datatable', validate: datatable => { // TODO: Check columns types. Only string, boolean, number, date, allowed for now. - if (!datatable.columns) { + if (!datatable.columns) throw new Error('datatable must have a columns array, even if it is empty'); - } if (!datatable.rows) throw new Error('datatable must have a rows array, even if it is empty'); }, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/types/error.js b/x-pack/plugins/canvas/canvas_plugin_src/types/error.js new file mode 100644 index 00000000000000..51051c804db560 --- /dev/null +++ b/x-pack/plugins/canvas/canvas_plugin_src/types/error.js @@ -0,0 +1,22 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const error = () => ({ + name: 'error', + to: { + render: input => { + const { error, info } = input; + return { + type: 'render', + as: 'error', + value: { + error, + info, + }, + }; + }, + }, +}); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/types/filter.js b/x-pack/plugins/canvas/canvas_plugin_src/types/filter.js new file mode 100644 index 00000000000000..8627dd20bb89f9 --- /dev/null +++ b/x-pack/plugins/canvas/canvas_plugin_src/types/filter.js @@ -0,0 +1,20 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const filter = () => ({ + name: 'filter', + from: { + null: () => { + return { + type: 'filter', + // Any meta data you wish to pass along. + meta: {}, + // And filters. If you need an "or", create a filter type for it. + and: [], + }; + }, + }, +}); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/types/image.js b/x-pack/plugins/canvas/canvas_plugin_src/types/image.js new file mode 100644 index 00000000000000..f63d3f1b8b2aa5 --- /dev/null +++ b/x-pack/plugins/canvas/canvas_plugin_src/types/image.js @@ -0,0 +1,18 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const image = () => ({ + name: 'image', + to: { + render: input => { + return { + type: 'render', + as: 'image', + value: input, + }; + }, + }, +}); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/types/index.js b/x-pack/plugins/canvas/canvas_plugin_src/types/index.js new file mode 100644 index 00000000000000..2e9a4fa02ef8ee --- /dev/null +++ b/x-pack/plugins/canvas/canvas_plugin_src/types/index.js @@ -0,0 +1,33 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { boolean } from './boolean'; +import { datatable } from './datatable'; +import { error } from './error'; +import { filter } from './filter'; +import { image } from './image'; +import { nullType } from './null'; +import { number } from './number'; +import { pointseries } from './pointseries'; +import { render } from './render'; +import { shape } from './shape'; +import { string } from './string'; +import { style } from './style'; + +export const typeSpecs = [ + boolean, + datatable, + error, + filter, + image, + number, + nullType, + pointseries, + render, + shape, + string, + style, +]; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/types/null.js b/x-pack/plugins/canvas/canvas_plugin_src/types/null.js new file mode 100644 index 00000000000000..27e9cdf59b0046 --- /dev/null +++ b/x-pack/plugins/canvas/canvas_plugin_src/types/null.js @@ -0,0 +1,12 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const nullType = () => ({ + name: 'null', + from: { + '*': () => null, + }, +}); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/types/number.js b/x-pack/plugins/canvas/canvas_plugin_src/types/number.js new file mode 100644 index 00000000000000..63ee587075fdd8 --- /dev/null +++ b/x-pack/plugins/canvas/canvas_plugin_src/types/number.js @@ -0,0 +1,29 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const number = () => ({ + name: 'number', + from: { + null: () => 0, + boolean: b => Number(b), + string: n => Number(n), + }, + to: { + render: value => { + const text = `${value}`; + return { + type: 'render', + as: 'text', + value: { text }, + }; + }, + datatable: value => ({ + type: 'datatable', + columns: [{ name: 'value', type: 'number' }], + rows: [{ value }], + }), + }, +}); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/types/pointseries.js b/x-pack/plugins/canvas/canvas_plugin_src/types/pointseries.js new file mode 100644 index 00000000000000..1a007386200501 --- /dev/null +++ b/x-pack/plugins/canvas/canvas_plugin_src/types/pointseries.js @@ -0,0 +1,31 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const pointseries = () => ({ + name: 'pointseries', + from: { + null: () => { + return { + type: 'pointseries', + rows: [], + columns: [], + }; + }, + }, + to: { + render: (pointseries, types) => { + const datatable = types.datatable.from(pointseries, types); + return { + type: 'render', + as: 'table', + value: { + datatable, + showHeader: true, + }, + }; + }, + }, +}); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/types/register.js b/x-pack/plugins/canvas/canvas_plugin_src/types/register.js new file mode 100644 index 00000000000000..e960dd0f6566ae --- /dev/null +++ b/x-pack/plugins/canvas/canvas_plugin_src/types/register.js @@ -0,0 +1,10 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import 'babel-polyfill'; +import { typeSpecs } from './index'; + +typeSpecs.forEach(canvas.register); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/types/render.js b/x-pack/plugins/canvas/canvas_plugin_src/types/render.js new file mode 100644 index 00000000000000..0f261f0398816f --- /dev/null +++ b/x-pack/plugins/canvas/canvas_plugin_src/types/render.js @@ -0,0 +1,16 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const render = () => ({ + name: 'render', + from: { + '*': v => ({ + type: 'render', + as: 'debug', + value: v, + }), + }, +}); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/types/shape.js b/x-pack/plugins/canvas/canvas_plugin_src/types/shape.js new file mode 100644 index 00000000000000..1b306b7b1c3911 --- /dev/null +++ b/x-pack/plugins/canvas/canvas_plugin_src/types/shape.js @@ -0,0 +1,18 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const shape = () => ({ + name: 'shape', + to: { + render: input => { + return { + type: 'render', + as: 'shape', + value: input, + }; + }, + }, +}); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/types/string.js b/x-pack/plugins/canvas/canvas_plugin_src/types/string.js new file mode 100644 index 00000000000000..c8d58aaaffbcad --- /dev/null +++ b/x-pack/plugins/canvas/canvas_plugin_src/types/string.js @@ -0,0 +1,28 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const string = () => ({ + name: 'string', + from: { + null: () => '', + boolean: b => String(b), + number: n => String(n), + }, + to: { + render: text => { + return { + type: 'render', + as: 'text', + value: { text }, + }; + }, + datatable: value => ({ + type: 'datatable', + columns: [{ name: 'value', type: 'string' }], + rows: [{ value }], + }), + }, +}); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/types/style.js b/x-pack/plugins/canvas/canvas_plugin_src/types/style.js new file mode 100644 index 00000000000000..62632c03231ad7 --- /dev/null +++ b/x-pack/plugins/canvas/canvas_plugin_src/types/style.js @@ -0,0 +1,18 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const style = () => ({ + name: 'style', + from: { + null: () => { + return { + type: 'style', + spec: {}, + css: '', + }; + }, + }, +}); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/datacolumn/index.js b/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/datacolumn/index.js index 64a426a84a7cd5..0540a146034605 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/datacolumn/index.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/datacolumn/index.js @@ -9,8 +9,8 @@ import { compose, withPropsOnChange, withHandlers } from 'recompose'; import PropTypes from 'prop-types'; import { EuiSelect, EuiFlexItem, EuiFlexGroup } from '@elastic/eui'; import { sortBy } from 'lodash'; -import { getType } from '@kbn/interpreter/common/lib/get_type'; import { createStatefulPropHoc } from '../../../../public/components/enhance/stateful_prop'; +import { getType } from '../../../../common/lib/get_type'; import { templateFromReactComponent } from '../../../../public/lib/template_from_react_component'; import { SimpleMathFunction } from './simple_math_function'; import { getFormObject } from './get_form_object'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/palette.js b/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/palette.js index fc0f89692f646b..e0f8e56df8b6f8 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/palette.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/palette.js @@ -7,8 +7,8 @@ import React from 'react'; import PropTypes from 'prop-types'; import { get } from 'lodash'; -import { getType } from '@kbn/interpreter/common/lib/get_type'; import { PalettePicker } from '../../../public/components/palette_picker'; +import { getType } from '../../../common/lib/get_type'; import { templateFromReactComponent } from '../../../public/lib/template_from_react_component'; const PaletteArgInput = ({ onValueChange, argValue, renderError }) => { diff --git a/x-pack/plugins/canvas/common/functions/to.js b/x-pack/plugins/canvas/common/functions/to.js index 25446b28686525..6f15569c27a11b 100644 --- a/x-pack/plugins/canvas/common/functions/to.js +++ b/x-pack/plugins/canvas/common/functions/to.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { castProvider } from '@kbn/interpreter/common/interpreter/cast'; +import { castProvider } from '../interpreter/cast'; export const to = () => ({ name: 'to', diff --git a/packages/kbn-interpreter/common/interpreter/cast.js b/x-pack/plugins/canvas/common/interpreter/cast.js similarity index 53% rename from packages/kbn-interpreter/common/interpreter/cast.js rename to x-pack/plugins/canvas/common/interpreter/cast.js index cc257a7dc55e03..7e559afcba40ed 100644 --- a/packages/kbn-interpreter/common/interpreter/cast.js +++ b/x-pack/plugins/canvas/common/interpreter/cast.js @@ -1,20 +1,7 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import { getType } from '../lib/get_type'; @@ -32,9 +19,8 @@ export function castProvider(types) { for (let i = 0; i < toTypeNames.length; i++) { // First check if the current type can cast to this type - if (fromTypeDef && fromTypeDef.castsTo(toTypeNames[i])) { + if (fromTypeDef && fromTypeDef.castsTo(toTypeNames[i])) return fromTypeDef.to(node, toTypeNames[i], types); - } // If that isn't possible, check if this type can cast from the current type const toTypeDef = types[toTypeNames[i]]; diff --git a/x-pack/plugins/canvas/common/interpreter/create_error.js b/x-pack/plugins/canvas/common/interpreter/create_error.js new file mode 100644 index 00000000000000..5de9819330dbd0 --- /dev/null +++ b/x-pack/plugins/canvas/common/interpreter/create_error.js @@ -0,0 +1,13 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const createError = err => ({ + type: 'error', + error: { + stack: process.env.NODE_ENV === 'production' ? undefined : err.stack, + message: typeof err === 'string' ? err : err.message, + }, +}); diff --git a/packages/kbn-interpreter/common/interpreter/interpret.js b/x-pack/plugins/canvas/common/interpreter/interpret.js similarity index 88% rename from packages/kbn-interpreter/common/interpreter/interpret.js rename to x-pack/plugins/canvas/common/interpreter/interpret.js index d2a786cd3c85dc..ff7a2547f236f3 100644 --- a/packages/kbn-interpreter/common/interpreter/interpret.js +++ b/x-pack/plugins/canvas/common/interpreter/interpret.js @@ -1,20 +1,7 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import clone from 'lodash.clone'; @@ -125,9 +112,8 @@ export function interpretProvider(config) { (argAsts, argAst, argName) => { const argDef = getByAlias(argDefs, argName); // TODO: Implement a system to allow for undeclared arguments - if (!argDef) { + if (!argDef) throw new Error(`Unknown argument '${argName}' passed to function '${fnDef.name}'`); - } argAsts[argDef.name] = (argAsts[argDef.name] || []).concat(argAst); return argAsts; @@ -156,9 +142,8 @@ export function interpretProvider(config) { const argAstsWithDefaults = reduce( argDefs, (argAsts, argDef, argName) => { - if (typeof argAsts[argName] === 'undefined' && typeof argDef.default !== 'undefined') { + if (typeof argAsts[argName] === 'undefined' && typeof argDef.default !== 'undefined') argAsts[argName] = [fromExpression(argDef.default, 'argument')]; - } return argAsts; }, diff --git a/packages/kbn-interpreter/common/interpreter/socket_interpret.js b/x-pack/plugins/canvas/common/interpreter/socket_interpret.js similarity index 72% rename from packages/kbn-interpreter/common/interpreter/socket_interpret.js rename to x-pack/plugins/canvas/common/interpreter/socket_interpret.js index 1ea95e0f5f6f1e..c8d5acf4fdd526 100644 --- a/packages/kbn-interpreter/common/interpreter/socket_interpret.js +++ b/x-pack/plugins/canvas/common/interpreter/socket_interpret.js @@ -1,20 +1,7 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import uuid from 'uuid/v4'; @@ -53,9 +40,8 @@ export function socketInterpreterProvider({ // Get the list of functions that are known elsewhere return Promise.resolve(referableFunctions).then(referableFunctionMap => { // Check if the not-found function is in the list of alternatives, if not, throw - if (!getByAlias(referableFunctionMap, functionName)) { + if (!getByAlias(referableFunctionMap, functionName)) throw new Error(`Function not found: ${functionName}`); - } // set a unique message ID so the code knows what response to process const id = uuid(); diff --git a/x-pack/plugins/canvas/common/lib/__tests__/arg.js b/x-pack/plugins/canvas/common/lib/__tests__/arg.js new file mode 100644 index 00000000000000..f8badc67175ace --- /dev/null +++ b/x-pack/plugins/canvas/common/lib/__tests__/arg.js @@ -0,0 +1,23 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import expect from 'expect.js'; +import { Arg } from '../arg'; + +describe('Arg', () => { + it('sets required to false by default', () => { + const isOptional = new Arg({ + name: 'optional_me', + }); + expect(isOptional.required).to.equal(false); + + const isRequired = new Arg({ + name: 'require_me', + required: true, + }); + expect(isRequired.required).to.equal(true); + }); +}); diff --git a/packages/kbn-interpreter/common/lib/ast.from_expression.test.js b/x-pack/plugins/canvas/common/lib/__tests__/ast.from_expression.js similarity index 59% rename from packages/kbn-interpreter/common/lib/ast.from_expression.test.js rename to x-pack/plugins/canvas/common/lib/__tests__/ast.from_expression.js index c144770f94c54f..631973247dc6c4 100644 --- a/packages/kbn-interpreter/common/lib/ast.from_expression.test.js +++ b/x-pack/plugins/canvas/common/lib/__tests__/ast.from_expression.js @@ -1,47 +1,35 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -import { fromExpression } from './ast'; -import { getType } from './get_type'; +import expect from 'expect.js'; +import { fromExpression } from '../ast'; +import { getType } from '../../lib/get_type'; describe('ast fromExpression', () => { describe('invalid expression', () => { it('throws when empty', () => { const check = () => fromExpression(''); - expect(check).toThrowError(/Unable to parse expression/i); + expect(check).to.throwException(/Unable to parse expression/i); }); it('throws with invalid expression', () => { const check = () => fromExpression('wat!'); - expect(check).toThrowError(/Unable to parse expression/i); + expect(check).to.throwException(/Unable to parse expression/i); }); }); describe('single item expression', () => { it('is a chain', () => { const expression = 'whatever'; - expect(fromExpression(expression)).toHaveProperty('chain'); + expect(fromExpression(expression)).to.have.property('chain'); }); it('is a value', () => { const expression = '"hello"'; - expect(fromExpression(expression, 'argument')).toBe('hello'); + expect(fromExpression(expression, 'argument')).to.equal('hello'); }); describe('function without arguments', () => { @@ -56,15 +44,15 @@ describe('ast fromExpression', () => { }); it('is a function ', () => { - expect(getType(block)).toBe('function'); + expect(getType(block)).to.equal('function'); }); it('is csv function', () => { - expect(block.function).toBe('csv'); + expect(block.function).to.equal('csv'); }); it('has no arguments', () => { - expect(block.arguments).toEqual({}); + expect(block.arguments).to.eql({}); }); }); @@ -80,17 +68,17 @@ describe('ast fromExpression', () => { }); it('has arguemnts properties', () => { - expect(block.arguments).not.toEqual({}); + expect(block.arguments).not.to.eql({}); }); it('has index argument with string value', () => { - expect(block.arguments).toHaveProperty('index'); - expect(block.arguments.index).toEqual(['logstash-*']); + expect(block.arguments).to.have.property('index'); + expect(block.arguments.index).to.eql(['logstash-*']); }); it('has oranges argument with string value', () => { - expect(block.arguments).toHaveProperty('oranges'); - expect(block.arguments.oranges).toEqual(['bananas']); + expect(block.arguments).to.have.property('oranges'); + expect(block.arguments.oranges).to.eql(['bananas']); }); }); @@ -106,12 +94,12 @@ describe('ast fromExpression', () => { }); it('is expression type', () => { - expect(block.arguments).toHaveProperty('exampleFunction'); - expect(block.arguments.exampleFunction[0]).toHaveProperty('type'); + expect(block.arguments).to.have.property('exampleFunction'); + expect(block.arguments.exampleFunction[0]).to.have.property('type', 'expression'); }); it('has expected shape', () => { - expect(block.arguments.exampleFunction).toEqual([ + expect(block.arguments.exampleFunction).to.eql([ { type: 'expression', chain: [ @@ -140,12 +128,12 @@ describe('ast fromExpression', () => { }); it('is expression type', () => { - expect(block.arguments).toHaveProperty('examplePartial'); - expect(block.arguments.examplePartial[0]).toHaveProperty('type'); + expect(block.arguments).to.have.property('examplePartial'); + expect(block.arguments.examplePartial[0]).to.have.property('type', 'expression'); }); it('has expected shape', () => { - expect(block.arguments.examplePartial).toEqual([ + expect(block.arguments.examplePartial).to.eql([ { type: 'expression', chain: [ diff --git a/packages/kbn-interpreter/common/lib/ast.to_expression.test.js b/x-pack/plugins/canvas/common/lib/__tests__/ast.to_expression.js similarity index 83% rename from packages/kbn-interpreter/common/lib/ast.to_expression.test.js rename to x-pack/plugins/canvas/common/lib/__tests__/ast.to_expression.js index 455b12f583f30a..4b5985832e6abb 100644 --- a/packages/kbn-interpreter/common/lib/ast.to_expression.test.js +++ b/x-pack/plugins/canvas/common/lib/__tests__/ast.to_expression.js @@ -1,39 +1,18 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -import { toExpression } from './ast'; +import expect from 'expect.js'; +import { toExpression } from '../ast'; describe('ast toExpression', () => { describe('single expression', () => { - it('throws if no type included', () => { - const errMsg = 'Objects must have a type property'; - const astObject = { hello: 'world' }; - expect(() => toExpression(astObject)).toThrowError(errMsg); - }); - it('throws if not correct type', () => { const errMsg = 'Expression must be an expression or argument function'; - const astObject = { - type: 'hi', - hello: 'world', - }; - expect(() => toExpression(astObject)).toThrowError(errMsg); + const astObject = { hello: 'world' }; + expect(() => toExpression(astObject)).to.throwException(errMsg); }); it('throws if expression without chain', () => { @@ -42,7 +21,7 @@ describe('ast toExpression', () => { type: 'expression', hello: 'world', }; - expect(() => toExpression(astObject)).toThrowError(errMsg); + expect(() => toExpression(astObject)).to.throwException(errMsg); }); it('throws if arguments type is invalid', () => { @@ -50,7 +29,7 @@ describe('ast toExpression', () => { const invalidTypes = [null, []]; function validate(obj) { - expect(() => toExpression(obj)).toThrowError(errMsg); + expect(() => toExpression(obj)).to.throwException(errMsg); } for (let i = 0; i < invalidTypes.length; i++) { @@ -77,12 +56,12 @@ describe('ast toExpression', () => { function: 'pointseries', arguments: null, }; - expect(() => toExpression(astObject)).toThrowError(errMsg); + expect(() => toExpression(astObject)).to.throwException(errMsg); }); it('throws on invalid argument type', () => { const argType = '__invalid__wat__'; - const errMsg = `Invalid argument type in AST: ${argType}`; + const errMsg = `invalid argument type: ${argType}`; const astObject = { type: 'expression', chain: [ @@ -101,7 +80,7 @@ describe('ast toExpression', () => { ], }; - expect(() => toExpression(astObject)).toThrowError(errMsg); + expect(() => toExpression(astObject)).to.throwException(errMsg); }); it('throws on expressions without chains', () => { @@ -125,7 +104,7 @@ describe('ast toExpression', () => { ], }; - expect(() => toExpression(astObject)).toThrowError(errMsg); + expect(() => toExpression(astObject)).to.throwException(errMsg); }); it('throws on nameless functions and partials', () => { @@ -141,7 +120,7 @@ describe('ast toExpression', () => { ], }; - expect(() => toExpression(astObject)).toThrowError(errMsg); + expect(() => toExpression(astObject)).to.throwException(errMsg); }); it('single expression', () => { @@ -157,7 +136,7 @@ describe('ast toExpression', () => { }; const expression = toExpression(astObj); - expect(expression).toBe('csv'); + expect(expression).to.equal('csv'); }); it('single expression with string argument', () => { @@ -175,7 +154,7 @@ describe('ast toExpression', () => { }; const expression = toExpression(astObj); - expect(expression).toBe('csv input="stuff\nthings"'); + expect(expression).to.equal('csv input="stuff\nthings"'); }); it('single expression string value with a backslash', () => { @@ -193,7 +172,7 @@ describe('ast toExpression', () => { }; const expression = toExpression(astObj); - expect(expression).toBe('csv input="slash \\\\\\\\ slash"'); + expect(expression).to.equal('csv input="slash \\\\\\\\ slash"'); }); it('single expression string value with a double quote', () => { @@ -211,7 +190,7 @@ describe('ast toExpression', () => { }; const expression = toExpression(astObj); - expect(expression).toBe('csv input="stuff\nthings\n\\"such\\""'); + expect(expression).to.equal('csv input="stuff\nthings\n\\"such\\""'); }); it('single expression with number argument', () => { @@ -229,7 +208,7 @@ describe('ast toExpression', () => { }; const expression = toExpression(astObj); - expect(expression).toBe('series input=1234'); + expect(expression).to.equal('series input=1234'); }); it('single expression with boolean argument', () => { @@ -247,7 +226,7 @@ describe('ast toExpression', () => { }; const expression = toExpression(astObj); - expect(expression).toBe('series input=true'); + expect(expression).to.equal('series input=true'); }); it('single expression with null argument', () => { @@ -265,7 +244,7 @@ describe('ast toExpression', () => { }; const expression = toExpression(astObj); - expect(expression).toBe('series input=null'); + expect(expression).to.equal('series input=null'); }); it('single expression with multiple arguments', () => { @@ -284,7 +263,7 @@ describe('ast toExpression', () => { }; const expression = toExpression(astObj); - expect(expression).toBe('csv input="stuff\nthings" separator="\\\\n"'); + expect(expression).to.equal('csv input="stuff\nthings" separator="\\\\n"'); }); it('single expression with multiple and repeated arguments', () => { @@ -303,12 +282,12 @@ describe('ast toExpression', () => { }; const expression = toExpression(astObj); - expect(expression).toBe( + expect(expression).to.equal( 'csv input="stuff\nthings" input="more,things\nmore,stuff" separator="\\\\n"' ); }); - it('single expression with `getcalc` expression argument', () => { + it('single expression with expression argument', () => { const astObj = { type: 'expression', chain: [ @@ -335,10 +314,10 @@ describe('ast toExpression', () => { }; const expression = toExpression(astObj); - expect(expression).toBe('csv calc={getcalc} input="stuff\nthings"'); + expect(expression).to.equal('csv calc={getcalc} input="stuff\nthings"'); }); - it('single expression with `partcalc` expression argument', () => { + it('single expression with expression argument', () => { const astObj = { type: 'expression', chain: [ @@ -365,7 +344,7 @@ describe('ast toExpression', () => { }; const expression = toExpression(astObj); - expect(expression).toBe('csv calc={partcalc} input="stuff\nthings"'); + expect(expression).to.equal('csv calc={partcalc} input="stuff\nthings"'); }); it('single expression with expression arguments, with arguments', () => { @@ -411,7 +390,7 @@ describe('ast toExpression', () => { }; const expression = toExpression(astObj); - expect(expression).toBe( + expect(expression).to.equal( 'csv sep={partcalc type="comma"} input="stuff\nthings" break={setBreak type="newline"}' ); }); @@ -489,7 +468,7 @@ describe('ast toExpression', () => { '2016,honda,fit,15890,', '2016,honda,civic,18640"\n| line x={distinct f="year"} y={sum f="price"} colors={distinct f="model"}', ]; - expect(expression).toBe(expected.join('\n')); + expect(expression).to.equal(expected.join('\n')); }); it('three chained expressions', () => { @@ -584,7 +563,7 @@ describe('ast toExpression', () => { '2016,honda,civic,18640"\n| pointseries x={distinct f="year"} y={sum f="price"} ' + 'colors={distinct f="model"}\n| line pallette={getColorPallette name="elastic"}', ]; - expect(expression).toBe(expected.join('\n')); + expect(expression).to.equal(expected.join('\n')); }); }); @@ -604,7 +583,7 @@ describe('ast toExpression', () => { }; const expression = toExpression(astObj); - expect(expression).toBe('list "one" "two" "three"'); + expect(expression).to.equal('list "one" "two" "three"'); }); it('named and unnamed', () => { @@ -624,7 +603,7 @@ describe('ast toExpression', () => { }; const expression = toExpression(astObj); - expect(expression).toBe('both named="example" another="item" "one" "two" "three"'); + expect(expression).to.equal('both named="example" another="item" "one" "two" "three"'); }); }); }); diff --git a/x-pack/plugins/canvas/common/lib/__tests__/get_by_alias.js b/x-pack/plugins/canvas/common/lib/__tests__/get_by_alias.js new file mode 100644 index 00000000000000..eaeeeade4cc593 --- /dev/null +++ b/x-pack/plugins/canvas/common/lib/__tests__/get_by_alias.js @@ -0,0 +1,74 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import expect from 'expect.js'; +import { getByAlias } from '../get_by_alias'; + +describe('getByAlias', () => { + const fnsObject = { + foo: { name: 'foo', aliases: ['f'] }, + bar: { name: 'bar', aliases: ['b'] }, + }; + + const fnsArray = [{ name: 'foo', aliases: ['f'] }, { name: 'bar', aliases: ['b'] }]; + + it('returns the function by name', () => { + expect(getByAlias(fnsObject, 'foo')).to.be(fnsObject.foo); + expect(getByAlias(fnsObject, 'bar')).to.be(fnsObject.bar); + expect(getByAlias(fnsArray, 'foo')).to.be(fnsArray[0]); + expect(getByAlias(fnsArray, 'bar')).to.be(fnsArray[1]); + }); + + it('returns the function by alias', () => { + expect(getByAlias(fnsObject, 'f')).to.be(fnsObject.foo); + expect(getByAlias(fnsObject, 'b')).to.be(fnsObject.bar); + expect(getByAlias(fnsArray, 'f')).to.be(fnsArray[0]); + expect(getByAlias(fnsArray, 'b')).to.be(fnsArray[1]); + }); + + it('returns the function by case-insensitive name', () => { + expect(getByAlias(fnsObject, 'FOO')).to.be(fnsObject.foo); + expect(getByAlias(fnsObject, 'BAR')).to.be(fnsObject.bar); + expect(getByAlias(fnsArray, 'FOO')).to.be(fnsArray[0]); + expect(getByAlias(fnsArray, 'BAR')).to.be(fnsArray[1]); + }); + + it('returns the function by case-insensitive alias', () => { + expect(getByAlias(fnsObject, 'F')).to.be(fnsObject.foo); + expect(getByAlias(fnsObject, 'B')).to.be(fnsObject.bar); + expect(getByAlias(fnsArray, 'F')).to.be(fnsArray[0]); + expect(getByAlias(fnsArray, 'B')).to.be(fnsArray[1]); + }); + + it('handles empty strings', () => { + const emptyStringFnsObject = { '': { name: '' } }; + const emptyStringAliasFnsObject = { foo: { name: 'foo', aliases: [''] } }; + expect(getByAlias(emptyStringFnsObject, '')).to.be(emptyStringFnsObject['']); + expect(getByAlias(emptyStringAliasFnsObject, '')).to.be(emptyStringAliasFnsObject.foo); + + const emptyStringFnsArray = [{ name: '' }]; + const emptyStringAliasFnsArray = [{ name: 'foo', aliases: [''] }]; + expect(getByAlias(emptyStringFnsArray, '')).to.be(emptyStringFnsArray[0]); + expect(getByAlias(emptyStringAliasFnsArray, '')).to.be(emptyStringAliasFnsArray[0]); + }); + + it('handles "undefined" strings', () => { + const undefinedFnsObject = { undefined: { name: 'undefined' } }; + const undefinedAliasFnsObject = { foo: { name: 'undefined', aliases: ['undefined'] } }; + expect(getByAlias(undefinedFnsObject, 'undefined')).to.be(undefinedFnsObject.undefined); + expect(getByAlias(undefinedAliasFnsObject, 'undefined')).to.be(undefinedAliasFnsObject.foo); + + const emptyStringFnsArray = [{ name: 'undefined' }]; + const emptyStringAliasFnsArray = [{ name: 'foo', aliases: ['undefined'] }]; + expect(getByAlias(emptyStringFnsArray, 'undefined')).to.be(emptyStringFnsArray[0]); + expect(getByAlias(emptyStringAliasFnsArray, 'undefined')).to.be(emptyStringAliasFnsArray[0]); + }); + + it('returns undefined if not found', () => { + expect(getByAlias(fnsObject, 'baz')).to.be(undefined); + expect(getByAlias(fnsArray, 'baz')).to.be(undefined); + }); +}); diff --git a/packages/kbn-interpreter/common/lib/registry.test.js b/x-pack/plugins/canvas/common/lib/__tests__/registry.js similarity index 60% rename from packages/kbn-interpreter/common/lib/registry.test.js rename to x-pack/plugins/canvas/common/lib/__tests__/registry.js index dbeeb16dc1ff0c..fd19bf0300417e 100644 --- a/packages/kbn-interpreter/common/lib/registry.test.js +++ b/x-pack/plugins/canvas/common/lib/__tests__/registry.js @@ -1,63 +1,51 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -import { Registry } from './registry'; +import expect from 'expect.js'; +import { Registry } from '../registry'; function validateRegistry(registry, elements) { it('gets items by lookup property', () => { - expect(registry.get('__test2')).toEqual(elements[1]()); + expect(registry.get('__test2')).to.eql(elements[1]()); }); it('ignores case when getting items', () => { - expect(registry.get('__TeSt2')).toEqual(elements[1]()); - expect(registry.get('__tESt2')).toEqual(elements[1]()); + expect(registry.get('__TeSt2')).to.eql(elements[1]()); + expect(registry.get('__tESt2')).to.eql(elements[1]()); }); it('gets a shallow clone', () => { - expect(registry.get('__test2')).not.toBe(elements[1]()); + expect(registry.get('__test2')).to.not.equal(elements[1]()); }); it('is null with no match', () => { - expect(registry.get('@@nope_nope')).toBe(null); + expect(registry.get('@@nope_nope')).to.be(null); }); it('returns shallow clone of the whole registry via toJS', () => { const regAsJs = registry.toJS(); - expect(regAsJs).toEqual({ + expect(regAsJs).to.eql({ __test1: elements[0](), __test2: elements[1](), }); - expect(regAsJs.__test1).toEqual(elements[0]()); - expect(regAsJs.__test1).not.toBe(elements[0]()); + expect(regAsJs.__test1).to.eql(elements[0]()); + expect(regAsJs.__test1).to.not.equal(elements[0]()); }); it('returns shallow clone array via toArray', () => { const regAsArray = registry.toArray(); - expect(regAsArray).toBeInstanceOf(Array); - expect(regAsArray[0]).toEqual(elements[0]()); - expect(regAsArray[0]).not.toBe(elements[0]()); + expect(regAsArray).to.be.an(Array); + expect(regAsArray[0]).to.eql(elements[0]()); + expect(regAsArray[0]).to.not.equal(elements[0]()); }); it('resets the registry', () => { - expect(registry.get('__test2')).toEqual(elements[1]()); + expect(registry.get('__test2')).to.eql(elements[1]()); registry.reset(); - expect(registry.get('__test2')).toBe(null); + expect(registry.get('__test2')).to.equal(null); }); } @@ -82,12 +70,12 @@ describe('Registry', () => { validateRegistry(registry, elements); it('has a prop of name', () => { - expect(registry.getProp()).toBe('name'); + expect(registry.getProp()).to.equal('name'); }); it('throws when object is missing the lookup prop', () => { const check = () => registry.register(() => ({ hello: 'world' })); - expect(check).toThrowError(/object with a name property/); + expect(check).to.throwException(/object with a name property/i); }); }); @@ -111,12 +99,12 @@ describe('Registry', () => { validateRegistry(registry, elements); it('has a prop of type', () => { - expect(registry.getProp()).toBe('type'); + expect(registry.getProp()).to.equal('type'); }); it('throws when object is missing the lookup prop', () => { const check = () => registry.register(() => ({ hello: 'world' })); - expect(check).toThrowError(/object with a type property/); + expect(check).to.throwException(/object with a type property/i); }); }); @@ -149,8 +137,9 @@ describe('Registry', () => { registry.register(elements[1]); it('contains wrapped elements', () => { - expect(registry.get(elements[0]().name)).toHaveProperty('__CUSTOM_PROP__'); - expect(registry.get(elements[1]().name)).toHaveProperty('__CUSTOM_PROP__'); + // test for the custom prop on the returned elements + expect(registry.get(elements[0]().name)).to.have.property('__CUSTOM_PROP__', 1); + expect(registry.get(elements[1]().name)).to.have.property('__CUSTOM_PROP__', 2); }); }); @@ -182,18 +171,20 @@ describe('Registry', () => { }); it('get contains the full prototype', () => { - expect(typeof thing().baseFunc).toBe('function'); - expect(typeof registry.get(name).baseFunc).toBe('function'); + expect(thing().baseFunc).to.be.a('function'); + expect(registry.get(name).baseFunc).to.be.a('function'); }); it('toJS contains the full prototype', () => { const val = registry.toJS(); - expect(typeof val[name].baseFunc).toBe('function'); + expect(val[name].baseFunc).to.be.a('function'); }); }); describe('throws when lookup prop is not a string', () => { const check = () => new Registry(2); - expect(check).toThrowError(/must be a string/); + expect(check).to.throwException(e => { + expect(e.message).to.be('Registry property name must be a string'); + }); }); }); diff --git a/x-pack/plugins/canvas/common/lib/arg.js b/x-pack/plugins/canvas/common/lib/arg.js new file mode 100644 index 00000000000000..7713fcb342bc25 --- /dev/null +++ b/x-pack/plugins/canvas/common/lib/arg.js @@ -0,0 +1,24 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { includes } from 'lodash'; + +export function Arg(config) { + if (config.name === '_') throw Error('Arg names must not be _. Use it in aliases instead.'); + this.name = config.name; + this.required = config.required || false; + this.help = config.help || ''; + this.types = config.types || []; + this.default = config.default; + this.aliases = config.aliases || []; + this.multi = config.multi == null ? false : config.multi; + this.resolve = config.resolve == null ? true : config.resolve; + this.options = config.options || []; + this.accepts = type => { + if (!this.types.length) return true; + return includes(config.types, type); + }; +} diff --git a/packages/kbn-interpreter/common/lib/ast.js b/x-pack/plugins/canvas/common/lib/ast.js similarity index 81% rename from packages/kbn-interpreter/common/lib/ast.js rename to x-pack/plugins/canvas/common/lib/ast.js index 61cfe94ac955c9..b31848944e9db3 100644 --- a/packages/kbn-interpreter/common/lib/ast.js +++ b/x-pack/plugins/canvas/common/lib/ast.js @@ -1,23 +1,10 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -import { getType } from './get_type'; +import { getType } from '../lib/get_type'; import { parse } from './grammar'; function getArgumentString(arg, argKey, level = 0) { @@ -61,9 +48,8 @@ function getExpressionArgs(block, level = 0) { const lineLength = acc.split('\n').pop().length; // if arg values are too long, move it to the next line - if (level === 0 && lineLength + argString.length > MAX_LINE_LENGTH) { + if (level === 0 && lineLength + argString.length > MAX_LINE_LENGTH) return `${acc}\n ${argString}`; - } // append arg values to existing arg values if (lineLength > 0) return `${acc} ${argString}`; diff --git a/x-pack/plugins/canvas/common/lib/autocomplete.js b/x-pack/plugins/canvas/common/lib/autocomplete.js index 5a18c2570919b3..d87e199de46717 100644 --- a/x-pack/plugins/canvas/common/lib/autocomplete.js +++ b/x-pack/plugins/canvas/common/lib/autocomplete.js @@ -5,8 +5,8 @@ */ import { uniq } from 'lodash'; -import { parse } from '@kbn/interpreter/common/lib/grammar'; -import { getByAlias } from '@kbn/interpreter/common/lib/get_by_alias'; +import { parse } from './grammar'; +import { getByAlias } from './get_by_alias'; const MARKER = 'CANVAS_SUGGESTION_MARKER'; diff --git a/packages/kbn-interpreter/common/lib/fn.js b/x-pack/plugins/canvas/common/lib/fn.js similarity index 54% rename from packages/kbn-interpreter/common/lib/fn.js rename to x-pack/plugins/canvas/common/lib/fn.js index c6b2fcbe677992..70948c76579b37 100644 --- a/packages/kbn-interpreter/common/lib/fn.js +++ b/x-pack/plugins/canvas/common/lib/fn.js @@ -1,20 +1,7 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import { mapValues, includes } from 'lodash'; diff --git a/x-pack/plugins/canvas/common/lib/functions_registry.js b/x-pack/plugins/canvas/common/lib/functions_registry.js new file mode 100644 index 00000000000000..af8e8f0b122d06 --- /dev/null +++ b/x-pack/plugins/canvas/common/lib/functions_registry.js @@ -0,0 +1,16 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { Registry } from '../../common/lib/registry'; +import { Fn } from '../lib/fn'; + +class FunctionsRegistry extends Registry { + wrapper(obj) { + return new Fn(obj); + } +} + +export const functionsRegistry = new FunctionsRegistry(); diff --git a/x-pack/plugins/canvas/common/lib/get_by_alias.js b/x-pack/plugins/canvas/common/lib/get_by_alias.js new file mode 100644 index 00000000000000..c9986a50240086 --- /dev/null +++ b/x-pack/plugins/canvas/common/lib/get_by_alias.js @@ -0,0 +1,20 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +/** + * This is used for looking up function/argument definitions. It looks through + * the given object/array for a case-insensitive match, which could be either the + * `name` itself, or something under the `aliases` property. + */ +export function getByAlias(specs, name) { + const lowerCaseName = name.toLowerCase(); + return Object.values(specs).find(({ name, aliases }) => { + if (name.toLowerCase() === lowerCaseName) return true; + return (aliases || []).some(alias => { + return alias.toLowerCase() === lowerCaseName; + }); + }); +} diff --git a/x-pack/plugins/canvas/common/lib/get_type.js b/x-pack/plugins/canvas/common/lib/get_type.js new file mode 100644 index 00000000000000..8d2b5a13cb2837 --- /dev/null +++ b/x-pack/plugins/canvas/common/lib/get_type.js @@ -0,0 +1,15 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export function getType(node) { + if (node == null) return 'null'; + if (typeof node === 'object') { + if (!node.type) throw new Error('Objects must have a type propery'); + return node.type; + } + + return typeof node; +} diff --git a/packages/kbn-interpreter/common/lib/grammar.js b/x-pack/plugins/canvas/common/lib/grammar.js similarity index 100% rename from packages/kbn-interpreter/common/lib/grammar.js rename to x-pack/plugins/canvas/common/lib/grammar.js diff --git a/packages/kbn-interpreter/common/lib/grammar.peg b/x-pack/plugins/canvas/common/lib/grammar.peg similarity index 100% rename from packages/kbn-interpreter/common/lib/grammar.peg rename to x-pack/plugins/canvas/common/lib/grammar.peg diff --git a/x-pack/plugins/canvas/common/lib/index.js b/x-pack/plugins/canvas/common/lib/index.js index 321a4abff44e0d..5d56a5026590de 100644 --- a/x-pack/plugins/canvas/common/lib/index.js +++ b/x-pack/plugins/canvas/common/lib/index.js @@ -5,6 +5,8 @@ */ export * from './datatable'; +export * from './arg'; +export * from './ast'; export * from './autocomplete'; export * from './constants'; export * from './dataurl'; @@ -12,10 +14,15 @@ export * from './errors'; export * from './expression_form_handlers'; export * from './fetch'; export * from './find_in_object'; +export * from './fn'; export * from './fonts'; +export * from './functions_registry'; +export * from './get_by_alias'; export * from './get_colors_from_palette'; export * from './get_field_type'; export * from './get_legend_config'; +export * from './get_type'; +export * from './grammar'; export * from './handlebars'; export * from './hex_to_rgb'; export * from './httpurl'; @@ -23,6 +30,10 @@ export * from './latest_change'; export * from './missing_asset'; export * from './palettes'; export * from './pivot_object_array'; +export * from './registry'; export * from './resolve_dataurl'; +export * from './serialize'; +export * from './type'; +export * from './types_registry'; export * from './unquote_string'; export * from './url'; diff --git a/packages/kbn-interpreter/common/lib/registry.js b/x-pack/plugins/canvas/common/lib/registry.js similarity index 56% rename from packages/kbn-interpreter/common/lib/registry.js rename to x-pack/plugins/canvas/common/lib/registry.js index 9882f3abde7232..accabae4bc5ebb 100644 --- a/packages/kbn-interpreter/common/lib/registry.js +++ b/x-pack/plugins/canvas/common/lib/registry.js @@ -1,20 +1,7 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import clone from 'lodash.clone'; @@ -35,9 +22,8 @@ export class Registry { const obj = fn(); - if (typeof obj !== 'object' || !obj[this._prop]) { + if (typeof obj !== 'object' || !obj[this._prop]) throw new Error(`Registered functions must return an object with a ${this._prop} property`); - } this._indexed[obj[this._prop].toLowerCase()] = this.wrapper(obj); } diff --git a/x-pack/plugins/canvas/common/lib/serialize.js b/x-pack/plugins/canvas/common/lib/serialize.js new file mode 100644 index 00000000000000..0786f6f06b3a35 --- /dev/null +++ b/x-pack/plugins/canvas/common/lib/serialize.js @@ -0,0 +1,24 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { get, identity } from 'lodash'; +import { getType } from '../lib/get_type'; + +export function serializeProvider(types) { + return { + serialize: provider('serialize'), + deserialize: provider('deserialize'), + }; + + function provider(key) { + return context => { + const type = getType(context); + const typeDef = types[type]; + const fn = get(typeDef, key) || identity; + return fn(context); + }; + } +} diff --git a/packages/kbn-interpreter/common/lib/type.js b/x-pack/plugins/canvas/common/lib/type.js similarity index 61% rename from packages/kbn-interpreter/common/lib/type.js rename to x-pack/plugins/canvas/common/lib/type.js index 356b82bf91cbd0..d917750e3848e9 100644 --- a/packages/kbn-interpreter/common/lib/type.js +++ b/x-pack/plugins/canvas/common/lib/type.js @@ -1,25 +1,12 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ // All types must be universal and be castable on the client or on the server import { get } from 'lodash'; -import { getType } from './get_type'; +import { getType } from '../lib/get_type'; // TODO: Currently all casting functions must be syncronous. @@ -48,12 +35,10 @@ export function Type(config) { this.to = (node, toTypeName, types) => { const typeName = getType(node); - if (typeName !== this.name) { + if (typeName !== this.name) throw new Error(`Can not cast object of type '${typeName}' using '${this.name}'`); - } - else if (!this.castsTo(toTypeName)) { + else if (!this.castsTo(toTypeName)) throw new Error(`Can not cast '${typeName}' to '${toTypeName}'`); - } return getToFn(toTypeName)(node, types); }; diff --git a/x-pack/plugins/canvas/common/lib/types_registry.js b/x-pack/plugins/canvas/common/lib/types_registry.js new file mode 100644 index 00000000000000..3d2bb65e9fa0f7 --- /dev/null +++ b/x-pack/plugins/canvas/common/lib/types_registry.js @@ -0,0 +1,16 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { Registry } from '../../common/lib/registry'; +import { Type } from '../../common/lib/type'; + +class TypesRegistry extends Registry { + wrapper(obj) { + return new Type(obj); + } +} + +export const typesRegistry = new TypesRegistry(); diff --git a/x-pack/plugins/canvas/index.js b/x-pack/plugins/canvas/index.js index 0f34eef6c2edbc..b92e29341a14b3 100644 --- a/x-pack/plugins/canvas/index.js +++ b/x-pack/plugins/canvas/index.js @@ -5,11 +5,9 @@ */ import { resolve } from 'path'; -import { pathsRegistry } from '@kbn/interpreter/common/lib/paths_registry'; import init from './init'; import { mappings } from './server/mappings'; import { CANVAS_APP } from './common/lib/constants'; -import { pluginPaths } from './plugin_paths'; export function canvas(kibana) { return new kibana.Plugin({ @@ -41,9 +39,6 @@ export function canvas(kibana) { }).default(); }, - preInit: () => { - pathsRegistry.registerAll(pluginPaths); - }, init, }); } diff --git a/x-pack/plugins/canvas/init.js b/x-pack/plugins/canvas/init.js index 70a8db10d7e664..1ef56fac4e97c2 100644 --- a/x-pack/plugins/canvas/init.js +++ b/x-pack/plugins/canvas/init.js @@ -4,10 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -import { functionsRegistry } from '@kbn/interpreter/common/lib/functions_registry'; -import { getServerRegistries } from '@kbn/interpreter/server/server_registries'; import { routes } from './server/routes'; +import { functionsRegistry } from './common/lib'; import { commonFunctions } from './common/functions'; +import { populateServerRegistries } from './server/lib/server_registries'; import { registerCanvasUsageCollector } from './server/usage'; import { loadSampleData } from './server/sample_data'; @@ -34,6 +34,6 @@ export default async function(server /*options*/) { loadSampleData(server); // Do not initialize the app until the registries are populated - await getServerRegistries(); + await populateServerRegistries(['serverFunctions', 'types']); routes(server); } diff --git a/x-pack/plugins/canvas/plugin_paths.js b/x-pack/plugins/canvas/plugin_paths.js deleted file mode 100644 index 9c9f5d1c49bdec..00000000000000 --- a/x-pack/plugins/canvas/plugin_paths.js +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { resolve } from 'path'; - -export const pluginPaths = { - serverFunctions: resolve(__dirname, 'canvas_plugin/functions/server'), - browserFunctions: resolve(__dirname, 'canvas_plugin/functions/browser'), - commonFunctions: resolve(__dirname, 'canvas_plugin/functions/common'), - elements: resolve(__dirname, 'canvas_plugin/elements'), - renderers: resolve(__dirname, 'canvas_plugin/renderers'), - interfaces: resolve(__dirname, 'canvas_plugin/interfaces'), - transformUIs: resolve(__dirname, 'canvas_plugin/uis/transforms'), - datasourceUIs: resolve(__dirname, 'canvas_plugin/uis/datasources'), - modelUIs: resolve(__dirname, 'canvas_plugin/uis/models'), - viewUIs: resolve(__dirname, 'canvas_plugin/uis/views'), - argumentUIs: resolve(__dirname, 'canvas_plugin/uis/arguments'), -}; diff --git a/x-pack/plugins/canvas/public/components/app/index.js b/x-pack/plugins/canvas/public/components/app/index.js index b776bf59efc994..5f633169604d6f 100644 --- a/x-pack/plugins/canvas/public/components/app/index.js +++ b/x-pack/plugins/canvas/public/components/app/index.js @@ -4,25 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ -import { createSocket } from '@kbn/interpreter/public/socket'; -import { initialize as initializeInterpreter } from '@kbn/interpreter/public/interpreter'; import { connect } from 'react-redux'; import { compose, withProps } from 'recompose'; -import { populateBrowserRegistries } from '@kbn/interpreter/public/browser_registries'; +import { createSocket } from '../../socket'; +import { initialize as initializeInterpreter } from '../../lib/interpreter'; +import { populateBrowserRegistries } from '../../lib/browser_registries'; import { getAppReady, getBasePath } from '../../state/selectors/app'; import { appReady, appError } from '../../state/actions/app'; -import { loadPrivateBrowserFunctions } from '../../lib/load_private_browser_functions'; -import { elementsRegistry } from '../../lib/elements_registry'; -import { renderFunctionsRegistry } from '../../lib/render_functions_registry'; -import { - argTypeRegistry, - datasourceRegistry, - modelRegistry, - transformRegistry, - viewRegistry, -} from '../../expression_types'; -import { App as Component } from './app'; import { trackRouteChange } from './track_route_change'; +import { App as Component } from './app'; const mapStateToProps = state => { // appReady could be an error object @@ -34,24 +24,13 @@ const mapStateToProps = state => { }; }; -const types = { - elements: elementsRegistry, - renderers: renderFunctionsRegistry, - transformUIs: transformRegistry, - datasourceUIs: datasourceRegistry, - modelUIs: modelRegistry, - viewUIs: viewRegistry, - argumentUIs: argTypeRegistry, -}; - const mapDispatchToProps = dispatch => ({ // TODO: the correct socket path should come from upstream, using the constant here is not ideal setAppReady: basePath => async () => { try { // initialize the socket and interpreter await createSocket(basePath); - loadPrivateBrowserFunctions(); - await populateBrowserRegistries(types); + await populateBrowserRegistries(); await initializeInterpreter(); // set app state to ready diff --git a/x-pack/plugins/canvas/public/components/arg_form/advanced_failure.js b/x-pack/plugins/canvas/public/components/arg_form/advanced_failure.js index 13ecfe89bb922c..2bd779de759d94 100644 --- a/x-pack/plugins/canvas/public/components/arg_form/advanced_failure.js +++ b/x-pack/plugins/canvas/public/components/arg_form/advanced_failure.js @@ -8,8 +8,8 @@ import React from 'react'; import PropTypes from 'prop-types'; import { compose, withProps, withPropsOnChange } from 'recompose'; import { EuiForm, EuiTextArea, EuiButton, EuiButtonEmpty, EuiFormRow } from '@elastic/eui'; -import { fromExpression, toExpression } from '@kbn/interpreter/common/lib/ast'; import { createStatefulPropHoc } from '../../components/enhance/stateful_prop'; +import { fromExpression, toExpression } from '../../../common/lib/ast'; export const AdvancedFailureComponent = props => { const { diff --git a/x-pack/plugins/canvas/public/components/datasource/datasource_preview/index.js b/x-pack/plugins/canvas/public/components/datasource/datasource_preview/index.js index f1f3fb2ddae979..8b21c38a5f6f71 100644 --- a/x-pack/plugins/canvas/public/components/datasource/datasource_preview/index.js +++ b/x-pack/plugins/canvas/public/components/datasource/datasource_preview/index.js @@ -4,10 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -import { interpretAst } from '@kbn/interpreter/public/interpreter'; import { pure, compose, lifecycle, withState, branch, renderComponent } from 'recompose'; import { PropTypes } from 'prop-types'; import { Loading } from '../../loading'; +import { interpretAst } from '../../../lib/interpreter'; import { DatasourcePreview as Component } from './datasource_preview'; export const DatasourcePreview = compose( diff --git a/x-pack/plugins/canvas/public/components/element_content/element_content.js b/x-pack/plugins/canvas/public/components/element_content/element_content.js index cb53f9efd0e63a..4f9ee400940a45 100644 --- a/x-pack/plugins/canvas/public/components/element_content/element_content.js +++ b/x-pack/plugins/canvas/public/components/element_content/element_content.js @@ -8,7 +8,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { pure, compose, branch, renderComponent } from 'recompose'; import Style from 'style-it'; -import { getType } from '@kbn/interpreter/common/lib/get_type'; +import { getType } from '../../../common/lib/get_type'; import { Loading } from '../loading'; import { RenderWithFn } from '../render_with_fn'; import { ElementShareContainer } from '../element_share_container'; diff --git a/x-pack/plugins/canvas/public/components/expression/index.js b/x-pack/plugins/canvas/public/components/expression/index.js index 81d73959e83b81..18690529d4e800 100644 --- a/x-pack/plugins/canvas/public/components/expression/index.js +++ b/x-pack/plugins/canvas/public/components/expression/index.js @@ -15,9 +15,9 @@ import { branch, renderComponent, } from 'recompose'; -import { fromExpression } from '@kbn/interpreter/common/lib/ast'; import { getSelectedPage, getSelectedElement } from '../../state/selectors/workpad'; import { setExpression, flushContext } from '../../state/actions/elements'; +import { fromExpression } from '../../../common/lib/ast'; import { getFunctionDefinitions } from '../../lib/function_definitions'; import { getWindow } from '../../lib/get_window'; import { ElementNotSelected } from './element_not_selected'; diff --git a/x-pack/plugins/canvas/public/components/function_form_list/index.js b/x-pack/plugins/canvas/public/components/function_form_list/index.js index 84748f5bbbbb3f..8b6702d94340fd 100644 --- a/x-pack/plugins/canvas/public/components/function_form_list/index.js +++ b/x-pack/plugins/canvas/public/components/function_form_list/index.js @@ -4,11 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import { interpretAst } from '@kbn/interpreter/public/interpreter'; import { compose, withProps } from 'recompose'; import { get } from 'lodash'; -import { toExpression } from '@kbn/interpreter/common/lib/ast'; import { modelRegistry, viewRegistry, transformRegistry } from '../../expression_types'; +import { interpretAst } from '../../lib/interpreter'; +import { toExpression } from '../../../common/lib/ast'; import { FunctionFormList as Component } from './function_form_list'; function normalizeContext(chain) { diff --git a/x-pack/plugins/canvas/public/expression_types/arg_type.js b/x-pack/plugins/canvas/public/expression_types/arg_type.js index a19c726e138c26..76f29afee7185a 100644 --- a/x-pack/plugins/canvas/public/expression_types/arg_type.js +++ b/x-pack/plugins/canvas/public/expression_types/arg_type.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Registry } from '@kbn/interpreter/common/lib/registry'; +import { Registry } from '../../common/lib/registry'; import { BaseForm } from './base_form'; export class ArgType extends BaseForm { diff --git a/x-pack/plugins/canvas/public/expression_types/datasource.js b/x-pack/plugins/canvas/public/expression_types/datasource.js index cd9a8af5f0182a..858be2b4e33dd4 100644 --- a/x-pack/plugins/canvas/public/expression_types/datasource.js +++ b/x-pack/plugins/canvas/public/expression_types/datasource.js @@ -6,7 +6,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { Registry } from '@kbn/interpreter/common/lib/registry'; +import { Registry } from '../../common/lib/registry'; import { RenderToDom } from '../components/render_to_dom'; import { ExpressionFormHandlers } from '../../common/lib/expression_form_handlers'; import { BaseForm } from './base_form'; diff --git a/x-pack/plugins/canvas/public/expression_types/function_form.js b/x-pack/plugins/canvas/public/expression_types/function_form.js index c7bc16a5b2e2b1..70da0004ab1754 100644 --- a/x-pack/plugins/canvas/public/expression_types/function_form.js +++ b/x-pack/plugins/canvas/public/expression_types/function_form.js @@ -7,7 +7,7 @@ import { EuiCallOut } from '@elastic/eui'; import React from 'react'; import { isPlainObject, uniq, last, compact } from 'lodash'; -import { fromExpression } from '@kbn/interpreter/common/lib/ast'; +import { fromExpression } from '../../common/lib/ast'; import { ArgAddPopover } from '../components/arg_add_popover'; import { SidebarSection } from '../components/sidebar/sidebar_section'; import { SidebarSectionTitle } from '../components/sidebar/sidebar_section_title'; diff --git a/x-pack/plugins/canvas/public/expression_types/model.js b/x-pack/plugins/canvas/public/expression_types/model.js index 7ce1126bdec55a..bae74d75589be7 100644 --- a/x-pack/plugins/canvas/public/expression_types/model.js +++ b/x-pack/plugins/canvas/public/expression_types/model.js @@ -5,7 +5,7 @@ */ import { get, pick } from 'lodash'; -import { Registry } from '@kbn/interpreter/common/lib/registry'; +import { Registry } from '../../common/lib/registry'; import { FunctionForm } from './function_form'; const NO_NEXT_EXP = 'no next expression'; diff --git a/x-pack/plugins/canvas/public/expression_types/transform.js b/x-pack/plugins/canvas/public/expression_types/transform.js index 760eae46195d65..216e79b9c106cd 100644 --- a/x-pack/plugins/canvas/public/expression_types/transform.js +++ b/x-pack/plugins/canvas/public/expression_types/transform.js @@ -5,7 +5,7 @@ */ import { pick } from 'lodash'; -import { Registry } from '@kbn/interpreter/common/lib/registry'; +import { Registry } from '../../common/lib/registry'; import { FunctionForm } from './function_form'; export class Transform extends FunctionForm { diff --git a/x-pack/plugins/canvas/public/expression_types/view.js b/x-pack/plugins/canvas/public/expression_types/view.js index 1b7fe13d508b0a..ee83fe3340d760 100644 --- a/x-pack/plugins/canvas/public/expression_types/view.js +++ b/x-pack/plugins/canvas/public/expression_types/view.js @@ -5,7 +5,7 @@ */ import { pick } from 'lodash'; -import { Registry } from '@kbn/interpreter/common/lib/registry'; +import { Registry } from '../../common/lib/registry'; import { FunctionForm } from './function_form'; export class View extends FunctionForm { diff --git a/x-pack/plugins/canvas/public/functions/filters.js b/x-pack/plugins/canvas/public/functions/filters.js index 3c578a93fc3b67..a6f8d2a63fc5e0 100644 --- a/x-pack/plugins/canvas/public/functions/filters.js +++ b/x-pack/plugins/canvas/public/functions/filters.js @@ -4,11 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import { interpretAst } from '@kbn/interpreter/public/interpreter'; -import { fromExpression } from '@kbn/interpreter/common/lib/ast'; -import { typesRegistry } from '@kbn/interpreter/common/lib/types_registry'; +import { fromExpression } from '../../common/lib/ast'; +import { typesRegistry } from '../../common/lib/types_registry'; import { getState } from '../state/store'; import { getGlobalFilterExpression } from '../state/selectors/workpad'; +import { interpretAst } from '../lib/interpreter'; export const filters = () => ({ name: 'filters', diff --git a/x-pack/plugins/canvas/public/lib/arg_helpers.js b/x-pack/plugins/canvas/public/lib/arg_helpers.js index e1cd8b64b323fe..e53e26b62dd157 100644 --- a/x-pack/plugins/canvas/public/lib/arg_helpers.js +++ b/x-pack/plugins/canvas/public/lib/arg_helpers.js @@ -5,7 +5,7 @@ */ import { includes } from 'lodash'; -import { getType } from '@kbn/interpreter/common/lib/get_type'; +import { getType } from '../../common/lib/get_type'; /* diff --git a/x-pack/plugins/canvas/public/lib/browser_registries.js b/x-pack/plugins/canvas/public/lib/browser_registries.js new file mode 100644 index 00000000000000..efceec04d6dce8 --- /dev/null +++ b/x-pack/plugins/canvas/public/lib/browser_registries.js @@ -0,0 +1,74 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import chrome from 'ui/chrome'; +import $script from 'scriptjs'; +import { typesRegistry } from '../../common/lib/types_registry'; +import { + argTypeRegistry, + datasourceRegistry, + transformRegistry, + modelRegistry, + viewRegistry, +} from '../expression_types'; +import { elementsRegistry } from './elements_registry'; +import { renderFunctionsRegistry } from './render_functions_registry'; +import { functionsRegistry as browserFunctions } from './functions_registry'; +import { loadPrivateBrowserFunctions } from './load_private_browser_functions'; + +const registries = { + browserFunctions: browserFunctions, + commonFunctions: browserFunctions, + elements: elementsRegistry, + types: typesRegistry, + renderers: renderFunctionsRegistry, + transformUIs: transformRegistry, + datasourceUIs: datasourceRegistry, + modelUIs: modelRegistry, + viewUIs: viewRegistry, + argumentUIs: argTypeRegistry, +}; + +let resolve = null; +let called = false; + +const populatePromise = new Promise(_resolve => { + resolve = _resolve; +}); + +export const getBrowserRegistries = () => { + return populatePromise; +}; + +export const populateBrowserRegistries = () => { + if (called) throw new Error('function should only be called once per process'); + called = true; + + // loadPrivateBrowserFunctions is sync. No biggie. + loadPrivateBrowserFunctions(); + + const remainingTypes = Object.keys(registries); + const populatedTypes = {}; + + function loadType() { + const type = remainingTypes.pop(); + window.canvas = window.canvas || {}; + window.canvas.register = d => registries[type].register(d); + + // Load plugins one at a time because each needs a different loader function + // $script will only load each of these once, we so can call this as many times as we need? + const pluginPath = chrome.addBasePath(`/api/canvas/plugins?type=${type}`); + $script(pluginPath, () => { + populatedTypes[type] = registries[type]; + + if (remainingTypes.length) loadType(); + else resolve(populatedTypes); + }); + } + + if (remainingTypes.length) loadType(); + return populatePromise; +}; diff --git a/x-pack/plugins/canvas/public/lib/create_handlers.js b/x-pack/plugins/canvas/public/lib/create_handlers.js new file mode 100644 index 00000000000000..93247210eb2911 --- /dev/null +++ b/x-pack/plugins/canvas/public/lib/create_handlers.js @@ -0,0 +1,11 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export function createHandlers(/*socket*/) { + return { + environment: 'client', + }; +} diff --git a/x-pack/plugins/canvas/public/lib/elements_registry.js b/x-pack/plugins/canvas/public/lib/elements_registry.js index dc3d743f498771..898fba183c9f5c 100644 --- a/x-pack/plugins/canvas/public/lib/elements_registry.js +++ b/x-pack/plugins/canvas/public/lib/elements_registry.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Registry } from '@kbn/interpreter/common/lib/registry'; +import { Registry } from '../../common/lib/registry'; import { Element } from './element'; class ElementsRegistry extends Registry { diff --git a/x-pack/plugins/canvas/public/lib/function_definitions.js b/x-pack/plugins/canvas/public/lib/function_definitions.js index c0f3496dfc0835..c4bc16a4c94c30 100644 --- a/x-pack/plugins/canvas/public/lib/function_definitions.js +++ b/x-pack/plugins/canvas/public/lib/function_definitions.js @@ -5,8 +5,8 @@ */ import uniqBy from 'lodash.uniqby'; -import { getBrowserRegistries } from '@kbn/interpreter/public/browser_registries'; import { getServerFunctions } from '../state/selectors/app'; +import { getBrowserRegistries } from './browser_registries'; export async function getFunctionDefinitions(state) { const { browserFunctions } = await getBrowserRegistries(); diff --git a/x-pack/plugins/canvas/public/lib/functions_registry.js b/x-pack/plugins/canvas/public/lib/functions_registry.js index 36f9a631f06ea6..3cc084d8ca66ed 100644 --- a/x-pack/plugins/canvas/public/lib/functions_registry.js +++ b/x-pack/plugins/canvas/public/lib/functions_registry.js @@ -5,4 +5,4 @@ */ // export the common registry here, so it's available in plugin public code -export { functionsRegistry } from '@kbn/interpreter/common/lib/functions_registry'; +export { functionsRegistry } from '../../common/lib/functions_registry'; diff --git a/packages/kbn-interpreter/public/interpreter.js b/x-pack/plugins/canvas/public/lib/interpreter.js similarity index 55% rename from packages/kbn-interpreter/public/interpreter.js rename to x-pack/plugins/canvas/public/lib/interpreter.js index 5c1e199bce363f..36878871b8b150 100644 --- a/packages/kbn-interpreter/public/interpreter.js +++ b/x-pack/plugins/canvas/public/lib/interpreter.js @@ -1,28 +1,15 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -import { socketInterpreterProvider } from '../common/interpreter/socket_interpret'; -import { serializeProvider } from '../common/lib/serialize'; -import { getSocket } from './socket'; -import { typesRegistry } from '../common/lib/types_registry'; +import { socketInterpreterProvider } from '../../common/interpreter/socket_interpret'; +import { serializeProvider } from '../../common/lib/serialize'; +import { getSocket } from '../socket'; +import { typesRegistry } from '../../common/lib/types_registry'; import { createHandlers } from './create_handlers'; -import { functionsRegistry } from '../common/lib/functions_registry'; +import { functionsRegistry } from './functions_registry'; import { getBrowserRegistries } from './browser_registries'; let socket; diff --git a/x-pack/plugins/canvas/public/lib/parse_single_function_chain.js b/x-pack/plugins/canvas/public/lib/parse_single_function_chain.js index 696c058e34a2b0..f8eec880af624b 100644 --- a/x-pack/plugins/canvas/public/lib/parse_single_function_chain.js +++ b/x-pack/plugins/canvas/public/lib/parse_single_function_chain.js @@ -5,7 +5,7 @@ */ import { get, mapValues, map } from 'lodash'; -import { fromExpression } from '@kbn/interpreter/common/lib/ast'; +import { fromExpression } from '../../common/lib/ast'; export function parseSingleFunctionChain(filterString) { const ast = fromExpression(filterString); diff --git a/x-pack/plugins/canvas/public/lib/render_functions_registry.js b/x-pack/plugins/canvas/public/lib/render_functions_registry.js index a34ed009a33b19..3d040047aeb9ac 100644 --- a/x-pack/plugins/canvas/public/lib/render_functions_registry.js +++ b/x-pack/plugins/canvas/public/lib/render_functions_registry.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Registry } from '@kbn/interpreter/common/lib/registry'; +import { Registry } from '../../common/lib/registry'; import { RenderFunction } from './render_function'; class RenderFunctionsRegistry extends Registry { diff --git a/x-pack/plugins/canvas/public/lib/run_interpreter.js b/x-pack/plugins/canvas/public/lib/run_interpreter.js index 7bb898b254ec80..cc0d9a7544786c 100644 --- a/x-pack/plugins/canvas/public/lib/run_interpreter.js +++ b/x-pack/plugins/canvas/public/lib/run_interpreter.js @@ -4,9 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -import { interpretAst } from '@kbn/interpreter/public/interpreter'; -import { fromExpression } from '@kbn/interpreter/common/lib/ast'; -import { getType } from '@kbn/interpreter/common/lib/get_type'; +import { fromExpression } from '../../common/lib/ast'; +import { getType } from '../../common/lib/get_type'; +import { interpretAst } from './interpreter'; import { notify } from './notify'; /** diff --git a/x-pack/plugins/canvas/public/lib/transitions_registry.js b/x-pack/plugins/canvas/public/lib/transitions_registry.js index 8ead0aa896ab79..8d2e421b8233c4 100644 --- a/x-pack/plugins/canvas/public/lib/transitions_registry.js +++ b/x-pack/plugins/canvas/public/lib/transitions_registry.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Registry } from '@kbn/interpreter/common/lib/registry'; +import { Registry } from '../../common/lib/registry'; import { Transition } from '../transitions/transition'; class TransitionsRegistry extends Registry { diff --git a/x-pack/plugins/canvas/public/lib/types_registry.js b/x-pack/plugins/canvas/public/lib/types_registry.js index 05b82c744c3833..c1f13b1ae4612c 100644 --- a/x-pack/plugins/canvas/public/lib/types_registry.js +++ b/x-pack/plugins/canvas/public/lib/types_registry.js @@ -5,4 +5,4 @@ */ // export the common registry here, so it's available in plugin public code -export { typesRegistry } from '@kbn/interpreter/common/lib/types_registry'; +export { typesRegistry } from '../../common/lib/types_registry'; diff --git a/packages/kbn-interpreter/public/socket.js b/x-pack/plugins/canvas/public/socket.js similarity index 64% rename from packages/kbn-interpreter/public/socket.js rename to x-pack/plugins/canvas/public/socket.js index 9143f0018377b6..92deedd488c062 100644 --- a/packages/kbn-interpreter/public/socket.js +++ b/x-pack/plugins/canvas/public/socket.js @@ -1,25 +1,12 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import io from 'socket.io-client'; import { functionsRegistry } from '../common/lib/functions_registry'; -import { getBrowserRegistries } from './browser_registries'; +import { getBrowserRegistries } from './lib/browser_registries'; const SOCKET_CONNECTION_TIMEOUT = 5000; // timeout in ms let socket; diff --git a/x-pack/plugins/canvas/public/state/actions/elements.js b/x-pack/plugins/canvas/public/state/actions/elements.js index be157d9d8085b2..fb82de32fc0ef4 100644 --- a/x-pack/plugins/canvas/public/state/actions/elements.js +++ b/x-pack/plugins/canvas/public/state/actions/elements.js @@ -4,17 +4,17 @@ * you may not use this file except in compliance with the Elastic License. */ -import { interpretAst } from '@kbn/interpreter/public/interpreter'; import { createAction } from 'redux-actions'; import { createThunk } from 'redux-thunks'; import { set, del } from 'object-path-immutable'; import { get, pick, cloneDeep, without } from 'lodash'; -import { toExpression, safeElementFromExpression } from '@kbn/interpreter/common/lib/ast'; import { getPages, getElementById, getSelectedPageIndex } from '../selectors/workpad'; import { getValue as getResolvedArgsValue } from '../selectors/resolved_args'; import { getDefaultElement } from '../defaults'; +import { toExpression, safeElementFromExpression } from '../../../common/lib/ast'; import { notify } from '../../lib/notify'; import { runInterpreter } from '../../lib/run_interpreter'; +import { interpretAst } from '../../lib/interpreter'; import { selectElement } from './transient'; import * as args from './resolved_args'; diff --git a/x-pack/plugins/canvas/public/state/selectors/workpad.js b/x-pack/plugins/canvas/public/state/selectors/workpad.js index 6d888f60c2191c..1db0128abab073 100644 --- a/x-pack/plugins/canvas/public/state/selectors/workpad.js +++ b/x-pack/plugins/canvas/public/state/selectors/workpad.js @@ -5,7 +5,7 @@ */ import { get, omit } from 'lodash'; -import { safeElementFromExpression } from '@kbn/interpreter/common/lib/ast'; +import { safeElementFromExpression } from '../../../common/lib/ast'; import { append } from '../../lib/modify_path'; import { getAssets } from './assets'; diff --git a/src/core_plugins/interpreter/server/lib/__tests__/create_handlers.js b/x-pack/plugins/canvas/server/lib/__tests__/create_handlers.js similarity index 83% rename from src/core_plugins/interpreter/server/lib/__tests__/create_handlers.js rename to x-pack/plugins/canvas/server/lib/__tests__/create_handlers.js index 9afe458c444a73..9dbe0e413a1af1 100644 --- a/src/core_plugins/interpreter/server/lib/__tests__/create_handlers.js +++ b/x-pack/plugins/canvas/server/lib/__tests__/create_handlers.js @@ -1,25 +1,12 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import expect from 'expect.js'; import { createHandlers } from '../create_handlers'; -import { SECURITY_AUTH_MESSAGE } from '../../../common/constants'; +import { SECURITY_AUTH_MESSAGE } from '../../../common/lib/constants'; let securityMode = 'pass'; let isSecurityAvailable = true; diff --git a/src/core_plugins/interpreter/server/lib/create_handlers.js b/x-pack/plugins/canvas/server/lib/create_handlers.js similarity index 58% rename from src/core_plugins/interpreter/server/lib/create_handlers.js rename to x-pack/plugins/canvas/server/lib/create_handlers.js index 9c4dcd112c9286..f42f8fbe1a59dc 100644 --- a/src/core_plugins/interpreter/server/lib/create_handlers.js +++ b/x-pack/plugins/canvas/server/lib/create_handlers.js @@ -1,25 +1,12 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import boom from 'boom'; +import { SECURITY_AUTH_MESSAGE } from '../../common/lib/constants'; import { isSecurityEnabled } from './feature_check'; -import { SECURITY_AUTH_MESSAGE } from '../../common/constants'; export const createHandlers = (request, server) => { const { callWithRequest } = server.plugins.elasticsearch.getCluster('data'); @@ -37,9 +24,8 @@ export const createHandlers = (request, server) => { if (isSecurityEnabled(server)) { try { const authenticationResult = await server.plugins.security.authenticate(request); - if (!authenticationResult.succeeded()) { + if (!authenticationResult.succeeded()) throw boom.unauthorized(authenticationResult.error); - } } catch (e) { // if authenticate throws, show error in development if (process.env.NODE_ENV !== 'production') { diff --git a/x-pack/plugins/canvas/server/lib/feature_check.js b/x-pack/plugins/canvas/server/lib/feature_check.js new file mode 100644 index 00000000000000..e9cec029235825 --- /dev/null +++ b/x-pack/plugins/canvas/server/lib/feature_check.js @@ -0,0 +1,13 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +// TODO: replace this when we use the method exposed by security https://github.com/elastic/kibana/pull/24616 +export const isSecurityEnabled = server => { + const kibanaSecurity = server.plugins.security; + const esSecurity = server.plugins.xpack_main.info.feature('security'); + + return kibanaSecurity && esSecurity.isAvailable() && esSecurity.isEnabled(); +}; diff --git a/x-pack/plugins/canvas/server/lib/get_plugin_paths.js b/x-pack/plugins/canvas/server/lib/get_plugin_paths.js new file mode 100644 index 00000000000000..02582e5f749cc7 --- /dev/null +++ b/x-pack/plugins/canvas/server/lib/get_plugin_paths.js @@ -0,0 +1,83 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import path from 'path'; +import fs from 'fs'; +import { promisify } from 'util'; +import { flatten } from 'lodash'; +import { pluginPaths } from './plugin_paths'; + +const lstat = promisify(fs.lstat); +const readdir = promisify(fs.readdir); + +const canvasPluginDirectoryName = 'canvas_plugin'; + +const isDirectory = path => + lstat(path) + .then(stat => stat.isDirectory()) + .catch(() => false); + +const isDirname = (p, name) => path.basename(p) === name; + +const getKibanaPluginsPath = () => { + const basePluginPath = path.resolve(__dirname, '..', '..', '..', '..', '..'); + + // find the kibana path in dev mode + if (isDirname(basePluginPath, 'kibana')) return path.join(basePluginPath, 'plugins'); + + // find the kibana path in the build, which lives in node_modules and requires going 1 path up + const buildPluginPath = path.join(basePluginPath, '..'); + if (isDirname(basePluginPath, 'node_modules')) { + const pluginPath = path.join(buildPluginPath, 'plugins'); + return isDirectory(pluginPath) && pluginPath; + } + + return false; +}; + +// These must all exist +const paths = [ + path.resolve(__dirname, '..', '..', '..'), // Canvas core plugins + getKibanaPluginsPath(), // Kibana plugin directory +].filter(Boolean); + +export const getPluginPaths = type => { + const typePath = pluginPaths[type]; + if (!typePath) throw new Error(`Unknown type: ${type}`); + + async function findPlugins(directory) { + const isDir = await isDirectory(directory); + if (!isDir) return; + + const names = await readdir(directory); // Get names of everything in the directory + return names + .filter(name => name[0] !== '.') + .map(name => path.resolve(directory, name, canvasPluginDirectoryName, ...typePath)); + } + + return Promise.all(paths.map(findPlugins)) + .then(dirs => + dirs.reduce((list, dir) => { + if (!dir) return list; + return list.concat(dir); + }, []) + ) + .then(possibleCanvasPlugins => { + // Check how many are directories. If lstat fails it doesn't exist anyway. + return Promise.all( + // An array + possibleCanvasPlugins.map(pluginPath => isDirectory(pluginPath)) + ).then(isDirectory => possibleCanvasPlugins.filter((pluginPath, i) => isDirectory[i])); + }) + .then(canvasPluginDirectories => { + return Promise.all( + canvasPluginDirectories.map(dir => + // Get the full path of all files in the directory + readdir(dir).then(files => files.map(file => path.resolve(dir, file))) + ) + ).then(flatten); + }); +}; diff --git a/x-pack/plugins/canvas/server/lib/get_plugin_stream.js b/x-pack/plugins/canvas/server/lib/get_plugin_stream.js new file mode 100644 index 00000000000000..6a08e2beeff8ea --- /dev/null +++ b/x-pack/plugins/canvas/server/lib/get_plugin_stream.js @@ -0,0 +1,24 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import fs from 'fs'; +import ss from 'stream-stream'; +import { getPluginPaths } from './get_plugin_paths'; + +export const getPluginStream = type => { + const stream = ss({ + separator: '\n', + }); + + getPluginPaths(type).then(files => { + files.forEach(file => { + stream.write(fs.createReadStream(file)); + }); + stream.end(); + }); + + return stream; +}; diff --git a/x-pack/plugins/canvas/server/lib/get_request.js b/x-pack/plugins/canvas/server/lib/get_request.js new file mode 100644 index 00000000000000..d55421e437fc42 --- /dev/null +++ b/x-pack/plugins/canvas/server/lib/get_request.js @@ -0,0 +1,30 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +import boom from 'boom'; +import { API_ROUTE } from '../../common/lib/constants'; + +export function getRequest(server, { headers }) { + const url = `${API_ROUTE}/ping`; + + return server + .inject({ + method: 'POST', + url, + headers, + }) + .then(res => { + if (res.statusCode !== 200) { + if (process.env.NODE_ENV !== 'production') { + console.error( + new Error(`Auth request failed: [${res.statusCode}] ${res.result.message}`) + ); + } + throw boom.unauthorized('Failed to authenticate socket connection'); + } + + return res.request; + }); +} diff --git a/x-pack/plugins/canvas/server/lib/plugin_paths.js b/x-pack/plugins/canvas/server/lib/plugin_paths.js new file mode 100644 index 00000000000000..cb90cc0c0f06c3 --- /dev/null +++ b/x-pack/plugins/canvas/server/lib/plugin_paths.js @@ -0,0 +1,20 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const pluginPaths = { + serverFunctions: ['functions', 'server'], + browserFunctions: ['functions', 'browser'], + commonFunctions: ['functions', 'common'], + types: ['types'], + elements: ['elements'], + renderers: ['renderers'], + interfaces: ['interfaces'], + transformUIs: ['uis', 'transforms'], + datasourceUIs: ['uis', 'datasources'], + modelUIs: ['uis', 'models'], + viewUIs: ['uis', 'views'], + argumentUIs: ['uis', 'arguments'], +}; diff --git a/src/core_plugins/interpreter/server/lib/route_expression/browser.js b/x-pack/plugins/canvas/server/lib/route_expression/browser.js similarity index 65% rename from src/core_plugins/interpreter/server/lib/route_expression/browser.js rename to x-pack/plugins/canvas/server/lib/route_expression/browser.js index 0fe27f4d27c684..feae107873ac62 100644 --- a/src/core_plugins/interpreter/server/lib/route_expression/browser.js +++ b/x-pack/plugins/canvas/server/lib/route_expression/browser.js @@ -1,20 +1,7 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import uuid from 'uuid/v4'; diff --git a/src/core_plugins/interpreter/server/lib/route_expression/index.js b/x-pack/plugins/canvas/server/lib/route_expression/index.js similarity index 51% rename from src/core_plugins/interpreter/server/lib/route_expression/index.js rename to x-pack/plugins/canvas/server/lib/route_expression/index.js index 1b3556e051d2df..3533b55687246c 100644 --- a/src/core_plugins/interpreter/server/lib/route_expression/index.js +++ b/x-pack/plugins/canvas/server/lib/route_expression/index.js @@ -1,23 +1,9 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ - -import { createError } from '@kbn/interpreter/common/interpreter/create_error'; +import { createError } from '../../../common/interpreter/create_error'; export const routeExpressionProvider = environments => { async function routeExpression(ast, context = null) { diff --git a/x-pack/plugins/canvas/server/lib/route_expression/server.js b/x-pack/plugins/canvas/server/lib/route_expression/server.js new file mode 100644 index 00000000000000..b24e4cb7e5e418 --- /dev/null +++ b/x-pack/plugins/canvas/server/lib/route_expression/server.js @@ -0,0 +1,27 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { getServerRegistries } from '../server_registries'; +import { interpretProvider } from '../../../common/interpreter/interpret'; +import { createHandlers } from '../create_handlers'; + +export const server = async ({ onFunctionNotFound, server, request }) => { + const { serverFunctions, types } = await getServerRegistries(['serverFunctions', 'types']); + + return { + interpret: (ast, context) => { + const interpret = interpretProvider({ + types: types.toJS(), + functions: serverFunctions.toJS(), + handlers: createHandlers(request, server), + onFunctionNotFound, + }); + + return interpret(ast, context); + }, + getFunctions: () => Object.keys(serverFunctions.toJS()), + }; +}; diff --git a/x-pack/plugins/canvas/server/lib/route_expression/thread/babeled.js b/x-pack/plugins/canvas/server/lib/route_expression/thread/babeled.js new file mode 100644 index 00000000000000..b7c1e83beb7c75 --- /dev/null +++ b/x-pack/plugins/canvas/server/lib/route_expression/thread/babeled.js @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +require('babel-register')({ + ignore: [ + // stolen from kibana/src/setup_node_env/babel_register/register.js + // ignore paths matching `/node_modules/{a}/{b}`, unless `a` + // is `x-pack` and `b` is not `node_modules` + /\/node_modules\/(?!x-pack\/(?!node_modules)([^\/]+))([^\/]+\/[^\/]+)/, + ], + babelrc: false, + presets: [require.resolve('@kbn/babel-preset/node_preset')], +}); + +require('./polyfill'); +require('./worker'); diff --git a/src/core_plugins/interpreter/server/lib/route_expression/thread/index.js b/x-pack/plugins/canvas/server/lib/route_expression/thread/index.js similarity index 78% rename from src/core_plugins/interpreter/server/lib/route_expression/thread/index.js rename to x-pack/plugins/canvas/server/lib/route_expression/thread/index.js index ff476793325e90..d3748db02f65c3 100644 --- a/src/core_plugins/interpreter/server/lib/route_expression/thread/index.js +++ b/x-pack/plugins/canvas/server/lib/route_expression/thread/index.js @@ -1,20 +1,7 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import { fork } from 'child_process'; diff --git a/x-pack/plugins/canvas/server/lib/route_expression/thread/polyfill.js b/x-pack/plugins/canvas/server/lib/route_expression/thread/polyfill.js new file mode 100644 index 00000000000000..be4983e9a37e8f --- /dev/null +++ b/x-pack/plugins/canvas/server/lib/route_expression/thread/polyfill.js @@ -0,0 +1,18 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +// taken from kibana/src/setup_node_env/babel_register/polyfill.js +// ... +// `babel-preset-env` looks for and rewrites the following import +// statement into a list of import statements based on the polyfills +// necessary for our target environment (the current version of node) +// but since it does that during compilation, `import 'babel-polyfill'` +// must be in a file that is loaded with `require()` AFTER `babel-register` +// is configured. +// +// This is why we have this single statement in it's own file and require +// it from ./babeled.js +import 'babel-polyfill'; diff --git a/src/core_plugins/interpreter/server/lib/route_expression/thread/worker.js b/x-pack/plugins/canvas/server/lib/route_expression/thread/worker.js similarity index 62% rename from src/core_plugins/interpreter/server/lib/route_expression/thread/worker.js rename to x-pack/plugins/canvas/server/lib/route_expression/thread/worker.js index 5159679bb9f4f7..d81df410f7af79 100644 --- a/src/core_plugins/interpreter/server/lib/route_expression/thread/worker.js +++ b/x-pack/plugins/canvas/server/lib/route_expression/thread/worker.js @@ -1,26 +1,13 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import uuid from 'uuid/v4'; -import { populateServerRegistries } from '@kbn/interpreter/server/server_registries'; -import { interpretProvider } from '@kbn/interpreter/common/interpreter/interpret'; -import { serializeProvider } from '@kbn/interpreter/common/lib/serialize'; +import { populateServerRegistries } from '../../server_registries'; +import { interpretProvider } from '../../../../common/interpreter/interpret'; +import { serializeProvider } from '../../../../common/lib/serialize'; // We actually DO need populateServerRegistries here since this is a different node process const pluginsReady = populateServerRegistries(['commonFunctions', 'types']); @@ -57,9 +44,8 @@ process.on('message', msg => { }, }); - if (type === 'getFunctions') { + if (type === 'getFunctions') process.send({ type: 'functionList', value: Object.keys(commonFunctions.toJS()) }); - } if (type === 'msgSuccess') { heap[id].resolve(deserialize(value)); diff --git a/x-pack/plugins/canvas/server/lib/server_registries.js b/x-pack/plugins/canvas/server/lib/server_registries.js new file mode 100644 index 00000000000000..cff63a1138ea37 --- /dev/null +++ b/x-pack/plugins/canvas/server/lib/server_registries.js @@ -0,0 +1,55 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { typesRegistry } from '../../common/lib/types_registry'; +import { functionsRegistry as serverFunctions } from '../../common/lib/functions_registry'; +import { getPluginPaths } from './get_plugin_paths'; + +const registries = { + serverFunctions: serverFunctions, + commonFunctions: serverFunctions, + types: typesRegistry, +}; + +let resolve = null; +let called = false; + +const populatePromise = new Promise(_resolve => { + resolve = _resolve; +}); + +export const getServerRegistries = () => { + return populatePromise; +}; + +export const populateServerRegistries = types => { + if (called) throw new Error('function should only be called once per process'); + called = true; + if (!types || !types.length) throw new Error('types is required'); + + const remainingTypes = types; + const populatedTypes = {}; + + const loadType = () => { + const type = remainingTypes.pop(); + getPluginPaths(type).then(paths => { + global.canvas = global.canvas || {}; + global.canvas.register = d => registries[type].register(d); + + paths.forEach(path => { + require(path); + }); + + global.canvas = undefined; + populatedTypes[type] = registries[type]; + if (remainingTypes.length) loadType(); + else resolve(populatedTypes); + }); + }; + + if (remainingTypes.length) loadType(); + return populatePromise; +}; diff --git a/x-pack/plugins/canvas/server/routes/index.js b/x-pack/plugins/canvas/server/routes/index.js index 45f26a423fc845..ab2edfe86b56f0 100644 --- a/x-pack/plugins/canvas/server/routes/index.js +++ b/x-pack/plugins/canvas/server/routes/index.js @@ -5,9 +5,15 @@ */ import { workpad } from './workpad'; +import { socketApi } from './socket'; +import { translate } from './translate'; import { esFields } from './es_fields'; +import { plugins } from './plugins'; export function routes(server) { workpad(server); + socketApi(server); + translate(server); esFields(server); + plugins(server); } diff --git a/x-pack/plugins/canvas/server/routes/plugins.js b/x-pack/plugins/canvas/server/routes/plugins.js new file mode 100644 index 00000000000000..be94ef52ac9e4a --- /dev/null +++ b/x-pack/plugins/canvas/server/routes/plugins.js @@ -0,0 +1,25 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { getPluginStream } from '../lib/get_plugin_stream'; +import { pluginPaths } from '../lib/plugin_paths'; + +export function plugins(server) { + server.route({ + method: 'GET', + path: '/api/canvas/plugins', + handler: function(request, h) { + const { type } = request.query; + + if (!pluginPaths[type]) return h.response({ error: 'Invalid type' }).code(400); + + return getPluginStream(type); + }, + config: { + auth: false, + }, + }); +} diff --git a/src/core_plugins/interpreter/server/routes/socket.js b/x-pack/plugins/canvas/server/routes/socket.js similarity index 68% rename from src/core_plugins/interpreter/server/routes/socket.js rename to x-pack/plugins/canvas/server/routes/socket.js index daf16ec7a44324..8e06c25769d4c1 100644 --- a/src/core_plugins/interpreter/server/routes/socket.js +++ b/x-pack/plugins/canvas/server/routes/socket.js @@ -1,32 +1,19 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ import socket from 'socket.io'; -import { serializeProvider } from '@kbn/interpreter/common/lib/serialize'; -import { typesRegistry } from '@kbn/interpreter/common/lib/types_registry'; -import { getServerRegistries } from '@kbn/interpreter/server/server_registries'; -import { routeExpressionProvider } from '../lib/route_expression/index'; +import { serializeProvider } from '../../common/lib/serialize'; +import { typesRegistry } from '../../common/lib/types_registry'; +import { getServerRegistries } from '../lib/server_registries'; +import { routeExpressionProvider } from '../lib/route_expression'; import { browser } from '../lib/route_expression/browser'; -import { thread } from '../lib/route_expression/thread/index'; +import { thread } from '../lib/route_expression/thread'; import { server as serverEnv } from '../lib/route_expression/server'; import { getRequest } from '../lib/get_request'; -import { API_ROUTE } from '../../common/constants'; +import { API_ROUTE } from '../../common/lib/constants'; async function getModifiedRequest(server, socket) { try { diff --git a/x-pack/plugins/canvas/server/routes/translate.js b/x-pack/plugins/canvas/server/routes/translate.js new file mode 100644 index 00000000000000..6125898a7dab9e --- /dev/null +++ b/x-pack/plugins/canvas/server/routes/translate.js @@ -0,0 +1,34 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { fromExpression, toExpression } from '../../common/lib/ast'; + +export function translate(server) { + /* + Get AST from expression + */ + server.route({ + method: 'GET', + path: '/api/canvas/ast', + handler: function(request, h) { + if (!request.query.expression) + return h.response({ error: '"expression" query is required' }).code(400); + return fromExpression(request.query.expression); + }, + }); + + server.route({ + method: 'POST', + path: '/api/canvas/expression', + handler: function(request, h) { + try { + return toExpression(request.payload); + } catch (e) { + return h.response({ error: e.message }).code(400); + } + }, + }); +} diff --git a/x-pack/plugins/canvas/server/usage/collector.js b/x-pack/plugins/canvas/server/usage/collector.js index d76d023f7c7e48..a4e73ffe85071b 100644 --- a/x-pack/plugins/canvas/server/usage/collector.js +++ b/x-pack/plugins/canvas/server/usage/collector.js @@ -5,8 +5,8 @@ */ import { sum as arraySum, min as arrayMin, max as arrayMax, get } from 'lodash'; -import { fromExpression } from '@kbn/interpreter/common/lib/ast'; import { CANVAS_USAGE_TYPE, CANVAS_TYPE } from '../../common/lib/constants'; +import { fromExpression } from '../../common/lib/ast'; /* * @param ast: an ast that includes functions to track diff --git a/x-pack/plugins/canvas/tasks/helpers/webpack.plugins.js b/x-pack/plugins/canvas/tasks/helpers/webpack.plugins.js index 8b8f3601d86e9e..c53eccd87bd979 100644 --- a/x-pack/plugins/canvas/tasks/helpers/webpack.plugins.js +++ b/x-pack/plugins/canvas/tasks/helpers/webpack.plugins.js @@ -21,6 +21,7 @@ module.exports = { 'uis/arguments/all': path.join(sourceDir, 'uis/arguments/register.js'), 'functions/browser/all': path.join(sourceDir, 'functions/browser/register.js'), 'functions/common/all': path.join(sourceDir, 'functions/common/register.js'), + 'types/all': path.join(sourceDir, 'types/register.js'), }, // there were problems with the node and web targets since this code is actually diff --git a/x-pack/test/functional/apps/canvas/index.js b/x-pack/test/functional/apps/canvas/index.js index 9ede9ff8c67cb9..6620ee6c26f026 100644 --- a/x-pack/test/functional/apps/canvas/index.js +++ b/x-pack/test/functional/apps/canvas/index.js @@ -5,7 +5,7 @@ */ export default function canvasApp({ loadTestFile }) { - describe.skip('Canvas app', function canvasAppTestSuite() { + describe('Canvas app', function canvasAppTestSuite() { this.tags('ciGroup2'); // CI requires tags ヽ(゜Q。)ノ? loadTestFile(require.resolve('./smoke_test')); });