mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
Co-authored-by: Tiago Costa <tiagoffcc@hotmail.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Tiago Costa <tiagoffcc@hotmail.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
5efd3453ad
commit
e33c29d1b2
31 changed files with 191 additions and 1286 deletions
|
@ -30,8 +30,6 @@ snapshots.js
|
||||||
|
|
||||||
# package overrides
|
# package overrides
|
||||||
/packages/elastic-eslint-config-kibana
|
/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-plugin-generator/template
|
||||||
/packages/kbn-pm/dist
|
/packages/kbn-pm/dist
|
||||||
/packages/kbn-test/src/functional_test_runner/__tests__/fixtures/
|
/packages/kbn-test/src/functional_test_runner/__tests__/fixtures/
|
||||||
|
|
|
@ -81,6 +81,7 @@ yarn kbn watch-bazel
|
||||||
- @kbn/eslint-plugin-eslint
|
- @kbn/eslint-plugin-eslint
|
||||||
- @kbn/expect
|
- @kbn/expect
|
||||||
- @kbn/i18n
|
- @kbn/i18n
|
||||||
|
- @kbn/interpreter
|
||||||
- @kbn/io-ts-utils
|
- @kbn/io-ts-utils
|
||||||
- @kbn/legacy-logging
|
- @kbn/legacy-logging
|
||||||
- @kbn/logging
|
- @kbn/logging
|
||||||
|
|
|
@ -129,7 +129,7 @@
|
||||||
"@kbn/config-schema": "link:bazel-bin/packages/kbn-config-schema",
|
"@kbn/config-schema": "link:bazel-bin/packages/kbn-config-schema",
|
||||||
"@kbn/crypto": "link:bazel-bin/packages/kbn-crypto",
|
"@kbn/crypto": "link:bazel-bin/packages/kbn-crypto",
|
||||||
"@kbn/i18n": "link:bazel-bin/packages/kbn-i18n",
|
"@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/io-ts-utils": "link:bazel-bin/packages/kbn-io-ts-utils",
|
||||||
"@kbn/legacy-logging": "link:bazel-bin/packages/kbn-legacy-logging",
|
"@kbn/legacy-logging": "link:bazel-bin/packages/kbn-legacy-logging",
|
||||||
"@kbn/logging": "link:bazel-bin/packages/kbn-logging",
|
"@kbn/logging": "link:bazel-bin/packages/kbn-logging",
|
||||||
|
|
|
@ -24,6 +24,7 @@ filegroup(
|
||||||
"//packages/kbn-eslint-plugin-eslint:build",
|
"//packages/kbn-eslint-plugin-eslint:build",
|
||||||
"//packages/kbn-expect:build",
|
"//packages/kbn-expect:build",
|
||||||
"//packages/kbn-i18n:build",
|
"//packages/kbn-i18n:build",
|
||||||
|
"//packages/kbn-interpreter:build",
|
||||||
"//packages/kbn-io-ts-utils:build",
|
"//packages/kbn-io-ts-utils:build",
|
||||||
"//packages/kbn-legacy-logging:build",
|
"//packages/kbn-legacy-logging:build",
|
||||||
"//packages/kbn-logging:build",
|
"//packages/kbn-logging:build",
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
"presets": ["@kbn/babel-preset/webpack_preset"],
|
|
||||||
"plugins": [
|
|
||||||
"@babel/plugin-transform-modules-commonjs",
|
|
||||||
["@babel/plugin-transform-runtime", {
|
|
||||||
"regenerator": true
|
|
||||||
}]
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
src
|
|
||||||
tasks
|
|
||||||
.babelrc
|
|
99
packages/kbn-interpreter/BUILD.bazel
Normal file
99
packages/kbn-interpreter/BUILD.bazel
Normal file
|
@ -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"],
|
||||||
|
)
|
|
@ -1,6 +1,5 @@
|
||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"main": "../target/common/index.js",
|
"main": "../target/common/index.js",
|
||||||
"types": "../target/common/index.d.ts",
|
"types": "../target/common/index.d.ts"
|
||||||
"jsnext:main": "../src/common/index.js"
|
|
||||||
}
|
}
|
|
@ -2,11 +2,5 @@
|
||||||
"name": "@kbn/interpreter",
|
"name": "@kbn/interpreter",
|
||||||
"private": "true",
|
"private": "true",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "SSPL-1.0 OR Elastic License 2.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"
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,9 +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
|
|
||||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
||||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
||||||
* Side Public License, v 1.
|
|
||||||
*/
|
|
||||||
|
|
||||||
require('../tasks/build/cli');
|
|
12
packages/kbn-interpreter/src/common/index.d.ts
vendored
12
packages/kbn-interpreter/src/common/index.d.ts
vendored
|
@ -1,12 +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
|
|
||||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
||||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
||||||
* Side Public License, v 1.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export { Registry } from './lib/registry';
|
|
||||||
|
|
||||||
export { fromExpression, toExpression, Ast, ExpressionFunctionAST } from './lib/ast';
|
|
||||||
export { getType } from './lib/get_type';
|
|
|
@ -6,11 +6,19 @@
|
||||||
* Side Public License, v 1.
|
* 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 { Fn } from './lib/fn';
|
||||||
export { getType } from './lib/get_type';
|
export { getType } from './lib/get_type';
|
||||||
export { castProvider } from './lib/cast';
|
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 { getByAlias } from './lib/get_by_alias';
|
||||||
export { Registry } from './lib/registry';
|
export { Registry } from './lib/registry';
|
||||||
export { addRegistries, register, registryFactory } from './registries';
|
export { addRegistries, register, registryFactory } from './registries';
|
25
packages/kbn-interpreter/src/common/lib/ast.d.ts
vendored
25
packages/kbn-interpreter/src/common/lib/ast.d.ts
vendored
|
@ -1,25 +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
|
|
||||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
||||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
||||||
* Side Public License, v 1.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export type ExpressionArgAST = string | boolean | number | Ast;
|
|
||||||
|
|
||||||
export interface ExpressionFunctionAST {
|
|
||||||
type: 'function';
|
|
||||||
function: string;
|
|
||||||
arguments: {
|
|
||||||
[key: string]: ExpressionArgAST[];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Ast {
|
|
||||||
type: 'expression';
|
|
||||||
chain: ExpressionFunctionAST[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export declare function fromExpression(expression: string): Ast;
|
|
||||||
export declare function toExpression(astObj: Ast, type?: string): string;
|
|
|
@ -6,7 +6,7 @@
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { fromExpression } from './ast';
|
import { fromExpression } from '@kbn/interpreter/target/common/lib/ast';
|
||||||
import { getType } from './get_type';
|
import { getType } from './get_type';
|
||||||
|
|
||||||
describe('ast fromExpression', () => {
|
describe('ast fromExpression', () => {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { toExpression } from './ast';
|
import { toExpression } from '@kbn/interpreter/common';
|
||||||
|
|
||||||
describe('ast toExpression', () => {
|
describe('ast toExpression', () => {
|
||||||
describe('single expression', () => {
|
describe('single expression', () => {
|
||||||
|
|
|
@ -7,12 +7,35 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { getType } from './get_type';
|
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);
|
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}`;
|
return argKey == null || argKey === '_' ? argString : `${argKey}=${argString}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +59,7 @@ function getArgumentString(arg, argKey, level = 0) {
|
||||||
throw new Error(`Invalid argument type in AST: ${type}`);
|
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 args = block.arguments;
|
||||||
const hasValidArgs = typeof args === 'object' && args != null && !Array.isArray(args);
|
const hasValidArgs = typeof args === 'object' && args != null && !Array.isArray(args);
|
||||||
|
|
||||||
|
@ -45,7 +68,7 @@ function getExpressionArgs(block, level = 0) {
|
||||||
const argKeys = Object.keys(args);
|
const argKeys = Object.keys(args);
|
||||||
const MAX_LINE_LENGTH = 80; // length before wrapping arguments
|
const MAX_LINE_LENGTH = 80; // length before wrapping arguments
|
||||||
return argKeys.map((argKey) =>
|
return argKeys.map((argKey) =>
|
||||||
args[argKey].reduce((acc, arg) => {
|
args[argKey].reduce((acc: any, arg: any) => {
|
||||||
const argString = getArgumentString(arg, argKey, level);
|
const argString = getArgumentString(arg, argKey, level);
|
||||||
const lineLength = acc.split('\n').pop().length;
|
const lineLength = acc.split('\n').pop().length;
|
||||||
|
|
||||||
|
@ -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;
|
if (!args || args.length === 0) return fnName;
|
||||||
return `${fnName} ${args.join(' ')}`;
|
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');
|
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
|
// break new functions onto new lines if we're not in a nested/sub-expression
|
||||||
|
@ -90,7 +113,7 @@ function getExpression(chain, level = 0) {
|
||||||
.join(separator);
|
.join(separator);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fromExpression(expression, type = 'expression') {
|
export function fromExpression(expression: string, type = 'expression'): Ast {
|
||||||
try {
|
try {
|
||||||
return parse(String(expression), { startRule: type });
|
return parse(String(expression), { startRule: type });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -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
|
// 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 {
|
try {
|
||||||
return fromExpression(expression);
|
return fromExpression(expression);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -116,8 +139,11 @@ Thanks for understanding,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Respect the user's existing formatting
|
// TODO: Respect the user's existing formatting
|
||||||
export function toExpression(astObj, type = 'expression') {
|
export function toExpression(astObj: Ast, type = 'expression'): string {
|
||||||
if (type === 'argument') return getArgumentString(astObj);
|
if (type === 'argument') {
|
||||||
|
// @ts-ignore
|
||||||
|
return getArgumentString(astObj);
|
||||||
|
}
|
||||||
|
|
||||||
const validType = ['expression', 'function'].includes(getType(astObj));
|
const validType = ['expression', 'function'].includes(getType(astObj));
|
||||||
if (!validType) throw new Error('Expression must be an expression or argument function');
|
if (!validType) throw new Error('Expression must be an expression or argument function');
|
|
@ -1,9 +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
|
|
||||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
||||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
||||||
* Side Public License, v 1.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export declare function getType(node: any): string;
|
|
|
@ -6,7 +6,7 @@
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function getType(node) {
|
export function getType(node: any): string {
|
||||||
if (node == null) return 'null';
|
if (node == null) return 'null';
|
||||||
if (typeof node === 'object') {
|
if (typeof node === 'object') {
|
||||||
if (!node.type) throw new Error('Objects must have a type property');
|
if (!node.type) throw new Error('Objects must have a type property');
|
File diff suppressed because it is too large
Load diff
|
@ -1,25 +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
|
|
||||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
||||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
||||||
* Side Public License, v 1.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export class Registry<ItemSpec, Item> {
|
|
||||||
constructor(prop?: string);
|
|
||||||
|
|
||||||
public wrapper(obj: ItemSpec): Item;
|
|
||||||
|
|
||||||
public register(fn: () => ItemSpec): void;
|
|
||||||
|
|
||||||
public toJS(): { [key: string]: any };
|
|
||||||
|
|
||||||
public toArray(): Item[];
|
|
||||||
|
|
||||||
public get(name: string): Item;
|
|
||||||
|
|
||||||
public getProp(): string;
|
|
||||||
|
|
||||||
public reset(): void;
|
|
||||||
}
|
|
|
@ -8,49 +8,59 @@
|
||||||
|
|
||||||
import { clone } from 'lodash';
|
import { clone } from 'lodash';
|
||||||
|
|
||||||
export class Registry {
|
export class Registry<ItemSpec, Item> {
|
||||||
|
private readonly _prop: string;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
|
private _indexed: Object;
|
||||||
|
|
||||||
constructor(prop = 'name') {
|
constructor(prop = 'name') {
|
||||||
if (typeof prop !== 'string') throw new Error('Registry property name must be a string');
|
if (typeof prop !== 'string') throw new Error('Registry property name must be a string');
|
||||||
this._prop = prop;
|
this._prop = prop;
|
||||||
this._indexed = new Object();
|
this._indexed = new Object();
|
||||||
}
|
}
|
||||||
|
|
||||||
wrapper(obj) {
|
wrapper(obj: ItemSpec): Item {
|
||||||
|
// @ts-ignore
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
register(fn) {
|
register(fn: () => ItemSpec): void {
|
||||||
const obj = typeof fn === 'function' ? fn() : fn;
|
const obj = typeof fn === 'function' ? fn() : fn;
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
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`);
|
throw new Error(`Registered functions must return an object with a ${this._prop} property`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
this._indexed[obj[this._prop].toLowerCase()] = this.wrapper(obj);
|
this._indexed[obj[this._prop].toLowerCase()] = this.wrapper(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
toJS() {
|
toJS(): { [key: string]: any } {
|
||||||
return Object.keys(this._indexed).reduce((acc, key) => {
|
return Object.keys(this._indexed).reduce((acc, key) => {
|
||||||
|
// @ts-ignore
|
||||||
acc[key] = this.get(key);
|
acc[key] = this.get(key);
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
toArray() {
|
toArray(): Item[] {
|
||||||
return Object.keys(this._indexed).map((key) => this.get(key));
|
return Object.keys(this._indexed).map((key) => this.get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
get(name) {
|
get(name: string): Item {
|
||||||
|
// @ts-ignore
|
||||||
if (name === undefined) return null;
|
if (name === undefined) return null;
|
||||||
const lowerCaseName = name.toLowerCase();
|
const lowerCaseName = name.toLowerCase();
|
||||||
|
// @ts-ignore
|
||||||
return this._indexed[lowerCaseName] ? clone(this._indexed[lowerCaseName]) : null;
|
return this._indexed[lowerCaseName] ? clone(this._indexed[lowerCaseName]) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
getProp() {
|
getProp(): string {
|
||||||
return this._prop;
|
return this._prop;
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset(): void {
|
||||||
this._indexed = new Object();
|
this._indexed = new Object();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,3 +0,0 @@
|
||||||
/* eslint-disable */
|
|
||||||
import util from 'util';
|
|
||||||
console.log(util.format('hello world'));
|
|
|
@ -1,82 +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
|
|
||||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
||||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
||||||
* Side Public License, v 1.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const { relative } = require('path');
|
|
||||||
|
|
||||||
const getopts = require('getopts');
|
|
||||||
const del = require('del');
|
|
||||||
const supportsColor = require('supports-color');
|
|
||||||
const { ToolingLog, withProcRunner, pickLevelFromFlags } = require('@kbn/dev-utils');
|
|
||||||
|
|
||||||
const { ROOT_DIR, BUILD_DIR } = require('./paths');
|
|
||||||
|
|
||||||
const unknownFlags = [];
|
|
||||||
const flags = getopts(process.argv, {
|
|
||||||
boolean: ['watch', 'dev', 'help', 'debug'],
|
|
||||||
unknown(name) {
|
|
||||||
unknownFlags.push(name);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const log = new ToolingLog({
|
|
||||||
level: pickLevelFromFlags(flags),
|
|
||||||
writeTo: process.stdout,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (unknownFlags.length) {
|
|
||||||
log.error(`Unknown flag(s): ${unknownFlags.join(', ')}`);
|
|
||||||
flags.help = true;
|
|
||||||
process.exitCode = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags.help) {
|
|
||||||
log.info(`
|
|
||||||
Simple build tool for @kbn/interpreter package
|
|
||||||
|
|
||||||
--dev Build for development, include source maps
|
|
||||||
--watch Run in watch mode
|
|
||||||
--debug Turn on debug logging
|
|
||||||
`);
|
|
||||||
process.exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
withProcRunner(log, async (proc) => {
|
|
||||||
log.info('Deleting old output');
|
|
||||||
await del(BUILD_DIR);
|
|
||||||
|
|
||||||
const cwd = ROOT_DIR;
|
|
||||||
const env = { ...process.env };
|
|
||||||
if (supportsColor.stdout) {
|
|
||||||
env.FORCE_COLOR = 'true';
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info(`Starting babel ${flags.watch ? ' in watch mode' : ''}`);
|
|
||||||
await Promise.all([
|
|
||||||
proc.run('babel ', {
|
|
||||||
cmd: 'babel',
|
|
||||||
args: [
|
|
||||||
'src',
|
|
||||||
'--ignore',
|
|
||||||
`*.test.js`,
|
|
||||||
'--out-dir',
|
|
||||||
relative(cwd, BUILD_DIR),
|
|
||||||
'--copy-files',
|
|
||||||
...(flags.dev ? ['--source-maps', 'inline'] : []),
|
|
||||||
...(flags.watch ? ['--watch'] : ['--quiet']),
|
|
||||||
],
|
|
||||||
wait: true,
|
|
||||||
env,
|
|
||||||
cwd,
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
|
|
||||||
log.success('Complete');
|
|
||||||
}).catch((error) => {
|
|
||||||
log.error(error);
|
|
||||||
process.exit(1);
|
|
||||||
});
|
|
|
@ -1,15 +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
|
|
||||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
||||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
||||||
* Side Public License, v 1.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const { resolve } = require('path');
|
|
||||||
|
|
||||||
exports.ROOT_DIR = resolve(__dirname, '../../');
|
|
||||||
exports.SOURCE_DIR = resolve(exports.ROOT_DIR, 'src');
|
|
||||||
exports.BUILD_DIR = resolve(exports.ROOT_DIR, 'target');
|
|
||||||
|
|
||||||
exports.BABEL_PRESET_PATH = require.resolve('@kbn/babel-preset/webpack_preset');
|
|
|
@ -1,7 +1,21 @@
|
||||||
{
|
{
|
||||||
"extends": "../../tsconfig.base.json",
|
"extends": "../../tsconfig.base.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"tsBuildInfoFile": "../../build/tsbuildinfo/packages/kbn-interpreter"
|
"allowJs": true,
|
||||||
|
"incremental": true,
|
||||||
|
"outDir": "./target",
|
||||||
|
"declaration": true,
|
||||||
|
"declarationMap": true,
|
||||||
|
"rootDir": "src",
|
||||||
|
"sourceMap": true,
|
||||||
|
"sourceRoot": "../../../../packages/kbn-interpreter/src",
|
||||||
|
"stripInternal": true,
|
||||||
|
"types": [
|
||||||
|
"jest",
|
||||||
|
"node"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"include": ["index.d.ts", "src/**/*.d.ts"]
|
"include": [
|
||||||
|
"src/**/*",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Ast } from '@kbn/interpreter/common';
|
import { ExpressionAstExpression } from '../../../../expressions/common/ast';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Information about a series in a chart used to determine its color.
|
* Information about a series in a chart used to determine its color.
|
||||||
|
@ -78,7 +78,7 @@ export interface PaletteDefinition<T = unknown> {
|
||||||
* This function should be used to pass the palette to the expression function applying color and other styles
|
* This function should be used to pass the palette to the expression function applying color and other styles
|
||||||
* @param state The internal state of the palette
|
* @param state The internal state of the palette
|
||||||
*/
|
*/
|
||||||
toExpression: (state?: T) => Ast;
|
toExpression: (state?: T) => ExpressionAstExpression;
|
||||||
/**
|
/**
|
||||||
* Color a series according to the internal rules of the palette.
|
* Color a series according to the internal rules of the palette.
|
||||||
* @param series The current series along with its ancestors.
|
* @param series The current series along with its ancestors.
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// @ts-expect-error untyped Elastic library
|
|
||||||
import { castProvider } from '@kbn/interpreter/common';
|
import { castProvider } from '@kbn/interpreter/common';
|
||||||
import { ExpressionFunctionDefinition } from 'src/plugins/expressions/public';
|
import { ExpressionFunctionDefinition } from 'src/plugins/expressions/public';
|
||||||
import { getFunctionHelp, getFunctionErrors } from '../../i18n';
|
import { getFunctionHelp, getFunctionErrors } from '../../i18n';
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
* 2.0.
|
* 2.0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// @ts-expect-error untyped module
|
|
||||||
import { addRegistries, register } from '@kbn/interpreter/common';
|
import { addRegistries, register } from '@kbn/interpreter/common';
|
||||||
// @ts-expect-error untyped local
|
// @ts-expect-error untyped local
|
||||||
import { elementsRegistry } from './lib/elements_registry';
|
import { elementsRegistry } from './lib/elements_registry';
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { get, omit } from 'lodash';
|
import { get, omit } from 'lodash';
|
||||||
// @ts-expect-error untyped local
|
|
||||||
import { safeElementFromExpression, fromExpression } from '@kbn/interpreter/common';
|
import { safeElementFromExpression, fromExpression } from '@kbn/interpreter/common';
|
||||||
import { append } from '../../lib/modify_path';
|
import { append } from '../../lib/modify_path';
|
||||||
import { getAssets } from './assets';
|
import { getAssets } from './assets';
|
||||||
|
|
|
@ -2669,7 +2669,7 @@
|
||||||
version "0.0.0"
|
version "0.0.0"
|
||||||
uid ""
|
uid ""
|
||||||
|
|
||||||
"@kbn/interpreter@link:packages/kbn-interpreter":
|
"@kbn/interpreter@link:bazel-bin/packages/kbn-interpreter":
|
||||||
version "0.0.0"
|
version "0.0.0"
|
||||||
uid ""
|
uid ""
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue