Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
073bb86
moving files
ppisljar Nov 15, 2018
1245ff4
updating license headers
ppisljar Nov 15, 2018
863e520
updating references
ppisljar Nov 15, 2018
05b8b2d
eslint
ppisljar Nov 15, 2018
b942ef9
creating package and plugin
ppisljar Nov 15, 2018
c84f2c5
plugin loading
ppisljar Nov 15, 2018
24b0823
workaround for mocha tests
ppisljar Nov 16, 2018
42259f2
Ensure kbn-interpreter tests get run by jest.
lukeelmers Nov 16, 2018
05fab93
Add unit tests for kbn-interpreter PathsRegistry.
lukeelmers Nov 17, 2018
d592e97
review feedback
ppisljar Nov 19, 2018
607a4df
fixing based on marcos review
ppisljar Nov 19, 2018
eda6dc3
this should actually be in package not in plugin
ppisljar Nov 20, 2018
7ab6dcc
fix(NA): deadlock on init canvas in node 10.
mistic Nov 21, 2018
51bcf08
refact(NA): move kbn interpretor to a trully package.
mistic Nov 22, 2018
d85b8f1
docs(NA): correct description for babel register. fix(NA): make canva…
mistic Nov 22, 2018
8963f9c
fix(NA): make canvas still static analyzable when isolate kbn interpr…
mistic Nov 22, 2018
d907057
chore(NA): fix eslint ignore.
mistic Nov 22, 2018
3c95b45
Merge branch 'ref/canvasInterpreter2OSS' of github.com:ppisljar/kibana
Nov 22, 2018
cd53cf1
Merge branch 'fix-canvas-deadlock-on-node10' of github.com:mistic/kibana
Nov 22, 2018
bf7a36c
chore(NA): apply missed details when merging with Fix deadlock starti…
mistic Nov 22, 2018
53ea0ff
fix(NA): kbn-interpreter build to include runtime generator.
mistic Nov 22, 2018
a437c01
Merge branch 'master' of github.com:elastic/kibana into pr/26068
Nov 23, 2018
bfb2a58
[kbn-interpreter] only include build directories at root of package
Nov 23, 2018
d362673
[kbn-interpreter] move dependencies out of x-pack
Nov 23, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ bower_components
/x-pack/coverage
/x-pack/build
/x-pack/plugins/**/__tests__/fixtures/**
/x-pack/plugins/canvas/common/lib/grammar.js
/packages/kbn-interpreter/common
/packages/kbn-interpreter/plugin
/packages/kbn-interpreter/public
/packages/kbn-interpreter/server
/packages/kbn-interpreter/src/common/lib/grammar.js
/x-pack/plugins/canvas/canvas_plugin
/x-pack/plugins/canvas/canvas_plugin_src/lib/flot-charts
**/*.js.snap
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"@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",
Expand Down Expand Up @@ -383,4 +384,4 @@
"node": "8.11.4",
"yarn": "^1.10.1"
}
}
}
9 changes: 9 additions & 0 deletions packages/kbn-interpreter/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"presets": ["@kbn/babel-preset/webpack_preset"],
"plugins": [
["transform-runtime", {
"polyfill": false,
"regenerator": true
}]
]
}
4 changes: 4 additions & 0 deletions packages/kbn-interpreter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
common
plugin
public
server
16 changes: 16 additions & 0 deletions packages/kbn-interpreter/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@kbn/interpreter",
"version": "1.0.0",
"license": "Apache-2.0",
"scripts": {
"build": "babel src --out-dir ./ --ignore 'src/plugin' && node tasks/build.js",
"canvas:peg": "pegjs common/lib/grammar.peg",
"kbn:bootstrap": "yarn build"
},
"devDependencies": {
"@kbn/babel-preset": "1.0.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +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.
* 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 { getType } from '../lib/get_type';
Expand All @@ -19,8 +32,9 @@ 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]];
Expand Down
26 changes: 26 additions & 0 deletions packages/kbn-interpreter/src/common/interpreter/create_error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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,
},
});
Original file line number Diff line number Diff line change
@@ -1,7 +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.
* 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 clone from 'lodash.clone';
Expand Down Expand Up @@ -112,8 +125,9 @@ 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;
Expand Down Expand Up @@ -142,8 +156,9 @@ 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;
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +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.
* 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 uuid from 'uuid/v4';
Expand Down Expand Up @@ -40,8 +53,9 @@ 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();
Expand Down
37 changes: 37 additions & 0 deletions packages/kbn-interpreter/src/common/lib/arg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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);
};
}
35 changes: 35 additions & 0 deletions packages/kbn-interpreter/src/common/lib/arg.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +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.
*/

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);
});
});
Loading