Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ES|QL] Introduces a new package for esql types #212754

Merged
merged 13 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,9 @@ src/platform/packages/shared/kbn-es-errors @elastic/kibana-core
src/platform/packages/shared/kbn-es-query @elastic/kibana-data-discovery
src/platform/packages/shared/kbn-es-types @elastic/kibana-core @elastic/obs-knowledge-team
src/platform/packages/shared/kbn-esql-ast @elastic/kibana-esql
src/platform/packages/shared/kbn-esql-types @elastic/kibana-esql
src/platform/packages/shared/kbn-esql-utils @elastic/kibana-esql
src/platform/packages/shared/kbn-esql-validation-autocomplete @elastic/kibana-esql
src/platform/packages/shared/kbn-esql-variables-types @elastic/kibana-esql
src/platform/packages/shared/kbn-event-annotation-common @elastic/kibana-visualizations
src/platform/packages/shared/kbn-event-annotation-components @elastic/kibana-visualizations
src/platform/packages/shared/kbn-expect @elastic/kibana-operations @elastic/appex-qa
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,10 @@
"@kbn/esql-ast-inspector-plugin": "link:examples/esql_ast_inspector",
"@kbn/esql-datagrid": "link:src/platform/plugins/shared/esql_datagrid",
"@kbn/esql-editor": "link:src/platform/packages/private/kbn-esql-editor",
"@kbn/esql-types": "link:src/platform/packages/shared/kbn-esql-types",
"@kbn/esql-utils": "link:src/platform/packages/shared/kbn-esql-utils",
"@kbn/esql-validation-autocomplete": "link:src/platform/packages/shared/kbn-esql-validation-autocomplete",
"@kbn/esql-validation-example-plugin": "link:examples/esql_validation_example",
"@kbn/esql-variables-types": "link:src/platform/packages/shared/kbn-esql-variables-types",
"@kbn/eui-provider-dev-warning": "link:test/plugin_functional/plugins/eui_provider_dev_warning",
"@kbn/event-annotation-common": "link:src/platform/packages/shared/kbn-event-annotation-common",
"@kbn/event-annotation-components": "link:src/platform/packages/shared/kbn-event-annotation-components",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ import memoize from 'lodash/memoize';
import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { createPortal } from 'react-dom';
import { css } from '@emotion/react';
import {
type ESQLRealField,
ESQLVariableType,
type ESQLControlVariable,
} from '@kbn/esql-validation-autocomplete';
import { ESQLVariableType, type ESQLControlVariable } from '@kbn/esql-types';
import { type ESQLRealField } from '@kbn/esql-validation-autocomplete';
import { FieldType } from '@kbn/esql-validation-autocomplete/src/definitions/types';
import { EditorFooter } from './editor_footer';
import { fetchFieldsFromESQL } from './fetch_fields_from_esql';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type { UsageCollectionStart } from '@kbn/usage-collection-plugin/public';
import type { Storage } from '@kbn/kibana-utils-plugin/public';
import type { UiActionsStart } from '@kbn/ui-actions-plugin/public';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { ESQLControlVariable } from '@kbn/esql-validation-autocomplete';
import type { ESQLControlVariable } from '@kbn/esql-types';

