Skip to content

Commit

Permalink
Merge branch 'master' into kibana-page-template-as-6
Browse files Browse the repository at this point in the history
  • Loading branch information
Constance committed Jun 22, 2021
2 parents e62f3ce + 84d999d commit 9513d1f
Show file tree
Hide file tree
Showing 270 changed files with 6,311 additions and 4,004 deletions.
2 changes: 0 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ snapshots.js

# package overrides
/packages/elastic-eslint-config-kibana
/packages/kbn-interpreter/src/common/lib/grammar.js
/packages/kbn-tinymath/src/grammar.js
/packages/kbn-plugin-generator/template
/packages/kbn-pm/dist
/packages/kbn-test/src/functional_test_runner/__tests__/fixtures/
Expand Down
1 change: 1 addition & 0 deletions docs/developer/getting-started/monorepo-packages.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ yarn kbn watch-bazel
- @kbn/eslint-plugin-eslint
- @kbn/expect
- @kbn/i18n
- @kbn/interpreter
- @kbn/io-ts-utils
- @kbn/legacy-logging
- @kbn/logging
Expand Down
2 changes: 1 addition & 1 deletion docs/user/dashboard/drilldowns.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ The following panel types support drilldowns.
^| X
^| X

| TSVB
| TSVB (only for time series visualizations)
^| X
^| X

Expand Down
1 change: 0 additions & 1 deletion jest.config.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module.exports = {
rootDir: '.',
roots: ['<rootDir>/src', '<rootDir>/packages'],
testMatch: ['**/integration_tests**/*.test.{js,mjs,ts,tsx}'],
testRunner: 'jasmine2',
testPathIgnorePatterns: preset.testPathIgnorePatterns.filter(
(pattern) => !pattern.includes('integration_tests')
),
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"@elastic/charts": "30.1.0",
"@elastic/datemath": "link:bazel-bin/packages/elastic-datemath",
"@elastic/elasticsearch": "npm:@elastic/elasticsearch-canary@^8.0.0-canary.13",
"@elastic/ems-client": "7.13.0",
"@elastic/ems-client": "7.14.0",
"@elastic/eui": "33.0.0",
"@elastic/filesaver": "1.1.2",
"@elastic/good": "^9.0.1-kibana3",
Expand Down Expand Up @@ -133,7 +133,7 @@
"@kbn/crypto": "link:bazel-bin/packages/kbn-crypto",
"@kbn/mapbox-gl": "link:bazel-bin/packages/kbn-mapbox-gl",
"@kbn/i18n": "link:bazel-bin/packages/kbn-i18n",
"@kbn/interpreter": "link:packages/kbn-interpreter",
"@kbn/interpreter": "link:bazel-bin/packages/kbn-interpreter",
"@kbn/io-ts-utils": "link:bazel-bin/packages/kbn-io-ts-utils",
"@kbn/legacy-logging": "link:bazel-bin/packages/kbn-legacy-logging",
"@kbn/logging": "link:bazel-bin/packages/kbn-logging",
Expand Down
1 change: 1 addition & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ filegroup(
"//packages/kbn-eslint-plugin-eslint:build",
"//packages/kbn-expect:build",
"//packages/kbn-i18n:build",
"//packages/kbn-interpreter:build",
"//packages/kbn-io-ts-utils:build",
"//packages/kbn-legacy-logging:build",
"//packages/kbn-logging:build",
Expand Down
9 changes: 0 additions & 9 deletions packages/kbn-interpreter/.babelrc

This file was deleted.

3 changes: 0 additions & 3 deletions packages/kbn-interpreter/.npmignore

This file was deleted.

99 changes: 99 additions & 0 deletions packages/kbn-interpreter/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project")
load("@npm//pegjs:index.bzl", "pegjs")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library", "pkg_npm")

PKG_BASE_NAME = "kbn-interpreter"
PKG_REQUIRE_NAME = "@kbn/interpreter"

SOURCE_FILES = glob(
[
"src/**/*",
]
)

TYPE_FILES = []

SRCS = SOURCE_FILES + TYPE_FILES

filegroup(
name = "srcs",
srcs = SRCS,
)

NPM_MODULE_EXTRA_FILES = [
"common/package.json",
"package.json",
]

SRC_DEPS = [
"@npm//lodash",
]

TYPES_DEPS = [
"@npm//@types/jest",
"@npm//@types/lodash",
"@npm//@types/node",
]

DEPS = SRC_DEPS + TYPES_DEPS

pegjs(
name = "grammar",
data = [
":grammar/grammar.pegjs"
],
output_dir = True,
args = [
"--allowed-start-rules",
"expression,argument",
"-o",
"$(@D)/index.js",
"./%s/grammar/grammar.pegjs" % package_name()
],
)

ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig.base.json",
],
)

ts_project(
name = "tsc",
args = ['--pretty'],
srcs = SRCS,
deps = DEPS,
allow_js = True,
declaration = True,
declaration_map = True,
incremental = True,
out_dir = "target",
source_map = True,
root_dir = "src",
tsconfig = ":tsconfig",
)

js_library(
name = PKG_BASE_NAME,
srcs = NPM_MODULE_EXTRA_FILES + [":grammar"],
deps = DEPS + [":tsc"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)

pkg_npm(
name = "npm_module",
deps = [
":%s" % PKG_BASE_NAME,
]
)

filegroup(
name = "build",
srcs = [
":npm_module",
],
visibility = ["//visibility:public"],
)
3 changes: 1 addition & 2 deletions packages/kbn-interpreter/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"private": true,
"main": "../target/common/index.js",
"types": "../target/common/index.d.ts",
"jsnext:main": "../src/common/index.js"
"types": "../target/common/index.d.ts"
}
8 changes: 1 addition & 7 deletions packages/kbn-interpreter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,5 @@
"name": "@kbn/interpreter",
"private": "true",
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0",
"scripts": {
"interpreter:peg": "../../node_modules/.bin/pegjs src/common/lib/grammar.peg",
"build": "node scripts/build",
"kbn:bootstrap": "node scripts/build --dev",
"kbn:watch": "node scripts/build --dev --watch"
}
"license": "SSPL-1.0 OR Elastic License 2.0"
}
12 changes: 0 additions & 12 deletions packages/kbn-interpreter/src/common/index.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@
* Side Public License, v 1.
*/

export { fromExpression, toExpression, safeElementFromExpression } from './lib/ast';
export {
fromExpression,
toExpression,
safeElementFromExpression,
Ast,
ExpressionFunctionAST,
} from './lib/ast';
export { Fn } from './lib/fn';
export { getType } from './lib/get_type';
export { castProvider } from './lib/cast';
export { parse } from './lib/grammar';
// @ts-expect-error
// @internal
export { parse } from '../../grammar';
export { getByAlias } from './lib/get_by_alias';
export { Registry } from './lib/registry';
export { addRegistries, register, registryFactory } from './registries';
25 changes: 0 additions & 25 deletions packages/kbn-interpreter/src/common/lib/ast.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { fromExpression } from './ast';
import { fromExpression } from '@kbn/interpreter/target/common/lib/ast';
import { getType } from './get_type';

describe('ast fromExpression', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { toExpression } from './ast';
import { toExpression } from '@kbn/interpreter/common';

describe('ast toExpression', () => {
describe('single expression', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,35 @@
*/

import { getType } from './get_type';
import { parse } from './grammar';
// @ts-expect-error
import { parse } from '../../../grammar';

function getArgumentString(arg, argKey, level = 0) {
export type ExpressionArgAST = string | boolean | number | Ast;

export interface ExpressionFunctionAST {
type: 'function';
function: string;
arguments: {
[key: string]: ExpressionArgAST[];
};
}

export interface Ast {
/** @internal */
function: any;
/** @internal */
arguments: any;
type: 'expression';
chain: ExpressionFunctionAST[];
/** @internal */
replace(regExp: RegExp, s: string): string;
}

function getArgumentString(arg: Ast, argKey: string | undefined, level = 0) {
const type = getType(arg);

function maybeArgKey(argKey, argString) {
// eslint-disable-next-line @typescript-eslint/no-shadow
function maybeArgKey(argKey: string | null | undefined, argString: string) {
return argKey == null || argKey === '_' ? argString : `${argKey}=${argString}`;
}

Expand All @@ -36,7 +59,7 @@ function getArgumentString(arg, argKey, level = 0) {
throw new Error(`Invalid argument type in AST: ${type}`);
}

function getExpressionArgs(block, level = 0) {
function getExpressionArgs(block: Ast, level = 0) {
const args = block.arguments;
const hasValidArgs = typeof args === 'object' && args != null && !Array.isArray(args);

Expand All @@ -45,7 +68,7 @@ function getExpressionArgs(block, level = 0) {
const argKeys = Object.keys(args);
const MAX_LINE_LENGTH = 80; // length before wrapping arguments
return argKeys.map((argKey) =>
args[argKey].reduce((acc, arg) => {
args[argKey].reduce((acc: any, arg: any) => {
const argString = getArgumentString(arg, argKey, level);
const lineLength = acc.split('\n').pop().length;

Expand All @@ -63,12 +86,12 @@ function getExpressionArgs(block, level = 0) {
);
}

function fnWithArgs(fnName, args) {
function fnWithArgs(fnName: any, args: any[]) {
if (!args || args.length === 0) return fnName;
return `${fnName} ${args.join(' ')}`;
}

function getExpression(chain, level = 0) {
function getExpression(chain: any[], level = 0) {
if (!chain) throw new Error('Expressions must contain a chain');

// break new functions onto new lines if we're not in a nested/sub-expression
Expand All @@ -90,7 +113,7 @@ function getExpression(chain, level = 0) {
.join(separator);
}

export function fromExpression(expression, type = 'expression') {
export function fromExpression(expression: string, type = 'expression'): Ast {
try {
return parse(String(expression), { startRule: type });
} catch (e) {
Expand All @@ -99,7 +122,7 @@ export function fromExpression(expression, type = 'expression') {
}

// TODO: OMG This is so bad, we need to talk about the right way to handle bad expressions since some are element based and others not
export function safeElementFromExpression(expression) {
export function safeElementFromExpression(expression: string) {
try {
return fromExpression(expression);
} catch (e) {
Expand All @@ -116,8 +139,11 @@ Thanks for understanding,
}

// TODO: Respect the user's existing formatting
export function toExpression(astObj, type = 'expression') {
if (type === 'argument') return getArgumentString(astObj);
export function toExpression(astObj: Ast, type = 'expression'): string {
if (type === 'argument') {
// @ts-ignore
return getArgumentString(astObj);
}

const validType = ['expression', 'function'].includes(getType(astObj));
if (!validType) throw new Error('Expression must be an expression or argument function');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

export function getType(node) {
export function getType(node: any): string {
if (node == null) return 'null';
if (typeof node === 'object') {
if (!node.type) throw new Error('Objects must have a type property');
Expand Down
Loading

0 comments on commit 9513d1f

Please sign in to comment.