export interface ESQLEditorProps {
/** The aggregate type query */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"@kbn/content-management-favorites-common",
"@kbn/kibana-utils-plugin",
"@kbn/ui-actions-plugin",
"@kbn/shared-ux-table-persist"
"@kbn/shared-ux-table-persist",
"@kbn/esql-types"
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import type { ESQLControlVariable } from '@kbn/esql-validation-autocomplete';
import type { ESQLControlVariable } from '@kbn/esql-types';
import { Filter, Query, TimeRange } from '../filters';

export interface ExecutionContextSearch {
Expand Down
2 changes: 1 addition & 1 deletion src/platform/packages/shared/kbn-es-query/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@kbn/utility-types",
"@kbn/i18n",
"@kbn/safer-lodash-set",
"@kbn/esql-validation-autocomplete"
"@kbn/esql-types"
],
"exclude": [
"target/**/*",
Expand Down
31 changes: 31 additions & 0 deletions src/platform/packages/shared/kbn-esql-types/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")

SRCS = glob(
[
"**/*.ts",
"**/*functions.json",
],
exclude = [
"**/*.config.js",
"**/*.mock.*",
"**/*.test.*",
"**/*.stories.*",
"**/__snapshots__/**",
"**/integration_tests/**",
"**/mocks/**",
"**/scripts/**",
"**/storybook/**",
"**/test_fixtures/**",
"**/test_helpers/**",
],
)

SHARED_DEPS = []

js_library(
name = "kbn-esql-types",
package_name = "@kbn/esql-types",
srcs = ["package.json"] + SRCS,
deps = SHARED_DEPS,
visibility = ["//visibility:public"],
)
3 changes: 3 additions & 0 deletions src/platform/packages/shared/kbn-esql-types/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/esql-types

Gathers types of esql usage across kibana.
17 changes: 17 additions & 0 deletions src/platform/packages/shared/kbn-esql-types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export {
ESQLVariableType,
type ESQLControlVariable,
type PublishesESQLVariable,
type PublishesESQLVariables,
apiPublishesESQLVariable,
apiPublishesESQLVariables,
} from './src/variables_types';
14 changes: 14 additions & 0 deletions src/platform/packages/shared/kbn-esql-types/jest.config.js
Original file line number Diff line number Diff line change
@@ -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
* 2.0", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../../../../..',
roots: ['<rootDir>/src/platform/packages/shared/kbn-esql-types'],
};
9 changes: 9 additions & 0 deletions src/platform/packages/shared/kbn-esql-types/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "shared-common",
"id": "@kbn/esql-types",
"owner": [
"@elastic/kibana-esql"
],
"group": "platform",
"visibility": "shared"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "@kbn/esql-variables-types",
"name": "@kbn/esql-types",
"private": true,
"version": "1.0.0",
"author": "Kibana ES|QL",
"license": "Elastic License 2.0 OR AGPL-3.0-only OR SSPL-1.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import type { ESQLControlVariable } from '@kbn/esql-validation-autocomplete';
import { PublishingSubject } from '@kbn/presentation-publishing';

/**
* This should all be moved into a package and reorganized into separate files etc
*/
import { BehaviorSubject } from 'rxjs';

type PublishingSubject<T extends unknown = unknown> = Omit<BehaviorSubject<T>, 'next'>;

export enum ESQLVariableType {
TIME_LITERAL = 'time_literal',
FIELDS = 'fields',
VALUES = 'values',
FUNCTIONS = 'functions',
}

export interface ESQLControlVariable {
key: string;
value: string | number;
type: ESQLVariableType;
}

export interface PublishesESQLVariable {
esqlVariable$: PublishingSubject<ESQLControlVariable>;
Expand Down
10 changes: 10 additions & 0 deletions src/platform/packages/shared/kbn-esql-types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types"
},
"include": ["*.ts", "src/**/*", "__mocks__/**/*.ts"],
"kbn_references": [
],
"exclude": ["target/**/*"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import type { DatatableColumn } from '@kbn/expressions-plugin/common';
import { ESQLVariableType, type ESQLControlVariable } from '@kbn/esql-validation-autocomplete';
import { ESQLVariableType, type ESQLControlVariable } from '@kbn/esql-types';
import {
getIndexPatternFromESQLQuery,
getLimitFromESQLQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
ESQLSingleAstItem,
ESQLCommandOption,
} from '@kbn/esql-ast';
import type { ESQLControlVariable } from '@kbn/esql-validation-autocomplete';
import type { ESQLControlVariable } from '@kbn/esql-types';
import type { DatatableColumn } from '@kbn/expressions-plugin/common';

const DEFAULT_ESQL_LIMIT = 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import { ESQLVariableType, type ESQLControlVariable } from '@kbn/esql-validation-autocomplete';
import { ESQLVariableType, type ESQLControlVariable } from '@kbn/esql-types';
import { getStartEndParams, getNamedParams } from './run_query';

describe('run query helpers', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import type { TimeRange } from '@kbn/es-query';
import { esFieldTypeToKibanaFieldType } from '@kbn/field-types';
import type { ESQLColumn, ESQLSearchResponse, ESQLSearchParams } from '@kbn/es-types';
import { lastValueFrom } from 'rxjs';
import { type ESQLControlVariable, ESQLVariableType } from '@kbn/esql-validation-autocomplete';
import { type ESQLControlVariable } from '@kbn/esql-types';
import { ESQLVariableType } from '@kbn/esql-types';

export const hasStartEndParams = (query: string) => /\?_tstart|\?_tend/i.test(query);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
"@kbn/crypto-browser",
"@kbn/data-view-utils",
"@kbn/esql-ast",
"@kbn/esql-types",
"@kbn/search-types",
"@kbn/expressions-plugin",
"@kbn/field-types",
"@kbn/es-types",
"@kbn/i18n",
"@kbn/datemath",
"@kbn/es-query",
"@kbn/esql-validation-autocomplete"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ SRCS = glob(

SHARED_DEPS = [
"//src/platform/packages/shared/kbn-i18n",
"//src/platform/packages/shared/kbn-esql-types",
"@npm//fastest-levenshtein",
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

export type { SuggestionRawDefinition, ItemKind } from './src/autocomplete/types';
export { ESQLVariableType, type ESQLControlVariable } from './src/shared/types';
export type { CodeAction } from './src/code_actions/types';
export type {
FunctionDefinition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { ESQLVariableType } from '@kbn/esql-types';
import { FieldType, FunctionReturnType } from '../../definitions/types';
import { ESQL_COMMON_NUMERIC_TYPES, ESQL_NUMBER_TYPES } from '../../shared/esql_types';
import { ESQLVariableType } from '../../shared/types';
import { getDateHistogramCompletionItem } from '../commands/stats/util';
import { allStarConstant } from '../complete_items';
import { roundParameterTypes } from './constants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { ESQLVariableType } from '@kbn/esql-types';
import { ESQL_COMMON_NUMERIC_TYPES } from '../../shared/esql_types';
import { ESQLVariableType } from '../../shared/types';
import { pipeCompleteItem } from '../complete_items';
import { getDateLiterals } from '../factories';
import { log10ParameterTypes, powParameterTypes } from './constants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
type ESQLFunction,
type ESQLSingleAstItem,
} from '@kbn/esql-ast';
import { ESQLVariableType, type ESQLControlVariable } from '@kbn/esql-types';
import { ESQL_NUMBER_TYPES, isNumericType } from '../shared/esql_types';
import type { EditorContext, ItemKind, SuggestionRawDefinition, GetColumnsByTypeFn } from './types';
import {
Expand Down Expand Up @@ -84,12 +85,7 @@ import {
getPolicyHelper,
getSourcesHelper,
} from '../shared/resources_helpers';
import type {
ESQLCallbacks,
ESQLSourceResult,
ESQLControlVariable,
ESQLVariableType,
} from '../shared/types';
import type { ESQLCallbacks, ESQLSourceResult } from '../shared/types';
import {
getFunctionsToIgnoreForStats,
getQueryForFields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { ESQLVariableType } from '@kbn/esql-types';
import { CommandSuggestParams } from '../../../definitions/types';
import type { SuggestionRawDefinition } from '../../types';
import {
Expand All @@ -15,7 +15,6 @@ import {
getFunctionSuggestions,
getControlSuggestionIfSupported,
} from '../../factories';
import { ESQLVariableType } from '../../../shared/types';
import { commaCompleteItem, pipeCompleteItem } from '../../complete_items';
import { pushItUpInTheList } from '../../helper';
import { byCompleteItem, getDateHistogramCompletionItem, getPosition } from './util';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import { i18n } from '@kbn/i18n';
import { memoize } from 'lodash';
import { ESQLVariableType, type ESQLControlVariable } from '@kbn/esql-types';
import { SuggestionRawDefinition } from './types';
import { groupingFunctionDefinitions } from '../definitions/generated/grouping_functions';
import { aggFunctionDefinitions } from '../definitions/generated/aggregation_functions';
Expand All @@ -29,7 +30,6 @@ import { ESQLRealField } from '../validation/types';
import { isNumericType } from '../shared/esql_types';
import { getTestFunctions } from '../shared/test_functions';
import { operatorsDefinitions } from '../definitions/all_operators';
import { ESQLVariableType, ESQLControlVariable } from '../shared/types';

const techPreviewLabel = i18n.translate(
'kbn-esql-validation-autocomplete.esql.autocomplete.techPreviewLabel',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
type ESQLSource,
} from '@kbn/esql-ast';
import { uniqBy } from 'lodash';
import { ESQLVariableType } from '@kbn/esql-types';
import {
isParameterType,
type FunctionDefinition,
Expand Down Expand Up @@ -49,7 +50,6 @@ import { EDITOR_MARKER } from '../shared/constants';
import { ESQLRealField, ESQLVariable, ReferenceMaps } from '../validation/types';
import { listCompleteItem } from './complete_items';
import { removeMarkerArgFromArgsList } from '../shared/context';
import { ESQLVariableType } from '../shared/types';

function extractFunctionArgs(args: ESQLAstItem[]): ESQLFunction[] {
return args.flatMap((arg) => (isAssignment(arg) ? arg.args[1] : arg)).filter(isFunctionItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import type { ESQLVariableType } from '../shared/types';
import type { ESQLVariableType } from '@kbn/esql-types';

// This is a subset of the Monaco's editor CompletitionItemKind type
export type ItemKind =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import type { ESQLVariableType, ESQLControlVariable } from '@kbn/esql-types';
import type {
ESQLAstItem,
ESQLCommand,
Expand All @@ -16,12 +16,7 @@ import type {
ESQLSource,
} from '@kbn/esql-ast';
import { GetColumnsByTypeFn, SuggestionRawDefinition } from '../autocomplete/types';
import type {
ESQLCallbacks,
ESQLControlVariable,
ESQLVariableType,
ESQLSourceResult,
} from '../shared/types';
import type { ESQLCallbacks, ESQLSourceResult } from '../shared/types';

/**
* All supported field types in ES|QL. This is all the types
Expand Down
Loading